public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH RFC] x86/cpu: fix intermittent lockup on poweroff
@ 2023-04-25 19:26 Tony Battersby
  2023-04-25 19:39 ` Borislav Petkov
                   ` (3 more replies)
  0 siblings, 4 replies; 23+ messages in thread
From: Tony Battersby @ 2023-04-25 19:26 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86
  Cc: H. Peter Anvin, Mario Limonciello, Tom Lendacky,
	linux-kernel@vger.kernel.org

In stop_this_cpu(), make sure the CPUID leaf exists before accessing the
leaf.  This fixes a lockup on poweroff 50% of the time due to the wrong
branch being taken randomly on some CPUs (seen on Supermicro X8DTH-6F
with Intel Xeon X5650).

Fixes: 08f253ec3767 ("x86/cpu: Clear SME feature flag when not in use")
Cc: <stable@vger.kernel.org> # 5.18+
Signed-off-by: Tony Battersby <tonyb@cybernetics.com>
---

NOTE: I don't have any AMD CPUs to test, so I was unable to fully test
this patch.  Could someone with an AMD CPU that supports SME please test
this and make sure it calls native_wbinvd()?


 arch/x86/kernel/process.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
index b650cde3f64d..26aa32e8f636 100644
--- a/arch/x86/kernel/process.c
+++ b/arch/x86/kernel/process.c
@@ -754,13 +754,15 @@ bool xen_set_default_idle(void)
 
 void __noreturn stop_this_cpu(void *dummy)
 {
+	struct cpuinfo_x86 *c = this_cpu_ptr(&cpu_info);
+
 	local_irq_disable();
 	/*
 	 * Remove this CPU:
 	 */
 	set_cpu_online(smp_processor_id(), false);
 	disable_local_APIC();
-	mcheck_cpu_clear(this_cpu_ptr(&cpu_info));
+	mcheck_cpu_clear(c);
 
 	/*
 	 * Use wbinvd on processors that support SME. This provides support
@@ -774,7 +776,8 @@ void __noreturn stop_this_cpu(void *dummy)
 	 * Test the CPUID bit directly because the machine might've cleared
 	 * X86_FEATURE_SME due to cmdline options.
 	 */
-	if (cpuid_eax(0x8000001f) & BIT(0))
+	if (c->extended_cpuid_level >= 0x8000001f &&
+	    (cpuid_eax(0x8000001f) & BIT(0)))
 		native_wbinvd();
 	for (;;) {
 		/*
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2023-06-20 13:02 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-25 19:26 [PATCH RFC] x86/cpu: fix intermittent lockup on poweroff Tony Battersby
2023-04-25 19:39 ` Borislav Petkov
2023-04-25 19:58   ` Tony Battersby
2023-04-25 20:03 ` Dave Hansen
2023-04-25 20:34   ` Dave Hansen
2023-04-25 21:06     ` Borislav Petkov
2023-04-25 21:05   ` Thomas Gleixner
2023-04-25 22:29     ` Dave Hansen
2023-04-25 23:00       ` Thomas Gleixner
2023-04-26  0:10       ` H. Peter Anvin
2023-04-26 14:45     ` Tony Battersby
2023-04-26 16:37       ` Thomas Gleixner
2023-04-26 17:37         ` Tony Battersby
2023-04-26 17:41           ` [PATCH v2] x86/cpu: fix SME test in stop_this_cpu() Tony Battersby
2023-05-22 14:07             ` [PATCH v2 RESEND] " Tony Battersby
2023-04-26 17:51           ` [PATCH RFC] x86/cpu: fix intermittent lockup on poweroff Tom Lendacky
2023-04-26 18:15             ` Dave Hansen
2023-04-26 19:18               ` Tom Lendacky
2023-04-26 22:02                 ` Andi Kleen
2023-04-26 23:20                   ` Thomas Gleixner
2023-04-26 20:00             ` Thomas Gleixner
2023-06-20 13:00 ` [tip: x86/core] x86/smp: Dont access non-existing CPUID leaf tip-bot2 for Tony Battersby
2023-06-20 13:00 ` [tip: x86/core] x86/smp: Make stop_other_cpus() more robust tip-bot2 for Thomas Gleixner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox