[PATCH] nvme-fc: initialize I/O queues added during reconnect
From: shao.mingyin
Date: Sat Nov 14 2026 - 12:29:15 EST
From: Shao Mingyin <shao.mingyin@xxxxxxxxxx>
nvme_fc_alloc_ctrl() initializes only the admin queue and leaves the
other nvme_fc_queue entries zeroed. The initial connect path calls
nvme_fc_init_io_queues() before creating the tag set, but reconnects go
through nvme_fc_recreate_io_queues(), which does not initialize the
queues it adds when the controller grants more I/O queues than the
previous connection.
blk_mq_update_nr_hw_queues() then publishes the new hardware contexts
while the corresponding queue entries still have qnum == 0 and
ctrl == NULL. nvme_fc_connect_io_queues() builds Create Connection
commands from qnum, so the new queues are connected with queue ID 0
(the admin queue), and __nvme_fc_init_request() also classifies their
requests as admin commands. Worse, nvme_fc_queue_rq() dereferences
queue->ctrl, so any request dispatched to a new hardware context before
the queue is initialized crashes. This includes the connect requests
themselves, since connect_q belongs to the same tag set.
Initialize the newly added queues before growing the tag set, matching
what the initial connect path does. Existing queues are left alone so
their connection state is preserved, as required by
nvme_fc_recreate_io_queues().
Fixes: 3e493c00cedb ("nvme-fc: fix nulling of queue data on reconnect")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Shao Mingyin <shao.mingyin@xxxxxxxxxx>
---
Tested on 7.3.0-next-20261030 with nvmet-fcloop in a single QEMU/TCG
guest (2 vCPUs); no FC or network hardware is involved.
The controller is created with one I/O queue (attr_qid_max=1), then
attr_qid_max=2 deletes it and forces a reconnect that grants two
queues, so nvme_fc_recreate_io_queues() grows the tag set from 1 to 2:
unpatched patched
nvme0: reconnect: revising io queue same
count from 1 to 2
Oops: 0000 [#1] SMP NOPTI no oops, 6/6 cycles
Workqueue: nvme-wq
nvme_fc_connect_ctrl_work
RIP: nvme_fc_queue_rq+0x21/0x190 queue_count=3
CR2: 0000000000000020 I/O from cpu1, ret=0
Kernel panic - not syncing
The NULL dereference is the Create Connection for the new queue: it
goes through ctrl->connect_q, which shares the tag set, and is
dispatched to the new hctx whose queue->ctrl is still NULL. CR2 is
0x20, the offset nvme_check_ready() reads. The target also warns about
a duplicate queue id on the same reconnect, because the new queue is
connected with queue ID 0 instead of 2.
drivers/nvme/host/fc.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/nvme/host/fc.c b/drivers/nvme/host/fc.c
index 0b9ff50d26ff..f3603c793ede 100644
--- a/drivers/nvme/host/fc.c
+++ b/drivers/nvme/host/fc.c
@@ -2932,7 +2932,7 @@ nvme_fc_recreate_io_queues(struct nvme_fc_ctrl *ctrl)
struct nvmf_ctrl_options *opts = ctrl->ctrl.opts;
u32 prior_ioq_cnt = ctrl->ctrl.queue_count - 1;
unsigned int nr_io_queues;
- int ret;
+ int ret, i;
nr_io_queues = min3(opts->nr_io_queues, num_online_cpus(),
ctrl->lport->ops->max_hw_queues);
@@ -2959,6 +2959,8 @@ nvme_fc_recreate_io_queues(struct nvme_fc_ctrl *ctrl)
dev_info(ctrl->ctrl.device,
"reconnect: revising io queue count from %d to %d\n",
prior_ioq_cnt, nr_io_queues);
+ for (i = prior_ioq_cnt + 1; i <= nr_io_queues; i++)
+ nvme_fc_init_queue(ctrl, i);
blk_mq_update_nr_hw_queues(&ctrl->tag_set, nr_io_queues);
}
--
2.43.0