[RFC PATCH 03/16] x86/split_lock: Set up #AC exception for split locked accesses on all CPUs
From: Fenghua Yu
Date: Sun May 27 2018 - 11:46:29 EST
#AC for split lock is set up when each CPU is brought up. By default,
kernel disables the feature bit 29 in TEST_CTL MSR on each CPU.
Signed-off-by: Fenghua Yu <fenghua.yu@xxxxxxxxx>
---
arch/x86/include/asm/cpu.h | 3 +++
arch/x86/kernel/cpu/common.c | 2 ++
arch/x86/kernel/cpu/test_ctl.c | 14 ++++++++++++++
3 files changed, 19 insertions(+)
diff --git a/arch/x86/include/asm/cpu.h b/arch/x86/include/asm/cpu.h
index 083ef6d05c45..00f453fd44ac 100644
--- a/arch/x86/include/asm/cpu.h
+++ b/arch/x86/include/asm/cpu.h
@@ -43,6 +43,7 @@ unsigned int x86_stepping(unsigned int sig);
#ifdef CONFIG_SPLIT_LOCK_AC
void detect_split_lock_ac(void);
bool do_split_lock_exception(struct pt_regs *regs, unsigned long error_code);
+void setup_split_lock(void);
#else /* CONFIG_SPLIT_LOCK_AC */
static inline void detect_split_lock_ac(void) {}
static inline bool
@@ -50,5 +51,7 @@ do_split_lock_exception(struct pt_regs *regs, unsigned long error_code)
{
return false;
}
+
+static inline void setup_split_lock(void) {}
#endif /* CONFIG_SPLIT_LOCK_AC */
#endif /* _ASM_X86_CPU_H */
diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
index b02d90320ec6..af3f23170503 100644
--- a/arch/x86/kernel/cpu/common.c
+++ b/arch/x86/kernel/cpu/common.c
@@ -1382,6 +1382,8 @@ static void identify_cpu(struct cpuinfo_x86 *c)
/* Init Machine Check Exception if available. */
mcheck_cpu_init(c);
+ setup_split_lock();
+
select_idle_routine(c);
#ifdef CONFIG_NUMA
diff --git a/arch/x86/kernel/cpu/test_ctl.c b/arch/x86/kernel/cpu/test_ctl.c
index 82f110759662..c72c0517c6ab 100644
--- a/arch/x86/kernel/cpu/test_ctl.c
+++ b/arch/x86/kernel/cpu/test_ctl.c
@@ -28,6 +28,8 @@ static DEFINE_PER_CPU(struct delayed_work, reenable_delayed_work);
static unsigned long disable_split_lock_jiffies;
static DEFINE_MUTEX(reexecute_split_lock_mutex);
+static int split_lock_ac_kernel = DISABLE_SPLIT_LOCK_AC;
+
/* Detete feature of #AC for split lock by probing bit 29 in MSR_TEST_CTL. */
void detect_split_lock_ac(void)
{
@@ -84,6 +86,18 @@ static void _setup_split_lock(int split_lock_ac_val)
wrmsrl(MSR_TEST_CTL, val);
}
+void setup_split_lock(void)
+{
+ if (!boot_cpu_has(X86_FEATURE_SPLIT_LOCK_AC))
+ return;
+
+ _setup_split_lock(split_lock_ac_kernel);
+
+ pr_info_once("#AC execption for split lock is %sd\n",
+ split_lock_ac_kernel == ENABLE_SPLIT_LOCK_AC ? "enable"
+ : "disable");
+}
+
static void wait_for_reexecution(void)
{
while (time_before(jiffies, disable_split_lock_jiffies +
--
2.5.0