virtualization.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 0/9] Fix bio chain related issues
@ 2025-11-29  9:01 zhangshida
  2025-11-29  9:01 ` [PATCH v3 1/9] md: bcache: fix improper use of bi_end_io zhangshida
                   ` (8 more replies)
  0 siblings, 9 replies; 17+ messages in thread
From: zhangshida @ 2025-11-29  9:01 UTC (permalink / raw)
  To: Johannes.Thumshirn, hch, agruenba, ming.lei, hsiangkao, csander
  Cc: linux-block, linux-bcache, nvdimm, virtualization, ntfs3,
	linux-xfs, linux-kernel, zhangshida, starzhangzsd

From: Shida Zhang <zhangshida@kylinos.cn>

Hi all,

While investigating another problem [mentioned in v1], we identified
some buggy code in the bio chain handling logic. This series addresses
those issues and performs related code cleanup.

Patches 1-3 fix incorrect usage of bio_chain_endio().
Patches 4-9 clean up repetitive code patterns in bio chain handling.

v3:
- Remove the dead code in bio_chain_endio and drop patch 1 in v2 
- Refined the __bio_chain_endio changes with minor modifications (was
  patch 02 in v2).
- Dropped cleanup patches 06 and 12 from v2 due to an incorrect 'prev'
  and 'new' order.

v2:
- Added fix for bcache.
- Added BUG_ON() in bio_chain_endio().
- Enhanced commit messages for each patch
https://lore.kernel.org/all/20251128083219.2332407-1-zhangshida@kylinos.cn/

v1:
https://lore.kernel.org/all/20251121081748.1443507-1-zhangshida@kylinos.cn/

Shida Zhang (9):
  md: bcache: fix improper use of bi_end_io
  block: prohibit calls to bio_chain_endio
  block: prevent race condition on bi_status in __bio_chain_endio
  block: export bio_chain_and_submit
  xfs: Replace the repetitive bio chaining code patterns
  block: Replace the repetitive bio chaining code patterns
  fs/ntfs3: Replace the repetitive bio chaining code patterns
  zram: Replace the repetitive bio chaining code patterns
  nvdimm: Replace the repetitive bio chaining code patterns

 block/bio.c                   | 12 +++++++++---
 drivers/block/zram/zram_drv.c |  3 +--
 drivers/md/bcache/request.c   |  6 +++---
 drivers/nvdimm/nd_virtio.c    |  3 +--
 fs/ntfs3/fsntfs.c             | 12 ++----------
 fs/squashfs/block.c           |  3 +--
 fs/xfs/xfs_bio_io.c           |  3 +--
 fs/xfs/xfs_buf.c              |  3 +--
 fs/xfs/xfs_log.c              |  3 +--
 9 files changed, 20 insertions(+), 28 deletions(-)

-- 
2.34.1


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH v3 1/9] md: bcache: fix improper use of bi_end_io
  2025-11-29  9:01 [PATCH v3 0/9] Fix bio chain related issues zhangshida
@ 2025-11-29  9:01 ` zhangshida
  2025-12-01  5:45   ` Coly Li
  2025-11-29  9:01 ` [PATCH v3 2/9] block: prohibit calls to bio_chain_endio zhangshida
                   ` (7 subsequent siblings)
  8 siblings, 1 reply; 17+ messages in thread
From: zhangshida @ 2025-11-29  9:01 UTC (permalink / raw)
  To: Johannes.Thumshirn, hch, agruenba, ming.lei, hsiangkao, csander
  Cc: linux-block, linux-bcache, nvdimm, virtualization, ntfs3,
	linux-xfs, linux-kernel, zhangshida, starzhangzsd

From: Shida Zhang <zhangshida@kylinos.cn>

Don't call bio->bi_end_io() directly. Use the bio_endio() helper
function instead, which handles completion more safely and uniformly.

Suggested-by: Christoph Hellwig <hch@infradead.org>
Signed-off-by: Shida Zhang <zhangshida@kylinos.cn>
---
 drivers/md/bcache/request.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/md/bcache/request.c b/drivers/md/bcache/request.c
index af345dc6fde..82fdea7dea7 100644
--- a/drivers/md/bcache/request.c
+++ b/drivers/md/bcache/request.c
@@ -1104,7 +1104,7 @@ static void detached_dev_end_io(struct bio *bio)
 	}
 
 	kfree(ddip);
