From patchwork Mon Jul 19 13:51:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 480318 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=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER, 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 307A0C636C9 for ; Mon, 19 Jul 2021 13:53:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0F0AA61166 for ; Mon, 19 Jul 2021 13:53:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240999AbhGSNMy (ORCPT ); Mon, 19 Jul 2021 09:12:54 -0400 Received: from mail-eopbgr40062.outbound.protection.outlook.com ([40.107.4.62]:65094 "EHLO EUR03-DB5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S240761AbhGSNMB (ORCPT ); Mon, 19 Jul 2021 09:12:01 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BjsW5fmcPpcOidVqkFq4Sk5Wjr2LCf+jHM21Hv8taUhV75RGr+EsbLdV0D+pN0W20wE6K2XYfLm1XvNjDIE9ccJFto5E8GXqUZeL8amUWuKcXFkHZ1K+nhyGDvo1o0eIvDBwILdOVPjzxXA0fYBnGZORwchQeJZiDZeyZHKeiabmsY6ZS+h1hUTiFSaecCKX2fbMrixbOSSRbJfq86wx89VZp+0UI+FimfRxeYYWYCuJ79x7/Did/OKRA8ebGTdJVidyBXbEVOit6zgtGml0HqJIv9M8xg0U2U5EWZRDQdosBu5EDh4eWiJkMj1F3SAWhw5J1TWQWv6jO3oQ1Q/7/w== 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-SenderADCheck; bh=5mcWNza9gQmSxGt3bwRx61Kopd5OlGB2WGW5uMng2ew=; b=ISkWFCVctNFBopAGCgPFQj8BHqpHVGH19D4FX9Smb6FlkQklqCFCJHL+742Bbf5UJpCzsX6fM62z9eTZgbayabWHECSr755DaLHkLL6SUyRgPLdIplP2k3dGkzj7QTnMVDVOiSdGiXEOKaWCTQRE7/5IpopN3T5tWdDqBSWoh/Iv9sgI2nc1yBpkRSL0BMUDPOC3kYSBm2uZEztBd5ccOvS08Hd5aiH4bbWMbxUR6q33p8tUHZWVBS+nhbAporBu3dc2qs2oZjTcKwZP0Igx0E/or5PC1abi5Am58v4Rf/k2tLHQb5/pOuLL8FQ96xayv2pjZfLozR+sRRhfekD/VQ== 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=5mcWNza9gQmSxGt3bwRx61Kopd5OlGB2WGW5uMng2ew=; b=LAKmOlKypKvDRfZ6POm7X6LhpOgvXYVrHEXuUjMdu2s8PqlC1roe5rJdfZ6lQsLhdJDv+qwCQIWro8qIcWcTjHzGR1/RJrg9nQ3NEsMCf2mpMGIP2JxSFOkrq9oQomjkX8Z/KZi07e5cta41R2WXuEhnt7z1MiNdH5FT7QGgd2c= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none; vger.kernel.org; dmarc=none action=none header.from=nxp.com; Received: from VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) by VE1PR04MB7471.eurprd04.prod.outlook.com (2603:10a6:800:1a7::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4331.23; Mon, 19 Jul 2021 13:52:00 +0000 Received: from VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::109:1995:3e6b:5bd0]) by VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::109:1995:3e6b:5bd0%2]) with mapi id 15.20.4331.032; Mon, 19 Jul 2021 13:52:00 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org, Jakub Kicinski , "David S. Miller" Cc: Andrew Lunn , Florian Fainelli , Vivien Didelot , Jiri Pirko , Ido Schimmel , Tobias Waldekranz , Roopa Prabhu , Nikolay Aleksandrov , Stephen Hemminger , bridge@lists.linux-foundation.org, DENG Qingfang Subject: [PATCH net-next 1/3] net: switchdev: introduce helper for checking dynamically learned FDB entries Date: Mon, 19 Jul 2021 16:51:38 +0300 Message-Id: <20210719135140.278938-2-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210719135140.278938-1-vladimir.oltean@nxp.com> References: <20210719135140.278938-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: PAYP264CA0013.FRAP264.PROD.OUTLOOK.COM (2603:10a6:102:11e::18) To VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (82.76.66.29) by PAYP264CA0013.FRAP264.PROD.OUTLOOK.COM (2603:10a6:102:11e::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4331.21 via Frontend Transport; Mon, 19 Jul 2021 13:51:59 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: af336278-e453-44b3-8d9d-08d94abc61d4 X-MS-TrafficTypeDiagnostic: VE1PR04MB7471: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5516; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: tmjyRX2xOdcCIvzLVtWVsXUI/xxJIBGwYICrHH7WafYVMEtU7Kik8sIpYfHgH07AiK0R1NBYC+ogMSFfAKq5wmAGDFnT+WzSiMBb0aftorgRfVVPmBMXdUwqo2puoOAYpRYdIQbmwM6y0Ubj0FyrLceK162uP2eAkCSiosjfzGPN3toBqtpsd6J2i4aLp71b71EjgHLADYID5G5S0t/oP799HCbl/PbYZvBmPdNaGHh978wKL4QZ5vH4IioINswsOnL6x0H6R6NSxuwvwq+4ivYJibnviAtlnWY8vXMaqutz78eIMYVhzCgA7SX5uYQiWNniTJCzRr0FAMDrbntA1RuF0Wi5Op/NW2D0UQ+AMWL6ANLPwZEz6zqG1lttJ9Xblx3h8JmI+xdh92Mn53lWD76NY3Gwh54gp2jc1wZEAz9XxXrxEteK2Q0ND9IRFz/szddg+MNy2Mj9JmAfjbeDy6V1542wmzYVBgvzF4pb6N4r2J/wleqSTbr8VGWGdwlZfx4Zy3Y1uawChr8otUh408o2XnuWtEAWOfZGUdeth9xTHPZ0EaJWunZz8ijoM1aovxRG3nN11BKxYIt6zWt7YVcWKF4eQLH1mKIhQnPUK2br6Zs/7znld7uGOj/YYP/bdedZNTaZ9nE47168cm5RCsXs0Hwp7lAOv+xKinTIJOFgkOBeV80YRBcsY0FePDh+xvBi3Jw6RGkuNgKdUhHV3w== 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:(4636009)(396003)(366004)(39860400002)(346002)(376002)(136003)(6506007)(8676002)(7416002)(1076003)(44832011)(5660300002)(52116002)(110136005)(316002)(54906003)(8936002)(6486002)(66556008)(6666004)(4326008)(6512007)(36756003)(478600001)(83380400001)(186003)(86362001)(2906002)(38100700002)(66476007)(26005)(66946007)(956004)(2616005)(38350700002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: cG1D0D6rcqxEjqE6qEYVaycWrL6bH+Lhzp7yiOKxAk7GQgiEzuLryAAUyOErE5MNQKDxzo8hZTaayWND+crIeO9qkx5zCmCOIeFWZI4fSaDpdvElTMetjVT+lQsZ6lrV18/tWWxCqiEfG8J3vOtrYgl6mBOZpl6+bVukaOmeTLA5FGqz+H1JzlctegxL2qtzd11qQWlZJSS5V3CXoCc7OOd6Owf5rMXPXV49jBbYG5sqUhYbckUqSbYXv82agEV56bb/RIZEOvBtLH/Q7qQISg6RW2F1IS6VNmZiQljHdXm6GDbCdGCmL5SRLGQpf8P+DH0K0wh5VOdvkQ88M+30Eim8hvN7+Mz/gfV7rJ+GYuNCs53ChsHiUCawvmwbaQng5dliloLiYeR/eF91hJjcASPZ1w3xsGB8axQMIJdx7eV/Egnd+MFEykpUqHKJy039QbWPtJf3HTdgfZoUWxFpwfdDqU2XM1AdYnNfEX0AiV1X8BpJmXJOSBr56RCpZ0GSvqE2zkpriIT1/uQD4vChdRVmzpnSks1btXk1YoT58e2DDiMFN4z9vxiotsZCiCyxRByFtFwgDx1xe0yoCaBab0lcsvZqs+aI7653pq/IZqP/a6ZaFnSZ324Csei/jQUPo2A5APyPmVu7gk2EyWJ9dK1/RGe9hx14/31kmIMYbfsENjntOzlabIjyZcty//T7DCEk5UMqnHskkQpFEKW5/kroRZmNWnAinsVwogsKXiLfEZ+7/kLZmtMQPooNB7itaVcWS3AwkmUjoKilGuvnNqTJ0UkUkxPOPgiyc7Ctpz1UhWSAhJek7yQn82XkuYJDJbuAnPA4DFYY5zjrQW3q2g7nI8skGWYl3Gi1b4+KiwghQ74dyx5n83Juu0WycATZMRfYWyKsVqThmwGa3M81ZZ4+wFGJpyusRbAasJoKMAjKSGxSoR5CRepSEdPmGs/uBshHNW6yh0a1mYV1XtNR9mln/JL+QGMJTZGTWeeSypHsRYHniRcTk/70Vrtda3RHYp1YETbeMq8GlX9iTiVwImECQh5KVSw01LrD6+7bCOump9wJn4a/Ufyo7lz8vpkuE6C25qrurdlAbnroTvJlykpVw1PHaOTZK0lVG8pMpmdAGm4GmsxwHAqJ58A7IEwGAujjUmuQjw8ObQvlbgcHkYCisiYDW3pnoPxdG2w7O2s2XDUJf5reDxVATRAGk/W4LDfpkvjbpay2t+ep9FaxVtHpiR6UOYgO7xMlwggFep7Oz5/nNoJFSZKE5/0LFjckx3DuV5FoR7htkLXzfDw+n9NPOGk5OD0Sieo5v0a0unpnjMqCGOyx38QXCkE7rizU X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: af336278-e453-44b3-8d9d-08d94abc61d4 X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jul 2021 13:52:00.7821 (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: qu7zo4yhKFq99p6zX5xttqCn6ENHPiZm4duSiUEP7ggmeLT1Vxm6zce6ulFdATvf+9LAc6dSRCSVEDHznLaUOw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR04MB7471 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org It is a bit difficult to understand what DSA checks when it tries to avoid installing dynamically learned addresses on foreign interfaces as local host addresses, so create a generic switchdev helper that can be reused and is generally more readable. Signed-off-by: Vladimir Oltean --- include/net/switchdev.h | 6 ++++++ net/dsa/slave.c | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/include/net/switchdev.h b/include/net/switchdev.h index e4cac9218ce1..745eb25fb8c4 100644 --- a/include/net/switchdev.h +++ b/include/net/switchdev.h @@ -238,6 +238,12 @@ switchdev_notifier_info_to_extack(const struct switchdev_notifier_info *info) return info->extack; } +static inline bool +switchdev_fdb_is_dynamically_learned(const struct switchdev_notifier_fdb_info *fdb_info) +{ + return !fdb_info->added_by_user && !fdb_info->is_local; +} + #ifdef CONFIG_NET_SWITCHDEV void switchdev_deferred_process(void); diff --git a/net/dsa/slave.c b/net/dsa/slave.c index ffbba1e71551..feb64f58faed 100644 --- a/net/dsa/slave.c +++ b/net/dsa/slave.c @@ -2438,7 +2438,7 @@ static int dsa_slave_switchdev_event(struct notifier_block *unused, * On the other hand, FDB entries for local termination * should always be installed. */ - if (!fdb_info->added_by_user && !fdb_info->is_local && + if (switchdev_fdb_is_dynamically_learned(fdb_info) && !dp->ds->assisted_learning_on_cpu_port) return NOTIFY_DONE; From patchwork Mon Jul 19 13:51:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 480317 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=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER, 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 64466C6377C for ; Mon, 19 Jul 2021 13:53:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5253C610A5 for ; Mon, 19 Jul 2021 13:53:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241024AbhGSNM6 (ORCPT ); Mon, 19 Jul 2021 09:12:58 -0400 Received: from mail-eopbgr40062.outbound.protection.outlook.com ([40.107.4.62]:65094 "EHLO EUR03-DB5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S240772AbhGSNMZ (ORCPT ); Mon, 19 Jul 2021 09:12:25 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mGAJGX//d6feJMUyYcnwbS8g52+264YWv26js71lJw+niq0KU50pjnkHgOw8YyzQt+i2f+dKP0J9MfZtYna86adHC+Wc0tyaC3uZJF5vbZ9MYv0oifcmdLXmnLjN/11HUEvCNZD+Jo6EBC0Fhg4c9shYqjeO0VA/j3kx4qjXFelGG81k54193xIvM+/AXFHmcovQhUzNgVPy6FlFvn/aDrcYah3SfGIuET+bN2BiuuuL7yhT0/xeDZUyT9EE9s6gdDN+tWgu7enIzQylbvG5fW223mbTeoT6kI7f9MaOnaeae52Kn2EANRQbfRcD7b1XR7NhpfTZPsg73XxlX25daQ== 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-SenderADCheck; bh=XLMbPaoN3FMzym7hsZyiIWH3QIQDCDi4v1MvQHkMpNU=; b=aR+SPyzdO5l156rUj7ZhnvQbpuG+K4EL525U22VK5BzPc0ANu9mbdwd6W+qyMu6XiSL9NeeE/9XSrmLlukS5yRtrNGs6rruqXgbEpHp5U41PvdM4B1k1IUjlKx9sW8nOho7HSXSYurJaBlh5nnezFHlwOHp5XIpmomaiivjuV/CUYncQpSwMpK+It+iyPfB9ucawuhM9TQVtvMVO9pA4vNgTsgAt2uDtQ4ORzugncx+hHCWMb6OXfSS6ASK18p8fDHx0/yySsSBvyK1KAvlgVm+9bLbgmCiTka0Tg3Jj8w+yotbvDouQstlb7tAB89jHnezUC01USLhdv/g+4YZmXg== 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=XLMbPaoN3FMzym7hsZyiIWH3QIQDCDi4v1MvQHkMpNU=; b=drbKA5HPplGiRW4dHtAxZS8RVBKYSeDOW8zsrtBrSbPEE0k7OME1ZCjt2YiyGqjTi9x57/V4E8TnFvc9FQxJMyS32QwgBTSSoxzS2nBO8Z6z5ZFwMUPOcRj+mqxdv+Jtnve4L0PluHOdpGtty5iEXdCMIr4ISh1V5fj9uVME8xA= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none; vger.kernel.org; dmarc=none action=none header.from=nxp.com; Received: from VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) by VE1PR04MB7471.eurprd04.prod.outlook.com (2603:10a6:800:1a7::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4331.23; Mon, 19 Jul 2021 13:52:02 +0000 Received: from VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::109:1995:3e6b:5bd0]) by VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::109:1995:3e6b:5bd0%2]) with mapi id 15.20.4331.032; Mon, 19 Jul 2021 13:52:02 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org, Jakub Kicinski , "David S. Miller" Cc: Andrew Lunn , Florian Fainelli , Vivien Didelot , Jiri Pirko , Ido Schimmel , Tobias Waldekranz , Roopa Prabhu , Nikolay Aleksandrov , Stephen Hemminger , bridge@lists.linux-foundation.org, DENG Qingfang Subject: [PATCH net-next 2/3] net: switchdev: introduce a fanout helper for SWITCHDEV_FDB_{ADD, DEL}_TO_DEVICE Date: Mon, 19 Jul 2021 16:51:39 +0300 Message-Id: <20210719135140.278938-3-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210719135140.278938-1-vladimir.oltean@nxp.com> References: <20210719135140.278938-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: PAYP264CA0013.FRAP264.PROD.OUTLOOK.COM (2603:10a6:102:11e::18) To VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (82.76.66.29) by PAYP264CA0013.FRAP264.PROD.OUTLOOK.COM (2603:10a6:102:11e::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4331.21 via Frontend Transport; Mon, 19 Jul 2021 13:52:01 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 60bc141d-b505-4715-b553-08d94abc62bf X-MS-TrafficTypeDiagnostic: VE1PR04MB7471: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:10000; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: oPWME9LVlUbYQSMw1wIohuWmshlQj4wrsycxTDfYl1IUYIeq8jkamYIRb5oWdUZX8uGScwaIUnwWjUR4Xsl1ojXCZ5uOXG0f1hUac3WP9OxpqMyKinLfJGaq4AIgDRmUVWkE3MZ2JsmBvu5XtbtNSiq/LttcPcNjGJixqYuh2Fc+vH4YEN4aqrayt7cVAcLwmLpm3SbraVWU11815iVm8fjy4zhSiiJosBSNdaIbwWgP1RXzZkuw7HMG4i9irDFDupmWrCe0H7GQdKC/8qqaOg09RvHpXFzTUP3nThOFEKRGtINve3+aonwp7EoEIaQ0sOFQL/AooFO7naOaQWLmmFvcjajVPS8RXwrL7muxZqsIts4t4h6jERnXv3iPDR7PZpo5d5te44ey41exMJ3BRxG6ybA9j7bsTL7706D+tkQG66kUyUY/1yUjDodM/ltfi0KsjmVMQ3Qttw9rnPtQahcl+N5eEfUZ8G6OxV9/myN/1mGqudZp8AZ5fSm3lmtbEnKZy+7dvoRLGRwlBmQmrTe9df7BuOxNp0XPN7QmVEb4jD9/wOFZCuz/kXzg1Oyr9SI+DlIfmZHa590xnEk5pVVCo1nbyYsqjkbnUxhE1GxHak+Rq+HvwPq+fVkI1CCvLLrUf0nCokMHFEMMIvriWyPxckD9x10CzehWr2+cIXFBB2WnnmPkClpeS2OyR//ptAB5spSgBCb01rZG9m3aDw== 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:(4636009)(396003)(366004)(39860400002)(346002)(376002)(136003)(6506007)(8676002)(7416002)(1076003)(44832011)(5660300002)(52116002)(110136005)(30864003)(316002)(54906003)(8936002)(6486002)(66556008)(6666004)(4326008)(6512007)(36756003)(478600001)(83380400001)(186003)(86362001)(2906002)(38100700002)(66476007)(26005)(66946007)(956004)(2616005)(38350700002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: kyiR1ILcWnmZeYzgYAA1c44HtM09ClR3c3dxGj30tzBFyxSKhTEFm8MabKPGGd7P76Yys55Va573c0CSkUFm4Axo7ydET95cCc9ahIhwizgDjooCaiRsfKbFIXJZTmj/R3n/q8vgOxNcXRoPsWRnIrpxxBX20kl30o4vXdRfAzkE03iFo4Tbt91qvBg/MncMebke0JTqQkZ2id+y9bYsF5Hjxa2jTyEaImHVxJsQvtXtyV+igF0A0KMgvaJbw2FJ9BQlousaxyI+sYVKfoBrinCPL2n++3d5HXJsFH64llOR5DcEwarGiqILA6D/vJ15Ka0Dv2IFsoUrt0MhyQ/VCY38xSsbQTDu7/CXkYB6z9zy6xMx4RpkwVm+jZ9EckpQYeykEehNR6q/5HZ8Oc2CkbpwQ2CeqS3fj3dtB5iHAIM3FlQnEU863+9Kpf+AsRA84kbDaTFGwbvt+PcXHpxKL0fkq+2wsBXPxTAlLn882IhtOsx88tqcmDX6esss3i5jWafTaYeUOWUryItktBn7bYAB9EpSanHVXGENfFJN14ULCWSYl3STiqDd2Y5UevWuxxgcJBJwnlod6RCEVc8T7WHDQNqTL6elA60IG2TgYawkAbdtWZwaJ8zJ4PqGYNOGArxjCFa2OkaJ8lUX+vuwRD6rhTWCVEVF5kHLVJWMc/+BKu20lhqmqwG4/uR8JnS7qtsweIVCX3n84vjwulzZ35ZelnJpIX8vVIoZGs6PsFbAFMh0AsY6VKde83VJNJY0IBtiypMwvJ4OeWlu5Y601SGfnmy2GpNljPrVX6m+z8Y6pfmdTcLLEVZdaAsOEphd/XPvNg+EsHDJAynPRex3clm/hSGMPXrTjGlPIlSKgM1JmvG6G3NFqRSauCZsme0WLLJivrrExDMOlImnN+3jBCr0b/h20IsgNwBZiI0ikiq+rdtnyAo/It4mvYUVTEp6/16+8Hv6BGkfKvhUj8k/xNJtIr6+TyLliTSMT/PH7GqZ17bXZBNYqyGGN+cgBjEJmV5lauGRydnoLqr7IgWn+TcIzPNUge2Rd2DJMwJ/dMSGmMNyN8+AS7GdS7JiDBcrBBaM5BBhBknwE7SXdxavdsdP58DkXw0Aty+LOZUNIN7GBQDM8Bteg3lGhfAis3+0uP6hVufHNC5BOhEEpQDtoXPexaIHs7GHZIFPUN+gfOM7SA4Y0MwT/irQuneDjdP0CqyQfA3XXUIlG74FoeW/HtSXnYVHFrwOFB2YCSTTlCw8NLROYkBik6vOxhDWUyEf4g73GNXg/XM2EAlJTgR6KPkDfsqiv33CF/ZjV7nvK5KXoJCPUNNS2UnxPSrZ5pmn X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 60bc141d-b505-4715-b553-08d94abc62bf X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jul 2021 13:52:02.3452 (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: MLWlpbw3LmyTQznB2ChhBe+hrxXmm6YWrVXVbxJMoxkgM9KxHmg5ZBNsy/YI/wiqIXXwQjmLjxgTRpSxocC14w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR04MB7471 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Currently DSA has an issue with FDB entries pointing towards the bridge in the presence of br_fdb_replay() being called at port join and leave time. In particular, each bridge port will ask for a replay for the FDB entries pointing towards the bridge when it joins, and for another replay when it leaves. This means that for example, a bridge with 4 switch ports will notify DSA 4 times of the bridge MAC address. But if the MAC address of the bridge changes during the normal runtime of the system, the bridge notifies switchdev [ once ] of the deletion of the old MAC address as a local FDB towards the bridge, and of the insertion [ again once ] of the new MAC address as a local FDB. This is a problem, because DSA keeps the old MAC address as a host FDB entry with refcount 4 (4 ports asked for it using br_fdb_replay). So the old MAC address will not be deleted. Additionally, the new MAC address will only be installed with refcount 1, and when the first switch port leaves the bridge (leaving 3 others as still members), it will delete with it the new MAC address of the bridge from the local FDB entries kept by DSA (because the br_fdb_replay call on deletion will bring the entry's refcount from 1 to 0). So the problem, really, is that the number of br_fdb_replay() calls is not matched with the refcount that a host FDB is offloaded to DSA during normal runtime. An elegant way to solve the problem would be to make the switchdev notification emitted by br_fdb_change_mac_address() result in a host FDB kept by DSA which has a refcount exactly equal to the number of ports under that bridge. Then, no matter how many DSA ports join or leave that bridge, the host FDB entry will always be deleted when there are exactly zero remaining DSA switch ports members of the bridge. To implement the proposed solution, we remember that the switchdev objects and port attributes have some helpers provided by switchdev, which can be optionally called by drivers: switchdev_handle_port_obj_{add,del} and switchdev_handle_port_attr_set. These helpers: - fan out a switchdev object/attribute emitted for the bridge towards all the lower interfaces that pass the check_cb(). - fan out a switchdev object/attribute emitted for a bridge port that is a LAG towards all the lower interfaces that pass the check_cb(). In other words, this is the model we need for the FDB events too: something that will keep an FDB entry emitted towards a physical port as it is, but translate an FDB entry emitted towards the bridge into N FDB entries, one per physical port. Of course, there are many differences between fanning out a switchdev object (VLAN) on 3 lower interfaces of a LAG and fanning out an FDB entry on 3 lower interfaces of a LAG. Intuitively, an FDB entry towards a LAG should be treated specially, because FDB entries are unicast, we can't just install the same address towards 3 destinations. It is imaginable that drivers might want to treat this case specifically, so create some methods for this case and do not recurse into the LAG lower ports, just the bridge ports. DSA also listens for FDB entries on "foreign" interfaces, aka interfaces bridged with us which are not part of our hardware domain: think an Ethernet switch bridged with a Wi-Fi AP. For those addresses, DSA installs host FDB entries. However, there we have the same problem (those host FDB entries are installed with a refcount of only 1) and an even bigger one which we did not have with FDB entries towards the bridge: br_fdb_replay() is currently not called for FDB entries on foreign interfaces, just for the physical port and for the bridge itself. So when DSA sniffs an address learned by the software bridge towards a foreign interface like an e1000 port, and then that e1000 leaves the bridge, DSA remains with the dangling host FDB address. That will be fixed separately by replaying all FDB entries and not just the ones towards the port and the bridge. Signed-off-by: Vladimir Oltean --- include/net/switchdev.h | 56 +++++++++++ net/switchdev/switchdev.c | 190 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 246 insertions(+) diff --git a/include/net/switchdev.h b/include/net/switchdev.h index 745eb25fb8c4..6f57eb2e89cc 100644 --- a/include/net/switchdev.h +++ b/include/net/switchdev.h @@ -272,6 +272,30 @@ void switchdev_port_fwd_mark_set(struct net_device *dev, struct net_device *group_dev, bool joining); +int switchdev_handle_fdb_add_to_device(struct net_device *dev, + const struct switchdev_notifier_fdb_info *fdb_info, + bool (*check_cb)(const struct net_device *dev), + bool (*foreign_dev_check_cb)(const struct net_device *dev, + const struct net_device *foreign_dev), + int (*add_cb)(struct net_device *dev, + const struct net_device *orig_dev, const void *ctx, + const struct switchdev_notifier_fdb_info *fdb_info), + int (*lag_add_cb)(struct net_device *dev, + const struct net_device *orig_dev, const void *ctx, + const struct switchdev_notifier_fdb_info *fdb_info)); + +int switchdev_handle_fdb_del_to_device(struct net_device *dev, + const struct switchdev_notifier_fdb_info *fdb_info, + bool (*check_cb)(const struct net_device *dev), + bool (*foreign_dev_check_cb)(const struct net_device *dev, + const struct net_device *foreign_dev), + int (*del_cb)(struct net_device *dev, + const struct net_device *orig_dev, const void *ctx, + const struct switchdev_notifier_fdb_info *fdb_info), + int (*lag_del_cb)(struct net_device *dev, + const struct net_device *orig_dev, const void *ctx, + const struct switchdev_notifier_fdb_info *fdb_info)); + int switchdev_handle_port_obj_add(struct net_device *dev, struct switchdev_notifier_port_obj_info *port_obj_info, bool (*check_cb)(const struct net_device *dev), @@ -355,6 +379,38 @@ call_switchdev_blocking_notifiers(unsigned long val, return NOTIFY_DONE; } +static inline int +switchdev_handle_fdb_add_to_device(struct net_device *dev, + const struct switchdev_notifier_fdb_info *fdb_info, + bool (*check_cb)(const struct net_device *dev), + bool (*foreign_dev_check_cb)(const struct net_device *dev, + const struct net_device *foreign_dev), + int (*add_cb)(struct net_device *dev, + const struct net_device *orig_dev, const void *ctx, + const struct switchdev_notifier_fdb_info *fdb_info), + int (*lag_add_cb)(struct net_device *dev, + const struct net_device *orig_dev, const void *ctx, + const struct switchdev_notifier_fdb_info *fdb_info)) +{ + return 0; +} + +static inline int +switchdev_handle_fdb_del_to_device(struct net_device *dev, + const struct switchdev_notifier_fdb_info *fdb_info, + bool (*check_cb)(const struct net_device *dev), + bool (*foreign_dev_check_cb)(const struct net_device *dev, + const struct net_device *foreign_dev), + int (*del_cb)(struct net_device *dev, + const struct net_device *orig_dev, const void *ctx, + const struct switchdev_notifier_fdb_info *fdb_info), + int (*lag_del_cb)(struct net_device *dev, + const struct net_device *orig_dev, const void *ctx, + const struct switchdev_notifier_fdb_info *fdb_info)); +{ + return 0; +} + static inline int switchdev_handle_port_obj_add(struct net_device *dev, struct switchdev_notifier_port_obj_info *port_obj_info, diff --git a/net/switchdev/switchdev.c b/net/switchdev/switchdev.c index 070698dd19bc..82dd4e4e86f5 100644 --- a/net/switchdev/switchdev.c +++ b/net/switchdev/switchdev.c @@ -378,6 +378,196 @@ int call_switchdev_blocking_notifiers(unsigned long val, struct net_device *dev, } EXPORT_SYMBOL_GPL(call_switchdev_blocking_notifiers); +static int __switchdev_handle_fdb_add_to_device(struct net_device *dev, + const struct net_device *orig_dev, + const struct switchdev_notifier_fdb_info *fdb_info, + bool (*check_cb)(const struct net_device *dev), + bool (*foreign_dev_check_cb)(const struct net_device *dev, + const struct net_device *foreign_dev), + int (*add_cb)(struct net_device *dev, + const struct net_device *orig_dev, const void *ctx, + const struct switchdev_notifier_fdb_info *fdb_info), + int (*lag_add_cb)(struct net_device *dev, + const struct net_device *orig_dev, const void *ctx, + const struct switchdev_notifier_fdb_info *fdb_info)) +{ + const struct switchdev_notifier_info *info = &fdb_info->info; + struct net_device *lower_dev; + struct list_head *iter; + int err = -EOPNOTSUPP; + + if (check_cb(dev)) { + /* Handle FDB entries on foreign interfaces as FDB entries + * towards the software bridge. + */ + if (foreign_dev_check_cb && foreign_dev_check_cb(dev, orig_dev)) { + struct net_device *br = netdev_master_upper_dev_get_rcu(dev); + + if (!br || !netif_is_bridge_master(br)) + return 0; + + /* No point in handling FDB entries on a foreign bridge */ + if (foreign_dev_check_cb(dev, br)) + return 0; + + return __switchdev_handle_fdb_add_to_device(br, orig_dev, + fdb_info, check_cb, + foreign_dev_check_cb, + add_cb, lag_add_cb); + } + + return add_cb(dev, orig_dev, info->ctx, fdb_info); + } + + /* If we passed over the foreign check, it means that the LAG interface + * is offloaded. + */ + if (netif_is_lag_master(dev)) { + if (!lag_add_cb) + return -EOPNOTSUPP; + + return lag_add_cb(dev, orig_dev, info->ctx, fdb_info); + } + + /* Recurse through lower interfaces in case the FDB entry is pointing + * towards a bridge device. + */ + netdev_for_each_lower_dev(dev, lower_dev, iter) { + /* Do not propagate FDB entries across bridges */ + if (netif_is_bridge_master(lower_dev)) + continue; + + err = __switchdev_handle_fdb_add_to_device(lower_dev, orig_dev, + fdb_info, check_cb, + foreign_dev_check_cb, + add_cb, lag_add_cb); + if (err && err != -EOPNOTSUPP) + return err; + } + + return err; +} + +int switchdev_handle_fdb_add_to_device(struct net_device *dev, + const struct switchdev_notifier_fdb_info *fdb_info, + bool (*check_cb)(const struct net_device *dev), + bool (*foreign_dev_check_cb)(const struct net_device *dev, + const struct net_device *foreign_dev), + int (*add_cb)(struct net_device *dev, + const struct net_device *orig_dev, const void *ctx, + const struct switchdev_notifier_fdb_info *fdb_info), + int (*lag_add_cb)(struct net_device *dev, + const struct net_device *orig_dev, const void *ctx, + const struct switchdev_notifier_fdb_info *fdb_info)) +{ + int err; + + err = __switchdev_handle_fdb_add_to_device(dev, dev, fdb_info, + check_cb, + foreign_dev_check_cb, + add_cb, lag_add_cb); + if (err == -EOPNOTSUPP) + err = 0; + + return err; +} +EXPORT_SYMBOL_GPL(switchdev_handle_fdb_add_to_device); + +static int __switchdev_handle_fdb_del_to_device(struct net_device *dev, + const struct net_device *orig_dev, + const struct switchdev_notifier_fdb_info *fdb_info, + bool (*check_cb)(const struct net_device *dev), + bool (*foreign_dev_check_cb)(const struct net_device *dev, + const struct net_device *foreign_dev), + int (*del_cb)(struct net_device *dev, + const struct net_device *orig_dev, const void *ctx, + const struct switchdev_notifier_fdb_info *fdb_info), + int (*lag_del_cb)(struct net_device *dev, + const struct net_device *orig_dev, const void *ctx, + const struct switchdev_notifier_fdb_info *fdb_info)) +{ + const struct switchdev_notifier_info *info = &fdb_info->info; + struct net_device *lower_dev; + struct list_head *iter; + int err = -EOPNOTSUPP; + + if (check_cb(dev)) { + /* Handle FDB entries on foreign interfaces as FDB entries + * towards the software bridge. + */ + if (foreign_dev_check_cb && foreign_dev_check_cb(dev, orig_dev)) { + struct net_device *br = netdev_master_upper_dev_get_rcu(dev); + + if (!br || !netif_is_bridge_master(br)) + return 0; + + /* No point in handling FDB entries on a foreign bridge */ + if (foreign_dev_check_cb(dev, br)) + return 0; + + return __switchdev_handle_fdb_del_to_device(br, orig_dev, + fdb_info, check_cb, + foreign_dev_check_cb, + del_cb, lag_del_cb); + } + + return del_cb(dev, orig_dev, info->ctx, fdb_info); + } + + /* If we passed over the foreign check, it means that the LAG interface + * is offloaded. + */ + if (netif_is_lag_master(dev)) { + if (!lag_del_cb) + return -EOPNOTSUPP; + + return lag_del_cb(dev, orig_dev, info->ctx, fdb_info); + } + + /* Recurse through lower interfaces in case the FDB entry is pointing + * towards a bridge device. + */ + netdev_for_each_lower_dev(dev, lower_dev, iter) { + /* Do not propagate FDB entries across bridges */ + if (netif_is_bridge_master(lower_dev)) + continue; + + err = switchdev_handle_fdb_del_to_device(lower_dev, fdb_info, + check_cb, + foreign_dev_check_cb, + del_cb, lag_del_cb); + if (err && err != -EOPNOTSUPP) + return err; + } + + return err; +} + +int switchdev_handle_fdb_del_to_device(struct net_device *dev, + const struct switchdev_notifier_fdb_info *fdb_info, + bool (*check_cb)(const struct net_device *dev), + bool (*foreign_dev_check_cb)(const struct net_device *dev, + const struct net_device *foreign_dev), + int (*del_cb)(struct net_device *dev, + const struct net_device *orig_dev, const void *ctx, + const struct switchdev_notifier_fdb_info *fdb_info), + int (*lag_del_cb)(struct net_device *dev, + const struct net_device *orig_dev, const void *ctx, + const struct switchdev_notifier_fdb_info *fdb_info)) +{ + int err; + + err = __switchdev_handle_fdb_del_to_device(dev, dev, fdb_info, + check_cb, + foreign_dev_check_cb, + del_cb, lag_del_cb); + if (err == -EOPNOTSUPP) + err = 0; + + return err; +} +EXPORT_SYMBOL_GPL(switchdev_handle_fdb_del_to_device); + static int __switchdev_handle_port_obj_add(struct net_device *dev, struct switchdev_notifier_port_obj_info *port_obj_info, bool (*check_cb)(const struct net_device *dev), From patchwork Mon Jul 19 13:51:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 482085 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=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER, 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 5C989C636CE for ; Mon, 19 Jul 2021 13:53:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4534C61166 for ; Mon, 19 Jul 2021 13:53:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241011AbhGSNM5 (ORCPT ); Mon, 19 Jul 2021 09:12:57 -0400 Received: from mail-eopbgr40062.outbound.protection.outlook.com ([40.107.4.62]:65094 "EHLO EUR03-DB5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S240769AbhGSNMV (ORCPT ); Mon, 19 Jul 2021 09:12:21 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Cb2xD4MnWx0CmzKnmex7LI/bJm6eoJBGwmBBeicDkNtrsGRGvVSaJosZ3cDTTHcj3AK5mVLNH7afPWjfrFnV2qBWAr8M0yrDw/kEIAizOZWq08WJQZ2Nq5WX7S66HniEZXs8YEMxb+lkexRlw3GAUX4aEzZCcVeOdsKZ7YzT03JxHoHMqHtL8fcolo05wshpHZz2A5vmV+/91xoUvvuV9Qob5xwOCdrs/LQGpTt8C11vlQixI0CGpcv0HoF6Ara3cLy4nTLC/oMVLH50OeJVy3ADKf9vY/vrBLy4WYXDzaBJE2y/akszyZ7/M7i3ji8zbrRui9dC7m3YpiULgrarjA== 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-SenderADCheck; bh=i+wlcFQmlttP1MyZSwz0f2uvGjTh91BntK9D0CsW3mk=; b=RoU6EcJOQnQ4Xoc9IV40a0bgoMB5LM+fd0m1yp1fPxtGDC0+hN/LwGkL+nCQ4RM+tt1BiP6JM0BWH/5JtdztDQPAvQHcKvT6o74AlRElooS82Ji2k6ghj8MJsGi0HDunbtvIs3wY0sD4CNSgFEvVQzMi3rUYHfiNA2a++YS5IMkIbXJft72tWYe1vB9gLhTZAIvLeECS1GbtMn88BGDPphwEdnYwNLOQJegmhFwWi7B2f+MbDY1iqF/BWO1Eapk2XS2/xXp4/DWOa9vNR9i03Bkhk/hsUznlostPSfK+x0tLg5VStFW8EyFgSkM051lzfP3xeb+4Q30xUAJ4ZgNiUQ== 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=i+wlcFQmlttP1MyZSwz0f2uvGjTh91BntK9D0CsW3mk=; b=aQuHUCSKrboL8uyuzfSn8llHui/B5s9XMoi9zOl88bBfrdcbgd0G9piKg0mjtyxpViAe0GzI5VUuWjj/oZPJBK/rpD4HnjBmagiwAMioT4wc0h+Vl+G5bPqdOPN7EJkVU17a3utMJvgGDf4okPcKJpmE076VNLF7e5KLwiFFt4I= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none; vger.kernel.org; dmarc=none action=none header.from=nxp.com; Received: from VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) by VE1PR04MB7471.eurprd04.prod.outlook.com (2603:10a6:800:1a7::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4331.23; Mon, 19 Jul 2021 13:52:05 +0000 Received: from VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::109:1995:3e6b:5bd0]) by VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::109:1995:3e6b:5bd0%2]) with mapi id 15.20.4331.032; Mon, 19 Jul 2021 13:52:05 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org, Jakub Kicinski , "David S. Miller" Cc: Andrew Lunn , Florian Fainelli , Vivien Didelot , Jiri Pirko , Ido Schimmel , Tobias Waldekranz , Roopa Prabhu , Nikolay Aleksandrov , Stephen Hemminger , bridge@lists.linux-foundation.org, DENG Qingfang Subject: [PATCH net-next 3/3] net: dsa: use switchdev_handle_fdb_{add, del}_to_device Date: Mon, 19 Jul 2021 16:51:40 +0300 Message-Id: <20210719135140.278938-4-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210719135140.278938-1-vladimir.oltean@nxp.com> References: <20210719135140.278938-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: PAYP264CA0013.FRAP264.PROD.OUTLOOK.COM (2603:10a6:102:11e::18) To VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (82.76.66.29) by PAYP264CA0013.FRAP264.PROD.OUTLOOK.COM (2603:10a6:102:11e::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4331.21 via Frontend Transport; Mon, 19 Jul 2021 13:52:02 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a2980f87-e222-4fc6-a03a-08d94abc63ab X-MS-TrafficTypeDiagnostic: VE1PR04MB7471: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6108; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: X26vn3YKjMroe6pWhAD1QgrTBCLalq0xbknMBvPEBG6gmYVmiWSp06OnskKlYAJpgFFd1wYB8FZUkpK2lAKoC3DIFAUeFW6s3KAcZBwKdYeQrIb2eNAVvBRcXLGwcWQzGKU/6hEVM1cs9qt/+k8XStL4kzfKPbQMlxJrvs6m+Owfx4OsHuoGq2NcQSIF/Uge9hjUSTKqILlexnvPVb5FBm68UcYvrNJuXWMCIlhrG6uvqxAGx455s0O3bERW9M9D4DW9KvLWtalAWafRrVnb4zSl3GogwPtviWS2OdjeniS0Nlzto3yrI9ZQodfDRXUY3EbnDzEx07j31tem8681Q1x/1Z6Z0jYOrICGu4NwPdgEzPWqE5HY5vAfqnuBEnKUMr3p2i0dfkEFBy1P/CIQAqlN/ODy5Vo/bRp/IxMCUuCPe3wPqdUJLlkoeu6pOWXWgjFZ2qRApq6iom62ZcJer8YCVj83F11a3BLyFyZjSVCwm+cF3dGCnxdxCDqNCZYLKWTKwPhyTFULTPMilZqEX8Fv5IYYPSSmqvXLEZ59DvaxcppD2Ng5LpfQsvLF6arg2fffiumabtBw19rWoZLKeK6veBLS52yaxrW7tgYO59VdyDi6qRcqEZej4D+WCO2PH3EDmpGAflAL2E5l6c5XVbmqBvQacDSLK9l+WoUGiNgI0voACQd54cgmoMOUCa4s 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:(4636009)(396003)(366004)(39860400002)(346002)(376002)(136003)(6506007)(8676002)(7416002)(1076003)(44832011)(5660300002)(52116002)(110136005)(316002)(54906003)(8936002)(6486002)(66556008)(6666004)(4326008)(6512007)(36756003)(478600001)(83380400001)(186003)(86362001)(2906002)(38100700002)(66476007)(26005)(66946007)(956004)(2616005)(38350700002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: TpBn/rykDctPxbX9PLwcUUf8RE9QyRq8dAYgLcJcRgvUBnpB4JqORap0ryetZr45wxVuefpZO6oeDW1F2eJSRlUSzpop4maAOyblPeLnwCQQHPrADyYw5fxanemcwYe8GtJVJ/MSCy65zd+hwutwCQ1Bte61VDJXhbtB2/OmSbj21zUFvRAjqh5KKPKnrGeq6uoAl/nEwqL9af7WDwcNnuopTkWOmWI4fBzB36EZ2z8Yw4RxU+S/j4J6w44C2G/4ySilHWhpNeucI4S/IoepabC7CBD15UGv4fKPhgCxAc62bgPYJS4I/gB0xdFzvTZDx87ZiLN/6UYG3CJVHmVLmeKXqhW5qrH3wPGstLyjzslYthpluLICB0vZUXcPEMQJWyKzzA750sm00UqstrraWhpnfSlGyFW456+vGyPgDzDnMwMINCiOJCYRLO8XcS9h1erri1FcaOyBVW3el9WI6re+93Kr37NGoZC3PWZVbIu6uZbwv/qmHz7px48m3GVFzhzVL8F/LfBbtqpnNeeASr6uSVijohZ9eholaxM4YYJ+RfzlV4pA0Yv1CWNgramL7BiR2XFdLB1mxelr8WWRUJvfknXm1Q0rIV0P4XfH6/srXaKSzAJ14shCCAIzSFg7Fq7ZUXs6IMjXOdg28M42eiIu18L3oyuzmY3CxoQ3UKpI3fRC2occ+WKCBgNPkURfLA/udbq5cKwnPfHutoANBbjLcqR5/mOgljkn1nk1x6s9dtvJfz4pKI2BIOLoJ3F0geAb0Do6djBLmS9h/k7gFjW5SalUY3Y86kmiW4dtoTzOw48K2YGeTWYf+tln6KX12sZVEdfx1QD7Dzi3EoVVWg6h0UtZgZLdiqexUEhDa3j4gHP7ADNWCdjyAzX3ALsAXLdY7k5I1aKXo4trPoKL1itFnPSp7G78e4ShYi0NwnHciIE1+v50+RdHa27a438Ddj7+G5Btj7CsOI8Eo3Y+Mxwts3bTJDvj4v3W7pjX9F3Nw0mIM+mgM0hHRgpmXOt7JrRJlcwecClVkrRY9PP+Yz/ff/d+6A52QIMQTF0tJFaCbLnuYvAYgVIled/EwKTa4O14YcmUcCdjs9N+hXustdxKpXe9ksGw4fVFa/T+52PehsimZr37EcjiPuw4eTgrSTUTQgraz0+obhMdXQRG/sx54gmrC8UNou3F7OxlQhOSiQ/9lDubHw/4BixY1Z086xG1kNUlDVgIVei5C+kA+7yZliugDO1UP6JOPBCF04OAafHFTcREeVuIay8cxeykW54u4/m2IL1QZ68/v9bYl5OU602yhynoPEewhq3ETfANp/UhubvAvms/ejsbvJsV X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: a2980f87-e222-4fc6-a03a-08d94abc63ab X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jul 2021 13:52:05.0796 (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: Js1asAqjqoBXFDXVC5LWGELrgaUI2pVLOE5VtLHeTT6SmZY0XihhGomeOd5kvs3m1Ickew6M3GBhVKvUCPWb5Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR04MB7471 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Using the new fan-out helper for FDB entries installed on the software bridge, we can install host addresses with the proper refcount on the CPU port, such that this case: ip link set swp0 master br0 ip link set swp1 master br0 ip link set swp2 master br0 ip link set swp3 master br0 ip link set br0 address 00:01:02:03:04:05 ip link set swp3 nomaster works properly and the br0 address remains installed as a host entry with refcount 3 instead of getting deleted. Signed-off-by: Vladimir Oltean --- net/dsa/dsa_priv.h | 19 ++++- net/dsa/slave.c | 199 ++++++++++++++++++++++----------------------- 2 files changed, 113 insertions(+), 105 deletions(-) diff --git a/net/dsa/dsa_priv.h b/net/dsa/dsa_priv.h index f201c33980bf..e4b2e9f2a020 100644 --- a/net/dsa/dsa_priv.h +++ b/net/dsa/dsa_priv.h @@ -256,13 +256,13 @@ void dsa_port_hsr_leave(struct dsa_port *dp, struct net_device *hsr); extern const struct phylink_mac_ops dsa_port_phylink_mac_ops; static inline bool dsa_port_offloads_bridge_port(struct dsa_port *dp, - struct net_device *dev) + const struct net_device *dev) { return dsa_port_to_bridge_port(dp) == dev; } static inline bool dsa_port_offloads_bridge(struct dsa_port *dp, - struct net_device *bridge_dev) + const struct net_device *bridge_dev) { /* DSA ports connected to a bridge, and event was emitted * for the bridge. @@ -272,7 +272,7 @@ static inline bool dsa_port_offloads_bridge(struct dsa_port *dp, /* Returns true if any port of this tree offloads the given net_device */ static inline bool dsa_tree_offloads_bridge_port(struct dsa_switch_tree *dst, - struct net_device *dev) + const struct net_device *dev) { struct dsa_port *dp; @@ -283,6 +283,19 @@ static inline bool dsa_tree_offloads_bridge_port(struct dsa_switch_tree *dst, return false; } +/* Returns true if any port of this tree offloads the given bridge */ +static inline bool dsa_tree_offloads_bridge(struct dsa_switch_tree *dst, + const struct net_device *bridge_dev) +{ + struct dsa_port *dp; + + list_for_each_entry(dp, &dst->ports, list) + if (dsa_port_offloads_bridge(dp, bridge_dev)) + return true; + + return false; +} + /* slave.c */ extern const struct dsa_device_ops notag_netdev_ops; extern struct notifier_block dsa_slave_switchdev_notifier; diff --git a/net/dsa/slave.c b/net/dsa/slave.c index feb64f58faed..22ce11cd770e 100644 --- a/net/dsa/slave.c +++ b/net/dsa/slave.c @@ -2353,26 +2353,98 @@ static void dsa_slave_switchdev_event_work(struct work_struct *work) kfree(switchdev_work); } -static int dsa_lower_dev_walk(struct net_device *lower_dev, - struct netdev_nested_priv *priv) +static bool dsa_foreign_dev_check(const struct net_device *dev, + const struct net_device *foreign_dev) { - if (dsa_slave_dev_check(lower_dev)) { - priv->data = (void *)netdev_priv(lower_dev); - return 1; - } + const struct dsa_port *dp = dsa_slave_to_port(dev); + struct dsa_switch_tree *dst = dp->ds->dst; - return 0; + if (netif_is_bridge_master(foreign_dev)) + return !dsa_tree_offloads_bridge(dst, foreign_dev); + + if (netif_is_bridge_port(foreign_dev)) + return !dsa_tree_offloads_bridge_port(dst, foreign_dev); + + /* Everything else is foreign */ + return true; } -static struct dsa_slave_priv *dsa_slave_dev_lower_find(struct net_device *dev) +static int dsa_slave_fdb_event(struct net_device *dev, + const struct net_device *orig_dev, + const void *ctx, + const struct switchdev_notifier_fdb_info *fdb_info, + unsigned long event) { - struct netdev_nested_priv priv = { - .data = NULL, - }; + struct dsa_switchdev_event_work *switchdev_work; + struct dsa_port *dp = dsa_slave_to_port(dev); + bool host_addr = fdb_info->is_local; + struct dsa_switch *ds = dp->ds; + + if (ctx && ctx != dp) + return 0; + + if (!ds->ops->port_fdb_add || !ds->ops->port_fdb_del) + return -EOPNOTSUPP; + + if (dsa_slave_dev_check(orig_dev) && + switchdev_fdb_is_dynamically_learned(fdb_info)) + return 0; + + /* FDB entries learned by the software bridge should be installed as + * host addresses only if the driver requests assisted learning. + */ + if (switchdev_fdb_is_dynamically_learned(fdb_info) && + !ds->assisted_learning_on_cpu_port) + return 0; + + /* Also treat FDB entries on foreign interfaces bridged with us as host + * addresses. + */ + if (dsa_foreign_dev_check(dev, orig_dev)) + host_addr = true; + + switchdev_work = kzalloc(sizeof(*switchdev_work), GFP_ATOMIC); + if (!switchdev_work) + return -ENOMEM; + + netdev_dbg(dev, "%s FDB entry towards %s, addr %pM vid %d%s\n", + event == SWITCHDEV_FDB_ADD_TO_DEVICE ? "Adding" : "Deleting", + orig_dev->name, fdb_info->addr, fdb_info->vid, + host_addr ? " as host address" : ""); - netdev_walk_all_lower_dev_rcu(dev, dsa_lower_dev_walk, &priv); + INIT_WORK(&switchdev_work->work, dsa_slave_switchdev_event_work); + switchdev_work->ds = ds; + switchdev_work->port = dp->index; + switchdev_work->event = event; + switchdev_work->dev = dev; - return (struct dsa_slave_priv *)priv.data; + ether_addr_copy(switchdev_work->addr, fdb_info->addr); + switchdev_work->vid = fdb_info->vid; + switchdev_work->host_addr = host_addr; + + /* Hold a reference for dsa_fdb_offload_notify */ + dev_hold(dev); + dsa_schedule_work(&switchdev_work->work); + + return 0; +} + +static int +dsa_slave_fdb_add_to_device(struct net_device *dev, + const struct net_device *orig_dev, const void *ctx, + const struct switchdev_notifier_fdb_info *fdb_info) +{ + return dsa_slave_fdb_event(dev, orig_dev, ctx, fdb_info, + SWITCHDEV_FDB_ADD_TO_DEVICE); +} + +static int +dsa_slave_fdb_del_to_device(struct net_device *dev, + const struct net_device *orig_dev, const void *ctx, + const struct switchdev_notifier_fdb_info *fdb_info) +{ + return dsa_slave_fdb_event(dev, orig_dev, ctx, fdb_info, + SWITCHDEV_FDB_DEL_TO_DEVICE); } /* Called under rcu_read_lock() */ @@ -2380,10 +2452,6 @@ static int dsa_slave_switchdev_event(struct notifier_block *unused, unsigned long event, void *ptr) { struct net_device *dev = switchdev_notifier_info_to_dev(ptr); - const struct switchdev_notifier_fdb_info *fdb_info; - struct dsa_switchdev_event_work *switchdev_work; - bool host_addr = false; - struct dsa_port *dp; int err; switch (event) { @@ -2393,92 +2461,19 @@ static int dsa_slave_switchdev_event(struct notifier_block *unused, dsa_slave_port_attr_set); return notifier_from_errno(err); case SWITCHDEV_FDB_ADD_TO_DEVICE: + err = switchdev_handle_fdb_add_to_device(dev, ptr, + dsa_slave_dev_check, + dsa_foreign_dev_check, + dsa_slave_fdb_add_to_device, + NULL); + return notifier_from_errno(err); case SWITCHDEV_FDB_DEL_TO_DEVICE: - fdb_info = ptr; - - if (dsa_slave_dev_check(dev)) { - dp = dsa_slave_to_port(dev); - - if (fdb_info->is_local) - host_addr = true; - else if (!fdb_info->added_by_user) - return NOTIFY_OK; - } else { - /* Snoop addresses added to foreign interfaces - * bridged with us, or the bridge - * itself. Dynamically learned addresses can - * also be added for switches that don't - * automatically learn SA from CPU-injected - * traffic. - */ - struct net_device *br_dev; - struct dsa_slave_priv *p; - - if (netif_is_bridge_master(dev)) - br_dev = dev; - else - br_dev = netdev_master_upper_dev_get_rcu(dev); - - if (!br_dev) - return NOTIFY_DONE; - - if (!netif_is_bridge_master(br_dev)) - return NOTIFY_DONE; - - p = dsa_slave_dev_lower_find(br_dev); - if (!p) - return NOTIFY_DONE; - - dp = p->dp; - host_addr = fdb_info->is_local; - - /* FDB entries learned by the software bridge should - * be installed as host addresses only if the driver - * requests assisted learning. - * On the other hand, FDB entries for local termination - * should always be installed. - */ - if (switchdev_fdb_is_dynamically_learned(fdb_info) && - !dp->ds->assisted_learning_on_cpu_port) - return NOTIFY_DONE; - - /* When the bridge learns an address on an offloaded - * LAG we don't want to send traffic to the CPU, the - * other ports bridged with the LAG should be able to - * autonomously forward towards it. - * On the other hand, if the address is local - * (therefore not learned) then we want to trap it to - * the CPU regardless of whether the interface it - * belongs to is offloaded or not. - */ - if (dsa_tree_offloads_bridge_port(dp->ds->dst, dev) && - !fdb_info->is_local) - return NOTIFY_DONE; - } - - if (!dp->ds->ops->port_fdb_add || !dp->ds->ops->port_fdb_del) - return NOTIFY_DONE; - - switchdev_work = kzalloc(sizeof(*switchdev_work), GFP_ATOMIC); - if (!switchdev_work) - return NOTIFY_BAD; - - INIT_WORK(&switchdev_work->work, - dsa_slave_switchdev_event_work); - switchdev_work->ds = dp->ds; - switchdev_work->port = dp->index; - switchdev_work->event = event; - switchdev_work->dev = dev; - - ether_addr_copy(switchdev_work->addr, - fdb_info->addr); - switchdev_work->vid = fdb_info->vid; - switchdev_work->host_addr = host_addr; - - /* Hold a reference for dsa_fdb_offload_notify */ - dev_hold(dev); - dsa_schedule_work(&switchdev_work->work); - break; + err = switchdev_handle_fdb_del_to_device(dev, ptr, + dsa_slave_dev_check, + dsa_foreign_dev_check, + dsa_slave_fdb_del_to_device, + NULL); + return notifier_from_errno(err); default: return NOTIFY_DONE; }