Skip to content

Commit 93a4a9b

Browse files
metze-sambarleon
authored andcommitted
RDMA/core: Check id_priv->restricted_node_type in cma_listen_on_dev()
When listening on wildcard addresses we have a global list for the application layer rdma_cm_id and for any existing device or any device added in future we try to listen on any wildcard listener. When the listener has a restricted_node_type we should prevent listening on devices with a different node type. While there fix the documentation comment of rdma_restrict_node_type() to include rdma_resolve_addr() instead of having rdma_bind_addr() twice. Fixes: a760e80 ("RDMA/core: introduce rdma_restrict_node_type()") Cc: Jason Gunthorpe <jgg@ziepe.ca> Cc: Leon Romanovsky <leon@kernel.org> Cc: Steve French <smfrench@gmail.com> Cc: Namjae Jeon <linkinjeon@kernel.org> Cc: Tom Talpey <tom@talpey.com> Cc: Long Li <longli@microsoft.com> Cc: linux-rdma@vger.kernel.org Cc: linux-cifs@vger.kernel.org Cc: samba-technical@lists.samba.org Signed-off-by: Stefan Metzmacher <metze@samba.org> Link: https://patch.msgid.link/20260224165951.3582093-2-metze@samba.org Signed-off-by: Leon Romanovsky <leon@kernel.org>
1 parent faa7210 commit 93a4a9b

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

drivers/infiniband/core/cma.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2729,13 +2729,17 @@ static int cma_listen_on_dev(struct rdma_id_private *id_priv,
27292729
*to_destroy = NULL;
27302730
if (cma_family(id_priv) == AF_IB && !rdma_cap_ib_cm(cma_dev->device, 1))
27312731
return 0;
2732+
if (id_priv->restricted_node_type != RDMA_NODE_UNSPECIFIED &&
2733+
id_priv->restricted_node_type != cma_dev->device->node_type)
2734+
return 0;
27322735

27332736
dev_id_priv =
27342737
__rdma_create_id(net, cma_listen_handler, id_priv,
27352738
id_priv->id.ps, id_priv->id.qp_type, id_priv);
27362739
if (IS_ERR(dev_id_priv))
27372740
return PTR_ERR(dev_id_priv);
27382741

2742+
dev_id_priv->restricted_node_type = id_priv->restricted_node_type;
27392743
dev_id_priv->state = RDMA_CM_ADDR_BOUND;
27402744
memcpy(cma_src_addr(dev_id_priv), cma_src_addr(id_priv),
27412745
rdma_addr_size(cma_src_addr(id_priv)));
@@ -4194,7 +4198,7 @@ int rdma_restrict_node_type(struct rdma_cm_id *id, u8 node_type)
41944198
}
41954199

41964200
mutex_lock(&lock);
4197-
if (id_priv->cma_dev)
4201+
if (READ_ONCE(id_priv->state) != RDMA_CM_IDLE)
41984202
ret = -EALREADY;
41994203
else
42004204
id_priv->restricted_node_type = node_type;

include/rdma/rdma_cm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ void rdma_destroy_id(struct rdma_cm_id *id);
181181
*
182182
* It needs to be called before the RDMA identifier is bound
183183
* to an device, which mean it should be called before
184-
* rdma_bind_addr(), rdma_bind_addr() and rdma_listen().
184+
* rdma_bind_addr(), rdma_resolve_addr() and rdma_listen().
185185
*/
186186
int rdma_restrict_node_type(struct rdma_cm_id *id, u8 node_type);
187187

0 commit comments

Comments
 (0)