From: Chuck Anderson Date: Mon, 26 Feb 2018 07:58:47 +0000 (-0800) Subject: retpoline: move lock/unlock of spec_ctrl_mutex into init_scattered_cpuid_features() X-Git-Tag: v4.1.12-124.31.3~1111 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=9d7c6d542641c59fbe2cb485468cfd488ee10dcc;p=users%2Fjedix%2Flinux-maple.git retpoline: move lock/unlock of spec_ctrl_mutex into init_scattered_cpuid_features() init_scattered_cpuid_features() changes spectre mitigation state. Not all callers obtained spec_ctrl_mutex. Move the lock/unlock of spec_ctrl_mutex to init_scattered_cpuid_features() rather than have the callers obtain it. That also allows init_scattered_cpuid_features() to serialize just the spectre state changes instead of the entire function. Orabug: 27625404 Signed-off-by: Chuck Anderson Reviewed-by: Konrad Rzeszutek Wilk Reviewed-by: Darren Kenny --- diff --git a/arch/x86/kernel/cpu/microcode/core.c b/arch/x86/kernel/cpu/microcode/core.c index 6b7a843db454..2f83c508c1cc 100644 --- a/arch/x86/kernel/cpu/microcode/core.c +++ b/arch/x86/kernel/cpu/microcode/core.c @@ -233,9 +233,7 @@ static ssize_t microcode_write(struct file *file, const char __user *buf, perf_check_microcode(); /* check spec_ctrl capabilities */ - mutex_lock(&spec_ctrl_mutex); init_scattered_cpuid_features(&boot_cpu_data); - mutex_unlock(&spec_ctrl_mutex); mutex_unlock(µcode_mutex); put_online_cpus(); diff --git a/arch/x86/kernel/cpu/scattered.c b/arch/x86/kernel/cpu/scattered.c index b4825d59a9b4..39e16bb62490 100644 --- a/arch/x86/kernel/cpu/scattered.c +++ b/arch/x86/kernel/cpu/scattered.c @@ -178,6 +178,8 @@ void init_scattered_cpuid_features(struct cpuinfo_x86 *c) clear_cpu_cap(c, X86_FEATURE_STIBP); } + mutex_lock(&spec_ctrl_mutex); + if (cpu_has(c, X86_FEATURE_IBRS)) { set_ibrs_supported(); /* @@ -193,4 +195,6 @@ void init_scattered_cpuid_features(struct cpuinfo_x86 *c) set_ibpb_supported(); sysctl_ibpb_enabled = ibpb_inuse ? 1 : 0; } + + mutex_unlock(&spec_ctrl_mutex); }