]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
x86/entry: Zap the #VC entry user and kernel macros
authorBorislav Petkov (AMD) <bp@alien8.de>
Mon, 20 Apr 2026 16:43:52 +0000 (18:43 +0200)
committerBorislav Petkov (AMD) <bp@alien8.de>
Mon, 4 May 2026 09:18:41 +0000 (11:18 +0200)
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) <bp@alien8.de>
Reviewed-by: Nikunj A. Dadhania <nikunj@amd.com>
Reviewed-by: Tom Lendacky <thomas.lendacky@amd.com>
Acked-by: Joerg Roedel <joerg.roedel@amd.com>
Tested-by: Nikunj A. Dadhania <nikunj@amd.com>
Link: https://patch.msgid.link/20260420164352.32129-1-bp@kernel.org
arch/x86/coco/sev/internal.h
arch/x86/coco/sev/vc-handle.c
arch/x86/entry/entry_64.S
arch/x86/entry/entry_fred.c
arch/x86/include/asm/idtentry.h

index b1d0c66a651a607b31f01ba56855e0f77e1dce08..b9632c0fc3916bd4808a4ef22c3191d218bc2d9e 100644 (file)
@@ -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);
index d98b5c08ef00d8a091d30dc78ab3103f7835d631..96b62b49b2b53deaf9fc63cca9b4136415e9afd0 100644 (file)
@@ -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;
index 42447b1e1dffa47eb9ce45edd90f471485de24f4..c6d996593f3297b05a4ca40f0fd91511cbf7589e 100644 (file)
@@ -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)
index fbe2d10dd737daef6603873150024407753e2d5b..fb3594ddf731f5e5a0e4a1f27ac8c1e0ce8a369e 100644 (file)
@@ -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 */
index 42bf6a58ec3688116a9b9fd2cc5bedcc8551fd0e..20f5487024042a63c76829dea058f2228a3fb07d 100644 (file)
@@ -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 */
 
 /**