From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.175 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796149734; b=x9XphUMQ8n7ueytD4psB1/wUGdtF6KVO5qIOni8XSnk5P1Co0Yz2gZb1oDEMNJMc56f9 LqBGgOxKHJOSdr0jVF2EV7u8rQyewYw/y3GyW8Arz6sAPGqZAqSg2YxgWGd4hN0MhZ7uF YQG6hirFQ0vhpbZIh2tz25i6fBahEjmgPSJ+JEnIW7WcWkG1DNFcB3TeMzBOyGvvp+Xj8 +4mtvwinMztGSfF6a791ClnHVHVLuihJVvi25OZVNFcx2zNJl9dCs+NnIJLmfyplsGdMr yiFHBnZMWfXjsZELbcN7owDiGsIuOaqoXBlMx1eAYuz8QawANY45A9JnYTCOmaMmIpw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796149734; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: 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=/gsSNXD1/zp59XBIKnk+T06HOsvA/echoC8hXt3G/PM=; b=GKO9dI+r6pY1K01KgcGs4b3jOH/efZMCtxJ4WP9ErVMES/pO5y8ctkc11psVCWE96FUT m93JASqlZYTtjv6YR/N6hnaNyRdiTrSNA2cBsR5Nfti67jPgZiHDhBEYjHLwQUxbZFEKF gkO5PxaQSI2GMfLww2M7vFmdd1L0EPPC0RXhhWf11tSnF87w3YzLBgjdFQ02+pykzWSN5 N/ugGL97BApYlSQ9PhiQbg1ozenQ/Vpr8Y9Qyy1srKbI9PmWkr7Y44DCeUq75s+oas46w QYeR6qGx0QyJDovKyBxExoeFZbeaLUSSSEewjszjjS0UJvWFhyIxN0V4VYzE/Rb9zLg== 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=c1tdpQTp; arc=none smtp.remote-ip=74.125.82.175 Received: from mail-dy1-f175.google.com (mail-dy1-f175.google.com [74.125.82.175]) (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 F0C1B606A320 for ; Tue, 1 Dec 2026 18:28:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org F0C1B606A320 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com 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=c1tdpQTp Received: by mail-dy1-f175.google.com with SMTP id 5a478bee46e88-385d8a00598so20907029eec.1 for ; Tue, 01 Dec 2026 10:28:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796149733; x=1796754533; 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=/gsSNXD1/zp59XBIKnk+T06HOsvA/echoC8hXt3G/PM=; b=c1tdpQTplmVE8E5jMuYzgjF53UHuqxlbBl2QSt3leJi5KtLC48F892qUPHqiP6Q/CF PDtMt4f8mq9iQDhc69b+DBDqc3dvYx0CRBMV73hOE3U+EiZCEftUGvhYit2hK06LsuJV CdD2Z5OfXbE513u7Tb8sxadPu6j40qKV0KIF40odIGVD/5F4ICfmngq/5dlnW1iflfG8 fs+xIAKggtAjLMOx9vletPY+UslS1SUNqghDpzn4Wx2JBGKxIqw2tMEqHZKcZrFFgN2O ej3G4hxOAwZEymtMRy88ChCko1yzbHSZDb+mr1px7konUv12WQq4G+BnxHGHbG73KHRN JzCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796149733; x=1796754533; 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=/gsSNXD1/zp59XBIKnk+T06HOsvA/echoC8hXt3G/PM=; b=pQA6KnRTfIgcGdwkJnomQgsxtyceFZh/41p5R0SITdc0peoi3id5hHi3dPFohLnUzX Bajq+pL0XFjNWK/CSrz8w02AUsyayHAvFt3gogPFpABgeiCDwWnfOe6cWxL1agzFx4jN FYEBCPi49CACo6vpufc8gi/7jo1I9XS9QEnVdjU3K+bcgVNuy5Ozbvgk2wEO7W3AahEh +KEeNUgriq8kcXeO66c4KUJdTvJKAnrJUai6/5oSOVIUUko4Ajc0/T2tWPA4cYfsJkKd CSJyjoiAMe+ZNC+7vZgaWYfQdVApcd/2eG5aHSOrrn95FENGeFE3DepiQm9NVsAXupnR HvdQ== X-Gm-Message-State: APuU4Z+zLrUy2J+Lfbfu0UeOsU5QzI/81Q+T/oACzBzBON/Muls51cv6 NdO4QlUUC/drOsB43II1CzsnaRILw0EuJq779qMWF6/RWphaGQLd7U8M X-Gm-Gg: AZFdTZeImDRxiD6/A+7NqkJyTVGUah7OtisUOUfrY7TtqKPV5A8tv5I1vlSlumQkqcl t+dC4ri+/XnL13kjwoyTiHva3BA3+z1vg/Ya1TeNgSeFrC9ntF/CpJ3gmwoA0E2yRdBRW2Qp1yQ 9s1pH7AY7UOG4Gx/esLTbzrdLJckhilG4ae+75YNJqqf0c7i6JfmgH2tpaIT7aa2U4v2vvAvysj jlYVltT5dEETXReqO7yDP0nfg95Xndhxlv5oF6sV5Zyv+dWCGw0+j3LHY5Z1Twr2Cof0cqKqKd+ X5bVC+6LmutjOiMHkXImjnfjkluRMXrNSj3WYKN+QpQfRv099J0KSVNqN3fRfJcGwJlFYASWw7j DJ7SkXP6v9COxYxqsq+PsvKBInLIXtcQnoRbNmHBzclaWv6MViyBOouJLSMkXtPGyo7UjazmgoW rNBhNsAp2UJz0vjsanbZQubdEh/iA3fboKvcT4vT9WihHogNb+mGfIiyWxLteH5XQwPFYtmR+bH UYKQgAkn704LUC+/ms0ICZzMHBl0HqCeUcUXxQjZF/f37yLiW7jdPIeJwc/Q8jbFsDafBfbFZnq BDhyrwOoVL8LVlrWotaPemeZO8Y41ek/OTmOdq/h1MXxvaF/TpxQ88RmlOdA8pkWfQRfdUeKqL1 /g5tbqtxZeljoKwYESVBAkYS9XNEl X-Received: by 2002:a05:693c:414d:20b0:386:9f89:aa80 with SMTP id 5a478bee46e88-3869f89aee3mr32365863eec.0.1796149732753; Tue, 01 Dec 2026 10:28:52 -0800 (PST) Received: from ?IPV6:2a03:83e0:1151:15:18db:c1e7:4974:be38? ([2620:10d:c090:500::6:f3a8]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-385646633d0sm190490442eec.3.2026.12.01.10.28.51 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 01 Dec 2026 10:28:52 -0800 (PST) Message-ID: <8b41c3f8-dc65-4f04-b5d1-99ed19483aa1@gmail.com> Date: Tue, 1 Dec 2026 10:28:51 -0800 X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH net-next v3] net: mlx5: Allow police as the last action of a TC rule To: Mark Bloch , netdev-bot+sashiko@kernel.org Cc: netdev@vger.kernel.org, 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 References: <20261124220251.776944-1-mohsin.bashr@gmail.com> <179570909592.3135.1382351175870070773@kernel.org> Content-Language: en-US From: Mohsin Bashir In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 12/1/26 5:04 AM, Mark Bloch wrote: > > > On 26/11/2026 23:54, Mohsin Bashir wrote: >> >> >> On 11/26/26 8:04 AM, netdev-bot+sashiko@kernel.org wrote: >>> Thank you for your contribution! Sashiko AI review found 2 potential >>> issue(s) to consider. >>> >>> Critical: 0 · High: 0 · Medium: 1 · 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). >>> >>> - [Medium] In police_act_can_offload_jump() >>>    (drivers/net/ethernet/mellanox/mlx5/core/en/tc/act/police.c), every… >>> - [Low] Besides adding police-as-last-action support, the patch fixes two >>>    hardware/software mismatches in existing offloaded rules, both present… >>> >>> -- >>> >>> net: mlx5: Allow police as the last action of a TC rule >>> >>> This patch lets mlx5 offload TC rules in switchdev mode where police is >>> the last action. It also changes how police results are offloaded: ok is >>> now accept, pipe as the last action is accept, and a jump is only >>> offloaded when police is the first action and the skipped actions are all >>> drop or all ok. The forward to the post meter table is now set for rate >>> police as well as mtu police. >>> >>>> 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..f03a992cbc270 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) >>>> +{ >>> >>> [ ... ] >>> >>>> +    prev = act; >>>> +    for (i = 1; i <= target; i++) { >>>> +        entry = &flow_action->entries[i]; >>>> + >>>> +        if (i < target && >>>> +            ((entry->id != FLOW_ACTION_DROP && >>>> +              entry->id != FLOW_ACTION_ACCEPT) || >>>> +             entry->id != flow_action->entries[1].id)) { >>>> +            NL_SET_ERR_MSG_MOD(extack, >>>> +                       "Jump can only skip actions that are all drop or all ok"); >>>> +            return false; >>>> +        } >>> >>> [Severity: Medium] >>> >>> Does this check stop offloading police-first jump rules that were offloaded >>> correctly before this patch? >>> >>> tc_act_can_offload_police() calls police_act_can_offload_jump() for each >>> jump result of both rate and mtu police. With police at index 0, any >>> skipped action other than drop or ok is now rejected. For example: >>> >>>    action police mtu 1500 conform-exceed pipe/jump 2 \ >>>    action mirred egress redirect dev A \ >>>    action mirred egress redirect dev B >>> >>> Before this patch, dec_jump_count() already handled this case when police >>> is at index 0. jump_count is set to extval and decremented once per >>> distinct TC action, so the jump lands on the same entry where >>> tcf_action_exec() restarts. >>> >>> The last skipped action is either marked terminating or forwarded to the >>> post action table (as for mirror): >>> >>> dec_jump_count() { >>>      ... >>>         if (tc_act->is_terminating_action) { /* the branch ends here */ >>>             attr->flags |= MLX5_ATTR_FLAG_TERMINATING; >>>             ... >>>         } else { /* the branch continues executing the rest of the actions */ >>>             attr->action |= MLX5_FLOW_CONTEXT_ACTION_FWD_DEST; >>>             ... >>> } >>> >>> With this patch these rules fail can_offload with "Jump can only skip >>> actions that are all drop or all ok". With skip_sw the filter add fails. >>> Without skip_sw (for example with OVS) the traffic goes to the software >>> datapath. >>> >>> The only flaw the commit message names in the old jump handling is that >>> the jump is counted from police instead of from the start of the action >>> list. That cannot happen when police is at index 0, and the act_index >>> check above already rejects the other case. >>> >>> Is the extra all drop or all ok restriction needed? If it is intentional, >>> could the commit message say that rules which offload today will stop >>> offloading, instead of only "Reject the rest"? >>> >> >> Thanks for the review. Yes, this is intentional. Please see the discussion on v1 and v2 >> https://lore.kernel.org/netdev/20261117031337.4126403-1-mohsin.bashr@gmail.com >> https://lore.kernel.org/netdev/20261119040010.1405900-1-mohsin.bashr@gmail.com >> >> In summary, we discussed that a jump either executes the correct target or the offload is rejected. >> >> Police first alone does not meet this expectation. My understanding is that the driver counts a jump in flow action entries, while TC counts it in TC actions, and the two do not always match. This can be an issue when one TC action gives entries of different types, for example a pedit with a set and an add key. I have not tested this on HW though. Maybe Mark or someone else from NVIDIA can correct me here. >> > > So sashiko has a point there. How about rejecting only what the > countdown gets wrong: > > --- a/drivers/net/ethernet/mellanox/mlx5/core/en/tc/act/police.c > +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/tc/act/police.c > @@ -62,12 +62,16 @@ police_act_can_offload_jump(struct mlx5e > for (i = 1; i <= target; i++) { > entry = &flow_action->entries[i]; > > + /* The jump is counted in flow action entries. A pedit has one > + * entry per key, and a police among the skipped actions takes > + * over the jump of this one. > + */ > if (i < target && > - ((entry->id != FLOW_ACTION_DROP && > - entry->id != FLOW_ACTION_ACCEPT) || > - entry->id != flow_action->entries[1].id)) { > + (entry->id == FLOW_ACTION_MANGLE || > + entry->id == FLOW_ACTION_ADD || > + entry->id == FLOW_ACTION_POLICE)) { > NL_SET_ERR_MSG_MOD(extack, > - "Jump can only skip actions that are all drop or all ok"); > + "Jump over a pedit or police action is not supported"); > return false; > } > > A jump over a pedit with only set > keys, or a single key, is counted correctly today and is rejected by > this as well. Handling that needs a bigger change, which we can leave > for later probably. > > Mark > Sure, this makes sense. I'll send v4 with your suggested change. >>>> + >>>> +        if (entry->id == prev->id && entry->hw_index == prev->hw_index) { >>> >>> [ ... ] >>> >>>> @@ -49,6 +95,16 @@ tc_act_can_offload_police(struct mlx5e_tc_act_parse_state *parse_state, >>>>       if (err) >>>>           return false; >>>>   +    if (act->police.exceed.act_id == FLOW_ACTION_JUMP && >>>> +        !police_act_can_offload_jump(parse_state, act, act_index, >>>> +                     act->police.exceed.extval)) >>>> +        return false; >>>> + >>>> +    if (act->police.notexceed.act_id == FLOW_ACTION_JUMP && >>>> +        !police_act_can_offload_jump(parse_state, act, act_index, >>>> +                     act->police.notexceed.extval)) >>>> +        return false; >>>> + >>>>       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 runtime bug in the patch. However, this hunk and the >>> act_index check in police_act_can_offload_jump() also fix two >>> hardware/software mismatches in rules that are already offloaded. >>> >>> First, alloc_branch_attr() handled an ok police result like pipe. For >>> "police ... conform-exceed drop/ok action mirred ...", the hardware ran >>> the following actions for conforming packets, while tcf_action_exec() >>> stops at TC_ACT_OK. >>> >>> Second, dec_jump_count() counts a police jump from the police action, >>> while TC counts from the start of the list. With police at a non-zero >>> index, the hardware ran different actions than software did. >>> >>> Both seem to date back to the branching support in commit f86488cb4685 >>> ("net/mlx5e: TC, initialize branch flow attributes") and its follow-up >>> c84fa1ab94a77c ("net/mlx5e: TC, initialize branching action with target >>> attr"). >>> >>> The commit message describes the behavior change, but there is no Fixes: >>> tag, and the fixes are mixed with the new police-as-last-action support. >>> Could these fixes be split out and sent to net with Fixes: tags, so that >>> stable trees pick them up? >>> >> >> I kept them in net-next on purpose, since both change the behavior of rules that are offloaded today. That said, if the maintainers prefer, I can split them out to net with appropriate fixes tags. >> >>>>       case FLOW_ACTION_JUMP: >>>>           if (*jump_count) { >>> >>> [ ... ] >>> >> >