* [PATCH] nvme-fc: initialize I/O queues added during reconnect
@ 2026-11-14 17:28 shao.mingyin
2026-11-20 17:43 ` Christoph Hellwig
2026-11-20 19:54 ` Keith Busch
0 siblings, 2 replies; 3+ messages in thread
From: shao.mingyin @ 2026-11-14 17:28 UTC (permalink / raw)
To: kbusch, axboe, hch, sagi, linux-nvme
Cc: linux-kernel, stable, justin.tee, nareshgottumukkala83, paul.ely
From: Shao Mingyin <shao.mingyin@zte.com.cn>
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@vger.kernel.org
Signed-off-by: Shao Mingyin <shao.mingyin@zte.com.cn>
---
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
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] nvme-fc: initialize I/O queues added during reconnect
2026-11-14 17:28 [PATCH] nvme-fc: initialize I/O queues added during reconnect shao.mingyin
@ 2026-11-20 17:43 ` Christoph Hellwig
2026-11-20 19:54 ` Keith Busch
1 sibling, 0 replies; 3+ messages in thread
From: Christoph Hellwig @ 2026-11-20 17:43 UTC (permalink / raw)
To: shao.mingyin
Cc: kbusch, axboe, sagi, linux-nvme, linux-kernel, stable, justin.tee,
nareshgottumukkala83, paul.ely
Looks good:
Reviewed-by: Christoph Hellwig <hch@lst.de>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] nvme-fc: initialize I/O queues added during reconnect
2026-11-14 17:28 [PATCH] nvme-fc: initialize I/O queues added during reconnect shao.mingyin
2026-11-20 17:43 ` Christoph Hellwig
@ 2026-11-20 19:54 ` Keith Busch
1 sibling, 0 replies; 3+ messages in thread
From: Keith Busch @ 2026-11-20 19:54 UTC (permalink / raw)
To: axboe, hch, sagi, linux-nvme, shao.mingyin
Cc: linux-kernel, stable, justin.tee, nareshgottumukkala83, paul.ely
On Sun, 15 Nov 2026 01:28:09 +0800 (CST), shao.mingyin@zte.com.cn wrote:
> 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.
>
> [...]
Thanks, applied to nvme-7.4.
[1/1] nvme-fc: initialize I/O queues added during reconnect
commit: 828408399e142ab52298317f478646dd61071aac
--
Keith Busch <kbusch@kernel.org>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-20 19:54 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-14 17:28 [PATCH] nvme-fc: initialize I/O queues added during reconnect shao.mingyin
2026-11-20 17:43 ` Christoph Hellwig
2026-11-20 19:54 ` Keith Busch
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox