lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251208121020.1780402-6-agruenba@redhat.com>
Date: Mon,  8 Dec 2025 12:10:12 +0000
From: Andreas Gruenbacher <agruenba@...hat.com>
To: Christoph Hellwig <hch@...radead.org>,
	Jens Axboe <axboe@...nel.dk>,
	Chris Mason <clm@...com>,
	David Sterba <dsterba@...e.com>
Cc: Andreas Gruenbacher <agruenba@...hat.com>,
	linux-block@...r.kernel.org,
	linux-btrfs@...r.kernel.org,
	linux-raid@...r.kernel.org,
	dm-devel@...ts.linux.dev,
	linux-kernel@...r.kernel.org
Subject: [RFC 05/12] bio: add bio_set_status

Add a bio_set_status(bio, status) helper that sets bio->bi_status to
status if status != BLK_STS_OK.  Replace instances of this pattern in
the code with a call to the new helper.

The WRITE_ONCE() in bio_set_status() ensures that the compiler won't
reorder things in a weird way, but it isn't needed to prevent tearing
because a single-byte field like bi_status cannot tear.

Created with Coccinelle using the following semantic patch:

@@
struct bio *bio;
expression status;
@@
- if (status)
-       bio->bi_status = status;
+ bio_set_status(bio, status);

@@
struct bio *bio;
expression status;
@@
- if (unlikely(status))
-       bio->bi_status = status;
+ bio_set_status(bio, status);

Signed-off-by: Andreas Gruenbacher <agruenba@...hat.com>
---
 block/blk-mq.c      | 3 +--
 drivers/md/dm.c     | 3 +--
 include/linux/bio.h | 6 ++++++
 3 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/block/blk-mq.c b/block/blk-mq.c
index d626d32f6e57..bc837aa51daa 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -969,8 +969,7 @@ bool blk_update_request(struct request *req, blk_status_t error,
 		struct bio *bio = req->bio;
 		unsigned bio_bytes = min(bio->bi_iter.bi_size, nr_bytes);
 
-		if (unlikely(error))
-			bio->bi_status = error;
+		bio_set_status(bio, error);
 
 		if (bio_bytes == bio->bi_iter.bi_size) {
 			req->bio = bio->bi_next;
diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index 6c83ab940af7..cbc64377fa96 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -983,8 +983,7 @@ static void __dm_io_complete(struct dm_io *io, bool first_stage)
 		queue_io(md, bio);
 	} else {
 		/* done with normal IO or empty flush */
-		if (io_error)
-			bio->bi_status = io_error;
+		bio_set_status(bio, io_error);
 		bio_endio(bio);
 	}
 }
diff --git a/include/linux/bio.h b/include/linux/bio.h
index 38ebf03036cb..bf4df0b15ee1 100644
--- a/include/linux/bio.h
+++ b/include/linux/bio.h
@@ -376,6 +376,12 @@ void submit_bio(struct bio *bio);
 
 extern void bio_endio(struct bio *);
 
+static inline void bio_set_status(struct bio *bio, blk_status_t status)
+{
+	if (status)
+		WRITE_ONCE(bio->bi_status, status);
+}
+
 static inline void bio_io_error(struct bio *bio)
 {
 	bio->bi_status = BLK_STS_IOERR;
-- 
2.51.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