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

Zhu Yanjun
2022-10-23T05:39:36Z

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 --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);
--
2.27.0