From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.53 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796342731; b=KuwCZZIvoOvJQR/SWDZQ73zAPkDo4ULTf/LN079QN3eNqr3XEjPyCIQaMG82th1mBUe2 iHjp1CklMBFNq6p/ZoRiH8LmOFbKfTdVlwxa0tUa3ZPugv6wppSaOcdCagP1H/eULiWL/ gUlpeApNwQlWi3qKrYJVHzva4GPcvCwzhSZLhPj0XiPWSiJizbFVLQ/PkCz69Ur6rjgC5 ISyrY5/jV242eHeUmgD++bv1339ZcvcOPyRdZE/R/kC4fM0ni0gLz9l8LpJ1LfkVYQnEy PqMI9N0d87QCtQZSJkxz/TiypSBAfPrHkAPnqOrjS/VsnSuY3YRvmJnsOlxnyoNMV6A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796342731; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=WVJDoIFhLf3jSi01A5/bYGaEDS2eOTA8eH+sX5KfLyQ=; b=vcFsNBES4xym3tpFhG+YA8jIYwDKA4roAhCuPbjhxrhqboDOeHbxinnMuINm1dBm8GLF ALDBgjmUsulV71M2TbuGSLe2McNBptvnUSxXc9kr0zhCIzBDiQmRRioh8ixSaWa5Kn5Gz 6DlaHrE7hi37Uba3QrdSDUDcaCQc5MCnUk6OcOJNOTyk/JN1lPkIOYngdqebjS+yYTvWG HRd2sSh4Rw9ueRWLixFMBsv/Ha4B5CmyCeLRy1S9I0cTfDddoEMLPc5PdhdBLD3kjeM9H UWCC3wX+3rX4RGgM49MA5b84qMdLbfy/CzQxDRsbWHDWzROThnvoqG0vXLx8Zm//3Dg== 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=LK7QHFhI; arc=none smtp.remote-ip=209.85.128.53 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) (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 F2DF5606A335 for ; Fri, 4 Dec 2026 00:05:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org F2DF5606A335 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=LK7QHFhI Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-4bb5b8ef642so3121125e9.1 for ; Thu, 03 Dec 2026 16:05:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796342729; x=1796947529; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=WVJDoIFhLf3jSi01A5/bYGaEDS2eOTA8eH+sX5KfLyQ=; b=LK7QHFhIccqukO8g+pFIYn6x0lieFK36kf4wMgrEKJmNWToqSKSavbSLu+1ahPWkYM xUdxAhFn5BCacKFQHGw6Ouu3ZgoX2xUt3H27pTzdH151j+XPT0/n51l/qInIckHv2T9s bGHowJxHb25DDyLuqejXvH4mkBAqJwPn4Hxk51RcG3HbgwjVpiX2e0gEZimP9oLTAUkH DPpa+bkoriBPra2QVnb3ySZXy+EIuTS0lqVuu7ldaNhz2sP0vhVAPDI9+TMombZW/gAX z1TwKOeSWMe4IHPHyhvqQ1ymU+UThnR3ya7fRlakJkmftiY7Uu8tD9kMna5015CjIQry FCSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796342729; x=1796947529; h=content-transfer-encoding:mime-version:references:in-reply-to :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=WVJDoIFhLf3jSi01A5/bYGaEDS2eOTA8eH+sX5KfLyQ=; b=QsZmsMNCAv84PycMvrJk8RltZ7svSNiFD3eUcWGoDy6WWbk7liztlE4U7hTL15vaio U8v6tr1Ah6IzAuv80MvS+PCcp0aTWrAOnpFMX9LWPQf9fyy5LMqzRvmDzlzikqlsrHjZ cD1xteCVLtIdV1R/Cyoj3pfu3ftzGp07bfWsA+yrwqu3Vfz+MBpGkanvzQAYtmyeBAPW kgTe+b90OUoAKC0hhEEDTFctE193MHMhbv90wTwBy4BPHaA5sZr08PuT2tels6UNkWMa LpQhrRHsP5L0ZKjT3vo2GDMo2mp90po92KA+Z20bVgryODhRgJAM1P3C5+n2qwiVG0dN Hr3A== X-Gm-Message-State: APuU4Z+fQeygzoNbSmzFXzdAEfTWVKv0IsmUDyw/q4JAo7D3ZtrYlgq+ q8/qw+5ywMZvCktiVXbNo7tE7Q8OfYhstJBHMshuUDQt7Nj0YLdoWYDPfo+5sXMV X-Gm-Gg: AZFdTZeeDyJsWqbZeGRHa/1wNeiWNksfD3lRcEGczPDTTuEYBI+iaNbqoDGIVIGIywn 5+tcJkRGytOsulyxOwiGpKg7vtrNFaL6694vN8MLFFJIZuMwMk9NxoGLw3AjJF6e3k5McbX5IFL DdlbOh6Bc/ld21wmKd2u5DM9dEFBN/3jPNWr2tpYkuTJwqfwN185FAs/WmPWLJkRFsxvuF/acaR mtxKQxCH15l9xf6p1W/DO+FtpHOgu9sVppbaCccdwBaa3l5DfF3BXzb+Z1THZYeVv4abp+T/Uf7 v4PNyFQLFjci3Z0G0hcwciDa/NgdslYukLmfDuXEiYbK356k1yZHf2LhPPJnDsVHnP28sjGBEOz 0QBDHKsqNt/C531343w0CLhHG2c1IFLefiFiaibKdoqtEY/IBICWt2St7iVPiqdz5oEszkfaSJC mraQGES/q3YBf5reIWEg8lNTAE0HDR1Ic6nbnAHubgbh7r+bnetjqF/5Tk7p083FjToleL4mLl9 o5hdjyD8aqAS7KnpJbICW3xY6qVwb9Fqz9ljYYCdjV45np8sK2URTE6wY5E2Hvxn5pZGNuTmb0l TEZUXzFrce8zTIzdMHucc8MUQjM= X-Received: by 2002:a05:600d:82e5:b0:4bb:5c92:ce12 with SMTP id 5b1f17b1804b1-4bbeb8afe06mr4284695e9.17.1796342729367; Thu, 03 Dec 2026 16:05:29 -0800 (PST) Received: from localhost ([2a03:2880:31ff:4d::]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bbea2d6aa8sm10283425e9.15.2026.12.03.16.05.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2026 16:05:27 -0800 (PST) From: Mohsin Bashir To: netdev@vger.kernel.org Cc: andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com, shuah@kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next 02/11] selftests: drv-net: Add tc-flower police offload test Date: Thu, 3 Dec 2026 16:05:12 -0800 Message-ID: <20261204000521.3396802-3-mohsin.bashr@gmail.com> X-Mailer: git-send-email 2.53.1 In-Reply-To: <20261204000521.3396802-1-mohsin.bashr@gmail.com> References: <20261204000521.3396802-1-mohsin.bashr@gmail.com> 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 Content-Transfer-Encoding: 8bit From: Mohsin Bashir Add tc_flower_police.py to test tc flower police offload, starting with the offload flags. A skip_sw rule must be reported as in_hw and a skip_hw rule must not. The rules match on the destination IPv6 address, so the test needs LOCAL_PREFIX_V6. Tests skip if the device does not offload the rule and report XFAIL if hw-tc-offload cannot be turned on. Signed-off-by: Jakub Kicinski Signed-off-by: Mohsin Bashir --- .../testing/selftests/drivers/net/hw/Makefile | 1 + tools/testing/selftests/drivers/net/hw/config | 2 + .../drivers/net/hw/lib/py/__init__.py | 4 +- .../drivers/net/hw/tc_flower_police.py | 103 ++++++++++++++++++ 4 files changed, 108 insertions(+), 2 deletions(-) create mode 100755 tools/testing/selftests/drivers/net/hw/tc_flower_police.py diff --git a/tools/testing/selftests/drivers/net/hw/Makefile b/tools/testing/selftests/drivers/net/hw/Makefile index 429cb545a4f0..809d84358d95 100644 --- a/tools/testing/selftests/drivers/net/hw/Makefile +++ b/tools/testing/selftests/drivers/net/hw/Makefile @@ -47,6 +47,7 @@ TEST_PROGS = \ rss_drv.py \ rss_flow_label.py \ rss_input_xfrm.py \ + tc_flower_police.py \ tls_hw_offload.py \ toeplitz.py \ tso.py \ diff --git a/tools/testing/selftests/drivers/net/hw/config b/tools/testing/selftests/drivers/net/hw/config index 081155bf7847..f16d22215f09 100644 --- a/tools/testing/selftests/drivers/net/hw/config +++ b/tools/testing/selftests/drivers/net/hw/config @@ -13,8 +13,10 @@ CONFIG_IPV6=y CONFIG_IPV6_GRE=y CONFIG_IPV6_SIT=y CONFIG_IPV6_TUNNEL=y +CONFIG_NET_ACT_POLICE=y CONFIG_NET_CLS_ACT=y CONFIG_NET_CLS_BPF=y +CONFIG_NET_CLS_FLOWER=y CONFIG_NET_DEVMEM=y CONFIG_NET_IPGRE=y CONFIG_NET_IPGRE_DEMUX=y diff --git a/tools/testing/selftests/drivers/net/hw/lib/py/__init__.py b/tools/testing/selftests/drivers/net/hw/lib/py/__init__.py index 4077f5f1a1be..96f2f5659c23 100644 --- a/tools/testing/selftests/drivers/net/hw/lib/py/__init__.py +++ b/tools/testing/selftests/drivers/net/hw/lib/py/__init__.py @@ -23,7 +23,7 @@ try: NlError, RtnlFamily, DevlinkFamily, PSPFamily, Netlink from net.lib.py import CmdExitFailure from net.lib.py import bkg, cmd, bpftool, bpftrace, defer, ethtool, \ - fd_read_timeout, ip, rand_port, rand_ports, wait_port_listen, \ + fd_read_timeout, ip, rand_port, rand_ports, tc, wait_port_listen, \ wait_file, ctl_file_write, tool from net.lib.py import bpf_map_set, bpf_map_dump, bpf_prog_map_ids from net.lib.py import KsftSkipEx, KsftFailEx, KsftXfailEx @@ -40,7 +40,7 @@ try: "NlError", "RtnlFamily", "DevlinkFamily", "PSPFamily", "Netlink", "CmdExitFailure", "bkg", "cmd", "bpftool", "bpftrace", "defer", "ethtool", - "fd_read_timeout", "ip", "rand_port", "rand_ports", + "fd_read_timeout", "ip", "rand_port", "rand_ports", "tc", "wait_port_listen", "wait_file", "ctl_file_write", "tool", "bpf_map_set", "bpf_map_dump", "bpf_prog_map_ids", "KsftSkipEx", "KsftFailEx", "KsftXfailEx", diff --git a/tools/testing/selftests/drivers/net/hw/tc_flower_police.py b/tools/testing/selftests/drivers/net/hw/tc_flower_police.py new file mode 100755 index 000000000000..86d26314decf --- /dev/null +++ b/tools/testing/selftests/drivers/net/hw/tc_flower_police.py @@ -0,0 +1,103 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0 +"""Test HW offload of tc-flower rules with a police action on ingress.""" + +import ipaddress +from lib.py import ksft_run, ksft_exit +from lib.py import ksft_eq +from lib.py import CmdExitFailure, KsftSkipEx, KsftXfailEx, KsftFailEx +from lib.py import NetDrvEpEnv +from lib.py import set_ethtool_feat +from lib.py import cmd, defer, ethtool, tc + + +def _setup_clsact(cfg): + feats = ethtool(f"-k {cfg.ifname}", json=True)[0] + try: + set_ethtool_feat(cfg.ifname, feats, {"hw-tc-offload": True}) + except CmdExitFailure as ex: + raise KsftXfailEx("Cannot turn hw-tc-offload on") from ex + res = cmd(f"tc qdisc add dev {cfg.ifname} clsact", fail=False) + if res.ret: + raise KsftSkipEx(f"Cannot add clsact qdisc: {res.stderr.strip()}") + defer(tc, f"qdisc del dev {cfg.ifname} clsact") + + +def _local_prefix(cfg): + cfg.require_ipver("6") + prefix = cfg.env.get("LOCAL_PREFIX_V6") + if not prefix: + raise KsftSkipEx("LOCAL_PREFIX_V6 required") + net = ipaddress.IPv6Network(prefix, strict=False) + if ipaddress.ip_address(cfg.addr_v["6"]) in net: + raise KsftSkipEx("LOCAL_V6 must not fall within LOCAL_PREFIX_V6") + return net + + +def _police(rate_mbit): + return (f"action police rate {rate_mbit}mbit burst 1m " + "conform-exceed drop/ok") + + +def _try_filter(cfg, rule, action, pref): + res = cmd(f"tc filter add dev {cfg.ifname} ingress pref {pref} handle 1 " + f"{rule} skip_sw {action}", fail=False) + if res.ret == 0: + defer(cmd, f"tc filter del dev {cfg.ifname} ingress pref {pref}", + fail=False) + return res.ret == 0, res.stderr.strip() + + +def _add_filter(cfg, rule, action, pref): + added, err = _try_filter(cfg, rule, action, pref) + if not added: + raise KsftSkipEx(f"Rule not offloaded: {err}") + + +def _filter_info(cfg, pref): + data = tc(f"filter show dev {cfg.ifname} ingress pref {pref}", json=True) + for entry in data: + if "options" in entry: + return entry["options"] + return None + + +def _check_in_hw(cfg, pref, expect=True): + info = _filter_info(cfg, pref) + if info is None: + raise KsftFailEx(f"No filter at pref {pref}") + ksft_eq(bool(info.get("in_hw")), expect, f"in_hw for pref {pref}: {info}") + + +def _ctrl_rule(cfg, i=0): + # The rule sees no traffic, so its address is not added + net = _local_prefix(cfg) + if i + 1 >= net.num_addresses: + raise KsftSkipEx("LOCAL_PREFIX_V6 too small for the control rules") + return f"protocol ipv6 flower dst_ip {net[i + 1]}" + + +def offload_flags(cfg): + """ + Check that a skip_sw police rule is offloaded and reported in_hw, and + that a skip_hw rule is not. + """ + _setup_clsact(cfg) + _add_filter(cfg, _ctrl_rule(cfg, 0), _police(100), pref=10) + _check_in_hw(cfg, 10) + # A software-only rule only needs flower and act_police + tc(f"filter add dev {cfg.ifname} ingress pref 11 {_ctrl_rule(cfg, 1)} " + f"skip_hw {_police(100)}") + _check_in_hw(cfg, 11, expect=False) + + +def main() -> None: + """Ksft boilerplate main.""" + with NetDrvEpEnv(__file__, nsim_test=False) as cfg: + ksft_run([offload_flags], + args=(cfg,)) + ksft_exit() + + +if __name__ == "__main__": + main() -- 2.53.1-Meta