mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Stefan Metzmacher <metze@samba.org>
To: linux-cifs@vger.kernel.org, samba-technical@lists.samba.org
Cc: metze@samba.org, stable@vger.kernel.org,
	Jason Gunthorpe <jgg@ziepe.ca>, Leon Romanovsky <leon@kernel.org>,
	Namjae Jeon <linkinjeon@kernel.org>,
	linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 1/2] RDMA/cma: introduce rdma_set_iwpm()
Date: Tue,  1 Dec 2026 17:27:11 +0100	[thread overview]
Message-ID: <9d31c3e2c2d367582b0b2af7a0988a77cb2a3962.1796142211.git.metze@samba.org> (raw)
In-Reply-To: <cover.1796142211.git.metze@samba.org>

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


  reply	other threads:[~2026-12-01 16:27 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2026-12-01 16:27 ` [PATCH 2/2] " Stefan Metzmacher

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=9d31c3e2c2d367582b0b2af7a0988a77cb2a3962.1796142211.git.metze@samba.org \
    --to=metze@samba.org \
    --cc=jgg@ziepe.ca \
    --cc=leon@kernel.org \
    --cc=linkinjeon@kernel.org \
    --cc=linux-cifs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=samba-technical@lists.samba.org \
    --cc=stable@vger.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®