public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH][net-next] net/mlx5: Move command entry freeing outside of spinlock
@ 2026-03-31 12:26 lirongqing
  2026-04-01  8:21 ` Tariq Toukan
  2026-04-02  2:00 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: lirongqing @ 2026-03-31 12:26 UTC (permalink / raw)
  To: Saeed Mahameed, Leon Romanovsky, Tariq Toukan, Mark Bloch,
	Andrew Lunn, David S . Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Li RongQing, netdev, linux-rdma, linux-kernel

From: Li RongQing <lirongqing@baidu.com>

Move the kfree() call outside the critical section to reduce lock
holding time. This aligns with the general principle of minimizing
work under locks.

Signed-off-by: Li RongQing <lirongqing@baidu.com>
---
 drivers/net/ethernet/mellanox/mlx5/core/cmd.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/cmd.c b/drivers/net/ethernet/mellanox/mlx5/core/cmd.c
index 6c99c7f..c89417c 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/cmd.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/cmd.c
@@ -196,17 +196,18 @@ static void cmd_ent_put(struct mlx5_cmd_work_ent *ent)
 	unsigned long flags;
 
 	spin_lock_irqsave(&cmd->alloc_lock, flags);
-	if (!refcount_dec_and_test(&ent->refcnt))
-		goto out;
+	if (!refcount_dec_and_test(&ent->refcnt)) {
+		spin_unlock_irqrestore(&cmd->alloc_lock, flags);
+		return;
+	}
 
 	if (ent->idx >= 0) {
 		cmd_free_index(cmd, ent->idx);
 		up(ent->page_queue ? &cmd->vars.pages_sem : &cmd->vars.sem);
 	}
+	spin_unlock_irqrestore(&cmd->alloc_lock, flags);
 
 	cmd_free_ent(ent);
-out:
-	spin_unlock_irqrestore(&cmd->alloc_lock, flags);
 }
 
 static struct mlx5_cmd_layout *get_inst(struct mlx5_cmd *cmd, int idx)
-- 
2.9.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH][net-next] net/mlx5: Move command entry freeing outside of spinlock
  2026-03-31 12:26 [PATCH][net-next] net/mlx5: Move command entry freeing outside of spinlock lirongqing
@ 2026-04-01  8:21 ` Tariq Toukan
  2026-04-02  2:00 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: Tariq Toukan @ 2026-04-01  8:21 UTC (permalink / raw)
  To: lirongqing, Saeed Mahameed, Leon Romanovsky, Tariq Toukan,
	Mark Bloch, Andrew Lunn, David S . Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, netdev, linux-rdma, linux-kernel



On 31/03/2026 15:26, lirongqing wrote:
> From: Li RongQing <lirongqing@baidu.com>
> 
> Move the kfree() call outside the critical section to reduce lock
> holding time. This aligns with the general principle of minimizing
> work under locks.
> 
> Signed-off-by: Li RongQing <lirongqing@baidu.com>
> ---
>   drivers/net/ethernet/mellanox/mlx5/core/cmd.c | 9 +++++----
>   1 file changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/cmd.c b/drivers/net/ethernet/mellanox/mlx5/core/cmd.c
> index 6c99c7f..c89417c 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/cmd.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/cmd.c
> @@ -196,17 +196,18 @@ static void cmd_ent_put(struct mlx5_cmd_work_ent *ent)
>   	unsigned long flags;
>   
>   	spin_lock_irqsave(&cmd->alloc_lock, flags);
> -	if (!refcount_dec_and_test(&ent->refcnt))
> -		goto out;
> +	if (!refcount_dec_and_test(&ent->refcnt)) {
> +		spin_unlock_irqrestore(&cmd->alloc_lock, flags);
> +		return;
> +	}
>   
>   	if (ent->idx >= 0) {
>   		cmd_free_index(cmd, ent->idx);
>   		up(ent->page_queue ? &cmd->vars.pages_sem : &cmd->vars.sem);
>   	}
> +	spin_unlock_irqrestore(&cmd->alloc_lock, flags);
>   
>   	cmd_free_ent(ent);
> -out:
> -	spin_unlock_irqrestore(&cmd->alloc_lock, flags);
>   }
>   
>   static struct mlx5_cmd_layout *get_inst(struct mlx5_cmd *cmd, int idx)

Reviewed-by: Tariq Toukan <tariqt@nvidia.com>

Thanks.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH][net-next] net/mlx5: Move command entry freeing outside of spinlock
  2026-03-31 12:26 [PATCH][net-next] net/mlx5: Move command entry freeing outside of spinlock lirongqing
  2026-04-01  8:21 ` Tariq Toukan
@ 2026-04-02  2:00 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-04-02  2:00 UTC (permalink / raw)
  To: lirongqing
  Cc: saeedm, leon, tariqt, mbloch, andrew+netdev, davem, edumazet,
	kuba, pabeni, netdev, linux-rdma, linux-kernel

Hello:

This patch was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Tue, 31 Mar 2026 08:26:04 -0400 you wrote:
> From: Li RongQing <lirongqing@baidu.com>
> 
> Move the kfree() call outside the critical section to reduce lock
> holding time. This aligns with the general principle of minimizing
> work under locks.
> 
> Signed-off-by: Li RongQing <lirongqing@baidu.com>
> 
> [...]

Here is the summary with links:
  - [net-next] net/mlx5: Move command entry freeing outside of spinlock
    https://git.kernel.org/netdev/net-next/c/2897c697b326

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-04-02  2:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-31 12:26 [PATCH][net-next] net/mlx5: Move command entry freeing outside of spinlock lirongqing
2026-04-01  8:21 ` Tariq Toukan
2026-04-02  2:00 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox