Skip to content

Commit fc17de9

Browse files
yamahatabonzini
authored andcommitted
KVM: TDX: Wait lapic expire when timer IRQ was injected
Call kvm_wait_lapic_expire() when POSTED_INTR_ON is set and the vector for LVTT is set in PIR before TD entry. KVM always assumes a timer IRQ was injected if APIC state is protected. For TDX guest, APIC state is protected and KVM injects timer IRQ via posted interrupt. To avoid unnecessary wait calls, only call kvm_wait_lapic_expire() when a timer IRQ was injected, i.e., POSTED_INTR_ON is set and the vector for LVTT is set in PIR. Add a helper to test PIR. Signed-off-by: Isaku Yamahata <isaku.yamahata@intel.com> Co-developed-by: Binbin Wu <binbin.wu@linux.intel.com> Signed-off-by: Binbin Wu <binbin.wu@linux.intel.com> Message-ID: <20250222014757.897978-7-binbin.wu@linux.intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent 14aecf2 commit fc17de9

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

arch/x86/include/asm/posted_intr.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ static inline bool pi_test_sn(struct pi_desc *pi_desc)
8181
return test_bit(POSTED_INTR_SN, (unsigned long *)&pi_desc->control);
8282
}
8383

84+
static inline bool pi_test_pir(int vector, struct pi_desc *pi_desc)
85+
{
86+
return test_bit(vector, (unsigned long *)pi_desc->pir);
87+
}
88+
8489
/* Non-atomic helpers */
8590
static inline void __pi_set_sn(struct pi_desc *pi_desc)
8691
{

arch/x86/kvm/vmx/tdx.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -969,9 +969,14 @@ fastpath_t tdx_vcpu_run(struct kvm_vcpu *vcpu, bool force_immediate_exit)
969969

970970
trace_kvm_entry(vcpu, force_immediate_exit);
971971

972-
if (pi_test_on(&vt->pi_desc))
972+
if (pi_test_on(&vt->pi_desc)) {
973973
apic->send_IPI_self(POSTED_INTR_VECTOR);
974974

975+
if (pi_test_pir(kvm_lapic_get_reg(vcpu->arch.apic, APIC_LVTT) &
976+
APIC_VECTOR_MASK, &vt->pi_desc))
977+
kvm_wait_lapic_expire(vcpu);
978+
}
979+
975980
tdx_vcpu_enter_exit(vcpu);
976981

977982
if (vt->host_debugctlmsr & ~TDX_DEBUGCTL_PRESERVED)

0 commit comments

Comments
 (0)