All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 6.6.y] md/raid0: fix data corruption when chunk size is below PAGE_SIZE
@ 2026-10-13 13:32 Yunye Zhao
  2026-10-13 13:44 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Yunye Zhao @ 2026-10-13 13:32 UTC (permalink / raw)
  To: linux-raid
  Cc: Yu Kuai, Song Liu, Li Nan, Xiao Ni, Jan Kara, John Garry,
	Joseph Qi, YunyeZhao

From: YunyeZhao <yunye.zhao@linux.alibaba.com>

Commit 319ff40a5427 ("md/raid0: Fix performance regression for large sequential writes")
assumes that bios reaching RAID0 are no larger than the chunk size.

However, blk_queue_max_hw_sectors() raises limits smaller than
PAGE_SIZE to one page. With 64 KiB pages and a 16 KiB RAID0 chunk, a
bio can therefore span several chunks. raid0_make_request() splits it
only once and maps the multi-chunk remainder to one member device,
causing silent data corruption.

Set the queue chunk boundary after stacking the member limits, combined
with any inherited boundary using gcd(). This makes the block layer
split bios at chunk boundaries before they reach RAID0. Only install a
boundary aligned to the logical block size so that bio splitting
always makes progress.

Setting the boundary after disk_stack_limits() is required because
stacking may clear or reduce a boundary installed earlier. This adapts
the mechanism introduced by upstream commit 4b8beba60d32
("md/raid0: set chunk_sectors limit") to the queue limits API used by
6.6.y.

The corruption was reproduced on arm64 with 64 KiB pages and a 16 KiB
chunk. A 64 KiB chunk configuration is unaffected.

Fixes: 319ff40a5427 ("md/raid0: Fix performance regression for large sequential writes")
Signed-off-by: YunyeZhao <yunye.zhao@linux.alibaba.com>
---
 drivers/md/raid0.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/drivers/md/raid0.c b/drivers/md/raid0.c
index c50a7abda744..5a57e327c6ba 100644
--- a/drivers/md/raid0.c
+++ b/drivers/md/raid0.c
@@ -11,6 +11,7 @@
 */
 
 #include <linux/blkdev.h>
+#include <linux/gcd.h>
 #include <linux/seq_file.h>
 #include <linux/module.h>
 #include <linux/slab.h>
@@ -382,6 +383,7 @@ static void raid0_free(struct mddev *mddev, void *priv)
 static int raid0_run(struct mddev *mddev)
 {
 	struct r0conf *conf;
+	unsigned int chunk_limit;
 	int ret;
 
 	if (mddev->chunk_sectors == 0) {
@@ -413,6 +415,18 @@ static int raid0_run(struct mddev *mddev)
 			disk_stack_limits(mddev->gendisk, rdev->bdev,
 					  rdev->data_offset << 9);
 		}
+
+		/*
+		 * Set the chunk boundary after stacking member limits, which
+		 * may clear or reduce it. Without it a bio may span several
+		 * chunks when chunk size < PAGE_SIZE. Keep it a multiple of
+		 * the logical block size so the block layer can split at it.
+		 */
+		chunk_limit = gcd(mddev->queue->limits.chunk_sectors,
+				  mddev->chunk_sectors);
+		if (!(chunk_limit %
+		      (mddev->queue->limits.logical_block_size >> SECTOR_SHIFT)))
+			blk_queue_chunk_sectors(mddev->queue, chunk_limit);
 	}
 
 	/* calculate array device size */
-- 
2.19.1.6.gb485710b


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

end of thread, other threads:[~2026-10-13 13:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-13 13:32 [PATCH 6.6.y] md/raid0: fix data corruption when chunk size is below PAGE_SIZE Yunye Zhao
2026-10-13 13:44 ` sashiko-bot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.