Skip to content

Commit c071b0f

Browse files
nickdesaulnierstorvalds
authored andcommitted
x86: bitops: fix build regression
This is easily reproducible via CC=clang + CONFIG_STAGING=y + CONFIG_VT6656=m. It turns out that if your config tickles __builtin_constant_p via differences in choices to inline or not, these statements produce invalid assembly: $ cat foo.c long a(long b, long c) { asm("orb %1, %0" : "+q"(c): "r"(b)); return c; } $ gcc foo.c foo.c: Assembler messages: foo.c:2: Error: `%rax' not allowed with `orb' Use the `%b` "x86 Operand Modifier" to instead force register allocation to select a lower-8-bit GPR operand. The "q" constraint only has meaning on -m32 otherwise is treated as "r". Not all GPRs have low-8-bit aliases for -m32. Fixes: 1651e70 ("x86: Fix bitops.h warning with a moved cast") Reported-by: kernelci.org bot <[email protected]> Suggested-by: Andy Shevchenko <[email protected]> Suggested-by: Brian Gerst <[email protected]> Suggested-by: H. Peter Anvin <[email protected]> Suggested-by: Ilie Halip <[email protected]> Signed-off-by: Nick Desaulniers <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Tested-by: Sedat Dilek <[email protected]> Tested-by: Nathan Chancellor <[email protected]> [build, clang-11] Reviewed-by: Nathan Chancellor <[email protected]> Reviewed-By: Brian Gerst <[email protected]> Reviewed-by: Jesse Brandeburg <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: Marco Elver <[email protected]> Cc: "Paul E. McKenney" <[email protected]> Cc: Andrey Ryabinin <[email protected]> Cc: Luc Van Oostenryck <[email protected]> Cc: Masahiro Yamada <[email protected]> Cc: Daniel Axtens <[email protected]> Cc: "Peter Zijlstra (Intel)" <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Link: ClangBuiltLinux#961 Link: https://lore.kernel.org/lkml/[email protected]/ Link: https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html#x86Operandmodifiers Signed-off-by: Linus Torvalds <[email protected]>
1 parent 60858c0 commit c071b0f

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

arch/x86/include/asm/bitops.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ static __always_inline void
5252
arch_set_bit(long nr, volatile unsigned long *addr)
5353
{
5454
if (__builtin_constant_p(nr)) {
55-
asm volatile(LOCK_PREFIX "orb %1,%0"
55+
asm volatile(LOCK_PREFIX "orb %b1,%0"
5656
: CONST_MASK_ADDR(nr, addr)
57-
: "iq" (CONST_MASK(nr) & 0xff)
57+
: "iq" (CONST_MASK(nr))
5858
: "memory");
5959
} else {
6060
asm volatile(LOCK_PREFIX __ASM_SIZE(bts) " %1,%0"
@@ -72,9 +72,9 @@ static __always_inline void
7272
arch_clear_bit(long nr, volatile unsigned long *addr)
7373
{
7474
if (__builtin_constant_p(nr)) {
75-
asm volatile(LOCK_PREFIX "andb %1,%0"
75+
asm volatile(LOCK_PREFIX "andb %b1,%0"
7676
: CONST_MASK_ADDR(nr, addr)
77-
: "iq" (CONST_MASK(nr) ^ 0xff));
77+
: "iq" (~CONST_MASK(nr)));
7878
} else {
7979
asm volatile(LOCK_PREFIX __ASM_SIZE(btr) " %1,%0"
8080
: : RLONG_ADDR(addr), "Ir" (nr) : "memory");
@@ -123,9 +123,9 @@ static __always_inline void
123123
arch_change_bit(long nr, volatile unsigned long *addr)
124124
{
125125
if (__builtin_constant_p(nr)) {
126-
asm volatile(LOCK_PREFIX "xorb %1,%0"
126+
asm volatile(LOCK_PREFIX "xorb %b1,%0"
127127
: CONST_MASK_ADDR(nr, addr)
128-
: "iq" ((u8)CONST_MASK(nr)));
128+
: "iq" (CONST_MASK(nr)));
129129
} else {
130130
asm volatile(LOCK_PREFIX __ASM_SIZE(btc) " %1,%0"
131131
: : RLONG_ADDR(addr), "Ir" (nr) : "memory");

0 commit comments

Comments
 (0)