๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #26567

Re: [PATCH net] net/mlx5: Serialize command interface flush

#26567
From: netdev-bot+sashiko
Date: Thu, 03 Dec 2026 19:45
106 lines
11792 bytes
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
Technical Details
Message-ID: <179632710033.3146.5432425460925812356@kernel.org>
Path: mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-mo.newsdeef.eu!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376842-linux-kernel-netdev=dewy.ru
References: <20261202194338.3593396-1-tariqt@nvidia.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-mo.newsdeef.eu!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376842-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net] net/mlx5: Serialize command interface flush
Date: Thu, 03 Dec 2026 19:45:00 +0000
Organization: Usenet Network
Message-ID: <179632710033.3146.5432425460925812356@kernel.org>
References: <20261202194338.3593396-1-tariqt@nvidia.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="2579963"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:o9EBwl/J8/D2sIVTu3XtQ2Y+Nyw= sha256:rdj8RkytPVT7RyAqT3hfGQJWrs/1NSzTArXYXvmj+Ss=
	sha1:Qo7zDwaL0LL1p1c0Ilc94ojR1gc= sha256:oC3VfAWrrdAPfxo5akM5+B+AR+gCge24JEIBKsY7ZaM=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id A606A1179D5; Thu,  3 Dec 2026 22:45:24 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.64
X-Spam-Status: No, score=-3.64 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.24, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id fZjpZiIU7vdk;
	Thu,  3 Dec 2026 22:45:21 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-376842-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 157A3117A1D; Thu,  3 Dec 2026 22:45:12 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id BCFEE24D1A; Thu,  3 Dec 2026 19:45:07 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1796327107;
	b=X+IRC2FgPoAHFVPQ9yZ6ojw9LTclfsMfZ8gEVgp7UPO6oJ3+QKoCNZ2dpDcNVMB0gE/I
	 /QRsK/nvMHhGnHPJs/FWPnOBi2Z/Uc/lH2PQv8K62oLXmBjzCJGzZTgmd42U/5PNbtQU6
	 MSJrmkLq0EGs2e8zygkS/9BcQIzN+NbhHPkiBQjPLosMbK8AVq2RtsFu8U2Rc1ZhF3oYA
	 josPZp96XHE+vF9o288uqcwKjpCXO52102iJ2+WA62PTX2dVT/DHXgze0NzmbaH2k7H2C
	 nKgd0jC+g/QgOePHJq3LGtur1ZJtktlq8ddjlTg3IU/iDH113fvtaE6x+hfzFTWZHuA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796327107;
	h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc:
	 Date:Message-ID:In-Reply-To:References:X-sashiko-severity:
	 Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version;
	bh=3xONhX0krX8eN0U/mdkTr+sh8HYnrWv0P0nzU1kXwGI=;
	b=E9ib/l4/k4S1MuZts/Zo11ZCk1W0b9rSnEWhy0nJgf9v3YSCO3C3XjZdSAElHHV/5F7A
	 eLUy8biY6fnXO1DM58j/254FigkELnL+sgmKUgwa16Tw4VZXVrQPIRGuLH+1Z8SGmWNrN
	 J642NDY6RvVPXkZPdtoc0Icp5OmeSdCuKFc/thCmKWmq0Tk/yIxe3ML+A1ABcBET4Sq8u
	 0weCzP6vfhT57QavrVmwfbxSkd3l55nggZiZyNcGCAXOFHX9CZabl7zqvPkYgjdHBy4vD
	 lhWtmIXwapDfzgv1qyPtBCIh7d786qht15oqHyASgCO3NIn8OWV9CZHmkCiLS6MJBKQ==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=OYeTr9iU;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 9251F606A338;
	Thu,  3 Dec 2026 19:45:07 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=OYeTr9iU
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1796327101;
	b=X9mq8EsJSqA0WWuEwno1MWrcs9jOTz8Z5KJEnXZmRBvMftD115Hon5TUnuzQ/O5CiJZ7
	 kqVsvTUW3DO27OplYRllbzgLw3W2OsmOIfdSmo2LiL4OB23L1NDApaaWm4E+OZftx8eYL
	 +by0EypdOwmwud+qaIVOQkDM2ga6NNUE1KLmpHrZSH66HOCeSzri8X1mCmfhVa9Y0e+ub
	 zx5r6xYKwmz7Nap67j7znBLFSKqLtC7mZrINE7JnJb/c09+foV8K5+0M1HpZTha5b7dnN
	 xLJh+P2cNgxXSdxDz+EAjjRkWyW70qB+A9II/ZqRl/rWdnsyshuW5JOMVP99/iL3yOg==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796327101;
	h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID:
	 In-Reply-To:References:X-sashiko-severity:Content-Type:
	 Content-Transfer-Encoding:MIME-Version;
	bh=3xONhX0krX8eN0U/mdkTr+sh8HYnrWv0P0nzU1kXwGI=;
	b=IDsbI2tpk6bM+wBwJcImUsNaIkDBdN1vukHjKbUu7vZD0Cp0uAdbKmolDvu15BbTtNvR
	 G4aIgSFhOQf+ui3JInmlaUjK2UPtOlhJv7LdxLK3f02oglbm7XkGMQqrfzDdMgIMpYnG2
	 ZXo/KfkdWlJgfCk4kKR30I++WgkYm8Toh+ASUorxJPjVtu/xi4Nm8OkWC1Tw/Ur0hoCfU
	 b3pbCiq+hDLApemmbKXRJEiRKPqCk2mmHD7IzsnlkrvcGlS980Y+blUGYtOtZHJG+ZT09
	 FsSWH9OhdHphtEkpeVMbZZAhg2YNNPI80/kgDCSpfT8MJvleZHsU7WFePDv5BDk6u1g==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=OYeTr9iU;
	arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id B1CB3606A32F;
	Thu,  3 Dec 2026 19:45:01 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id BEC2C1F000C2;
	Thu,  3 Dec 2026 19:45:00 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1796327101;
	bh=3xONhX0krX8eN0U/mdkTr+sh8HYnrWv0P0nzU1kXwGI=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=OYeTr9iUUESxcPUGGdXHlGsGzLYSKIiYwYrcwH7HRYyA/ADw5MLR4ak4iYcwYhJ2q
	 WqfD4TlrpqQW4P0lqCXUJghdQ8+acyggvFyonDdBqNhg162bLoZZgUiEC5k2+b1OCO
	 gq54nI5Ah1lK6F80DuCUkKuAgtxjSdUYmaqcft0wRRBU5TJkXWC/PNLrKYfaq8oUzE
	 t0wrg0bdQwnIvy18hokNdkTRLd5GF+3kykql+1RF/9I7e8ZRlLHOwVTSVtymuFh2R3
	 xkXOUrWJiDNE86WLI4oloi8WShiFgktBHgYFnkOyGEGARlRUYE7uvf7Fn4f1yxPNpi
	 0vEuR3WtxQJwg==
X-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
X-In-Reply-To: <20261202194338.3593396-1-tariqt@nvidia.com>
X-sashiko-severity: High
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list