>From 12dc39eeb3d5ed1950a9bbaf4ac68c46943d0e9d Mon Sep 17 00:00:00 2001 From: Sean Christopherson Date: Thu, 1 May 2025 11:20:29 -0700 Subject: [PATCH 2/3] x86/fred: Play nice with invoking asm_fred_entry_from_kvm() on non-FRED hardware Modify asm_fred_entry_from_kvm() to allow it to be invoked by KVM even when FRED isn't fully enabled, e.g. when running with CONFIG_X86_FRED=y on non-FRED hardware. This will allow forcing KVM to always use the FRED entry points for 64-bit kernels, which in turn will eliminate a rather gross non-CFI indirect call that KVM uses to trampoline IRQs by doing IDT lookups. When FRED isn't enabled, simply skip ERETS and restore RBP and RSP from the stack frame prior to doing a "regular" RET back to KVM (in quotes because of all the RET mitigation horrors). Signed-off-by: Sean Christopherson --- arch/x86/entry/entry_64_fred.S | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/arch/x86/entry/entry_64_fred.S b/arch/x86/entry/entry_64_fred.S index 29c5c32c16c3..7aff2f0a285f 100644 --- a/arch/x86/entry/entry_64_fred.S +++ b/arch/x86/entry/entry_64_fred.S @@ -116,7 +116,8 @@ SYM_FUNC_START(asm_fred_entry_from_kvm) movq %rsp, %rdi /* %rdi -> pt_regs */ call __fred_entry_from_kvm /* Call the C entry point */ POP_REGS - ERETS + + ALTERNATIVE "", __stringify(ERETS), X86_FEATURE_FRED 1: /* * Objtool doesn't understand what ERETS does, this hint tells it that @@ -124,7 +125,7 @@ SYM_FUNC_START(asm_fred_entry_from_kvm) * isn't strictly needed, but it's the simplest form. */ UNWIND_HINT_RESTORE - pop %rbp + leave RET SYM_FUNC_END(asm_fred_entry_from_kvm) -- 2.49.0.906.g1f30a19c02-goog