]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
KVM: SVM: WARN if ir_list is non-empty at vCPU free
authorSean Christopherson <seanjc@google.com>
Wed, 11 Jun 2025 22:45:55 +0000 (15:45 -0700)
committerSean Christopherson <seanjc@google.com>
Mon, 23 Jun 2025 16:50:46 +0000 (09:50 -0700)
Now that AVIC IRTE tracking is in a mostly sane state, WARN if a vCPU is
freed with ir_list entries, i.e. if KVM leaves a dangling IRTE.

Initialize the per-vCPU interrupt remapping list and its lock even if AVIC
is disabled so that the WARN doesn't hit false positives (and so that KVM
doesn't need to call into AVIC code for a simple sanity check).

Link: https://lore.kernel.org/r/20250611224604.313496-54-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
arch/x86/kvm/svm/avic.c
arch/x86/kvm/svm/svm.c

index eaf793a281277ccfea3b68c9c3b3a060540fed11..4b359a4a7e400cd9e95e9f53c45328096edd89c7 100644 (file)
@@ -705,6 +705,9 @@ int avic_init_vcpu(struct vcpu_svm *svm)
        int ret;
        struct kvm_vcpu *vcpu = &svm->vcpu;
 
+       INIT_LIST_HEAD(&svm->ir_list);
+       spin_lock_init(&svm->ir_list_lock);
+
        if (!enable_apicv || !irqchip_in_kernel(vcpu->kvm))
                return 0;
 
@@ -712,8 +715,6 @@ int avic_init_vcpu(struct vcpu_svm *svm)
        if (ret)
                return ret;
 
-       INIT_LIST_HEAD(&svm->ir_list);
-       spin_lock_init(&svm->ir_list_lock);
        svm->dfr_reg = APIC_DFR_FLAT;
 
        return ret;
index 68b6a19220788a64f518ca32480139e1c1a1a386..7f0df9dbc2324c353853f8e43ce5601bd67c50b3 100644 (file)
@@ -1491,6 +1491,8 @@ static void svm_vcpu_free(struct kvm_vcpu *vcpu)
 {
        struct vcpu_svm *svm = to_svm(vcpu);
 
+       WARN_ON_ONCE(!list_empty(&svm->ir_list));
+
        svm_leave_nested(vcpu);
        svm_free_nested(svm);