From: Qi Wu <shijing.wuqi@linux.alibaba.com>
To: Paolo Bonzini <pbonzini@redhat.com>,
Sean Christopherson <seanjc@google.com>,
kvm@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH] KVM: irqfd: Publish the resampler after adding its first member
Date: Sun, 22 Nov 2026 17:50:10 +0800 [thread overview]
Message-ID: <20261122095010.444794-1-shijing.wuqi@linux.alibaba.com> (raw)
kvm_irqfd_assign() publishes a new resampler before adding its first
member and then calls synchronize_srcu_expedited() to drain readers that
may have seen an empty member list. This per-new-resampler grace period
runs under resampler_lock and adds to VM creation / snapshot restore
latency.
Add the first member while the resampler is private, then publish it to
both global entries. RCU list insertion guarantees any reader that finds
the resampler also sees its first member, so the empty-list state is never
visible and the first member needs no grace period; later members still
synchronize. This also prevents kvm_notify_irqfd_resampler() from finding
an empty resampler and dropping a pending interrupt on IOAPIC unmask.
synchronize_srcu() calls per path (regression check; only the first row
changes):
path before after
new resampler, first member 1 0
existing resampler, next member 1 1
non-resample irqfd assign 0 0
irqfd_shutdown (UAF fix) 1 1
deassign, non-last member 1 1
deassign, last member 1 1
Build-tested with gcc/clang and KASAN+PROVE_RCU+PROVE_LOCKING / KCSAN
(KVM subsystem and selftests compile); checkpatch --strict clean.
This patch was prepared with AI assistance; the author reviewed and owns
the change.
Signed-off-by: Qi Wu <shijing.wuqi@linux.alibaba.com>
---
virt/kvm/eventfd.c | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/virt/kvm/eventfd.c b/virt/kvm/eventfd.c
index f43b8b25bc85..74851accd881 100644
--- a/virt/kvm/eventfd.c
+++ b/virt/kvm/eventfd.c
@@ -444,14 +444,18 @@ kvm_irqfd_assign(struct kvm *kvm, struct kvm_irqfd *args)
resampler->notifier.irq_acked = irqfd_resampler_ack;
INIT_LIST_HEAD(&resampler->link);
- list_add_rcu(&resampler->link, &kvm->irqfds.resampler_list);
- kvm_register_irq_ack_notifier(kvm,
- &resampler->notifier);
irqfd->resampler = resampler;
- }
- list_add_rcu(&irqfd->resampler_link, &irqfd->resampler->list);
- synchronize_srcu_expedited(&kvm->irq_srcu);
+ /*
+ * Publish last so no reader sees an empty member list.
+ */
+ list_add_rcu(&irqfd->resampler_link, &resampler->list);
+ list_add_rcu(&resampler->link, &kvm->irqfds.resampler_list);
+ kvm_register_irq_ack_notifier(kvm, &resampler->notifier);
+ } else {
+ list_add_rcu(&irqfd->resampler_link, &irqfd->resampler->list);
+ synchronize_srcu_expedited(&kvm->irq_srcu);
+ }
mutex_unlock(&kvm->irqfds.resampler_lock);
}
--
2.47.3
reply other threads:[~2026-11-22 9:50 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261122095010.444794-1-shijing.wuqi@linux.alibaba.com \
--to=shijing.wuqi@linux.alibaba.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®