mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@infradead.org>
To: Avi Weiss <thnkslprpt@gmail.com>
Cc: Jens Axboe <axboe@kernel.dk>,
	linux-kernel@vger.kernel.org, Josef Bacik <josef@toxicpanda.com>,
	Christian Brauner <brauner@kernel.org>,
	linux-block@vger.kernel.org
Subject: Re: [PATCH] block: avoid repeated notifications for dead disks
Date: Tue, 3 Nov 2026 02:42:13 -0800	[thread overview]
Message-ID: <aum6hZ6u9G4bNyCU@infradead.org> (raw)
In-Reply-To: <20261031171325.4073830-2-thnkslprpt@gmail.com>

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

      reply	other threads:[~2026-11-03 10:42 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-31 17:13 Avi Weiss
2026-11-03 10:42 ` Christoph Hellwig [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aum6hZ6u9G4bNyCU@infradead.org \
    --to=hch@infradead.org \
    --cc=axboe@kernel.dk \
    --cc=brauner@kernel.org \
    --cc=josef@toxicpanda.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=thnkslprpt@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®