md: Correctly disable write zeroes for raid 1, 10 and 5
PATCH 1/1 md: Correctly disable write zeroes for raid 1, 10 and 5
raid1_set_limits(), raid10_set_queue_limits() and raid5_set_limits() set max_write_zeroes_sectors to 0 to disable write zeroes support.
However, blk_validate_limits() checks that if max_hw_wzeroes_unmap_sectors is not zero, it must be equal to max_write_zeroes_sectors. When creating a RAID1, RAID10 or RAID5 array of block devices that have a non-zero max_hw_wzeroes_unmap_sectors limit, blk_validate_limits() returns an error resulting in a failure to start the array.
Fix this by setting max_hw_wzeroes_unmap_sectors to 0 as well in raid1_set_limits(), raid10_set_queue_limits() and raid5_set_limits().
--- drivers/md/raid1.c | 2 ++ drivers/md/raid10.c | 1 + drivers/md/raid5.c | 1 + 3 files changed, 4 insertions(+)
drivers/md/raid1.c +2 -0
@@ -3211,6 +3211,8 @@ static int raid1_set_limits(struct mddev *mddev)md_init_stacking_limits (&lim); lim.max_write_zeroes_sectors =0 ; + lim.max_hw_wzeroes_unmap_sectors =0 ; + lim.features |=BLK_FEAT_ATOMIC_WRITES ; err =mddev_stack_rdev_limits (mddev, &lim,MDDEV_STACK_INTEGRITY );if (err)
drivers/md/raid10.c +1 -0
@@ -4008,6 +4008,7 @@ static int raid10_set_queue_limits(struct mddev *mddev)md_init_stacking_limits (&lim); lim.max_write_zeroes_sectors =0 ; + lim.max_hw_wzeroes_unmap_sectors = 0 lim.io_min = mddev->chunk_sectors <<9 ; lim.chunk_sectors = mddev->chunk_sectors; lim.io_opt = lim.io_min *raid10_nr_stripes (conf);
drivers/md/raid5.c +1 -0
@@ -7732,6 +7732,7 @@ static int raid5_set_limits(struct mddev *mddev) lim.features |=BLK_FEAT_RAID_PARTIAL_STRIPES_EXPENSIVE ; lim.discard_granularity = stripe; lim.max_write_zeroes_sectors =0 ; + lim.max_hw_wzeroes_unmap_sectors = 0mddev_stack_rdev_limits (mddev, &lim,0 );rdev_for_each (rdev, mddev) queue_limits_stack_bdev(&lim, rdev->bdev, rdev->new_data_offset,
Signature · 1 line
2.51.0
Hi,
Quoted 13 lines · Damien Le Moal
raid1_set_limits(),raid10_set_queue_limits()andraid5_set_limits()setmax_write_zeroes_sectorsto 0 to disable write zeroes support.However,
blk_validate_limits()checks that ifmax_hw_wzeroes_unmap_sectorsis not zero, it must be equal tomax_write_zeroes_sectors. When creating a RAID1, RAID10 or RAID5 array of block devices that have a non-zeromax_hw_wzeroes_unmap_sectorslimit,blk_validate_limits()returns an error resulting in a failure to start the array.Fix this by setting
max_hw_wzeroes_unmap_sectorsto 0 as well inraid1_set_limits(),raid10_set_queue_limits()andraid5_set_limits().
Quoted 7 lines
Fixes 0c40d7cb5ef3 ("block: introduce max_{hw|user}_wzeroes_unmap_sectors to queue limits")Signed-off-by Damien Le Moal <[email protected]>--- drivers/md/raid1.c | 2 ++ drivers/md/raid10.c | 1 + drivers/md/raid5.c | 1 + 3 files changed, 4 insertions(+)
Yi already posted a fix:
[PATCH 1/2] md: init queue_limits->max_hw_wzeroes_unmap_sectors parameter - Zhang Yi <https://lore.kernel.org/all/[email protected]/>
Thanks,
Kuai
Quoted 37 lines
drivers/md/raid1.c +2
-0@@ -3211,6 +3211,8 @@ static int raid1_set_limits(struct mddev *mddev)md_init_stacking_limits (&lim); lim.max_write_zeroes_sectors =0 ; + lim.max_hw_wzeroes_unmap_sectors =0 ; + lim.features |=BLK_FEAT_ATOMIC_WRITES ; err =mddev_stack_rdev_limits (mddev, &lim,MDDEV_STACK_INTEGRITY );if (err)drivers/md/raid10.c +1
-0@@ -4008,6 +4008,7 @@ static int raid10_set_queue_limits(struct mddev *mddev)md_init_stacking_limits (&lim); lim.max_write_zeroes_sectors =0 ; + lim.max_hw_wzeroes_unmap_sectors = 0 lim.io_min = mddev->chunk_sectors <<9 ; lim.chunk_sectors = mddev->chunk_sectors; lim.io_opt = lim.io_min *raid10_nr_stripes (conf);drivers/md/raid5.c +1
-0@@ -7732,6 +7732,7 @@ static int raid5_set_limits(struct mddev *mddev) lim.features |=BLK_FEAT_RAID_PARTIAL_STRIPES_EXPENSIVE ; lim.discard_granularity = stripe; lim.max_write_zeroes_sectors =0 ; + lim.max_hw_wzeroes_unmap_sectors = 0mddev_stack_rdev_limits (mddev, &lim,0 );rdev_for_each (rdev, mddev) queue_limits_stack_bdev(&lim, rdev->bdev, rdev->new_data_offset,
kernel test robot
build botkernel test robot noticed the following build errors:
Hi Damien,
kernel test robot noticed the following build errors:
[auto build test ERROR on linus/master]
[also build test ERROR on v6.17-rc4 next-20250902]
[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/Damien-Le-Moal/md-Correctly-disable-write-zeroes-for-raid-1-10-and-5/20250902-174321 base: linus/master patch link: https://lore.kernel.org/r/20250902093843.187767-1-dlemoal%40kernel.org patch subject: [PATCH] md: Correctly disable write zeroes for raid 1, 10 and 5 config: i386-buildonly-randconfig-004-20250903 (https://download.01.org/0day-ci/archive/20250903/[email protected]/config) compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250903/[email protected]/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 <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
drivers/md/raid5.c:4207:7: warning: variable 'qread' set but not used [-Wunused-but-set-variable]
4207 | int qread =0;
| ^
>> drivers/md/raid5.c:7735:38: error: expected ';' after expression
7735 | lim.max_hw_wzeroes_unmap_sectors = 0
| ^
| ;1 warning and 1 error generated.
vim +7735 drivers/md/raid5.c
7709
7710 static int raid5_set_limits(struct mddev *mddev)
7711 {
7712 struct r5conf *conf = mddev->private;
7713 struct queue_limits lim;
7714 int data_disks, stripe;
7715 struct md_rdev *rdev;
7716
7717 /*
7718 * The read-ahead size must cover two whole stripes, which is
7719 * 2 * (datadisks) * chunksize where 'n' is the number of raid devices.
7720 */
7721 data_disks = conf->previous_raid_disks - conf->max_degraded;
7722
7723 /*
7724 * We can only discard a whole stripe. It doesn't make sense to
7725 * discard data disk but write parity disk
7726 */
7727 stripe = roundup_pow_of_two(data_disks * (mddev->chunk_sectors << 9));
7728
7729 md_init_stacking_limits(&lim);
7730 lim.io_min = mddev->chunk_sectors << 9;
7731 lim.io_opt = lim.io_min * (conf->raid_disks - conf->max_degraded);
7732 lim.features |= BLK_FEAT_RAID_PARTIAL_STRIPES_EXPENSIVE;
7733 lim.discard_granularity = stripe;
7734 lim.max_write_zeroes_sectors = 0;
> 7735 lim.max_hw_wzeroes_unmap_sectors = 0
7736 mddev_stack_rdev_limits(mddev, &lim, 0);
7737 rdev_for_each(rdev, mddev)
7738 queue_limits_stack_bdev(&lim, rdev->bdev, rdev->new_data_offset,
7739 mddev->gendisk->disk_name);
7740
7741 /*
7742 * Zeroing is required for discard, otherwise data could be lost.
7743 *
7744 * Consider a scenario: discard a stripe (the stripe could be
7745 * inconsistent if discard_zeroes_data is 0); write one disk of the
7746 * stripe (the stripe could be inconsistent again depending on which
7747 * disks are used to calculate parity); the disk is broken; The stripe
7748 * data of this disk is lost.
7749 *
7750 * We only allow DISCARD if the sysadmin has confirmed that only safe
7751 * devices are in use by setting a module parameter. A better idea
7752 * might be to turn DISCARD into WRITE_ZEROES requests, as that is
7753 * required to be safe.
7754 */
7755 if (!devices_handle_discard_safely ||
7756 lim.max_discard_sectors < (stripe >> 9) ||
7757 lim.discard_granularity < stripe)
7758 lim.max_hw_discard_sectors = 0;
7759
7760 /*
7761 * Requests require having a bitmap for each stripe.
7762 * Limit the max sectors based on this.
7763 */
7764 lim.max_hw_sectors = RAID5_MAX_REQ_STRIPES << RAID5_STRIPE_SHIFT(conf);
7765
7766 /* No restrictions on the number of segments in the request */
7767 lim.max_segments = USHRT_MAX;
7768
7769 return queue_limits_set(mddev->gendisk->queue, &lim);
7770 }
7771
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Quoted 24 lines · Yu Kuai
Hi,
Quoted 13 lines · Damien Le Moal
raid1_set_limits(),raid10_set_queue_limits()andraid5_set_limits()setmax_write_zeroes_sectorsto 0 to disable write zeroes support.However,
blk_validate_limits()checks that ifmax_hw_wzeroes_unmap_sectorsis not zero, it must be equal tomax_write_zeroes_sectors. When creating a RAID1, RAID10 or RAID5 array of block devices that have a non-zeromax_hw_wzeroes_unmap_sectorslimit,blk_validate_limits()returns an error resulting in a failure to start the array.Fix this by setting
max_hw_wzeroes_unmap_sectorsto 0 as well inraid1_set_limits(),raid10_set_queue_limits()andraid5_set_limits().Quoted 7 lines
Fixes 0c40d7cb5ef3 ("block: introduce max_{hw|user}_wzeroes_unmap_sectors to queue limits")Signed-off-by Damien Le Moal <[email protected]>--- drivers/md/raid1.c | 2 ++ drivers/md/raid10.c | 1 + drivers/md/raid5.c | 1 + 3 files changed, 4 insertions(+)
Quoted 4 lines
Yi already posted a fix:
[PATCH 1/2] md: init
queue_limits->max_hw_wzeroes_unmap_sectors
parameter - Zhang Yi <https://lore.kernel.org/all/[email protected]/>
Missed that... Thank you for the link.
Signature · 2 lines
Damien Le Moal Western Digital Research