-	bio->bi_end_io(bio);
+	bio_endio(bio);
 }
 
 static void detached_dev_do_request(struct bcache_device *d, struct bio *bio,
@@ -1121,7 +1121,7 @@ static void detached_dev_do_request(struct bcache_device *d, struct bio *bio,
 	ddip = kzalloc(sizeof(struct detached_dev_io_private), GFP_NOIO);
 	if (!ddip) {
 		bio->bi_status = BLK_STS_RESOURCE;
-		bio->bi_end_io(bio);
+		bio_endio(bio);
 		return;
 	}
 
@@ -1136,7 +1136,7 @@ static void detached_dev_do_request(struct bcache_device *d, struct bio *bio,
 
 	if ((bio_op(bio) == REQ_OP_DISCARD) &&
 	    !bdev_max_discard_sectors(dc->bdev))
-		bio->bi_end_io(bio);
+		detached_dev_end_io(bio);
 	else
 		submit_bio_noacct(bio);
 }
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH v3 2/9] block: prohibit calls to bio_chain_endio
  2025-11-29  9:01 [PATCH v3 0/9] Fix bio chain related issues zhangshida
  2025-11-29  9:01 ` [PATCH v3 1/9] md: bcache: fix improper use of bi_end_io zhangshida
@ 2025-11-29  9:01 ` zhangshida
  2025-12-01  6:14   ` Christoph Hellwig
  2025-11-29  9:01 ` [PATCH v3 3/9] block: prevent race condition on bi_status in __bio_chain_endio zhangshida
                   ` (6 subsequent siblings)
  8 siblings, 1 reply; 17+ messages in thread
From: zhangshida @ 2025-11-29  9:01 UTC (permalink / raw)
  To: Johannes.Thumshirn, hch, agruenba, ming.lei, hsiangkao, csander
  Cc: linux-block, linux-bcache, nvdimm, virtualization, ntfs3,
	linux-xfs, linux-kernel, zhangshida, starzhangzsd

From: Shida Zhang <zhangshida@kylinos.cn>

Now that all potential callers of bio_chain_endio have been
eliminated, completely prohibit any future calls to this function.

Suggested-by: Ming Lei <ming.lei@redhat.com>
Suggested-by: Andreas Gruenbacher <agruenba@redhat.com>
Suggested-by: Christoph Hellwig <hch@infradead.org>
Signed-off-by: Shida Zhang <zhangshida@kylinos.cn>
---
 block/bio.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/block/bio.c b/block/bio.c
index b3a79285c27..1b5e4577f4c 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -320,9 +320,13 @@ static struct bio *__bio_chain_endio(struct bio *bio)
 	return parent;
 }
 
+/**
+ * This function should only be used as a flag and must never be called.
+ * If execution reaches here, it indicates a serious programming error.
+ */
 static void bio_chain_endio(struct bio *bio)
 {
-	bio_endio(__bio_chain_endio(bio));
+	BUG_ON(1);
 }
 
 /**
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH v3 3/9] block: prevent race condition on bi_status in __bio_chain_endio
  2025-11-29  9:01 [PATCH v3 0/9] Fix bio chain related issues zhangshida
  2025-11-29  9:01 ` [PATCH v3 1/9] md: bcache: fix improper use of bi_end_io zhangshida
  2025-11-29  9:01 ` [PATCH v3 2/9] block: prohibit calls to bio_chain_endio zhangshida
@ 2025-11-29  9:01 ` zhangshida
  2025-12-01  6:14   ` Christoph Hellwig
  2025-12-06 18:01   ` kernel test robot
  2025-11-29  9:01 ` [PATCH v3 4/9] block: export bio_chain_and_submit zhangshida
                   ` (5 subsequent siblings)
  8 siblings, 2 replies; 17+ messages in thread
From: zhangshida @ 2025-11-29  9:01 UTC (permalink / raw)
  To: Johannes.Thumshirn, hch, agruenba, ming.lei, hsiangkao, csander
  Cc: linux-block, linux-bcache, nvdimm, virtualization, ntfs3,
	linux-xfs, linux-kernel, zhangshida, starzhangzsd

From: Shida Zhang <zhangshida@kylinos.cn>

Andreas point out that multiple completions can race setting
bi_status.

The check (parent->bi_status) and the subsequent write are not an
atomic operation. The value of parent->bi_status could have changed
between the time you read it for the if check and the time you write
to it. So we use cmpxchg to fix the race, as suggested by Christoph.

Suggested-by: Andreas Gruenbacher <agruenba@redhat.com>
Suggested-by: Christoph Hellwig <hch@infradead.org>
Suggested-by: Caleb Sander Mateos <csander@purestorage.com>
Signed-off-by: Shida Zhang <zhangshida@kylinos.cn>
---
 block/bio.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/block/bio.c b/block/bio.c
index 1b5e4577f4c..097c1cd2054 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -314,8 +314,9 @@ static struct bio *__bio_chain_endio(struct bio *bio)
 {
 	struct bio *parent = bio->bi_private;
 
-	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);
+
 	bio_put(bio);
 	return parent;
 }
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH v3 4/9] block: export bio_chain_and_submit
  2025-11-29  9:01 [PATCH v3 0/9] Fix bio chain related issues zhangshida
                   ` (2 preceding siblings ...)
  2025-11-29  9:01 ` [PATCH v3 3/9] block: prevent race condition on bi_status in __bio_chain_endio zhangshida
