Linux RDMA and InfiniBand development
 help / color / mirror / Atom feed
From: Tariq Toukan <tariqt@nvidia.com>
To: Andrew Lunn <andrew+netdev@lunn.ch>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, <netdev@vger.kernel.org>,
	Paolo Abeni <pabeni@redhat.com>,
	Willem de Bruijn <willemb@google.com>
Cc: Gal Pressman <gal@nvidia.com>, Leon Romanovsky <leon@kernel.org>,
	<linux-rdma@vger.kernel.org>, Mark Bloch <mbloch@nvidia.com>,
	Moshe Shemesh <moshe@nvidia.com>,
	Saeed Mahameed <saeedm@nvidia.com>, Shay Drory <shayd@nvidia.com>,
	Tariq Toukan <tariqt@nvidia.com>, Uri Dar <udar@nvidia.com>
Subject: [PATCH net] net/mlx5: Serialize command interface flush
Date: Wed, 2 Dec 2026 21:43:38 +0200	[thread overview]
Message-ID: <20261202194338.3593396-1-tariqt@nvidia.com> (raw)

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


             reply	other threads:[~2026-12-02 19:44 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02 19:43 Tariq Toukan [this message]
2026-12-02 19:49 ` [PATCH net] net/mlx5: Serialize command interface flush netdev-bot+sinfo

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=20261202194338.3593396-1-tariqt@nvidia.com \
    --to=tariqt@nvidia.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=gal@nvidia.com \
    --cc=kuba@kernel.org \
    --cc=leon@kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=mbloch@nvidia.com \
    --cc=moshe@nvidia.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=saeedm@nvidia.com \
    --cc=shayd@nvidia.com \
    --cc=udar@nvidia.com \
    --cc=willemb@google.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox