Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp3979646rwb; Sun, 9 Oct 2022 15:11:56 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7UYwzEBni23BP7C9Y9XdaGxeGvEtTql5xGQZ799djEh5sDEAaZON+aYCQEC25GNG7A7i6d X-Received: by 2002:a17:907:a46:b0:782:1c1c:8141 with SMTP id be6-20020a1709070a4600b007821c1c8141mr12662987ejc.549.1665353515940; Sun, 09 Oct 2022 15:11:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665353515; cv=none; d=google.com; s=arc-20160816; b=OSad91SxoypEVMSgLRe2X6/zExqj887hGjK7vgTzAstv+M3/CI61Oe8KJzHC7FEBRa T7XkmGL+R5oY4CSSC71IVb1ghDDKnRBMuoiPmmqTujwtQh6BUpLsjBi5IVB9NA94F0fb 6tNU8rPYJIDvnUTVjSA7jpFT52sv4CJd/WX1z+3704OLLFh/FpIb7yx+zKk2bJsaVwRw Ypf3IHY4TBreCpGlgf8DMYwFjpd/gLbIDVf1Q9ZL7m7iCnnGWtWwRbI1zwRGHuCz8YZo fAKMHHmSTGqzmonrJs+AGW/iR53VrYtSJfG32AniPnJEOCeWYy3d6rSwecN7I66Fz99T HA8A== 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=J5tSy64ezTU36nQHIZ+mailwSjSRMaiknOGejjEw8zc=; b=K5jH85VjSEUV2wOivnkhCYb4Mr7xktol/2xTn2h52dt256RdgV96/D9Mw5R2ick2qe mTCyqtdtTsuQjqhTW094hBv1vB+biYkUaivZMxrHnl9ypU5GbnJjtxmFZH3Q+zpGeBaq Eg5c0XUD2oKtrpXjLSkdmgof7wXq7i/hjP55em2mdO3WZnH8GJE1VZMKOA8LuKxXVDRj qZCKJsluH85TO3qPZmzSEkf4zBXu7me+m6JQ1CIbfraupgR1gJhJ2w9mqFRISumHV1cq GpymV+HORO9nDY/O9mRn1Vb7qCbWE0xAi2CPnxics+XzE3QUcDfXugK6OSEyWTj/Tt/N wurQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="Vw/x9lID"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gb31-20020a170907961f00b0078db3556bddsi2778219ejc.804.2022.10.09.15.11.30; Sun, 09 Oct 2022 15:11:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="Vw/x9lID"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S231202AbiJIWJz (ORCPT + 99 others); Sun, 9 Oct 2022 18:09:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40848 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230406AbiJIWJD (ORCPT ); Sun, 9 Oct 2022 18:09:03 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 61FB12981A; Sun, 9 Oct 2022 15:08:35 -0700 (PDT) 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 dfw.source.kernel.org (Postfix) with ESMTPS id 3B1F460CBB; Sun, 9 Oct 2022 22:08:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3DD41C433C1; Sun, 9 Oct 2022 22:08:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1665353306; bh=4I++Kn9fSoZUHIYC6BYNYv/X7IAgLUe/WFzrPJLmnbY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Vw/x9lID/j16T7UHNsbb+uN/t+aJVql3H9GoownUOY0HZhSgFsWngJFTaYzzgjGpr agSMDEumy541OavxYunr1ZdZqelQ701R+8O+8Th5BY8fj2P06bx2vQeQTrSdJwHI3J nbxlNuToAgzqGdGUnrB9e9Hr5m/AXg2NNscuPgMYzFBui8oeaDpmQi+21npxBbBqob +pxH4hTBve6PDK/53aR1PjGfQufaDIhBAYAD71nFIQfsp0VAv9xM70Y8qET7w9Ah6M ygCxrjaWbdtqC5dRdPCAN7AXQnAIc+Fw3MD1uJgKspnxkI3ATpR1BEtHcxqQrvtLKE 0bOtNDUrUEtdQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Vladimir Oltean , Florian Fainelli , Paolo Abeni , Sasha Levin , andrew@lunn.ch, vivien.didelot@gmail.com, olteanv@gmail.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, netdev@vger.kernel.org Subject: [PATCH AUTOSEL 6.0 11/77] net: dsa: all DSA masters must be down when changing the tagging protocol Date: Sun, 9 Oct 2022 18:06:48 -0400 Message-Id: <20221009220754.1214186-11-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221009220754.1214186-1-sashal@kernel.org> References: <20221009220754.1214186-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Vladimir Oltean [ Upstream commit f41ec1fd1c20e2a4e60a4ab8490b3e63423c0a8a ] The fact that the tagging protocol is set and queried from the /sys/class/net//dsa/tagging file is a bit of a quirk from the single CPU port days which isn't aging very well now that DSA can have more than a single CPU port. This is because the tagging protocol is a switch property, yet in the presence of multiple CPU ports it can be queried and set from multiple sysfs files, all of which are handled by the same implementation. The current logic ensures that the net device whose sysfs file we're changing the tagging protocol through must be down. That net device is the DSA master, and this is fine for single DSA master / CPU port setups. But exactly because the tagging protocol is per switch [ tree, in fact ] and not per DSA master, this isn't fine any longer with multiple CPU ports, and we must iterate through the tree and find all DSA masters, and make sure that all of them are down. Signed-off-by: Vladimir Oltean Reviewed-by: Florian Fainelli Signed-off-by: Paolo Abeni Signed-off-by: Sasha Levin --- net/dsa/dsa2.c | 10 +++------- net/dsa/dsa_priv.h | 1 - net/dsa/master.c | 2 +- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c index cac48a741f27..b2fe62bfe8dd 100644 --- a/net/dsa/dsa2.c +++ b/net/dsa/dsa2.c @@ -1238,7 +1238,6 @@ static int dsa_tree_bind_tag_proto(struct dsa_switch_tree *dst, * they would have formed disjoint trees (different "dsa,member" values). */ int dsa_tree_change_tag_proto(struct dsa_switch_tree *dst, - struct net_device *master, const struct dsa_device_ops *tag_ops, const struct dsa_device_ops *old_tag_ops) { @@ -1254,14 +1253,11 @@ int dsa_tree_change_tag_proto(struct dsa_switch_tree *dst, * attempts to change the tagging protocol. If we ever lift the IFF_UP * restriction, there needs to be another mutex which serializes this. */ - if (master->flags & IFF_UP) - goto out_unlock; - list_for_each_entry(dp, &dst->ports, list) { - if (!dsa_port_is_user(dp)) - continue; + if (dsa_port_is_cpu(dp) && (dp->master->flags & IFF_UP)) + goto out_unlock; - if (dp->slave->flags & IFF_UP) + if (dsa_port_is_user(dp) && (dp->slave->flags & IFF_UP)) goto out_unlock; } diff --git a/net/dsa/dsa_priv.h b/net/dsa/dsa_priv.h index d9722e49864b..cc1cc866dc42 100644 --- a/net/dsa/dsa_priv.h +++ b/net/dsa/dsa_priv.h @@ -545,7 +545,6 @@ struct dsa_lag *dsa_tree_lag_find(struct dsa_switch_tree *dst, int dsa_tree_notify(struct dsa_switch_tree *dst, unsigned long e, void *v); int dsa_broadcast(unsigned long e, void *v); int dsa_tree_change_tag_proto(struct dsa_switch_tree *dst, - struct net_device *master, const struct dsa_device_ops *tag_ops, const struct dsa_device_ops *old_tag_ops); void dsa_tree_master_admin_state_change(struct dsa_switch_tree *dst, diff --git a/net/dsa/master.c b/net/dsa/master.c index 2851e44c4cf0..32c0a00a8b92 100644 --- a/net/dsa/master.c +++ b/net/dsa/master.c @@ -307,7 +307,7 @@ static ssize_t tagging_store(struct device *d, struct device_attribute *attr, */ goto out; - err = dsa_tree_change_tag_proto(cpu_dp->ds->dst, dev, new_tag_ops, + err = dsa_tree_change_tag_proto(cpu_dp->ds->dst, new_tag_ops, old_tag_ops); if (err) { /* On failure the old tagger is restored, so we don't need the -- 2.35.1