public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: Andreas Gruenbacher <agruenba@redhat.com>
Cc: zhangshida <starzhangzsd@gmail.com>,
	Johannes.Thumshirn@wdc.com, ming.lei@redhat.com,
	hsiangkao@linux.alibaba.com, csander@purestorage.com,
	colyli@fnnas.com, linux-block@vger.kernel.org,
	linux-bcache@vger.kernel.org, linux-kernel@vger.kernel.org,
	zhangshida@kylinos.cn
Subject: Re: [PATCH v4 3/3] block: prevent race condition on bi_status in __bio_chain_endio
Date: Tue, 2 Dec 2025 06:48:41 +0100	[thread overview]
Message-ID: <20251202054841.GC15524@lst.de> (raw)
In-Reply-To: <CAHc6FU7k7vH5bJaM6Hk6rej77t4xijBESDeThdDe1yCOqogjtA@mail.gmail.com>

On Mon, Dec 01, 2025 at 02:07:07PM +0100, Andreas Gruenbacher wrote:
> On Mon, Dec 1, 2025 at 12:25 PM Christoph Hellwig <hch@infradead.org> wrote:
> > On Mon, Dec 01, 2025 at 11:22:32AM +0100, Andreas Gruenbacher wrote:
> > > > -       if (bio->bi_status && !parent->bi_status)
> > > > -               parent->bi_status = bio->bi_status;
> > > > +       if (bio->bi_status)
> > > > +               cmpxchg(&parent->bi_status, 0, bio->bi_status);
> > >
> > > Hmm. I don't think cmpxchg() actually is of any value here: for all
> > > the chained bios, bi_status is initialized to 0, and it is only set
> > > again (to a non-0 value) when a failure occurs. When there are
> > > multiple failures, we only need to make sure that one of those
> > > failures is eventually reported, but for that, a simple assignment is
> > > enough here.
> >
> > A simple assignment doesn't guarantee atomicy.
> 
> Well, we've already discussed that bi_status is a single byte and so
> tearing won't be an issue. Otherwise, WRITE_ONCE() would still be
> enough here.

No.  At least older alpha can tear byte updates as they need a
read-modify-write cycle.  But even on normal x86 the check and the update
would be racy.  The cmpxchg makes the intentions very clear, works
everywhere and given it only happens in the error path does not create
any fast path overhead.


  reply	other threads:[~2025-12-02  5:48 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-01  9:04 [PATCH v4 0/3] Fix bio chain related issues zhangshida
2025-12-01  9:04 ` [PATCH v4 1/3] bcache: fix improper use of bi_end_io zhangshida
2025-12-01  9:04 ` [PATCH v4 2/3] block: prohibit calls to bio_chain_endio zhangshida
2025-12-01  9:34   ` Andreas Gruenbacher
2025-12-04  1:17     ` Stephen Zhang
2025-12-01  9:04 ` [PATCH v4 3/3] block: prevent race condition on bi_status in __bio_chain_endio zhangshida
2025-12-01 10:22   ` Andreas Gruenbacher
2025-12-01 11:25     ` Christoph Hellwig
2025-12-01 13:07       ` Andreas Gruenbacher
2025-12-02  5:48         ` Christoph Hellwig [this message]
2025-12-02 21:15           ` Andreas Gruenbacher
2025-12-03  1:51             ` Stephen Zhang
2025-12-03  3:09               ` Stephen Zhang
2025-12-03  4:34                 ` Caleb Sander Mateos
2025-12-03  6:14                 ` Christoph Hellwig

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=20251202054841.GC15524@lst.de \
    --to=hch@lst.de \
    --cc=Johannes.Thumshirn@wdc.com \
    --cc=agruenba@redhat.com \
    --cc=colyli@fnnas.com \
    --cc=csander@purestorage.com \
    --cc=hsiangkao@linux.alibaba.com \
    --cc=linux-bcache@vger.kernel.org \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ming.lei@redhat.com \
    --cc=starzhangzsd@gmail.com \
    --cc=zhangshida@kylinos.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