Skip to content

Commit b776078

Browse files
author
Peter Zijlstra
committed
x86/word-at-a-time: Remove .fixup usage
Rewrite load_unaligned_zeropad() to not require .fixup text. This is easiest done using asm-goto-output, where we can stick a C label in the exception table entry. The fallback version isn't nearly so nice but should work. Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Reviewed-by: Josh Poimboeuf <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent d5d797d commit b776078

File tree

1 file changed

+47
-19
lines changed

1 file changed

+47
-19
lines changed

arch/x86/include/asm/word-at-a-time.h

Lines changed: 47 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -77,30 +77,58 @@ static inline unsigned long find_zero(unsigned long mask)
7777
* and the next page not being mapped, take the exception and
7878
* return zeroes in the non-existing part.
7979
*/
80+
#ifdef CONFIG_CC_HAS_ASM_GOTO_OUTPUT
81+
8082
static inline unsigned long load_unaligned_zeropad(const void *addr)
8183
{
82-
unsigned long ret, dummy;
84+
unsigned long offset, data;
85+
unsigned long ret;
86+
87+
asm_volatile_goto(
88+
"1: mov %[mem], %[ret]\n"
89+
90+
_ASM_EXTABLE(1b, %l[do_exception])
91+
92+
: [ret] "=r" (ret)
93+
: [mem] "m" (*(unsigned long *)addr)
94+
: : do_exception);
95+
96+
return ret;
97+
98+
do_exception:
99+
offset = (unsigned long)addr & (sizeof(long) - 1);
100+
addr = (void *)((unsigned long)addr & ~(sizeof(long) - 1));
101+
data = *(unsigned long *)addr;
102+
ret = data >> offset * 8;
103+
104+
return ret;
105+
}
83106

84-
asm(
85-
"1:\tmov %2,%0\n"
107+
#else /* !CONFIG_CC_HAS_ASM_GOTO_OUTPUT */
108+
109+
static inline unsigned long load_unaligned_zeropad(const void *addr)
110+
{
111+
unsigned long offset, data;
112+
unsigned long ret, err = 0;
113+
114+
asm( "1: mov %[mem], %[ret]\n"
86115
"2:\n"
87-
".section .fixup,\"ax\"\n"
88-
"3:\t"
89-
"lea %2,%1\n\t"
90-
"and %3,%1\n\t"
91-
"mov (%1),%0\n\t"
92-
"leal %2,%%ecx\n\t"
93-
"andl %4,%%ecx\n\t"
94-
"shll $3,%%ecx\n\t"
95-
"shr %%cl,%0\n\t"
96-
"jmp 2b\n"
97-
".previous\n"
98-
_ASM_EXTABLE(1b, 3b)
99-
:"=&r" (ret),"=&c" (dummy)
100-
:"m" (*(unsigned long *)addr),
101-
"i" (-sizeof(unsigned long)),
102-
"i" (sizeof(unsigned long)-1));
116+
117+
_ASM_EXTABLE_FAULT(1b, 2b)
118+
119+
: [ret] "=&r" (ret), "+a" (err)
120+
: [mem] "m" (*(unsigned long *)addr));
121+
122+
if (unlikely(err)) {
123+
offset = (unsigned long)addr & (sizeof(long) - 1);
124+
addr = (void *)((unsigned long)addr & ~(sizeof(long) - 1));
125+
data = *(unsigned long *)addr;
126+
ret = data >> offset * 8;
127+
}
128+
103129
return ret;
104130
}
105131

132+
#endif /* CONFIG_CC_HAS_ASM_GOTO_OUTPUT */
133+
106134
#endif /* _ASM_WORD_AT_A_TIME_H */

0 commit comments

Comments
 (0)