[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250522235223.3178519-3-seanjc@google.com>
Date: Thu, 22 May 2025 16:52:12 -0700
From: Sean Christopherson <seanjc@...gle.com>
To: "K. Y. Srinivasan" <kys@...rosoft.com>, Haiyang Zhang <haiyangz@...rosoft.com>,
Wei Liu <wei.liu@...nel.org>, Dexuan Cui <decui@...rosoft.com>,
Juergen Gross <jgross@...e.com>, Stefano Stabellini <sstabellini@...nel.org>,
Paolo Bonzini <pbonzini@...hat.com>, Ingo Molnar <mingo@...hat.com>,
Peter Zijlstra <peterz@...radead.org>, Juri Lelli <juri.lelli@...hat.com>,
Vincent Guittot <vincent.guittot@...aro.org>, Shuah Khan <shuah@...nel.org>,
Marc Zyngier <maz@...nel.org>, Oliver Upton <oliver.upton@...ux.dev>,
Sean Christopherson <seanjc@...gle.com>
Cc: linux-kernel@...r.kernel.org, linux-hyperv@...r.kernel.org,
xen-devel@...ts.xenproject.org, kvm@...r.kernel.org,
linux-kselftest@...r.kernel.org, linux-arm-kernel@...ts.infradead.org,
kvmarm@...ts.linux.dev, K Prateek Nayak <kprateek.nayak@....com>,
David Matlack <dmatlack@...gle.com>
Subject: [PATCH v3 02/13] KVM: Acquire SCRU lock outside of irqfds.lock during assignment
Acquire SRCU outside of irqfds.lock so that the locking is symmetrical,
and add a comment explaining why on earth KVM holds SRCU for so long.
Signed-off-by: Sean Christopherson <seanjc@...gle.com>
---
virt/kvm/eventfd.c | 19 ++++++++++++++++---
1 file changed, 16 insertions(+), 3 deletions(-)
diff --git a/virt/kvm/eventfd.c b/virt/kvm/eventfd.c
index 39e42b19d9f7..42c02c35e542 100644
--- a/virt/kvm/eventfd.c
+++ b/virt/kvm/eventfd.c
@@ -401,6 +401,18 @@ kvm_irqfd_assign(struct kvm *kvm, struct kvm_irqfd *args)
*/
init_waitqueue_func_entry(&irqfd->wait, irqfd_wakeup);
+ /*
+ * Set the irqfd routing and add it to KVM's list before registering
+ * the irqfd with the eventfd, so that the routing information is valid
+ * and stays valid, e.g. if there are GSI routing changes, prior to
+ * making the irqfd visible, i.e. before it might be signaled.
+ *
+ * Note, holding SRCU ensures a stable read of routing information, and
+ * also prevents irqfd_shutdown() from freeing the irqfd before it's
+ * fully initialized.
+ */
+ idx = srcu_read_lock(&kvm->irq_srcu);
+
spin_lock_irq(&kvm->irqfds.lock);
ret = 0;
@@ -409,11 +421,9 @@ kvm_irqfd_assign(struct kvm *kvm, struct kvm_irqfd *args)
continue;
/* This fd is used for another irq already. */
ret = -EBUSY;
- spin_unlock_irq(&kvm->irqfds.lock);
- goto fail;
+ goto fail_duplicate;
}
- idx = srcu_read_lock(&kvm->irq_srcu);
irqfd_update(kvm, irqfd);
list_add_tail(&irqfd->list, &kvm->irqfds.items);
@@ -449,6 +459,9 @@ kvm_irqfd_assign(struct kvm *kvm, struct kvm_irqfd *args)
srcu_read_unlock(&kvm->irq_srcu, idx);
return 0;
+fail_duplicate:
+ spin_unlock_irq(&kvm->irqfds.lock);
+ srcu_read_unlock(&kvm->irq_srcu, idx);
fail:
if (irqfd->resampler)
irqfd_resampler_shutdown(irqfd);
--
2.49.0.1151.ga128411c76-goog
Powered by blists - more mailing lists