@ 2025-11-29  9:01 ` zhangshida
  2025-12-01  6:15   ` Christoph Hellwig
  2025-11-29  9:01 ` [PATCH v3 5/9] xfs: Replace the repetitive bio chaining code patterns zhangshida
                   ` (4 subsequent siblings)
  8 siblings, 1 reply; 17+ messages in thread
From: zhangshida @ 2025-11-29  9:01 UTC (permalink / raw)
  To: Johannes.Thumshirn, hch, agruenba, ming.lei, hsiangkao, csander
  Cc: linux-block, linux-bcache, nvdimm, virtualization, ntfs3,
	linux-xfs, linux-kernel, zhangshida, starzhangzsd

From: Shida Zhang <zhangshida@kylinos.cn>

Export the bio_chain_and_submit function to make it available as a
common utility. This will allow replacing repetitive bio chaining
patterns found in multiple locations throughout the codebase.

Signed-off-by: Shida Zhang <zhangshida@kylinos.cn>
---
 block/bio.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/block/bio.c b/block/bio.c
index 097c1cd2054..7aa4a1d3672 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -368,6 +368,7 @@ struct bio *bio_chain_and_submit(struct bio *prev, struct bio *new)
 	}
 	return new;
 }
+EXPORT_SYMBOL_GPL(bio_chain_and_submit);
 
 struct bio *blk_next_bio(struct bio *bio, struct block_device *bdev,
 		unsigned int nr_pages, blk_opf_t opf, gfp_t gfp)
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH v3 5/9] xfs: Replace the repetitive bio chaining code patterns
  2025-11-29  9:01 [PATCH v3 0/9] Fix bio chain related issues zhangshida
                   ` (3 preceding siblings ...)
  2025-11-29  9:01 ` [PATCH v3 4/9] block: export bio_chain_and_submit zhangshida
@ 2025-11-29  9:01 ` zhangshida
  2025-11-29  9:01 ` [PATCH v3 6/9] block: " zhangshida
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 17+ messages in thread
From: zhangshida @ 2025-11-29  9:01 UTC (permalink / raw)
  To: Johannes.Thumshirn, hch, agruenba, ming.lei, hsiangkao, csander
  Cc: linux-block, linux-bcache, nvdimm, virtualization, ntfs3,
	linux-xfs, linux-kernel, zhangshida, starzhangzsd

From: Shida Zhang <zhangshida@kylinos.cn>

Replace duplicate bio chaining logic with the common
bio_chain_and_submit helper function.

Signed-off-by: Shida Zhang <zhangshida@kylinos.cn>
---
 fs/xfs/xfs_bio_io.c | 3 +--
 fs/xfs/xfs_buf.c    | 3 +--
 fs/xfs/xfs_log.c    | 3 +--
 3 files changed, 3 insertions(+), 6 deletions(-)

diff --git a/fs/xfs/xfs_bio_io.c b/fs/xfs/xfs_bio_io.c
index 2a736d10eaf..4a6577b0789 100644
--- a/fs/xfs/xfs_bio_io.c
+++ b/fs/xfs/xfs_bio_io.c
@@ -38,8 +38,7 @@ xfs_rw_bdev(
 					bio_max_vecs(count - done),
 					prev->bi_opf, GFP_KERNEL);
 			bio->bi_iter.bi_sector = bio_end_sector(prev);
