🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #24056

Re: [PATCH net] net/mlx5e: Fix deadlock when parsing flow actions fails

#24056
From: netdev-bot+sashiko
Date: Sun, 29 Nov 2026 04:37
193 lines
15288 bytes
Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.

Critical: 0 · High: 1 · Medium: 0 · Low: 2

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 deadlock between encap_tbl_lock and flow->init_done can
  still happen after this patch, and in some cases it happens on the…
- [Low] The commit message describes the wrong mechanism for failures in
  the checks that parse_tc_fdb_actions() runs after…
- [Low] The new comments state the safety invariant the fix relies on,
  but they leave out part of it.

--

net/mlx5e: Fix deadlock when parsing flow actions fails

This patch handles a failure while parsing the actions of an FDB flow.
It first removes the post action rules installed so far. It then marks
the flow FAILED and completes init_done, so neigh and route updaters
waiting on the flow are woken before error cleanup takes encap_tbl_lock
again.

> The checks parse_tc_fdb_actions() runs after
> alloc_flow_post_acts() reach the same detach from mlx5e_flow_put().  An
> update that holds the lock and waits for the flow then blocks the
> cleanup that would have to wake it, and both sides hang.

[Severity: Low]
Is this the right mechanism for the checks that run after
alloc_flow_post_acts()?

An updater waiting on this flow has already taken a reference in
mlx5e_take_tmp_flow() in en/tc_tun_encap.c:

    if (IS_ERR(mlx5e_flow_get(flow))) {
        ...
        wait_for_completion(&flow->del_hw_done);
        return;
    }
    wait_for_completion(&flow->init_done);

So before this patch, err_free -> mlx5e_flow_put() in
__mlx5e_add_fdb_flow() only drops refcnt from 2 to 1. Neither
mlx5e_tc_del_flow() nor mlx5e_detach_encap() runs, and
__mlx5e_add_fdb_flow() returns normally.

In that case the hang looks like a completion that is never signalled,
not a lock cycle. The updater sleeps on init_done forever while holding
encap_tbl_lock, and also rtnl on the neigh path.

If the add path does drop the last reference, mlx5e_flow_get() fails in
the updater. It then waits on del_hw_done instead, which
mlx5e_tc_del_fdb_flow() completes before detaching.

The lock cycle described here only seems to exist for failures inside
alloc_flow_post_acts(), where free_flow_post_acts() takes the lock
directly.

The message also doesn't mention a behaviour change. With the fix, the
woken neigh or route worker usually holds the last reference. It then
runs the full mlx5e_tc_del_flow() teardown from mlx5e_put_flow_list(),
after __mlx5e_add_fdb_flow() has already returned the error.

Could the commit message be updated to describe this?

> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
> index 011741553f5b9..d97612a7190b9 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
> @@ -3748,6 +3748,39 @@ free_flow_post_acts(struct mlx5e_tc_flow *flow)
>  	}
>  }
>  
> +/* Neigh and route updates wait for init_done while holding
> + * encap_tbl_lock, so the waiters have to be woken before error cleanup
> + * takes that lock again.  A flow that fails here is skipped by them: the
> + * neigh paths check OFFLOADED and the route paths check FAILED.
> + */
> +static void mlx5e_flow_init_failed(struct mlx5e_tc_flow *flow)
> +{
> +	flow_flag_set(flow, FAILED);
> +	complete_all(&flow->init_done);
> +}
> +
> +/* Remove the post action rules of a flow that failed to initialize.  A
> + * woken neigh update may release the encap header they point to, so they
> + * have to go before init_done is completed.
> + */

[Severity: Low]
This isn't a bug, but are these two comments complete?

The route path checks both flags, at different steps. In
en/tc_tun_encap.c, mlx5e_invalidate_encap() and
mlx5e_unoffload_flow_list() check OFFLOADED:

    if (!mlx5e_is_offloaded_flow(flow))
        continue;

Only mlx5e_reoffload_encap() and mlx5e_reoffload_decap() check FAILED.

The neigh update is also not the only path that releases the encap
header. The route path's mlx5e_invalidate_encap() does too:

    if (e->flags & MLX5_ENCAP_ENTRY_VALID) {
        e->flags &= ~MLX5_ENCAP_ENTRY_VALID;
        mlx5_packet_reformat_dealloc(priv->mdev, e->pkt_reformat);
        e->pkt_reformat = NULL;
    }

The code is correct today. A failed flow is FAILED and never OFFLOADED,
and the handles are removed before complete_all() whichever updater
wakes.

Could the comments mention both flag checks and the route path dealloc?

[ ... ]

