From: Hannes Reinecke <hare@kernel.org>
To: Christoph Hellwig <hch@lst.de>
Cc: Keith Busch <kbusch@kernel.org>, Sagi Grimberg <sagi@grimberg.me>,
linux-nvme@lists.infradead.org, Hannes Reinecke <hare@kernel.org>
Subject: [PATCH] nvme-rdma: use current network namespace
Date: Wed, 25 Nov 2026 15:17:37 +0100 [thread overview]
Message-ID: <20261125141737.2383-1-hare@kernel.org> (raw)
Creating the connection manager in the initial network namespace
will result in expected issues when running with network namespaces.
So capture the current network namespace when setting up the
connection manager to ensure we're accessing the right information.
Fixes: 711023071960 ("nvme-rdma: add a NVMe over Fabrics RDMA host driver")
Signed-off-by: Hannes Reinecke <hare@kernel.org>
---
drivers/nvme/host/rdma.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/drivers/nvme/host/rdma.c b/drivers/nvme/host/rdma.c
index 32189fdfc0f5..76b4cba80b36 100644
--- a/drivers/nvme/host/rdma.c
+++ b/drivers/nvme/host/rdma.c
@@ -133,6 +133,7 @@ struct nvme_rdma_ctrl {
u32 max_fr_pages;
+ struct net *net;
struct sockaddr_storage addr;
struct sockaddr_storage src_addr;
@@ -595,8 +596,8 @@ static int nvme_rdma_alloc_queue(struct nvme_rdma_queue *queue)
else
queue->cmnd_capsule_len = sizeof(struct nvme_command);
- queue->cm_id = rdma_create_id(&init_net, nvme_rdma_cm_handler, queue,
- RDMA_PS_TCP, IB_QPT_RC);
+ queue->cm_id = rdma_create_id(ctrl->net, nvme_rdma_cm_handler,
+ queue, RDMA_PS_TCP, IB_QPT_RC);
if (IS_ERR(queue->cm_id)) {
dev_info(ctrl->ctrl.device,
"failed to create CM ID: %ld\n", PTR_ERR(queue->cm_id));
@@ -2288,6 +2289,8 @@ static struct nvme_rdma_ctrl *nvme_rdma_alloc_ctrl(struct device *dev,
if (!ctrl)
return ERR_PTR(-ENOMEM);
ctrl->ctrl.opts = opts;
+ ctrl->net = get_net(current->nsproxy->net_ns);
+
/*
* Safe to init list while allocating ctrl object.
*/
@@ -2303,7 +2306,7 @@ static struct nvme_rdma_ctrl *nvme_rdma_alloc_ctrl(struct device *dev,
opts->mask |= NVMF_OPT_TRSVCID;
}
- ret = inet_pton_with_scope(&init_net, AF_UNSPEC,
+ ret = inet_pton_with_scope(ctrl->net, AF_UNSPEC,
opts->traddr, opts->trsvcid, &ctrl->addr);
if (ret) {
pr_err("malformed address passed: %s:%s\n",
@@ -2312,7 +2315,7 @@ static struct nvme_rdma_ctrl *nvme_rdma_alloc_ctrl(struct device *dev,
}
if (opts->mask & NVMF_OPT_HOST_TRADDR) {
- ret = inet_pton_with_scope(&init_net, AF_UNSPEC,
+ ret = inet_pton_with_scope(ctrl->net, AF_UNSPEC,
opts->host_traddr, NULL, &ctrl->src_addr);
if (ret) {
pr_err("malformed src address passed: %s\n",
@@ -2354,6 +2357,7 @@ static struct nvme_rdma_ctrl *nvme_rdma_alloc_ctrl(struct device *dev,
out_kfree_queues:
kfree(ctrl->queues);
out_free_ctrl:
+ put_net(ctrl->net);
kfree(ctrl);
return ERR_PTR(ret);
}
--
2.51.0
next reply other threads:[~2026-11-25 14:17 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 14:17 Hannes Reinecke [this message]
2026-11-25 14:25 ` [PATCH] nvme-rdma: use current network namespace sashiko-bot
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=20261125141737.2383-1-hare@kernel.org \
--to=hare@kernel.org \
--cc=hch@lst.de \
--cc=kbusch@kernel.org \
--cc=linux-nvme@lists.infradead.org \
--cc=sagi@grimberg.me \
/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