🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #18123

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

#18123
From: Mohsin Bashir
Date: Tue, 17 Nov 2026 21:52
118 lines
16196 bytes

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
> 
Technical Details
Message-ID: <09ae2064-38ff-4d25-83e5-0ac4c3eb1658@gmail.com>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-365632-linux-kernel-netdev=dewy.ru
References: <20261117031337.4126403-1-mohsin.bashr@gmail.com> <82d9959a-8176-4433-94a4-ff72445306ca@nvidia.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-365632-linux-kernel-netdev=dewy.ru
From: mohsin.bashr@gmail.com (Mohsin Bashir)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net-next] net: mlx5: Allow police as the last action of a
 TC rule
Date: Tue, 17 Nov 2026 13:52:00 -0800
Organization: Usenet Network
Message-ID: <09ae2064-38ff-4d25-83e5-0ac4c3eb1658@gmail.com>
References: <20261117031337.4126403-1-mohsin.bashr@gmail.com>
 <82d9959a-8176-4433-94a4-ff72445306ca@nvidia.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: usenet.network;
	logging-data="2435257"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:Ih2ZyCx86XKITzToIBRnkSk+avo= sha256:nWyujDzUll7MCSTpppeI2Iy4uBVQ1e5npdd86shLQ5c=
	sha1:l4fp2QDdkZYmG1giRZ35HJa7/3c= sha256:9DUyZqxxHsMrwjDLPJgFGiZPNyrU2TII7OuJEfhPAhk=
Content-Language: en-US
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 6CA3411509F; Wed, 18 Nov 2026 00:52:25 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.049
X-Spam-Status: No, score=-3.049 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.001,
	FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=gmail.com
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 Aqap2nPXHpiy;
	Wed, 18 Nov 2026 00:52:21 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-365632-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id F422811509D; Wed, 18 Nov 2026 00:52:10 +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 926AE6041C; Tue, 17 Nov 2026 21:52:05 +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=1794952324;
	b=Gwzlltw8gC4KLoqEZ5NZNjO7FMTxZqB6Hlfo/Xus3HTUL189dSjuaEm75e9XN+Kf5VfG
	 Y7kWQW0+gUkzWW30D1h1ORvYN/DH+CjwL2ou/opGG92/3A4BlDc5FZ3GpthQ1GD/P8WZ9
	 X3q9skFsZgCyNF7cKyceVkdNy/4nh9EcfEwMFK+0927YHSjCpW6Z43ZjgXXBc1wILrYSf
	 rM9mQ5OY6UlG5nR8jgfF8NdNl+IPpPkn8ZPjza2nBHI7y3w1tfNRfWF6lfSqcrirkFLmY
	 pusyY7pPpTbSP3ACpu70Qi+d2FefVFyoLk30TVbB/54DWbM1IucEeXvyKu4jsUkQ4pg==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794952324;
	h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
	 X-Google-DKIM-Signature:X-Forwarded-Encrypted:X-Gm-Message-State:
	 X-Gm-Gg:X-Received:Received:Message-ID:Date:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version:User-Agent:Subject:To:Cc:References:
	 Content-Language:From:In-Reply-To:Content-Type:
	 Content-Transfer-Encoding;
	bh=1qwGms5hMR2ux4q7/I/Tiy8y6p3Q9O52I2CVtKqKrq4=;
	b=uQURRHzUHxDMWHvx266744M1Uh/nIm85K3Hq2XHKEUMlphwsT6a/MwBE+PhNicezDFiy
	 q999tCW16c8fkxs/s6B19r8Ihq41TnVkpaKyD3GyaO5hJ/eUHbMu8Nowgk1aHfwaT88R9
	 rOawfr2Tow7SYv2SQQHBHWJWVqFOgcUBl7sYfY9G4/As4LfE/OxoA5OYfSAbrOy2rimiq
	 AWXUxyasUUf3IncVewL8NMs0iPl0saqzzRRms3uTqD/d+3mqVe2ZArA5fn16AKoJf82Lw
	 2tI78iV2VS3VuzcvWZ9YF9ez4HwPF+ySwjuhKcMRXHAx1MlOD1yNEAmH99XweNQLjrA==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=udPMbES0;
	dmarc=pass header.from=gmail.com;
	spf=pass smtp.mailfrom=gmail.com;
	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 D309C606A33F;
	Tue, 17 Nov 2026 21:52:04 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=udPMbES0
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.176
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1794952324;
	b=y43EV1VFQq/l3vZxvvvK4YAx96AvFXIonvSI9R0UpDHmGhrjoZwn94rocvEtac70mrqf
	 8tnG7Z88qZPEusGjlzvwm4E5wQfOv2lvmHg3zNEJ8GtRVcGT1+koDeKV6FY5mrsvfGhB6
	 d9U3oghTNhB6Pj4pb1FovdYERVaCxg8Dna+TEdUU/2A0TvW/cmz3AvjMW9A60dp0WjBL8
	 BW2lMDDtSCj9BcWxy/A0wfoWSgC4pKSb7GjStBLDGn/MFDHhrua57RXCku3ktQziFzWlT
	 GziZsvC6hwtuyuC1AXQhCe+W5fl2lf9NFqQrkVVb5020p9mpCPRTr7xfaaft2wz5/Tw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794952324;
	h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
	 X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received:
	 Message-ID:Date:MIME-Version:User-Agent:Subject:To:Cc:References:
	 Content-Language:From:In-Reply-To:Content-Type:
	 Content-Transfer-Encoding;
	bh=1qwGms5hMR2ux4q7/I/Tiy8y6p3Q9O52I2CVtKqKrq4=;
	b=W0w5WAld1Ezi1aAoxeA1C974h/n99LYUr6u02kz3AWjATFOj3x7K5CSwGkqYN1v+rglr
	 9N5VZfJBzE7wTMtXN+URouzEsThrcpY/nMqtADPEYir1ljpn/IZHRTozYYlqSyXX1rVaI
	 xA0evxTiVthyBn48u/H4xBxdwSYXtnJQaRBqXL5BWLyHtsRWs4bqhGB5yWT41ekuqicES
	 vpmSXT4mV5a0VxjAhuMltyRXF/zywR/BySt1kpvRR3FORwVvoiB7lXlBNDPdp+Gakfjga
	 ZEpOsHhMSRbWhymvL+h+H/2THOy9J67u96QhjFp541R6hBlRNW4ZJFtHY30zIz+77Dw==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=gmail.com;
	spf=pass smtp.mailfrom=gmail.com;
	dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=udPMbES0;
	arc=none smtp.remote-ip=74.125.82.176
