[PATCH 2/2] nvme: don't do scan work if io queue count is zero

Ruozhu Li liruozhu at huawei.com
Tue Aug 3 02:06:30 PDT 2021


kernel panic when try to rescan ns when io queue count is zero.Because
kernel BUG_ON when hctx_idx is greater than ctrl->queue_count.
--
nvme_rdma_init_hctx+0x58/0x60 [nvme_rdma]
blk_mq_realloc_hw_ctxs+0x140/0x4c0
blk_mq_init_allocated_queue+0x130/0x410
blk_mq_init_queue+0x40/0x88
nvme_validate_ns+0xb8/0x740
nvme_scan_work+0x29c/0x460
process_one_work+0x1f8/0x490
worker_thread+0x50/0x4b8
kthread+0x134/0x138
ret_from_fork+0x10/0x18
--
Defence it by not allowing rescan ns when io queue count is zero.

Signed-off-by: Ruozhu Li <liruozhu at huawei.com>
---
 drivers/nvme/host/core.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index dfd9dec0c1f6..d9f837eb3e26 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -141,7 +141,8 @@ void nvme_queue_scan(struct nvme_ctrl *ctrl)
 	/*
 	 * Only new queue scan work when admin and IO queues are both alive
 	 */
-	if (ctrl->state == NVME_CTRL_LIVE && ctrl->tagset)
+	if (ctrl->state == NVME_CTRL_LIVE &&
+	    ctrl->tagset && ctrl->queue_count > 1)
 		queue_work(nvme_wq, &ctrl->scan_work);
 }
 
@@ -4047,7 +4048,8 @@ static void nvme_scan_work(struct work_struct *work)
 		container_of(work, struct nvme_ctrl, scan_work);
 
 	/* No tagset on a live ctrl means IO queues could not created */
-	if (ctrl->state != NVME_CTRL_LIVE || !ctrl->tagset)
+	if (ctrl->state != NVME_CTRL_LIVE ||
+	    !ctrl->tagset || ctrl->queue_count < 2)
 		return;
 
 	if (test_and_clear_bit(NVME_AER_NOTICE_NS_CHANGED, &ctrl->events)) {
-- 
2.16.4




More information about the Linux-nvme mailing list