From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=144.76.82.148 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796244575; b=L/ogzGorlIkdS33peKyGkGLD9fZZXjfgpaxI7HOegqBNzW1E4C8T9x9lnkeYvM0Gkt7B bQP1HuCRmUFz3bKwMnAtopHTKCVovP2zMW7TnNm1rz703xV1HlVxK3TMsyz/l7qEoKCQI R1wVt45avb/+3uqQ0EAJB/e8d+gCdvMWtbHSZQMLeyRUCbSvaylvj+6D7rY9QlvwgLuHO fjxjKsNIoUZuDAAocTix0/5z7gCo23f0RicVAoGtuCgUhkJOCDciPg1XlqgeY7fIpyzQX J3ErIAK19UnTVw21I+yC5cCg2gYAq+0yKMwCb3Mge8HCWhGSDMs4C5LNT2CTLbb/Ypg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796244575; h=DMARC-Filter:DKIM-Signature:Received:From:To:Cc:Subject:Date: Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=k/VO1Y1RL9HdulWWcP+8G8Zw7slzte3H0VMK2p/4pZk=; b=lA4B0I+68BjUXwAw7DIuHIgph5uSsEdCaQ+4GbxHlXydIJEl/VWMzt24Nv1IkB/yaRvQ IdSRWSvelQZNgC6QiAXXKFgsWEQK1rrRpDL6Ym75fBP0d0FnwYKh52Kg4r/Q5ULKcBIGO CQ1PDC+NuuSATWlR3YwOOwt+d6acnh7wy8PmaCKtT3KMB9YChK0SOd4hUYu10H27j13s9 6MDvs08pxAk/igTnr9C04EKsjN5HL6mF9W3yBI5BKNYemRAjOxaQNOw+SBQyJVqqGiu5b B5mkz16tJNFaQxaLFcU3XomoidWSaM+IHs6KRxJYAhr60rGSpqR4y9r/aG6j6MHYSTA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=samba.org; spf=pass smtp.mailfrom=samba.org; dkim=pass header.d=samba.org header.i=@samba.org header.a=rsa-sha256 header.s=42 header.b=jTwFpWDb; arc=none smtp.remote-ip=144.76.82.148 Received: from hr2.samba.org (hr2.samba.org [144.76.82.148]) (using TLSv1.3 with cipher TLS_CHACHA20_POLY1305_SHA256 (256/256 bits) key-exchange ECDHE (prime256v1) server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C9B91606A338; Wed, 2 Dec 2026 20:49:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org C9B91606A338 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=samba.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samba.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (3072-bit key) header.d=samba.org header.i=@samba.org header.a=rsa-sha256 header.s=42 header.b=jTwFpWDb DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=samba.org; s=42; h=Message-ID:Date:Cc:To:From; bh=k/VO1Y1RL9HdulWWcP+8G8Zw7slzte3H0VMK2p/4pZk=; b=jTwFpWDbmtIg6Nqijvc780LV3L E9Klx152GHgaw9EbdM3GnlyD08oZa+w2SZbJv4qgme90HuUQa0i+l8Qe2myc5X/VM60tFUGkNIYp1 qsjqXJMtp31ytkw0PWLiSyiZHmFxdyVFZcpEBkN/G+s8D4MlJeARuiaQOReSHMsqFkGaRKUBB6uCH nBCFbbJLyQ+iRVGJKyyzPBNBdYRxMoq2z1dBDyXk1JYtHonljA1/C7ebwV9bEzXQs5+d1CwnuzfSu oyidvybp2WbxFJCepYVOf2g1jGn55OIY0o545DpmEhSc/f6JdGm/loCgAHiB4izAaFKSo9+CMbPwD rKCy5B71p/XqkqQr9kZQxlITAXw4geSs6cVM8x/gT9zF1Zw3rafkJUmnzuxSTY7SyweVIO1a5JDMD 8MtaXmsRYG0FBXLamOP0ORQQpNvflESU+sSFvFmetdH223EE0xKg78s5x0NumaH6V5AVp1/qcyMcs yYLczakoXm6B4HUP3nLhpdPF; Received: from [127.0.0.2] (localhost [127.0.0.1]) by hr2.samba.org with esmtpsa (TLS1.3:ECDHE_SECP256R1__ECDSA_SECP256R1_SHA256__CHACHA20_POLY1305:256) (Exim) id 1xYrGX-00000000nmz-3i4m; Wed, 02 Dec 2026 20:49:26 +0000 From: Stefan Metzmacher To: linux-cifs@vger.kernel.org, samba-technical@lists.samba.org Cc: metze@samba.org, stable@vger.kernel.org, Jason Gunthorpe , Leon Romanovsky , Namjae Jeon , linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 1/2] RDMA/cma: introduce rdma_set_iwpm() Date: Wed, 2 Dec 2026 21:49:11 +0100 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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. The port mapper itself is fine for its other users, their default stays unchanged. This is a prerequisite for a following smbdirect patch, smbdirect needs to operate on the fixed iWarp port 5445. Cc: stable@vger.kernel.org Cc: Jason Gunthorpe Cc: Leon Romanovsky Cc: Namjae Jeon Cc: linux-rdma@vger.kernel.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Stefan Metzmacher --- 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