> @@ -3852,6 +3885,8 @@ alloc_flow_post_acts(struct mlx5e_tc_flow *flow, struct netlink_ext_ack *extack)
>  	return 0;
>  
>  out_free:
> +	del_flow_post_act_handles(flow);
> +	mlx5e_flow_init_failed(flow);
>  	free_flow_post_acts(flow);
>  	return err;
>  }

[Severity: High]
Can the add thread still deadlock before it reaches this out_free label?

alloc_flow_post_acts() calls post_process_attr() for each post action
attribute in its loop. mlx5e_tc_tun_encap_dests_set() takes and drops
encap_tbl_lock once per attribute, and mlx5e_attach_encap() adds the
flow to e->flows while the lock is held.

Suppose attribute N attaches the flow to encap e1 and drops the lock. A
neigh update or the FIB work can then do:

mlx5e_rep_update_flows() / mlx5e_tc_fib_event_work()
    mutex_lock(&esw->offloads.encap_tbl_lock);
    mlx5e_take_tmp_flow()
        wait_for_completion(&flow->init_done);

Next, attribute N+1 with encap dests reaches:

alloc_flow_post_acts()
    post_process_attr()
        mlx5e_tc_tun_encap_dests_set()
            mutex_lock(&esw->offloads.encap_tbl_lock);

It blocks there before any of its error checks run. The failures in
mlx5e_tc_tun_encap_dests_set() all come after the mutex_lock():

    NL_SET_ERR_MSG_MOD(extack, "Requested mirred device not found");
    ...
    err = mlx5e_attach_encap(priv, flow, attr, out_dev, out_index,
                             extack, &encap_dev);
    ...
    NL_SET_ERR_MSG_MOD(extack, "VF tunnel encap with mirroring is not supported");

So these parse failures would still deadlock. The neigh worker also
holds rtnl, so rtnl would be stuck as well.

A rule like this looks like it creates two post action attributes with
encap dests:

    police; tunnel_key set; mirred vxlan0; police; tunnel_key set;
    mirred vxlan1

The commit message mentions two successful-setup cases in
mlx5e_tc_add_fdb_flow(): post_process_attr() for the main attribute,
and mlx5e_attach_decap_route() for TUN_RX flows. It doesn't mention
this case inside the alloc_flow_post_acts() loop.

Each place that takes the lock again would need its own early
completion. Would a design change work better? Some options:

- hold encap_tbl_lock across all attaches
- have updaters skip flows that are not yet initialized instead of
  sleeping under the mutex
