Skip to content

Commit 28d11e4

Browse files
sean-jcPeter Zijlstra
authored andcommitted
x86/fred: KVM: VMX: Always use FRED for IRQs when CONFIG_X86_FRED=y
Now that FRED provides C-code entry points for handling IRQs, use the FRED infrastructure for forwarding IRQs even if FRED is fully disabled, e.g. isn't supported in hardware. Avoiding the non-FRED assembly trampolines into the IDT handlers for IRQs eliminates the associated non-CFI indirect call (KVM performs a CALL by doing a lookup on the IDT using the IRQ vector). Keep NMIs on the legacy IDT path, as the FRED NMI entry code relies on FRED's architectural behavior with respect to NMI blocking, i.e. doesn't jump through the myriad hoops needed to deal with IRET "unexpectedly" unmasking NMIs. KVM's NMI path already makes a direct CALL to C-code, i.e. isn't problematic for CFI. KVM does make a short detour through assembly code to build the stack frame, but the "FRED entry from KVM" path does the same. Force FRED for 64-bit kernels if KVM_INTEL is enabled, as the benefits of eliminating the IRQ trampoline usage far outwieghts the code overhead for FRED. Suggested-by: Peter Zijlstra <[email protected]> Signed-off-by: Sean Christopherson <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent deed19b commit 28d11e4

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

arch/x86/kvm/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ config KVM_INTEL
9797
depends on KVM && IA32_FEAT_CTL
9898
select KVM_GENERIC_PRIVATE_MEM if INTEL_TDX_HOST
9999
select KVM_GENERIC_MEMORY_ATTRIBUTES if INTEL_TDX_HOST
100+
select X86_FRED if X86_64
100101
help
101102
Provides support for KVM on processors equipped with Intel's VT
102103
extensions, a.k.a. Virtual Machine Extensions (VMX).

arch/x86/kvm/vmx/vmx.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6913,8 +6913,14 @@ static void handle_external_interrupt_irqoff(struct kvm_vcpu *vcpu,
69136913
"unexpected VM-Exit interrupt info: 0x%x", intr_info))
69146914
return;
69156915

6916+
/*
6917+
* Invoke the kernel's IRQ handler for the vector. Use the FRED path
6918+
* when it's available even if FRED isn't fully enabled, e.g. even if
6919+
* FRED isn't supported in hardware, in order to avoid the indirect
6920+
* CALL in the non-FRED path.
6921+
*/
69166922
kvm_before_interrupt(vcpu, KVM_HANDLING_IRQ);
6917-
if (cpu_feature_enabled(X86_FEATURE_FRED))
6923+
if (IS_ENABLED(CONFIG_X86_FRED))
69186924
fred_entry_from_kvm(EVENT_TYPE_EXTINT, vector);
69196925
else
69206926
vmx_do_interrupt_irqoff(gate_offset((gate_desc *)host_idt_base + vector));

0 commit comments

Comments
 (0)