Skip to contentSkip to conversation

RDMA/core: check id_priv->restricted_node_type in cma_listen_on_dev()

PATCH Applied Stefan Metzmacher 2 participants 5 messages Feb 24 – Mar 2

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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 a760e80e90f5 ("RDMA/core: introduce rdma_restrict_node_type()")
Cc Jason Gunthorpe <[email protected]>
Cc Leon Romanovsky <[email protected]>
Cc Steve French <[email protected]>
Cc Namjae Jeon <[email protected]>
Cc Tom Talpey <[email protected]>
Cc Long Li <[email protected]>
---
 drivers/infiniband/core/cma.c | 6 +++++-
 include/rdma/rdma_cm.h        | 2 +-
 2 files changed, 6 insertions(+), 2 deletions(-)
drivers/infiniband/core/cma.c +5 -1
index e54c07c74575..9480d1a51c11 100644
@@ -2729,6 +2729,9 @@ static int cma_listen_on_dev(struct rdma_id_private *id_priv,
 	*to_destroy = NULL;
 	if (cma_family(id_priv) == AF_IB && !rdma_cap_ib_cm(cma_dev->device, 1))
 		return 0;
+	if (id_priv->restricted_node_type != RDMA_NODE_UNSPECIFIED &&
+	    id_priv->restricted_node_type != cma_dev->device->node_type)
+		return 0;
 
 	dev_id_priv =
 		__rdma_create_id(net, cma_listen_handler, id_priv,
@@ -2736,6 +2739,7 @@ static int cma_listen_on_dev(struct rdma_id_private *id_priv,
 	if (IS_ERR(dev_id_priv))
 		return PTR_ERR(dev_id_priv);
 
+	dev_id_priv->restricted_node_type = id_priv->restricted_node_type;
 	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)));
@@ -4194,7 +4198,7 @@ int rdma_restrict_node_type(struct rdma_cm_id *id, u8 node_type)
 	}
 
 	mutex_lock(&lock);
-	if (id_priv->cma_dev)
+	if (READ_ONCE(id_priv->state) != RDMA_CM_IDLE)
 		ret = -EALREADY;
 	else
 		id_priv->restricted_node_type = node_type;
include/rdma/rdma_cm.h +1 -1
index 6de6fd8bd15e..d639ff889e64 100644
@@ -181,7 +181,7 @@ void rdma_destroy_id(struct rdma_cm_id *id);
  *
  * It needs to be called before the RDMA identifier is bound
  * to an device, which mean it should be called before
- * rdma_bind_addr(), rdma_bind_addr() and rdma_listen().
+ * rdma_bind_addr(), rdma_resolve_addr() and rdma_listen().
  */
 int rdma_restrict_node_type(struct rdma_cm_id *id, u8 node_type);
 
Signature · 1 line
2.43.0
#1 lore raw
Quoted 24 lines · Stefan Metzmacher

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 a760e80e90f5 ("RDMA/core: introduce rdma_restrict_node_type()")
Cc Jason Gunthorpe <[email protected]>
Cc Leon Romanovsky <[email protected]>
Cc Steve French <[email protected]>
Cc Namjae Jeon <[email protected]>
Cc Tom Talpey <[email protected]>
Cc Long Li <[email protected]>
Quoted 4 lines
---
 drivers/infiniband/core/cma.c | 6 +++++-
 include/rdma/rdma_cm.h        | 2 +-
 2 files changed, 6 insertions(+), 2 deletions(-)

Applied, thanks.

#2 lore raw

Am 25.02.26 um 13:52 schrieb Leon Romanovsky:

Quoted 30 lines · Stefan Metzmacher
Quoted 24 lines

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 a760e80e90f5 ("RDMA/core: introduce rdma_restrict_node_type()")
Cc Jason Gunthorpe <[email protected]>
Cc Leon Romanovsky <[email protected]>
Cc Steve French <[email protected]>
Cc Namjae Jeon <[email protected]>
Cc Tom Talpey <[email protected]>
Cc Long Li <[email protected]>
Quoted 4 lines
---
  drivers/infiniband/core/cma.c | 6 +++++-
  include/rdma/rdma_cm.h        | 2 +-
  2 files changed, 6 insertions(+), 2 deletions(-)
Quoted 1 line

Applied, thanks.

Great!

Will this be scheduled for rc2?
Would be great as it fixes a regression in ksmbd
with iwarp.

Thanks!
metze

#3 lore raw
Quoted 31 lines · Stefan Metzmacher

Am 25.02.26 um 13:52 schrieb Leon Romanovsky:

Quoted 30 lines · Stefan Metzmacher
Quoted 28 lines

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 a760e80e90f5 ("RDMA/core: introduce rdma_restrict_node_type()")
Cc Jason Gunthorpe <[email protected]>
Cc Leon Romanovsky <[email protected]>
Cc Steve French <[email protected]>
Cc Namjae Jeon <[email protected]>
Cc Tom Talpey <[email protected]>
Cc Long Li <[email protected]>
---
  drivers/infiniband/core/cma.c | 6 +++++-
  include/rdma/rdma_cm.h        | 2 +-
  2 files changed, 6 insertions(+), 2 deletions(-)
Quoted 5 lines
Quoted 1 line

Applied, thanks.

Great!

Will this be scheduled for rc2?

I hope so, rdma-rc has a compilation fix which I would like to see in Linus's master as soon as possible.

Quoted 2 lines

Would be great as it fixes a regression in ksmbd
with iwarp.

Thanks

Quoted 3 lines

Thanks!
metze

#4 lore raw
Quoted 32 lines · Leon Romanovsky
Quoted 31 lines · Stefan Metzmacher

Am 25.02.26 um 13:52 schrieb Leon Romanovsky:

Quoted 30 lines · Stefan Metzmacher
Quoted 28 lines

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 a760e80e90f5 ("RDMA/core: introduce rdma_restrict_node_type()")
Cc Jason Gunthorpe <[email protected]>
Cc Leon Romanovsky <[email protected]>
Cc Steve French <[email protected]>
Cc Namjae Jeon <[email protected]>
Cc Tom Talpey <[email protected]>
Cc Long Li <[email protected]>
---
  drivers/infiniband/core/cma.c | 6 +++++-
  include/rdma/rdma_cm.h        | 2 +-
  2 files changed, 6 insertions(+), 2 deletions(-)
Quoted 8 lines
Quoted 5 lines
Quoted 1 line

Applied, thanks.

Great!

Will this be scheduled for rc2?

I hope so, rdma-rc has a compilation fix which I would like to see in Linus's master as soon as possible.

It was merged before -rc2:
e3c81bae4f28 ("Merge tag 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/rdma/rdma")
93a4a9b732fb ("RDMA/core: Check id_priv->restricted_node_type in cma_listen_on_dev()")

Thanks