-			bio_chain(prev, bio);
-			submit_bio(prev);
+			bio_chain_and_submit(prev, bio);
 		}
 		done += added;
 	} while (done < count);
diff --git a/fs/xfs/xfs_buf.c b/fs/xfs/xfs_buf.c
index 773d959965d..c26bd28edb4 100644
--- a/fs/xfs/xfs_buf.c
+++ b/fs/xfs/xfs_buf.c
@@ -1357,8 +1357,7 @@ xfs_buf_submit_bio(
 		split = bio_split(bio, bp->b_maps[map].bm_len, GFP_NOFS,
 				&fs_bio_set);
 		split->bi_iter.bi_sector = bp->b_maps[map].bm_bn;
-		bio_chain(split, bio);
-		submit_bio(split);
+		bio_chain_and_submit(split, bio);
 	}
 	bio->bi_iter.bi_sector = bp->b_maps[map].bm_bn;
 	submit_bio(bio);
diff --git a/fs/xfs/xfs_log.c b/fs/xfs/xfs_log.c
index 603e85c1ab4..f4c9ad1d148 100644
--- a/fs/xfs/xfs_log.c
+++ b/fs/xfs/xfs_log.c
@@ -1687,8 +1687,7 @@ xlog_write_iclog(
 
 		split = bio_split(&iclog->ic_bio, log->l_logBBsize - bno,
 				  GFP_NOIO, &fs_bio_set);
-		bio_chain(split, &iclog->ic_bio);
-		submit_bio(split);
+		bio_chain_and_submit(split, &iclog->ic_bio);
 
 		/* restart at logical offset zero for the remainder */
 		iclog->ic_bio.bi_iter.bi_sector = log->l_logBBstart;
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH v3 6/9] block: Replace the repetitive bio chaining code patterns
  2025-11-29  9:01 [PATCH v3 0/9] Fix bio chain related issues zhangshida
                   ` (4 preceding siblings ...)
  2025-11-29  9:01 ` [PATCH v3 5/9] xfs: Replace the repetitive bio chaining code patterns zhangshida
@ 2025-11-29  9:01 ` zhangshida
  2025-11-29  9:01 ` [PATCH v3 7/9] fs/ntfs3: " zhangshida
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 17+ messages in thread
From: zhangshida @ 2025-11-29  9:01 UTC (permalink / raw)
  To: Johannes.Thumshirn, hch, agruenba, ming.lei, hsiangkao, csander
  Cc: linux-block, linux-bcache, nvdimm, virtualization, ntfs3,
	linux-xfs, linux-kernel, zhangshida, starzhangzsd

From: Shida Zhang <zhangshida@kylinos.cn>

Replace duplicate bio chaining logic with the common
bio_chain_and_submit helper function.

Signed-off-by: Shida Zhang <zhangshida@kylinos.cn>
---
 fs/squashfs/block.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/fs/squashfs/block.c b/fs/squashfs/block.c
index a05e3793f93..5818e473255 100644
--- a/fs/squashfs/block.c
+++ b/fs/squashfs/block.c
@@ -126,8 +126,7 @@ static int squashfs_bio_read_cached(struct bio *fullbio,
 			if (bio) {
 				bio_trim(bio, start_idx * PAGE_SECTORS,
 					 (end_idx - start_idx) * PAGE_SECTORS);
-				bio_chain(bio, new);
-				submit_bio(bio);
+				bio_chain_and_submit(bio, new);
 			}
 
 			bio = new;
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH v3 7/9] fs/ntfs3: Replace the repetitive bio chaining code patterns
  2025-11-29  9:01 [PATCH v3 0/9] Fix bio chain related issues zhangshida
                   ` (5 preceding siblings ...)
  2025-11-29  9:01 ` [PATCH v3 6/9] block: " zhangshida
