From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.47 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796342734; b=10SjhYao0HVSskmZrvMSf7DOqDR52X6rZs5LkYv85iCyDMTGvg2XMTnX5TJc2oC26aZ/ WK8bLgCGNWCf3xPqzQr2dlXzezB3V0UQH2ekl5nn31E7sub5qwk9pnfRMOKNrR5ArnU8i lZt6vP9o+CbvxNTrvGxOLCDmNk/Vt9fVxY0JCckOgCqjvBgeiUbYdgpDYKj6Zsc/nDHeT 26qtAzh6y/iIhdvxyLvydRjPao3du6plPoP3BYESkrMmkdmg8RDUn9wNHeHgJff0ZM758 0K5PFW5q7K4PID2vEUGmhNgs0Nf175bJyE0dTlBYVLx66noBw4qaQtBna8ck+t4r61g== 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=XVXA731e4i4fEeBsu6Scn958hGE+Lyp6N6Czncc620duZoSuOANk0YgFuxZNnZPNRdb4 H3zRqdq1wYfpUftAO102dbKtsToE9qOSkeycpZpY1BApWNV0V4DK/XRJh9XzVaj0Jj17Z 0xvfUlx60YgQX3zFPhSixLD5aLSKtKbJU9oe+oWk3TkydL1Pdt4MgtUz1HC8byn9gTJd5 C6QwWIbwzESO4iYNqOjAIVkufRnNo4YVkDEI2cnFqGlAh9Vwex8BGxTbMrsEJzUORBGZZ YBM3BKHpmhcdtqL6JaPBG+rkIwQtlRFBi3gsCANCRjs8KCySBVHnr3Pxphccv1k5hcw== 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.47 Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47]) (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 9F4B5606A333 for ; Fri, 4 Dec 2026 00:05:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 9F4B5606A333 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-f47.google.com with SMTP id ffacd0b85a97d-4c4b8e58c9aso249079f8f.0 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=zH5xBLy32MMjDEuJsK1WxqB4AWz0PJKZ49NAAxj9E8MWw3zmAG9ZvSJyjtuytERHyi Z5B5GCftz6wAkbSpaVjSaTWaA38WdIfJNMfukKdvoknKAXwA10xw4Q6o+Km0ISnZu05h 1DsFe6Pkir48P+al1PdP3TeOvSCmKZ0u3gIQJo/PSCxtar/QbsPJcGV9pXU4ydbYGS/0 uCzJ3Pz24QzqJNxHW4H8JgTtJ2m64G10A1P8l7i5lYyPtuQFUJeQIOLDNqPPYs9z9SSg WUM/clrQPCzuxvhHNqesPfnO4t+JsPEO5CC2HT4tdtfzMJOeVVoyx5ppREvLkeWpNATZ EzkA== X-Forwarded-Encrypted: i=1; AL+hErFAGor1gp829D2TlC0VCjn5QkxI9An7AhgkVHUsobJHFZDaYGzDhaxIDfUQZvxnSAvwXJ/TPh1RS9R7zu97Tsc=@vger.kernel.org X-Gm-Message-State: APuU4Z9Z6Swk2T+bVTs5EOAh/6pEzSPo+tWb8jDj8Of9jbBY2xywm7vL LSV49HsS2Jm+OJCFg05mn+b2jXSmrd3oxgOZ2QfTXuVxnZPECu868s0c X-Gm-Gg: AZFdTZe4FSTj2YHM6J8/cwUU2ylIgQgeNmAki/2mGT5wkOPchHh31DFsV/u91Ut6E+A GQGAhrHdbqox6Gtt0EpQDRXV+WfFvF3A1ffqXY6UlP6Ka8/lNfzvccxy2sNZPJwklYv/rFoxcxG 0kaOn8h4b9JGVC0asn8QWrhrRPXgMBp83Fws17pjRI9ZbOE2CJgwl57RGqebCat6mCr5KxaGQOf GgH2cue0uxkADA5H6OMNiJ9xBj6/DYzBmVvWk7HenyJTmS+o2Yj7F0i+d36XlH950m+EAJoXEBl zeWwbdC8CYWwWkU0A+WMKARHMdwkQe4AX9RjLutZ3sW6TrPsVwhM+S7ulcU9VdJaRekrD4xPioK HehaXFOQ+4dOXHpANSWuGyRTcr93d9HiHb3a7BAzDJj9dpKufTWU4Lcj1T2/O/Ty1o6G0kw62Pt s5PFzRdSLxQ6jAbw4WtrXwGgPH5faERrBPzvXdM2CBkhJ4vYxsT1maZlmqcrWfLpVTKD/oKGoDs C2GQS05g4NCeCc8CYCDm9mTGhoFt4FaA8yrgd/KSkNQIOC6t6sZ1w9QfDur/IdbSyb3rB5RE5ec KfQ1TwmN7Lx2UsIiRcKWdgDdQZo/ 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-kselftest@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