Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3390985pxb; Mon, 17 Jan 2022 19:26:01 -0800 (PST) X-Google-Smtp-Source: ABdhPJwNh42qxOG8Q6jhqueYJfBiRNU2a6J657ce4E8ZIxApXmZfa+0cvcl/k3nUxRLCheVPxgw+ X-Received: by 2002:a17:902:e84b:b0:14a:2b59:7780 with SMTP id t11-20020a170902e84b00b0014a2b597780mr25764395plg.43.1642476361728; Mon, 17 Jan 2022 19:26:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642476361; cv=none; d=google.com; s=arc-20160816; b=WAYJ0ghOE9Q9Up1nrr5qNWHqQxiB7X2y6WdiJYXXlz9gjXa9a+PfY+HJlWvIxWyslu uje9jfBAidKy/toJMf7KtFY8AzFgXwyb/XKRp3dJUr6T1YT0VD75CuVk4YcaXB5abFQ3 YYEKeAy9l98T6+bQsLjlTLs7Udovtki256gdhGGYs9atDLKznHl0pPIFpUb/VnmVlYYD t3Q4WFOOJ604RVAzjORH+kEleR+SSP7O3X701KQnV2jUbrEIegvbnQU4pQWqfgmlBZkz repB/1H9Ym6uKznBmYz9xwgxR7+AJ+e71+9DqK0H5ZP+gb1NxtVGHru/EOqleQDf38fo g1vA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=2VRSgoOwAeFSPBwoR3bQh37YARpymQmrFGjFudEl8rI=; b=ewW/eI6mMTIru4i3hSK9vynEH+wi3KIn76AHzGeuZvM0SSAC7GByhS7rFVnkULZhBE BIT2E74JwO3hIVakluyOL19k0fZ1oKUC4HT/6yLuiDdSC4HqauG+Pgkz4hPtiJtblI10 5yiI8rbmgXFJ2nRt/Ijzfgw2gvoqq4fBX6Q+hu2m1UlSiStv1m0so8fbj/wkleCH3zSo uCcEZD08+71N7qaN+Y2sMmzip08GVRrzEQXuT01WNv7a0Zjrn1Wpo769upGoQweQxQJV XWELGY01Q3JRzRZgpTH3iyeHUl/g2em+s+Ze+UwoVi4qcP//f1Ud/X32sHnMbAsjuDAI t0sw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=KqBSh+mn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i10si17353836plr.275.2022.01.17.19.25.49; Mon, 17 Jan 2022 19:26:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=KqBSh+mn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344442AbiARCgc (ORCPT + 99 others); Mon, 17 Jan 2022 21:36:32 -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: linux-kernel@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