X-Received: from mail-dy1-f176.google.com (mail-dy1-f176.google.com [74.125.82.176])
	(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2886F606A32A
	for <netdev@vger.kernel.org>; Tue, 17 Nov 2026 21:52:02 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 2886F606A32A
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-dy1-f176.google.com with SMTP id 5a478bee46e88-381f65e4e4bso624240eec.0
        for <netdev@vger.kernel.org>; Tue, 17 Nov 2026 13:52:02 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20260707; t=1794952322; x=1795557122; darn=vger.kernel.org;
        h=content-transfer-encoding:content-type:in-reply-to:from
         :content-language:references:cc:to:subject:user-agent:mime-version
         :date:message-id:from:to:cc:subject:date:message-id:reply-to
         :content-type;
        bh=1qwGms5hMR2ux4q7/I/Tiy8y6p3Q9O52I2CVtKqKrq4=;
        b=udPMbES0S0UI5JNlspXvnRXGLvL+W2zq0yiU1w96P37k5Clj8PLIHs74era0RAU0Ck
         hxRFnHVeaE1+K46NXpoMDEBiOQN/jbrobcU5NvTyPHLWcBaeZ9WOZBsY3pWYImVnK1l/
         Tz5SAWxpqn/9xRjvU+94p5aXsYnx1riQgoEdSjoPMC7+epTrL4hPPk7UGIoGiyMVNFdb
         qo5xaFet9hI6c8jd4rUhZpd6duPUY/0wB8iRajlAOC62OMBievQT89txsk3+q/fUv9+c
         8/1IDUj/+gx+Q5KvRQ+7UwJVQHznrEP1SfY8LzaZLCQWEf3256bjNMGf1Se7W/eHIxMu
         NAXQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20260707; t=1794952322; x=1795557122;
        h=content-transfer-encoding:content-type:in-reply-to:from
         :content-language:references:cc:to:subject:user-agent:mime-version
         :date:message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date
         :message-id:reply-to:content-type;
        bh=1qwGms5hMR2ux4q7/I/Tiy8y6p3Q9O52I2CVtKqKrq4=;
        b=EDUkjWT9Z3K6sZBJidSKZT9C+Zt0MMyUlgocJl3tjhHBwtthwbf7Kw+KLZWSbEcrot
         inq1/KJlOU4vgJm9yRAtU32MHcRq6HPjyRzQEG/2sTBCR5BQ/Oxq1GCiTRdpDk1F/1oR
         Oj8lsT4yxHCP4OlZmEDTDd4CNrBxzMSTo2jRCspOPDtCTtVpiUl8DNLKzVUY6tc8O87m
         0KbnqUzFWv1rsJTS2hueYWJow4Fin2Q6UoP8p1EyjR2xubAKtUGv9ApGGPqiA5WWvpXv
         3xmHSGMYKan1zOMFswYyE2Fjt6OHEt+jyQSSmxFNpUoY6ih6vWcV357a3G0VOaYAaYij
         qPUA==
X-Forwarded-Encrypted: i=1; AL+hErGwyn89hwyX+eDVeL3kvEE8uhQBVHXLgQLZ2UyLw1vQaaIj1rk7CuTV0PFHcPGuVPpTf23uAY0=@vger.kernel.org
X-Gm-Message-State: APuU4Z8pn0hP/KT3d1OTOZ78dFMUUuvkFKtYkrR+uq2lu4Re0wXYvOZt
	8gx57TK7LMlUhzuKaIK2YtetUjm3MtqCB9ybPRu0tqYQMnO7E6RbKzPx
X-Gm-Gg: AZFdTZelUnMnGHvj6xKiIwJi9QRZqaH7y/nbHpWJ6oIKulkGyhP1KfARMnDjMKeLDkC
	kedoP/Xw6PAJfUGo+NafwFhQVf9DT/wB8oRx2wxpn7qAxR8GxOdy/25sxJ4U/AtW0bVzVXWccdE
	uIuqGRbB0BKtEG9lydApDtDhmnv+Rhq1wIZOeCNifQ1Qr0uuk/FVAmnRCH+m1CKqumtQFUpUfbN
	pkfSkArzwzBqelrrpDcu7AfcKRwxsYxEmpVSZJoT4dcbfAP9EfNruVDdOhMLx8/j34YRqO8HAxm
	pUp5AFlT8svz97gmwqpk9mT30CYIanSPKdMT6Q6q9IKC/839wTCZOheS1/kvJHcFzZdGPOaQmY3
	I/dSu1EmHszQaoDL6ViwOa85VlILJpCElNQEAfZEwfzIR3rcWsr4vQx9FgaBmWs3T/ubD59qQ0C
	irWiYkAAsoUCXaKAr+7eBxb/Z4NvlMZh9brW0Epy2zkq2WeY/nARVfuHaIqNEbtQ2JsmX3gaG1v
	DAOVO7LqJWVYX2k6QDyhNewoSoWFbP7pjiMIs3IKWBlQclSCAS4/nOR7zxHOpVgMPlBqJryVYyP
	iGLUMFQvrz5hBDNaUitURqw6nm8GX8uRyovEjJxtgGfXAVVBAcrjdu2djiahqO8uNi0=
X-Received: by 2002:a05:7301:da17:b0:378:314:402c with SMTP id 5a478bee46e88-382814260bamr585440eec.28.1794952322062;
        Tue, 17 Nov 2026 13:52:02 -0800 (PST)
X-Received: from ?IPV6:2620:10d:c085:21d6::11c9? ([2620:10d:c090:400::5:bd16])
        by smtp.gmail.com with ESMTPSA id 5a478bee46e88-382a4522829sm852730eec.1.2026.11.17.13.52.01
        (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);
        Tue, 17 Nov 2026 13:52:01 -0800 (PST)
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
X-User-Agent: Mozilla Thunderbird
X-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
X-In-Reply-To: <82d9959a-8176-4433-94a4-ff72445306ca@nvidia.com>