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/2026…%40nvidia.com