[RFC PATCH 04/16] x86/split_lock: Use non locked bit set instruction in set_cpu_cap

From: Fenghua Yu
Date: Sun May 27 2018 - 11:49:57 EST


set_bit() called by set_cpu_cap() is a locked bit set instruction for
atomic operation.

Since the c->x86_capability can span two cache lines depending on kernel
configuration and building evnironment, the locked bit set instruction may
cause #AC exception when #AC exception for split lock is enabled.

But set_cpu_cap() is only called in early init phase on one CPU and
therefore there is no contention for set_cpu_cap(). It's unnecessary
to be atomic operation.

Using __set_bit(), which is not a locked instruction, is faster than
the locked instruction and can fix kernel split lock issue.

Signed-off-by: Fenghua Yu <fenghua.yu@xxxxxxxxx>
Acked-by: Dave Hansen <dave.hansen@xxxxxxxxx>
---
arch/x86/include/asm/cpufeature.h | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
index aced6c9290d6..0793ec95d18b 100644
--- a/arch/x86/include/asm/cpufeature.h
+++ b/arch/x86/include/asm/cpufeature.h
@@ -128,7 +128,8 @@ extern const char * const x86_bug_flags[NBUGINTS*32];

#define boot_cpu_has(bit) cpu_has(&boot_cpu_data, bit)

-#define set_cpu_cap(c, bit) set_bit(bit, (unsigned long *)((c)->x86_capability))
+#define set_cpu_cap(c, bit) \
+ __set_bit(bit, (unsigned long *)((c)->x86_capability))

extern void setup_clear_cpu_cap(unsigned int bit);
extern void clear_cpu_cap(struct cpuinfo_x86 *c, unsigned int bit);
--
2.5.0