Re: [PATCH v5 2/2] x86/speculation: Enable cross-hyperthread spectre v2 STIBP mitigation

From: Thomas Gleixner
Date: Mon Sep 10 2018 - 06:04:15 EST


On Mon, 10 Sep 2018, Jiri Kosina wrote:
> +static void update_stibp_msr(void *info)
> +{
> + wrmsrl(MSR_IA32_SPEC_CTRL, x86_spec_ctrl_base);
> +}
> +
> +void arch_smt_update(void)
> +{
> + if (stibp_needed()) {

if (!stib_needed())
return;

spares you an indentation level.

> + u64 mask;

Newline between declarations and code please.

> + mutex_lock(&spec_ctrl_mutex);
> + mask = x86_spec_ctrl_base;
> + if (cpu_smt_control == CPU_SMT_ENABLED)
> + mask |= SPEC_CTRL_STIBP;
> + else
> + mask &= ~SPEC_CTRL_STIBP;
> +
> + if (mask != x86_spec_ctrl_base) {
> + pr_info("Spectre v2 cross-process SMT mitigation: %s STIBP\n",
> + cpu_smt_control == CPU_SMT_ENABLED ?
> + "Enabling" : "Disabling");
> + x86_spec_ctrl_base = mask;
> + on_each_cpu(update_stibp_msr, NULL, 1);
> + }
> + mutex_unlock(&spec_ctrl_mutex);
> + }
> +}
> +

That looks much more palatable. One missing piece is the sysfs mitigation
file for spectre v2. That should reflect STIPB state as well.

Thanks,

tglx