From: Jason Gunthorpe <jgg@ziepe.ca>
To: Michael Gur <michaelgur@nvidia.com>
Cc: wujing <realwujing@qq.com>,
leon@kernel.org, linux-kernel@vger.kernel.org,
linux-rdma@vger.kernel.org, yuanql9@chinatelecom.cn
Subject: Re: [PATCH] IB/core: Fix ABBA deadlock in rdma_dev_exit_net
Date: Tue, 16 Dec 2025 10:22:36 -0400 [thread overview]
Message-ID: <20251216142236.GD31492@ziepe.ca> (raw)
In-Reply-To: <a51bcd2d-d1c6-4516-90c1-f6c50ce01f9f@nvidia.com>
On Tue, Dec 16, 2025 at 03:59:32PM +0200, Michael Gur wrote:
>
> On 12/16/2025 11:59 AM, wujing wrote:
> > Hi Jason,
> >
> > You're right that the locks aren't nested in rdma_dev_exit_net() - it does release
> > rdma_nets_rwsem before acquiring devices_rwsem. However, this is still an ABBA deadlock,
> > just not the trivial nested kind. The issue is caused by **rwsem writer priority**
> > and lock ordering inconsistency.
> >
> > Here's the actual deadlock scenario:
> >
> > **Thread A (rdma_dev_exit_net - cleanup_net workqueue):**
> > ```
> > down_write(&rdma_nets_rwsem); // Acquired
> > xa_store(&rdma_nets, ...);
> > up_write(&rdma_nets_rwsem); // Released
> > down_read(&devices_rwsem); // Waiting here <-- BLOCKED
> > ```
> >
> > **Thread B (rdma_dev_init_net - stress-ng-clone):**
> > ```
> > down_read(&devices_rwsem); // Acquired
> > down_read(&rdma_nets_rwsem); // Waiting here <-- BLOCKED
> > ```
> >
> > The deadlock happens because:
> >
> > 1. Thread A releases rdma_nets_rwsem as a **writer**
> > 2. Thread B (and many others) are waiting to acquire rdma_nets_rwsem as **readers**
> > 3. Thread A then tries to acquire devices_rwsem as a reader
> > 4. BUT: rwsem gives priority to pending writers over new readers
> > 5. Since Thread A was a pending writer on rdma_nets_rwsem, Thread B's read request is blocked
> > 6. Thread B holds devices_rwsem, which Thread A needs
> > 7. Thread A holds the "writer priority slot" on rdma_nets_rwsem, which Thread B needs
> >
> Why would Thread A still hold any writer priority after calling up_write()?
I've never heard of a 'writer priority slot' in linux, a thread does
not block other users of a lock after it has released the lock.
The rwsem priority is done by biasing the atomic counter, not with
some kind of weird per-thread slots.
Jason
prev parent reply other threads:[~2025-12-16 14:22 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-11 8:08 [PATCH] IB/core: Fix ABBA deadlock in rdma_dev_exit_net wujing
2025-12-16 0:57 ` Jason Gunthorpe
2025-12-16 9:59 ` wujing
2025-12-16 13:59 ` Michael Gur
2025-12-16 14:22 ` Jason Gunthorpe [this message]
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=20251216142236.GD31492@ziepe.ca \
--to=jgg@ziepe.ca \
--cc=leon@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=michaelgur@nvidia.com \
--cc=realwujing@qq.com \
--cc=yuanql9@chinatelecom.cn \
/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;
as well as URLs for NNTP newsgroup(s).