Skip to content

Commit f792709

Browse files
Stanislav Fomichevkuba-moo
authored andcommitted
selftests: net: validate team flags propagation
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 <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent fa919a3 commit f792709

File tree

5 files changed

+93
-2
lines changed

5 files changed

+93
-2
lines changed

drivers/net/netdevsim/netdev.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -881,11 +881,13 @@ static void nsim_setup(struct net_device *dev)
881881
NETIF_F_SG |
882882
NETIF_F_FRAGLIST |
883883
NETIF_F_HW_CSUM |
884+
NETIF_F_LRO |
884885
NETIF_F_TSO;
885886
dev->hw_features |= NETIF_F_HW_TC |
886887
NETIF_F_SG |
887888
NETIF_F_FRAGLIST |
888889
NETIF_F_HW_CSUM |
890+
NETIF_F_LRO |
889891
NETIF_F_TSO;
890892
dev->max_mtu = ETH_MAX_MTU;
891893
dev->xdp_features = NETDEV_XDP_ACT_HW_OFFLOAD;

net/core/dev.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9278,8 +9278,16 @@ static int __dev_set_promiscuity(struct net_device *dev, int inc, bool notify)
92789278

92799279
dev_change_rx_flags(dev, IFF_PROMISC);
92809280
}
9281-
if (notify)
9281+
if (notify) {
9282+
/* The ops lock is only required to ensure consistent locking
9283+
* for `NETDEV_CHANGE` notifiers. This function is sometimes
9284+
* called without the lock, even for devices that are ops
9285+
* locked, such as in `dev_uc_sync_multiple` when using
9286+
* bonding or teaming.
9287+
*/
9288+
netdev_ops_assert_locked(dev);
92829289
__dev_notify_flags(dev, old_flags, IFF_PROMISC, 0, NULL);
9290+
}
92839291
return 0;
92849292
}
92859293

tools/testing/selftests/drivers/net/team/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# SPDX-License-Identifier: GPL-2.0
22
# Makefile for net selftests
33

4-
TEST_PROGS := dev_addr_lists.sh
4+
TEST_PROGS := dev_addr_lists.sh propagation.sh
55

66
TEST_INCLUDES := \
77
../bonding/lag_lib.sh \
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
CONFIG_DUMMY=y
22
CONFIG_IPV6=y
33
CONFIG_MACVLAN=y
4+
CONFIG_NETDEVSIM=m
45
CONFIG_NET_TEAM=y
56
CONFIG_NET_TEAM_MODE_LOADBALANCE=y
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: GPL-2.0
3+
4+
set -e
5+
6+
NSIM_LRO_ID=$((256 + RANDOM % 256))
7+
NSIM_LRO_SYS=/sys/bus/netdevsim/devices/netdevsim$NSIM_LRO_ID
8+
9+
NSIM_DEV_SYS_NEW=/sys/bus/netdevsim/new_device
10+
NSIM_DEV_SYS_DEL=/sys/bus/netdevsim/del_device
11+
12+
cleanup()
13+
{
14+
set +e
15+
ip link del dummyteam &>/dev/null
16+
ip link del team0 &>/dev/null
17+
echo $NSIM_LRO_ID > $NSIM_DEV_SYS_DEL
18+
modprobe -r netdevsim
19+
}
20+
21+
# Trigger LRO propagation to the lower.
22+
# https://lore.kernel.org/netdev/aBvOpkIoxcr9PfDg@mini-arch/
23+
team_lro()
24+
{
25+
# using netdevsim because it supports NETIF_F_LRO
26+
NSIM_LRO_NAME=$(find $NSIM_LRO_SYS/net -maxdepth 1 -type d ! \
27+
-path $NSIM_LRO_SYS/net -exec basename {} \;)
28+
29+
ip link add name team0 type team
30+
ip link set $NSIM_LRO_NAME down
31+
ip link set dev $NSIM_LRO_NAME master team0
32+
ip link set team0 up
33+
ethtool -K team0 large-receive-offload off
34+
35+
ip link del team0
36+
}
37+
38+
# Trigger promisc propagation to the lower during IFLA_MASTER.
39+
# https://lore.kernel.org/netdev/[email protected]/
40+
team_promisc()
41+
{
42+
ip link add name dummyteam type dummy
43+
ip link add name team0 type team
44+
ip link set dummyteam down
45+
ip link set team0 promisc on
46+
ip link set dev dummyteam master team0
47+
ip link set team0 up
48+
49+
ip link del team0
50+
ip link del dummyteam
51+
}
52+
53+
# Trigger promisc propagation to the lower via netif_change_flags (aka
54+
# ndo_change_rx_flags).
55+
# https://lore.kernel.org/netdev/[email protected]/
56+
team_change_flags()
57+
{
58+
ip link add name dummyteam type dummy
59+
ip link add name team0 type team
60+
ip link set dummyteam down
61+
ip link set dev dummyteam master team0
62+
ip link set team0 up
63+
ip link set team0 promisc on
64+
65+
# Make sure we can add more L2 addresses without any issues.
66+
ip link add link team0 address 00:00:00:00:00:01 team0.1 type macvlan
67+
ip link set team0.1 up
68+
69+
ip link del team0.1
70+
ip link del team0
71+
ip link del dummyteam
72+
}
73+
74+
trap cleanup EXIT
75+
modprobe netdevsim || :
76+
echo $NSIM_LRO_ID > $NSIM_DEV_SYS_NEW
77+
udevadm settle
78+
team_lro
79+
team_promisc
80+
team_change_flags

0 commit comments

Comments
 (0)