Re: [PATCH v15] x86/split_lock: Enable split lock detection by kernel

From: Thomas Gleixner
Date: Sat Jan 25 2020 - 08:41:51 EST


Tony,

"Luck, Tony" <tony.luck@xxxxxxxxx> writes:
> +
> +void switch_to_sld(struct task_struct *prev, struct task_struct *next)
> +{
> + bool prevflag = test_tsk_thread_flag(prev, TIF_SLD);
> + bool nextflag = test_tsk_thread_flag(next, TIF_SLD);
> +
> + /*
> + * If we are switching between tasks that have the same
> + * need for split lock checking, then the MSR is (probably)
> + * right (modulo the other thread messing with it.
> + * Otherwise look at whether the new task needs split
> + * lock enabled.
> + */
> + if (prevflag != nextflag)
> + __sld_msr_set(nextflag);
> +}
> diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
> index 839b5244e3b7..b34d359c4e39 100644
> --- a/arch/x86/kernel/process.c
> +++ b/arch/x86/kernel/process.c
> @@ -650,6 +650,8 @@ void __switch_to_xtra(struct task_struct *prev_p, struct task_struct *next_p)
> /* Enforce MSR update to ensure consistent state */
> __speculation_ctrl_update(~tifn, tifn);
> }
> +
> + switch_to_sld(prev_p, next_p);

This really wants to follow the logic of the other TIF checks.

if ((tifp ^ tifn) & _TIF_SLD)
switch_to_sld(tifn);

and

void switch_to_sld(tifn)
{
__sld_msr_set(tif & _TIF_SLD);
}

That reuses tifp, tifn which are ready to consume there and calls only
out of line when the bits differ. The xor/and combo turned out to result
in the most efficient code.

Thanks,

tglx