]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
RDMA/mlx5: Allocate IB device with net namespace supplied from core dev
authorMark Bloch <mbloch@nvidia.com>
Tue, 17 Jun 2025 08:44:02 +0000 (11:44 +0300)
committerLeon Romanovsky <leon@kernel.org>
Thu, 26 Jun 2025 12:10:07 +0000 (08:10 -0400)
Use the new ib_alloc_device_with_net() API to allocate the IB device
so that it is properly bound to the network namespace obtained via
mlx5_core_net(). This change ensures correct namespace association
(e.g., for containerized setups).

Additionally, expose mlx5_core_net so that RDMA driver can use it.

Signed-off-by: Shay Drory <shayd@nvidia.com>
Signed-off-by: Mark Bloch <mbloch@nvidia.com>
Reviewed-by: Parav Pandit <parav@nvidia.com>
Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
drivers/infiniband/hw/mlx5/ib_rep.c
drivers/infiniband/hw/mlx5/main.c
drivers/net/ethernet/mellanox/mlx5/core/lib/mlx5.h
include/linux/mlx5/driver.h

index 49af1cfbe6d1747436090bb431dfee50558562b7..cc8859d3c2f539fca9ab70d02a7383ffe662dd6f 100644 (file)
@@ -88,7 +88,8 @@ mlx5_ib_vport_rep_load(struct mlx5_core_dev *dev, struct mlx5_eswitch_rep *rep)
        else
                return mlx5_ib_set_vport_rep(lag_master, rep, vport_index);
 
-       ibdev = ib_alloc_device(mlx5_ib_dev, ib_dev);
+       ibdev = ib_alloc_device_with_net(mlx5_ib_dev, ib_dev,
+                                        mlx5_core_net(lag_master));
        if (!ibdev)
                return -ENOMEM;
 
index efea3ffd9715db59202be8fff574f14dd5dac5bf..c521bce2eeffd10350a8045ed95baa66db3131c5 100644 (file)
@@ -4793,7 +4793,8 @@ static struct ib_device *mlx5_ib_add_sub_dev(struct ib_device *parent,
            !MLX5_CAP_GEN_2(mparent->mdev, multiplane_qp_ud))
                return ERR_PTR(-EOPNOTSUPP);
 
-       mplane = ib_alloc_device(mlx5_ib_dev, ib_dev);
+       mplane = ib_alloc_device_with_net(mlx5_ib_dev, ib_dev,
+                                         mlx5_core_net(mparent->mdev));
        if (!mplane)
                return ERR_PTR(-ENOMEM);
 
@@ -4907,7 +4908,8 @@ static int mlx5r_probe(struct auxiliary_device *adev,
 
        num_ports = max(MLX5_CAP_GEN(mdev, num_ports),
                        MLX5_CAP_GEN(mdev, num_vhca_ports));
-       dev = ib_alloc_device(mlx5_ib_dev, ib_dev);
+       dev = ib_alloc_device_with_net(mlx5_ib_dev, ib_dev,
+                                      mlx5_core_net(mdev));
        if (!dev)
                return -ENOMEM;
 
index 37d5f445598c7bff34f1a09b8d3c2ac8749d923b..b111ccd03b02677d91815c7aa2905bb45ab0bd97 100644 (file)
@@ -45,11 +45,6 @@ int mlx5_crdump_enable(struct mlx5_core_dev *dev);
 void mlx5_crdump_disable(struct mlx5_core_dev *dev);
 int mlx5_crdump_collect(struct mlx5_core_dev *dev, u32 *cr_data);
 
-static inline struct net *mlx5_core_net(struct mlx5_core_dev *dev)
-{
-       return devlink_net(priv_to_devlink(dev));
-}
-
 static inline struct net_device *mlx5_uplink_netdev_get(struct mlx5_core_dev *mdev)
 {
        return mdev->mlx5e_res.uplink_netdev;
index e6ba8f4f4bd1f423db4552aba0a7ec07d2f03a3f..3475d33c75f4e5c706dc64ea148f6419524bbf8f 100644 (file)
@@ -1349,4 +1349,9 @@ enum {
 };
 
 bool mlx5_wc_support_get(struct mlx5_core_dev *mdev);
+
+static inline struct net *mlx5_core_net(struct mlx5_core_dev *dev)
+{
+       return devlink_net(priv_to_devlink(dev));
+}
 #endif /* MLX5_DRIVER_H */