@ 2025-11-29  9:01 ` zhangshida
  2025-11-29  9:01 ` [PATCH v3 8/9] zram: " zhangshida
  2025-11-29  9:01 ` [PATCH v3 9/9] nvdimm: " zhangshida
  8 siblings, 0 replies; 17+ messages in thread
From: zhangshida @ 2025-11-29  9:01 UTC (permalink / raw)
  To: Johannes.Thumshirn, hch, agruenba, ming.lei, hsiangkao, csander
  Cc: linux-block, linux-bcache, nvdimm, virtualization, ntfs3,
	linux-xfs, linux-kernel, zhangshida, starzhangzsd

From: Shida Zhang <zhangshida@kylinos.cn>

Replace duplicate bio chaining logic with the common
bio_chain_and_submit helper function.

Signed-off-by: Shida Zhang <zhangshida@kylinos.cn>
---
 fs/ntfs3/fsntfs.c | 12 ++----------
 1 file changed, 2 insertions(+), 10 deletions(-)

diff --git a/fs/ntfs3/fsntfs.c b/fs/ntfs3/fsntfs.c
index c7a2f191254..35685ee4ed2 100644
--- a/fs/ntfs3/fsntfs.c
+++ b/fs/ntfs3/fsntfs.c
@@ -1514,11 +1514,7 @@ int ntfs_bio_pages(struct ntfs_sb_info *sbi, const struct runs_tree *run,
 		len = ((u64)clen << cluster_bits) - off;
 new_bio:
 		new = bio_alloc(bdev, nr_pages - page_idx, op, GFP_NOFS);
-		if (bio) {
-			bio_chain(bio, new);
-			submit_bio(bio);
-		}
-		bio = new;
+		bio = bio_chain_and_submit(bio, new);
 		bio->bi_iter.bi_sector = lbo >> 9;
 
 		while (len) {
@@ -1611,11 +1607,7 @@ int ntfs_bio_fill_1(struct ntfs_sb_info *sbi, const struct runs_tree *run)
 		len = (u64)clen << cluster_bits;
 new_bio:
 		new = bio_alloc(bdev, BIO_MAX_VECS, REQ_OP_WRITE, GFP_NOFS);
-		if (bio) {
-			bio_chain(bio, new);
-			submit_bio(bio);
-		}
-		bio = new;
+		bio = bio_chain_and_submit(bio, new);
 		bio->bi_iter.bi_sector = lbo >> 9;
 
 		for (;;) {
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH v3 8/9] zram: Replace the repetitive bio chaining code patterns
  2025-11-29  9:01 [PATCH v3 0/9] Fix bio chain related issues zhangshida
                   ` (6 preceding siblings ...)
  2025-11-29  9:01 ` [PATCH v3 7/9] fs/ntfs3: " zhangshida
@ 2025-11-29  9:01 ` zhangshida
  2025-12-04  9:00   ` Sergey Senozhatsky
  2025-11-29  9:01 ` [PATCH v3 9/9] nvdimm: " zhangshida
  8 siblings, 1 reply; 17+ messages in thread
From: zhangshida @ 2025-11-29  9:01 UTC (permalink / raw)
  To: Johannes.Thumshirn, hch, agruenba, ming.lei, hsiangkao, csander
  Cc: linux-block, linux-bcache, nvdimm, virtualization, ntfs3,
	linux-xfs, linux-kernel, zhangshida, starzhangzsd

From: Shida Zhang <zhangshida@kylinos.cn>

Replace duplicate bio chaining logic with the common
bio_chain_and_submit helper function.

Signed-off-by: Shida Zhang <zhangshida@kylinos.cn>
---
 drivers/block/zram/zram_drv.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index a4307465753..084de60ebaf 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -730,8 +730,7 @@ static void read_from_bdev_async(struct zram *zram, struct page *page,
 	bio = bio_alloc(zram->bdev, 1, parent->bi_opf, GFP_NOIO);
 	bio->bi_iter.bi_sector = entry * (PAGE_SIZE >> 9);
 	__bio_add_page(bio, page, PAGE_SIZE, 0);
-	bio_chain(bio, parent);
-	submit_bio(bio);
+	bio_chain_and_submit(bio, parent);
 }
 
 static int zram_writeback_slots(struct zram *zram, struct zram_pp_ctl *ctl)
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH v3 9/9] nvdimm: Replace the repetitive bio chaining code patterns
  2025-11-29  9:01 [PATCH v3 0/9] Fix bio chain related issues zhangshida
                   ` (7 preceding siblings ...)
  2025-11-29  9:01 ` [PATCH v3 8/9] zram: " zhangshida
