Linux kernel -stable discussions
 help / color / mirror / Atom feed
* [PATCH] md/raid5: complete unsupported discards successfully
       [not found] <CAO96y0V6oncv54ihXnHfJMYiG_QAQ-NM8BOdqPDXKL8r8-kR9Q@mail.gmail.com>
@ 2026-10-26  6:21 ` Konstantin Nikiforov
  2026-11-06  3:26   ` yu kuai
  2026-11-21 21:21   ` Konstantin Nikiforov
  0 siblings, 2 replies; 4+ messages in thread
From: Konstantin Nikiforov @ 2026-10-26  6:21 UTC (permalink / raw)
  To: linux-raid
  Cc: linux-bcache, regressions, linux-kernel, stable, yukuai, song,
	magiclinan, xiao, colyli, kent.overstreet

Since commit 90573092673c ("md/raid5: validate discard support at
request time") raid5 advertises max_hw_discard_sectors = UINT_MAX no
matter whether the member devices support discard or
devices_handle_discard_safely is set, and make_discard_request() fails
the discards it cannot handle with BLK_STS_NOTSUPP.

Before that commit such arrays did not advertise discard at all, so
upper layers never sent one. Now they do, and the failure is not
harmless:

 - bcache forwards discards to its backing device whenever
   bdev_max_discard_sectors() is non-zero, and backing_request_endio()
   treats every non-zero bi_status as a media error. After io_error_limit
   (64) of them bch_cached_dev_error() stops the cached device. On a
   machine with root on LVM over bcache over a raid5 of three HDDs the
   root filesystem disappeared a few minutes after every boot.

 - btrfs enables discard=async by default on any device that advertises
   discard, which is what generated the discards in the first place.

Discard is advisory: blkdev_issue_discard() already turns -EOPNOTSUPP
into success for its callers, and md_submit_discard_bio() silently skips
raid0/raid10 members without discard support. Do the same here and
complete the bio successfully when the array cannot pass it down safely,
so that callers submitting their own discard bios, like bcache, see the
same behaviour.

Fixes: 90573092673c ("md/raid5: validate discard support at request time")
Cc: stable@vger.kernel.org # 7.2
Closes: https://lore.kernel.org/all/CAO96y0V6oncv54ihXnHfJMYiG_QAQ-NM8BOdqPDXKL8r8-kR9Q@mail.gmail.com/
Signed-off-by: Konstantin Nikiforov <helllamer@gmail.com>
---
Kuai, this is the raid5-side change you were fine with in the report
thread. Reproducer: raid5 over three loop devices with a bcache backing
device on top, four blkdiscard calls on the bcache device. On 7.2.11
without the patch bcache's io_errors goes to 4 (bch_count_backing_io_errors
in dmesg); with the patch applied to 7.2.11 it stays at 0, and the
affected machine (root on LVM over bcache over raid5 of HDDs) boots and
runs with the patched module without any backing-device errors.
blkdiscard on the md device itself reports success either way because
blkdev_issue_discard() masks EOPNOTSUPP.

One correction to my report: the "discard_granularity is 0" observation
was a side effect of my own workaround (writing 0 to discard_max_bytes
makes the block layer report granularity 0); on a fresh array the
granularity is the stripe size as expected.

 drivers/md/raid5.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index b91545ce090d..b462b18e47ff 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -1144,7 +1144,16 @@ static bool raid5_discard_limits(struct mddev *mddev, struct bio *bi)
 	if (!conf->raid5_discard_unsupported)
 		return true;
 
-	bi->bi_status = BLK_STS_NOTSUPP;
+	/*
+	 * Discard is advisory. The array advertises discard regardless of
+	 * member support, so an upper layer may legitimately send discards
+	 * that cannot be forwarded safely. Complete them successfully
+	 * instead of failing them: bcache counts every failed backing
+	 * device bio as an I/O error and stops the device after
+	 * io_error_limit of them, and btrfs enables discard=async on any
+	 * device that advertises discard. This also matches what
+	 * md_submit_discard_bio() does for members without discard support.
+	 */
 	bio_endio(bi);
 	return false;
 }

base-commit: 6b4b543fa18757297ac756a6fe6e64f506b7844a
-- 
2.56.0


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

* Re: [PATCH] md/raid5: complete unsupported discards successfully
  2026-10-26  6:21 ` [PATCH] md/raid5: complete unsupported discards successfully Konstantin Nikiforov
