Skip to content

Commit 3645eb7

Browse files
nikunjadbp3tk0v
authored andcommitted
x86/fred: Fix early boot failures on SEV-ES/SNP guests
FRED-enabled SEV-(ES,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 * Early FRED #VC exceptions attempt to use uninitialized per-CPU GHCBs instead of boot_ghcb Add X86_TRAP_VC case to fred_hwexc() with a new exc_vmm_communication() function that provides the unified entry point FRED requires, dispatching to existing user/kernel handlers based on privilege level. The function is already declared via DECLARE_IDTENTRY_VC(). Fix early GHCB access by falling back to boot_ghcb in __sev_{get,put}_ghcb() when per-CPU GHCBs are not yet initialized. Fixes: 14619d9 ("x86/fred: FRED entry/exit and dispatch code") Signed-off-by: Nikunj A Dadhania <nikunj@amd.com> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Reviewed-by: Tom Lendacky <thomas.lendacky@amd.com> Cc: <stable@kernel.org> # 6.12+ Link: https://patch.msgid.link/20260318075654.1792916-4-nikunj@amd.com
1 parent 411df12 commit 3645eb7

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

arch/x86/coco/sev/noinstr.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ noinstr struct ghcb *__sev_get_ghcb(struct ghcb_state *state)
121121

122122
WARN_ON(!irqs_disabled());
123123

124+
if (!sev_cfg.ghcbs_initialized)
125+
return boot_ghcb;
126+
124127
data = this_cpu_read(runtime_data);
125128
ghcb = &data->ghcb_page;
126129

@@ -164,6 +167,9 @@ noinstr void __sev_put_ghcb(struct ghcb_state *state)
164167

165168
WARN_ON(!irqs_disabled());
166169

170+
if (!sev_cfg.ghcbs_initialized)
171+
return;
172+
167173
data = this_cpu_read(runtime_data);
168174
ghcb = &data->ghcb_page;
169175

arch/x86/entry/entry_fred.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,16 @@ static noinstr void fred_extint(struct pt_regs *regs)
177177
}
178178
}
179179

180+
#ifdef CONFIG_AMD_MEM_ENCRYPT
181+
noinstr void exc_vmm_communication(struct pt_regs *regs, unsigned long error_code)
182+
{
183+
if (user_mode(regs))
184+
return user_exc_vmm_communication(regs, error_code);
185+
else
186+
return kernel_exc_vmm_communication(regs, error_code);
187+
}
188+
#endif
189+
180190
static noinstr void fred_hwexc(struct pt_regs *regs, unsigned long error_code)
181191
{
182192
/* Optimize for #PF. That's the only exception which matters performance wise */
@@ -207,6 +217,10 @@ static noinstr void fred_hwexc(struct pt_regs *regs, unsigned long error_code)
207217
#ifdef CONFIG_X86_CET
208218
case X86_TRAP_CP: return exc_control_protection(regs, error_code);
209219
#endif
220+
#ifdef CONFIG_AMD_MEM_ENCRYPT
221+
case X86_TRAP_VC: return exc_vmm_communication(regs, error_code);
222+
#endif
223+
210224
default: return fred_bad_type(regs, error_code);
211225
}
212226

0 commit comments

Comments
 (0)