public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1 1/1] x86/fred: Fix system hang during S4 resume with FRED enabled
@ 2025-03-26  6:25 Xin Li (Intel)
  2025-03-31 12:36 ` [tip: x86/urgent] " tip-bot2 for Xin Li (Intel)
  2025-03-31 15:30 ` [PATCH v1 1/1] " Rafael J. Wysocki
  0 siblings, 2 replies; 8+ messages in thread
From: Xin Li (Intel) @ 2025-03-26  6:25 UTC (permalink / raw)
  To: linux-pm, linux-kernel, stable
  Cc: rafael, pavel, tglx, mingo, bp, dave.hansen, x86, hpa, xi.pardee,
	todd.e.brandt, xin

During an S4 resume, the system first performs a cold power-on.  The
kernel image is initially loaded to a random linear address, and the
FRED MSRs are initialized.  Subsequently, the S4 image is loaded,
and the kernel image is relocated to its original address from before
the S4 suspend.  Due to changes in the kernel text and data mappings,
the FRED MSRs must be reinitialized.

Reported-by: Xi Pardee <xi.pardee@intel.com>
Reported-and-Tested-by: Todd Brandt <todd.e.brandt@intel.com>
Suggested-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Signed-off-by: Xin Li (Intel) <xin@zytor.com>
Cc: stable@kernel.org # 6.9+
---
 arch/x86/power/cpu.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
index 63230ff8cf4f..ef3c152c319c 100644
--- a/arch/x86/power/cpu.c
+++ b/arch/x86/power/cpu.c
@@ -27,6 +27,7 @@
 #include <asm/mmu_context.h>
 #include <asm/cpu_device_id.h>
 #include <asm/microcode.h>
+#include <asm/fred.h>
 
 #ifdef CONFIG_X86_32
 __visible unsigned long saved_context_ebx;
@@ -231,6 +232,21 @@ static void notrace __restore_processor_state(struct saved_context *ctxt)
 	 */
 #ifdef CONFIG_X86_64
 	wrmsrl(MSR_GS_BASE, ctxt->kernelmode_gs_base);
+
+	/*
+	 * Restore FRED configs.
+	 *
+	 * FRED configs are completely derived from current kernel text and
+	 * data mappings, thus nothing needs to be saved and restored.
+	 *
+	 * As such, simply re-initialize FRED to restore FRED configs.
+	 *
+	 * Note, FRED RSPs setup needs to access percpu data structures.
+	 */
+	if (ctxt->cr4 & X86_CR4_FRED) {
+		cpu_init_fred_exceptions();
+		cpu_init_fred_rsps();
+	}
 #else
 	loadsegment(fs, __KERNEL_PERCPU);
 #endif
-- 
2.48.1


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

end of thread, other threads:[~2025-04-01  8:22 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-26  6:25 [PATCH v1 1/1] x86/fred: Fix system hang during S4 resume with FRED enabled Xin Li (Intel)
2025-03-31 12:36 ` [tip: x86/urgent] " tip-bot2 for Xin Li (Intel)
2025-03-31 15:30 ` [PATCH v1 1/1] " Rafael J. Wysocki
2025-03-31 16:19   ` Ingo Molnar
2025-03-31 20:03   ` H. Peter Anvin
2025-03-31 20:25     ` Rafael J. Wysocki
2025-04-01  8:22     ` Ingo Molnar
2025-04-01  6:34   ` Xin Li

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