From: Christian Aurich Zanettini Martins <christian.aurichzm@gmail.com>
To: linux-nvme@lists.infradead.org
Cc: kbusch@kernel.org, axboe@kernel.dk, hch@lst.de, sagi@grimberg.me,
hare@kernel.org, sgogte@purestorage.com, wagi@kernel.org,
linux-kernel@vger.kernel.org,
Christian Aurich Zanettini Martins <christian.aurichzm@gmail.com>
Subject: [PATCH] nvme-tcp: fix NULL queue->ctrl dereference on reconnect
Date: Tue, 27 Oct 2026 21:26:54 -0300 [thread overview]
Message-ID: <20261028002654.1077190-1-christian.aurichzm@gmail.com> (raw)
Since commit 61b0ed3be81b ("nvme-tcp: parallelize I/O queue allocation
and startup"), a reconnect that gets more I/O queues than before grows
the tag set before the new queues are allocated. queue->ctrl is only
set by nvme_tcp_alloc_queue(), so I/O submitted in between reaches
nvme_tcp_queue_rq() on a queue that was never allocated and
dereferences a NULL queue->ctrl:
BUG: kernel NULL pointer dereference, address: 00000000000002ac
RIP: 0010:nvme_tcp_queue_rq+0x33/0x3b0
Add nvme_tcp_init_queue() for the queue fields that do not depend on
the connection (ctrl, pf_cache_lock and both digests) and call it for
every queue when allocating the controller. Such requests are then
requeued like on any other queue that is not live.
Fixes: 61b0ed3be81b ("nvme-tcp: parallelize I/O queue allocation and startup")
Suggested-by: Keith Busch <kbusch@kernel.org>
Signed-off-by: Christian Aurich Zanettini Martins <christian.aurichzm@gmail.com>
---
Keith suggested the helper when applying "nvme-tcp: fix request PDU
size when header digest is enabled". Based on nvme-7.4 (9afc1b71d963)
with that patch on top.
Reproduced in QEMU with nvmet-tcp over loopback and
CONFIG_NVME_MULTIPATH=n: connect with attr_qid_max=2, keep direct reads
running on the CPUs that map to the new hw queues, then raise
attr_qid_max to 4. Before the patch the host oopsed as above within two
tries in each of three boots; after it, 8 of 8 tries went live. Digest
I/O, the 2 to 4 queue grow and 30 resets under I/O also pass, and the
grow and reset runs are clean with lockdep enabled.
drivers/nvme/host/tcp.c | 31 ++++++++++++++++++-------------
1 file changed, 18 insertions(+), 13 deletions(-)
diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c
index 191e5811d25e..46816a9fb2bf 100644
--- a/drivers/nvme/host/tcp.c
+++ b/drivers/nvme/host/tcp.c
@@ -1977,6 +1977,22 @@ static int nvme_tcp_start_tls(struct nvme_ctrl *nctrl,
return ret;
}
+/*
+ * The I/O tag set is allocated, and grown on reconnect, before the queues are
+ * connected, so blk-mq can initialize requests on a queue, and dispatch to it,
+ * before nvme_tcp_alloc_queue() has run for it. Set up the fields that do not
+ * depend on the connection once, when allocating the controller.
+ */
+static void nvme_tcp_init_queue(struct nvme_tcp_ctrl *ctrl, int qid)
+{
+ struct nvme_tcp_queue *queue = &ctrl->queues[qid];
+
+ queue->ctrl = ctrl;
+ mutex_init(&queue->pf_cache_lock);
+ queue->hdr_digest = ctrl->ctrl.opts->hdr_digest;
+ queue->data_digest = ctrl->ctrl.opts->data_digest;
+}
+
static int nvme_tcp_alloc_queue(struct nvme_ctrl *nctrl, int qid,
key_serial_t pskid)
{
@@ -1986,7 +2002,6 @@ static int nvme_tcp_alloc_queue(struct nvme_ctrl *nctrl, int qid,
struct file *sock_file;
mutex_init(&queue->queue_lock);
- queue->ctrl = ctrl;
init_llist_head(&queue->req_list);
INIT_LIST_HEAD(&queue->send_list);
mutex_init(&queue->send_mutex);
@@ -2079,8 +2094,6 @@ static int nvme_tcp_alloc_queue(struct nvme_ctrl *nctrl, int qid,
}
}
- queue->data_digest = nctrl->opts->data_digest;
-
rcv_pdu_size = sizeof(struct nvme_tcp_rsp_pdu) +
nvme_tcp_hdgst_len(queue);
queue->pdu = kmalloc(rcv_pdu_size, GFP_KERNEL);
@@ -3225,16 +3238,8 @@ static struct nvme_tcp_ctrl *nvme_tcp_alloc_ctrl(struct device *dev,
goto out_free_ctrl;
}
- /*
- * The I/O tag set is allocated before the I/O queues, and initializing
- * its requests already allocates the PDUs from the page frag caches of
- * the queues, sized by their header digest setting, so set up the
- * locks and hdr_digest here.
- */
- for (i = 0; i < ctrl->ctrl.queue_count; i++) {
- mutex_init(&ctrl->queues[i].pf_cache_lock);
- ctrl->queues[i].hdr_digest = opts->hdr_digest;
- }
+ for (i = 0; i < ctrl->ctrl.queue_count; i++)
+ nvme_tcp_init_queue(ctrl, i);
ctrl->net = get_net(current->nsproxy->net_ns);
--
2.43.0
next reply other threads:[~2026-10-28 0:27 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-28 0:26 Christian Aurich Zanettini Martins [this message]
2026-10-28 1:48 ` Keith Busch
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261028002654.1077190-1-christian.aurichzm@gmail.com \
--to=christian.aurichzm@gmail.com \
--cc=axboe@kernel.dk \
--cc=hare@kernel.org \
--cc=hch@lst.de \
--cc=kbusch@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nvme@lists.infradead.org \
--cc=sagi@grimberg.me \
--cc=sgogte@purestorage.com \
--cc=wagi@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®