Skip to content

Commit 9b04045

Browse files
abattersbyKAGA-KOKO
authored andcommitted
x86/smp: Dont access non-existing CPUID leaf
stop_this_cpu() tests CPUID leaf 0x8000001f::EAX unconditionally. Intel CPUs return the content of the highest supported leaf when a non-existing leaf is read, while AMD CPUs return all zeros for unsupported leafs. So the result of the test on Intel CPUs is lottery. While harmless it's incorrect and causes the conditional wbinvd() to be issued where not required. Check whether the leaf is supported before reading it. [ tglx: Adjusted changelog ] Fixes: 08f253e ("x86/cpu: Clear SME feature flag when not in use") Signed-off-by: Tony Battersby <tonyb@cybernetics.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Reviewed-by: Mario Limonciello <mario.limonciello@amd.com> Reviewed-by: Borislav Petkov (AMD) <bp@alien8.de> Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/3817d810-e0f1-8ef8-0bbd-663b919ca49b@cybernetics.com Link: https://lore.kernel.org/r/20230615193330.322186388@linutronix.de
1 parent 1f5e7eb commit 9b04045

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

arch/x86/kernel/process.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,7 @@ struct cpumask cpus_stop_mask;
763763

764764
void __noreturn stop_this_cpu(void *dummy)
765765
{
766+
struct cpuinfo_x86 *c = this_cpu_ptr(&cpu_info);
766767
unsigned int cpu = smp_processor_id();
767768

768769
local_irq_disable();
@@ -777,7 +778,7 @@ void __noreturn stop_this_cpu(void *dummy)
777778
*/
778779
set_cpu_online(cpu, false);
779780
disable_local_APIC();
780-
mcheck_cpu_clear(this_cpu_ptr(&cpu_info));
781+
mcheck_cpu_clear(c);
781782

782783
/*
783784
* Use wbinvd on processors that support SME. This provides support
@@ -791,7 +792,7 @@ void __noreturn stop_this_cpu(void *dummy)
791792
* Test the CPUID bit directly because the machine might've cleared
792793
* X86_FEATURE_SME due to cmdline options.
793794
*/
794-
if (cpuid_eax(0x8000001f) & BIT(0))
795+
if (c->extended_cpuid_level >= 0x8000001f && (cpuid_eax(0x8000001f) & BIT(0)))
795796
native_wbinvd();
796797

797798
/*

0 commit comments

Comments
 (0)