๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #20549

Re: [PATCH net-next v2] net: mlx5: Allow police as the last action of a TC rule

#20549
From: netdev-bot+sashiko
Date: Sun, 22 Nov 2026 22:03
150 lines
13282 bytes
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 0 ยท High: 1 ยท Medium: 0 ยท Low: 1

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 rejects jump only when police is the last action, but
  leaves the same mismatch in place for every other police position.
- [Low] The patch fixes a user-visible bug but has no Fixes: tag, and the
  fix is folded into a feature change.

--

net: mlx5: Allow police as the last action of a TC rule

This commit lets a police action be the last (or only) action of an
offloaded mlx5 TC rule in switchdev mode. It sets the forward to the post
meter table while parsing police, and sends an ok result (and a pipe
result on the last police) to the end of the TC chains. It also rejects
jump when police is the last action.

> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/tc/act/police.c b/drivers/net/ethernet/mellanox/mlx5/core/en/tc/act/police.c
> index 1bd1c94fb9776..faa0822b1136f 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/en/tc/act/police.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/tc/act/police.c
> @@ -49,6 +49,14 @@ tc_act_can_offload_police(struct mlx5e_tc_act_parse_state *parse_state,
>  	if (err)
>  		return false;
>  
> +	if (flow_action_is_last_entry(parse_state->flow_action, act) &&
> +	    (act->police.exceed.act_id == FLOW_ACTION_JUMP ||
> +	     act->police.notexceed.act_id == FLOW_ACTION_JUMP)) {
> +		NL_SET_ERR_MSG_MOD(parse_state->extack,
> +				   "Jump on last police action is not supported");
> +		return false;
> +	}
> +

[Severity: High]
The commit message explains the rejection this way:

  "A jump counts from the start of the action list, so its target may be
  an earlier action or police itself."

That applies to a police at any action index k >= 1, not only to the
last one. Should this check use act_index and the remaining action count
rather than flow_action_is_last_entry()?

In software, tcf_action_exec() restarts from actions[0] and skips N
actions, so the target is the absolute index N:

net/sched/act_api.c:tcf_action_exec() {
    ...
		if (TC_ACT_EXT_CMP(ret, TC_ACT_JUMP)) {
			jmp_prgcnt = ret & TCA_ACT_MAX_PRIO_MASK;
			if (!jmp_prgcnt || (jmp_prgcnt > nr_actions)) {
				/* faulty opcode, stop pipeline */
				return TC_ACT_OK;
			} else {
				jmp_ttl -= 1;
				if (jmp_ttl > 0)
					goto restart_act_graph;
    ...
}

In mlx5, alloc_branch_attr() sets *jump_count = cond->extval, and
dec_jump_count() counts down once for each TC action after the police.
The hardware target ends up at k+N, measured from the police.

Some rules that still pass the new check:

  [pedit A, police drop/jump 1, B]
    TC jumps back to police and runs it again. mlx5 goes to B.

  [A, police drop/jump 2, B, C]
    TC runs B. mlx5 skips B and goes to C.

There is also the case of a jump that runs past the end of the list:

  [police1 drop/jump 3, police2 drop/pipe]

TC returns TC_ACT_OK here, because jmp_prgcnt > nr_actions. In mlx5,
jump_state.jump_count never reaches 0, so no attr gets jumping_attr.
police1->branch_true then keeps a plain post_act destination and reaches
police2. parse_tc_actions() never checks for a jump count left over
after the action loop.

Won't all of these rules be accepted for offload and then run a different
action sequence in hardware than TC runs in software?

>  	return !!mlx5e_get_flow_meters(parse_state->flow->priv->mdev);
>  }

[ ... ]

> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
> index 1d35c97aea0bc..7e7111e6d058b 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c

[ ... ]

> @@ -3891,11 +3891,17 @@ alloc_branch_attr(struct mlx5e_tc_flow *flow,
>  	case FLOW_ACTION_DROP:
>  		attr->action |= MLX5_FLOW_CONTEXT_ACTION_DROP;
>  		break;
> -	case FLOW_ACTION_ACCEPT:
>  	case FLOW_ACTION_PIPE:
> -		err = set_branch_dest_ft(flow->priv, attr);
> -		if (err)
> -			goto out_err;
> +		if (!last) {
> +			err = set_branch_dest_ft(flow->priv, attr);
> +			if (err)
> +				goto out_err;
> +			break;
> +		}
> +		fallthrough;
> +	case FLOW_ACTION_ACCEPT:
> +		attr->action |= MLX5_FLOW_CONTEXT_ACTION_FWD_DEST;
> +		attr->flags |= MLX5_ATTR_FLAG_ACCEPT;
>  		break;

[Severity: Low]
This isn't a bug, but the change to FLOW_ACTION_ACCEPT handling in
alloc_branch_attr() fixes a user-visible mismatch with TC. Before, a
police ok result ran the actions after police. TC accepts the packet and
stops instead.

The old "case FLOW_ACTION_ACCEPT: case FLOW_ACTION_PIPE:" handling comes
from commit f86488cb4685 ("net/mlx5e: TC, initialize branch flow
attributes").

Could this fix be split from the police-only feature and given a Fixes:
tag? It would also help to state whether it is meant for net/stable, so
it can be routed on its own.

>  	case FLOW_ACTION_JUMP:
>  		if (*jump_count) {

[ ... ]

-- 
Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261119040010.1405900-1-mohsin.bashr%40gmail.com
Technical Details
Message-ID: <179538498162.3135.15158973349412949279@kernel.org>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-368848-linux-kernel-netdev=dewy.ru
References: <20261119040010.1405900-1-mohsin.bashr@gmail.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-368848-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net-next v2] net: mlx5: Allow police as the last action of
 a TC rule
Date: Sun, 22 Nov 2026 22:03:01 +0000
Organization: Usenet Network
Message-ID: <179538498162.3135.15158973349412949279@kernel.org>
References: <20261119040010.1405900-1-mohsin.bashr@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="3733632"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:NqZvMirQSokqy91ozEWWuQjDSbg= sha256:u4V1WOP6FpZ/GPMoZDOdti/EH+vnyWuZUbyt56wcOy0=
	sha1:s1U6SX5dgdRRpiRqb+Z+dj2wB14= sha256:Ih7WtoojUeXVrjz3D/R5a9zzcfofjD0YwmGsXY5nRjI=
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 B3AA3125D88; Mon, 23 Nov 2026 01:03:20 +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 D-oFUf3mbyyj;
	Mon, 23 Nov 2026 01:03:16 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-368848-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 150D0125D5D; Mon, 23 Nov 2026 01:03:07 +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 582582B7F5; Sun, 22 Nov 2026 22:03:04 +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=1795384984;
	b=eADR6dhKXcoh5mmCy5RGQPRffk5tGiIbMUkXZDy0ADcRbmKksJg0+c8r6Bri9FR9hDAn
	 yRsItaZ9iKtg0fFSo6qnxZ+VnHlskJGpUKu3KmrwJushaGXoo07Ewa3ZhZDXuyFx2jw96
	 kZLbQ0oIbPRtwKjLImnGUiE5kiLBSohln/kiL0HryPXGy6sujA4z5Cj08nG2Jd8Lc8OED
	 YxAveFVSdqI2cVFfEnHajE8IEwSRQJQomqizWH0rs/RswKwVg/sylMXI/ogxZ4ktj0BYv
	 eMTEAwPsP/qpKlqaPSX3e1Q+QAFe6EmjDU2KXH4JOctC5qE3w6or/Y4W8XVNmat5C5w==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795384984;
	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=Dd2jOoQYjx0SN+L+IeyhT47RMzYPHgA9OxlNT8tCwBI=;
	b=25MKA6PT8QdsVliBkX11rvv3GOi2TEOZkq+/zuZwapER6cx6SO0tDs1IpzbZktv8KV1k
	 m4+Pi6MhCXqGUfqMGokh3BPMeM2FrNnddvtSMrpQIJgEwFUHOejTalI2rVaXHixMVo6vz
	 GrCzAzBbuRXbTwAuNTg5u59J2JoUP1Y9c6R2RI84u+SEtRURdkUdyOe4vQwJ9jr8S/9ne
	 1C2VSd9zOBoYXFXW0rdpC8JeYcKAf3cbmk8Rxs0X5+igIU9rWtjeMNo0Jste/v/eWYQJH
	 1iTNI9JuPmrw+cs27PKXMVMLcWJ3h3QJt8VddHrgbjC/JF4znLseIpnZHSB9+/YE65w==
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=PDJuNO4C;
	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 2BC0B606A330;
	Sun, 22 Nov 2026 22:03:04 +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=PDJuNO4C
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=1795384983;
	b=Z9lHdDTTbJVuK6BmlLqDqvJtMGV/8mhvLms7OovAirs8lVJX+rU/60QNdC+DQPDww6WT
	 gbBbeTdcEkDH/mpSR13siNnFIu7p024cERemLVnsN671pAvi7rzeWleY71AxigdGM//MC
	 vBXxBtEZJhkdHQzUDIabaQE+tN7guObQa32TTGda+47jT/FImRUzrwKNhR55Ess8A6hyU
	 iIUrIf2vhhPe2a7lkckEm/vb9zOzeeNlIdDhJPy9PC3LXJ7v3RbwhYWhj1+lQ+c0P2Zpz
	 e4mphsjCEDSBwQWLhAdGQFgDGjpH0LBFotaPeQzPMJvK0AkCTw1l20VATvc/u9ZCdzQ==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795384983;
	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=Dd2jOoQYjx0SN+L+IeyhT47RMzYPHgA9OxlNT8tCwBI=;
	b=fTXj/161e5DOOPNzH0WXbu+UDlFFEjbcV6rZgkmcfgQdJiQcFAY00ph1hA69Hq9yP9zI
	 PB7YGYiEV9NDWwXxAUhNW/Q0ck95JkFPUmfDugRYB2xwIuTa0dARb8GcwLJxIKRi3rC7P
	 8XkYjrVqMF2i7oXyB31N0ZuNqwcw72UMTD1jPR3jdMrtSUVlb6F4X1gGN6vUP82eDi6cp
	 wLg6xUZ4RekPx4K/XCKMZebq1x9skEc1lqqwTwRDmPmGANy3vuIMCRj8fFwbjcOho5gRa
	 eYzGyC0DWbpp6EG5ON/olU8t4iWeij5wAr82F1IBYEe5eli727ssFHzux2t2hJR5D1w==
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=PDJuNO4C;
	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 49DDF606A31A;
	Sun, 22 Nov 2026 22:03:03 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1CBA51F000C4;
	Sun, 22 Nov 2026 22:03:02 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1795384982;
	bh=Dd2jOoQYjx0SN+L+IeyhT47RMzYPHgA9OxlNT8tCwBI=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=PDJuNO4CUPLHuiqMlmLyFurxPur31NPXnmTjgHIlZFWhq3zd8T9DSQZx6oRH+/0c9
	 3j2OBVZlXuzmKp4HyVvN2nsn2Ij9XaOCeMN3Jnqh/hcnx6FjEThs5yaWflzN1Kb1Ud
	 u16mu/r23Byz+MCFpQpJ/S2Dyw9pKIItSU6EseMzMpggwPXLMIp8aLmbEBMI2ymecT
	 lK3WDkn5KAs+Njpcu+tKc8QBtcHPlb5hI54r2j/og2LfsJ2vDfoDjDg/crXAgIQJ68
	 07JCnmVTuAnxGwngZbPhqoOZe58GvUeul9QuTNWXZ4Ok6p2rTsrR6BwJf9x+Cbfj8I
	 ShTxsQcMm9m4w==
X-Cc: netdev@vger.kernel.org, saeedm@nvidia.com, leon@kernel.org,
 tariqt@nvidia.com, mbloch@nvidia.com, cjubran@nvidia.com,
 andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@kernel.org,
 kuba@kernel.org, pabeni@redhat.com, linux-rdma@vger.kernel.org,
 linux-kernel@vger.kernel.org
X-In-Reply-To: <20261119040010.1405900-1-mohsin.bashr@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