public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86/fred: Fix early boot failures on SEV-ES/SNP guests
@ 2026-02-05  5:10 Nikunj A Dadhania
  2026-02-05  5:55 ` Greg KH
                   ` (6 more replies)
  0 siblings, 7 replies; 28+ messages in thread
From: Nikunj A Dadhania @ 2026-02-05  5:10 UTC (permalink / raw)
  To: linux-kernel, kvm, bp, thomas.lendacky
  Cc: tglx, mingo, dave.hansen, hpa, xin, seanjc, pbonzini, x86,
	jon.grimm, nikunj, stable

FRED enabled SEV-ES and SNP guests fail to boot due to the following
issues in the early boot sequence:

* FRED does not have a #VC exception handler in the dispatch logic

* For secondary CPUs, FRED is enabled before setting up the FRED MSRs, and
  console output triggers a #VC which cannot be handled

* Early FRED #VC exceptions should use boot_ghcb until per-CPU GHCBs are
  initialized

Fix these issues to ensure SEV-ES/SNP guests can handle #VC exceptions
correctly during early boot when FRED is enabled.

Fixes: 14619d912b65 ("x86/fred: FRED entry/exit and dispatch code")
Cc: stable@vger.kernel.org # 6.9+
Signed-off-by: Nikunj A Dadhania <nikunj@amd.com>
---

Reason to add stable tag:

With FRED support for SVM here 
https://lore.kernel.org/kvm/20260129063653.3553076-1-shivansh.dhiman@amd.com,
SVM and SEV guests running 6.9 and later kernels will support FRED.
However, *SEV-ES and SNP guests cannot support FRED* and will fail to boot
with the following error:

    [    0.005144] Using GB pages for direct mapping
    [    0.008402] Initialize FRED on CPU0
    qemu-system-x86_64: cpus are not resettable, terminating

Three problems were identified as detailed in the commit message above and
is fixed with this patch.

I would like the patch to be backported to the LTS kernels (6.12 and 6.18) to
ensure SEV-ES and SNP guests running these stable kernel versions can boot
with FRED enabled on FRED-enabled hypervisors.

---

 arch/x86/coco/sev/noinstr.c |  6 ++++++
 arch/x86/entry/entry_fred.c |  5 +++++
 arch/x86/kernel/fred.c      | 14 +++++++++++---
 3 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/arch/x86/coco/sev/noinstr.c b/arch/x86/coco/sev/noinstr.c
index 9d94aca4a698..5afd663a1c21 100644
--- a/arch/x86/coco/sev/noinstr.c
+++ b/arch/x86/coco/sev/noinstr.c
@@ -121,6 +121,9 @@ noinstr struct ghcb *__sev_get_ghcb(struct ghcb_state *state)
 
 	WARN_ON(!irqs_disabled());
 
+	if (!sev_cfg.ghcbs_initialized)
+		return boot_ghcb;
+
 	data = this_cpu_read(runtime_data);
 	ghcb = &data->ghcb_page;
 
@@ -164,6 +167,9 @@ noinstr void __sev_put_ghcb(struct ghcb_state *state)
 
 	WARN_ON(!irqs_disabled());
 
+	if (!sev_cfg.ghcbs_initialized)
+		return;
+
 	data = this_cpu_read(runtime_data);
 	ghcb = &data->ghcb_page;
 
diff --git a/arch/x86/entry/entry_fred.c b/arch/x86/entry/entry_fred.c
index a9b72997103d..7a8659f19441 100644
--- a/arch/x86/entry/entry_fred.c
+++ b/arch/x86/entry/entry_fred.c
@@ -208,6 +208,11 @@ static noinstr void fred_hwexc(struct pt_regs *regs, unsigned long error_code)
 #ifdef CONFIG_X86_CET
 	case X86_TRAP_CP: return exc_control_protection(regs, error_code);
 #endif
+	case X86_TRAP_VC:
+		if (user_mode(regs))
+			return user_exc_vmm_communication(regs, error_code);
+		else
+			return kernel_exc_vmm_communication(regs, error_code);
 	default: return fred_bad_type(regs, error_code);
 	}
 
diff --git a/arch/x86/kernel/fred.c b/arch/x86/kernel/fred.c
index e736b19e18de..8cf4da546a8e 100644
--- a/arch/x86/kernel/fred.c
+++ b/arch/x86/kernel/fred.c
@@ -27,9 +27,6 @@ EXPORT_PER_CPU_SYMBOL(fred_rsp0);
 
 void cpu_init_fred_exceptions(void)
 {
-	/* When FRED is enabled by default, remove this log message */
-	pr_info("Initialize FRED on CPU%d\n", smp_processor_id());
-
 	/*
 	 * If a kernel event is delivered before a CPU goes to user level for
 	 * the first time, its SS is NULL thus NULL is pushed into the SS field
@@ -70,6 +67,17 @@ void cpu_init_fred_exceptions(void)
 	/* Use int $0x80 for 32-bit system calls in FRED mode */
 	setup_clear_cpu_cap(X86_FEATURE_SYSFAST32);
 	setup_clear_cpu_cap(X86_FEATURE_SYSCALL32);
+
+	/*
+	 * For secondary processors, FRED bit in CR4 gets enabled in cr4_init()
+	 * and FRED MSRs are not configured till the end of this function. For
+	 * SEV-ES and SNP guests, any console write before the FRED MSRs are
+	 * setup will cause a #VC and cannot be handled. Move the pr_info to
+	 * the end of this function.
+	 *
+	 * When FRED is enabled by default, remove this log message
+	 */
+	pr_info("Initialized FRED on CPU%d\n", smp_processor_id());
 }
 
 /* Must be called after setup_cpu_entry_areas() */

base-commit: 3c2ca964f75460093a8aad6b314a6cd558e80e66
-- 
2.48.1


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

end of thread, other threads:[~2026-02-19 20:50 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-05  5:10 [PATCH] x86/fred: Fix early boot failures on SEV-ES/SNP guests Nikunj A Dadhania
2026-02-05  5:55 ` Greg KH
2026-02-05  6:10   ` Nikunj A. Dadhania
2026-02-05  6:20     ` Greg KH
2026-02-05 15:50       ` Sean Christopherson
2026-02-05 15:58         ` Dave Hansen
2026-02-05 16:00         ` Greg KH
2026-02-05  5:56 ` Greg KH
2026-02-05  6:24   ` Nikunj A. Dadhania
2026-02-05  7:11 ` Xin Li
2026-02-05  8:54   ` Nikunj A. Dadhania
2026-02-05 14:34     ` Xin Li
2026-02-05 10:41 ` kernel test robot
2026-02-06  3:31   ` Nikunj A. Dadhania
2026-02-06  9:34     ` Xin Li
2026-02-05 12:24 ` kernel test robot
2026-02-05 12:35 ` kernel test robot
2026-02-05 16:10 ` Dave Hansen
2026-02-05 17:20   ` Dave Hansen
2026-02-05 17:39     ` Tom Lendacky
2026-02-06 12:38       ` Nikunj A. Dadhania
2026-02-16  5:16         ` Nikunj A. Dadhania
2026-02-16 17:10           ` Dave Hansen
2026-02-19 19:27           ` Sohil Mehta
2026-02-19 20:22             ` Dave Hansen
2026-02-19 20:50               ` Sohil Mehta
2026-02-05 17:39     ` H. Peter Anvin
2026-02-06 12:12   ` Nikunj A. Dadhania

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