From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7C9CEC433EF for ; Tue, 18 Jan 2022 02:44:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343604AbiARCoT (ORCPT ); Mon, 17 Jan 2022 21:44:19 -0500 Received: from ams.source.kernel.org ([145.40.68.75]:48696 "EHLO ams.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346607AbiARCjh (ORCPT ); Mon, 17 Jan 2022 21:39:37 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id CE5F8B8125D; Tue, 18 Jan 2022 02:39:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6C4F5C36AF3; Tue, 18 Jan 2022 02:39:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642473573; bh=VnaSr4MhSWW2i7WWLbWLmwOjCnxmEcd4nHfq1PKfJy0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BXWhaZ8ESIiyQKDSNyyNmJkICuhEMfnhOs+R7f9rI8J82a0i4T6Q53LxugbLqBYTH /SjuvCrsxYi3E7plsrMSJU3lhhHqdiRHyBQpWJpX+33/6SQzj4YiRXVUxvZJU3/uhk 6gE9+5X4tW8fZrL95EzAmS3302C1ze6SoqYb4U3MjOmUEpmpMS0ZFo9+ekgvq204ga sSpynoayG4YA0A+BP9oOzRoWnT8S1xMlv9zMVuWHtuS7eW++vgHnPCOHicH7l2pbZP Ipbrdsw48qChV7KfEUZF3oD3y8zO5VME86S1NHHj4nSOCkNdsqVpuaNjq6hOhpzcdV mD7exzX6HOCgA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Vladimir Oltean , Florian Fainelli , "David S . Miller" , Sasha Levin , andrew@lunn.ch, vivien.didelot@gmail.com, olteanv@gmail.com, kuba@kernel.org, netdev@vger.kernel.org Subject: [PATCH AUTOSEL 5.15 174/188] net: dsa: hold rtnl_mutex when calling dsa_master_{setup,teardown} Date: Mon, 17 Jan 2022 21:31:38 -0500 Message-Id: <20220118023152.1948105-174-sashal@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220118023152.1948105-1-sashal@kernel.org> References: <20220118023152.1948105-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Vladimir Oltean [ 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 Reviewed-by: Florian Fainelli Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- 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 e9911b18bdbfa..db9cdfb190fc0 100644 --- a/net/dsa/dsa2.c +++ b/net/dsa/dsa2.c @@ -1011,6 +1011,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); @@ -1019,6 +1021,8 @@ static int dsa_tree_setup_master(struct dsa_switch_tree *dst) } } + rtnl_unlock(); + return 0; } @@ -1026,9 +1030,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