From: Mark Bloch <mbloch@nvidia.com>
To: Mohsin Bashir <mohsin.bashr@gmail.com>, netdev@vger.kernel.org
Cc: saeedm@nvidia.com, leon@kernel.org, tariqt@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,
idosch@nvidia.com
Subject: Re: [PATCH net-next] net: mlx5: Allow police as the last action of a TC rule
Date: Wed, 18 Nov 2026 00:14:54 +0200 [thread overview]
Message-ID: <194e1103-0d28-45d4-986a-819955e11268@nvidia.com> (raw)
In-Reply-To: <09ae2064-38ff-4d25-83e5-0ac4c3eb1658@gmail.com>
On 17/11/2026 23:52, Mohsin Bashir wrote:
>
>
> On 11/17/26 11:18 AM, Mark Bloch wrote:
>> On 17/11/2026 5:13, Mohsin Bashir wrote:
>>> From: Mohsin Bashir <hmohsin@meta.com>
>>>
>>> In switchdev mode, mlx5 offloads police only when other actions follow
>>> it. TC needs no extra action for a police-only rule to work. The mlx5
>>> driver makes every police rule forward to the post meter table, but for
>>> a rate police it adds that forward only after verify_attr_actions() has
>>> checked the rule, so the check rejects it. The ok result of police is
>>> also handled as pipe. In TC, ok accepts the packet and ends the action
>>> list, whereas mlx5 goes on with the actions after police.
>>>
>>> Support police as the only action of a rule. Set the forward while
>>> parsing police, as is already done for police with mtu, and forward
>>> an ok result to the end of the TC chains, as the driver does when it
>>> offloads the gact ok action. The upcoming selftest series also relies on
>>> such rules for TC offload validation.
>>>
>>> The patch was tested on a ConnectX-7 in switchdev mode with the command
>>> below, and it was verified that the rule is offloaded and limits the
>>> matching traffic to the configured rate, using the hardware drop counter.
>>>
>>> tc filter add dev eth0 ingress pref 100 protocol ipv6 flower skip_sw \
>>> ip_proto udp dst_port 5201 \
>>> action police rate 100mbit burst 1m conform-exceed drop/ok
>>>
>>> Cc: Carolina Jubran <cjubran@nvidia.com>
>>> Signed-off-by: Mohsin Bashir <hmohsin@meta.com>
>>> ---
>>> drivers/net/ethernet/mellanox/mlx5/core/en/tc/act/police.c | 3 ++-
>>> drivers/net/ethernet/mellanox/mlx5/core/en_tc.c | 3 +++
>>> 2 files changed, 5 insertions(+), 1 deletion(-)
>>>
>>> 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 1bd1c94fb977..52295f5d644c 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
>>> @@ -94,13 +94,14 @@ tc_act_parse_police(struct mlx5e_tc_act_parse_state *parse_state,
>>> MLX5_FLOW_STEERING_CAP_MATCH_RANGES))
>>> return -EOPNOTSUPP;
>>> - attr->action |= MLX5_FLOW_CONTEXT_ACTION_FWD_DEST;
>>> attr->flags |= MLX5_ATTR_FLAG_MTU;
>>> } else {
>>> attr->action |= MLX5_FLOW_CONTEXT_ACTION_EXECUTE_ASO;
>>> attr->exe_aso_type = MLX5_EXE_ASO_FLOW_METER;
>>> }
>>> + attr->action |= MLX5_FLOW_CONTEXT_ACTION_FWD_DEST;
>>
>> This makes every police that is the lact action pass verify_attr_actions()
>> not only ok case described.
>>
>> what happens with:
>> "police ... conform-exceed drop/pipe"
>> with this not writes to FTEID_TO_REG so what happens once a packet
>> reaches the port action table?
>>
>> also what about:
>> tc filter add dev eth0 ingress pref 100 protocol ipv6 flower skip_sw \
>> ip_proto udp dst_port 5201 \
>> action police rate 100mbit burst 1m conform-exceed drop/pipe \
>> action police rate 100mbit burst 1m conform-exceed drop/pipe
>>
>> won't this create a loop?
>>
>
> Thanks for reviewing Mark.
>
> Ahh! I missed the loop case. I had a patch to handle pipe on the last police but I dropped it, since my testing showed the post_act table still passed the packets up. Let me respin and send pipe and jump on the last police to the end of the TC chains. Would that work in your opinion?
Yes for PIPE.
For JUMP, we need to check the target. tcf_action_exec() counts from
the start of the action list, so even the last police can jump back
to itself or an earlier action. If we can't offload that, we should
probably reject it.
That's how I read tcf_action_exec(), but please correct me if I'm
missing something as I'm not really a tc expert.
>
>>> +
>>> return 0;
>>> }
>>> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
>>> index 1d35c97aea0b..8685e41487f3 100644
>>> --- a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
>>> +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
>>> @@ -3892,6 +3892,9 @@ alloc_branch_attr(struct mlx5e_tc_flow *flow,
>>> attr->action |= MLX5_FLOW_CONTEXT_ACTION_DROP;
>>> break;
>>> case FLOW_ACTION_ACCEPT:
>>> + attr->action |= MLX5_FLOW_CONTEXT_ACTION_FWD_DEST;
>>> + attr->flags |= MLX5_ATTR_FLAG_ACCEPT;
>>> + break;
>>> case FLOW_ACTION_PIPE:
>>> err = set_branch_dest_ft(flow->priv, attr);
>>> if (err)
>>
>> This also changes rules where police is not the last action.
>> The conform result defaults to ok when it is not given.
>>
>> action police rate 100mbit burst 1m conform-exceed drop \
>> action mirred egress redirect dev eth2
>>
>>
>> won't with this change the conforming packets go to the tc end table
>> and not to the redirect dev?
>> The rule is still reported as offloaded and installs the redirect
>> which can't reached now.
>>
>
> Maybe I am missing something here, but when the conform action is not given, doesn't it default to ok? For example, if we have
> action police rate 100mbit burst 1m conform-exceed drop action drop
> shouldn't conforming packets still be pushed up rather than dropped by the following action, making the action drop (or the action mirred) dead code?
>
Yes, agreed, the following action is dead code in software too,
a separated cleanup patch maybe?
What about packets that reach the rep? I don't see anything in
the ACCEPT path that tells software TC the packet has already been
processed. For example:
tc filter add dev eth2 ingress pref 100 protocol ipv6 flower skip_sw \
ip_proto udp dst_port 5201 \
action police rate 100mbit burst 1m conform-exceed drop/ok
tc filter add dev eth2 ingress pref 200 protocol ipv6 flower skip_hw \
ip_proto udp dst_port 5201 \
action drop
Wouldn't a conforming packet reach software, skip the first rule and
get dropped by the second, despite already being accepted in hardware?
Can you test this? The existing gact ok path might have the same issue.
Mark
>> Mark
>>
>
prev parent reply other threads:[~2026-11-17 22:16 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 3:13 [PATCH net-next] net: mlx5: Allow police as the last action of a TC rule Mohsin Bashir
2026-11-17 19:18 ` Mark Bloch
2026-11-17 21:52 ` Mohsin Bashir
2026-11-17 22:14 ` Mark Bloch [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=194e1103-0d28-45d4-986a-819955e11268@nvidia.com \
--to=mbloch@nvidia.com \
--cc=andrew+netdev@lunn.ch \
--cc=cjubran@nvidia.com \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=idosch@nvidia.com \
--cc=kuba@kernel.org \
--cc=leon@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=mohsin.bashr@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=saeedm@nvidia.com \
--cc=tariqt@nvidia.com \
/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