mirror of
https://github.com/torvalds/linux.git
synced 2026-11-07 06:17:02 +01:00
selftests: net: add test for netdev instance lock ordering on unregister
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> Link: https://patch.msgid.link/20260926041832.1649675-2-kuba@kernel.org Signed-off-by: Paolo Abeni <pabeni@redhat.com>
This commit is contained in:
parent
b6f74dff6d
commit
e542bad8d5
|
|
@ -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 \
|
||||
|
|
|
|||
42
tools/testing/selftests/net/netdev_lock.py
Executable file
42
tools/testing/selftests/net/netdev_lock.py
Executable file
|
|
@ -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()
|
||||
Loading…
Reference in New Issue
Block a user