blk-mq-debugfs: Fix warning about possible deadlock
PATCH 1/1 blk-mq-debugfs: Fix warning about possible deadlock
Commit 65d466b62984 ("blk-mq-debugfs: warn about possible deadlock") added WARN_ONCE_ON() to debugfs_create_files() to prevent potential deadlock if the queue is frozen. We hit this warning with the stacktrace below
WARNING: block/blk-mq-debugfs.c:620 at debugfs_create_files+0x9c/0x1d0 Workqueue: nvme-wq nvme_tcp_reconnect_ctrl_work [nvme_tcp] RIP: 0010:debugfs_create_files+0x9c/0x1d0 Call Trace: <TASK> blk_mq_debugfs_register_hctx+0x186/0x320 blk_mq_debugfs_register_hctxs+0x80/0xa0 blk_mq_update_nr_hw_queues+0xc8f/0xd50 nvme_tcp_setup_ctrl+0xcfa/0xda0 [nvme_tcp] nvme_tcp_reconnect_ctrl_work+0x51/0x180 [nvme_tcp] process_scheduled_works+0x840/0xd80 worker_thread+0x36d/0x4a0 kthread+0x366/0x380 ret_from_fork+0x7b/0x670 ret_from_fork_asm+0x1a/0x30 </TASK>
Here __blk_mq_update_nr_hw_queues() did set PF_MEMALLOC_NOIO flag before calling blk_mq_debugfs_register_hctxs() and this should guarantee the described deadlock will not happen. Warn only if the queue is frozen and NOIO flag is not set.
--- block/blk-mq-debugfs.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
block/blk-mq-debugfs.c +3 -1
@@ -612,12 +612,14 @@ static void debugfs_create_files(struct request_queue *q, struct dentry *parent,void *data, const struct blk_mq_debugfs_attr *attr) { + unsigned int pflags = READ_ONCE(current->flags); +lockdep_assert_held (&q->debugfs_mutex);/* * Creating new debugfs entries with queue freezed has the risk of * deadlock. */ -WARN_ON_ONCE (q->mq_freeze_depth !=0 ); +WARN_ON_ONCE ((q->mq_freeze_depth !=0 ) && !(pflags &PF_MEMALLOC_NOIO ));/* * debugfs_mutex should not be nested under other locks that can be * grabbed while queue is frozen.
base-commit: cd7a5651db263b5384aef1950898e5e889425134
Signature · 1 line
2.52.0
Quoted 54 lines · Mohamed Khalfella
Commit
65d466b62984("blk-mq-debugfs: warn about possible deadlock") addedWARN_ONCE_ON()todebugfs_create_files()to prevent potential deadlock if the queue is frozen. We hit this warning with the stacktrace belowWARNING: block/blk-mq-debugfs.c:620 at debugfs_create_files+0x9c/0x1d0 Workqueue: nvme-wq nvme_tcp_reconnect_ctrl_work [nvme_tcp] RIP: 0010:debugfs_create_files+0x9c/0x1d0 Call Trace: <TASK> blk_mq_debugfs_register_hctx+0x186/0x320 blk_mq_debugfs_register_hctxs+0x80/0xa0 blk_mq_update_nr_hw_queues+0xc8f/0xd50 nvme_tcp_setup_ctrl+0xcfa/0xda0 [nvme_tcp] nvme_tcp_reconnect_ctrl_work+0x51/0x180 [nvme_tcp] process_scheduled_works+0x840/0xd80 worker_thread+0x36d/0x4a0 kthread+0x366/0x380 ret_from_fork+0x7b/0x670 ret_from_fork_asm+0x1a/0x30 </TASK>Here
__blk_mq_update_nr_hw_queues()did setPF_MEMALLOC_NOIOflag before callingblk_mq_debugfs_register_hctxs()and this should guarantee the described deadlock will not happen. Warn only if the queue is frozen and NOIO flag is not set.Fixes 65d466b62984 ("blk-mq-debugfs: warn about possible deadlock")Signed-off-by Mohamed Khalfella <[email protected]>--- block/blk-mq-debugfs.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)block/blk-mq-debugfs.c +3
-1@@ -612,12 +612,14 @@ static void debugfs_create_files(struct request_queue *q, struct dentry *parent,void *data, const struct blk_mq_debugfs_attr *attr) { + unsigned int pflags = READ_ONCE(current->flags); +lockdep_assert_held (&q->debugfs_mutex);/* * Creating new debugfs entries with queue freezed has the risk of * deadlock. */ -WARN_ON_ONCE (q->mq_freeze_depth !=0 ); +WARN_ON_ONCE ((q->mq_freeze_depth !=0 ) && !(pflags &PF_MEMALLOC_NOIO ));/* * debugfs_mutex should not be nested under other locks that can be * grabbed while queue is frozen.
Quoted 1 line
base-commit:
cd7a5651db263b5384aef1950898e5e889425134
This issue is already being addressed here:
https://lore.kernel.org/all/[email protected]/
Thanks,
--Nilay
Quoted 57 lines · Nilay Shroff
Quoted 54 lines · Mohamed Khalfella
Commit
65d466b62984("blk-mq-debugfs: warn about possible deadlock") addedWARN_ONCE_ON()todebugfs_create_files()to prevent potential deadlock if the queue is frozen. We hit this warning with the stacktrace belowWARNING: block/blk-mq-debugfs.c:620 at debugfs_create_files+0x9c/0x1d0 Workqueue: nvme-wq nvme_tcp_reconnect_ctrl_work [nvme_tcp] RIP: 0010:debugfs_create_files+0x9c/0x1d0 Call Trace: <TASK> blk_mq_debugfs_register_hctx+0x186/0x320 blk_mq_debugfs_register_hctxs+0x80/0xa0 blk_mq_update_nr_hw_queues+0xc8f/0xd50 nvme_tcp_setup_ctrl+0xcfa/0xda0 [nvme_tcp] nvme_tcp_reconnect_ctrl_work+0x51/0x180 [nvme_tcp] process_scheduled_works+0x840/0xd80 worker_thread+0x36d/0x4a0 kthread+0x366/0x380 ret_from_fork+0x7b/0x670 ret_from_fork_asm+0x1a/0x30 </TASK>Here
__blk_mq_update_nr_hw_queues()did setPF_MEMALLOC_NOIOflag before callingblk_mq_debugfs_register_hctxs()and this should guarantee the described deadlock will not happen. Warn only if the queue is frozen and NOIO flag is not set.Fixes 65d466b62984 ("blk-mq-debugfs: warn about possible deadlock")Signed-off-by Mohamed Khalfella <[email protected]>--- block/blk-mq-debugfs.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)block/blk-mq-debugfs.c +3
-1@@ -612,12 +612,14 @@ static void debugfs_create_files(struct request_queue *q, struct dentry *parent,void *data, const struct blk_mq_debugfs_attr *attr) { + unsigned int pflags = READ_ONCE(current->flags); +lockdep_assert_held (&q->debugfs_mutex);/* * Creating new debugfs entries with queue freezed has the risk of * deadlock. */ -WARN_ON_ONCE (q->mq_freeze_depth !=0 ); +WARN_ON_ONCE ((q->mq_freeze_depth !=0 ) && !(pflags &PF_MEMALLOC_NOIO ));/* * debugfs_mutex should not be nested under other locks that can be * grabbed while queue is frozen.
Quoted 4 lines
Quoted 1 line
base-commit:
cd7a5651db263b5384aef1950898e5e889425134This issue is already being addressed here:
https://lore.kernel.org/all/[email protected]/
Got it. Thank you.