mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH net-next] net: mlx5: Allow police as the last action of a TC rule
@ 2026-11-17  3:13 Mohsin Bashir
  2026-11-17 19:18 ` Mark Bloch
  2026-11-18 18:13 ` netdev-bot+sashiko
  0 siblings, 2 replies; 6+ messages in thread
From: Mohsin Bashir @ 2026-11-17  3:13 UTC (permalink / raw)
  To: netdev
  Cc: saeedm, leon, tariqt, mbloch, cjubran, andrew+netdev, davem,
	edumazet, kuba, pabeni, linux-rdma, linux-kernel

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;
+
 	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)
-- 
2.53.1-Meta


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH net-next] net: mlx5: Allow police as the last action of a TC rule
  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-18 18:13 ` netdev-bot+sashiko
  1 sibling, 1 reply; 6+ messages in thread
From: Mark Bloch @ 2026-11-17 19:18 UTC (permalink / raw)
  To: Mohsin Bashir, netdev
  Cc: saeedm, leon, tariqt, cjubran, andrew+netdev, davem, edumazet,
	kuba, pabeni, linux-rdma, linux-kernel, idosch

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?

> +
>  	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.

Mark


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH net-next] net: mlx5: Allow police as the last action of a TC rule
  2026-11-17 19:18 ` Mark Bloch
@ 2026-11-17 21:52   ` Mohsin Bashir
  2026-11-17 22:14     ` Mark Bloch
  0 siblings, 1 reply; 6+ messages in thread
From: Mohsin Bashir @ 2026-11-17 21:52 UTC (permalink / raw)
  To: Mark Bloch, netdev
  Cc: saeedm, leon, tariqt, cjubran, andrew+netdev, davem, edumazet,
	kuba, pabeni, linux-rdma, linux-kernel, idosch



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?

>> +
>>   	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?

> Mark
> 


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH net-next] net: mlx5: Allow police as the last action of a TC rule
  2026-11-17 21:52   ` Mohsin Bashir
@ 2026-11-17 22:14     ` Mark Bloch
  2026-11-18  0:52       ` Mohsin Bashir
  0 siblings, 1 reply; 6+ messages in thread
From: Mark Bloch @ 2026-11-17 22:14 UTC (permalink / raw)
  To: Mohsin Bashir, netdev
  Cc: saeedm, leon, tariqt, cjubran, andrew+netdev, davem, edumazet,
	kuba, pabeni, linux-rdma, linux-kernel, idosch



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
>>
> 


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH net-next] net: mlx5: Allow police as the last action of a TC rule
  2026-11-17 22:14     ` Mark Bloch
@ 2026-11-18  0:52       ` Mohsin Bashir
  0 siblings, 0 replies; 6+ messages in thread
From: Mohsin Bashir @ 2026-11-18  0:52 UTC (permalink / raw)
  To: Mark Bloch, netdev
  Cc: saeedm, leon, tariqt, cjubran, andrew+netdev, davem, edumazet,
	kuba, pabeni, linux-rdma, linux-kernel, idosch



On 11/17/26 2:14 PM, Mark Bloch wrote:
> 
> 
> 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.
> 
>>

Yeah, jump restarts the list. Before this patch police as the last 
action was rejected anyway, so I believe rejecting jump there in the 
respin should be okay?

>>>> +
>>>>        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?
> 

Yeah probably.

> 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.

Yeah, in both cases (police and gact ok) the conforming packets are 
pushed up, where they get dropped by the skip_hw rule. My understanding 
is that with existing behavior the restore doesn't happen on accept 
path, so sw tc takes the packet through classification again.

> Mark


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH net-next] net: mlx5: Allow police as the last action of a TC rule
  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-18 18:13 ` netdev-bot+sashiko
  1 sibling, 0 replies; 6+ messages in thread
From: netdev-bot+sashiko @ 2026-11-18 18:13 UTC (permalink / raw)
  To: mohsin.bashr
  Cc: netdev, saeedm, leon, tariqt, mbloch, cjubran, andrew+netdev,
	davem, edumazet, kuba, pabeni, linux-rdma, linux-kernel

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] This patch makes a rate police allowed as the last action.
- [Low] The `FLOW_ACTION_ACCEPT` change in `alloc_branch_attr()`
  (en_tc.c:3894-3897) changes how already-deployed police rules forward…