@ 2025-11-29  9:01 ` zhangshida
  8 siblings, 0 replies; 17+ messages in thread
From: zhangshida @ 2025-11-29  9:01 UTC (permalink / raw)
  To: Johannes.Thumshirn, hch, agruenba, ming.lei, hsiangkao, csander
  Cc: linux-block, linux-bcache, nvdimm, virtualization, ntfs3,
	linux-xfs, linux-kernel, zhangshida, starzhangzsd

From: Shida Zhang <zhangshida@kylinos.cn>

Replace duplicate bio chaining logic with the common
bio_chain_and_submit helper function.

Signed-off-by: Shida Zhang <zhangshida@kylinos.cn>
---
 drivers/nvdimm/nd_virtio.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/nvdimm/nd_virtio.c b/drivers/nvdimm/nd_virtio.c
index c3f07be4aa2..e6ec7ceee9b 100644
--- a/drivers/nvdimm/nd_virtio.c
+++ b/drivers/nvdimm/nd_virtio.c
@@ -122,8 +122,7 @@ int async_pmem_flush(struct nd_region *nd_region, struct bio *bio)
 			return -ENOMEM;
 		bio_clone_blkg_association(child, bio);
 		child->bi_iter.bi_sector = -1;
-		bio_chain(child, bio);
-		submit_bio(child);
+		bio_chain_and_submit(child, bio);
 		return 0;
 	}
 	if (virtio_pmem_flush(nd_region))
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* Re: [PATCH v3 1/9] md: bcache: fix improper use of bi_end_io
  2025-11-29  9:01 ` [PATCH v3 1/9] md: bcache: fix improper use of bi_end_io zhangshida
@ 2025-12-01  5:45   ` Coly Li
  2025-12-01  8:29     ` Stephen Zhang
  0 siblings, 1 reply; 17+ messages in thread
From: Coly Li @ 2025-12-01  5:45 UTC (permalink / raw)
  To: zhangshida
  Cc: Johannes.Thumshirn, hch, agruenba, ming.lei, hsiangkao, csander,
	linux-block, linux-bcache, nvdimm, virtualization, ntfs3,
	linux-xfs, linux-kernel, zhangshida

> 2025年11月29日 17:01,zhangshida <starzhangzsd@gmail.com> 写道:
> 
> From: Shida Zhang <zhangshida@kylinos.cn>
> 
> Don't call bio->bi_end_io() directly. Use the bio_endio() helper
> function instead, which handles completion more safely and uniformly.
> 
> Suggested-by: Christoph Hellwig <hch@infradead.org>
> Signed-off-by: Shida Zhang <zhangshida@kylinos.cn>
> ---
> drivers/md/bcache/request.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/md/bcache/request.c b/drivers/md/bcache/request.c
> index af345dc6fde..82fdea7dea7 100644
> --- a/drivers/md/bcache/request.c
> +++ b/drivers/md/bcache/request.c

[snipped]

The patch is good. Please modify the patch subject to:  bcache: fix improper use of bi_end_io

You may directly send the refined version to linux-bcache mailing list, I will take it.

Thanks.

Coly Li

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v3 2/9] block: prohibit calls to bio_chain_endio
  2025-11-29  9:01 ` [PATCH v3 2/9] block: prohibit calls to bio_chain_endio zhangshida
@ 2025-12-01  6:14   ` Christoph Hellwig
  0 siblings, 0 replies; 17+ messages in thread
From: Christoph Hellwig @ 2025-12-01  6:14 UTC (permalink / raw)
  To: zhangshida
  Cc: Johannes.Thumshirn, hch, agruenba, ming.lei, hsiangkao, csander,
	linux-block, linux-bcache, nvdimm, virtualization, ntfs3,
	linux-xfs, linux-kernel, zhangshida

On Sat, Nov 29, 2025 at 05:01:15PM +0800, zhangshida wrote:
> From: Shida Zhang <zhangshida@kylinos.cn>
> 
> Now that all potential callers of bio_chain_endio have been
> eliminated, completely prohibit any future calls to this function.

Note that we'll need to be prepared for a flame from Linus for
using BUG_ON, but I still think it is reasonable here.

