cbbe52b0cc97b2ebb84bb419919d407b58c54861
[openwrt/openwrt.git] /
1 From c146f9bc195a9dc3ad7fd000a14540e7c9df952d Mon Sep 17 00:00:00 2001
2 From: Vladimir Oltean <vladimir.oltean@nxp.com>
3 Date: Thu, 6 Jan 2022 01:11:15 +0200
4 Subject: [PATCH 4/6] net: dsa: hold rtnl_mutex when calling
5 dsa_master_{setup,teardown}
6
7 DSA needs to simulate master tracking events when a binding is first
8 with a DSA master established and torn down, in order to give drivers
9 the simplifying guarantee that ->master_state_change calls are made
10 only when the master's readiness state to pass traffic changes.
11 master_state_change() provide a operational bool that DSA driver can use
12 to understand if DSA master is operational or not.
13 To avoid races, we need to block the reception of
14 NETDEV_UP/NETDEV_CHANGE/NETDEV_GOING_DOWN events in the netdev notifier
15 chain while we are changing the master's dev->dsa_ptr (this changes what
16 netdev_uses_dsa(dev) reports).
17
18 The dsa_master_setup() and dsa_master_teardown() functions optionally
19 require the rtnl_mutex to be held, if the tagger needs the master to be
20 promiscuous, these functions call dev_set_promiscuity(). Move the
21 rtnl_lock() from that function and make it top-level.
22
23 Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
24 Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
25 Signed-off-by: David S. Miller <davem@davemloft.net>
26 ---
27 net/dsa/dsa2.c | 8 ++++++++
28 net/dsa/master.c | 4 ++--
29 2 files changed, 10 insertions(+), 2 deletions(-)
30
31 diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c
32 index a0d84f9f864f..52fb1958b535 100644
33 --- a/net/dsa/dsa2.c
34 +++ b/net/dsa/dsa2.c
35 @@ -1038,6 +1038,8 @@ static int dsa_tree_setup_master(struct dsa_switch_tree *dst)
36 struct dsa_port *dp;
37 int err;
38
39 + rtnl_lock();
40 +
41 list_for_each_entry(dp, &dst->ports, list) {
42 if (dsa_port_is_cpu(dp)) {
43 err = dsa_master_setup(dp->master, dp);
44 @@ -1046,6 +1048,8 @@ static int dsa_tree_setup_master(struct dsa_switch_tree *dst)
45 }
46 }
47
48 + rtnl_unlock();
49 +
50 return 0;
51 }
52
53 @@ -1053,9 +1057,13 @@ static void dsa_tree_teardown_master(struct dsa_switch_tree *dst)
54 {
55 struct dsa_port *dp;
56
57 + rtnl_lock();
58 +
59 list_for_each_entry(dp, &dst->ports, list)
60 if (dsa_port_is_cpu(dp))
61 dsa_master_teardown(dp->master);
62 +
63 + rtnl_unlock();
64 }
65
66 static int dsa_tree_setup_lags(struct dsa_switch_tree *dst)
67 diff --git a/net/dsa/master.c b/net/dsa/master.c
68 index f4efb244f91d..2199104ca7df 100644
69 --- a/net/dsa/master.c
70 +++ b/net/dsa/master.c
71 @@ -267,9 +267,9 @@ static void dsa_master_set_promiscuity(struct net_device *dev, int inc)
72 if (!ops->promisc_on_master)
73 return;
74
75 - rtnl_lock();
76 + ASSERT_RTNL();
77 +
78 dev_set_promiscuity(dev, inc);
79 - rtnl_unlock();
80 }
81
82 static ssize_t tagging_show(struct device *d, struct device_attribute *attr,
83 --
84 2.34.1
85