From: Christoph Hellwig <hch@lst.de>
To: Dave Chinner <dgc@kernel.org>
Cc: Christoph Hellwig <hch@lst.de>, Carlos Maiolino <cem@kernel.org>,
Andrey Albershteyn <aalbersh@redhat.com>,
linux-xfs@vger.kernel.org
Subject: Re: [PATCH] xfs: fix a buffer lookup against removal race
Date: Mon, 18 May 2026 07:44:37 +0200 [thread overview]
Message-ID: <20260518054437.GA10057@lst.de> (raw)
In-Reply-To: <ageXNcsKQinCWyV1@dread>
On Sat, May 16, 2026 at 07:59:17AM +1000, Dave Chinner wrote:
> > + if (bp) {
> > + /*
> > + * If there is an existing buffer with a dead lockref, retry
> > + * until the new buffer is added or usable buffer is found.
> > + */
> > + if (!lockref_get_not_dead(&bp->b_lockref)) {
> > + rcu_read_unlock();
> > + goto retry;
> > + }
>
> Like the inode cache, there probably should be a delay here rather
> than spinning hard. There is no guarantee that the object actually
> appears removed from the cache until the RCU grace period expires,
> though typically races that find objects being removed are much
> shorter duration than that.
I don't think in the current version we need it because it is
basically imposisble to hit. But with your comment below fixed
we do need it, so I'll add it.
> Also, is it safe to run lockref_get_not_dead() whilst some other
> thread is racing to get lockref.lock and calls lockref_mark_dead()
> on it?
Yes, it is specifically designed for that: the lockref idea is that you
can do fast path increment/decrements using atomics that are serialized
as if you'd always take the lock around manual opeations on the count
field. The ability to mark it dead under the lock and synchronize
against atomic increments one of the most important aspects of that.
> That'll cause issues. RCU algorithms require the object to be marked
> dead before it is removed from the index so that RCU lookup races
> that find it after removal (i.e. during the RCU grace period) see
> the object as dead, not as a valid buffer (think RT preemption
> between remove and mark dead).
Yes, this should be switched around. And with that the retry loop
above becomes more likely and needs the cpu_relax().
I wrote a version doing this and ran it through test over the weekend,
which I'll post soon.
next prev parent reply other threads:[~2026-05-18 5:44 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-15 13:31 fix a buffer lookup against removal race Christoph Hellwig
2026-05-15 13:31 ` [PATCH] xfs: " Christoph Hellwig
2026-05-15 15:34 ` Carlos Maiolino
2026-05-15 21:59 ` Dave Chinner
2026-05-18 5:44 ` Christoph Hellwig [this message]
2026-05-16 12:55 ` Andrey Albershteyn
-- strict thread matches above, loose matches on Subject: below --
2026-05-18 6:02 fix a buffer lookup against removal race v2 Christoph Hellwig
2026-05-18 6:02 ` [PATCH] xfs: fix a buffer lookup against removal race Christoph Hellwig
2026-05-20 9:11 ` Carlos Maiolino
2026-05-21 11:38 ` Andrey Albershteyn
2026-05-26 9:56 ` Carlos Maiolino
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=20260518054437.GA10057@lst.de \
--to=hch@lst.de \
--cc=aalbersh@redhat.com \
--cc=cem@kernel.org \
--cc=dgc@kernel.org \
--cc=linux-xfs@vger.kernel.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