Reviewed-by: Christoph Hellwig <hch@lst.de>


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v3 3/9] block: prevent race condition on bi_status in __bio_chain_endio
  2025-11-29  9:01 ` [PATCH v3 3/9] block: prevent race condition on bi_status in __bio_chain_endio zhangshida
@ 2025-12-01  6:14   ` Christoph Hellwig
  2025-12-06 18:01   ` kernel test robot
  1 sibling, 0 replies; 17+ messages in thread
From: Christoph Hellwig @ 2025-12-01  6:14 UTC (permalink / raw)
  To: zhangshida
  Cc: Johannes.Thumshirn, hch, agruenba, ming.lei, hsiangkao, csander,
	linux-block, linux-bcache, nvdimm, virtualization, ntfs3,
	linux-xfs, linux-kernel, zhangshida

On Sat, Nov 29, 2025 at 05:01:16PM +0800, zhangshida wrote:
> From: Shida Zhang <zhangshida@kylinos.cn>
> 
> Andreas point out that multiple completions can race setting
> bi_status.
> 
> The check (parent->bi_status) and the subsequent write are not an
> atomic operation. The value of parent->bi_status could have changed
> between the time you read it for the if check and the time you write
> to it. So we use cmpxchg to fix the race, as suggested by Christoph.

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v3 4/9] block: export bio_chain_and_submit
  2025-11-29  9:01 ` [PATCH v3 4/9] block: export bio_chain_and_submit zhangshida
@ 2025-12-01  6:15   ` Christoph Hellwig
  0 siblings, 0 replies; 17+ messages in thread
From: Christoph Hellwig @ 2025-12-01  6:15 UTC (permalink / raw)
  To: zhangshida
  Cc: Johannes.Thumshirn, hch, agruenba, ming.lei, hsiangkao, csander,
	linux-block, linux-bcache, nvdimm, virtualization, ntfs3,
	linux-xfs, linux-kernel, zhangshida

Please split this and the remainder into a separate series, to be
resubmitted after -rc1.


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v3 1/9] md: bcache: fix improper use of bi_end_io
  2025-12-01  5:45   ` Coly Li
@ 2025-12-01  8:29     ` Stephen Zhang
  0 siblings, 0 replies; 17+ messages in thread
From: Stephen Zhang @ 2025-12-01  8:29 UTC (permalink / raw)
  To: Coly Li
  Cc: Johannes.Thumshirn, hch, agruenba, ming.lei, hsiangkao, csander,
	linux-block, linux-bcache, nvdimm, virtualization, ntfs3,
	linux-xfs, linux-kernel, zhangshida

Coly Li <colyli@fnnas.com> 于2025年12月1日周一 13:45写道:
>
> > 2025年11月29日 17:01,zhangshida <starzhangzsd@gmail.com> 写道:
> >
> > From: Shida Zhang <zhangshida@kylinos.cn>
> >
> > Don't call bio->bi_end_io() directly. Use the bio_endio() helper
> > function instead, which handles completion more safely and uniformly.
> >
> > Suggested-by: Christoph Hellwig <hch@infradead.org>
> > Signed-off-by: Shida Zhang <zhangshida@kylinos.cn>
> > ---
> > drivers/md/bcache/request.c | 6 +++---
> > 1 file changed, 3 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/md/bcache/request.c b/drivers/md/bcache/request.c
> > index af345dc6fde..82fdea7dea7 100644
> > --- a/drivers/md/bcache/request.c
> > +++ b/drivers/md/bcache/request.c
>
> [snipped]
>
> The patch is good. Please modify the patch subject to:  bcache: fix improper use of bi_end_io
>
> You may directly send the refined version to linux-bcache mailing list, I will take it.
>

Thank you. This has now been taken care of.

Thanks,
Shida

> Thanks.
>
> Coly Li

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v3 8/9] zram: Replace the repetitive bio chaining code patterns
  2025-11-29  9:01 ` [PATCH v3 8/9] zram: " zhangshida
