From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CE1733AC0E3 for ; Fri, 20 Mar 2026 11:54:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774007667; cv=none; b=Y6h0oq56YJPCkl5P6Yu9rNLlqDJ9rCU5qz9HMGjAqh3Ypk3VQ1hH6dVhIktY/CzbpsnBScRElI/J/pjM/jAaiXLgh+QB97QrKZzNKq/G9YON6uQtdmEAxTp661gUAiJgsqN5F+ZWlHIRq8c0fUwkoFxjkQaeE++GwH1VqwsT+sI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774007667; c=relaxed/simple; bh=Y/aaIKfTme5283X74Uxei3bvshkBl4zu7/vkryT3i+g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LMJrHJaws7rliC5ICpapMXhTC4vH6fsUjD4PlBZARWEJmBIfYE0kWKyFV9Nwv0HUaxqFW4MbX0HXOdxg3HnWzMYFvxKCeT9oPjtEIcDdHcP7shiLUdqrPgF0XwKCVAGSEfYifQyma/8d9AEVB5aBOdI8H/c6dGnp676iQNJXyZ4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=sslQZj9e; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="sslQZj9e" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 28753C2BCB0; Fri, 20 Mar 2026 11:54:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1774007667; bh=Y/aaIKfTme5283X74Uxei3bvshkBl4zu7/vkryT3i+g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sslQZj9ej6cQNWI15W++4/+uiXS2S+NfXy47JAzo96OsMnqdmSRTB8Il7J52evBYz TkF5Gpd6oHibO8b90Kl4tg5kE2SqJk+v8HSJknStFCpayr+TDhqDBX7jFmrPcF+02f Kg0T4u+ybQd8nQM4zA2aQe1x33+cF+HFj1A2VZu4yYpWwHAslJVc0z8LSXTQvwzl2o /OKDccfiYHGDq7TnR6/wTZbHVapGHg4UbnQ1G1+GrNsl4Cp2drDiSq7NJomDBkQyJ9 fZ8YasazghLE7uRGZDPrSw+e1MjeC4Fk0t0pEkL7QnyNajtaeJHO9XGkc0b8mqF5yI lurGEnCiyy93w== From: Borislav Petkov To: X86 ML Cc: Nikunj A Dadhania , LKML , "Borislav Petkov (AMD)" , Tom Lendacky , stable@kernel.org Subject: [PATCH 3/4] x86/fred: Fix early boot failures on SEV-ES/SNP guests Date: Fri, 20 Mar 2026 12:54:16 +0100 Message-ID: <20260320115417.4156-4-bp@kernel.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260320115417.4156-1-bp@kernel.org> References: <20260320115417.4156-1-bp@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Nikunj A Dadhania 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: 14619d912b65 ("x86/fred: FRED entry/exit and dispatch code") Signed-off-by: Nikunj A Dadhania Signed-off-by: Borislav Petkov (AMD) Reviewed-by: Tom Lendacky Cc: # 6.12+ Link: https://patch.msgid.link/20260318075654.1792916-4-nikunj@amd.com --- arch/x86/coco/sev/noinstr.c | 6 ++++++ arch/x86/entry/entry_fred.c | 14 ++++++++++++++ 2 files changed, 20 insertions(+) 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 88c757ac8ccd..fbe2d10dd737 100644 --- a/arch/x86/entry/entry_fred.c +++ b/arch/x86/entry/entry_fred.c @@ -177,6 +177,16 @@ static noinstr void fred_extint(struct pt_regs *regs) } } +#ifdef CONFIG_AMD_MEM_ENCRYPT +noinstr void exc_vmm_communication(struct pt_regs *regs, unsigned long error_code) +{ + if (user_mode(regs)) + return user_exc_vmm_communication(regs, error_code); + else + return kernel_exc_vmm_communication(regs, error_code); +} +#endif + static noinstr void fred_hwexc(struct pt_regs *regs, unsigned long error_code) { /* 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) #ifdef CONFIG_X86_CET case X86_TRAP_CP: return exc_control_protection(regs, error_code); #endif +#ifdef CONFIG_AMD_MEM_ENCRYPT + case X86_TRAP_VC: return exc_vmm_communication(regs, error_code); +#endif + default: return fred_bad_type(regs, error_code); } -- 2.51.0