From: Zhu Yanjun <yanjun.zhu@intel.com>
To: jgg@ziepe.ca, leon@kernel.org, linux-rdma@vger.kernel.org,
yanjun.zhu@linux.dev, yanjun.zhu@intel.com
Subject: [PATCH 3/3] RDMA/core: Get all the ib devices from net devices
Date: Sun, 23 Oct 2022 18:04:50 -0400 [thread overview]
Message-ID: <20221023220450.2287909-4-yanjun.zhu@intel.com> (raw)
In-Reply-To: <20221023220450.2287909-1-yanjun.zhu@intel.com>
From: Zhu Yanjun <yanjun.zhu@linux.dev>
To mlx4/5, the function ib_device_get_by_netdev can not get
ib devices from net devices.
So this function parses all the ib devices to get all the net
devices, then compares the net devices with the given net device.
Signed-off-by: Zhu Yanjun <yanjun.zhu@linux.dev>
---
drivers/infiniband/core/device.c | 39 ++++++++++++++++++++++++++++++--
1 file changed, 37 insertions(+), 2 deletions(-)
diff --git a/drivers/infiniband/core/device.c b/drivers/infiniband/core/device.c
index d38eb1fc2ed7..55e2d75d752e 100644
--- a/drivers/infiniband/core/device.c
+++ b/drivers/infiniband/core/device.c
@@ -2740,14 +2740,49 @@ int ib_dma_virt_map_sg(struct ib_device *dev, struct scatterlist *sg, int nents)
EXPORT_SYMBOL(ib_dma_virt_map_sg);
#endif /* CONFIG_INFINIBAND_VIRT_DMA */
+static struct ib_device *get_ibdev_from_ndev(struct net_device *ndev)
+{
+ unsigned long index;
+ struct ib_device *dev;
+ int i;
+
+ down_read(&devices_rwsem);
+ xa_for_each_marked(&devices, index, dev, DEVICE_REGISTERED) {
+ if (!dev->ops.get_netdev)
+ continue;
+
+ for (i = 0; i < dev->phys_port_cnt; i++) {
+ struct net_device *netdev;
+
+ netdev = dev->ops.get_netdev(dev, i+1);
+ if (!netdev)
+ continue;
+
+ dev_put(netdev);
+ if (ndev == netdev) {
+ up_read(&devices_rwsem);
+ if (!ib_device_try_get(dev))
+ dev = NULL;
+ return dev;
+ }
+ }
+ }
+ up_read(&devices_rwsem);
+ return NULL;
+}
+
static int rdma_netns_notify(struct notifier_block *not_blk,
unsigned long event, void *arg)
{
struct net_device *ndev = netdev_notifier_info_to_dev(arg);
struct ib_device *ibdev = ib_device_get_by_netdev(ndev, RDMA_DRIVER_UNKNOWN);
- if (!ibdev)
- return NOTIFY_OK;
+ if (!ibdev) {
+ /* This is for MLX4/5 */
+ ibdev = get_ibdev_from_ndev(ndev);
+ if (!ibdev)
+ return NOTIFY_OK;
+ }
/* This will exclude IB device */
if (rdma_protocol_ib(ibdev, rdma_start_port(ibdev))) {
--
2.27.0
next prev parent reply other threads:[~2022-10-23 5:39 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-23 22:04 [PATCH 0/3] RDMA net namespace Zhu Yanjun
2022-10-23 13:04 ` Leon Romanovsky
2022-10-23 13:42 ` Yanjun Zhu
2022-10-23 16:45 ` Leon Romanovsky
2022-10-24 7:20 ` yanjun.zhu
2022-10-23 22:04 ` [PATCH 1/3] RDMA/core: Move ib device to the same net namespace with net device Zhu Yanjun
2022-10-23 22:04 ` [PATCH 2/3] RDMA/core: The legacy IB devices still work with shared/exclusive mode Zhu Yanjun
2022-10-23 22:04 ` Zhu Yanjun [this message]
2022-10-24 1:10 ` [PATCH 0/3] RDMA net namespace Dust Li
2022-10-24 6:15 ` yanjun.zhu
2022-10-24 11:52 ` Dust Li
2022-10-24 13:12 ` Yanjun Zhu
2022-10-24 14:35 ` Dust Li
2022-10-24 16:41 ` Jason Gunthorpe
2022-10-25 2:51 ` Yanjun Zhu
2022-10-26 4:08 ` Dust Li
2022-10-26 15:01 ` Dust Li
2022-10-27 2:30 ` Dust Li
2022-10-27 2:54 ` yanjun.zhu
2022-10-27 3:01 ` Parav Pandit
2022-10-27 3:07 ` yanjun.zhu
2022-10-27 3:10 ` Parav Pandit
2022-10-27 3:17 ` yanjun.zhu
2022-10-27 3:21 ` Parav Pandit
2022-10-27 3:39 ` yanjun.zhu
2022-10-27 3:48 ` Parav Pandit
2022-10-27 6:01 ` yanjun.zhu
2022-10-27 14:06 ` Parav Pandit
2022-10-28 3:21 ` Yanjun Zhu
2022-10-28 3:31 ` Parav Pandit
2022-10-28 3:49 ` Yanjun Zhu
2022-10-28 3:58 ` Parav Pandit
2022-11-11 2:38 ` Yanjun Zhu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221023220450.2287909-4-yanjun.zhu@intel.com \
--to=yanjun.zhu@intel.com \
--cc=jgg@ziepe.ca \
--cc=leon@kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=yanjun.zhu@linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox