67d434006b77210b6ef2371bbb772b64cb78ff6a
[openwrt/staging/dedeckeh.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 --- a/net/dsa/dsa2.c
32 +++ b/net/dsa/dsa2.c
33 @@ -1034,6 +1034,8 @@ static int dsa_tree_setup_master(struct
34 struct dsa_port *dp;
35 int err;
36
37 + rtnl_lock();
38 +
39 list_for_each_entry(dp, &dst->ports, list) {
40 if (dsa_port_is_cpu(dp)) {
41 err = dsa_master_setup(dp->master, dp);
42 @@ -1042,6 +1044,8 @@ static int dsa_tree_setup_master(struct
43 }
44 }
45
46 + rtnl_unlock();
47 +
48 return 0;
49 }
50
51 @@ -1049,9 +1053,13 @@ static void dsa_tree_teardown_master(str
52 {
53 struct dsa_port *dp;
54
55 + rtnl_lock();
56 +
57 list_for_each_entry(dp, &dst->ports, list)
58 if (dsa_port_is_cpu(dp))
59 dsa_master_teardown(dp->master);
60 +
61 + rtnl_unlock();
62 }
63
64 static int dsa_tree_setup_lags(struct dsa_switch_tree *dst)
65 --- a/net/dsa/master.c
66 +++ b/net/dsa/master.c
67 @@ -267,9 +267,9 @@ static void dsa_master_set_promiscuity(s
68 if (!ops->promisc_on_master)
69 return;
70
71 - rtnl_lock();
72 + ASSERT_RTNL();
73 +
74 dev_set_promiscuity(dev, inc);
75 - rtnl_unlock();
76 }
77
78 static ssize_t tagging_show(struct device *d, struct device_attribute *attr,