Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp4043192rwb; Sun, 9 Oct 2022 16:40:24 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7LhsdCgVa+A4VAvQmpS6SxDHoKEYGRHacPZzwS69/CP8L0RRgM8i45RaqYVsBEPgfy7pn1 X-Received: by 2002:a63:1326:0:b0:439:40b5:77cc with SMTP id i38-20020a631326000000b0043940b577ccmr14583992pgl.473.1665358824092; Sun, 09 Oct 2022 16:40:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665358824; cv=none; d=google.com; s=arc-20160816; b=deNP8iVWufRKU5pPANLR3tpgAMqYiKEM8RhCny7jAYcYrW9FNdPZEH3kmCydCOCBkY GUQlV8UlYANpX/1m4V4x5N8/XK7jKrz1gTo5P2Msj6BE1AiMugj3OgTKS5eRn9B+xRPe de+drX8Drew899alHQ3Hoauyrm3+BysXLLfB0tybpszrZ1gzgSGVAXH58WbjCqXdlFIE KYNV4QknG8wmv1ucE8FEcnn2gWbr4bhUw3rTS/NDLwQ1273Wbu4K7KMUV306bwGDKLaY lfZ18BBqhAhbpyznuR4CmK+WBLqiRh+2vVRuDeS+YLJaOyTFs7+caJEhFFMY7h2zDH+h trWA== 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=NdOCB7l+a9Fkhq+3YE08wa4JUqn+lTJ2g/0reFXf5ctip2K6ARfCE9kHAMvIj5h0ws WpiBQ4PWBymoJmLwUj3mf7MwbH3uYMtYOod01Bn7EVnb1dUs5G106R48PLisGOqRyoxd r7WTOgfuhHTDmHjzlJ9gNysSA4pHv8F47GEthiOrJG3j+11xHJW0FILscaRoRuBJBCc+ P50s+l1iOUHLnKBzqj2djBeThC/ht/8EhrWx8KIbKrWt7QqEFUTL8DAJRdlhoO5WClT9 Ku15sLgsFFbsoBI+r7d6whT/il3QRaxcYeEh+NmQkgf/p4vX2kaoQt8o4fE3tuKViVVh 4kKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=qpRIrCNQ; 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 c3-20020a656743000000b0045abcc62064si10799719pgu.695.2022.10.09.16.40.13; Sun, 09 Oct 2022 16:40:24 -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=qpRIrCNQ; 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 S232130AbiJIW1s (ORCPT + 99 others); Sun, 9 Oct 2022 18:27:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42212 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231909AbiJIWZ4 (ORCPT ); Sun, 9 Oct 2022 18:25:56 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F178222AA; Sun, 9 Oct 2022 15:18:17 -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 ams.source.kernel.org (Postfix) with ESMTPS id C3694B80DF3; Sun, 9 Oct 2022 22:15:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 36105C433D7; Sun, 9 Oct 2022 22:15:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1665353743; bh=4I++Kn9fSoZUHIYC6BYNYv/X7IAgLUe/WFzrPJLmnbY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qpRIrCNQIp15xrprso+D6NeTNGZIDsVyzC9Lqd7irAHDh/qS699wAet03KMwk4HJV eBwErSp5zYpnFlLlhyLO8bWSqBmCs8PNXKYfZJACDz9k4YSkwLMGpBdQUWKZddTZPH Nn3XOvPqUuC69IaGM8wIpeLDasbh21BMdRh3ZBImoypXIBrOQXlFN078P+dkMxfZcj rK8DPkFLxNC6HKlibEJ1NKEcbMJG7FE6Q0ALgoEc+n7iCtca8as8HuhsHuxJmnBGUv TSwSKTeBvPTKHsCn0ntxMJwzyp+ySjocJS846P2iDpVK/CQlqWgTaWXZctzJKWwLhE DTYq9oy3ZdCeg== 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 5.19 10/73] net: dsa: all DSA masters must be down when changing the tagging protocol Date: Sun, 9 Oct 2022 18:13:48 -0400 Message-Id: <20221009221453.1216158-10-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221009221453.1216158-1-sashal@kernel.org> References: <20221009221453.1216158-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