@@ -5334,3 +5334,11 @@ bool sev_savic_has_pending_interrupt(struct kvm_vcpu *vcpu)
return READ_ONCE(to_svm(vcpu)->sev_savic_has_pending_ipi) ||
kvm_apic_has_interrupt(vcpu) != -1;
}
+
+bool sev_savic_timer_int_injected(struct kvm_vcpu *vcpu)
+{
+ u32 reg = kvm_lapic_get_reg(vcpu->arch.apic, APIC_LVTT);
+ int vec = reg & APIC_VECTOR_MASK;
+
+ return to_svm(vcpu)->vmcb->control.requested_irr[vec / 32] & BIT(vec % 32);
+}
@@ -4292,7 +4292,8 @@ static __no_kcsan fastpath_t svm_vcpu_run(struct kvm_vcpu *vcpu,
clgi();
kvm_load_guest_xsave_state(vcpu);
- kvm_wait_lapic_expire(vcpu);
+ if (!sev_savic_active(vcpu->kvm) || sev_savic_timer_int_injected(vcpu))
+ kvm_wait_lapic_expire(vcpu);
/*
* If this vCPU has touched SPEC_CTRL, restore the guest's value if
@@ -765,6 +765,7 @@ static inline bool sev_savic_active(struct kvm *kvm)
}
void sev_savic_set_requested_irr(struct vcpu_svm *svm, bool reinjected);
bool sev_savic_has_pending_interrupt(struct kvm_vcpu *vcpu);
+bool sev_savic_timer_int_injected(struct kvm_vcpu *vcpu);
#else
static inline struct page *snp_safe_alloc_page_node(int node, gfp_t gfp)
{
@@ -798,6 +799,7 @@ static inline int sev_private_max_mapping_level(struct kvm *kvm, kvm_pfn_t pfn)
static inline bool sev_savic_active(struct kvm *kvm) { return false; }
static inline void sev_savic_set_requested_irr(struct vcpu_svm *svm, bool reinjected) {}
static inline bool sev_savic_has_pending_interrupt(struct kvm_vcpu *vcpu) { return false; }
+static inline bool sev_savic_timer_int_injected(struct kvm_vcpu *vcpu) { return true; }
#endif
/* vmenter.S */
For Secure AVIC guests, call kvm_wait_lapic_expire() only when the vector for LVTT is set in requested_IRR. KVM always assumes a timer IRQ was injected if APIC state is protected. For Secure AVIC guests, check to-be-injected vectors in the requested_IRR to avoid unnecessary wait calls. Signed-off-by: Neeraj Upadhyay <Neeraj.Upadhyay@amd.com> --- arch/x86/kvm/svm/sev.c | 8 ++++++++ arch/x86/kvm/svm/svm.c | 3 ++- arch/x86/kvm/svm/svm.h | 2 ++ 3 files changed, 12 insertions(+), 1 deletion(-)