From: netdev-bot+sashiko@kernel.org
To: tariqt@nvidia.com
Cc: andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@kernel.org,
kuba@kernel.org, netdev@vger.kernel.org, pabeni@redhat.com,
willemb@google.com, gal@nvidia.com, leon@kernel.org,
linux-rdma@vger.kernel.org, mbloch@nvidia.com, moshe@nvidia.com,
saeedm@nvidia.com, shayd@nvidia.com, udar@nvidia.com
Subject: Re: [PATCH net] net/mlx5: Serialize command interface flush
Date: Thu, 03 Dec 2026 19:45:00 +0000 [thread overview]
Message-ID: <179632710033.3146.5432425460925812356@kernel.org> (raw)
In-Reply-To: <20261202194338.3593396-1-tariqt@nvidia.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 0 · Low: 0
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [High] The patch only partly closes the permit-splitting deadlock it
targets.
--
net/mlx5: Serialize command interface flush
This commit adds a mutex, cmd->flush_lock, around mlx5_cmd_flush(). Two
concurrent flushes can split the cmd->vars.sem permits and spin forever,
and the mutex prevents that. The scenario given is the fatal health work
calling enter_error_state() without intf_state_mutex while the PCI error
handler enters error state.
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/cmd.c b/drivers/net/ethernet/mellanox/mlx5/core/cmd.c
> index 84583dc5eb1c0..4874c81b642a8 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);
[Severity: High]
Does this cover every function that collects all the permits?
Two other functions in cmd.c also take every cmd->vars.sem permit one at a
time, and they do not take flush_lock:
drivers/net/ethernet/mellanox/mlx5/core/cmd.c:mlx5_cmd_allowed_opcode() {
...
for (i = 0; i < cmd->vars.max_reg_cmds; i++)
down(&cmd->vars.sem);
down(&cmd->vars.pages_sem);
...
}
mlx5_cmd_change_mod() has the same loop. It is reached through
mlx5_cmd_use_events() and mlx5_cmd_use_polling().
If one of these runs at the same time as mlx5_cmd_flush(), the two can
still split the max_reg_cmds permits. The collector would then sleep in
down() forever.
mlx5_cmd_flush() would spin in its down_trylock() loop. Calling
mlx5_cmd_trigger_completions() there would not help. No regular command
slot can be allocated while the two collectors hold every permit, so
~bitmask & MLX5_CMD_MASK is 0 and nothing is completed.
This looks reachable in the scenario from the commit message. The fatal
health work drops intf_state_mutex before it flushes:
mlx5_fw_fatal_reporter_err_work()
mutex_unlock(&dev->intf_state_mutex);
enter_error_state(dev, false);
mlx5_cmd_flush()
mlx5_pci_err_detected() calls mlx5_unload_one() before
mlx5_drain_health_wq():
mlx5_pci_err_detected()
mlx5_enter_error_state(dev, false);
mlx5_error_sw_reset(dev);
mlx5_unload_one(dev, false);
mlx5_drain_health_wq(dev);
The unload path reaches both collectors:
mlx5_unload_one()->mlx5_unload()->mlx5_eq_table_destroy()->destroy_async_eqs()
mlx5_cmd_allowed_opcode(dev, MLX5_CMD_OP_DESTROY_EQ);
mlx5_cmd_use_polling(dev);
mlx5_cmd_change_mod()
create_async_eqs() on the load path calls mlx5_cmd_allowed_opcode() and
mlx5_cmd_use_events() in the same way.
If this happens, the PCI error handler or the load/unload thread sleeps
forever in an uninterruptible down() while holding devl_lock and
intf_state_mutex. The health kworker keeps spinning in mlx5_cmd_flush().
Should mlx5_cmd_allowed_opcode() and mlx5_cmd_change_mod() take the same
mutex? If so, a more general name than flush_lock would fit better. The
comment in struct mlx5_cmd in include/linux/mlx5/driver.h ("serialize
command interface flush") would need updating as well.
> cond_resched();
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261202194338.3593396-1-tariqt%40nvidia.com
prev parent reply other threads:[~2026-12-03 19:45 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 19:43 [PATCH net] net/mlx5: Serialize command interface flush Tariq Toukan
2026-12-02 19:49 ` netdev-bot+sinfo
2026-12-02 19:56 ` sashiko-bot
2026-12-02 20:29 ` Keller, Jacob E
2026-12-03 19:45 ` netdev-bot+sashiko [this message]
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=179632710033.3146.5432425460925812356@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--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=tariqt@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