From: "Paul E. McKenney" <paulmck@kernel.org>
To: Sean Christopherson <seanjc@google.com>
Cc: Sonam Sanju <sonam.sanju@intel.com>,
Lai Jiangshan <jiangshanlai@gmail.com>,
Josh Triplett <josh@joshtriplett.org>,
Paolo Bonzini <pbonzini@redhat.com>,
Vineeth Pillai <vineeth@bitbyteword.org>,
Dmitry Maluka <dmaluka@chromium.org>,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org, Steven Rostedt <rostedt@goodmis.org>,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
rcu@vger.kernel.org
Subject: Re: [PATCH v2] KVM: irqfd: fix deadlock by moving synchronize_srcu out of resampler_lock
Date: Tue, 31 Mar 2026 13:51:11 -0700 [thread overview]
Message-ID: <2d080c02-9602-4b22-94ce-1f7a71cc19a4@paulmck-laptop> (raw)
In-Reply-To: <acwPr_Aic9xd95_R@google.com>
On Tue, Mar 31, 2026 at 11:17:19AM -0700, Sean Christopherson wrote:
> +srcu folks
>
> Please don't post subsequent versions In-Reply-To previous versions, it tends to
> muck up tooling.
>
> On Mon, Mar 23, 2026, Sonam Sanju wrote:
> > irqfd_resampler_shutdown() and kvm_irqfd_assign() both call
> > synchronize_srcu_expedited() while holding kvm->irqfds.resampler_lock.
> > This can deadlock when multiple irqfd workers run concurrently on the
> > kvm-irqfd-cleanup workqueue during VM teardown or when VMs are rapidly
> > created and destroyed:
> >
> > CPU A (mutex holder) CPU B/C/D (mutex waiters)
> > irqfd_shutdown() irqfd_shutdown() / kvm_irqfd_assign()
> > irqfd_resampler_shutdown() irqfd_resampler_shutdown()
> > mutex_lock(resampler_lock) <---- mutex_lock(resampler_lock) //BLOCKED
> > list_del_rcu(...) ...blocked...
> > synchronize_srcu_expedited() // Waiters block workqueue,
> > // waits for SRCU grace preventing SRCU grace
> > // period which requires period from completing
> > // workqueue progress --- DEADLOCK ---
> >
> > In irqfd_resampler_shutdown(), the synchronize_srcu_expedited() in
> > the else branch is called directly within the mutex. In the if-last
> > branch, kvm_unregister_irq_ack_notifier() also calls
> > synchronize_srcu_expedited() internally. In kvm_irqfd_assign(),
> > synchronize_srcu_expedited() is called after list_add_rcu() but
> > before mutex_unlock(). All paths can block indefinitely because:
> >
> > 1. synchronize_srcu_expedited() waits for an SRCU grace period
> > 2. SRCU grace period completion needs workqueue workers to run
> > 3. The blocked mutex waiters occupy workqueue slots preventing progress
>
> Unless I'm misunderstanding the bug, "fixing" in this in KVM is papering over an
> underlying flaw. Essentially, this would be establishing a rule that
> synchronize_srcu_expedited() can *never* be called while holding a mutex. That's
> not viable.
First, it is OK to invoke synchronize_srcu_expedited() while holding
a mutex. Second, the synchronize_srcu_expedited() function's use of
workqueues is the same as that of synchronize_srcu(), so in an alternate
universe where it was not OK to invoke synchronize_srcu_expedited() while
holding a mutex, it would also not be OK to invoke synchronize_srcu()
while holding that same mutex. Third, it is also OK to acquire that
same mutex within a workqueue handler. Fourth, SRCU and RCU use their
own workqueue, which no one else should be using (and that prohibition
most definitely includes the irqfd workers).
As a result, I do have to ask... When you say "multiple irqfd workers",
exactly how many such workers are you running?
Thanx, Paul
> > 4. The mutex holder never releases the lock -> deadlock
next prev parent reply other threads:[~2026-03-31 20:51 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-16 7:20 [PATCH] KVM: irqfd: fix shutdown deadlock by moving SRCU sync outside resampler_lock Sonam Sanju
2026-03-17 16:27 ` Sonam Sanju
2026-03-20 12:56 ` Vineeth Pillai (Google)
2026-03-23 5:33 ` Sonam Sanju
2026-03-23 6:42 ` [PATCH v2] KVM: irqfd: fix deadlock by moving synchronize_srcu out of resampler_lock Sonam Sanju
2026-03-31 18:17 ` Sean Christopherson
2026-03-31 20:51 ` Paul E. McKenney [this message]
2026-04-01 9:47 ` Sonam Sanju
2026-04-06 23:09 ` Paul E. McKenney
2026-04-01 9:34 ` Kunwu Chan
2026-04-01 14:24 ` Sonam Sanju
2026-04-06 14:20 ` Kunwu Chan
2026-04-17 1:18 ` Vineeth Pillai
2026-04-19 3:03 ` Vineeth Remanan Pillai
2026-04-21 16:54 ` [PATCH v2] KVM: eventfd: Use WQ_UNBOUND workqueue for irqfd cleanup - New logs confirm preemption race Sonam Sanju
2026-04-21 18:22 ` Tejun Heo
2026-04-23 9:01 ` [PATCH v2] KVM: irqfd: fix deadlock by moving synchronize_srcu out of resampler_lock Sonam Sanju
2026-04-23 13:25 ` Vineeth Remanan Pillai
2026-04-21 5:12 ` Sonam Sanju
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=2d080c02-9602-4b22-94ce-1f7a71cc19a4@paulmck-laptop \
--to=paulmck@kernel.org \
--cc=dmaluka@chromium.org \
--cc=jiangshanlai@gmail.com \
--cc=josh@joshtriplett.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=pbonzini@redhat.com \
--cc=rcu@vger.kernel.org \
--cc=rostedt@goodmis.org \
--cc=seanjc@google.com \
--cc=sonam.sanju@intel.com \
--cc=stable@vger.kernel.org \
--cc=vineeth@bitbyteword.org \
/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®