All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vladimir Oltean <vladimir.oltean@nxp.com>
To: netdev@vger.kernel.org
Cc: "David S. Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>, Andrew Lunn <andrew@lunn.ch>,
	Vivien Didelot <vivien.didelot@gmail.com>,
	Florian Fainelli <f.fainelli@gmail.com>
Subject: [PATCH net-next 04/15] net: dsa: hold rtnl_mutex when calling dsa_master_{setup,teardown}
Date: Tue,  4 Jan 2022 19:14:02 +0200	[thread overview]
Message-ID: <20220104171413.2293847-5-vladimir.oltean@nxp.com> (raw)
In-Reply-To: <20220104171413.2293847-1-vladimir.oltean@nxp.com>

DSA needs to simulate master tracking events when a binding is first
with a DSA master established and torn down, in order to give drivers
the simplifying guarantee that ->master_state_change calls are made
only when the master's readiness state to pass traffic changes.
master_state_change() provide a operational bool that DSA driver can use
to understand if DSA master is operational or not.
To avoid races, we need to block the reception of
NETDEV_UP/NETDEV_CHANGE/NETDEV_GOING_DOWN events in the netdev notifier
chain while we are changing the master's dev->dsa_ptr (this changes what
netdev_uses_dsa(dev) reports).

The dsa_master_setup() and dsa_master_teardown() functions optionally
require the rtnl_mutex to be held, if the tagger needs the master to be
promiscuous, these functions call dev_set_promiscuity(). Move the
rtnl_lock() from that function and make it top-level.

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
---
 net/dsa/dsa2.c   | 8 ++++++++
 net/dsa/master.c | 4 ++--
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c
index c18b22c0bf55..f044136f3625 100644
--- a/net/dsa/dsa2.c
+++ b/net/dsa/dsa2.c
@@ -1038,6 +1038,8 @@ static int dsa_tree_setup_master(struct dsa_switch_tree *dst)
 	struct dsa_port *dp;
 	int err;
 
+	rtnl_lock();
+
 	list_for_each_entry(dp, &dst->ports, list) {
 		if (dsa_port_is_cpu(dp)) {
 			err = dsa_master_setup(dp->master, dp);
@@ -1046,6 +1048,8 @@ static int dsa_tree_setup_master(struct dsa_switch_tree *dst)
 		}
 	}
 
+	rtnl_unlock();
+
 	return 0;
 }
 
@@ -1053,9 +1057,13 @@ static void dsa_tree_teardown_master(struct dsa_switch_tree *dst)
 {
 	struct dsa_port *dp;
 
+	rtnl_lock();
+
 	list_for_each_entry(dp, &dst->ports, list)
 		if (dsa_port_is_cpu(dp))
 			dsa_master_teardown(dp->master);
+
+	rtnl_unlock();
 }
 
 static int dsa_tree_setup_lags(struct dsa_switch_tree *dst)
diff --git a/net/dsa/master.c b/net/dsa/master.c
index f4efb244f91d..2199104ca7df 100644
--- a/net/dsa/master.c
+++ b/net/dsa/master.c
@@ -267,9 +267,9 @@ static void dsa_master_set_promiscuity(struct net_device *dev, int inc)
 	if (!ops->promisc_on_master)
 		return;
 
-	rtnl_lock();
+	ASSERT_RTNL();
+
 	dev_set_promiscuity(dev, inc);
-	rtnl_unlock();
 }
 
 static ssize_t tagging_show(struct device *d, struct device_attribute *attr,
-- 
2.25.1


  parent reply	other threads:[~2022-01-04 17:14 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-04 17:13 [PATCH net-next 00/15] DSA miscellaneous cleanups Vladimir Oltean
2022-01-04 17:13 ` [PATCH net-next 01/15] net: dsa: reorder PHY initialization with MTU setup in slave.c Vladimir Oltean
2022-01-04 17:14 ` [PATCH net-next 02/15] net: dsa: merge rtnl_lock sections in dsa_slave_create Vladimir Oltean
2022-01-04 17:14 ` [PATCH net-next 03/15] net: dsa: stop updating master MTU from master.c Vladimir Oltean
2022-01-04 17:14 ` Vladimir Oltean [this message]
2022-01-04 17:14 ` [PATCH net-next 05/15] net: dsa: first set up shared ports, then non-shared ports Vladimir Oltean
2022-01-04 17:14 ` [PATCH net-next 06/15] net: dsa: setup master before ports Vladimir Oltean
2022-01-04 17:14 ` [PATCH net-next 07/15] net: dsa: remove cross-chip support for MRP Vladimir Oltean
2022-01-05 10:01   ` Horatiu Vultur
2022-01-05 11:51     ` Vladimir Oltean
2022-01-04 17:14 ` [PATCH net-next 08/15] net: dsa: remove cross-chip support for HSR Vladimir Oltean
2022-01-04 22:03   ` George McCollister
2022-01-04 22:20     ` Vladimir Oltean
2022-01-04 17:14 ` [PATCH net-next 09/15] net: dsa: move dsa_port :: stp_state near dsa_port :: mac Vladimir Oltean
2022-01-04 17:14 ` [PATCH net-next 10/15] net: dsa: merge all bools of struct dsa_port into a single u8 Vladimir Oltean
2022-01-04 17:14 ` [PATCH net-next 11/15] net: dsa: move dsa_port :: type near dsa_port :: index Vladimir Oltean
2022-01-04 17:14 ` [PATCH net-next 12/15] net: dsa: merge all bools of struct dsa_switch into a single u32 Vladimir Oltean
2022-01-04 17:14 ` [PATCH net-next 13/15] net: dsa: make dsa_switch :: num_ports an unsigned int Vladimir Oltean
2022-01-04 17:14 ` [PATCH net-next 14/15] net: dsa: move dsa_switch_tree :: ports and lags to first cache line Vladimir Oltean
2022-01-04 17:14 ` [PATCH net-next 15/15] net: dsa: combine two holes in struct dsa_switch_tree Vladimir Oltean

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220104171413.2293847-5-vladimir.oltean@nxp.com \
    --to=vladimir.oltean@nxp.com \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=f.fainelli@gmail.com \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=vivien.didelot@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.