]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
selftests: net: validate team flags propagation
authorStanislav Fomichev <stfomichev@gmail.com>
Fri, 16 May 2025 23:22:05 +0000 (16:22 -0700)
committerJakub Kicinski <kuba@kernel.org>
Wed, 21 May 2025 01:12:58 +0000 (18:12 -0700)
Cover three recent cases:
1. missing ops locking for the lowers during netdev_sync_lower_features
2. missing locking for dev_set_promiscuity (plus netdev_ops_assert_locked
   with a comment on why/when it's needed)
3. rcu lock during team_change_rx_flags

Verified that each one triggers when the respective fix is reverted.
Not sure about the placement, but since it all relies on teaming,
added to the teaming directory.

One ugly bit is that I add NETIF_F_LRO to netdevsim; there is no way
to trigger netdev_sync_lower_features without it.

Signed-off-by: Stanislav Fomichev <stfomichev@gmail.com>
Link: https://patch.msgid.link/20250516232205.539266-1-stfomichev@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/netdevsim/netdev.c
net/core/dev.c
tools/testing/selftests/drivers/net/team/Makefile
tools/testing/selftests/drivers/net/team/config
tools/testing/selftests/drivers/net/team/propagation.sh [new file with mode: 0755]

index 2aa999345fe1293628ee8e370b563497d4795296..af545d42961c3cb8c0ffcd78ac2fe54453bd27f0 100644 (file)
@@ -881,11 +881,13 @@ static void nsim_setup(struct net_device *dev)
                         NETIF_F_SG |
                         NETIF_F_FRAGLIST |
                         NETIF_F_HW_CSUM |
+                        NETIF_F_LRO |
                         NETIF_F_TSO;
        dev->hw_features |= NETIF_F_HW_TC |
                            NETIF_F_SG |
                            NETIF_F_FRAGLIST |
                            NETIF_F_HW_CSUM |
+                           NETIF_F_LRO |
                            NETIF_F_TSO;
        dev->max_mtu = ETH_MAX_MTU;
        dev->xdp_features = NETDEV_XDP_ACT_HW_OFFLOAD;
index fccf2167b2352f0cba80651c8245c9d5260ac205..6d1a238dd4401b9a9a9f116ad7c3c8522bc5175e 100644 (file)
@@ -9278,8 +9278,16 @@ static int __dev_set_promiscuity(struct net_device *dev, int inc, bool notify)
 
                dev_change_rx_flags(dev, IFF_PROMISC);
        }
-       if (notify)
+       if (notify) {
+               /* The ops lock is only required to ensure consistent locking
+                * for `NETDEV_CHANGE` notifiers. This function is sometimes
+                * called without the lock, even for devices that are ops
+                * locked, such as in `dev_uc_sync_multiple` when using
+                * bonding or teaming.
+                */
+               netdev_ops_assert_locked(dev);
                __dev_notify_flags(dev, old_flags, IFF_PROMISC, 0, NULL);
+       }
        return 0;
 }
 
index 2d5a76d9918104a5f39ae54a76b5ba97757c78dd..eaf6938f100e7c4a7db120acba4f7bc203f4f529 100644 (file)
@@ -1,7 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0
 # Makefile for net selftests
 
-TEST_PROGS := dev_addr_lists.sh
+TEST_PROGS := dev_addr_lists.sh propagation.sh
 
 TEST_INCLUDES := \
        ../bonding/lag_lib.sh \
index b5e3a3aad4bfbb5f1d77b4fd1bd4ae566f6394a1..636b3525b679a42acd9d833bd54af2e1e39b3d42 100644 (file)
@@ -1,5 +1,6 @@
 CONFIG_DUMMY=y
 CONFIG_IPV6=y
 CONFIG_MACVLAN=y
+CONFIG_NETDEVSIM=m
 CONFIG_NET_TEAM=y
 CONFIG_NET_TEAM_MODE_LOADBALANCE=y
diff --git a/tools/testing/selftests/drivers/net/team/propagation.sh b/tools/testing/selftests/drivers/net/team/propagation.sh
new file mode 100755 (executable)
index 0000000..4bea75b
--- /dev/null
@@ -0,0 +1,80 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+
+set -e
+
+NSIM_LRO_ID=$((256 + RANDOM % 256))
+NSIM_LRO_SYS=/sys/bus/netdevsim/devices/netdevsim$NSIM_LRO_ID
+
+NSIM_DEV_SYS_NEW=/sys/bus/netdevsim/new_device
+NSIM_DEV_SYS_DEL=/sys/bus/netdevsim/del_device
+
+cleanup()
+{
+       set +e
+       ip link del dummyteam &>/dev/null
+       ip link del team0 &>/dev/null
+       echo $NSIM_LRO_ID > $NSIM_DEV_SYS_DEL
+       modprobe -r netdevsim
+}
+
+# Trigger LRO propagation to the lower.
+# https://lore.kernel.org/netdev/aBvOpkIoxcr9PfDg@mini-arch/
+team_lro()
+{
+       # using netdevsim because it supports NETIF_F_LRO
+       NSIM_LRO_NAME=$(find $NSIM_LRO_SYS/net -maxdepth 1 -type d ! \
+               -path $NSIM_LRO_SYS/net -exec basename {} \;)
+
+       ip link add name team0 type team
+       ip link set $NSIM_LRO_NAME down
+       ip link set dev $NSIM_LRO_NAME master team0
+       ip link set team0 up
+       ethtool -K team0 large-receive-offload off
+
+       ip link del team0
+}
+
+# Trigger promisc propagation to the lower during IFLA_MASTER.
+# https://lore.kernel.org/netdev/20250506032328.3003050-1-sdf@fomichev.me/
+team_promisc()
+{
+       ip link add name dummyteam type dummy
+       ip link add name team0 type team
+       ip link set dummyteam down
+       ip link set team0 promisc on
+       ip link set dev dummyteam master team0
+       ip link set team0 up
+
+       ip link del team0
+       ip link del dummyteam
+}
+
+# Trigger promisc propagation to the lower via netif_change_flags (aka
+# ndo_change_rx_flags).
+# https://lore.kernel.org/netdev/20250514220319.3505158-1-stfomichev@gmail.com/
+team_change_flags()
+{
+       ip link add name dummyteam type dummy
+       ip link add name team0 type team
+       ip link set dummyteam down
+       ip link set dev dummyteam master team0
+       ip link set team0 up
+       ip link set team0 promisc on
+
+       # Make sure we can add more L2 addresses without any issues.
+       ip link add link team0 address 00:00:00:00:00:01 team0.1 type macvlan
+       ip link set team0.1 up
+
+       ip link del team0.1
+       ip link del team0
+       ip link del dummyteam
+}
+
+trap cleanup EXIT
+modprobe netdevsim || :
+echo $NSIM_LRO_ID > $NSIM_DEV_SYS_NEW
+udevadm settle
+team_lro
+team_promisc
+team_change_flags