- delay the post action encap attach until init_done is about to be
  completed

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261125042323.88050-1-ziyuzhang201%40gmail.com
Technical Details
Message-ID: <179592706111.3146.4086927068891315634@kernel.org>
Path: mbox-mo1.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-373373-linux-kernel-netdev=dewy.ru
References: <20261125042323.88050-1-ziyuzhang201@gmail.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-373373-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net] net/mlx5e: Fix deadlock when parsing flow actions fails
Date: Sun, 29 Nov 2026 04:37:41 +0000
Organization: Usenet Network
Message-ID: <179592706111.3146.4086927068891315634@kernel.org>
References: <20261125042323.88050-1-ziyuzhang201@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="1102124"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:dLW+I+Wuo4ISsmxMGL0oVrYlBYk= sha256:noyjmaA0ioMDoIckMdqNkRX9RtVVNmJtC17dtx2XkdM=
	sha1:4EYquhXzXE+Nm9Pp3LvkniOXN6w= sha256:k6tsoPHYc299RfeFMMW3B4sU3SFuZJ5cYch2EuH/Jjw=
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 E929A125F8A; Sun, 29 Nov 2026 07:38:05 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.4
X-Spam-Status: No, score=-3.4 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, 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, URIBL_BLOCKED=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 jhTPzwf2wJPy;
	Sun, 29 Nov 2026 07:38:01 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-373373-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 34424125F92; Sun, 29 Nov 2026 07:37:52 +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 D6C3025F9E; Sun, 29 Nov 2026 04:37:48 +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=1795927068;
	b=rbm9eIqw0r29xIndtRWPxq9QWklti4W6E+qx2lpiJSsMmFI1Rx/0XisClxIeuepxOrhI
	 R458nO1Dhl9NHXGyPlHOevOBvF8PNfqv3iz6ft9JDQQU0brOJzbd6CQDan3EgpLmLC01h
	 y4PK0/lU7tZaZ+LGIyGoZYt3mJD+xLGL5P18oVlvRKvJq/Pv7C4lm8nL5/pyWqR28z91W
	 QhD5rbSELTNvXzdbJ8I5+pY3YbP72imCtfY4kAMzkCZ9jOT7EFq+Lnh6d4Xr9PLnQwLOz
	 GqSIUJ0WwBesnbV51PG1Z4VpDfZl0kXJD74Qable5qG4Ro4vgwyVp+vG+trlG32W3pQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795927068;
	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=NbI1yI2i3Qz3+unQTnF3QoiF/6Id4hVsxGvJtaWk+48=;
	b=B2xOQA+GbUVMj/0n9ORkjQs46PAVknhM4ACa16NWgjoFJFzKuvHBj8ASlhQbZ8TrAUoi
	 qV2LKsO/b0bwsHBufXFgMCe+pg7VSDBIm5GIOqP0RFddCcUAj5izkO3HSaTC5aAGzMefn
	 UsC41YIis8MMR8MUOShItXzUGAed6pjEPadLjg/AI+gWhtguJkL19UpkOBdloAufwP7Gg
	 7tHESKreKBCkJqn95wSdFmfNtJlvg57yVkzgbhYS+wQfhc24FSVouxrmkNG0dzG0dGIYk
	 7ws/+7NLOTSrDZbbvryBCpArjNSAQ8lOadlhT/fXxF1Evde6Y+zr9jAHQklVF7P0EkQ==
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="Vq/C9DIE";
	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 AED5F606A329;
	Sun, 29 Nov 2026 04:37:48 +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=Vq/C9DIE
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=1795927062;
	b=zjhGRrXlWTCGpJzdWiBWzFPz3e7VZL8nvy02C2nDiG0RDI7yObdKdRbwaTPmTfeNKzTm
	 bnXOAUGUZ4cbcVAhKsNPmIz7iLXuikIO1ALZuisaaSqRSaihi3rGH8kx8+nIFoupw051/
	 e9A/Si5smDGeb92e2tycsq/FfwGQquIKUDjs6a2r2GD3v24hcLS1Ksf6rnGqq0cIgplMu
	 gd6v2gYPtLVK2xr+15pTuzpQPWAPrffb9+ucQqb3UVJkJrKpJa6HLN9tusg6ywohGT+Ci
	 AJtDuNv+0Geqrne+rW6f4jS8PKlXIapN7YtxmFdaGy5ZXCs8C3YV9WfMuXaoeqtwdtw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795927062;
	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=NbI1yI2i3Qz3+unQTnF3QoiF/6Id4hVsxGvJtaWk+48=;
	b=bcHAik8D9FJKsx77v/2DTu8CZLcb89U8RE6wOUSOLktIi27HybS+7JQuz6eAZglvog8d
	 0XMqQHK+R9xbmp5WwH46k5hu2bEJgUd/WDFuF350ypTTxRlgFRShm8uXU20d5AZmJNDVW
	 zoxMk4A9AdaNlGRtZn7l2xMMyKhuPMkut2FDXu3s0YhbvwkfwNbNqPmrW3hlWbKux2Xe6
	 Qs3FHNkr/cttqdbFoZfIgXMSLcth+GZ5sYF6VQS0S12Eu8/TaYKTu/2YFfBLdoblUcr7t
	 mdBjOueJr2A1E2fcVxUmEes5Ueou5c+57xgf8kLNVKZsNGhzZzwYtqKQ7+oy7LPFi/A==
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="Vq/C9DIE";
	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 CA808606A31C;
	Sun, 29 Nov 2026 04:37:42 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id A12B41F00897;
	Sun, 29 Nov 2026 04:37:41 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1795927062;
	bh=NbI1yI2i3Qz3+unQTnF3QoiF/6Id4hVsxGvJtaWk+48=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=Vq/C9DIEYz1BCe4IDb2S4PjDR3Gcrbrz5OuKCBpyn8kKkXGDtmvgsMQtrxygOwJOb
	 71Th40aHNP/jwbIw0S2lFsf3Ke9hGL0GrCXrOJnNioxNe7Pao6OPK0YHU8EwcaGt2N
	 aGr+HQNDa4NlK3KIsuQtRYw+niO7R/dClFND8xkZsYoAsjDoUdHH31JbSkVlTrCIAQ
	 ZRJHeuXc9bzkjtzgKlNgKoE9T7jmkfw7URTMQcKi8mRI22oPom77jW0oRi1+FAc95v
	 pR/f/VGuK37Q6lqSbUGMwZi+4ELoehv9srBe8Vb4b9jrDx9wlWNUJUHX6uliPMKwPV
	 YVh0SuX7EFChQ==
X-Cc: saeedm@nvidia.com, tariqt@nvidia.com, mbloch@nvidia.com, leon@kernel.org,
 netdev@vger.kernel.org, linux-rdma@vger.kernel.org,
 linux-kernel@vger.kernel.org, andrew+netdev@lunn.ch, davem@davemloft.net,
 edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com, roid@nvidia.com,
 baijiaju1990@gmail.com
X-In-Reply-To: <20261125042323.88050-1-ziyuzhang201@gmail.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