[PATCH] x86/percpu: Fix assembly in variable_test_bit

From: Keno Fischer
Date: Wed Mar 18 2020 - 01:25:20 EST


I was trying to compile the kernel with -Og for a better debugging
experience. One side effect of this that the compiler will no longer
do as aggressive dead code elimination, so assembly blocks that were
previously dce'd remained in the final assembly. There's quite a number
of places in the kernel that rely on this dce happening, so it's not
clear that this should be a supported configuration. Nevertheless,
in this particular instance, I believe it found a real issue. In
particular, I believe the `__percpu_arg` macro should be on the
memory operand rather than the immediate. As far as I can tell,
this was never correct, but just happened to be always dce'd out
because the cpu_test macro is generally only used with constant
`nr` arguments.

Fixes: 349c004e3d31 ("x86: A fast way to check capabilities of the current cpu")
Signed-off-by: Keno Fischer <keno@xxxxxxxxxxxxxxxxxx>
---
arch/x86/include/asm/percpu.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/include/asm/percpu.h b/arch/x86/include/asm/percpu.h
index 2278797c769d..17c7677e6cdd 100644
--- a/arch/x86/include/asm/percpu.h
+++ b/arch/x86/include/asm/percpu.h
@@ -539,7 +539,7 @@ static inline bool x86_this_cpu_variable_test_bit(int nr,
{
bool oldbit;

- asm volatile("btl "__percpu_arg(2)",%1"
+ asm volatile("btl %2,"__percpu_arg(1)"\n\t"
CC_SET(c)
: CC_OUT(c) (oldbit)
: "m" (*(unsigned long __percpu *)addr), "Ir" (nr));
--
2.24.0