* [PATCH 1/2] RDMA/cma: introduce rdma_set_iwpm()
2026-12-01 16:27 [PATCH 0/2] smb: smbdirect: don't use the iWarp port mapper Stefan Metzmacher
@ 2026-12-01 16:27 ` Stefan Metzmacher
2026-12-01 16:35 ` sashiko-bot
2026-12-01 16:27 ` [PATCH 2/2] smb: smbdirect: don't use the iWarp port mapper Stefan Metzmacher
2026-12-01 16:35 ` [PATCH 0/2] " sashiko-bot
2 siblings, 1 reply; 5+ messages in thread
From: Stefan Metzmacher @ 2026-12-01 16:27 UTC (permalink / raw)
To: linux-cifs, samba-technical
Cc: metze, stable, Jason Gunthorpe, Leon Romanovsky, Namjae Jeon,
linux-rdma, linux-kernel
If iwpmd is running, iw_cm_map() maps the local port of every
listening and connecting iw_cm_id and, for a connect, asks the
remote iwpmd for the mapped port of the remote listener.
For kernel users with a well known port, e.g. smbdirect using port
5445, this can be more harmful than helpful: if the state of the
iwpmd on both sides doesn't match the actual listeners, e.g. because
the listener was created before iwpmd was started, the connection
goes to a mapped port nobody listens on, while it works fine without
iwpmd.
Add iw_cm_id->skip_iwpm, which makes iw_cm_map() behave as if iwpmd
is not running for this iw_cm_id, and rdma_set_iwpm(), which lets
the upper layer decide whether iwpmd is used for an rdma_cm_id, by
setting iw_cm_id->skip_iwpm for the iw_cm_id used for rdma_listen()
and rdma_connect(). The setting is copied to the per device
listeners created by cma_listen_on_dev().
Like rdma_set_afonly() it needs to be called before rdma_listen() or
rdma_resolve_addr().
Without iwpmd the port of such an iw_cm_id is not reserved in the port
space of the host, so on iWarp devices sharing the IP addresses of the
host a TCP socket on the same port competes with it, like without
iwpmd running at all. For the well known port of a kernel service
that's what the administrator controls anyway.
Fixes: dce268ffcddc ("smb: smbdirect: introduce smbdirect_socket_init_{new,accepting}() and helpers")
Cc: stable@vger.kernel.org
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Cc: Leon Romanovsky <leon@kernel.org>
Cc: Namjae Jeon <linkinjeon@kernel.org>
Cc: linux-rdma@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Stefan Metzmacher <metze@samba.org>
---
drivers/infiniband/core/cma.c | 22 ++++++++++++++++++++++
drivers/infiniband/core/cma_priv.h | 1 +
drivers/infiniband/core/iwcm.c | 7 +++++++
include/rdma/iw_cm.h | 1 +
include/rdma/rdma_cm.h | 17 +++++++++++++++++
5 files changed, 48 insertions(+)
diff --git a/drivers/infiniband/core/cma.c b/drivers/infiniband/core/cma.c
index 337a49d1acf7..719b91eca088 100644
--- a/drivers/infiniband/core/cma.c
+++ b/drivers/infiniband/core/cma.c
@@ -2686,6 +2686,7 @@ static int cma_iw_listen(struct rdma_id_private *id_priv, int backlog)
id->tos_set = id_priv->tos_set;
mutex_unlock(&id_priv->qp_mutex);
id->afonly = id_priv->afonly;
+ id->skip_iwpm = id_priv->skip_iwpm;
id_priv->cm_id.iw = id;
memcpy(&id_priv->cm_id.iw->local_addr, cma_src_addr(id_priv),
@@ -2740,6 +2741,7 @@ static int cma_listen_on_dev(struct rdma_id_private *id_priv,
return PTR_ERR(dev_id_priv);
dev_id_priv->restricted_node_type = id_priv->restricted_node_type;
+ dev_id_priv->skip_iwpm = id_priv->skip_iwpm;
dev_id_priv->state = RDMA_CM_ADDR_BOUND;
memcpy(cma_src_addr(dev_id_priv), cma_src_addr(id_priv),
rdma_addr_size(cma_src_addr(id_priv)));
@@ -3648,6 +3650,25 @@ int rdma_set_afonly(struct rdma_cm_id *id, int afonly)
}
EXPORT_SYMBOL(rdma_set_afonly);
+int rdma_set_iwpm(struct rdma_cm_id *id, bool use_iwpm)
+{
+ struct rdma_id_private *id_priv;
+ unsigned long flags;
+ int ret;
+
+ id_priv = container_of(id, struct rdma_id_private, id);
+ spin_lock_irqsave(&id_priv->lock, flags);
+ if (id_priv->state == RDMA_CM_IDLE || id_priv->state == RDMA_CM_ADDR_BOUND) {
+ id_priv->skip_iwpm = !use_iwpm;
+ ret = 0;
+ } else {
+ ret = -EINVAL;
+ }
+ spin_unlock_irqrestore(&id_priv->lock, flags);
+ return ret;
+}
+EXPORT_SYMBOL(rdma_set_iwpm);
+
static void cma_bind_port(struct rdma_bind_list *bind_list,
struct rdma_id_private *id_priv)
{
@@ -4465,6 +4486,7 @@ static int cma_connect_iw(struct rdma_id_private *id_priv,
cm_id->tos = id_priv->tos;
cm_id->tos_set = id_priv->tos_set;
mutex_unlock(&id_priv->qp_mutex);
+ cm_id->skip_iwpm = id_priv->skip_iwpm;
id_priv->cm_id.iw = cm_id;
diff --git a/drivers/infiniband/core/cma_priv.h b/drivers/infiniband/core/cma_priv.h
index 04332eb82668..246d7340009a 100644
--- a/drivers/infiniband/core/cma_priv.h
+++ b/drivers/infiniband/core/cma_priv.h
@@ -73,6 +73,7 @@ struct rdma_id_private {
int internal_id;
enum rdma_cm_state state;
u8 restricted_node_type;
+ bool skip_iwpm;
spinlock_t lock;
struct mutex qp_mutex;
diff --git a/drivers/infiniband/core/iwcm.c b/drivers/infiniband/core/iwcm.c
index 4b05867dad89..d60878b79637 100644
--- a/drivers/infiniband/core/iwcm.c
+++ b/drivers/infiniband/core/iwcm.c
@@ -518,6 +518,13 @@ static int iw_cm_map(struct iw_cm_id *cm_id, bool active)
cm_id->m_local_addr = cm_id->local_addr;
cm_id->m_remote_addr = cm_id->remote_addr;
+ /*
+ * The upper layer doesn't want to use the port mapper,
+ * act as if iwpmd is not running.
+ */
+ if (cm_id->skip_iwpm)
+ return 0;
+
strscpy(pm_reg_msg.dev_name, devname);
strscpy(pm_reg_msg.if_name, ifname);
diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
index 57b33edd9ce7..fc6db7c8a795 100644
--- a/include/rdma/iw_cm.h
+++ b/include/rdma/iw_cm.h
@@ -71,6 +71,7 @@ struct iw_cm_id {
bool tos_set:1;
bool mapped:1;
bool afonly:1;
+ bool skip_iwpm:1; /* don't use the iWarp port mapper */
};
struct iw_cm_conn_param {
diff --git a/include/rdma/rdma_cm.h b/include/rdma/rdma_cm.h
index d639ff889e64..3ed197624cf3 100644
--- a/include/rdma/rdma_cm.h
+++ b/include/rdma/rdma_cm.h
@@ -377,6 +377,23 @@ int rdma_set_reuseaddr(struct rdma_cm_id *id, int reuse);
*/
int rdma_set_afonly(struct rdma_cm_id *id, int afonly);
+/**
+ * rdma_set_iwpm - Specify if the iWarp port mapper (iwpmd) is used
+ * @id: Communication identifier to configure.
+ * @use_iwpm: true (default) to use iwpmd if it is running,
+ * false to never use it, as if iwpmd is not running.
+ *
+ * Without iwpmd the iWarp device listens on and connects to the
+ * requested ports directly, which is what users of well known
+ * ports might want.
+ *
+ * Like rdma_set_afonly() it needs to be called before rdma_listen()
+ * or rdma_resolve_addr().
+ *
+ * Return: 0 on success, -EINVAL if called too late.
+ */
+int rdma_set_iwpm(struct rdma_cm_id *id, bool use_iwpm);
+
int rdma_set_ack_timeout(struct rdma_cm_id *id, u8 timeout);
int rdma_set_min_rnr_timer(struct rdma_cm_id *id, u8 min_rnr_timer);
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH 2/2] smb: smbdirect: don't use the iWarp port mapper
2026-12-01 16:27 [PATCH 0/2] smb: smbdirect: don't use the iWarp port mapper Stefan Metzmacher
2026-12-01 16:27 ` [PATCH 1/2] RDMA/cma: introduce rdma_set_iwpm() Stefan Metzmacher
@ 2026-12-01 16:27 ` Stefan Metzmacher
2026-12-01 16:35 ` [PATCH 0/2] " sashiko-bot
2 siblings, 0 replies; 5+ messages in thread
From: Stefan Metzmacher @ 2026-12-01 16:27 UTC (permalink / raw)
To: linux-cifs, samba-technical
Cc: metze, stable, Namjae Jeon, Paulo Alcantara, Tom Talpey,
Jason Gunthorpe, Leon Romanovsky, linux-rdma, linux-kernel
smbdirect uses the well known port 5445 for iWarp. If iwpmd is
running, the listener is mapped to another port and a client asks
the remote iwpmd for the mapped port of the remote listener, which
only works if the state of both sides matches. E.g. a listener
created before iwpmd was started is not mapped, but the remote
iwpmd still hands out a mapped port, so the connection goes to a
port nobody listens on.
Use rdma_set_iwpm(false), so iWarp devices always listen on and
connect to the requested ports.
Fixes: dce268ffcddc ("smb: smbdirect: introduce smbdirect_socket_init_{new,accepting}() and helpers")
Cc: stable@vger.kernel.org
Cc: Namjae Jeon <linkinjeon@kernel.org>
Cc: Paulo Alcantara <pc@manguebit.org>
Cc: Tom Talpey <tom@talpey.com>
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Cc: Leon Romanovsky <leon@kernel.org>
Cc: linux-cifs@vger.kernel.org
Cc: samba-technical@lists.samba.org
Cc: linux-rdma@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Stefan Metzmacher <metze@samba.org>
---
fs/smb/smbdirect/socket.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/fs/smb/smbdirect/socket.c b/fs/smb/smbdirect/socket.c
index 13cf50b96bc9..837883192857 100644
--- a/fs/smb/smbdirect/socket.c
+++ b/fs/smb/smbdirect/socket.c
@@ -76,6 +76,18 @@ int smbdirect_socket_init_new(struct net *net, struct smbdirect_socket *sc)
return ret;
}
+ /*
+ * Never use the iWarp port mapper (iwpmd), so an iWarp device
+ * listens on and connects to the ports we ask for, e.g. 5445.
+ */
+ ret = rdma_set_iwpm(id, false);
+ if (ret) {
+ rdma_destroy_id(id);
+ pr_err("%s: rdma_set_iwpm() failed %1pe\n",
+ __func__, SMBDIRECT_DEBUG_ERR_PTR(ret));
+ return ret;
+ }
+
sc->rdma.cm_id = id;
INIT_WORK(&sc->disconnect_work, smbdirect_socket_cleanup_work);
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread