mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] block: avoid repeated notifications for dead disks
@ 2026-10-31 17:13 Avi Weiss
  2026-11-03 10:42 ` Christoph Hellwig
  0 siblings, 1 reply; 2+ messages in thread
From: Avi Weiss @ 2026-10-31 17:13 UTC (permalink / raw)
  To: Jens Axboe
  Cc: linux-kernel, Avi Weiss, Josef Bacik, Christian Brauner, linux-block

blk_mark_disk_dead() reports disk death even when GD_DEAD is already
set. For example, NVMe reset failure and subsequent namespace removal
can call it twice, repeating holder mark_dead callbacks.

Only report disk death when __blk_mark_disk_dead() first sets GD_DEAD.
Keep its existing return value for queue drain handling in
__del_gendisk().

Fixes: d8530de5a6e8 ("block: call into the file system for bdev_mark_dead")
Signed-off-by: Avi Weiss <thnkslprpt@gmail.com>
---
 block/genhd.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/block/genhd.c b/block/genhd.c
index 10ca8b4d6eea..a511fc192174 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -657,13 +657,15 @@ static void blk_report_disk_dead(struct gendisk *disk, bool surprise)
 	rcu_read_unlock();
 }
 
-static bool __blk_mark_disk_dead(struct gendisk *disk)
+static bool __blk_mark_disk_dead(struct gendisk *disk, bool *newly_dead)
 {
 	/*
 	 * Fail any new I/O.
 	 */
 	if (test_and_set_bit(GD_DEAD, &disk->state))
 		return false;
+	if (newly_dead)
+		*newly_dead = true;
 
 	if (test_bit(GD_OWNS_QUEUE, &disk->state))
 		blk_queue_flag_set(QUEUE_FLAG_DYING, disk->queue);
@@ -688,9 +690,12 @@ static bool __blk_mark_disk_dead(struct gendisk *disk)
  */
 void blk_mark_disk_dead(struct gendisk *disk)
 {
+	bool newly_dead = false;
+
 	blk_queue_flag_set(QUEUE_FLAG_DYING, disk->queue);
-	__blk_mark_disk_dead(disk);
-	blk_report_disk_dead(disk, true);
+	__blk_mark_disk_dead(disk, &newly_dead);
+	if (newly_dead)
+		blk_report_disk_dead(disk, true);
 }
 EXPORT_SYMBOL_GPL(blk_mark_disk_dead);
 
@@ -727,7 +732,7 @@ static void __del_gendisk(struct gendisk *disk)
 	 * Drop all partitions now that the disk is marked dead.
 	 */
 	mutex_lock(&disk->open_mutex);
-	start_drain = __blk_mark_disk_dead(disk);
+	start_drain = __blk_mark_disk_dead(disk, NULL);
 	if (start_drain)
 		blk_freeze_acquire_lock(q);
 	xa_for_each_start(&disk->part_tbl, idx, part, 1)

base-commit: 36aad21d50d1af3f6954bb0c988257a908202477
-- 
2.43.0


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

* Re: [PATCH] block: avoid repeated notifications for dead disks
  2026-10-31 17:13 [PATCH] block: avoid repeated notifications for dead disks Avi Weiss
@ 2026-11-03 10:42 ` Christoph Hellwig
  0 siblings, 0 replies; 2+ messages in thread
From: Christoph Hellwig @ 2026-11-03 10:42 UTC (permalink / raw)
  To: Avi Weiss
  Cc: Jens Axboe, linux-kernel, Josef Bacik, Christian Brauner, linux-block

On Sat, Oct 31, 2026 at 07:13:26PM +0200, Avi Weiss wrote:
> blk_mark_disk_dead() reports disk death even when GD_DEAD is already
> set. For example, NVMe reset failure and subsequent namespace removal
> can call it twice, repeating holder mark_dead callbacks.
> 
> Only report disk death when __blk_mark_disk_dead() first sets GD_DEAD.
> Keep its existing return value for queue drain handling in
> __del_gendisk().

This would be much simpler if we move the test_and_set_bit of GD_DEAD
into the callers:

diff --git a/block/genhd.c b/block/genhd.c
index 10ca8b4d6eea..7e4570f9cea7 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -659,12 +659,6 @@ static void blk_report_disk_dead(struct gendisk *disk, bool surprise)
 
 static bool __blk_mark_disk_dead(struct gendisk *disk)
 {
-	/*
-	 * Fail any new I/O.
-	 */
-	if (test_and_set_bit(GD_DEAD, &disk->state))
-		return false;
-
 	if (test_bit(GD_OWNS_QUEUE, &disk->state))
 		blk_queue_flag_set(QUEUE_FLAG_DYING, disk->queue);
 
@@ -689,17 +683,19 @@ static bool __blk_mark_disk_dead(struct gendisk *disk)
 void blk_mark_disk_dead(struct gendisk *disk)
 {
 	blk_queue_flag_set(QUEUE_FLAG_DYING, disk->queue);
-	__blk_mark_disk_dead(disk);
-	blk_report_disk_dead(disk, true);
+	if (!test_and_set_bit(GD_DEAD, &disk->state)) {
+		__blk_mark_disk_dead(disk);
+		blk_report_disk_dead(disk, true);
+	}
 }
 EXPORT_SYMBOL_GPL(blk_mark_disk_dead);
 
 static void __del_gendisk(struct gendisk *disk)
 {
 	struct request_queue *q = disk->queue;
+	bool start_drain = false;
 	struct block_device *part;
 	unsigned long idx;
-	bool start_drain;
 
 	might_sleep();
 
@@ -727,9 +723,11 @@ static void __del_gendisk(struct gendisk *disk)
 	 * Drop all partitions now that the disk is marked dead.
 	 */
 	mutex_lock(&disk->open_mutex);
-	start_drain = __blk_mark_disk_dead(disk);
-	if (start_drain)
-		blk_freeze_acquire_lock(q);
+	if (!test_and_set_bit(GD_DEAD, &disk->state)) {
+		start_drain = __blk_mark_disk_dead(disk);
+		if (start_drain)
+			blk_freeze_acquire_lock(q);
+	}
 	xa_for_each_start(&disk->part_tbl, idx, part, 1)
 		drop_partition(part);
 	mutex_unlock(&disk->open_mutex);

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

end of thread, other threads:[~2026-11-03 10:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-31 17:13 [PATCH] block: avoid repeated notifications for dead disks Avi Weiss
2026-11-03 10:42 ` Christoph Hellwig

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

all inboxes | Powered by JetHome®