Netdev List
 help / color / mirror / Atom feed
* [PATCH net] net/mlx5: Serialize command interface flush
@ 2026-12-02 19:43 Tariq Toukan
  2026-12-02 19:49 ` netdev-bot+sinfo
  0 siblings, 1 reply; 2+ messages in thread
From: Tariq Toukan @ 2026-12-02 19:43 UTC (permalink / raw)
  To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	netdev, Paolo Abeni, Willem de Bruijn
  Cc: Gal Pressman, Leon Romanovsky, linux-rdma, Mark Bloch,
	Moshe Shemesh, Saeed Mahameed, Shay Drory, Tariq Toukan, Uri Dar

From: Uri Dar <udar@nvidia.com>

mlx5_cmd_flush() takes the command semaphore permits one at a time and
holds them until it has all of them. Two flushes running at the same
time can split the permits between them, and then both spin forever.

This can happen as the fatal health work calls enter_error_state()
without intf_state_mutex, for example while the PCI error handler
enters error state.

Serialize mlx5_cmd_flush() with a mutex. A second flush now waits for
the first one, then finds all permits free and returns at once.

Fixes: 51d138c2610a ("net/mlx5: Fix health error state handling")
Signed-off-by: Uri Dar <udar@nvidia.com>
Reviewed-by: Moshe Shemesh <moshe@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
---
 drivers/net/ethernet/mellanox/mlx5/core/cmd.c | 5 +++++
 include/linux/mlx5/driver.h                   | 4 ++++
 2 files changed, 9 insertions(+)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/cmd.c b/drivers/net/ethernet/mellanox/mlx5/core/cmd.c
index 84583dc5eb1c..4874c81b642a 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/cmd.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/cmd.c
@@ -1876,6 +1876,7 @@ void mlx5_cmd_flush(struct mlx5_core_dev *dev)
 	struct mlx5_cmd *cmd = &dev->cmd;
 	int i;
 
+	mutex_lock(&cmd->flush_lock);
 	for (i = 0; i < cmd->vars.max_reg_cmds; i++) {
 		while (down_trylock(&cmd->vars.sem)) {
 			mlx5_cmd_trigger_completions(dev);
@@ -1892,6 +1893,7 @@ void mlx5_cmd_flush(struct mlx5_core_dev *dev)
 	up(&cmd->vars.pages_sem);
 	for (i = 0; i < cmd->vars.max_reg_cmds; i++)
 		up(&cmd->vars.sem);
+	mutex_unlock(&cmd->flush_lock);
 }
 
 static struct mlx5_cmd_msg *alloc_msg(struct mlx5_core_dev *dev, int in_size,
@@ -2438,11 +2440,13 @@ int mlx5_cmd_init(struct mlx5_core_dev *dev)
 
 	spin_lock_init(&cmd->alloc_lock);
 	spin_lock_init(&cmd->token_lock);
+	mutex_init(&cmd->flush_lock);
 
 	set_wqname(dev);
 	cmd->wq = create_singlethread_workqueue(cmd->wq_name);
 	if (!cmd->wq) {
 		mlx5_core_err(dev, "failed to create command workqueue\n");
+		mutex_destroy(&cmd->flush_lock);
 		return -ENOMEM;
 	}
 
@@ -2457,6 +2461,7 @@ void mlx5_cmd_cleanup(struct mlx5_core_dev *dev)
 
 	mlx5_cmdif_debugfs_cleanup(dev);
 	destroy_workqueue(cmd->wq);
+	mutex_destroy(&cmd->flush_lock);
 }
 
 int mlx5_cmd_enable(struct mlx5_core_dev *dev)
diff --git a/include/linux/mlx5/driver.h b/include/linux/mlx5/driver.h
index 84e9f6bdb7c1..e336187c1091 100644
--- a/include/linux/mlx5/driver.h
+++ b/include/linux/mlx5/driver.h
@@ -325,6 +325,10 @@ struct mlx5_cmd {
 	 */
 	spinlock_t	token_lock;
 	u8		token;
+
+	/* serialize command interface flush
+	 */
+	struct mutex	flush_lock;
 	char		wq_name[MLX5_CMD_WQ_MAX_NAME];
 	struct workqueue_struct *wq;
 	int	mode;
-- 
2.44.0


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

* Re: [PATCH net] net/mlx5: Serialize command interface flush
  2026-12-02 19:43 [PATCH net] net/mlx5: Serialize command interface flush Tariq Toukan
@ 2026-12-02 19:49 ` netdev-bot+sinfo
  0 siblings, 0 replies; 2+ messages in thread
From: netdev-bot+sinfo @ 2026-12-02 19:49 UTC (permalink / raw)
  To: Tariq Toukan
  Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	netdev, Paolo Abeni, Willem de Bruijn, Gal Pressman,
	Leon Romanovsky, linux-rdma, Mark Bloch, Moshe Shemesh,
	Saeed Mahameed, Shay Drory, Uri Dar

Hi!

This is an automated message. This series looks like a fix, but its
commit messages seem to be missing some information:

 - How the issue was discovered, e.g. hit in production, hit during
   development, syzbot report, manual code inspection, LLM or static
   analysis tool scan.

 - Whether the issue was actually triggered, or is only theoretical
   (e.g. found by LLM and not proven at runtime). If it was triggered
   please include the symptoms, like the stack trace or kernel messages.

 - What hardware the change was tested on. For driver fixes please
   mention the device (and if relevant firmware version) used for
   testing, or say that the change was not tested on real hardware.

Please do not repost the series just to address the above. Instead,
reply to this email with the missing information, so that reviewers
can take it into account.

*IMPORTANT*: If you do repost (for other reasons) - please include
the relevant info in the cover letter or commit messages.
-- 
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.

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

end of thread, other threads:[~2026-12-02 19:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02 19:43 [PATCH net] net/mlx5: Serialize command interface flush Tariq Toukan
2026-12-02 19:49 ` netdev-bot+sinfo

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