From patchwork Sun May 3 22:12:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 220017 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.6 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, MENTIONS_GIT_HOSTING, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 99B6EC28CBC for ; Sun, 3 May 2020 22:12:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5BC2D206C0 for ; Sun, 3 May 2020 22:12:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="DVdIz2RX" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729151AbgECWMj (ORCPT ); Sun, 3 May 2020 18:12:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41858 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726825AbgECWMi (ORCPT ); Sun, 3 May 2020 18:12:38 -0400 Received: from mail-wm1-x344.google.com (mail-wm1-x344.google.com [IPv6:2a00:1450:4864:20::344]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 539EBC061A0E for ; Sun, 3 May 2020 15:12:38 -0700 (PDT) Received: by mail-wm1-x344.google.com with SMTP id 188so6242467wmc.2 for ; Sun, 03 May 2020 15:12:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=h1oqX0qcoFjTmmxWh5ubwYlhJBrdMiwB/36cUe6fTFQ=; b=DVdIz2RXx0BeKGBI4pc/Ajt30Qpv5RbSfQAE6L6UWzB4j4O5nFHqty5yaqZ3LKaxfs sFTnlx+EwiYCOMpsmIVs/adyqPMoL0UmKHneJ0TbPWGbii3vJeE8r24iPDRBDVJHk4mt WSuSXT5xJsrwTh/f8HuZp5HT2OL6nnOyqvfT5ruQe3iHZdl8I8C95UiGZMdJvfJFyFrY V01VGpG1TopL8jhWm9NY1Oo8A00E49nQqu99dTffqjBd/kdDXCoOsCszHrIFe26Ra6hs Z8IKYC8KjHAh259sd7FckIzuHQ3+VGzqgG6rQdHAQR7A/ATSdg28dLJotADoEryAnbYC 7x5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=h1oqX0qcoFjTmmxWh5ubwYlhJBrdMiwB/36cUe6fTFQ=; b=W/Z0eN3DGBYjLAJF0ps91+Kqehs77dLsjdvuMp/a6XD8VAEa19bSQv31HWtciogRI6 kUCf/POTVxXq3G9OXvI7yAX6zR6sDdNgTr6fpxCs2VuPrg11iOqZdVP6haKuNSZXnaxv AKpqAQGnBInl+B90H0jwm+AOW2joQtTTw2bBaVCe1g9zzdnuk3Oo6qHKVe5Xdxp6ghSq Cz9P07FJB/eUnixgbr1vzaoby/O7ZJdWNDFVP7NjKDAlQyeoFfbzli7SOq7auToqTYZn V6VizZ8myCAlyP7v2mg1h3FgE0xSHx5REFUaL8B4J7Nbrk7DekJTVWBSvTFtpBJIbOc2 XLqA== X-Gm-Message-State: AGi0Pub1cTghWL3wk1nl0EnX5VRGJR1Q1fqbZqmwm/rPs1dhrt8lhZQY HeSh31N2yL5CkBhSarqWBu4= X-Google-Smtp-Source: APiQypJTlHFMtLbW/Q1ze7Q0NVCczjZZG+otPmIlgLqkp5WXnd5hwPguCK2rdthkn1fxuWDbx6Pniw== X-Received: by 2002:a7b:c3ca:: with SMTP id t10mr10933640wmj.94.1588543956852; Sun, 03 May 2020 15:12:36 -0700 (PDT) Received: from localhost.localdomain ([86.121.118.29]) by smtp.gmail.com with ESMTPSA id q143sm10692188wme.31.2020.05.03.15.12.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 May 2020 15:12:36 -0700 (PDT) From: Vladimir Oltean To: andrew@lunn.ch, f.fainelli@gmail.com, vivien.didelot@gmail.com, davem@davemloft.net Cc: jiri@resnulli.us, idosch@idosch.org, kuba@kernel.org, netdev@vger.kernel.org, nikolay@cumulusnetworks.com, roopa@cumulusnetworks.com, mingkai.hu@nxp.com Subject: [PATCH v3 net-next 1/4] net: bridge: allow enslaving some DSA master network devices Date: Mon, 4 May 2020 01:12:25 +0300 Message-Id: <20200503221228.10928-2-olteanv@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200503221228.10928-1-olteanv@gmail.com> References: <20200503221228.10928-1-olteanv@gmail.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Vladimir Oltean Commit 8db0a2ee2c63 ("net: bridge: reject DSA-enabled master netdevices as bridge members") added a special check in br_if.c in order to check for a DSA master network device with a tagging protocol configured. This was done because back then, such devices, once enslaved in a bridge would become inoperative and would not pass DSA tagged traffic anymore due to br_handle_frame returning RX_HANDLER_CONSUMED. But right now we have valid use cases which do require bridging of DSA masters. One such example is when the DSA master ports are DSA switch ports themselves (in a disjoint tree setup). This should be completely equivalent, functionally speaking, from having multiple DSA switches hanging off of the ports of a switchdev driver. So we should allow the enslaving of DSA tagged master network devices. Instead of the regular br_handle_frame(), install a new function br_handle_frame_dummy() on these DSA masters, which returns RX_HANDLER_PASS in order to call into the DSA specific tagging protocol handlers, and lift the restriction from br_add_if. Suggested-by: Nikolay Aleksandrov Suggested-by: Florian Fainelli Signed-off-by: Vladimir Oltean Acked-by: Nikolay Aleksandrov --- Changes in v3: None. Changes in v2: * Removed the hotpath netdev_uses_dsa check and installed a dummy rx_handler for such net devices. * Improved the check of which DSA master net devices are able to be bridged and which aren't. * At this stage, the patch is different enough from where I took it from (aka https://github.com/ffainelli/linux/commit/75618cea75ada8d9eef7936c002b5ec3dd3e4eac) that I just added my authorship to it). include/net/dsa.h | 2 +- net/bridge/br_if.c | 32 +++++++++++++++++++++++--------- net/bridge/br_input.c | 23 ++++++++++++++++++++++- net/bridge/br_private.h | 6 +++--- 4 files changed, 49 insertions(+), 14 deletions(-) diff --git a/include/net/dsa.h b/include/net/dsa.h index fb3f9222f2a1..3c0ae84156c8 100644 --- a/include/net/dsa.h +++ b/include/net/dsa.h @@ -650,7 +650,7 @@ struct dsa_switch_driver { struct net_device *dsa_dev_to_net_device(struct device *dev); /* Keep inline for faster access in hot path */ -static inline bool netdev_uses_dsa(struct net_device *dev) +static inline bool netdev_uses_dsa(const struct net_device *dev) { #if IS_ENABLED(CONFIG_NET_DSA) return dev->dsa_ptr && dev->dsa_ptr->rcv; diff --git a/net/bridge/br_if.c b/net/bridge/br_if.c index ca685c0cdf95..a0e9a7937412 100644 --- a/net/bridge/br_if.c +++ b/net/bridge/br_if.c @@ -563,18 +563,32 @@ int br_add_if(struct net_bridge *br, struct net_device *dev, unsigned br_hr, dev_hr; bool changed_addr; - /* Don't allow bridging non-ethernet like devices, or DSA-enabled - * master network devices since the bridge layer rx_handler prevents - * the DSA fake ethertype handler to be invoked, so we do not strip off - * the DSA switch tag protocol header and the bridge layer just return - * RX_HANDLER_CONSUMED, stopping RX processing for these frames. - */ + /* Don't allow bridging non-ethernet like devices. */ if ((dev->flags & IFF_LOOPBACK) || dev->type != ARPHRD_ETHER || dev->addr_len != ETH_ALEN || - !is_valid_ether_addr(dev->dev_addr) || - netdev_uses_dsa(dev)) + !is_valid_ether_addr(dev->dev_addr)) return -EINVAL; + /* Also don't allow bridging of net devices that are DSA masters, since + * the bridge layer rx_handler prevents the DSA fake ethertype handler + * to be invoked, so we don't get the chance to strip off and parse the + * DSA switch tag protocol header (the bridge layer just returns + * RX_HANDLER_CONSUMED, stopping RX processing for these frames). + * The only case where that would not be an issue is when bridging can + * already be offloaded, such as when the DSA master is itself a DSA + * or plain switchdev port, and is bridged only with other ports from + * the same hardware device. + */ + if (netdev_uses_dsa(dev)) { + list_for_each_entry(p, &br->port_list, list) { + if (!netdev_port_same_parent_id(dev, p->dev)) { + NL_SET_ERR_MSG(extack, + "Cannot do software bridging with a DSA master"); + return -EINVAL; + } + } + } + /* No bridging of bridges */ if (dev->netdev_ops->ndo_start_xmit == br_dev_xmit) { NL_SET_ERR_MSG(extack, @@ -618,7 +632,7 @@ int br_add_if(struct net_bridge *br, struct net_device *dev, if (err) goto err3; - err = netdev_rx_handler_register(dev, br_handle_frame, p); + err = netdev_rx_handler_register(dev, br_get_rx_handler(dev), p); if (err) goto err4; diff --git a/net/bridge/br_input.c b/net/bridge/br_input.c index d5c34f36f0f4..59a318b9f646 100644 --- a/net/bridge/br_input.c +++ b/net/bridge/br_input.c @@ -17,6 +17,7 @@ #endif #include #include +#include #include #include #include "br_private.h" @@ -257,7 +258,7 @@ static int nf_hook_bridge_pre(struct sk_buff *skb, struct sk_buff **pskb) * Return NULL if skb is handled * note: already called with rcu_read_lock */ -rx_handler_result_t br_handle_frame(struct sk_buff **pskb) +static rx_handler_result_t br_handle_frame(struct sk_buff **pskb) { struct net_bridge_port *p; struct sk_buff *skb = *pskb; @@ -359,3 +360,23 @@ rx_handler_result_t br_handle_frame(struct sk_buff **pskb) } return RX_HANDLER_CONSUMED; } + +/* This function has no purpose other than to appease the br_port_get_rcu/rtnl + * helpers which identify bridged ports according to the rx_handler installed + * on them (so there _needs_ to be a bridge rx_handler even if we don't need it + * to do anything useful). This bridge won't support traffic to/from the stack, + * but only hardware bridging. So return RX_HANDLER_PASS so we don't steal + * frames from the ETH_P_XDSA packet_type handler. + */ +static rx_handler_result_t br_handle_frame_dummy(struct sk_buff **pskb) +{ + return RX_HANDLER_PASS; +} + +rx_handler_func_t *br_get_rx_handler(const struct net_device *dev) +{ + if (netdev_uses_dsa(dev)) + return br_handle_frame_dummy; + + return br_handle_frame; +} diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h index c35647cb138a..0defc2ff365f 100644 --- a/net/bridge/br_private.h +++ b/net/bridge/br_private.h @@ -705,16 +705,16 @@ int nbp_backup_change(struct net_bridge_port *p, struct net_device *backup_dev); /* br_input.c */ int br_handle_frame_finish(struct net *net, struct sock *sk, struct sk_buff *skb); -rx_handler_result_t br_handle_frame(struct sk_buff **pskb); +rx_handler_func_t *br_get_rx_handler(const struct net_device *dev); static inline bool br_rx_handler_check_rcu(const struct net_device *dev) { - return rcu_dereference(dev->rx_handler) == br_handle_frame; + return rcu_dereference(dev->rx_handler) == br_get_rx_handler(dev); } static inline bool br_rx_handler_check_rtnl(const struct net_device *dev) { - return rcu_dereference_rtnl(dev->rx_handler) == br_handle_frame; + return rcu_dereference_rtnl(dev->rx_handler) == br_get_rx_handler(dev); } static inline struct net_bridge_port *br_port_get_check_rcu(const struct net_device *dev) From patchwork Sun May 3 22:12:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 220015 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 37108C28CBC for ; Sun, 3 May 2020 22:12:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 101A2206C0 for ; Sun, 3 May 2020 22:12:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="JZt+C9Mg" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729186AbgECWMq (ORCPT ); Sun, 3 May 2020 18:12:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1729182AbgECWMo (ORCPT ); Sun, 3 May 2020 18:12:44 -0400 Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 81415C061A0E for ; Sun, 3 May 2020 15:12:44 -0700 (PDT) Received: by mail-wm1-x341.google.com with SMTP id v4so14155607wme.1 for ; Sun, 03 May 2020 15:12:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=PKWJfGIHtLWuN5jwDyBBGWfr52u7WQX+Z65ojM6uIqI=; b=JZt+C9MgXpQEy9pve090Wq4SPQ5IwwHMl+Z51LaAyB+uJAD4I2qGdMnmBJXENQHW1a KbF8EgQGSbutCAip01u0vlRRt4Kycb1PgDFqm503BzpAz1Dnk65fNPSAOoa0ksruVhK0 x6+Kw24f+aPaXpX7saIly6wlx1UHtxkohTEIdE4sTlmftSPaV2LcNypu96vdMa6Mma9Q Bqlp3vb41Sxbum1rDHM5Sff08BsqU9gaY0ZDXmzFSMrDtiVdXlZR0XtwWYFGp9oSw1Ix Zg84pKuzLrtCxl8LTtHh/ZxFgpVBcZEqoLXI2cpmVT4a4VQ+gcKVsWuykj2bm7wG4gxL MLKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=PKWJfGIHtLWuN5jwDyBBGWfr52u7WQX+Z65ojM6uIqI=; b=EBmJMmb8mzZwhqgHFF3qsDZKP09INAph58GDDyCl/UWUdEDj2ljks/om/6f5lhxz7y XK5cKWx/iC1JESgcwyQ+7mHuMgax1dYoav4QjPpp2e14zRAOTScuJBQ3cWNdM47wKbsJ g/kOn3vNOz8ZXp1psJRCtUgN9WnT6XgjO5jkLwyvOnf91d7bZeztYxcPmSf4ck9XllgL YJvTOuhwIYKj7yxeJGKlKs9ftgBerDFSIFx5vpAYMBpxm/8wJ681oGePXuBA0VkOLuq+ 8kHTGggUztu/J2nPwS5d3gLp1Tu6ISveLnXXzh5RTqSnbJUtOtXl8r9kdPwus1xEOhV0 hzkg== X-Gm-Message-State: AGi0PubgsYXllihTRGvlPbSyTgcXPxMjD3Kc8jE187cSz5Uo53hvAzzp 2/YWuH5VL4NcnsJDoPMs9Vo= X-Google-Smtp-Source: APiQypKGR1dT8P6B94ZZAz35EheOFEVec3XwVPI7xzGTrh5PeC5rkwkTeK+pecMJRt5lIGxZC7iJXA== X-Received: by 2002:a7b:c941:: with SMTP id i1mr10386715wml.132.1588543959175; Sun, 03 May 2020 15:12:39 -0700 (PDT) Received: from localhost.localdomain ([86.121.118.29]) by smtp.gmail.com with ESMTPSA id q143sm10692188wme.31.2020.05.03.15.12.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 May 2020 15:12:38 -0700 (PDT) From: Vladimir Oltean To: andrew@lunn.ch, f.fainelli@gmail.com, vivien.didelot@gmail.com, davem@davemloft.net Cc: jiri@resnulli.us, idosch@idosch.org, kuba@kernel.org, netdev@vger.kernel.org, nikolay@cumulusnetworks.com, roopa@cumulusnetworks.com, mingkai.hu@nxp.com Subject: [PATCH v3 net-next 3/4] net: dsa: introduce a dsa_switch_find function Date: Mon, 4 May 2020 01:12:27 +0300 Message-Id: <20200503221228.10928-4-olteanv@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200503221228.10928-1-olteanv@gmail.com> References: <20200503221228.10928-1-olteanv@gmail.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Vladimir Oltean Somewhat similar to dsa_tree_find, dsa_switch_find returns a dsa_switch structure pointer by searching for its tree index and switch index (the parameters from dsa,member). To be used, for example, by drivers who implement .crosschip_bridge_join and need a reference to the other switch indicated to by the tree_index and sw_index arguments. Signed-off-by: Vladimir Oltean --- Changes in v3: None. Changes in v2: None. include/net/dsa.h | 1 + net/dsa/dsa2.c | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/include/net/dsa.h b/include/net/dsa.h index bd5561dacb13..c5e2530f54c9 100644 --- a/include/net/dsa.h +++ b/include/net/dsa.h @@ -671,6 +671,7 @@ static inline bool dsa_can_decode(const struct sk_buff *skb, void dsa_unregister_switch(struct dsa_switch *ds); int dsa_register_switch(struct dsa_switch *ds); +struct dsa_switch *dsa_switch_find(int tree_index, int sw_index); #ifdef CONFIG_PM_SLEEP int dsa_switch_suspend(struct dsa_switch *ds); int dsa_switch_resume(struct dsa_switch *ds); diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c index 9a271a58a41d..07e01b195975 100644 --- a/net/dsa/dsa2.c +++ b/net/dsa/dsa2.c @@ -24,6 +24,27 @@ LIST_HEAD(dsa_tree_list); static const struct devlink_ops dsa_devlink_ops = { }; +struct dsa_switch *dsa_switch_find(int tree_index, int sw_index) +{ + struct dsa_switch_tree *dst; + struct dsa_port *dp; + + list_for_each_entry(dst, &dsa_tree_list, list) { + if (dst->index != tree_index) + continue; + + list_for_each_entry(dp, &dst->ports, list) { + if (dp->ds->index != sw_index) + continue; + + return dp->ds; + } + } + + return NULL; +} +EXPORT_SYMBOL_GPL(dsa_switch_find); + static struct dsa_switch_tree *dsa_tree_find(int index) { struct dsa_switch_tree *dst;