]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
RDMA/ipoib: Use parent rdma device net namespace
authorMark Bloch <mbloch@nvidia.com>
Tue, 17 Jun 2025 08:44:03 +0000 (11:44 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 15 Aug 2025 14:39:02 +0000 (16:39 +0200)
[ Upstream commit f1208b05574f63c52e88109d8c75afdf4fc6bf42 ]

Use the net namespace of the underlying rdma device.
After honoring the rdma device's namespace, the ipoib
netdev now also runs in the same net namespace of the
rdma device.

Add an API to read the net namespace of the rdma device
so that ULP such as IPoIB can use it to initialize its
netdev.

Signed-off-by: Parav Pandit <parav@nvidia.com>
Signed-off-by: Mark Bloch <mbloch@nvidia.com>
Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
Stable-dep-of: f458ccd2aa2c ("RDMA/uverbs: Check CAP_NET_RAW in user namespace for flow create")
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/infiniband/ulp/ipoib/ipoib_main.c
include/rdma/ib_verbs.h

index f2f5465f2a90081cd1223408ea5c236cda0d39ad..7acafc5c0e09a853920f7359387aabd76bd38eff 100644 (file)
@@ -2577,6 +2577,8 @@ static struct net_device *ipoib_add_port(const char *format,
 
        ndev->rtnl_link_ops = ipoib_get_link_ops();
 
+       dev_net_set(ndev, rdma_dev_net(hca));
+
        result = register_netdev(ndev);
        if (result) {
                pr_warn("%s: couldn't register ipoib port %d; error %d\n",
index af43a8d2a74aec87b0bddc8e36c6650b20cd796c..c83e5a375cd6ca8dc7505eb81920f75771e6beb9 100644 (file)
@@ -4855,6 +4855,11 @@ static inline int ibdev_to_node(struct ib_device *ibdev)
 bool rdma_dev_access_netns(const struct ib_device *device,
                           const struct net *net);
 
+static inline struct net *rdma_dev_net(struct ib_device *device)
+{
+       return read_pnet(&device->coredev.rdma_net);
+}
+
 #define IB_ROCE_UDP_ENCAP_VALID_PORT_MIN (0xC000)
 #define IB_ROCE_UDP_ENCAP_VALID_PORT_MAX (0xFFFF)
 #define IB_GRH_FLOWLABEL_MASK (0x000FFFFF)