All of lore.kernel.org
 help / color / mirror / Atom feed
From: Leon Romanovsky <leon@kernel.org>
To: Prathamesh Deshpande <prathameshdeshpande7@gmail.com>
Cc: Jason Gunthorpe <jgg@ziepe.ca>,
	linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org,
	dledford@redhat.com, haggaie@mellanox.com
Subject: Re: [PATCH v9 1/2] IB/mlx5: Fix transport-domain rollback and initialize lb mutex earlier
Date: Sun, 10 May 2026 13:56:09 +0300	[thread overview]
Message-ID: <20260510105609.GE15586@unreal> (raw)
In-Reply-To: <20260410005219.5197-2-prathameshdeshpande7@gmail.com>

On Fri, Apr 10, 2026 at 01:52:17AM +0100, Prathamesh Deshpande wrote:
> mlx5_ib_alloc_transport_domain() allocates a transport domain and then
> may fail in mlx5_ib_enable_lb(). In that case, the allocated TD is leaked.
> 
> Fix this by deallocating the TD when mlx5_ib_enable_lb() returns an
> error. Also return 0 explicitly in the no-loopback-capability success
> branch, and move dev->lb.mutex initialization to mlx5_ib_stage_init_init().
> 
> Fixes: 146d2f1af324 ("IB/mlx5: Allocate a Transport Domain for each ucontext")
> Signed-off-by: Prathamesh Deshpande <prathameshdeshpande7@gmail.com>
> ---
>  drivers/infiniband/hw/mlx5/main.c | 14 +++++++-------
>  1 file changed, 7 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/infiniband/hw/mlx5/main.c b/drivers/infiniband/hw/mlx5/main.c
> index e02bfb1479f5..6be198c0651c 100644
> --- a/drivers/infiniband/hw/mlx5/main.c
> +++ b/drivers/infiniband/hw/mlx5/main.c
> @@ -2068,9 +2068,13 @@ static int mlx5_ib_alloc_transport_domain(struct mlx5_ib_dev *dev, u32 *tdn,
>  	if ((MLX5_CAP_GEN(dev->mdev, port_type) != MLX5_CAP_PORT_TYPE_ETH) ||
>  	    (!MLX5_CAP_GEN(dev->mdev, disable_local_lb_uc) &&
>  	     !MLX5_CAP_GEN(dev->mdev, disable_local_lb_mc)))
> -		return err;
> +		return 0;
> +
> +	err = mlx5_ib_enable_lb(dev, true, false);
> +	if (err)
> +		mlx5_cmd_dealloc_transport_domain(dev->mdev, *tdn, uid);
>  
> -	return mlx5_ib_enable_lb(dev, true, false);
> +	return err;
>  }
>  
>  static void mlx5_ib_dealloc_transport_domain(struct mlx5_ib_dev *dev, u32 tdn,
> @@ -4513,6 +4517,7 @@ static int mlx5_ib_stage_init_init(struct mlx5_ib_dev *dev)
>  
>  	mutex_init(&dev->cap_mask_mutex);
>  	mutex_init(&dev->data_direct_lock);
> +	mutex_init(&dev->lb.mutex);

There is also a need to call mutex_destroy() to ensure proper resource cleanup.

Thanks

>  	INIT_LIST_HEAD(&dev->qp_list);
>  	spin_lock_init(&dev->reset_flow_resource_lock);
>  	xa_init(&dev->odp_mkeys);
> @@ -4786,11 +4791,6 @@ static int mlx5_ib_stage_caps_init(struct mlx5_ib_dev *dev)
>  	if (err)
>  		return err;
>  
> -	if ((MLX5_CAP_GEN(dev->mdev, port_type) == MLX5_CAP_PORT_TYPE_ETH) &&
> -	    (MLX5_CAP_GEN(dev->mdev, disable_local_lb_uc) ||
> -	     MLX5_CAP_GEN(dev->mdev, disable_local_lb_mc)))
> -		mutex_init(&dev->lb.mutex);
> -
>  	if (MLX5_CAP_GEN_64(dev->mdev, general_obj_types) &
>  			MLX5_GENERAL_OBJ_TYPES_CAP_VIRTIO_NET_Q) {
>  		err = mlx5_ib_init_var_region(dev);
> -- 
> 2.43.0
> 

  reply	other threads:[~2026-05-10 10:56 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-10  0:52 [PATCH v9 0/2] IB/mlx5: Fix loopback rollback and locking Prathamesh Deshpande
2026-04-10  0:52 ` [PATCH v9 1/2] IB/mlx5: Fix transport-domain rollback and initialize lb mutex earlier Prathamesh Deshpande
2026-05-10 10:56   ` Leon Romanovsky [this message]
2026-04-10  0:52 ` [PATCH v9 2/2] IB/mlx5: Serialize force-enable state and preserve loopback accounting Prathamesh Deshpande
2026-05-10 10:55 ` [PATCH v9 0/2] IB/mlx5: Fix loopback rollback and locking Leon Romanovsky
2026-05-10 22:35   ` Prathamesh Deshpande

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=20260510105609.GE15586@unreal \
    --to=leon@kernel.org \
    --cc=dledford@redhat.com \
    --cc=haggaie@mellanox.com \
    --cc=jgg@ziepe.ca \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=prathameshdeshpande7@gmail.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.