From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.43 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796342734; b=Ky9D+AmKGy2Gcq7cZ2KMQT3VvhflwBdLZB9vm1Ay/cX87lRouFcRK/YzoMdWlsEzLHsn ZWiVhV7IG/wp3toAdFjNLrHxRZNs/AnSgwAsDGnpwq15c4iZw6CXp8aD//wrrYsHZGkO0 dWFiR6cksBpNLWpPZ4KysLT1aFSoZB1zpw1Abq6JbkkyoYvWsm1HMmR4WQvJr7UsPb++U sXp8uACdlg+99NWkptzHGvryHxrFJssZrLwC8Cp56HnXQiJafAst8pxShf0XTu/IWAtSn 6ZhDKtYtdshOuhzivrXT7qqh+hbSCc6sdcJLqihpDQqlaj9U7+s/rwyJLfgqhICbVOA== 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-Forwarded-Encrypted: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=SExPxouZ9UrYM8sdHL39nx8mJaJecgv7UCaTv1edCl0VvWHL0kVFuHgCOzPOCHlGn295 rL8R6zx6dnKwjvF0iCtJDHoVRKLNYu0Y0QPRT7TFm1yC3KVMpcDOoxyLRZ572TCAnFFlH YFfOcI2UJeeGBkFZLtXRpp2KbUaesu+t8olHlXmPkLBHgFvOHSecSyo6t45MVoxgvy1vK evzgRb0aDmFfsf5f+HaocojUsdhKJKdyyhlmH8KDC0oiw/7s+02gFCcGx7hiFDb2NV22h XzKZ/0WAWKwv5SIEcOmJclMYZvPMhLybZiLs89ptadGEn3eWkgXyQIz+Tb+Wu357AnA== 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.43 Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) (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 B506D606A322 for ; Fri, 4 Dec 2026 00:05:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B506D606A322 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-f43.google.com with SMTP id ffacd0b85a97d-48e47347279so255102f8f.1 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=D4RK+gazwRj+pe0/yzrR1pFls/61GWu9a2s42khdZilLplQSKiY8TO/8MCAaY25ybT Og8UXw1+bN8OzRuVQwdTs/hQVrAIePoKm4C6PVq98SarY2eWAxW53ZM1IOKcpj733Rlf UR7k/4pzEqEZAzrutRr601ZeKGIO8BlYSsmx5X9crIed+0wQGMwjl7vv2OvLWCXgzki9 6CL1gYlhEHUFP+tsQBxhOE4pS+dMEnFuW8bWyXVLeg/EkcDzlcAu4x1t14JC3g6gMKp2 SqbSi7OGJiNFJs5XFbFHVLN39N0+g/g3KXx5ZdjVxnlUBHdgvAgPTqIXtyIGQtyYLGFZ Db7Q== X-Forwarded-Encrypted: i=1; AL+hErFCDoYj4rYbrdu6bnMPdZu5O6C7imGBq27ZJ2Kv/5R7ydnb6QviGnEninEm2H704VpzKzRpg7zF6aM7bRI=@vger.kernel.org X-Gm-Message-State: APuU4Z9JzNxUzJ3ztFRdQ8eZOpPJvrT4/0t9Z51dZp1mI096cpC0QNMM 0VK2M/XT4hPcKRbOHNTvHRXvMoL6S3MH2nf+kD8Fk2fDq06u6IJjFRPf X-Gm-Gg: AZFdTZe4oy8uKvBtEpS9iCFHG+h4fd7lgDtEuB9dQnoUGptAm1/FzRsPq0G+BYZDuET 0+BhPzVuSgPf0AKJXkWxk5erxDbTej6YFn/F38Rw0wW29aM78V2Y9rBOZSB4qaqIgnxcu252g9b o60VZIDd8CW109yNOOooOye6vJSn+fSzl8C3NqNreCkyhLF/SUWnbEqo/u/0ITT2bh8R4xiAoLj pDUggh1FDzi8j0xlxXm2SR89uq5pj2MX6brQAbIoHjWEdPMdy5CEMh8oKWaEdGzvbJBJvJLCOKB qgYObgV5LRA3OnmJoJYF8+Nrpj098/dZyUo5/NGyH9ed3RuS445dWic1f2OFJtdPT6u7X1jeo99 w9Sq+bx8GqJ0rWuFG6ox+CEkFiyIfxtOW0xnmzdnDTQQbT41F7iZjlUL6xdmGuSyQrJvW+5rpvg XTY4pKs4PhtLa//fQINdgvZfQM5Hn3z6GzE0SvkVOhPSDpEt4RcQ/s5ehfWg5vpFT+CVLtm1g9W oFdP7eyHutPS3mkHqnD/zZvEyzKTKt4gNn34HHxH0edJtJb4yFkmBzVJ6e7t/QcqQgFf3hG0/0p L2acI9icFM2TEjUVc/r2xXm7BoEW 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: linux-kernel@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