From: Christoph Hellwig <hch@lst.de>
To: Jens Axboe <axboe@kernel.dk>
Cc: Sergey Senozhatsky <senozhatsky@chromium.org>,
YangYang <yang.yang@vivo.com>,
linux-block@vger.kernel.org
Subject: [PATCH 2/2] block: mark the disk dead before taking open_mutx in del_gendisk
Date: Wed, 9 Oct 2024 13:38:21 +0200 [thread overview]
Message-ID: <20241009113831.557606-3-hch@lst.de> (raw)
In-Reply-To: <20241009113831.557606-1-hch@lst.de>
Now that we stop sd and sr from submitting passthrough commands from
their ->release methods we can and should start the drain before taking
->open_mutex, so that we can entirely prevent this kind of deadlock by
ensuring that the disk is clearly marked dead before open_mutex is
taken in del_gendisk.
This includes a revert of commit 7e04da2dc701 ("block: fix deadlock
between sd_remove & sd_release"), which was a partial fix for a similar
deadlock.
Reported-by: Sergey Senozhatsky <senozhatsky@chromium.org>
Suggested-by: Sergey Senozhatsky <senozhatsky@chromium.org>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Sergey Senozhatsky <senozhatsky@chromium.org>
---
block/genhd.c | 26 ++++++++++++++------------
1 file changed, 14 insertions(+), 12 deletions(-)
diff --git a/block/genhd.c b/block/genhd.c
index 7026569fa8a0be..c15e8f1163664b 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -655,16 +655,6 @@ void del_gendisk(struct gendisk *disk)
if (WARN_ON_ONCE(!disk_live(disk) && !(disk->flags & GENHD_FL_HIDDEN)))
return;
- disk_del_events(disk);
-
- /*
- * Prevent new openers by unlinked the bdev inode.
- */
- mutex_lock(&disk->open_mutex);
- xa_for_each(&disk->part_tbl, idx, part)
- bdev_unhash(part);
- mutex_unlock(&disk->open_mutex);
-
/*
* Tell the file system to write back all dirty data and shut down if
* it hasn't been notified earlier.
@@ -673,10 +663,22 @@ void del_gendisk(struct gendisk *disk)
blk_report_disk_dead(disk, false);
/*
- * Drop all partitions now that the disk is marked dead.
+ * Then mark the disk dead to stop new requests from being served ASAP.
+ * This needs to happen before taking ->open_mutex to prevent deadlocks
+ * with SCSI ULPs that send passthrough commands from their ->release
+ * methods.
*/
- mutex_lock(&disk->open_mutex);
__blk_mark_disk_dead(disk);
+
+ disk_del_events(disk);
+
+ /*
+ * Prevent new openers by unlinking the bdev inode, and drop all
+ * partitions.
+ */
+ mutex_lock(&disk->open_mutex);
+ xa_for_each(&disk->part_tbl, idx, part)
+ bdev_unhash(part);
xa_for_each_start(&disk->part_tbl, idx, part, 1)
drop_partition(part);
mutex_unlock(&disk->open_mutex);
--
2.45.2
next prev parent reply other threads:[~2024-10-09 11:38 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-09 11:38 try to avoid del_gendisk vs passthrough from ->release deadlocks v2 Christoph Hellwig
2024-10-09 11:38 ` [PATCH 1/2] block: also mark disk-owned queues as dying in __blk_mark_disk_dead Christoph Hellwig
2024-10-09 12:31 ` Sergey Senozhatsky
2024-10-09 12:41 ` Christoph Hellwig
2024-10-09 12:43 ` Sergey Senozhatsky
2024-10-09 13:49 ` Jens Axboe
2024-10-16 4:14 ` YangYang
2024-10-16 11:09 ` Ming Lei
2024-10-16 12:32 ` Christoph Hellwig
2024-10-16 12:49 ` Ming Lei
2024-10-16 13:35 ` Ming Lei
2024-10-19 1:25 ` Sergey Senozhatsky
2024-10-19 12:32 ` Ming Lei
2024-10-19 12:37 ` Sergey Senozhatsky
2024-10-19 12:50 ` Ming Lei
2024-10-19 12:58 ` Sergey Senozhatsky
2024-10-19 13:09 ` Ming Lei
2024-10-19 13:50 ` Sergey Senozhatsky
2024-10-19 15:03 ` Ming Lei
2024-10-19 15:11 ` Sergey Senozhatsky
2024-10-19 15:40 ` Sergey Senozhatsky
2024-10-28 5:44 ` Sergey Senozhatsky
2024-10-09 11:38 ` Christoph Hellwig [this message]
2024-10-16 4:15 ` [PATCH 2/2] block: mark the disk dead before taking open_mutx in del_gendisk YangYang
2024-10-16 2:09 ` try to avoid del_gendisk vs passthrough from ->release deadlocks v2 Sergey Senozhatsky
-- strict thread matches above, loose matches on Subject: below --
2024-10-08 11:57 RFC: try to avoid del_gendisk vs passthrough from ->release deadlocks Christoph Hellwig
2024-10-08 11:57 ` [PATCH 2/2] block: mark the disk dead before taking open_mutx in del_gendisk Christoph Hellwig
2024-10-09 5:04 ` Sergey Senozhatsky
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=20241009113831.557606-3-hch@lst.de \
--to=hch@lst.de \
--cc=axboe@kernel.dk \
--cc=linux-block@vger.kernel.org \
--cc=senozhatsky@chromium.org \
--cc=yang.yang@vivo.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;
as well as URLs for NNTP newsgroup(s).