Linux RDMA and InfiniBand development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Mohsin Bashir" <mohsin.bashr@gmail.com>
Cc: linux-rdma@vger.kernel.org
Subject: Re: [PATCH net-next v4] net: mlx5: Allow police as the last action of a TC rule
Date: Wed, 02 Dec 2026 21:25:11 +0000	[thread overview]
Message-ID: <sashiko-outbox-246641@kernel.org> (raw)
In-Reply-To: <20261201212455.2836814-1-mohsin.bashr@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] net/mlx5e: miscompiled skipped actions in
  police_act_can_offload_jump()
--

commit ca98fcfa7fb19e6a3e27e9587d032f9f75c3bf2b
Author: Mohsin Bashir <hmohsin@meta.com>

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

This commit updates mlx5 TC police action offloading to allow police as the
last action in a flow, handle ok and terminal pipe branch controls as
accept, and validate police jump targets.

> 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..1e6babff8b2b7 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
> @@ -37,6 +37,52 @@ static int police_act_validate(const struct flow_action_entry *act,
>  	return 0;
>  }
>  
> +static bool
> +police_act_can_offload_jump(struct mlx5e_tc_act_parse_state *parse_state,
> +			    const struct flow_action_entry *act,
> +			    int act_index, u32 target)
> +{
> +	const struct flow_action *flow_action = parse_state->flow_action;
> +	struct netlink_ext_ack *extack = parse_state->extack;
> +	const struct flow_action_entry *prev, *entry;
> +	u32 i;
> +
> +	if (act_index) {
> +		NL_SET_ERR_MSG_MOD(extack,
> +				   "Jump is only supported when police is the first action");
> +		return false;
> +	}
> +
> +	if (!target || target >= flow_action->num_entries) {
> +		NL_SET_ERR_MSG_MOD(extack, "Jump target must be a later action");
> +		return false;
> +	}
> +
> +	prev = act;
> +	for (i = 1; i <= target; i++) {
> +		entry = &flow_action->entries[i];
> +
> +		if (i < target &&
> +		    (entry->id == FLOW_ACTION_MANGLE ||
> +		     entry->id == FLOW_ACTION_ADD ||
> +		     entry->id == FLOW_ACTION_POLICE)) {
> +			NL_SET_ERR_MSG_MOD(extack,
> +					   "Jump over a pedit or police action is not supported");
> +			return false;
> +		}

[Severity: Medium]
Can police_act_can_offload_jump() allow skipped action sequences that
dec_jump_count() and parse_tc_actions() miscompile into hardware rules?

dec_jump_count() only sets jump_state->jump_target and checks
tc_act->is_terminating_action when --jump_state->jump_count == 1:

drivers/net/ethernet/mellanox/mlx5/core/en_tc.c:dec_jump_count() {
	...
	/* nothing to do for intermediate actions */
	if (--jump_state->jump_count > 1)
		return;

	if (jump_state->jump_count == 1) { /* last action in the jump action list */

		/* create a new attribute after this action */
		jump_state->jump_target = true;

		if (tc_act->is_terminating_action) { /* the branch ends here */
			attr->flags |= MLX5_ATTR_FLAG_TERMINATING;
			attr->action |= MLX5_FLOW_CONTEXT_ACTION_COUNT;
		} else { /* the branch continues executing the rest of the actions */
			struct mlx5e_post_act *post_act;

			attr->action |= MLX5_FLOW_CONTEXT_ACTION_FWD_DEST;
			post_act = get_post_action(priv);
			attr->dest_ft = mlx5e_tc_post_act_get_ft(post_act);
		}
	...
}

When target >= 3, parse_tc_actions() merges all non-multi-table skipped
actions in 1 <= i < target into a single mlx5_flow_attr.  If an earlier
skipped action is terminating (for example, conform-exceed pipe / jump 3
followed by redirect eth1 and ok), TC software stops at entries[1], whereas
merging entries[2] into the same attr sets MLX5_ATTR_FLAG_ACCEPT or
combines incompatible actions (such as drop and ok) that fail in
verify_attr_actions().

Even when target == 2, several allowed skipped actions do not work with
the jump split in parse_tc_actions():
- FLOW_ACTION_TRAP has is_terminating_action == false on mlx5e_tc_act_trap,
  so dec_jump_count() overwrites attr->dest_ft (slow_fdb) with post_act->ft
  and chains the trap rule into the jump target instead of trapping to the
  CPU.
- Actions that only record state in parse_state (such as
  FLOW_ACTION_TUNNEL_ENCAP, FLOW_ACTION_TUNNEL_DECAP, FLOW_ACTION_MPLS_PUSH,
  FLOW_ACTION_PTYPE, FLOW_ACTION_VLAN_PUSH_ETH and FLOW_ACTION_VLAN_POP_ETH)
  leave their parse_state flags set across the jump_target split because
  parse_tc_actions() only resets parse_state->if_count = 0, applying the
  skipped action to the jump target attribute.
- Any skipped action with is_terminating_action == false does not get
  MLX5_FLOW_CONTEXT_ACTION_COUNT in dec_jump_count(), so
  mlx5e_tc_act_stats_add_flow() attaches the jump target's counter to the
  skipped action's cookie and counts packets that jumped over it.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261201212455.2836814-1-mohsin.bashr@gmail.com?part=1

      parent reply	other threads:[~2026-12-02 21:25 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01 21:24 [PATCH net-next v4] net: mlx5: Allow police as the last action of a TC rule Mohsin Bashir
2026-12-02 17:15 ` Mark Bloch
2026-12-02 21:25 ` sashiko-bot [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=sashiko-outbox-246641@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=mohsin.bashr@gmail.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /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