From: Andreas Gruenbacher <agruenba@redhat.com>
To: Christoph Hellwig <hch@infradead.org>,
Jens Axboe <axboe@kernel.dk>, Chris Mason <clm@fb.com>,
David Sterba <dsterba@suse.com>,
Satya Tangirala <satyat@google.com>
Cc: Andreas Gruenbacher <agruenba@redhat.com>,
linux-block@vger.kernel.org, linux-btrfs@vger.kernel.org,
linux-raid@vger.kernel.org, dm-devel@lists.linux.dev,
linux-kernel@vger.kernel.org
Subject: [RFC v2 00/17] bio cleanups
Date: Sun, 21 Dec 2025 03:52:15 +0100 [thread overview]
Message-ID: <20251221025233.87087-1-agruenba@redhat.com> (raw)
Hello,
we are not quite careful enough about setting bio->bi_status in all
places (see BACKGROUND below). This patch queue tries to fix this by
systematically eliminating the direct assignments to bi_status sprinkled
all throughout the code. Please comment.
The patches are currently still based on v6.18.
GIT tree:
https://git.kernel.org/pub/scm/linux/kernel/git/gfs2/linux-gfs2.git/log/?h=bio-cleanups
The first version of this patch queue is avaliable here:
https://lore.kernel.org/linux-block/20251208121020.1780402-1-agruenba@redhat.com/
With these changes, only a few direct assignments to bio->bi_status
remain, in BTRFS and in MD, and SOME OF THOSE MAY BE UNSAFE. Could the
maintainers of those subsystems please have a look?
Once the remaining direct assignments to bi_status are gone, we may want
to think about "write protecting" bi_status to prevent unintended new
direct assignments from creeping back in.
BACKGROUND
'struct bio' objects start out with their bi_status field initialized to
BLK_STS_OK (0). When the bio completes, that field needs to be left
unchanged in case of success, and set to a BLK_STS_* error code
otherwise.
This is important when bios are chained (bio_chain()) because then,
multiple execution contexts will race updating the same bi_status field.
When an execution context resets bi_status to BLK_STS_OK (0) during bio
completion, this could hide the error code of the adjacent bio in the
chain.
When more than a single bio fails in a chain, we know that the resulting
bi_status will not be BLK_STS_OK, but we don't know which of the status
error codes will survive.
CRYPTO FALLBACK (SATYA TANGIRALA?)
Related to chained bios but unrelated to setting bio->bi_status,
blk_crypto_fallback_encrypt_bio() in block/blk-crypto-fallback.c swaps
out bi_private and bi_end_io and reuses the same bio for downcalls, then
restores those fields in blk_crypto_fallback_decrypt_endio() before
calling bio_endio() again on the same bio. This will at the very least
break with chained bios because it will mess up __bi_remaining.
Thanks,
Andreas
Andreas Gruenbacher (17):
xfs: don't clobber bi_status in xfs_zone_alloc_and_submit
bio: rename bio_chain arguments
bio: use bio_io_error more often
bio: add bio_set_status
bio: use bio_set_status for BLK_STS_* status codes
bio: do not check bio->bi_status before assigning to it
block: consecutive blk_status_t error codes
block: fix blk_status_to_{errno,str} inconsistency
block: turn blk_errors array into a macro
block: optimize blk_status <=> errno conversion
bio: bio_set_status from non-zero errno
bio: do not check bio->bi_status before assigning to it (part 2)
xfs: use bio_set_status in xfs_zone_alloc_and_submit
bio: switch to bio_set_status in submit_bio_noacct
bio: never set bi_status to BLK_STS_OK during completion
bio: never set bi_status to BLK_STS_OK during completion (part 2)
bio: add bio_endio_status
block/bio-integrity-auto.c | 3 +-
block/bio.c | 25 +++----
block/blk-core.c | 123 ++++++++++++++++---------------
block/blk-crypto-fallback.c | 22 +++---
block/blk-crypto-internal.h | 2 +-
block/blk-crypto.c | 4 +-
block/blk-merge.c | 6 +-
block/blk-mq.c | 10 +--
block/fops.c | 6 +-
block/t10-pi.c | 2 +-
drivers/block/aoe/aoecmd.c | 8 +-
drivers/block/aoe/aoedev.c | 2 +-
drivers/block/drbd/drbd_int.h | 3 +-
drivers/block/drbd/drbd_req.c | 7 +-
drivers/block/ps3vram.c | 3 +-
drivers/block/zram/zram_drv.c | 4 +-
drivers/md/bcache/bcache.h | 3 +-
drivers/md/bcache/request.c | 8 +-
drivers/md/dm-cache-target.c | 9 ++-
drivers/md/dm-ebs-target.c | 2 +-
drivers/md/dm-flakey.c | 2 +-
drivers/md/dm-integrity.c | 34 ++++-----
drivers/md/dm-mpath.c | 6 +-
drivers/md/dm-pcache/dm_pcache.c | 3 +-
drivers/md/dm-raid1.c | 7 +-
drivers/md/dm-thin.c | 7 +-
drivers/md/dm-vdo/data-vio.c | 3 +-
drivers/md/dm-verity-target.c | 2 +-
drivers/md/dm-writecache.c | 7 +-
drivers/md/dm-zoned-target.c | 3 +-
drivers/md/dm.c | 4 +-
drivers/md/md.c | 8 +-
drivers/md/raid1-10.c | 3 +-
drivers/md/raid1.c | 2 +-
drivers/md/raid10.c | 20 +++--
drivers/md/raid5.c | 4 +-
drivers/nvdimm/btt.c | 4 +-
drivers/nvdimm/pmem.c | 4 +-
fs/btrfs/bio.c | 8 +-
fs/btrfs/direct-io.c | 2 +-
fs/btrfs/raid56.c | 6 +-
fs/crypto/bio.c | 2 +-
fs/erofs/fileio.c | 4 +-
fs/erofs/fscache.c | 8 +-
fs/f2fs/data.c | 6 +-
fs/f2fs/segment.c | 3 +-
fs/iomap/ioend.c | 3 +-
fs/verity/verify.c | 2 +-
fs/xfs/xfs_aops.c | 3 +-
fs/xfs/xfs_zone_alloc.c | 4 +-
include/linux/bio.h | 28 ++++++-
include/linux/blk_types.h | 2 +-
include/linux/blkdev.h | 18 ++++-
53 files changed, 236 insertions(+), 238 deletions(-)
--
2.52.0
next reply other threads:[~2025-12-21 2:52 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-21 2:52 Andreas Gruenbacher [this message]
2025-12-21 2:52 ` [RFC v2 01/17] xfs: don't clobber bi_status in xfs_zone_alloc_and_submit Andreas Gruenbacher
2025-12-21 15:39 ` Andreas Gruenbacher
2025-12-21 2:52 ` [RFC v2 02/17] bio: rename bio_chain arguments Andreas Gruenbacher
2025-12-21 2:52 ` [RFC v2 03/17] bio: use bio_io_error more often Andreas Gruenbacher
2025-12-21 2:52 ` [RFC v2 04/17] bio: add bio_set_status Andreas Gruenbacher
2025-12-21 2:52 ` [RFC v2 05/17] bio: use bio_set_status for BLK_STS_* status codes Andreas Gruenbacher
2025-12-21 2:52 ` [RFC v2 06/17] bio: do not check bio->bi_status before assigning to it Andreas Gruenbacher
2025-12-21 2:52 ` [RFC v2 07/17] block: consecutive blk_status_t error codes Andreas Gruenbacher
2025-12-21 2:52 ` [RFC v2 08/17] block: fix blk_status_to_{errno,str} inconsistency Andreas Gruenbacher
2025-12-21 2:52 ` [RFC v2 09/17] block: turn blk_errors array into a macro Andreas Gruenbacher
2025-12-21 2:52 ` [RFC v2 10/17] block: optimize blk_status <=> errno conversion Andreas Gruenbacher
2025-12-21 2:52 ` [RFC v2 11/17] bio: bio_set_status from non-zero errno Andreas Gruenbacher
2025-12-21 2:52 ` [RFC v2 12/17] bio: do not check bio->bi_status before assigning to it (part 2) Andreas Gruenbacher
2025-12-21 2:52 ` [RFC v2 13/17] xfs: use bio_set_status in xfs_zone_alloc_and_submit Andreas Gruenbacher
2025-12-21 2:52 ` [RFC v2 14/17] bio: switch to bio_set_status in submit_bio_noacct Andreas Gruenbacher
2025-12-21 2:52 ` [RFC v2 15/17] bio: never set bi_status to BLK_STS_OK during completion Andreas Gruenbacher
2025-12-21 2:52 ` [RFC v2 16/17] bio: never set bi_status to BLK_STS_OK during completion (part 2) Andreas Gruenbacher
2025-12-21 2:52 ` [RFC v2 17/17] bio: add bio_endio_status Andreas Gruenbacher
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=20251221025233.87087-1-agruenba@redhat.com \
--to=agruenba@redhat.com \
--cc=axboe@kernel.dk \
--cc=clm@fb.com \
--cc=dm-devel@lists.linux.dev \
--cc=dsterba@suse.com \
--cc=hch@infradead.org \
--cc=linux-block@vger.kernel.org \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-raid@vger.kernel.org \
--cc=satyat@google.com \
/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®