@ 2026-11-06  3:26   ` yu kuai
  2026-11-21 21:21   ` Konstantin Nikiforov
  1 sibling, 0 replies; 4+ messages in thread
From: yu kuai @ 2026-11-06  3:26 UTC (permalink / raw)
  To: Konstantin Nikiforov, linux-raid, yu kuai
  Cc: linux-bcache, regressions, linux-kernel, stable, song, magiclinan,
	xiao, colyli, kent.overstreet

在 2026/10/26 14:21, Konstantin Nikiforov 写道:

> Since commit 90573092673c ("md/raid5: validate discard support at
> request time") raid5 advertises max_hw_discard_sectors = UINT_MAX no
> matter whether the member devices support discard or
> devices_handle_discard_safely is set, and make_discard_request() fails
> the discards it cannot handle with BLK_STS_NOTSUPP.
>
> Before that commit such arrays did not advertise discard at all, so
> upper layers never sent one. Now they do, and the failure is not
> harmless:
>
>   - bcache forwards discards to its backing device whenever
>     bdev_max_discard_sectors() is non-zero, and backing_request_endio()
>     treats every non-zero bi_status as a media error. After io_error_limit
>     (64) of them bch_cached_dev_error() stops the cached device. On a
>     machine with root on LVM over bcache over a raid5 of three HDDs the
>     root filesystem disappeared a few minutes after every boot.
>
>   - btrfs enables discard=async by default on any device that advertises
>     discard, which is what generated the discards in the first place.
>
> Discard is advisory: blkdev_issue_discard() already turns -EOPNOTSUPP
> into success for its callers, and md_submit_discard_bio() silently skips
> raid0/raid10 members without discard support. Do the same here and
> complete the bio successfully when the array cannot pass it down safely,
> so that callers submitting their own discard bios, like bcache, see the
> same behaviour.
>
> Fixes: 90573092673c ("md/raid5: validate discard support at request time")
> Cc:stable@vger.kernel.org # 7.2
> Closes:https://lore.kernel.org/all/CAO96y0V6oncv54ihXnHfJMYiG_QAQ-NM8BOdqPDXKL8r8-kR9Q@mail.gmail.com/
> Signed-off-by: Konstantin Nikiforov<helllamer@gmail.com>
> ---
> Kuai, this is the raid5-side change you were fine with in the report
> thread. Reproducer: raid5 over three loop devices with a bcache backing
> device on top, four blkdiscard calls on the bcache device. On 7.2.11
> without the patch bcache's io_errors goes to 4 (bch_count_backing_io_errors
> in dmesg); with the patch applied to 7.2.11 it stays at 0, and the
> affected machine (root on LVM over bcache over raid5 of HDDs) boots and
> runs with the patched module without any backing-device errors.
> blkdiscard on the md device itself reports success either way because
> blkdev_issue_discard() masks EOPNOTSUPP.
>
> One correction to my report: the "discard_granularity is 0" observation
> was a side effect of my own workaround (writing 0 to discard_max_bytes
> makes the block layer report granularity 0); on a fresh array the
> granularity is the stripe size as expected.
>
>   drivers/md/raid5.c | 11 ++++++++++-
>   1 file changed, 10 insertions(+), 1 deletion(-)
Applied

-- 
Thanks,
Kuai

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

* Re: [PATCH] md/raid5: complete unsupported discards successfully
  2026-10-26  6:21 ` [PATCH] md/raid5: complete unsupported discards successfully Konstantin Nikiforov
  2026-11-06  3:26   ` yu kuai
@ 2026-11-21 21:21   ` Konstantin Nikiforov
  2026-11-21 21:55     ` Konstantin Nikiforov
  1 sibling, 1 reply; 4+ messages in thread
From: Konstantin Nikiforov @ 2026-11-21 21:21 UTC (permalink / raw)
  To: linux-raid
  Cc: linux-bcache, regressions, linux-kernel, stable, Yu Kuai,
	Song Liu, Coly Li, Kent Overstreet, magiclinan, xiao

Hi Kuai,

I built and tested md-7.5 with b964c9240a37 on the machine from the
regression report.  The reproducer passes and the machine runs without
backing-device errors.

