Yang Yang
5a5625a83e
block: fix deadlock between sd_remove & sd_release
commit 7e04da2dc7 upstream.
Our test report the following hung task:
[ 2538.459400] INFO: task "kworker/0:0":7 blocked for more than 188 seconds.
[ 2538.459427] Call trace:
[ 2538.459430] __switch_to+0x174/0x338
[ 2538.459436] __schedule+0x628/0x9c4
[ 2538.459442] schedule+0x7c/0xe8
[ 2538.459447] schedule_preempt_disabled+0x24/0x40
[ 2538.459453] __mutex_lock+0x3ec/0xf04
[ 2538.459456] __mutex_lock_slowpath+0x14/0x24
[ 2538.459459] mutex_lock+0x30/0xd8
[ 2538.459462] del_gendisk+0xdc/0x350
[ 2538.459466] sd_remove+0x30/0x60
[ 2538.459470] device_release_driver_internal+0x1c4/0x2c4
[ 2538.459474] device_release_driver+0x18/0x28
[ 2538.459478] bus_remove_device+0x15c/0x174
[ 2538.459483] device_del+0x1d0/0x358
[ 2538.459488] __scsi_remove_device+0xa8/0x198
[ 2538.459493] scsi_forget_host+0x50/0x70
[ 2538.459497] scsi_remove_host+0x80/0x180
[ 2538.459502] usb_stor_disconnect+0x68/0xf4
[ 2538.459506] usb_unbind_interface+0xd4/0x280
[ 2538.459510] device_release_driver_internal+0x1c4/0x2c4
[ 2538.459514] device_release_driver+0x18/0x28
[ 2538.459518] bus_remove_device+0x15c/0x174
[ 2538.459523] device_del+0x1d0/0x358
[ 2538.459528] usb_disable_device+0x84/0x194
[ 2538.459532] usb_disconnect+0xec/0x300
[ 2538.459537] hub_event+0xb80/0x1870
[ 2538.459541] process_scheduled_works+0x248/0x4dc
[ 2538.459545] worker_thread+0x244/0x334
[ 2538.459549] kthread+0x114/0x1bc
[ 2538.461001] INFO: task "fsck.":15415 blocked for more than 188 seconds.
[ 2538.461014] Call trace:
[ 2538.461016] __switch_to+0x174/0x338
[ 2538.461021] __schedule+0x628/0x9c4
[ 2538.461025] schedule+0x7c/0xe8
[ 2538.461030] blk_queue_enter+0xc4/0x160
[ 2538.461034] blk_mq_alloc_request+0x120/0x1d4
[ 2538.461037] scsi_execute_cmd+0x7c/0x23c
[ 2538.461040] ioctl_internal_command+0x5c/0x164
[ 2538.461046] scsi_set_medium_removal+0x5c/0xb0
[ 2538.461051] sd_release+0x50/0x94
[ 2538.461054] blkdev_put+0x190/0x28c
[ 2538.461058] blkdev_release+0x28/0x40
[ 2538.461063] __fput+0xf8/0x2a8
[ 2538.461066] __fput_sync+0x28/0x5c
[ 2538.461070] __arm64_sys_close+0x84/0xe8
[ 2538.461073] invoke_syscall+0x58/0x114
[ 2538.461078] el0_svc_common+0xac/0xe0
[ 2538.461082] do_el0_svc+0x1c/0x28
[ 2538.461087] el0_svc+0x38/0x68
[ 2538.461090] el0t_64_sync_handler+0x68/0xbc
[ 2538.461093] el0t_64_sync+0x1a8/0x1ac
T1: T2:
sd_remove
del_gendisk
__blk_mark_disk_dead
blk_freeze_queue_start
++q->mq_freeze_depth
bdev_release
mutex_lock(&disk->open_mutex)
sd_release
scsi_execute_cmd
blk_queue_enter
wait_event(!q->mq_freeze_depth)
mutex_lock(&disk->open_mutex)
SCSI does not set GD_OWNS_QUEUE, so QUEUE_FLAG_DYING is not set in
this scenario. This is a classic ABBA deadlock. To fix the deadlock,
make sure we don't try to acquire disk->open_mutex after freezing
the queue.
Cc: stable@vger.kernel.org
Fixes: eec1be4c30 ("block: delete partitions later in del_gendisk")
Signed-off-by: Yang Yang <yang.yang@vivo.com>
Reviewed-by: Ming Lei <ming.lei@redhat.com>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Fixes: and Cc: stable tags are missing. Otherwise this patch looks fine
Link: https://lore.kernel.org/r/20240724070412.22521-1-yang.yang@vivo.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2024-08-03 08:54:24 +02:00
..
2024-06-12 11:11:35 +02:00
2022-04-23 07:15:26 -06:00
2024-03-26 18:19:40 -04:00
2023-04-13 06:46:49 -06:00
2023-06-30 11:57:07 -07:00
2023-04-06 16:17:32 -06:00
2023-01-29 15:18:33 -07:00
2024-08-03 08:53:20 +02:00
2024-04-03 15:28:27 +02:00
2023-06-01 09:13:31 -06:00
2023-02-14 14:24:09 -07:00
2022-07-14 12:14:30 -06:00
2024-06-12 11:12:46 +02:00
2024-04-17 11:19:28 +02:00
2024-06-12 11:11:35 +02:00
2023-08-18 15:00:39 -06:00
2023-03-16 09:35:09 -06:00
2023-07-05 16:36:12 -06:00
2023-02-09 09:38:16 -07:00
2023-03-16 09:35:09 -06:00
2024-06-21 14:38:35 +02:00
2023-02-09 09:38:16 -07:00
2023-04-26 18:22:50 -06:00
2023-06-07 07:51:00 -06:00
2024-05-17 12:02:20 +02:00
2023-08-10 17:24:53 -06:00
2023-06-06 22:26:26 -06:00
2022-09-26 19:09:31 -06:00
2022-09-15 00:25:17 -06:00
2024-03-01 13:34:49 +01:00
2024-06-12 11:11:35 +02:00
2023-04-13 06:52:29 -06:00
2022-07-06 06:46:26 -06:00
2023-06-12 09:55:53 -06:00
2022-06-17 07:31:05 -06:00
2023-04-13 06:52:29 -06:00
2023-04-13 06:57:18 -06:00
2023-05-18 19:42:54 -06:00
2023-04-13 06:52:29 -06:00
2023-06-26 12:47:20 -07:00
2023-04-13 06:52:29 -06:00
2024-08-03 08:53:22 +02:00
2023-06-12 09:55:53 -06:00
2023-04-13 06:52:29 -06:00
2021-02-22 06:33:48 -07:00
2023-09-18 14:15:28 -06:00
2023-04-13 06:46:49 -06:00
2024-04-03 15:28:20 +02:00
2024-04-13 13:07:37 +02:00
2021-12-14 17:23:05 -07:00
2023-07-17 08:18:18 -06:00
2023-12-20 17:01:55 +01:00
2023-08-30 10:15:01 -06:00
2020-07-31 16:29:47 -06:00
2024-02-23 09:25:16 +01:00
2023-06-26 09:53:36 -06:00
2023-07-11 12:15:15 -04:00
2024-06-12 11:11:35 +02:00
2022-08-02 17:22:54 -06:00
2023-06-12 08:04:04 -06:00
2023-06-30 11:57:07 -07:00
2023-09-26 00:43:34 -06:00
2023-06-22 09:09:33 -06:00
2023-08-19 07:47:17 -06:00
2023-04-13 06:52:30 -06:00
2024-06-12 11:11:35 +02:00
2024-08-03 08:54:24 +02:00
2022-11-16 15:19:56 -07:00
2024-06-27 13:49:01 +02:00
2023-06-16 12:04:30 -04:00
2023-08-22 11:10:26 -06:00
2023-01-30 09:42:42 -07:00
2023-04-13 06:52:30 -06:00
2023-06-05 10:57:40 -06:00
2024-08-03 08:53:22 +02:00
2024-03-26 18:19:12 -04:00
2024-06-21 14:38:35 +02:00
2022-03-07 12:48:35 -07:00