From: Christoph Hellwig <hch@lst.de>
To: Stephen Zhang <starzhangzsd@gmail.com>
Cc: Andreas Gruenbacher <agruenba@redhat.com>,
Christoph Hellwig <hch@lst.de>,
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: Wed, 3 Dec 2025 07:14:03 +0100 [thread overview]
Message-ID: <20251203061403.GA16604@lst.de> (raw)
In-Reply-To: <CANubcdWBF5tCfrutAOiUkFaZb=9s4=bMKzi7dSwQxTGbC_3_1Q@mail.gmail.com>
On Wed, Dec 03, 2025 at 11:09:36AM +0800, Stephen Zhang wrote:
>
> I’ve been reconsidering the two approaches for the upcoming patch revision.
> Essentially, we’re comparing two methods:
> A:
> if (bio->bi_status)
> parent->bi_status = bio->bi_status;
> B:
> if (bio->bi_status)
> cmpxchg(&parent->bi_status, 0, bio->bi_status);
>
> Both appear correct, but B seems a little bit redundant here.
A is not correct. You at least needs READ_ONCE/WRITE_ONCE here.
B solves all these issues.
> Upon further reflection, I’ve noticed a subtle difference:
> A unconditionally writes to parent->bi_status when bio->bi_status is non-zero,
> regardless of the current value of parent->bi_status.
> B uses cmpxchg to only update parent->bi_status if it is still zero.
>
> Thus, B could avoid unnecessary writes in cases where parent->bi_status has
> already been set to a non-zero value.
The unnecessary writes don't really matter, we're in an error slow path
here.
prev parent reply other threads:[~2025-12-03 6:14 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
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 [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=20251203061403.GA16604@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