* [PATCH v2 1/1] x86/fred: Fix system hang during S4 resume with FRED enabled
@ 2025-04-01 7:57 Xin Li (Intel)
2025-04-01 11:51 ` Rafael J. Wysocki
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Xin Li (Intel) @ 2025-04-01 7:57 UTC (permalink / raw)
To: linux-pm, linux-kernel, stable
Cc: rafael, pavel, tglx, mingo, bp, dave.hansen, x86, hpa, luto,
brgerst, jgross, torvalds, xi.pardee, todd.e.brandt, xin
Upon a wakeup from S4, the restore kernel starts and initializes the
FRED MSRs as needed from its perspective. It then loads a hibernation
image, including the image kernel, and attempts to load image pages
directly into their original page frames used before hibernation unless
those frames are currently in use. Once all pages are moved to their
original locations, it jumps to a "trampoline" page in the image kernel.
At this point, the image kernel takes control, but the FRED MSRs still
contain values set by the restore kernel, which may differ from those
set by the image kernel before hibernation. Therefore, the image kernel
must ensure the FRED MSRs have the same values as before hibernation.
Since these values depend only on the location of the kernel text and
data, they can be recomputed from scratch.
Reported-by: Xi Pardee <xi.pardee@intel.com>
Reported-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>
Tested-by: Todd Brandt <todd.e.brandt@intel.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: stable@vger.kernel.org # 6.9+
---
Change in v2:
* Rewrite the change log and in-code comments based on Rafael's feedback.
---
arch/x86/power/cpu.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
index 63230ff8cf4f..08e76a5ca155 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,19 @@ static void notrace __restore_processor_state(struct saved_context *ctxt)
*/
#ifdef CONFIG_X86_64
wrmsrl(MSR_GS_BASE, ctxt->kernelmode_gs_base);
+
+ /*
+ * Reinitialize FRED to ensure the FRED MSRs contain the same values
+ * as before hibernation.
+ *
+ * Note, the setup of FRED RSPs requires access to percpu data
+ * structures. Therefore, FRED reinitialization can only occur after
+ * the percpu access pointer (i.e., MSR_GS_BASE) is restored.
+ */
+ if (ctxt->cr4 & X86_CR4_FRED) {
+ cpu_init_fred_exceptions();
+ cpu_init_fred_rsps();
+ }
#else
loadsegment(fs, __KERNEL_PERCPU);
#endif
base-commit: 535bd326c5657fe570f41b1f76941e449d9e2062
--
2.49.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2 1/1] x86/fred: Fix system hang during S4 resume with FRED enabled
2025-04-01 7:57 [PATCH v2 1/1] x86/fred: Fix system hang during S4 resume with FRED enabled Xin Li (Intel)
@ 2025-04-01 11:51 ` Rafael J. Wysocki
2025-04-01 14:39 ` H. Peter Anvin
2025-04-01 20:41 ` [tip: x86/urgent] " tip-bot2 for Xin Li (Intel)
2 siblings, 0 replies; 5+ messages in thread
From: Rafael J. Wysocki @ 2025-04-01 11:51 UTC (permalink / raw)
To: Xin Li (Intel)
Cc: linux-pm, linux-kernel, stable, rafael, pavel, tglx, mingo, bp,
dave.hansen, x86, hpa, luto, brgerst, jgross, torvalds,
xi.pardee, todd.e.brandt
On Tue, Apr 1, 2025 at 9:57 AM Xin Li (Intel) <xin@zytor.com> wrote:
>
> Upon a wakeup from S4, the restore kernel starts and initializes the
> FRED MSRs as needed from its perspective. It then loads a hibernation
> image, including the image kernel, and attempts to load image pages
> directly into their original page frames used before hibernation unless
> those frames are currently in use. Once all pages are moved to their
> original locations, it jumps to a "trampoline" page in the image kernel.
>
> At this point, the image kernel takes control, but the FRED MSRs still
> contain values set by the restore kernel, which may differ from those
> set by the image kernel before hibernation. Therefore, the image kernel
> must ensure the FRED MSRs have the same values as before hibernation.
> Since these values depend only on the location of the kernel text and
> data, they can be recomputed from scratch.
>
> Reported-by: Xi Pardee <xi.pardee@intel.com>
> Reported-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>
> Tested-by: Todd Brandt <todd.e.brandt@intel.com>
> Cc: Andy Lutomirski <luto@kernel.org>
> Cc: Brian Gerst <brgerst@gmail.com>
> Cc: Juergen Gross <jgross@suse.com>
> Cc: Linus Torvalds <torvalds@linux-foundation.org>
> Cc: stable@vger.kernel.org # 6.9+
Reviewed-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> ---
>
> Change in v2:
> * Rewrite the change log and in-code comments based on Rafael's feedback.
Thanks!
> ---
> arch/x86/power/cpu.c | 14 ++++++++++++++
> 1 file changed, 14 insertions(+)
>
> diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
> index 63230ff8cf4f..08e76a5ca155 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,19 @@ static void notrace __restore_processor_state(struct saved_context *ctxt)
> */
> #ifdef CONFIG_X86_64
> wrmsrl(MSR_GS_BASE, ctxt->kernelmode_gs_base);
> +
> + /*
> + * Reinitialize FRED to ensure the FRED MSRs contain the same values
> + * as before hibernation.
> + *
> + * Note, the setup of FRED RSPs requires access to percpu data
> + * structures. Therefore, FRED reinitialization can only occur after
> + * the percpu access pointer (i.e., MSR_GS_BASE) is restored.
> + */
> + if (ctxt->cr4 & X86_CR4_FRED) {
> + cpu_init_fred_exceptions();
> + cpu_init_fred_rsps();
> + }
> #else
> loadsegment(fs, __KERNEL_PERCPU);
> #endif
>
> base-commit: 535bd326c5657fe570f41b1f76941e449d9e2062
> --
> 2.49.0
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2 1/1] x86/fred: Fix system hang during S4 resume with FRED enabled
2025-04-01 7:57 [PATCH v2 1/1] x86/fred: Fix system hang during S4 resume with FRED enabled Xin Li (Intel)
2025-04-01 11:51 ` Rafael J. Wysocki
@ 2025-04-01 14:39 ` H. Peter Anvin
2025-04-01 20:41 ` [tip: x86/urgent] " tip-bot2 for Xin Li (Intel)
2 siblings, 0 replies; 5+ messages in thread
From: H. Peter Anvin @ 2025-04-01 14:39 UTC (permalink / raw)
To: Xin Li (Intel), linux-pm, linux-kernel, stable
Cc: rafael, pavel, tglx, mingo, bp, dave.hansen, x86, luto, brgerst,
jgross, torvalds, xi.pardee, todd.e.brandt, xin
On April 1, 2025 12:57:27 AM PDT, "Xin Li (Intel)" <xin@zytor.com> wrote:
>Upon a wakeup from S4, the restore kernel starts and initializes the
>FRED MSRs as needed from its perspective. It then loads a hibernation
>image, including the image kernel, and attempts to load image pages
>directly into their original page frames used before hibernation unless
>those frames are currently in use. Once all pages are moved to their
>original locations, it jumps to a "trampoline" page in the image kernel.
>
>At this point, the image kernel takes control, but the FRED MSRs still
>contain values set by the restore kernel, which may differ from those
>set by the image kernel before hibernation. Therefore, the image kernel
>must ensure the FRED MSRs have the same values as before hibernation.
>Since these values depend only on the location of the kernel text and
>data, they can be recomputed from scratch.
>
>Reported-by: Xi Pardee <xi.pardee@intel.com>
>Reported-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>
>Tested-by: Todd Brandt <todd.e.brandt@intel.com>
>Cc: Andy Lutomirski <luto@kernel.org>
>Cc: Brian Gerst <brgerst@gmail.com>
>Cc: Juergen Gross <jgross@suse.com>
>Cc: Linus Torvalds <torvalds@linux-foundation.org>
>Cc: stable@vger.kernel.org # 6.9+
>---
>
>Change in v2:
>* Rewrite the change log and in-code comments based on Rafael's feedback.
>---
> arch/x86/power/cpu.c | 14 ++++++++++++++
> 1 file changed, 14 insertions(+)
>
>diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
>index 63230ff8cf4f..08e76a5ca155 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,19 @@ static void notrace __restore_processor_state(struct saved_context *ctxt)
> */
> #ifdef CONFIG_X86_64
> wrmsrl(MSR_GS_BASE, ctxt->kernelmode_gs_base);
>+
>+ /*
>+ * Reinitialize FRED to ensure the FRED MSRs contain the same values
>+ * as before hibernation.
>+ *
>+ * Note, the setup of FRED RSPs requires access to percpu data
>+ * structures. Therefore, FRED reinitialization can only occur after
>+ * the percpu access pointer (i.e., MSR_GS_BASE) is restored.
>+ */
>+ if (ctxt->cr4 & X86_CR4_FRED) {
>+ cpu_init_fred_exceptions();
>+ cpu_init_fred_rsps();
>+ }
> #else
> loadsegment(fs, __KERNEL_PERCPU);
> #endif
>
>base-commit: 535bd326c5657fe570f41b1f76941e449d9e2062
Reviewed-by: H. Peter Anvin (Intel) <hpa@zytor.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* [tip: x86/urgent] x86/fred: Fix system hang during S4 resume with FRED enabled
2025-04-01 7:57 [PATCH v2 1/1] x86/fred: Fix system hang during S4 resume with FRED enabled Xin Li (Intel)
2025-04-01 11:51 ` Rafael J. Wysocki
2025-04-01 14:39 ` H. Peter Anvin
@ 2025-04-01 20:41 ` tip-bot2 for Xin Li (Intel)
2 siblings, 0 replies; 5+ messages in thread
From: tip-bot2 for Xin Li (Intel) @ 2025-04-01 20:41 UTC (permalink / raw)
To: linux-tip-commits
Cc: Xi Pardee, Todd Brandt, H. Peter Anvin (Intel), Xin Li (Intel),
Ingo Molnar, Rafael J. Wysocki, Andy Lutomirski, Brian Gerst,
Juergen Gross, Linus Torvalds, x86, linux-kernel
The following commit has been merged into the x86/urgent branch of tip:
Commit-ID: e5f1e8af9c9e151ecd665f6d2e36fb25fec3b110
Gitweb: https://git.kernel.org/tip/e5f1e8af9c9e151ecd665f6d2e36fb25fec3b110
Author: Xin Li (Intel) <xin@zytor.com>
AuthorDate: Tue, 01 Apr 2025 00:57:27 -07:00
Committer: Ingo Molnar <mingo@kernel.org>
CommitterDate: Tue, 01 Apr 2025 22:29:02 +02:00
x86/fred: Fix system hang during S4 resume with FRED enabled
Upon a wakeup from S4, the restore kernel starts and initializes the
FRED MSRs as needed from its perspective. It then loads a hibernation
image, including the image kernel, and attempts to load image pages
directly into their original page frames used before hibernation unless
those frames are currently in use. Once all pages are moved to their
original locations, it jumps to a "trampoline" page in the image kernel.
At this point, the image kernel takes control, but the FRED MSRs still
contain values set by the restore kernel, which may differ from those
set by the image kernel before hibernation. Therefore, the image kernel
must ensure the FRED MSRs have the same values as before hibernation.
Since these values depend only on the location of the kernel text and
data, they can be recomputed from scratch.
Reported-by: Xi Pardee <xi.pardee@intel.com>
Reported-by: Todd Brandt <todd.e.brandt@intel.com>
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>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Reviewed-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Link: https://lore.kernel.org/r/20250401075728.3626147-1-xin@zytor.com
---
arch/x86/power/cpu.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
index 63230ff..08e76a5 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,19 @@ static void notrace __restore_processor_state(struct saved_context *ctxt)
*/
#ifdef CONFIG_X86_64
wrmsrl(MSR_GS_BASE, ctxt->kernelmode_gs_base);
+
+ /*
+ * Reinitialize FRED to ensure the FRED MSRs contain the same values
+ * as before hibernation.
+ *
+ * Note, the setup of FRED RSPs requires access to percpu data
+ * structures. Therefore, FRED reinitialization can only occur after
+ * the percpu access pointer (i.e., MSR_GS_BASE) is restored.
+ */
+ if (ctxt->cr4 & X86_CR4_FRED) {
+ cpu_init_fred_exceptions();
+ cpu_init_fred_rsps();
+ }
#else
loadsegment(fs, __KERNEL_PERCPU);
#endif
^ permalink raw reply [flat|nested] 5+ messages in thread
* [tip: x86/urgent] x86/fred: Fix system hang during S4 resume with FRED enabled
2025-03-26 6:25 [PATCH v1 1/1] " Xin Li (Intel)
@ 2025-03-31 12:36 ` tip-bot2 for Xin Li (Intel)
0 siblings, 0 replies; 5+ messages in thread
From: tip-bot2 for Xin Li (Intel) @ 2025-03-31 12:36 UTC (permalink / raw)
To: linux-tip-commits
Cc: Xi Pardee, Todd Brandt, H. Peter Anvin (Intel), Xin Li (Intel),
Ingo Molnar, Andy Lutomirski, Brian Gerst, Juergen Gross,
Linus Torvalds, x86, linux-kernel
The following commit has been merged into the x86/urgent branch of tip:
Commit-ID: b578bfe07ae943937a2945a9f6ac4b497f4d4e09
Gitweb: https://git.kernel.org/tip/b578bfe07ae943937a2945a9f6ac4b497f4d4e09
Author: Xin Li (Intel) <xin@zytor.com>
AuthorDate: Tue, 25 Mar 2025 23:25:40 -07:00
Committer: Ingo Molnar <mingo@kernel.org>
CommitterDate: Mon, 31 Mar 2025 14:19:35 +02:00
x86/fred: Fix system hang during S4 resume with FRED enabled
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 with new values.
[ mingo: Rephrased & clarified the comments. ]
Reported-by: Xi Pardee <xi.pardee@intel.com>
Reported-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>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Tested-by: Todd Brandt <todd.e.brandt@intel.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Link: https://lore.kernel.org/r/20250326062540.820556-1-xin@zytor.com
---
arch/x86/power/cpu.c | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
index 63230ff..70c8906 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,25 @@ static void notrace __restore_processor_state(struct saved_context *ctxt)
*/
#ifdef CONFIG_X86_64
wrmsrl(MSR_GS_BASE, ctxt->kernelmode_gs_base);
+
+ /*
+ * Restore FRED settings.
+ *
+ * FRED settings can be completely derived from
+ * current kernel text and data data mappings, thus
+ * nothing needs to be saved and restored.
+ *
+ * As such, simply re-initialize FRED to restore the FRED
+ * settings. Note that any changes to text and data mappings
+ * after S4 resume will generate different FRED configuration
+ * values.
+ *
+ * Also, FRED RSPs setup needs to access per-CPU data structures.
+ */
+ if (ctxt->cr4 & X86_CR4_FRED) {
+ cpu_init_fred_exceptions();
+ cpu_init_fred_rsps();
+ }
#else
loadsegment(fs, __KERNEL_PERCPU);
#endif
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-04-01 20:42 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-04-01 7:57 [PATCH v2 1/1] x86/fred: Fix system hang during S4 resume with FRED enabled Xin Li (Intel)
2025-04-01 11:51 ` Rafael J. Wysocki
2025-04-01 14:39 ` H. Peter Anvin
2025-04-01 20:41 ` [tip: x86/urgent] " tip-bot2 for Xin Li (Intel)
-- strict thread matches above, loose matches on Subject: below --
2025-03-26 6:25 [PATCH v1 1/1] " Xin Li (Intel)
2025-03-31 12:36 ` [tip: x86/urgent] " tip-bot2 for Xin Li (Intel)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®