Re: [PATCH net 5/5] net/mlx5: E-switch, Fix error handling for enabling roce

Michal Swiatkowski
2025-04-23T10:18:22Z

On Wed, Apr 23, 2025 at 11:36:11AM +0300, Mark Bloch wrote:
> From: Chris Mi <cmi@nvidia.com>
>
> The cited commit assumes enabling roce always succeeds. But it is
> not true. Add error handling for it.
>
> Fixes: 80f09dfc237f ("net/mlx5: Eswitch, enable RoCE loopback traffic")
> Signed-off-by: Chris Mi <cmi@nvidia.com>
> Reviewed-by: Roi Dayan <roid@nvidia.com>
> Reviewed-by: Maor Gottlieb <maorg@nvidia.com>
> Signed-off-by: Mark Bloch <mbloch@nvidia.com>
> ---
> .../net/ethernet/mellanox/mlx5/core/eswitch_offloads.c | 5 ++++-
> drivers/net/ethernet/mellanox/mlx5/core/rdma.c | 9 +++++----
> drivers/net/ethernet/mellanox/mlx5/core/rdma.h | 4 ++--
> 3 files changed, 11 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c b/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c
> index a6a8eea5980c..0e3a977d5332 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c
> @@ -3533,7 +3533,9 @@ int esw_offloads_enable(struct mlx5_eswitch *esw)
> int err;
>
> mutex_init(&esw->offloads.termtbl_mutex);
> - mlx5_rdma_enable_roce(esw->dev);
> + err = mlx5_rdma_enable_roce(esw->dev);
> + if (err)
> + goto err_roce;
>
> err = mlx5_esw_host_number_init(esw);
> if (err)
> @@ -3594,6 +3596,7 @@ int esw_offloads_enable(struct mlx5_eswitch *esw)
> esw_offloads_metadata_uninit(esw);
> err_metadata:
> mlx5_rdma_disable_roce(esw->dev);
> +err_roce:
> mutex_destroy(&esw->offloads.termtbl_mutex);
> return err;
> }
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/rdma.c b/drivers/net/ethernet/mellanox/mlx5/core/rdma.c
> index f585ef5a3424..5c552b71e371 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/rdma.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/rdma.c
> @@ -140,17 +140,17 @@ void mlx5_rdma_disable_roce(struct mlx5_core_dev *dev)
> mlx5_nic_vport_disable_roce(dev);
> }
>
> -void mlx5_rdma_enable_roce(struct mlx5_core_dev *dev)
> +int mlx5_rdma_enable_roce(struct mlx5_core_dev *dev)
> {
> int err;
>
> if (!MLX5_CAP_GEN(dev, roce))
> - return;
> + return 0;
>
> err = mlx5_nic_vport_enable_roce(dev);
> if (err) {
> mlx5_core_err(dev, "Failed to enable RoCE: %d\n", err);
> - return;
> + return err;
> }
>
> err = mlx5_rdma_add_roce_addr(dev);
> @@ -165,10 +165,11 @@ void mlx5_rdma_enable_roce(struct mlx5_core_dev *dev)
> goto del_roce_addr;
> }
>
> - return;
> + return err;
>
> del_roce_addr:
> mlx5_rdma_del_roce_addr(dev);
> disable_roce:
> mlx5_nic_vport_disable_roce(dev);
> + return err;
> }
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/rdma.h b/drivers/net/ethernet/mellanox/mlx5/core/rdma.h
> index 750cff2a71a4..3d9e76c3d42f 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/rdma.h
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/rdma.h
> @@ -8,12 +8,12 @@
>
> #ifdef CONFIG_MLX5_ESWITCH
>
> -void mlx5_rdma_enable_roce(struct mlx5_core_dev *dev);
> +int mlx5_rdma_enable_roce(struct mlx5_core_dev *dev);
> void mlx5_rdma_disable_roce(struct mlx5_core_dev *dev);
>
> #else /* CONFIG_MLX5_ESWITCH */
>
> -static inline void mlx5_rdma_enable_roce(struct mlx5_core_dev *dev) {}
> +static inline int mlx5_rdma_enable_roce(struct mlx5_core_dev *dev) { return 0; }
> static inline void mlx5_rdma_disable_roce(struct mlx5_core_dev *dev) {}
>
> #endif /* CONFIG_MLX5_ESWITCH */

Reviewed-by: Michal Swiatkowski <michal.swiatkowski@linux.intel.com>

> --
> 2.34.1