From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9250932D7C7 for ; Thu, 30 Jul 2026 10:00:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785405641; cv=none; b=WspjHSLRdIvrfWnTZB3ZGw0qKNCk0usQVtGJ1Fk2uVehyxyFB9aHi1uEV1o3Hiz/WpmJxFBj8FcE+AZuG4MuNXSRunxNvLM6gVB8TUKqpQOo4A9RakLLOXbeMSwJfEBLrprc2bmDAX7Ry1Wdaol5jlJh9jjt3ZGyYcKsezKIKl4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785405641; c=relaxed/simple; bh=M+EikJXOV5ueFth3iiiyE2gUNLf/QkhEf+GG9Ksx+o0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=U7TMTxGGEffoE4wlPWe35Ys8DgrPNzP0hqYeB2/lTsQqrHE797KHKqSYJvnb7M3qHLbGxH1WEeNIJU2BYSwIbnm5sliXKsXadesuEAlVOafJjApKqZnngCxDnWB4Hd8PHyfdKqGyOQkuTpt/i3wF5Rhfcf4SRNmY/ikXxPa5M1o= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=rJVcZk90; arc=none smtp.client-ip=209.85.221.53 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.b="rJVcZk90" Received: by mail-wr1-f53.google.com with SMTP id ffacd0b85a97d-47f3b39f2a1so1824243f8f.2 for ; Thu, 30 Jul 2026 03:00:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785405637; x=1786010437; 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=brqEgrC204Q7R2Ht2zUutLTCuoa/Yw12EIf+KqcFosU=; b=rJVcZk90XgABKAAS7X3Z3Q4VZwrrfhvjMtWep4Necwy5l5G1G4pxfcKQQcWjYfLjWD Df9Tzl6GQVHId31JQoUYnbO4U11vUxqTUYeQy6CcmCNnH2ruSUZqe7ecgmyW/TLiKlG0 joLT7JwMTctO9WlIJSRryLMnaxLZUlDaDc6WfAEQLHBUL5Z7bgs6yB9w6tSVPjzvEqxM RMd5WSEBkxVu+n8jV/TOW0saPkF9y8D44iAKEwAP9xlw6IBQXh07Js/m3cj94OX9+rbK +ZBBaqeF26pCMKemByQOQQrYVOCwKIi8SgHT1M69WJ44Do5w9AJP6eSRi4XJHrquz7Li Dlng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785405637; x=1786010437; 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=brqEgrC204Q7R2Ht2zUutLTCuoa/Yw12EIf+KqcFosU=; b=WrIQdmYpzjx5eAslGmr0gk+yyc1Q6ZBCn4adeFmV9Vj7lFKkM+YVT2ASA+H9fPcB/R geBF4R7pt2qAHXK0iK0qq9347WCC0kvz6b+dZLhuFvYzYuC3Z14mrIO7TQmXLm+V2veb hEMrzQF8yJ1YRRTzo7oByBcLAqb0VV6qVPBRIALeT44moU4/f2C3fYN6OV3a95aDMj7l Xcmt6D+GV8w73vcgwQ8UOvyES74VexXnBAiDEMgnokCirjdp2qZwu0PrTMuOtN09fr1c pCnHvjx+JlJveSDAq+fqdLhQITxG6mMxS3mfKWL4CO0Pm4q+WQpbkE1hTxHXRHtr4idi gH3w== X-Forwarded-Encrypted: i=1; AHgh+Rqzrl51fH9vzIdjdnUYl6FmaP9W5yybpmNsTijaU4EtmLNLoPEsgY6HAmeYPjYq+/rff+LHGC82KwjiQAA=@vger.kernel.org X-Gm-Message-State: AOJu0Yxd/tW9wefXEdRTisgOKCyeBWy1e8jTG7OWpS7gKpio671pNC76 XkrylzdhUav+83QhEfods6Do1fRtXw3nV9sCr3lQ0kRheIPPuGRyNimB X-Gm-Gg: AR+sD11tBWvV7c8MLFKx0GWmFd1IQTBtN6rb3JKZXNQbp+ki2m5nla6tpiO8i51zXzJ HITkLQo+lEK248EewhYYPmS2XftyVxCc/JDKdKNU/9WvLcyuihYpA/4Cx2Y9AC9sP6iYe0saqH5 yA7mqBFRhwRukeFzIYIFXPHOe5UQbvE2nW1oaF1PjyNLOG7+lAs046tXsdyUvYfxR1EWkGxF2v6 9jIMEX1mbIMTAdjnLwLdE3YPwUiR4wSgagXSFrih8SK08kaRQ7JRumu5y+r3BLfYQ4CP1311hdw wYZP5yad9b13l6T5Vazp2J3b7E8csTB2LgWjeHFtFsF/aL2bXZUshT1Kwd/S72PPbGxWH4XUKQH GjmX9xGrvfSO/RBpmX2/URx6UV4ZD/6oC4p01bgMLCnbecrn2Fhv059m3J8YjPpxshU4f/AUBZm sgWrI6a/mVFisFKDz14Y6ZFquzheNaZEWqLc3jvJ5OOgr+UMSNPu4bo03Q1Oy1NouoMd3NzKUTY v6aayv8MhzP X-Received: by 2002:a05:6000:4a10:b0:47f:9720:4740 with SMTP id ffacd0b85a97d-47fc822dc64mr2244168f8f.37.1785405636307; Thu, 30 Jul 2026 03:00:36 -0700 (PDT) Received: from pf-5j7x25.fkb.profitbricks.net ([2001:9e8:482:5000:a5d:311:98af:bd1a]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-47fc88e4721sm3984728f8f.16.2026.07.30.03.00.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Jul 2026 03:00:35 -0700 (PDT) From: Reshma Sreekumar To: Jamal Hadi Salim , Jiri Pirko , netdev@vger.kernel.org Cc: "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Shuah Khan , linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Reshma Sreekumar Subject: [PATCH net 2/2] selftests: net: check that a disturbed qdisc dump is flagged Date: Thu, 30 Jul 2026 12:00:06 +0200 Message-ID: <20260730100006.3547944-3-reshmaisat@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260730100006.3547944-1-reshmaisat@gmail.com> References: <20260730100006.3547944-1-reshmaisat@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Add a test for NLM_F_DUMP_INTR on RTM_GETQDISC. A qdisc dump spans several netlink batches once a few devices carry a full set of qdiscs, and RTNL is only held while a single batch is filled, so the device list can change in between and entries can be missed. Netlink dumps are driven by the reader, so rather than racing against a dump the test unregisters a device at a known point: it receives the first batch, unregisters a dummy, then drains the rest. This is deterministic -- one flagged message, every run. A second case dumps without disturbing anything and requires that the flag stays clear, so the test cannot be satisfied by a kernel that raises it unconditionally. Four dummy devices with mq + 16 fq + clsact each, read with a 4KiB buffer, give 12 batches and run in about a second. The test skips if dummy, mq, fq or clsact are unavailable. Signed-off-by: Reshma Sreekumar --- tools/testing/selftests/net/Makefile | 1 + .../testing/selftests/net/qdisc_dump_intr.py | 123 ++++++++++++++++++ 2 files changed, 124 insertions(+) create mode 100755 tools/testing/selftests/net/qdisc_dump_intr.py diff --git a/tools/testing/selftests/net/Makefile b/tools/testing/selftests/net/Makefile index 708d960ae..769ee26ae 100644 --- a/tools/testing/selftests/net/Makefile +++ b/tools/testing/selftests/net/Makefile @@ -72,6 +72,7 @@ TEST_PROGS := \ pmtu.sh \ protodown.sh \ psock_snd.sh \ + qdisc_dump_intr.py \ reuseaddr_ports_exhausted.sh \ reuseport_addr_any.sh \ route_hint.sh \ diff --git a/tools/testing/selftests/net/qdisc_dump_intr.py b/tools/testing/selftests/net/qdisc_dump_intr.py new file mode 100755 index 000000000..9623847f4 --- /dev/null +++ b/tools/testing/selftests/net/qdisc_dump_intr.py @@ -0,0 +1,123 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0 + +""" +Check that a qdisc dump disturbed by a device unregister reports +NLM_F_DUMP_INTR. + +tc_dump_qdisc() walks every netdev in the netns and spans several netlink +batches once there are more than a handful of qdiscs. RTNL is only held +while a single batch is filled, so the device list can change in between and +the reply can miss entries. Netlink dumps are driven by the reader, so this +test unregisters a device at a known point between two batches rather than +racing against one. +""" + +import socket +import struct + +from lib.py import ksft_run, ksft_exit, ksft_true, ksft_pr, KsftSkipEx +from lib.py import CmdExitFailure, NetNS, NetNSEnter, ip, tc + +NETLINK_ROUTE = 0 +RTM_NEWQDISC = 36 +RTM_GETQDISC = 38 +NLMSG_DONE = 3 +NLM_F_REQUEST = 0x001 +NLM_F_DUMP = 0x300 +NLM_F_DUMP_INTR = 0x010 + +NLMSGHDR = "=IHHII" +TCMSG_LEN = 20 # struct tcmsg + +# tc parses handles as hex; 64: keeps the mq root clear of the fq children +MQ_HANDLE = "64" +CHANNELS = 16 # fq children per device +NDEVS = 4 # 4 * (mq + 16 fq + clsact) is several batches worth +BUFSZ = 4096 # small recv buffer keeps the kernel's batches small + + +def _setup(): + """Devices carrying enough qdiscs that a dump has to paginate.""" + try: + for i in range(NDEVS): + ip(f"link add d{i} numtxqueues {CHANNELS} type dummy") + ip(f"link set d{i} up") + tc(f"qdisc replace dev d{i} root handle {MQ_HANDLE}: mq") + for q in range(1, CHANNELS + 1): + tc(f"qdisc replace dev d{i} parent {MQ_HANDLE}:{q:x} " + f"handle {q:x}: fq") + tc(f"qdisc replace dev d{i} clsact") + except CmdExitFailure as exc: + raise KsftSkipEx("dummy, mq, fq or clsact unavailable") from exc + + +def _dump(between_batches=None): + """ + Walk an RTM_GETQDISC dump one batch at a time, optionally running + `between_batches` after the first batch. Returns (batches, qdiscs, + messages carrying NLM_F_DUMP_INTR). + """ + sk = socket.socket(socket.AF_NETLINK, socket.SOCK_RAW, NETLINK_ROUTE) + try: + sk.bind((0, 0)) + hdr = struct.pack(NLMSGHDR, struct.calcsize(NLMSGHDR) + TCMSG_LEN, + RTM_GETQDISC, NLM_F_REQUEST | NLM_F_DUMP, 1, 0) + sk.send(hdr + bytes(TCMSG_LEN)) + + batches = qdiscs = intr = 0 + done = False + while not done: + buf = sk.recv(BUFSZ) + batches += 1 + off = 0 + while off + 16 <= len(buf): + mlen, mtype, flags = struct.unpack_from("=IHH", buf, off) + if mlen < 16: + break + if flags & NLM_F_DUMP_INTR: + intr += 1 + if mtype == NLMSG_DONE: + done = True + elif mtype == RTM_NEWQDISC: + qdiscs += 1 + off += (mlen + 3) & ~3 + if batches == 1 and not done and between_batches: + between_batches() + return batches, qdiscs, intr + finally: + sk.close() + + +def dump_intr_on_unregister() -> None: + """Unregistering a device mid-dump must raise NLM_F_DUMP_INTR.""" + ip("link add victim type dummy") + + batches, qdiscs, intr = _dump(lambda: ip("link del victim")) + + ksft_pr(f"{batches} batches, {qdiscs} qdiscs, {intr} flagged messages") + ksft_true(batches > 1, "dump did not paginate, nothing to disturb") + ksft_true(intr > 0, + "NLM_F_DUMP_INTR not set although a device was unregistered " + "while the dump was in flight") + + +def dump_intr_absent_when_stable() -> None: + """An undisturbed dump must not raise NLM_F_DUMP_INTR.""" + batches, qdiscs, intr = _dump() + + ksft_pr(f"{batches} batches, {qdiscs} qdiscs, {intr} flagged messages") + ksft_true(batches > 1, "dump did not paginate, test is not meaningful") + ksft_true(intr == 0, "NLM_F_DUMP_INTR set on an undisturbed dump") + + +def main() -> None: + with NetNS() as ns: + with NetNSEnter(str(ns)): + _setup() + ksft_run(globs=globals(), case_pfx={"dump_"}) + ksft_exit() + + +if __name__ == "__main__": + main() -- 2.43.0