Skip to contentSkip to conversation

block: skip sync_blockdev() on surprise removal in bdev_mark_dead()

PATCH Applied Chao Shi 4 participants 6 messages May 22 – May 27 Block layer

lore
Share & tools
lore

Chao Shi

author
#0 lore raw

PATCH 1/1 block: skip sync_blockdev() on surprise removal in bdev_mark_dead()

bdev_mark_dead()'s @surprise == true means the device is already gone. The filesystem callback fs_bdev_mark_dead() honours this and skips sync_filesystem(), but the bare block device path (no ->mark_dead op) lost its !surprise guard when the holder ->mark_dead callback was wired up (see Fixes), and now calls sync_blockdev() unconditionally, which can hang forever waiting on writeback that can no longer complete.

syzkaller hit this via nvme_reset_work()'s "I/O queues lost" path:
nvme_mark_namespaces_dead() -> blk_mark_disk_dead() -> bdev_mark_dead(bdev, true) -> sync_blockdev() blocks in folio_wait_writeback(), wedging the reset worker and every task waiting on it.

Skip the sync on surprise removal, matching fs_bdev_mark_dead(); invalidate_bdev() still runs. Orderly removal (surprise == false) is unchanged.

Fixes d8530de5a6e8 ("block: call into the file system for bdev_mark_dead")

Found by FuzzNvme(Syzkaller with FEMU fuzzing framework).

---
 block/bdev.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
block/bdev.c +7 -1
index b8fbb9576110..7fc3f5ba22a3 100644
@@ -1259,7 +1259,13 @@ void bdev_mark_dead(struct block_device *bdev, bool surprise)
 		bdev->bd_holder_ops->mark_dead(bdev, surprise);
 	else {
 		mutex_unlock(&bdev->bd_holder_lock);
-		sync_blockdev(bdev);
+		/*
+		 * On surprise removal the device is already gone; syncing is
+		 * futile and can hang forever waiting on I/O that will never
+		 * complete.  Match fs_bdev_mark_dead(), which also skips it.
+		 */
+		if (!surprise)
+			sync_blockdev(bdev);
 	}
 
 	invalidate_bdev(bdev);
Signature · 1 line
2.43.0
maintainer Applied
#3 lore raw
In reply to Chao Shi
Quoted 8 lines · Chao Shi

bdev_mark_dead()'s @surprise == true means the device is already gone. The filesystem callback fs_bdev_mark_dead() honours this and skips sync_filesystem(), but the bare block device path (no ->mark_dead op) lost its !surprise guard when the holder ->mark_dead callback was wired up (see Fixes), and now calls sync_blockdev() unconditionally, which can hang forever waiting on writeback that can no longer complete.

[...]

Applied, thanks!

[1/1] block: skip sync_blockdev() on surprise removal in bdev_mark_dead()

      commit: 304f384f34af98a205086ce67331cad4fea6504d

Best regards,

Signature · 1 line
Jens Axboe
author
#4 lore raw
In reply to Jens Axboe

Thanks Jens! I appreciate your work!.

Best,
Chao

Quoted 23 lines · Jens Axboe
Quoted 8 lines · Chao Shi

bdev_mark_dead()'s @surprise == true means the device is already gone. The filesystem callback fs_bdev_mark_dead() honours this and skips sync_filesystem(), but the bare block device path (no ->mark_dead op) lost its !surprise guard when the holder ->mark_dead callback was wired up (see Fixes), and now calls sync_blockdev() unconditionally, which can hang forever waiting on writeback that can no longer complete.

[...]

Applied, thanks!

[1/1] block: skip sync_blockdev() on surprise removal in bdev_mark_dead()

      commit: 304f384f34af98a205086ce67331cad4fea6504d

Best regards,
--
Jens Axboe

Reviewed-by on v1 1/1
#5 lore raw
In reply to Chao Shi
Quoted 17 lines · Chao Shi

bdev_mark_dead()'s @surprise == true means the device is already gone. The filesystem callback fs_bdev_mark_dead() honours this and skips sync_filesystem(), but the bare block device path (no ->mark_dead op) lost its !surprise guard when the holder ->mark_dead callback was wired up (see Fixes), and now calls sync_blockdev() unconditionally, which can hang forever waiting on writeback that can no longer complete.

syzkaller hit this via nvme_reset_work()'s "I/O queues lost" path:
nvme_mark_namespaces_dead() -> blk_mark_disk_dead() -> bdev_mark_dead(bdev, true) -> sync_blockdev() blocks in folio_wait_writeback(), wedging the reset worker and every task waiting on it.

Skip the sync on surprise removal, matching fs_bdev_mark_dead(); invalidate_bdev() still runs. Orderly removal (surprise == false) is unchanged.

Quoted 7 lines
Fixes d8530de5a6e8 ("block: call into the file system for bdev_mark_dead")

Found by FuzzNvme(Syzkaller with FEMU fuzzing framework).

---