--

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

In switchdev mode, this commit lets mlx5 offload a TC rule whose only or
last action is police. tc_act_parse_police() now sets
MLX5_FLOW_CONTEXT_ACTION_FWD_DEST for rate police as well as mtu police,
so verify_attr_actions() no longer rejects the rule. The police ok result
now goes to the end of the TC chains instead of being treated as pipe.

> 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..52295f5d644c5 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;
> +

[Severity: High]
Every rate police now sets FWD_DEST, so verify_attr_actions() accepts a
police-last rule whatever its conform/exceed results are. What happens
when the result is pipe or jump? For example:

  action police rate 100mbit burst 1m conform-exceed drop/pipe

alloc_branch_attr() still sends PIPE and JUMP through set_branch_dest_ft().
That function only points the branch at the post_act table:

  attr->action |= MLX5_FLOW_CONTEXT_ACTION_FWD_DEST;
  attr->dest_ft = mlx5e_tc_post_act_get_ft(post_act);

It does not write FTEID_TO_REG. Only mlx5e_tc_post_act_set_handle() writes
that register, through mlx5e_tc_act_set_next_post_act().
alloc_flow_post_acts() calls that only when a following attr exists:

  if (next_attr && !(attr->flags & MLX5_ATTR_FLAG_TERMINATING)) {
          err = mlx5e_tc_act_set_next_post_act(flow, attr, next_attr);

The jumping_attr case set up in dec_jump_count() also needs a later attr.
When police is the last action, neither path runs.

The post_act rules match only on the register:

  mlx5e_tc_match_to_reg_match(spec, FTEID_TO_REG, handle->id, MLX5_POST_ACTION_MASK);

On chain 0 the register is 0 and ids start at 1. The lookup misses and the
packet falls through, which happens to behave like accept.

If the packet reached this rule through an earlier post_act hop, though,
nothing clears the register. Take a CT pipeline: chain 0 has "ct zone Z
pipe action goto chain 1", and a chain 1 rule has "ct_state +trk+est
action police ... conform-exceed drop/pipe".

In that setup, couldn't green packets go back to the post_act table, match
the chain 0 rule's entry again, repeat its actions (goto chain 1), hit the
same meter, and loop? Any mirror, redirect or counter in that earlier entry
would also run again.

mtu police already set FWD_DEST before this patch, so it had the same gap.
This patch now exposes it for rate police too.

Should pipe at the end of the action list, and jump past the end, also go
to the end of the TC chains as ACCEPT now does? Or should they be rejected?

>  	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 1d35c97aea0bc..8685e41487f39 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;

[Severity: Low]
This isn't a bug, but the change also affects existing offloaded rules
where other actions follow police, not only police-last rules.

Before, ACCEPT fell through to PIPE (from commit f86488cb4685 "net/mlx5e:
TC, initialize branch flow attributes"). An ok branch went to the post_act
table and ran the following actions.

Now MLX5_ATTR_FLAG_ACCEPT makes esw_setup_dests() call
esw_setup_accept_dest(), which sends the branch to the chains end table.

tcfp_result defaults to TC_ACT_OK when TCA_POLICE_RESULT is absent, so the
common form is affected too:

  police ... conform-exceed drop action mirred egress redirect dev X

Conforming traffic that was redirected in hardware now goes to the end of
the chains.

This matches software TC semantics. Could it be split into its own fix
with a Fixes: f86488cb4685 tag? Could the commit message also say that
existing offloaded rules will forward traffic differently?

>  	case FLOW_ACTION_PIPE:
>  		err = set_branch_dest_ft(flow->priv, attr);
>  		if (err)

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261117031337.4126403-1-mohsin.bashr%40gmail.com

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-11-18 18:13 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2026-11-18  0:52       ` Mohsin Bashir
2026-11-18 18:13 ` netdev-bot+sashiko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®