@ 2025-12-04  9:00   ` Sergey Senozhatsky
  0 siblings, 0 replies; 17+ messages in thread
From: Sergey Senozhatsky @ 2025-12-04  9:00 UTC (permalink / raw)
  To: zhangshida
  Cc: Johannes.Thumshirn, hch, agruenba, ming.lei, hsiangkao, csander,
	linux-block, linux-bcache, nvdimm, virtualization, ntfs3,
	linux-xfs, linux-kernel, zhangshida

On (25/11/29 17:01), zhangshida wrote:
> Replace duplicate bio chaining logic with the common
> bio_chain_and_submit helper function.

A friendly hint: Cc-ing maintainers doesn't hurt, mostly.

Looks good to me, there is a slight chance of a conflict with
another pending zram patches, but it's quite trivial to resolve.

Acked-by: Sergey Senozhatsky <senozhatsky@chromium.org>

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v3 3/9] block: prevent race condition on bi_status in __bio_chain_endio
  2025-11-29  9:01 ` [PATCH v3 3/9] block: prevent race condition on bi_status in __bio_chain_endio zhangshida
  2025-12-01  6:14   ` Christoph Hellwig
@ 2025-12-06 18:01   ` kernel test robot
  1 sibling, 0 replies; 17+ messages in thread
From: kernel test robot @ 2025-12-06 18:01 UTC (permalink / raw)
  To: zhangshida, Johannes.Thumshirn, hch, agruenba, ming.lei,
	hsiangkao, csander
  Cc: oe-kbuild-all, linux-block, linux-bcache, nvdimm, virtualization,
	ntfs3, linux-xfs, linux-kernel, zhangshida, starzhangzsd

Hi zhangshida,

kernel test robot noticed the following build warnings:

[auto build test WARNING on axboe/for-next]
[also build test WARNING on xfs-linux/for-next nvdimm/libnvdimm-for-next linus/master brauner-vfs/vfs.all v6.18 next-20251205]
[cannot apply to nvdimm/dax-misc]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/zhangshida/md-bcache-fix-improper-use-of-bi_end_io/20251129-170348
base:   https://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux.git for-next
patch link:    https://lore.kernel.org/r/20251129090122.2457896-4-zhangshida%40kylinos.cn
patch subject: [PATCH v3 3/9] block: prevent race condition on bi_status in __bio_chain_endio
config: loongarch-randconfig-r133-20251130 (https://download.01.org/0day-ci/archive/20251207/202512070122.my7vkR7A-lkp@intel.com/config)
compiler: loongarch64-linux-gcc (GCC) 14.3.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251207/202512070122.my7vkR7A-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202512070122.my7vkR7A-lkp@intel.com/

sparse warnings: (new ones prefixed by >>)
>> block/bio.c:319:17: sparse: sparse: cast from restricted blk_status_t
>> block/bio.c:319:17: sparse: sparse: cast from restricted blk_status_t
>> block/bio.c:319:17: sparse: sparse: cast to restricted blk_status_t

vim +319 block/bio.c

   313	
   314	static struct bio *__bio_chain_endio(struct bio *bio)
   315	{
   316		struct bio *parent = bio->bi_private;
   317	
   318		if (bio->bi_status)
 > 319			cmpxchg(&parent->bi_status, 0, bio->bi_status);
   320	
   321		bio_put(bio);
   322		return parent;
   323	}
   324	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2025-12-06 18:01 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-29  9:01 [PATCH v3 0/9] Fix bio chain related issues zhangshida
2025-11-29  9:01 ` [PATCH v3 1/9] md: bcache: fix improper use of bi_end_io zhangshida
2025-12-01  5:45   ` Coly Li
2025-12-01  8:29     ` Stephen Zhang
2025-11-29  9:01 ` [PATCH v3 2/9] block: prohibit calls to bio_chain_endio zhangshida
2025-12-01  6:14   ` Christoph Hellwig
2025-11-29  9:01 ` [PATCH v3 3/9] block: prevent race condition on bi_status in __bio_chain_endio zhangshida
2025-12-01  6:14   ` Christoph Hellwig
2025-12-06 18:01   ` kernel test robot
2025-11-29  9:01 ` [PATCH v3 4/9] block: export bio_chain_and_submit zhangshida
2025-12-01  6:15   ` Christoph Hellwig
2025-11-29  9:01 ` [PATCH v3 5/9] xfs: Replace the repetitive bio chaining code patterns zhangshida
2025-11-29  9:01 ` [PATCH v3 6/9] block: " zhangshida
2025-11-29  9:01 ` [PATCH v3 7/9] fs/ntfs3: " zhangshida
2025-11-29  9:01 ` [PATCH v3 8/9] zram: " zhangshida
2025-12-04  9:00   ` Sergey Senozhatsky
2025-11-29  9:01 ` [PATCH v3 9/9] nvdimm: " zhangshida

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).