diff mbox series

[2/3] RDMA/core: The legacy IB devices still work with shared/exclusive mode

Message ID 20221023220450.2287909-3-yanjun.zhu@intel.com (mailing list archive)
State Changes Requested
Delegated to: Jason Gunthorpe
Headers show
Series RDMA net namespace | expand

Commit Message

Zhu Yanjun Oct. 23, 2022, 10:04 p.m. UTC
From: Zhu Yanjun <yanjun.zhu@linux.dev>

Other ib devices except legacy IB devices should work with its related
net devices. That is, these ib devices should be in the same net
namespace with the related net devices.

Signed-off-by: Zhu Yanjun <yanjun.zhu@linux.dev>
---
 drivers/infiniband/core/device.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/drivers/infiniband/core/device.c b/drivers/infiniband/core/device.c
index 59784fd10876..d38eb1fc2ed7 100644
--- a/drivers/infiniband/core/device.c
+++ b/drivers/infiniband/core/device.c
@@ -140,8 +140,13 @@  MODULE_PARM_DESC(netns_mode,
  */
 bool rdma_dev_access_netns(const struct ib_device *dev, const struct net *net)
 {
-	return (ib_devices_shared_netns ||
-		net_eq(read_pnet(&dev->coredev.rdma_net), net));
+	/* ib_devices_shared_netns is only for IB device. */
+	if (rdma_protocol_ib(dev, rdma_start_port(dev))) {
+		return (ib_devices_shared_netns ||
+			net_eq(read_pnet(&dev->coredev.rdma_net), net));
+	} else { /* Others device */
+		return net_eq(read_pnet(&dev->coredev.rdma_net), net);
+	}
 }
 EXPORT_SYMBOL(rdma_dev_access_netns);
 
@@ -2744,6 +2749,12 @@  static int rdma_netns_notify(struct notifier_block *not_blk,
 	if (!ibdev)
 		return NOTIFY_OK;
 
+	/* This will exclude IB device */
+	if (rdma_protocol_ib(ibdev, rdma_start_port(ibdev))) {
+		ib_device_put(ibdev);
+		return NOTIFY_OK;
+	}
+
 	switch (event) {
 	case NETDEV_REGISTER:
 		ib_device_put(ibdev);