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 6BC0CC433EF for ; Tue, 18 Jan 2022 02:33:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343778AbiARCdT (ORCPT ); Mon, 17 Jan 2022 21:33:19 -0500 Received: from ams.source.kernel.org ([145.40.68.75]:43158 "EHLO ams.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345106AbiARCbR (ORCPT ); Mon, 17 Jan 2022 21:31:17 -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 2BDCBB8122C; Tue, 18 Jan 2022 02:31:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D907AC36AE3; Tue, 18 Jan 2022 02:31:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642473075; bh=hUrr8ljdmpq8nqlX6tfnScUelLfOIbrBiiOFg4F6pKw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KqBSh+mnskk6VJA0q/RcIaiTlIv+bt0/AGB72SA1vR/muhCsxqfNIFvHF4hMOrk/t 48VsEWATgnEWJ57HTsroWWP9WodikKkYA/f1TKNa7NTYQHQ8O++2gt7fJPHGtE/UAg 7LArG9toXZ2+CidXIQtHTqS95xQ+loRi/SOgA4hszKTo0zK4fR1GQVMwzvq1HYBwYN MwODb49frB1+/K5FFP6c8UVZ815iOpj+Cp2K6b5q54mJcRclSMgVfA9ULaT8WfDFvR wvrpSFlm9xZpUAADSPgHxTVkN+xwbegiI1pyiBo9V+YNRADS5h66KunrRzqMOZUWNX KwRC1sDejtcBQ== 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.16 203/217] net: dsa: hold rtnl_mutex when calling dsa_master_{setup,teardown} Date: Mon, 17 Jan 2022 21:19:26 -0500 Message-Id: <20220118021940.1942199-203-sashal@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220118021940.1942199-1-sashal@kernel.org> References: <20220118021940.1942199-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 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