KVM: VMX: Don't send UNBLOCK when starting device assignment without APICv
authorSean Christopherson <seanjc@google.com>
Tue, 1 Apr 2025 16:18:02 +0000 (09:18 -0700)
committerSean Christopherson <seanjc@google.com>
Thu, 24 Apr 2025 18:18:37 +0000 (11:18 -0700)
When starting device assignment, i.e. potential IRQ bypass, don't blast
KVM_REQ_UNBLOCK if APICv is disabled/unsupported.  There is no need to
wake vCPUs if they can never use VT-d posted IRQs (sending UNBLOCK guards
against races being vCPUs blocking and devices starting IRQ bypass).

Opportunistically use kvm_arch_has_irq_bypass() for all relevant checks in
the VMX Posted Interrupt code so that all checks in KVM x86 incorporate
the same information (once AMD/AVIC is given similar treatment).

Cc: Yosry Ahmed <yosry.ahmed@linux.dev>
Link: https://lore.kernel.org/r/20250401161804.842968-2-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
arch/x86/kvm/vmx/posted_intr.c

index 99d1d599ff8ce27f633fca7dc738b430a449acfb..4cf5bf5b33d71487385f0701e91581be3d871076 100644 (file)
@@ -148,9 +148,8 @@ after_clear_sn:
 
 static bool vmx_can_use_vtd_pi(struct kvm *kvm)
 {
-       return irqchip_in_kernel(kvm) && enable_apicv &&
-               kvm_arch_has_assigned_device(kvm) &&
-               irq_remapping_cap(IRQ_POSTING_CAP);
+       return irqchip_in_kernel(kvm) && kvm_arch_has_irq_bypass() &&
+              kvm_arch_has_assigned_device(kvm);
 }
 
 /*
@@ -281,7 +280,7 @@ bool pi_has_pending_interrupt(struct kvm_vcpu *vcpu)
  */
 void vmx_pi_start_assignment(struct kvm *kvm)
 {
-       if (!irq_remapping_cap(IRQ_POSTING_CAP))
+       if (!kvm_arch_has_irq_bypass())
                return;
 
        kvm_make_all_cpus_request(kvm, KVM_REQ_UNBLOCK);