From patchwork Fri Aug 19 17:48:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 12949051 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6842DC32772 for ; Fri, 19 Aug 2022 18:02:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350083AbiHSSCi (ORCPT ); Fri, 19 Aug 2022 14:02:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52136 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350078AbiHSSCI (ORCPT ); Fri, 19 Aug 2022 14:02:08 -0400 Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-eopbgr80059.outbound.protection.outlook.com [40.107.8.59]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5054661104 for ; Fri, 19 Aug 2022 10:48:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UfZ2j91S4RvGrc4o81v9CpAUWGpY5rnV0KTVH37fR5H40jfVziNL7I4RUNlsojaFiFuN0FtDgIYD1c/UN5PqwSa+GlZsqHHEuJjZ0pBIuv4fKMIfR7yb2E5L5vVmyXP5DZ7L4w9zbs9ot+IqwP0zz/CjQkddFUGg05N9esx/QWIcALoLhd/HHmh4s6KuFBDUmcuVNtVTW9P6LGDQILtomTm4tbhFGAhKySujm6F4YyrHe9MJZU7ewlDBedLFDRSqsdAk9astciWJbi3yIXoTkMzGxGCb6NQ3RPvbDuiZRYK33QEezxJhf7S58qb2/qXn8wmIDc9berXs751g3xs6Uw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=c05nCBatA6p8JbJ2xNUWh+NBPqn32UhSKRjurn5BHOE=; b=A0CLSF6Cam2Wa44ieRmT4s/ZHXmEt4sPHnxSnH0suiAfFUSfeozpp7KCzZ6tkwsGwVoQ7rJCeEuwhiJv/iSihVX2ygHWRpXioZOVXWdfZYmu0NmM87x5CuFfuGwqLPwUdZkFg6TePifNeWer0MC3wwa2iXDcLxQ6/WbDhvpb3uKKARfTzDz1gnxw2ArIvCj6SWg0eh9f0zHRtViZGLogfbLAsTBRKf/5F7kFFdXfubjIRpzkdlTjuWXYvfdXNunP3JOzpmEDfSJPXRMmmZ6QR/qkg7hFH2LWqSBd6S3R00uUSUZHBpuq8VDllCtR88ywiNjPcYShVuprYx41O0RKHg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=c05nCBatA6p8JbJ2xNUWh+NBPqn32UhSKRjurn5BHOE=; b=phDnKynKIsocrQJVgKClWkIe3vHg3cGEk3OshvAZx+qic16UYozZpz77nQNbdj8u2ff110IDPg0IUhi8CbdhlrHGrC7VhdqOPyDUl29SsSytwWXvR6odyXAre5MMR64yzkMD5uhYZ0lcj8MAGjSrhbDyGozrm+/by4HwWdmOn1I= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) by DU2PR04MB8551.eurprd04.prod.outlook.com (2603:10a6:10:2d6::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5546.18; Fri, 19 Aug 2022 17:48:34 +0000 Received: from VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::71b7:8ed1:e4e0:3857]) by VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::71b7:8ed1:e4e0:3857%4]) with mapi id 15.20.5546.016; Fri, 19 Aug 2022 17:48:34 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org Cc: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Florian Fainelli , Vivien Didelot , Andrew Lunn , Vladimir Oltean , Claudiu Manoil , Alexandre Belloni , UNGLinuxDriver@microchip.com, Colin Foster , Roopa Prabhu , Nikolay Aleksandrov Subject: [PATCH v3 net-next 3/9] net: bridge: move DSA master bridging restriction to DSA Date: Fri, 19 Aug 2022 20:48:14 +0300 Message-Id: <20220819174820.3585002-4-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220819174820.3585002-1-vladimir.oltean@nxp.com> References: <20220819174820.3585002-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: AM4PR0501CA0044.eurprd05.prod.outlook.com (2603:10a6:200:68::12) To VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 3b0ad3b3-6668-4898-3427-08da820b09a4 X-MS-TrafficTypeDiagnostic: DU2PR04MB8551:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 4iTxDIzc6argDsCySURA0eumYCVieRp3LbeT/TKFH9wkOdEMSO4Ibzp56IF+iqOpGzpmabAmi36Gm+kSRegWJPFX8+TUct0K/3jsATlDTE+KN1jVcOWhrV9e8Dnj+OHFOf++plC4mCiqCSRgp+ZX9Ft0tseN4MyvJH9AfKixSgy0CpB2k6AI7aRO8owsr4uLeiJ7kNbGmk7oWC1WRNsvuoYN9xHpiT3kXlG2Upirrxa/HR4f32pnjcT3EyMUXkAUg/n8OaPZgSbRWa+hyJt0rJn8tVFPkpNStjgL3KDMTeOFqUStIgG/h35IBjm9i6E9m9wnxLxhesHH5yve3CeQCAFhgOX75nMgWov8Kfhr3RRScvFlfe50tmALrO/3jFJ+JHF2UuCFuIW8YNSt7FbENyeS3N/gsLxUa+iylZcbD1UAzLjlDt//XrRXblS6US440JMSFbtThAPq9gNpVVn9zYHFSBuHblFL2pn0ICykUFwI7K6b4XhwA934iSqsuCu3ff774T3v+BkE8hjNRecW1Dnj+5Ochpr5mCuahuDlgfwkN74E/dAwULAjGwH7rjw3y+BQMLzdoKDKINLdjDfPOVo68w/agO8W0QHgRwga0j5XcTgFUyG4jxxu1QLpMzppHzIumzPS1EZorOib3eHjcXnP34URjxzqBYXNk0ApjJWCNvUirWLv2TaRg809jgzFho5moFTgm4yHNxjBTbcGgO8jbP7hJDA6JpMakZMpWWxWqDbYhwVCMqNeXFbOLOlLkdQ+T9VD61bIoXHEkP75RA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR04MB5136.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230016)(4636009)(136003)(376002)(396003)(346002)(39860400002)(366004)(66556008)(8676002)(4326008)(7416002)(44832011)(66946007)(66476007)(316002)(6916009)(54906003)(5660300002)(36756003)(8936002)(2906002)(478600001)(6486002)(41300700001)(6506007)(6666004)(26005)(52116002)(6512007)(2616005)(86362001)(83380400001)(1076003)(38350700002)(38100700002)(186003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 0P7oG3kupAkiX+SrJpvQY0D3d/FXM1+q58FkCpIWaoYxv9K5lqQKuVm6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aDm7Yx+TcW2z6d/uQv/MX9V6qre/uTAoqHc1lakeDT4qetOB9iiGsZ04uc740sFNg46OYAEHMZw/A2PInd9srPyMiie4rhHutgGjHbpD9ZgawInVntwO6SNlkg4Wwz34Slg/X+v7ZKnKhH7Az8T4srm8z2EUpycmG/2fbA6EK9nqe0+SXBhJIEKkv/duztbq1jaq2PmvI55mct7J2DLZxZp/L6M7rR7CeFsBVjQDQclpsMIXXodUXs2ddddKN2IQvUmbre+ep1T64Sesjbrpic1pGyqJNGyHpEPNETxPFBdm+kf+DXxapNhlhfNX/Ve8jfbaoPYBgUvVbmCcucZiTlTqE263glaIrRO9ig+schOwK7lV9FYotZC4+b7PlhigWcy8G90yipNGnuLfwVSynE9MvhX9a2ZQdTr8+waFlnAmt5Eb2h/o38KsJquOxp0Fl2TdjSzm5DjOmvNTMmPSZn/KQ== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3b0ad3b3-6668-4898-3427-08da820b09a4 X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Aug 2022 17:48:34.6853 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: QYwVswIOI1U7UplB69WZC7Q1InONmWURJLrDHPX0dDAn8MpjDNtqgTfroEh6uMq3l2wVCeOJiu0XWVic5xZ/lA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU2PR04MB8551 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org When DSA gains support for multiple CPU ports in a LAG, it will become mandatory to monitor the changeupper events for the DSA master. In fact, there are already some restrictions to be imposed in that area, namely that a DSA master cannot be a bridge port except in some special circumstances. Centralize the restrictions at the level of the DSA layer as a preliminary step. Signed-off-by: Vladimir Oltean Reviewed-by: Florian Fainelli Acked-by: Nikolay Aleksandrov --- v1->v3: none net/bridge/br_if.c | 20 -------------------- net/dsa/slave.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 20 deletions(-) diff --git a/net/bridge/br_if.c b/net/bridge/br_if.c index a84a7cfb9d6d..efbd93e92ce2 100644 --- a/net/bridge/br_if.c +++ b/net/bridge/br_if.c @@ -568,26 +568,6 @@ int br_add_if(struct net_bridge *br, struct net_device *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, diff --git a/net/dsa/slave.c b/net/dsa/slave.c index 008bbe1c0285..09767f4b3b37 100644 --- a/net/dsa/slave.c +++ b/net/dsa/slave.c @@ -2699,6 +2699,46 @@ dsa_slave_prechangeupper_sanity_check(struct net_device *dev, return NOTIFY_DONE; } +/* Don't allow bridging of 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. + */ +static int +dsa_bridge_prechangelower_sanity_check(struct net_device *new_lower, + struct netdev_notifier_changeupper_info *info) +{ + struct net_device *br = info->upper_dev; + struct netlink_ext_ack *extack; + struct net_device *lower; + struct list_head *iter; + + if (!netif_is_bridge_master(br)) + return NOTIFY_DONE; + + if (!info->linking) + return NOTIFY_DONE; + + extack = netdev_notifier_info_to_extack(&info->info); + + netdev_for_each_lower_dev(br, lower, iter) { + if (!netdev_uses_dsa(new_lower) && !netdev_uses_dsa(lower)) + continue; + + if (!netdev_port_same_parent_id(lower, new_lower)) { + NL_SET_ERR_MSG(extack, + "Cannot do software bridging with a DSA master"); + return notifier_from_errno(-EINVAL); + } + } + + return NOTIFY_DONE; +} + static int dsa_slave_netdevice_event(struct notifier_block *nb, unsigned long event, void *ptr) { @@ -2713,6 +2753,10 @@ static int dsa_slave_netdevice_event(struct notifier_block *nb, if (notifier_to_errno(err)) return err; + err = dsa_bridge_prechangelower_sanity_check(dev, info); + if (notifier_to_errno(err)) + return err; + err = dsa_slave_prechangeupper(dev, ptr); if (notifier_to_errno(err)) return err;