Tested tree
-----------
md-7.5 tip c526b7cd32f7, based on v7.4-rc2, with b964c9240a37 applied.
Built as 7.4.0-rc2-md75+ (x86_64, Arch config, gcc 16.2.1) and booted
on the affected machine.

Reproducer
----------
Three 256M loop files -> raid5 (64K chunk, metadata 1.2) -> bcache
backing device.  devices_handle_discard_safely is left at its default
(N), so the array takes the raid5_discard_limits() path changed by the
patch.

  md125: discard_max_bytes=2199023255040, discard_granularity=131072
  blkdiscard 8M on md125: exit 0
  bcache1 over md125: discard_max_bytes=2199023255040
  4x blkdiscard 8M on bcache1: io_errors=0, no
  bch_count_backing_io_errors lines in dmesg

The same reproducer gave io_errors=4 with the unpatched 7.2.11 module.
With the patched 7.2.11 module, and now with this kernel, it stays 0.

Affected machine
----------------
3x ST1000DM010 (no TRIM) -> md126 raid5 -> bcache0 (NVMe cache
attached, writethrough) -> LVM -> ext4/btrfs root.

Since booting 7.4.0-rc2-md75+, md126 and md127 are [UUU],
/sys/block/bcache0/bcache/io_errors is 0, and dmesg has no
bch_count_backing_io_errors or md/bcache I/O errors.

Caveat: the local workaround (udev rule zeroing discard_max_bytes on
md*/bcache*, plus nodiscard mounts) is still in the initramfs, so the
HDD-backed array has not received discards on this boot.  The loop
reproducer is what exercises the changed code path.  I can do a
no-workaround boot and a scratch-LV discard test if you want that
before this goes to stable.

Note: 7.2.y is EOL (7.2.15, 2026-11-01), so the "Cc: stable # 7.2" is
stale; v7.3.5 still has the old code, so the fix is needed in 7.3.y
once this reaches mainline.

Tested-by: Konstantin Nikiforov <helllamer@gmail.com>

#regzbot fix: md/raid5: complete unsupported discards successfully

Thanks,
Konstantin
DeepSeek Harness 0.2.2-rc.5; model: deepseek-flash

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

* Re: [PATCH] md/raid5: complete unsupported discards successfully
  2026-11-21 21:21   ` Konstantin Nikiforov
@ 2026-11-21 21:55     ` Konstantin Nikiforov
  0 siblings, 0 replies; 4+ messages in thread
From: Konstantin Nikiforov @ 2026-11-21 21:55 UTC (permalink / raw)
  To: linux-raid
  Cc: linux-bcache, regressions, linux-kernel, stable, Yu Kuai,
	Song Liu, Coly Li, Kent Overstreet, magiclinan, xiao

Hi Kuai,

A short follow-up to my tested-by report: I removed the udev rule that
zeroed discard_max_bytes from the md75 initramfs and disabled the host
copy, then tested the real HDD-backed stack with an actual discard.

Same kernel: 7.4.0-rc2-md75+, md-7.5 tip c526b7cd32f7 with b964c9240a37.
The stack advertises discard again:

  md126:   discard_max_bytes=2199023255040, discard_granularity=1048576
  bcache0: discard_max_bytes=2199023255040, discard_granularity=512

devices_handle_discard_safely is still at its default (N), so this is the
raid5_discard_limits() path the patch changes.

I created a 1G scratch LV on vgpcrd5 (dm -> bcache0 -> md126 on the three
ST1000DM010 HDDs) and issued one 64M discard:

  blkdiscard -o 0 -l 64M /dev/vgpcrd5/discardtest-md75
  exit 0
  /sys/block/bcache0/bcache/io_errors = 0
  bch_count_backing_io_errors in dmesg = 0

So the real bcache -> md126 -> HDD path also completes unsupported discards
successfully, not just the loop reproducer.  That was the last test item
pending from my earlier report.

Thanks,
Konstantin
DeepSeek Flash v4.1

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

end of thread, other threads:[~2026-11-21 21:55 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <CAO96y0V6oncv54ihXnHfJMYiG_QAQ-NM8BOdqPDXKL8r8-kR9Q@mail.gmail.com>
2026-10-26  6:21 ` [PATCH] md/raid5: complete unsupported discards successfully Konstantin Nikiforov
2026-11-06  3:26   ` yu kuai
2026-11-21 21:21   ` Konstantin Nikiforov
2026-11-21 21:55     ` Konstantin Nikiforov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox