Skip to content

Commit a6a6074

Browse files
calmisiKAGA-KOKO
authored andcommitted
x86/split_lock: Avoid runtime reads of the TEST_CTRL MSR
In a context switch from a task that is detecting split locks to one that is not (or vice versa) we need to update the TEST_CTRL MSR. Currently this is done with the common sequence: read the MSR flip the bit write the MSR in order to avoid changing the value of any reserved bits in the MSR. Cache unused and reserved bits of TEST_CTRL MSR with SPLIT_LOCK_DETECT bit cleared during initialization, so we can avoid an expensive RDMSR instruction during context switch. Suggested-by: Sean Christopherson <[email protected]> Originally-by: Tony Luck <[email protected]> Signed-off-by: Xiaoyao Li <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent dbaba47 commit a6a6074

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

arch/x86/kernel/cpu/intel.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ enum split_lock_detect_state {
4545
* split lock detect, unless there is a command line override.
4646
*/
4747
static enum split_lock_detect_state sld_state __ro_after_init = sld_off;
48+
static u64 msr_test_ctrl_cache __ro_after_init;
4849

4950
/*
5051
* Processors which have self-snooping capability can handle conflicting
@@ -1034,6 +1035,8 @@ static void __init split_lock_setup(void)
10341035
break;
10351036
}
10361037

1038+
rdmsrl(MSR_TEST_CTRL, msr_test_ctrl_cache);
1039+
10371040
if (!split_lock_verify_msr(true)) {
10381041
pr_info("MSR access failed: Disabled\n");
10391042
return;
@@ -1050,14 +1053,10 @@ static void __init split_lock_setup(void)
10501053
*/
10511054
static void sld_update_msr(bool on)
10521055
{
1053-
u64 test_ctrl_val;
1054-
1055-
rdmsrl(MSR_TEST_CTRL, test_ctrl_val);
1056+
u64 test_ctrl_val = msr_test_ctrl_cache;
10561057

10571058
if (on)
10581059
test_ctrl_val |= MSR_TEST_CTRL_SPLIT_LOCK_DETECT;
1059-
else
1060-
test_ctrl_val &= ~MSR_TEST_CTRL_SPLIT_LOCK_DETECT;
10611060

10621061
wrmsrl(MSR_TEST_CTRL, test_ctrl_val);
10631062
}

0 commit comments

Comments
 (0)