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}
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).
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.
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>
27 net/dsa/dsa2.c | 8 ++++++++
28 net/dsa/master.c | 4 ++--
29 2 files changed, 10 insertions(+), 2 deletions(-)
33 @@ -1056,6 +1056,8 @@ static int dsa_tree_setup_master(struct
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 @@ -1064,6 +1066,8 @@ static int dsa_tree_setup_master(struct
51 @@ -1071,9 +1075,13 @@ static void dsa_tree_teardown_master(str
57 list_for_each_entry(dp, &dst->ports, list)
58 if (dsa_port_is_cpu(dp))
59 dsa_master_teardown(dp->master);
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 @@ -266,9 +266,9 @@ static void dsa_master_set_promiscuity(s
68 if (!ops->promisc_on_master)
74 dev_set_promiscuity(dev, inc);
78 static ssize_t tagging_show(struct device *d, struct device_attribute *attr,