* [PATCH for-rc 1/3] block: fail a delayed bio if its disk was removed
2026-12-05 12:55 Md Haris Iqbal
@ 2026-12-05 12:55 ` Md Haris Iqbal
0 siblings, 0 replies; 6+ messages in thread
From: Md Haris Iqbal @ 2026-12-05 12:55 UTC (permalink / raw)
To: Jens Axboe, linux-block
Cc: linux-kernel, Christoph Hellwig, Jonathan Corbet, linux-doc,
Md Haris Iqbal, Sashiko
A bio delayed by an error injection rule is resubmitted from a workqueue
with submit_bio_noacct_nocheck(), which skips bio_check_eod(). The
delayed bio holds no queue usage counter, so del_gendisk() does not wait
for it. For disks that don't own their queue, such as sd and sr, the
queue is unfrozen again after del_gendisk(). When sd is unbound while a
bio is delayed, the resubmitted bio reaches scsi_queue_rq() after the
driver is gone:
BUG: kernel NULL pointer dereference, address: 00000000000000c0
Workqueue: blk_error_inject blk_error_inject_delay_work
RIP: 0010:scsi_queue_rq+0x5b2/0xb80
Call Trace:
__blk_mq_issue_directly+0x3f/0xb0
blk_mq_try_issue_directly+0x8e/0x110
blk_mq_submit_bio+0x6b0/0x710
submit_bio_noacct_nocheck+0x2da/0x3c0
process_one_work+0x19b/0x370
Fail the bio instead of resubmitting it if the disk is dead. Rules
that fail the bio after the delay then also end it with BLK_STS_IOERR.
Fixes: 6bd856cc9996 ("block: allow error injection rules to delay bios")
Reported-by: Sashiko <sashiko-bot@kernel.org>
Link: https://sashiko.dev/#/patchset/20261111215838.103356-1-haris.iqbal%40linux.dev?part=2
Signed-off-by: Md Haris Iqbal <haris.iqbal@linux.dev>
---
block/error-injection.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/block/error-injection.c b/block/error-injection.c
index a6de52229ef3..88544eb41c08 100644
--- a/block/error-injection.c
+++ b/block/error-injection.c
@@ -66,6 +66,12 @@ static void blk_error_inject_delay_work(struct work_struct *work)
kfree(d);
+ /* the disk was removed while the bio was delayed */
+ if (test_bit(GD_DEAD, &bio->bi_bdev->bd_disk->state)) {
+ bio_io_error(bio);
+ return;
+ }
+
if (status != BLK_STS_OK) {
blk_error_inject_fail(bio, status);
return;
--
2.53.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH for-rc 0/3] block: error injection delay fixes
@ 2026-12-05 14:19 Md Haris Iqbal
2026-12-05 14:19 ` [PATCH for-rc 1/3] block: fail a delayed bio if its disk was removed Md Haris Iqbal
` (3 more replies)
0 siblings, 4 replies; 6+ messages in thread
From: Md Haris Iqbal @ 2026-12-05 14:19 UTC (permalink / raw)
To: Jens Axboe, linux-block
Cc: linux-kernel, Christoph Hellwig, Jonathan Corbet, linux-doc,
Md Haris Iqbal
Hi Jens,
Please consider these for the current rc. They fix the error injection
delay_us option added in 6bd856cc9996 ("block: allow error injection
rules to delay bios").
1: fail a delayed bio if its disk was removed; unbinding sd while a bio
is delayed oopses without it.
2: clear BIO_ERROR_INJECTED in bio_set_dev(), so it only covers the
device the bio was delayed on.
3: copy the flag to bio_split() splits, so raid10's discard split isn't
checked twice.
Tested in a VM with null_blk, nvme-loop and scsi_debug.
Claude helped with the fixes and was used to review them. I went through
all of it and tested it myself.
Md Haris Iqbal (3):
block: fail a delayed bio if its disk was removed
block: clear BIO_ERROR_INJECTED when a bio changes device
block: copy BIO_ERROR_INJECTED to the split in bio_split()
Documentation/block/error-injection.rst | 6 +++---
block/bio.c | 2 ++
block/error-injection.c | 10 ++++++++--
include/linux/bio.h | 4 +++-
4 files changed, 16 insertions(+), 6 deletions(-)
--
2.53.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH for-rc 1/3] block: fail a delayed bio if its disk was removed
2026-12-05 14:19 [PATCH for-rc 0/3] block: error injection delay fixes Md Haris Iqbal
@ 2026-12-05 14:19 ` Md Haris Iqbal
2026-12-05 14:19 ` [PATCH for-rc 2/3] block: clear BIO_ERROR_INJECTED when a bio changes device Md Haris Iqbal
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: Md Haris Iqbal @ 2026-12-05 14:19 UTC (permalink / raw)
To: Jens Axboe, linux-block
Cc: linux-kernel, Christoph Hellwig, Jonathan Corbet, linux-doc,
Md Haris Iqbal, Sashiko
A bio delayed by an error injection rule is resubmitted from a workqueue
with submit_bio_noacct_nocheck(), which skips bio_check_eod(). The
delayed bio holds no queue usage counter, so del_gendisk() does not wait
for it. For disks that don't own their queue, such as sd and sr, the
queue is unfrozen again after del_gendisk(). When sd is unbound while a
bio is delayed, the resubmitted bio reaches scsi_queue_rq() after the
driver is gone:
BUG: kernel NULL pointer dereference, address: 00000000000000c0
Workqueue: blk_error_inject blk_error_inject_delay_work
RIP: 0010:scsi_queue_rq+0x5b2/0xb80
Call Trace:
__blk_mq_issue_directly+0x3f/0xb0
blk_mq_try_issue_directly+0x8e/0x110
blk_mq_submit_bio+0x6b0/0x710
submit_bio_noacct_nocheck+0x2da/0x3c0
process_one_work+0x19b/0x370
Fail the bio instead of resubmitting it if the disk is dead. Rules
that fail the bio after the delay then also end it with BLK_STS_IOERR.
Fixes: 6bd856cc9996 ("block: allow error injection rules to delay bios")
Reported-by: Sashiko <sashiko-bot@kernel.org>
Link: https://sashiko.dev/#/patchset/20261111215838.103356-1-haris.iqbal%40linux.dev?part=2
Signed-off-by: Md Haris Iqbal <haris.iqbal@linux.dev>
---
block/error-injection.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/block/error-injection.c b/block/error-injection.c
index a6de52229ef3..88544eb41c08 100644
--- a/block/error-injection.c
+++ b/block/error-injection.c
@@ -66,6 +66,12 @@ static void blk_error_inject_delay_work(struct work_struct *work)
kfree(d);
+ /* the disk was removed while the bio was delayed */
+ if (test_bit(GD_DEAD, &bio->bi_bdev->bd_disk->state)) {
+ bio_io_error(bio);
+ return;
+ }
+
if (status != BLK_STS_OK) {
blk_error_inject_fail(bio, status);
return;
--
2.53.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH for-rc 2/3] block: clear BIO_ERROR_INJECTED when a bio changes device
2026-12-05 14:19 [PATCH for-rc 0/3] block: error injection delay fixes Md Haris Iqbal
2026-12-05 14:19 ` [PATCH for-rc 1/3] block: fail a delayed bio if its disk was removed Md Haris Iqbal
@ 2026-12-05 14:19 ` Md Haris Iqbal
2026-12-05 14:19 ` [PATCH for-rc 3/3] block: copy BIO_ERROR_INJECTED to the split in bio_split() Md Haris Iqbal
2026-12-05 14:33 ` [PATCH for-rc 0/3] block: error injection delay fixes Jens Axboe
3 siblings, 0 replies; 6+ messages in thread
From: Md Haris Iqbal @ 2026-12-05 14:19 UTC (permalink / raw)
To: Jens Axboe, linux-block
Cc: linux-kernel, Christoph Hellwig, Jonathan Corbet, linux-doc,
Md Haris Iqbal, Sashiko
BIO_ERROR_INJECTED keeps a bio that was delayed by an error injection
rule from being evaluated again when it is resubmitted. Rules belong to
a disk, but the flag stays set when a bio is remapped in place to
another device with bio_set_dev(), so the new device's rules would be
skipped for it.
Clear the flag in bio_set_dev() when the device changes, as is already
done for BIO_BPS_THROTTLED.
With nvme multipath, a bio delayed by a rule on the head disk loses the
flag when it is remapped to a path, so on failover it is checked against
the head's rules again.
Fixes: 6bd856cc9996 ("block: allow error injection rules to delay bios")
Reported-by: Sashiko <sashiko-bot@kernel.org>
Link: https://sashiko.dev/#/patchset/20261111215838.103356-1-haris.iqbal%40linux.dev?part=2
Signed-off-by: Md Haris Iqbal <haris.iqbal@linux.dev>
---
Documentation/block/error-injection.rst | 6 +++---
block/error-injection.c | 4 ++--
include/linux/bio.h | 4 +++-
3 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/Documentation/block/error-injection.rst b/Documentation/block/error-injection.rst
index 3c86defddb80..a4ccbf5d1558 100644
--- a/Documentation/block/error-injection.rst
+++ b/Documentation/block/error-injection.rst
@@ -56,9 +56,9 @@ Delays
A delayed bio is held above the driver, so the device never sees a slow I/O.
A delay does not reach the blk-mq timeout handler or SCSI error handling.
-A bio that matched a delay rule is not evaluated against the rules again, even
-after it is split and resubmitted internally. Removing a rule does not release
-bios it is already delaying.
+A bio that matched a delay rule is not evaluated against the rules again while
+it stays on that disk, even after it is split and resubmitted internally.
+Removing a rule does not release bios it is already delaying.
Holding a bio back reorders it against bios submitted later. On zoned devices
this breaks sequential write ordering and the block layer fails the
diff --git a/block/error-injection.c b/block/error-injection.c
index 88544eb41c08..c883602ac0c9 100644
--- a/block/error-injection.c
+++ b/block/error-injection.c
@@ -79,8 +79,8 @@ static void blk_error_inject_delay_work(struct work_struct *work)
/*
* Resubmit. The BIO_ERROR_INJECTED flag ensures that a bio that was
- * delayed once skips error injection entirely from here on, including
- * any other rule that covers it.
+ * delayed once skips error injection while it stays on this device,
+ * including any other rule that covers it.
*/
submit_bio_noacct_nocheck(bio, false);
}
diff --git a/include/linux/bio.h b/include/linux/bio.h
index 7a794ce723b8..facb80b33183 100644
--- a/include/linux/bio.h
+++ b/include/linux/bio.h
@@ -571,8 +571,10 @@ static inline void blkcg_punt_bio_submit(struct bio *bio)
static inline void bio_set_dev(struct bio *bio, struct block_device *bdev)
{
bio_clear_flag(bio, BIO_REMAPPED);
- if (bio->bi_bdev != bdev)
+ if (bio->bi_bdev != bdev) {
bio_clear_flag(bio, BIO_BPS_THROTTLED);
+ bio_clear_flag(bio, BIO_ERROR_INJECTED);
+ }
bio->bi_bdev = bdev;
bio_associate_blkg(bio);
}
--
2.53.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH for-rc 3/3] block: copy BIO_ERROR_INJECTED to the split in bio_split()
2026-12-05 14:19 [PATCH for-rc 0/3] block: error injection delay fixes Md Haris Iqbal
2026-12-05 14:19 ` [PATCH for-rc 1/3] block: fail a delayed bio if its disk was removed Md Haris Iqbal
2026-12-05 14:19 ` [PATCH for-rc 2/3] block: clear BIO_ERROR_INJECTED when a bio changes device Md Haris Iqbal
@ 2026-12-05 14:19 ` Md Haris Iqbal
2026-12-05 14:33 ` [PATCH for-rc 0/3] block: error injection delay fixes Jens Axboe
3 siblings, 0 replies; 6+ messages in thread
From: Md Haris Iqbal @ 2026-12-05 14:19 UTC (permalink / raw)
To: Jens Axboe, linux-block
Cc: linux-kernel, Christoph Hellwig, Jonathan Corbet, linux-doc,
Md Haris Iqbal, Sashiko
BIO_ERROR_INJECTED keeps a bio that was delayed by an error injection
rule from being evaluated again when it is resubmitted. bio_split()
does not copy the flag to the split. raid10_handle_discard() resubmits
the front split of an unaligned discard to the md device, so a discard
delayed by a rule on that device has its front part evaluated, and
possibly delayed, a second time.
Copy the flag in bio_split(), as is already done for
BIO_TRACE_COMPLETION.
Fixes: 6bd856cc9996 ("block: allow error injection rules to delay bios")
Reported-by: Sashiko <sashiko-bot@kernel.org>
Link: https://sashiko.dev/#/patchset/20261111215838.103356-1-haris.iqbal%40linux.dev?part=2
Signed-off-by: Md Haris Iqbal <haris.iqbal@linux.dev>
---
block/bio.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/block/bio.c b/block/bio.c
index b0fcc69de653..0bf72f7b9f4d 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -1962,6 +1962,8 @@ struct bio *bio_split(struct bio *bio, int sectors,
if (bio_flagged(bio, BIO_TRACE_COMPLETION))
bio_set_flag(split, BIO_TRACE_COMPLETION);
+ if (bio_flagged(bio, BIO_ERROR_INJECTED))
+ bio_set_flag(split, BIO_ERROR_INJECTED);
return split;
}
--
2.53.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH for-rc 0/3] block: error injection delay fixes
2026-12-05 14:19 [PATCH for-rc 0/3] block: error injection delay fixes Md Haris Iqbal
` (2 preceding siblings ...)
2026-12-05 14:19 ` [PATCH for-rc 3/3] block: copy BIO_ERROR_INJECTED to the split in bio_split() Md Haris Iqbal
@ 2026-12-05 14:33 ` Jens Axboe
3 siblings, 0 replies; 6+ messages in thread
From: Jens Axboe @ 2026-12-05 14:33 UTC (permalink / raw)
To: linux-block, Md Haris Iqbal
Cc: linux-kernel, Christoph Hellwig, Jonathan Corbet, linux-doc
On Sat, 05 Dec 2026 15:19:09 +0100, Md Haris Iqbal wrote:
> Please consider these for the current rc. They fix the error injection
> delay_us option added in 6bd856cc9996 ("block: allow error injection
> rules to delay bios").
>
> 1: fail a delayed bio if its disk was removed; unbinding sd while a bio
> is delayed oopses without it.
> 2: clear BIO_ERROR_INJECTED in bio_set_dev(), so it only covers the
> device the bio was delayed on.
> 3: copy the flag to bio_split() splits, so raid10's discard split isn't
> checked twice.
>
> [...]
Applied, thanks!
[1/3] block: fail a delayed bio if its disk was removed
(no commit info)
[2/3] block: clear BIO_ERROR_INJECTED when a bio changes device
(no commit info)
[3/3] block: copy BIO_ERROR_INJECTED to the split in bio_split()
(no commit info)
Best regards,
--
Jens Axboe
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-12-05 14:33 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-05 14:19 [PATCH for-rc 0/3] block: error injection delay fixes Md Haris Iqbal
2026-12-05 14:19 ` [PATCH for-rc 1/3] block: fail a delayed bio if its disk was removed Md Haris Iqbal
2026-12-05 14:19 ` [PATCH for-rc 2/3] block: clear BIO_ERROR_INJECTED when a bio changes device Md Haris Iqbal
2026-12-05 14:19 ` [PATCH for-rc 3/3] block: copy BIO_ERROR_INJECTED to the split in bio_split() Md Haris Iqbal
2026-12-05 14:33 ` [PATCH for-rc 0/3] block: error injection delay fixes Jens Axboe
-- strict thread matches above, loose matches on Subject: below --
2026-12-05 12:55 Md Haris Iqbal
2026-12-05 12:55 ` [PATCH for-rc 1/3] block: fail a delayed bio if its disk was removed Md Haris Iqbal
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox