Re: [PATCH AUTOSEL 5.16 203/217] net: dsa: hold rtnl_mutex when calling dsa_master_{setup,teardown}

From: Vladimir Oltean
Date: Tue Jan 18 2022 - 07:13:36 EST


Hi Sasha,

On Mon, Jan 17, 2022 at 09:19:26PM -0500, Sasha Levin wrote:
> From: Vladimir Oltean <vladimir.oltean@xxxxxxx>
>
> [ Upstream commit c146f9bc195a9dc3ad7fd000a14540e7c9df952d ]
>
> 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@xxxxxxx>
> Reviewed-by: Florian Fainelli <f.fainelli@xxxxxxxxx>
> Signed-off-by: David S. Miller <davem@xxxxxxxxxxxxx>
> Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>
> ---

Please drop this patch from all stable branches (5.16, 5.15, 5.10).
Thanks.

> 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 826957b6442b0..834f26539da73 100644
> --- a/net/dsa/dsa2.c
> +++ b/net/dsa/dsa2.c
> @@ -997,6 +997,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);
> @@ -1005,6 +1007,8 @@ static int dsa_tree_setup_master(struct dsa_switch_tree *dst)
> }
> }
>
> + rtnl_unlock();
> +
> return 0;
> }
>
> @@ -1012,9 +1016,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 e8e19857621bd..16b7dfd22bf5d 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.34.1
>