From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.50 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796342734; b=SzvoL/0Xw6u4Od6Hlm0bn6ho2bs9zoNp4kPnHE+fbfhPjFor/s5+9CqtRSpXBbwzr9vZ NJbz8Xe3DvOaIpoKz68xNmnaYfrSdDQmauMPHb9cPxo1mp1cuTt9Nj74zM7UDRanxKIgL qj69akq08Fnv9ahzNRXgaXHnLtUXTzapNjuyAKKGRgmEPOPjFvzEe1GEUsbASDimCXXUL 2fBsxc/gT9n6FP1duJw5/J3iF94BY1fSVS8qqP0lLns3BgD/B2uvUz26t88U948X9/TDg UM1OvfSJAlxdW/isFUJo+ASTclW4zFWN1zCloItBFDDm8vS5HNNkJyyUj7aLf3Rx5jg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796342734; 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=Xf7gUlEXVCnCWrI0oagt1iUWvXpbLutGfg9vCA6xjAk=; b=bJXP9D+eRMU0up62NLMrGQiz4uQJU2CFYxdimkuLOjdEiuLUO1i0aM8G+Q87/ECgbbjR 3w0wX6gc6LhBwZ2EEuJB+dJbLTjYQF9gJu1uGse/JgUGuJNJr2b3rDpd3X9b8ylt44Ccg YpDPZB1b6PWM9kCVvOqZkySI/I+6fn0Wt9K1WDSL89Zl1a1UlhjwmRxxrKMJad4ZSZ8hj nyYE6K9in6UcC7qRBwrbtBNCRY1QXat5RzzRr6GsthI8I/xY6lrqDCjl+Dhz3iCzYkDRw x+2s+lJbuCnKPK2s0TMVNIfmF8hFaE1bcUQCYav9fcaUWvS6LSdUppTPIKMNGm75HGg== 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="BMRjJv/b"; arc=none smtp.remote-ip=209.85.221.50 Received: from mail-wr1-f50.google.com (mail-wr1-f50.google.com [209.85.221.50]) (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 9F561606A334 for ; Fri, 4 Dec 2026 00:05:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 9F561606A334 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=BMRjJv/b Received: by mail-wr1-f50.google.com with SMTP id ffacd0b85a97d-498f5fa5103so234541f8f.2 for ; Thu, 03 Dec 2026 16:05:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796342732; x=1796947532; 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=Xf7gUlEXVCnCWrI0oagt1iUWvXpbLutGfg9vCA6xjAk=; b=BMRjJv/bUc7yGS/YLcVGbswRsUJAMAQkXhe88FroGRFAsam6u7ONhb20G6KvDHLn7f 1806j4U+8nbXEbzoclzSiEqjAefNA3CLRTamIveSdU2SBH5ErHXQzIvgLBNTMTzeuHye CmI5uAR3maR3RnxsG9bFJM6hKhcXImH424mr5UsNfRccwReStfHD9gIoHMcpdnKFE/+b Vng+rEdvgIkCBobXk+rr0ZnRsb/k83bGDy6RaOzte1Z5yyQcY7hBSveVd7zCw/VXDApF a654TPA1oAZvXvu10bFL/YXWEZBgdtyw7P0OAAU2BUidL5lGmao/9CEZGNSYeiXB4gU4 IPEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796342732; x=1796947532; 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=Xf7gUlEXVCnCWrI0oagt1iUWvXpbLutGfg9vCA6xjAk=; b=P/Z1+V+fv58Uj7kJzBSH9QRSMZ1+MmAsSen8ojgC6z2HISMaOhEflMJ4rlXtfu73go bHqLZRjvt/XY9PWUtbyL5+oGovcD8GO3u/BZbEiYhD9y2VdGFoEAibif9iAyDi+ie53E Z+Em0r+bpSX5uoVaAJba6oWBdNCJ9vywOwJ3f1Be6m2C6PRUa258RDUhcQdCVfXnBcYq dQ2Kdnf+G2P4luK/tKK2RRALUKDXlaR2i4RMvd7s3Cw5T6byOy8kw7n5wY6baruQdGN4 W/Vge11qBKmvUcMM9zerYk8StnY6E0l+HqhgsfqecHDxs33NaitQZ5YHA6gSzJiK33qT udXw== X-Gm-Message-State: APuU4Z8tzEuCaYiKw2M+GnDxPzSnh2hnRRU36bEPfnAIA8MuBqIPCo6x zjkwa32lcIAUHFi3WYph09+fZzQoX2JXDFqbYxp8RTaa7YtwE7iZoL/ET2uM84rv X-Gm-Gg: AZFdTZenTEhIjmf0Ci6/OZaNYgxkgTbHXsGg157ta7HFOiGKxaVLxP9Us+WzZMklkIl Fkf6fDZmsnCXuc6EHdKN4x42IB05kXATKND51f+Rnwuh5UFwlV/n3LIU7Yyuf3QayFXIKgFa+zl 2YCoHGcXETwQgT6uXyHl+aJHLF09w/9Mf4+hBlAQDtTHByaCCZ+zpyJB/wZUoKQwRF3rnFyVtIl OmRzJgS3S/NLNJW7+e+TAmh3M/6q6zueZrmiK7Ef2wi6Mll7V8G3yyBChefYQRo872BHXBo2jAI YAgC3EQradTIUHS8E1RAM6NKi6D7eo7TKdfvY5T1TTg3Slb5QqtBgiTr1CG0DnWDbZYazL7kILW 1XT+Tr7/jlNsFDNcWsPeOAMx9q0C+WOcRlTZLC/xOvIAomZGjS/8HyE4eGdjyLnAu+bxPjb9gvj lhPvKG9Nu5SqvfOIQPb4p08a6u5TqPnha8loN2z1LbBXdJ7MWfu2F8UCgk1eC/jGmk3gKSfuRcP QqQvxrlv+lNdHjCAlXeZd9jtSaJHheFNEBIi0SLpk0UtRxA64wDN2LyvKAMjH8WkutpFEZ/mVDx RoQA3KJo95j1aYqfY+5P/H6v5C6M X-Received: by 2002:a05:6000:4a19:b0:497:9e2a:b1e with SMTP id ffacd0b85a97d-4d1e7999141mr717816f8f.9.1796342732067; Thu, 03 Dec 2026 16:05:32 -0800 (PST) Received: from localhost ([2a03:2880:31ff:1d::]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4d16e0b0c8csm1928543f8f.2.2026.12.03.16.05.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2026 16:05:31 -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 03/11] selftests: drv-net: tc_flower_police: Test that rules do not leak Date: Thu, 3 Dec 2026 16:05:13 -0800 Message-ID: <20261204000521.3396802-4-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 Drivers often reserve a policer or a classifier entry before they know whether a rule can be installed. Missing the release on rule removal or on a failed install leaks the entry, and the device eventually rejects valid rules. Add police_no_leak to fill the device until it refuses a rule, flush the rules and verify that it takes the same number again. The test adds at most 1025 rules, each with its own address from LOCAL_PREFIX_V6, and skips if the prefix is too small or the device accepts all of them. Some devices use the action index as the policer slot, so both fills wait for earlier police actions to be freed. Police actions still present after 5 seconds skip the test before the first fill and fail it after the flush. Signed-off-by: Jakub Kicinski Signed-off-by: Mohsin Bashir --- .../drivers/net/hw/tc_flower_police.py | 66 ++++++++++++++++++- 1 file changed, 64 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/drivers/net/hw/tc_flower_police.py b/tools/testing/selftests/drivers/net/hw/tc_flower_police.py index 86d26314decf..b03a00ad0c0b 100755 --- a/tools/testing/selftests/drivers/net/hw/tc_flower_police.py +++ b/tools/testing/selftests/drivers/net/hw/tc_flower_police.py @@ -3,7 +3,9 @@ """Test HW offload of tc-flower rules with a police action on ingress.""" import ipaddress -from lib.py import ksft_run, ksft_exit +import tempfile +import time +from lib.py import ksft_run, ksft_exit, ksft_pr from lib.py import ksft_eq from lib.py import CmdExitFailure, KsftSkipEx, KsftXfailEx, KsftFailEx from lib.py import NetDrvEpEnv @@ -91,10 +93,70 @@ def offload_flags(cfg): _check_in_hw(cfg, 11, expect=False) +def _count_filters(cfg): + data = tc(f"filter show dev {cfg.ifname} ingress", json=True) + return sum(1 for entry in data if "options" in entry) + + +def _scale_fill(cfg, count, force=False): + with tempfile.NamedTemporaryFile("w") as tmp: + for i in range(count): + tmp.write(f"filter add dev {cfg.ifname} ingress pref 100 " + f"handle {i + 1} {_ctrl_rule(cfg, i)} skip_sw " + f"{_police(100)}\n") + tmp.flush() + res = cmd(f"tc {'-force ' if force else ''}-batch {tmp.name}", + fail=False) + if res.ret and "Command failed" not in res.stderr: + raise KsftFailEx(f"tc -batch failed: {res.stderr.strip()}") + return _count_filters(cfg) + + +def _wait_police_freed(): + for _ in range(50): + if not tc("actions list action police", json=True): + return True + time.sleep(0.1) + return False + + +def police_no_leak(cfg): + """ + Fill the device with police rules, flush them, and check that it then + takes exactly as many rules again. + """ + _setup_clsact(cfg) + + limit = 1025 + # Each rule uses its own address, starting with the second one + if _local_prefix(cfg).num_addresses <= limit: + raise KsftSkipEx(f"LOCAL_PREFIX_V6 too small, need {limit + 1} " + "addresses") + defer(cmd, f"tc filter del dev {cfg.ifname} ingress", fail=False) + if not _wait_police_freed(): + raise KsftSkipEx("Police actions present before the test") + full = _scale_fill(cfg, limit) + if not full: + raise KsftSkipEx("Rule not offloaded") + if full == limit: + raise KsftSkipEx(f"Device accepted all {limit} rules, cannot fill it") + ksft_pr(f"Device full after {full} rules") + + cmd(f"tc filter del dev {cfg.ifname} ingress") + left = _count_filters(cfg) + if left: + raise KsftFailEx(f"{left} rules left after the flush") + if not _wait_police_freed(): + raise KsftFailEx("Police actions still present after 5 s") + refill = _scale_fill(cfg, full + 1, force=True) + ksft_eq(refill, full, "Rules taken after the flush") + + def main() -> None: """Ksft boilerplate main.""" with NetDrvEpEnv(__file__, nsim_test=False) as cfg: - ksft_run([offload_flags], + ksft_run([offload_flags, + police_no_leak], args=(cfg,)) ksft_exit() -- 2.53.1-Meta