Re: [PATCH 1/1] x86/split_lock: check split lock feature on initialization

From: Sean Christopherson
Date: Fri Apr 03 2020 - 14:01:52 EST


On Fri, Apr 03, 2020 at 07:44:03PM +0200, Benjamin Lamowski wrote:
> While the setup code probes for the availability of the TEST_CTRL MSR,
> the current initialization code unconditionally probes it even on
> systems where this architectural MSR is not available.
>
> This commit changes the code to check for the availability of the split
> lock detect feature before initializing it.
>
> Fixes: dbaba47085b0c ("x86/split_lock: Rework the initialization flow of split lock detection")
> Signed-off-by: Benjamin Lamowski <benjamin.lamowski@xxxxxxxxxxxxxxx>
> ---
> arch/x86/kernel/cpu/intel.c | 9 +++++----
> 1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
> index 9a26e972cdea..70d338ff4807 100644
> --- a/arch/x86/kernel/cpu/intel.c
> +++ b/arch/x86/kernel/cpu/intel.c
> @@ -586,7 +586,7 @@ static void init_intel_misc_features(struct cpuinfo_x86 *c)
> wrmsrl(MSR_MISC_FEATURES_ENABLES, msr);
> }
>
> -static void split_lock_init(void);
> +static void split_lock_init(struct cpuinfo_x86 *c);
>
> static void init_intel(struct cpuinfo_x86 *c)
> {
> @@ -703,7 +703,7 @@ static void init_intel(struct cpuinfo_x86 *c)
> if (tsx_ctrl_state == TSX_CTRL_DISABLE)
> tsx_disable();
>
> - split_lock_init();
> + split_lock_init(c);
> }
>
> #ifdef CONFIG_X86_32
> @@ -1061,9 +1061,10 @@ static void sld_update_msr(bool on)
> wrmsrl(MSR_TEST_CTRL, test_ctrl_val);
> }
>
> -static void split_lock_init(void)
> +static void split_lock_init(struct cpuinfo_x86 *c)
> {
> - split_lock_verify_msr(sld_state != sld_off);
> + if (cpu_has(c, X86_FEATURE_SPLIT_LOCK_DETECT))
> + split_lock_verify_msr(sld_state != sld_off);

Calling split_lock_verify_msr() with X86_FEATURE_SPLIT_LOCK_DETECT=0 is
intentional, the idea is to ensure SLD is disabled on all CPUs, e.g. in the
unlikely scenario that BIOS enabled SLD.

The first rdmsrl_safe() should short circuit split_lock_verify_msr() if
the RDMSR faults, i.e. it might fault, but it shouldn't WARN. Are you
seeing issues or was this found via code inspection?

> }
>
> bool handle_user_split_lock(struct pt_regs *regs, long error_code)
> --
> 2.25.1
>