From: Jakub Kicinski <kuba@kernel.org>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com,
andrew+netdev@lunn.ch, horms@kernel.org, sdf.kernel@gmail.com,
Jakub Kicinski <kuba@kernel.org>,
Stanislav Fomichev <sdf@fomichev.me>
Subject: [PATCH net-next v2 2/2] selftests: net: add test for netdev instance lock ordering on unregister
Date: Fri, 25 Sep 2026 21:18:32 -0700 [thread overview]
Message-ID: <20260926041832.1649675-2-kuba@kernel.org> (raw)
In-Reply-To: <20260926041832.1649675-1-kuba@kernel.org>
Dismantle two netns holding a dummy and a netkit pair registered in
opposite order. unregister_netdevice_many_notify() takes the instance
locks of all the devices at once, nesting the two kinds of devices one
way for the first netns and the other way for the second. With lockdep
enabled this used to trigger a circular locking report.
Acked-by: Stanislav Fomichev <sdf@fomichev.me>
Reviewed-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
tools/testing/selftests/net/Makefile | 1 +
tools/testing/selftests/net/netdev_lock.py | 42 ++++++++++++++++++++++
2 files changed, 43 insertions(+)
create mode 100755 tools/testing/selftests/net/netdev_lock.py
diff --git a/tools/testing/selftests/net/Makefile b/tools/testing/selftests/net/Makefile
index 3ee3378f8b26..d4ca82fec0b4 100644
--- a/tools/testing/selftests/net/Makefile
+++ b/tools/testing/selftests/net/Makefile
@@ -67,6 +67,7 @@ TEST_PROGS := \
nat6to4.sh \
ndisc_unsolicited_na_test.sh \
netdev-l2addr.sh \
+ netdev_lock.py \
netdevice.sh \
netns-name.sh \
netns-sysctl.sh \
diff --git a/tools/testing/selftests/net/netdev_lock.py b/tools/testing/selftests/net/netdev_lock.py
new file mode 100755
index 000000000000..0015b987eb9d
--- /dev/null
+++ b/tools/testing/selftests/net/netdev_lock.py
@@ -0,0 +1,42 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: GPL-2.0
+
+"""Tests for the netdev instance lock."""
+
+from lib.py import ksft_run, ksft_exit
+from lib.py import ip
+from lib.py import NetNS
+
+
+def test_unreg_order() -> None:
+ """Dismantle two netns holding the same two kinds of ops locked device,
+ registered in opposite order.
+
+ unregister_netdevice_many_notify() takes the instance lock of every
+ device in the batch and holds them all at once, so the two kinds end up
+ nested one way round for the first netns and the other way round for
+ the second.
+ """
+ with NetNS() as ns1, NetNS() as ns2:
+ net1, net2 = str(ns1), str(ns2)
+
+ ip("link add du0 type dummy", ns=net1)
+ ip("link add nk0 type netkit peer name nk1", ns=net1)
+
+ ip("link add nk0 type netkit peer name nk1", ns=net2)
+ ip("link add du0 type dummy", ns=net2)
+
+ # only devices which are up get locked during unregister
+ for net in (net1, net2):
+ for dev in ("du0", "nk0", "nk1"):
+ ip(f"link set {dev} up", ns=net)
+
+
+def main() -> None:
+ """Ksft boilerplate main."""
+ ksft_run([test_unreg_order])
+ ksft_exit()
+
+
+if __name__ == "__main__":
+ main()
--
2.55.0
next prev parent reply other threads:[~2026-09-26 4:18 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-26 4:18 [PATCH net-next v2 1/2] net: use two lockdep classes for the netdev instance lock Jakub Kicinski
2026-09-26 4:18 ` Jakub Kicinski [this message]
2026-09-26 7:08 ` Eric Dumazet
2026-09-28 18:21 ` Jakub Kicinski
2026-09-28 16:40 ` Stanislav Fomichev
2026-09-29 11:19 ` Paolo Abeni
2026-09-29 11:30 ` patchwork-bot+netdevbpf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260926041832.1649675-2-kuba@kernel.org \
--to=kuba@kernel.org \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sdf.kernel@gmail.com \
--cc=sdf@fomichev.me \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).