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 E26BE3644D7 for ; Mon, 20 Apr 2026 16:43:56 +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=1776703437; cv=none; b=ShsWKzG1pbS5hu2uxdnjzi8LQHIyvkX692V717Gzj8ZAztYaDZbv5jvZXBbnSOq3sJnxBjgyX+T6wTAKmxB3gmHVZn3sGhsqKMaubgO/hFYF8sGEvAfzVTb5xvxvIpSyRAeUk8VjUg2N5vfFAD+YnCQE2OaLxNQbRtebmo3CfuE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776703437; c=relaxed/simple; bh=s9tdU88VhfG0dzMb3906Tya1Zl1xwsiwhRwzsd/pGn8=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=Fu39qCddToBC8mXyKUE43UQ5EGdyIqB1ZVL9PEKSjN63Zq/GaAUnpvBijrrkxs+WahEist+Ahp1jtSAGstgb+S1ENATHrQTy7DqYBrZF047AQefkK7EOeu2BrxGLRdv1TbHdcNUJJgqik25Iya8n1e/1LAvH5YDsnMJDeqHSB+Q= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=skN2q6Rd; 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="skN2q6Rd" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D80BDC19425; Mon, 20 Apr 2026 16:43:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776703436; bh=s9tdU88VhfG0dzMb3906Tya1Zl1xwsiwhRwzsd/pGn8=; h=From:To:Cc:Subject:Date:From; b=skN2q6Rd1Y3B4YVfTsmPzzna5JIP6pJT5kc1vr4pmR0GvTAsZqjUld1TEzaXWlvhW kNhqpCJWW0V2nplzvWsqSJbNWP7Rxoy/xpf+66OJXDWtsy9njLv85OJRJkEsCj7+2W N9Nt+xA/zDMamyD8JLM+GRTUSG70VHeya+1CxyoQt3Qz6K8rNLeZS4mUGtWw6A1GbX 15kkphNONZIfxXGgS8rrLsuCPGeEvinlVR81KfemDWqSJnmCLRwTkw2Ol5uzoJoIQD qHe6cWEp6ppBc5MqEfMp2KyIolgHTdTb+22NfJJODXwqbNp/uXlAix6kqs4AlI7Bhe lpJiil6O0Fbow== From: Borislav Petkov To: Tom Lendacky , Joerg Roedel , "Nikunj A. Dadhania" Cc: X86 ML , LKML , "Borislav Petkov (AMD)" Subject: [PATCH] x86/entry: Zap the #VC entry user and kernel macros Date: Mon, 20 Apr 2026 18:43:52 +0200 Message-ID: <20260420164352.32129-1-bp@kernel.org> X-Mailer: git-send-email 2.51.0 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: "Borislav Petkov (AMD)" Drop the separate kernel and user macros in favor of calling a single #VC C handler which multiplexes between the kernel and user #VC entry points by looking at CS's RPL. Zap unused DEFINE_IDTENTRY_VC while at it. There should be no functionality change resulting from this - just code simplification. Signed-off-by: Borislav Petkov (AMD) --- arch/x86/coco/sev/internal.h | 3 +++ arch/x86/coco/sev/vc-handle.c | 12 ++++++++++-- arch/x86/entry/entry_64.S | 4 ++-- arch/x86/entry/entry_fred.c | 10 ---------- arch/x86/include/asm/idtentry.h | 29 +++-------------------------- 5 files changed, 18 insertions(+), 40 deletions(-) diff --git a/arch/x86/coco/sev/internal.h b/arch/x86/coco/sev/internal.h index b1d0c66a651a..b9632c0fc391 100644 --- a/arch/x86/coco/sev/internal.h +++ b/arch/x86/coco/sev/internal.h @@ -70,6 +70,9 @@ void svsm_pval_pages(struct snp_psc_desc *desc); int svsm_perform_call_protocol(struct svsm_call *call); bool snp_svsm_vtpm_probe(void); +noinstr void kernel_exc_vmm_communication(struct pt_regs *regs, unsigned long error_code); +noinstr void user_exc_vmm_communication(struct pt_regs *regs, unsigned long error_code); + static inline u64 sev_es_rd_ghcb_msr(void) { return native_rdmsrq(MSR_AMD64_SEV_ES_GHCB); diff --git a/arch/x86/coco/sev/vc-handle.c b/arch/x86/coco/sev/vc-handle.c index d98b5c08ef00..96b62b49b2b5 100644 --- a/arch/x86/coco/sev/vc-handle.c +++ b/arch/x86/coco/sev/vc-handle.c @@ -954,7 +954,7 @@ static __always_inline bool vc_is_db(unsigned long error_code) * Runtime #VC exception handler when raised from kernel mode. Runs in NMI mode * and will panic when an error happens. */ -DEFINE_IDTENTRY_VC_KERNEL(exc_vmm_communication) +noinstr void kernel_exc_vmm_communication(struct pt_regs *regs, unsigned long error_code) { irqentry_state_t irq_state; @@ -1006,7 +1006,7 @@ DEFINE_IDTENTRY_VC_KERNEL(exc_vmm_communication) * Runtime #VC exception handler when raised from user mode. Runs in IRQ mode * and will kill the current task with SIGBUS when an error happens. */ -DEFINE_IDTENTRY_VC_USER(exc_vmm_communication) +noinstr void user_exc_vmm_communication(struct pt_regs *regs, unsigned long error_code) { /* * Handle #DB before calling into !noinstr code to avoid recursive #DB. @@ -1032,6 +1032,14 @@ DEFINE_IDTENTRY_VC_USER(exc_vmm_communication) irqentry_exit_to_user_mode(regs); } +DEFINE_IDTENTRY_RAW_ERRORCODE(exc_vmm_communication) +{ + if (user_mode(regs)) + return user_exc_vmm_communication(regs, error_code); + else + return kernel_exc_vmm_communication(regs, error_code); +} + bool __init handle_vc_boot_ghcb(struct pt_regs *regs) { unsigned long exit_code = regs->orig_ax; diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S index 42447b1e1dff..c6d996593f32 100644 --- a/arch/x86/entry/entry_64.S +++ b/arch/x86/entry/entry_64.S @@ -492,7 +492,7 @@ SYM_CODE_START(\asmsym) movq %rsp, %rdi /* pt_regs pointer */ - call kernel_\cfunc + call \cfunc /* * No need to switch back to the IST stack. The current stack is either @@ -503,7 +503,7 @@ SYM_CODE_START(\asmsym) /* Switch to the regular task stack */ .Lfrom_usermode_switch_stack_\@: - idtentry_body user_\cfunc, has_error_code=1 + idtentry_body \cfunc, has_error_code=1 _ASM_NOKPROBE(\asmsym) SYM_CODE_END(\asmsym) diff --git a/arch/x86/entry/entry_fred.c b/arch/x86/entry/entry_fred.c index fbe2d10dd737..fb3594ddf731 100644 --- a/arch/x86/entry/entry_fred.c +++ b/arch/x86/entry/entry_fred.c @@ -177,16 +177,6 @@ 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 */ diff --git a/arch/x86/include/asm/idtentry.h b/arch/x86/include/asm/idtentry.h index 42bf6a58ec36..20f548702404 100644 --- a/arch/x86/include/asm/idtentry.h +++ b/arch/x86/include/asm/idtentry.h @@ -340,17 +340,14 @@ static __always_inline void __##func(struct pt_regs *regs) __visible void noist_##func(struct pt_regs *regs) /** - * DECLARE_IDTENTRY_VC - Declare functions for the VC entry point + * DECLARE_IDTENTRY_VC - Declare a function for the VC entry point * @vector: Vector number (ignored for C) * @func: Function name of the entry point * - * Maps to DECLARE_IDTENTRY_RAW_ERRORCODE, but declares also the - * safe_stack C handler. + * Maps to DECLARE_IDTENTRY_RAW_ERRORCODE. */ #define DECLARE_IDTENTRY_VC(vector, func) \ - DECLARE_IDTENTRY_RAW_ERRORCODE(vector, func); \ - __visible noinstr void kernel_##func(struct pt_regs *regs, unsigned long error_code); \ - __visible noinstr void user_##func(struct pt_regs *regs, unsigned long error_code) + DECLARE_IDTENTRY_RAW_ERRORCODE(vector, func); /** * DEFINE_IDTENTRY_IST - Emit code for IST entry points @@ -391,26 +388,6 @@ static __always_inline void __##func(struct pt_regs *regs) #define DEFINE_IDTENTRY_DF(func) \ DEFINE_IDTENTRY_RAW_ERRORCODE(func) -/** - * DEFINE_IDTENTRY_VC_KERNEL - Emit code for VMM communication handler - * when raised from kernel mode - * @func: Function name of the entry point - * - * Maps to DEFINE_IDTENTRY_RAW_ERRORCODE - */ -#define DEFINE_IDTENTRY_VC_KERNEL(func) \ - DEFINE_IDTENTRY_RAW_ERRORCODE(kernel_##func) - -/** - * DEFINE_IDTENTRY_VC_USER - Emit code for VMM communication handler - * when raised from user mode - * @func: Function name of the entry point - * - * Maps to DEFINE_IDTENTRY_RAW_ERRORCODE - */ -#define DEFINE_IDTENTRY_VC_USER(func) \ - DEFINE_IDTENTRY_RAW_ERRORCODE(user_##func) - #else /* CONFIG_X86_64 */ /** -- 2.51.0