linux-raid.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] md: Correctly disable write zeroes for raid 1, 10 and 5
@ 2025-09-02  9:38 Damien Le Moal
  2025-09-02 10:58 ` Yu Kuai
  2025-09-03  1:16 ` kernel test robot
  0 siblings, 2 replies; 4+ messages in thread
From: Damien Le Moal @ 2025-09-02  9:38 UTC (permalink / raw)
  To: Song Liu, Yu Kuai, linux-raid

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().

Fixes: 0c40d7cb5ef3 ("block: introduce max_{hw|user}_wzeroes_unmap_sectors to queue limits")
Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
---
 drivers/md/raid1.c  | 2 ++
 drivers/md/raid10.c | 1 +
 drivers/md/raid5.c  | 1 +
 3 files changed, 4 insertions(+)

diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index 408c26398321..b366438f3c00 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -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)
diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index b60c30bfb6c7..fe3390948326 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -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);
diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index 023649fe2476..5f65dd80e2ef 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -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 = 0
 	mddev_stack_rdev_limits(mddev, &lim, 0);
 	rdev_for_each(rdev, mddev)
 		queue_limits_stack_bdev(&lim, rdev->bdev, rdev->new_data_offset,
-- 
2.51.0


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

* Re: [PATCH] md: Correctly disable write zeroes for raid 1, 10 and 5
  2025-09-02  9:38 [PATCH] md: Correctly disable write zeroes for raid 1, 10 and 5 Damien Le Moal
@ 2025-09-02 10:58 ` Yu Kuai
  2025-09-03  2:46   ` Damien Le Moal
  2025-09-03  1:16 ` kernel test robot
  1 sibling, 1 reply; 4+ messages in thread
From: Yu Kuai @ 2025-09-02 10:58 UTC (permalink / raw)
  To: Damien Le Moal, Song Liu, Yu Kuai, linux-raid

Hi,

在 2025/9/2 17:38, Damien Le Moal 写道:
> 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().
>
> Fixes: 0c40d7cb5ef3 ("block: introduce max_{hw|user}_wzeroes_unmap_sectors to queue limits")
> Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
> ---
>   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/20250825083320.797165-2-yi.zhang@huaweicloud.com/>

Thanks,
Kuai

> diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
> index 408c26398321..b366438f3c00 100644
> --- a/drivers/md/raid1.c
> +++ b/drivers/md/raid1.c
> @@ -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)
> diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
> index b60c30bfb6c7..fe3390948326 100644
> --- a/drivers/md/raid10.c
> +++ b/drivers/md/raid10.c
> @@ -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);
> diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
> index 023649fe2476..5f65dd80e2ef 100644
> --- a/drivers/md/raid5.c
> +++ b/drivers/md/raid5.c
> @@ -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 = 0
>   	mddev_stack_rdev_limits(mddev, &lim, 0);
>   	rdev_for_each(rdev, mddev)
>   		queue_limits_stack_bdev(&lim, rdev->bdev, rdev->new_data_offset,

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

* Re: [PATCH] md: Correctly disable write zeroes for raid 1, 10 and 5
  2025-09-02  9:38 [PATCH] md: Correctly disable write zeroes for raid 1, 10 and 5 Damien Le Moal
  2025-09-02 10:58 ` Yu Kuai
@ 2025-09-03  1:16 ` kernel test robot
  1 sibling, 0 replies; 4+ messages in thread
From: kernel test robot @ 2025-09-03  1:16 UTC (permalink / raw)
  To: Damien Le Moal, Song Liu, Yu Kuai, linux-raid; +Cc: llvm, oe-kbuild-all

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/202509030804.BSCTfNfn-lkp@intel.com/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/202509030804.BSCTfNfn-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/202509030804.BSCTfNfn-lkp@intel.com/

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	

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

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

* Re: [PATCH] md: Correctly disable write zeroes for raid 1, 10 and 5
  2025-09-02 10:58 ` Yu Kuai
@ 2025-09-03  2:46   ` Damien Le Moal
  0 siblings, 0 replies; 4+ messages in thread
From: Damien Le Moal @ 2025-09-03  2:46 UTC (permalink / raw)
  To: Yu Kuai, Song Liu, Yu Kuai, linux-raid

On 9/2/25 19:58, Yu Kuai wrote:
> Hi,
> 
> 在 2025/9/2 17:38, Damien Le Moal 写道:
>> 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().
>>
>> Fixes: 0c40d7cb5ef3 ("block: introduce max_{hw|user}_wzeroes_unmap_sectors to queue limits")
>> Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
>> ---
>>   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/20250825083320.797165-2-yi.zhang@huaweicloud.com/>

Missed that... Thank you for the link.


-- 
Damien Le Moal
Western Digital Research

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

end of thread, other threads:[~2025-09-03  2:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-02  9:38 [PATCH] md: Correctly disable write zeroes for raid 1, 10 and 5 Damien Le Moal
2025-09-02 10:58 ` Yu Kuai
2025-09-03  2:46   ` Damien Le Moal
2025-09-03  1:16 ` kernel test robot

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).