From patchwork Sun May 10 16:37:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 219526 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 A2374C38A2A for ; Sun, 10 May 2020 16:37:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7CFC62080C for ; Sun, 10 May 2020 16:37:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="eNJpAdj6" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728763AbgEJQh5 (ORCPT ); Sun, 10 May 2020 12:37:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726744AbgEJQh4 (ORCPT ); Sun, 10 May 2020 12:37:56 -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 3283AC061A0C for ; Sun, 10 May 2020 09:37:56 -0700 (PDT) Received: by mail-wm1-x341.google.com with SMTP id d207so2077624wmd.0 for ; Sun, 10 May 2020 09:37:56 -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=FTKK5OA7qs4HOdp07djytE2Mt4WGiNEy6O2g2e/5gw0=; b=eNJpAdj6JfJCxjQ6dQZA7lNi3RmB0BA0og/W+gM0ye4XHQve654/3XqpQFIB7H9NPk k5p5GkUhEqMqbkOFnN08CA22xj57+vY9eE73PZTCvTuFFJBetfPLdPXYmbknx9ZR9GUF 0cQRBBhYavgBjeynnym49s3UjA50ISNXqzQQAS8DYn+mjS04cGUvkoX5icW8qCh7/xXc 88gvy4Ats/0ZJWVP/l/s9oTmNhJwL8n+7uTwPTFAKRYHLLxk77N53NVF3hgulnG0YVws I8Ra8N9G7gWoR8UAxZXXB640IG7OU8RhdmwJ3EDIDeUF7NOk+eq+P2upOMuUDeYUiAle 37qw== 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=FTKK5OA7qs4HOdp07djytE2Mt4WGiNEy6O2g2e/5gw0=; b=B1lCNMhd44r2Guc4UjTRh8XCV/YBI5/3ujUz9ki3g+nBgZnwNItu6oyiw/nm0UJZHx 7Fv8gLPfwtuH4mpvK9xuOHcBoy3ZL8OCSA9y6IDw2eLTWRZA5+LGJrClAw3ufSE+G0Vd nipuq1z94tkJeFnVPJPDE8BYi/waQfLt6mzHQgQh/T4MRnpstTttmEz0AoZf+VO/qgLj +JBNjx7s3jMNnufwMr/hHL+tWBNYrZf4p2TSp4gflhfqEum4OeOed7nHFmO5ghDiPr5i uAJ9Je0Zd4M4E3tetqTH+4Fg8GfTFjg6nCanz+XYLtbirPVdOGz4uo0d0Y0pDxNevSBH Hc2Q== X-Gm-Message-State: AGi0PuYoacUeib+4nWo3z+kz0lWO40OfSrnMY/w6hsgr+tFqhN5KpEqS J21jnZqT+l3OJcnCPpWGDqs= X-Google-Smtp-Source: APiQypLCjKrBjFHn7Ci8sVtI2WO8+g6iX/eta6wRlNpSJI4OuoCdFj6/xRSSsY+CgNvqmOq5Jbq2GA== X-Received: by 2002:a05:600c:296:: with SMTP id 22mr23335699wmk.98.1589128674882; Sun, 10 May 2020 09:37:54 -0700 (PDT) Received: from localhost.localdomain ([86.121.118.29]) by smtp.gmail.com with ESMTPSA id d133sm25472394wmc.27.2020.05.10.09.37.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 May 2020 09:37:54 -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 Subject: [PATCH v4 resend net-next 1/4] net: bridge: allow enslaving some DSA master network devices Date: Sun, 10 May 2020 19:37:40 +0300 Message-Id: <20200510163743.18032-2-olteanv@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200510163743.18032-1-olteanv@gmail.com> References: <20200510163743.18032-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 Reviewed-by: Florian Fainelli Tested-by: Florian Fainelli --- Changes in v4: None. 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 6dfc8c2f68b8..02fb5025e0ac 100644 --- a/include/net/dsa.h +++ b/include/net/dsa.h @@ -651,7 +651,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 4dc21e8f7e33..7501be4eeba0 100644 --- a/net/bridge/br_private.h +++ b/net/bridge/br_private.h @@ -702,16 +702,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 10 16:37:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 219525 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 A1540C54E8C for ; Sun, 10 May 2020 16:38:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 773A520820 for ; Sun, 10 May 2020 16:38:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fAnKRTno" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728762AbgEJQh7 (ORCPT ); Sun, 10 May 2020 12:37:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1728892AbgEJQh6 (ORCPT ); Sun, 10 May 2020 12:37:58 -0400 Received: from mail-wm1-x343.google.com (mail-wm1-x343.google.com [IPv6:2a00:1450:4864:20::343]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6DD4AC061A0C for ; Sun, 10 May 2020 09:37:58 -0700 (PDT) Received: by mail-wm1-x343.google.com with SMTP id e26so15397404wmk.5 for ; Sun, 10 May 2020 09:37:58 -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=rH53CFBSBWJ7e00gOYK8G86J64m2HwFSCMB/ra3QTk8=; b=fAnKRTnobUWtBMyDeaV7BFsAA2vj0QZexf83iASvfKBaLQgDAk1TaAEfDktl+M6BpQ XjCqpVTF2A/LJjG2K8w3ig4/y2lezbDsYkQyGDlcnxW8wJFgwy9iblwuUsLxRKW2eKJj QQD0x3iA5Gws/sxDDtqOi7cXIr4RL5nEZHQbUc47AuZ3h4Ftk0IhJE6p6Fq0sKSa2pBs wBG5v1oab1xKZO8ZQwgKx2xHRUiLbMbWCychKAWRfBc5Cad3Gp/G2Nishove9I9KbbWs LYKRilsai97YVwFsINYos5cqbSvj1BAUonOGliARZdoqwr5mG2CstqBv8kYeYDCa8HYa oPUg== 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=rH53CFBSBWJ7e00gOYK8G86J64m2HwFSCMB/ra3QTk8=; b=kKzhk1Pvzil/tpRqph1eoodGgrhtZA/P7BpnvTkR79QvV4H2qmYNJvjJ3Bjlz0H1p0 pmHU6IW3qt0SDz4LnkZFC5yO0JNzEgVbDzcFZ4W9T9qD0J/T3VEvGMqsEvf0VsZ4IXi1 alnPQPMfY9IhT6ZFYRHkGxaaTf5+4ixyYrYUoMm1SeGCkVR/oUEQ9uLGQ+QoeNVp0D0X QloujNjPKkTD5ARxN0z3FPDTxdxgfguvcpIhsoduIMhZ4XEpneXnKgEBnMHz3UsYuHN4 CIyDaD0MKUv1mW/fj5LkAdY0do86XMZjdVNBwaPul6QgTRZG+wXeuMLeID5usHoqF6E8 w5Iw== X-Gm-Message-State: AGi0Publ0mTSiOkHbnu6hxsqzJKwZ0dzA2kVebkJf0aQTLwhvG/pq29J ymqCJ0x+I5+G6h+pguAVXWI= X-Google-Smtp-Source: APiQypKT1Xbmy2RL2M7YZSfBEkbtnDPNMwuCgTACxPeFSOdiEF/q7KAX6FuYfvDa0L07PpISV0lIVg== X-Received: by 2002:a1c:a793:: with SMTP id q141mr5872471wme.135.1589128677236; Sun, 10 May 2020 09:37:57 -0700 (PDT) Received: from localhost.localdomain ([86.121.118.29]) by smtp.gmail.com with ESMTPSA id d133sm25472394wmc.27.2020.05.10.09.37.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 May 2020 09:37:56 -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 Subject: [PATCH v4 resend net-next 3/4] net: dsa: introduce a dsa_switch_find function Date: Sun, 10 May 2020 19:37:42 +0300 Message-Id: <20200510163743.18032-4-olteanv@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200510163743.18032-1-olteanv@gmail.com> References: <20200510163743.18032-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 Reviewed-by: Florian Fainelli --- Changes in v4: None. 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 0f4fc00239d9..312c2f067e65 100644 --- a/include/net/dsa.h +++ b/include/net/dsa.h @@ -672,6 +672,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 d90665b465b8..076908fdd29b 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;