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(-)
31 diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c
32 index a0d84f9f864f..52fb1958b535 100644
35 @@ -1038,6 +1038,8 @@ static int dsa_tree_setup_master(struct dsa_switch_tree *dst)
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)
53 @@ -1053,9 +1057,13 @@ static void dsa_tree_teardown_master(struct dsa_switch_tree *dst)
59 list_for_each_entry(dp, &dst->ports, list)
60 if (dsa_port_is_cpu(dp))
61 dsa_master_teardown(dp->master);
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)
78 dev_set_promiscuity(dev, inc);
82 static ssize_t tagging_show(struct device *d, struct device_attribute *attr,