From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.48 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796160299; b=bRpy5z35qyBC75RAXuGTjSeIgzSA06ykYxoQmRzIAExelaxTip91ts80tDrAhT0yQYZd EYxLpLu8aGktm5LDl3/BAx18ZUvoNPiG+G4mplZdqVSVbjMXsaM06rgcVIHR58pQt25AJ ujWApFsozfGSgXeyBmK1gu2w+Z0nEgPrNejIRjgbQsPMzaLRoi5u30/SeExKnXHreT2x3 cv3xGsYttVbeddpkqwQiCw+eNpgKrzbT7SRFWhZ3nDCgHBlH3RWDILleEnBBfE32nb6fm dI4+dZ0FlF5zgvPTDOnfGCZ/Ccd8juH+miSG4Mjw0LuY9CGrqSUosTWPlycg78+N9yQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796160299; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=NRyifO5iSotKaq/o36WJTSBl7ODoWawNsSti8c6gFE8=; b=jr6mvE1AbIdjiYKETfWf0Km8/ZcvxwEOjI8eycD8GaKkTO9D7+nddAlVxiqqZfPpHWG4 6MJaTErtia+RNCyc9ZcDJMhQYhrg7L2dLDoCNoUlCuyWAK+VT+lBBDi75tA/Ll+o0Itz0 7z5ymLoruiqSUAouRAwVgaDTkLSf+kYyxtnGKU82vvAarJ9qTVsz+iTRLs2RyBU40Aonf 3dGttPtyBm4Q9HE8/JD6WCKJo+O21fNl6t+X+V6QBLPGdgantf7/BQXnIRLZXadeGOwpQ p2xpaup0xVXtGYjPQSf3p9tMl7zcMK/cA85sshsmKT6ilHrMQlZdVyMBqdeFrQ6vddQ== 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=Os+fOKeT; arc=none smtp.remote-ip=209.85.210.48 Received: from mail-ot1-f48.google.com (mail-ot1-f48.google.com [209.85.210.48]) (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 B4CC6606A322 for ; Tue, 1 Dec 2026 21:24:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B4CC6606A322 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=Os+fOKeT Received: by mail-ot1-f48.google.com with SMTP id 46e09a7af769-8629c7cc36eso6931537a34.3 for ; Tue, 01 Dec 2026 13:24:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796160298; x=1796765098; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=NRyifO5iSotKaq/o36WJTSBl7ODoWawNsSti8c6gFE8=; b=Os+fOKeTBM8ddADNAqb60znnYgJ+24kghWz3JbtkmgAEcxBvlUEvYvx+sCilKoYep3 +91LQZ6113vcHPL66iCksydLkKQyH5lBiSDYY8nNRu2/WcLopfJqs92BQS1c9vBc4NwV IH5J4P0uiKJKVwoD9d0lotzAhMWT94PQbV//k929bi+vaFjt+qXzdXI6PWEBK9tv8Kq1 A+IXIoTCZZMyQWkBpLQ+1FNmVfdYaBoV2lstiEdZ3zhVgOCDuvryYFS/NJbKgHhigLdE uEi+RS7oXOFf4qtX4ituYhhve+K8N+R68Y4fFKsHWRTBC6WjHP1TCyBVguTtnUoDorlO mOrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796160298; x=1796765098; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=NRyifO5iSotKaq/o36WJTSBl7ODoWawNsSti8c6gFE8=; b=KCFgo9GRXJiDWNjzo5JazHmIQoJH8tFNIVZtTaibOZYkC4XrHmNVyenb8WKosuCHgW fCKiUlKTOcp1ycLMbiMfV+h+K6q9KXQgqHogQim4M+0CQ+FdTkgFtMo0rwzVd0dbMz6t UATH9NpOBjf5GxgA5PoMJN5J85+8DmqmZPQDeNhXlHOVBk3fUvF+WXL0LHoyfsFBIm/I x8iaIejgT5tKxKxf9VeNLdLEMI6rbSM6QAyY26YWVYlf0aAZxuZ9o2XEE3dhiGw0HFix KY2cqTfRbCkWR6MUU2dIqsuPbUMRUUrhYeyPY7NATSmi1cUuX2LpUDlgyTDB9mc9L6xi tVuQ== X-Forwarded-Encrypted: i=1; AL+hErEJSyR8mSDxud0ykvpys9Te8gqPLKnY3OsR2ihT6Gl1CO7RFfto14LNbD2H8ERN0lfQBN4mBkOz01oo@vger.kernel.org X-Gm-Message-State: APuU4Z+7OrIC3ktQAiSxne7WiAXowpyBdE2Sjcs4SRQQTulOqclGBPSi l7c0h8ScAYOybtAtfixcWIzdNm0WRM/DM6nzOd2Q4gOsfyNUq0scBti+ X-Gm-Gg: AZFdTZeN3fYaChEteqGAMDU6qY4QxXn2Yj8mWHCi01L3f33iIx98TsWtt3SjyWFPA5B quIHd2s1ww97UWULZfDqIXqcSueHPUUreWKtBr6gdUNV5OCi0DrsLyvTPLXEyEWVG3kR2ZNyxkZ f8FGVzA99vvfFgS4+nn0sRpf7mq1v9vcQBE5GscXpq5IUeFEvDngwe3Q0BLoWGGDvswmuiNxfJw IxWhUVEc/aVcyvdprlfMva3vdivaLBFXX1US0sUrLrkKHVRlOaxqYePBP/4b6z+hdLjAvYzQnbd F1GPbTRJBxTbjiPJQruZZLwZOZpZDvdwoekvNQsp3NLUO4lk/sJULvwkvSHbRhtlJG1e+20vPeF 53AlVYNlwCovGsFzg9yePs1nOG1gpN9KS7bq4GUV4jvpluZsVQ6VFqKfD4bWvVpZKAXRSEzuk97 Peavi09O5qyqcW/oRFgq41k05xgVuwuNNBgUjcHc+SyYX/GBw7oLTWGXDKPg1D7GhZNubQ37ALq qKOGQMTDNVcE17T0mMxeQ+6mSOneY72WEv87Qe+pbOx5seKEhUOXYU6RKNv0Gi7lniXivFIh3it V1NxUEWuea+7/WvacT+0ecr917U= X-Received: by 2002:a05:6830:438e:b0:862:cfd7:747 with SMTP id 46e09a7af769-863152cdcf1mr43081687a34.2.1796160297713; Tue, 01 Dec 2026 13:24:57 -0800 (PST) Received: from localhost ([2a03:2880:31ff:4e::]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-863168f6da9sm27517918a34.15.2026.12.01.13.24.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Dec 2026 13:24:57 -0800 (PST) From: Mohsin Bashir To: netdev@vger.kernel.org Cc: saeedm@nvidia.com, leon@kernel.org, tariqt@nvidia.com, mbloch@nvidia.com, cjubran@nvidia.com, andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com, mohsin.bashr@gmail.com, linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v4] net: mlx5: Allow police as the last action of a TC rule Date: Tue, 1 Dec 2026 13:24:55 -0800 Message-ID: <20261201212455.2836814-1-mohsin.bashr@gmail.com> X-Mailer: git-send-email 2.53.1 X-Mailing-List: linux-rdma@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Mohsin Bashir In switchdev mode, mlx5 does not offload a rule where police is the last action, although TC needs no other action for such a rule. The upcoming selftest series relies on these rules. With nothing after police, the police result alone decides where the packet goes, so each result must be offloaded as TC executes it. The driver does not do that today. An ok result is handled as pipe and runs the actions after police, a pipe result always returns to the post action table, and a jump is counted from police while TC counts it from the start of the action list. A rate police is also rejected by verify_attr_actions(), as its forward to the post meter table is added only after the check. Make the offloaded rule behave as it does in TC. An ok result ends processing in TC. A pipe result does the same when police is the last action. Send both to the end of the TC chains as the driver already does for gact ok. For jump, offload only the case where police is the first action, no pedit or police is skipped, and no action follows itself. The driver counts a jump in flow action entries and merges only consecutive entries of the same action, so a pedit with both set and add keys counts more than once, and an action repeated in a row counts once. A skipped police takes over the jump. Reject the rest. Existing rules where police is followed by other actions also change. An ok result now accepts the packet instead of running those actions. Finally set the forward to the post meter table while parsing police. This is already done for police with mtu and lets a police-only rule pass verify_attr_actions(). Tested on a ConnectX-7 in switchdev mode with the commands below. The hardware drop counter showed that the rules are offloaded and limit the traffic to the configured rate, that the second police only sees the packets conforming to the first, and that the jump lands on its target. 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 tc filter add dev eth0 ingress pref 100 protocol ipv6 flower skip_sw \ ip_proto udp dst_port 5201 \ action police rate 200mbit burst 1m conform-exceed drop/pipe \ action police rate 100mbit burst 1m conform-exceed drop/pipe 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 / jump 2 \ action drop action ok Cc: Carolina Jubran Signed-off-by: Mohsin Bashir --- Changelog: v4: - Reject only a skipped pedit or police, instead of allowing only skipped actions that are all drop or all ok, as suggested by Mark: https://lore.kernel.org/netdev/c5ad051b-5ae8-47d7-ab90-c3853a379335@nvidia.com v3: https://lore.kernel.org/netdev/20261124220251.776944-1-mohsin.bashr@gmail.com v2: https://lore.kernel.org/netdev/20261119040010.1405900-1-mohsin.bashr@gmail.com v1: https://lore.kernel.org/netdev/20261117031337.4126403-1-mohsin.bashr@gmail.com --- .../mellanox/mlx5/core/en/tc/act/police.c | 59 ++++++++++++++++++- .../net/ethernet/mellanox/mlx5/core/en_tc.c | 26 +++++--- 2 files changed, 75 insertions(+), 10 deletions(-) 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..1e6babff8b2b 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; + } + + if (entry->id == prev->id && entry->hw_index == prev->hw_index) { + NL_SET_ERR_MSG_MOD(extack, + "Jump over the same action twice in a row is not supported"); + return false; + } + + prev = entry; + } + + return true; +} + static bool tc_act_can_offload_police(struct mlx5e_tc_act_parse_state *parse_state, const struct flow_action_entry *act, @@ -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); } @@ -94,13 +150,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 615af3acdb9e..ddf488e7cb68 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c @@ -3877,7 +3877,7 @@ static int alloc_branch_attr(struct mlx5e_tc_flow *flow, struct mlx5e_tc_act_branch_ctrl *cond, struct mlx5_flow_attr **cond_attr, - u32 *jump_count, + u32 *jump_count, bool last, struct netlink_ext_ack *extack) { struct mlx5_flow_attr *attr; @@ -3894,11 +3894,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; case FLOW_ACTION_JUMP: if (*jump_count) { @@ -3970,7 +3976,7 @@ dec_jump_count(struct flow_action_entry *act, struct mlx5e_tc_act *tc_act, static int parse_branch_ctrl(struct flow_action_entry *act, struct mlx5e_tc_act *tc_act, struct mlx5e_tc_flow *flow, struct mlx5_flow_attr *attr, - struct mlx5e_tc_jump_state *jump_state, + struct mlx5e_tc_jump_state *jump_state, bool last, struct netlink_ext_ack *extack) { struct mlx5e_tc_act_branch_ctrl cond_true, cond_false; @@ -3983,7 +3989,7 @@ parse_branch_ctrl(struct flow_action_entry *act, struct mlx5e_tc_act *tc_act, tc_act->get_branch_ctrl(act, &cond_true, &cond_false); err = alloc_branch_attr(flow, &cond_true, - &attr->branch_true, &jump_count, extack); + &attr->branch_true, &jump_count, last, extack); if (err) goto out_err; @@ -3991,7 +3997,7 @@ parse_branch_ctrl(struct flow_action_entry *act, struct mlx5e_tc_act *tc_act, jump_state->jumping_attr = attr->branch_true; err = alloc_branch_attr(flow, &cond_false, - &attr->branch_false, &jump_count, extack); + &attr->branch_false, &jump_count, last, extack); if (err) goto err_branch_false; @@ -4055,7 +4061,9 @@ parse_tc_actions(struct mlx5e_tc_act_parse_state *parse_state, dec_jump_count(act, tc_act, attr, priv, &jump_state); - err = parse_branch_ctrl(act, tc_act, flow, attr, &jump_state, extack); + err = parse_branch_ctrl(act, tc_act, flow, attr, &jump_state, + flow_action_is_last_entry(flow_action, act), + extack); if (err) goto out_free_post_acts; -- 2.53.1-Meta