From patchwork Tue Aug 24 11:40:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 12454835 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 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,URIBL_BLOCKED,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 B2469C432BE for ; Tue, 24 Aug 2021 11:41:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 98501613B1 for ; Tue, 24 Aug 2021 11:41:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236741AbhHXLmO (ORCPT ); Tue, 24 Aug 2021 07:42:14 -0400 Received: from mail-eopbgr80078.outbound.protection.outlook.com ([40.107.8.78]:43248 "EHLO EUR04-VI1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S236550AbhHXLmE (ORCPT ); Tue, 24 Aug 2021 07:42:04 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Z23HGec50iXriQvD/7SPF8RBSmmSeeR7m7bEoh3/Y/2wOakJUotiPRDzvaS/ezVjNt6iJkO4Cva7QYx1jmgWHC0OUvHSXqaWh9poPNwGZaATgHIamABtxvRl4mh2bBHq9BwIS3LfGFXXPK/CHhyP2sZtjBG16l8WQ8e/9f5SgauGTkyOH0KidEuKBiK7i6MRuwsKatJHV4PFgz9CdnKbtVU7dx0nlxjKRAJhNe1VtB26fScriIMGJLWEiz3xK8ShRDSqVQ5EFNlQl30Qi/YcnjNDZsPTgLYsRQXdcujCgYKJnfi7iyjd1ljlsfRf8XXZDRA5oRVAOvRm0t3JVwWfIw== 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=uXPQ1kGmLDc4MxjhE3mZ9yd1U45r/8dJzMYU0u1a4cU=; b=NlbOZcwYtGCGgHu7O5Px1EsmnR/0h059pWIXxmGWbrfYNbi9DQr7kCQmET5NZ4Drr/unV5CeK0U7U5Cx9BVo1xTkU4baGcDgs11G5qFzNv+hWZAAaOWQ3WGFk0PEsMMDmQP6WUh8fVjg7nVWyxje5VLIRzjcKvTVgRecpgTRvOJJzipkpx2uLJ0yxrIXInPDwVI6oyfYFoTFQSOp8kiMIuURV4+dhK5OLQLMY5YOy6NBUPDCCr6RAUKWIEP2x5kCYqpooii2VnBInRaT216eMQOOxLskL58x6/IESc+5usJZb8/rc0Nul8JydAhQWowrkyhxgjylKNeRPajHlXQGPw== 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=uXPQ1kGmLDc4MxjhE3mZ9yd1U45r/8dJzMYU0u1a4cU=; b=Pbl4nBpLaExShG0AckTHS2m3wmDTaiVyb11cGSuBCc7BTZXqvb/IeoSkRM6nUHRahi+DwGCy7zLsdUaV9O/aFixDMWX0L5LVJkjr1PvQnijCDeR8ky4i2Lj1keIOBbEaZTtSCjWKggzS/FK8B336kAyKfCFpQnzAVSVZyqyYkLo= 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 VI1PR04MB5696.eurprd04.prod.outlook.com (2603:10a6:803:e7::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.19; Tue, 24 Aug 2021 11:41:16 +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.4436.025; Tue, 24 Aug 2021 11:41:16 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org Cc: Florian Fainelli , Andrew Lunn , Vivien Didelot , Vladimir Oltean , UNGLinuxDriver@microchip.com, DENG Qingfang , Kurt Kanzenbach , Hauke Mehrtens , Woojung Huh , Sean Wang , Landen Chao , Alexandre Belloni , George McCollister , John Crispin , Aleksander Jan Bajkowski , Egil Hjelmeland , Oleksij Rempel Subject: [RFC PATCH net-next 1/8] net: dsa: sja1105: wait for dynamic config command completion on writes too Date: Tue, 24 Aug 2021 14:40:42 +0300 Message-Id: <20210824114049.3814660-2-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210824114049.3814660-1-vladimir.oltean@nxp.com> References: <20210824114049.3814660-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: FR0P281CA0083.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1e::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 (188.25.144.60) by FR0P281CA0083.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1e::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4457.6 via Frontend Transport; Tue, 24 Aug 2021 11:41:14 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 3a413f88-a326-47a7-4524-08d966f414de X-MS-TrafficTypeDiagnostic: VI1PR04MB5696: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: u31KE/hRn429QqBsuuDpWzI3gzi7Ii9/pYxZzDNVzlWr59OaFdeE3WEg7FBlqFcyHhbad5U98QksIk28bsrsNPbYtamuNbQU1mN/7MXdMEl/bCeseHVW7IQENksM4YAG4Pu+0uI8MoqpOEF6UCjGHKIcldvO6O2shGHauS4Sh96OXX5JspK+oxSm9TMm7PMb1axC6qwiJq6u4GwMchtlf8lMPPiJUjneQNQn5+T55lj+OpHv5MU1A9FrJWVv1iTp+PdN0heAiy32NxEsbSHZB7mi8TmaNK/n5dDGMD2fQNvgB5a6fgupxvcyl4+zW/D3ayBVZkITmHkbd6lE5JAvWHZtLsUTDylh/9nTXfWFB9gOrXi/2AKYYY/WaNDXeewWXMQtdHZGIBIwaXXS6ayL2Ulu1uf34heVsvVJjUJ/I1izOz7q1GPETvJLw7KYbx2gUf9OJw/M96bkJFxo8K3Jov81DCodQ8ioTHpc+xm/CvWKgDFs9QedV9O7fUzO08WHm6h9aWbj1ucda+0YdmObi/C9a775ExjghAQkjx3Y34nMR/52CmJoODfow4Qet6cac9cGLNP/fdajJnZQYuGEaSqcy95cueQlT12AQUaD8WFU0WQtF9c3Gk5O8dRJtvXvMns1MRDVedp91n7sQ+1sWH5MCV5rgZVBqbyNgPalozJYTX2PwNiwX+n//CLSXTynVRYkr7N1rmPpHmds1deLXg== 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)(366004)(346002)(396003)(136003)(39850400004)(376002)(52116002)(4326008)(478600001)(5660300002)(6916009)(66476007)(66556008)(26005)(83380400001)(1076003)(36756003)(66946007)(6486002)(6666004)(6512007)(7416002)(6506007)(186003)(8676002)(8936002)(2616005)(86362001)(44832011)(38100700002)(38350700002)(956004)(2906002)(54906003)(316002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: mEsWH+N6eD7omlYC2jXdB/3VrmQEKVYTrq60Kh9vvhCARM0zuAvu8ff+nKb6omGduGmW91Ai6wp9c4AqAoblhFncEMAe4YmYn3ryzs+Rz5ZO/IJxetQ7gIwKF+Q93ZoSNIqdtxGl4GEvFMefQ/MHzxtYWfNHBFDDvhxEDb/AWIfR/vKZsDmHDZeIOH7DI4hir2/AM+anV68bJINRP87COzcBpwOaQr/IqbzNcrnB7PwXhxqnIjnPPwRhiUffnJhMQdewt/nPoGu+5ql8vj5FD8okDtgHM2hrTTqcuVb54zko7sC+s1Kk3es/zl3fS2w43S9HLu+Lc+iCYHeYN410Ohs9SgEy3ZTctGo+4v4Jx6iqzXyFc70Scye54nODtUD3bY5sEBE8nWsYg+GxBT9d7xggwitvkYhMiF+z7/d7WkwdUJjXARpDcDWf17vuiSm4R3hsF4+atELrhMrfAVBU12GYBgtTH6NHCq5uTQldbuAKMcd74XOfwCJCn6kuhBvlx/0AwMlhEzOevvZQY92WkAdQNtJABoPqj533wWanqox6HM3JVlZ+olNM3lTg2dhhkdDLAERc/QFnbN4zstcwFA7KDYT658FOfSOkpgfIkAIsvQGnj48ySBHVtDYY3qrH+KAgMUAw7cgPGTw9Qqkv6u8sDPLA+1rJxZ6BJRStqdSGWoavod2d9QLUP+2VRR85Rkj9jnJMe+VJsqXoDgkHJWoLhiHHVteY+c0MYTpOjV1iM7NKU7mTX/oI2Tn/tPM9AWZNXF8AUkVPNNziZgzUUXdwa9pmYyIXWeKX21V7w5uy3JuYJaP9cjS/dE9nscPEFzUbN7wySeA8NZXVfZRphkqK84yKe89A7oyc1flIxF2jAzIn2FDINa5DiZYGH5WIw50BAwbZbtuKAO9suOKsQI48FWsRRk8GMcBhuvbpWiua+ZshIhez9ULRgC8ekfNvbYoxxUiyF/hQVvJdA254ewYhaxrVcteIWI1sYaAdCkON69nPQ0XWZilGKXz6ir90XqE3RsfukplIc+2rhqwQUUHeEhoHP4063W5BYWvR8esmLUxT1zjSW/ybAGdy+R3yV6v246zaXiD3MEDFbFM3Y/9kfyphkMMUnEAfCu6P8dZoftR3flm6XDUe4DFvlsqYW40Ze/6qZzh5puWkMU5SaeOWlA2IqTKdJfwdAdQpbUP7HavK0yIwQGIqOrdjMRgp72mThy2Fzlv7/B9ZfmysyT0Y07x+2qR8FR9pjjJ9f8Fez3do5osU1W2Q2VBAFFghgm/OjSxfdyk0Y4thrZ3SKYXBx8Snwp0b/qk8wP37gTE+V3pckrM7iVY89QvQ7MzG X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3a413f88-a326-47a7-4524-08d966f414de X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Aug 2021 11:41:16.0388 (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: 2NFpZVuih2PEZkXx2I8avQ5sTb6uu+c1jaVXMzJRqN5nIeqZUT3zqJw6SSW6qBr+IIRSJRGgAjf4vcoJ4od4ZQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB5696 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC The hardware manual says that software should attempt a new dynamic config access (be it a a write or a read-back) only while the VALID bit is cleared. The VALID bit is set by software to 1, and it remains set as long as the hardware is still processing the request. Currently the driver only polls for the command completion only for reads, because that's when we need the actual data read back. Writes have been more or less "asynchronous", although this has never been an observable issue. This change makes sja1105_dynamic_config_write poll the VALID bit as well, to absolutely ensure that a follow-up access to the static config finds the VALID bit cleared. So VALID means "work in progress", while VALIDENT means "entry being read is valid". On reads we check the VALIDENT bit too, while on writes that bit is not always defined. So we need to factor it out of the loop, and make the loop provide back the unpacked command structure, so that sja1105_dynamic_config_read can check the VALIDENT bit. The change also attempts to convert the open-coded loop to use the read_poll_timeout macro, since I know this will come up during review. It's more code, but hey, it uses read_poll_timeout! Tested on SJA1105T, SJA1105S, SJA1110A. Signed-off-by: Vladimir Oltean --- .../net/dsa/sja1105/sja1105_dynamic_config.c | 81 ++++++++++++++----- 1 file changed, 59 insertions(+), 22 deletions(-) diff --git a/drivers/net/dsa/sja1105/sja1105_dynamic_config.c b/drivers/net/dsa/sja1105/sja1105_dynamic_config.c index f2049f52833c..32ec34f181de 100644 --- a/drivers/net/dsa/sja1105/sja1105_dynamic_config.c +++ b/drivers/net/dsa/sja1105/sja1105_dynamic_config.c @@ -1170,6 +1170,56 @@ const struct sja1105_dynamic_table_ops sja1110_dyn_ops[BLK_IDX_MAX_DYN] = { }, }; +#define SJA1105_DYNAMIC_CONFIG_SLEEP_US 10 +#define SJA1105_DYNAMIC_CONFIG_TIMEOUT_US 100000 + +static int +sja1105_dynamic_config_poll_valid(struct sja1105_private *priv, + struct sja1105_dyn_cmd *cmd, + const struct sja1105_dynamic_table_ops *ops) +{ + u8 packed_buf[SJA1105_MAX_DYN_CMD_SIZE] = {}; + int rc; + + /* We don't _need_ to read the full entry, just the command area which + * is a fixed SJA1105_SIZE_DYN_CMD. But our cmd_packing() API expects a + * buffer that contains the full entry too. Additionally, our API + * doesn't really know how many bytes into the buffer does the command + * area really begin. So just read back the whole entry. + */ + rc = sja1105_xfer_buf(priv, SPI_READ, ops->addr, packed_buf, + ops->packed_size); + if (rc) + return rc; + + /* Unpack the command structure, and return it to the caller in case it + * needs to perform further checks on it (VALIDENT). + */ + memset(cmd, 0, sizeof(*cmd)); + ops->cmd_packing(packed_buf, cmd, UNPACK); + + /* Hardware hasn't cleared VALID => still working on it */ + return cmd->valid ? -EAGAIN : 0; +} + +/* Poll the dynamic config entry's control area until the hardware has + * cleared the VALID bit, which means we have confirmation that it has + * finished processing the command. + */ +static int +sja1105_dynamic_config_wait_complete(struct sja1105_private *priv, + struct sja1105_dyn_cmd *cmd, + const struct sja1105_dynamic_table_ops *ops) +{ + int rc; + + return read_poll_timeout(sja1105_dynamic_config_poll_valid, + rc, rc != -EAGAIN, + SJA1105_DYNAMIC_CONFIG_SLEEP_US, + SJA1105_DYNAMIC_CONFIG_TIMEOUT_US, + false, priv, cmd, ops); +} + /* Provides read access to the settings through the dynamic interface * of the switch. * @blk_idx is used as key to select from the sja1105_dynamic_table_ops. @@ -1196,7 +1246,6 @@ int sja1105_dynamic_config_read(struct sja1105_private *priv, struct sja1105_dyn_cmd cmd = {0}; /* SPI payload buffer */ u8 packed_buf[SJA1105_MAX_DYN_CMD_SIZE] = {0}; - int retries = 3; int rc; if (blk_idx >= BLK_IDX_MAX_DYN) @@ -1239,28 +1288,12 @@ int sja1105_dynamic_config_read(struct sja1105_private *priv, if (rc < 0) return rc; - /* Loop until we have confirmation that hardware has finished - * processing the command and has cleared the VALID field - */ - do { - memset(packed_buf, 0, ops->packed_size); - - /* Retrieve the read operation's result */ - rc = sja1105_xfer_buf(priv, SPI_READ, ops->addr, packed_buf, - ops->packed_size); - if (rc < 0) - return rc; - - cmd = (struct sja1105_dyn_cmd) {0}; - ops->cmd_packing(packed_buf, &cmd, UNPACK); - - if (!cmd.valident && !(ops->access & OP_VALID_ANYWAY)) - return -ENOENT; - cpu_relax(); - } while (cmd.valid && --retries); + rc = sja1105_dynamic_config_wait_complete(priv, &cmd, ops); + if (rc < 0) + return rc; - if (cmd.valid) - return -ETIMEDOUT; + if (!cmd.valident && !(ops->access & OP_VALID_ANYWAY)) + return -ENOENT; /* Don't dereference possibly NULL pointer - maybe caller * only wanted to see whether the entry existed or not. @@ -1321,6 +1354,10 @@ int sja1105_dynamic_config_write(struct sja1105_private *priv, if (rc < 0) return rc; + rc = sja1105_dynamic_config_wait_complete(priv, &cmd, ops); + if (rc < 0) + return rc; + cmd = (struct sja1105_dyn_cmd) {0}; ops->cmd_packing(packed_buf, &cmd, UNPACK); if (cmd.errors) From patchwork Tue Aug 24 11:40:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 12454839 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 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,URIBL_BLOCKED,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 ED8D1C432BE for ; Tue, 24 Aug 2021 11:41:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D3628613BD for ; Tue, 24 Aug 2021 11:41:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236849AbhHXLmR (ORCPT ); Tue, 24 Aug 2021 07:42:17 -0400 Received: from mail-eopbgr80078.outbound.protection.outlook.com ([40.107.8.78]:43248 "EHLO EUR04-VI1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S236676AbhHXLmH (ORCPT ); Tue, 24 Aug 2021 07:42:07 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Tqhv8fVZG/7cFEzNmhGEyaRtimefYz5WITH+DDyqwus8Ak3LHmineMc0+7BgOeJSE79SkjGaRO29W/kT2qQtRj6lmK3Xys8rTS5YKx5lO3dTPlxdDm5Oq2y7XaN5K4QxhVO1Poatl0lHe9eM9kM2Am1NZa/GvCbJ9V/RhZTjBiukudg36CYxVKwEBW737/X71kfa1N50/OQo4AadxwmFX5LF/v2fzUjFSZAmK4VORDyBHxPPinjBxNHhg8GkdtLALEY35ZaR+Hv2SwrvbE/lXa6cHLu4EoZUoaZhqyjJRhshRO15G8NLgtHV2nNXF7PSJqoAG1qWZijTQQgbriPoDg== 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=Gqm5Y2Dq0NDjNGf/qANFCCNYWpWuCRB8ITMXJyJXH3s=; b=B0sxDoQtjmk2VSRvPZgxa/QXYMoMaK5yL2Rb8UkiVpNNk9Ixz91an/V0d24DhORfyidBPoest8uHypjfbzdfzwR48pIwEJZTpVKd3hte9+jWzYrwhq1IV5Csf/CTS5x1tsxSVL20pIJHwB/ocnE0/eUT3LuAtBv/wdU1QMtrygA8IvMxhvTGbNS20LmgwG+EJ5D8g+wRuUnM7y+tSdlr/Np9FORGXCKLhiLBQU9zRzAU2neRKk0mbreObxnV8cVssJ9Nr+h0q6WSJ/uSIiDGg/m9w62RROhi0SlxVJWzEjI3QvEIcSake3RAKqI5KLbKmXwoCoCMGPp4UK08WfJ3Rg== 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=Gqm5Y2Dq0NDjNGf/qANFCCNYWpWuCRB8ITMXJyJXH3s=; b=Vx2zaMdwZJFrPrp4io5LjQZOu9nOBGh+prZem68Tkt53PkIhDrwF3AS/AIZKeUgAP6gLESU1NcUHT4kNoQCFM2c8uf8kBPaFixzq45IZ+mqk1y13f0QMUxTLEkLE/W7lCGlMDJP3IGrKFz9O8XkLZLv/7TpQ3+GGzK3dV43k0SU= 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 VI1PR04MB5696.eurprd04.prod.outlook.com (2603:10a6:803:e7::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.19; Tue, 24 Aug 2021 11:41:17 +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.4436.025; Tue, 24 Aug 2021 11:41:17 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org Cc: Florian Fainelli , Andrew Lunn , Vivien Didelot , Vladimir Oltean , UNGLinuxDriver@microchip.com, DENG Qingfang , Kurt Kanzenbach , Hauke Mehrtens , Woojung Huh , Sean Wang , Landen Chao , Alexandre Belloni , George McCollister , John Crispin , Aleksander Jan Bajkowski , Egil Hjelmeland , Oleksij Rempel Subject: [RFC PATCH net-next 2/8] net: dsa: sja1105: serialize access to the dynamic config interface Date: Tue, 24 Aug 2021 14:40:43 +0300 Message-Id: <20210824114049.3814660-3-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210824114049.3814660-1-vladimir.oltean@nxp.com> References: <20210824114049.3814660-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: FR0P281CA0083.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1e::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 (188.25.144.60) by FR0P281CA0083.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1e::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4457.6 via Frontend Transport; Tue, 24 Aug 2021 11:41:16 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 42d02875-b1e9-455b-7afc-08d966f415ba X-MS-TrafficTypeDiagnostic: VI1PR04MB5696: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: w/5atDwUVh9M+nBMp6CtGYnbQmPGh3HvxwDXci6IVxlSzmVGtveiavYRH+gMg8fZ8rKpfhJkDr0E6gnSDPE1FOj+MyeXbBuyLkuUZIHt1Zo9PGb2HW7DuHosCMEUHmfpBgPqQbBm/y3b+wjYUkwFtTLMZtR3l3imLwOA+0jHaY3glSonZqdyfIJA3IbgijjA2jEuocC1JeCdcseaDzZNg92Hbw0zxH6VuhBQ3qQY6m+hmmYm/y/bhI6CRgYv68GePcCTsCgpa+AmSReLJWtSYWFJJpx7gG6Zbd7iMX/bUmvZSAb55JZ41hsWgVlIrZlHEXmlDzf2w4XJOnSx000wKc38WOIfL/UhZgLNU4K6ai5rJh/UolT7ZIYlgkdxP2k6XNCAHAJzQbQ7lp7u1egICQASayhQutB/7D3joNcIjRpBQy5lpc1dPrQqHlrB+ncqcAvC5m8pIZu9NeIz+N8DlwvW19UK1v1Ht7YqMEw3uFkec5pWUygwoX98xSl812zUvrj5DAmzY5LxPlQcYDsj1GRlCPYptkZM6B9mwJQrLSTq0mVunItPGfiYUW+IyyP9Ue2vUj82efTc2BkiW+EN4sXG+gktEneDoPtBZn9EGKrgtY8UJfpLRO8PsJMjel6YCXeLKIUP3uow3dJkUFnFlD0x25GcvtRihL6cgUpDfBA2MFRxz8Kachm7Hok4SmxAY8VAUxGNoGrcETRIX/NOYNtjENHYai/JlY5AcOGvvcU= 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)(366004)(346002)(396003)(136003)(39850400004)(376002)(52116002)(4326008)(478600001)(5660300002)(6916009)(66476007)(66556008)(26005)(83380400001)(1076003)(36756003)(66946007)(6486002)(6666004)(6512007)(7416002)(6506007)(186003)(8676002)(8936002)(2616005)(86362001)(44832011)(38100700002)(38350700002)(956004)(2906002)(54906003)(316002)(290074003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: yhKl0mfF/qWIsh2/CK7f6UGUqIuC4/W/YRbbPiq41IDRBlZEXQnft8OZSDchTO123jQ8hIllp3GxPyO5kaPBpdh3meFJIjk8dB2+aqr0G9ChAhUhup99BJQXH+aHIA5ZsK0YvRZqxJwx69MT6syN34Wfm11GR1p1NY9nIj9RRVa0qJan/r5h74ssTqqzar6GNfdvdJnGircy4hYjednhXRhCaB1//lStrg1WFTVEeFcQvA+yR3NHuPUrcmVarvwd0LbscT4qislD2qm6vc5hkbWEKPgW8u0lfOlNBGapr4on28QN2WfnozZ/+rjyyz9L8TDm/dJvY0Ha91DRdONukjC01y5CCgOqQ+CsFZcSzQit68/bQvRYHC4eAHP+Ust1rqIu+vC1bl4aZg09JwBBnHoCZKaXMzzU4oeKQGaeSHOaXSsOGUdZeRlV1AXDpPR6El2iVpH7tJ1DsjVLV2ASucKsMR+auSgf5KlJy5XgxNF7cpFRcqj/olYXEiP88XV5JHk5Ko5PUPENkAm6EhuhmdrLO8dN3PcpzCBtbYKS20DqfUAQWVis48p1q47CFu8Y2Y0g1MTXKCLq2hjFHSY9mlU46lPHeAAmQ5oRj25K8lFXAqnzou4PhPiYX/PgNze5dnr16F6V90j3WJLiBD1BzyrtQ7C1SzklX+/8IHLikCdzX06ezTuhftJzjLRz5cdn1GlsdOpSPbni/bCB52tuSi2prbGP6VQ8b8lKG7OCN4r+KRViOp+M4c/6oSxqZa/iOaGbe6iVJhJWioUY5PnFep6uKZVCpEFTkGZW7Ejm28h8UhWFzeywFw8afdWHDDM/Mu5E5cntqJv2xCWgh5yESOZyCthjPU+tarI9meqaN5HWcdWPuYhhsZlr8HuiSiri3FBztFAv0Hm6kMLDPPjc9zoCPz1cWFgLAfqQW87hJ5vpz4uYgCqgzJ2I15gWmVpX+fp7zunvL1ny+3H8uR5WG7Jfq3AY25H/hKEONBKbwTc8AJl5aPtPax3a9ZvEhIHZpMf29VY5ct2yCAZZk4CI/wrLjVDr4LWLFoh21DKWs67enccL2KaEb7Fkz+aLwfnDlvDS2jE/rmkCvXDmd6mind6mK4rg5sqz5I+ekeCCY8Ih8bV9iG3i7KftC5YyK3y1JU+Etv83RLH/r5DlZfb5IRXQlCMYiNspqNFsHNLilxTCiuexN4797ZRki6qaU/5ODBNIyRsOGCBwqHSdeLnTmKYotFaAqJjVob30UPIGlu1laNwxzGx1ho6qUM6VUC4kPDlu2+OPQ9+wMooQJD2vA+HuF3cIhmFcsvCM6moOWwv//J+fortn9ii7OaoCcWIa X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 42d02875-b1e9-455b-7afc-08d966f415ba X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Aug 2021 11:41:17.3691 (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: yX0j5l/8PBmWTQoGu1jRTG9Jwdl5cVwuvVpMwwuQathjgabjfKG0h26mDDg60kK4oHsDlBrvEWtund1OITeNyw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB5696 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC The sja1105 hardware seems as concurrent as can be, but when we create a background script that adds/removes a rain of FDB entries without the rtnl_mutex taken, then in parallel we do another operation like run 'bridge fdb show', we can notice these errors popping up: sja1105 spi2.0: port 2 failed to read back entry for 00:01:02:03:00:40 vid 0: -ENOENT sja1105 spi2.0: port 2 failed to add 00:01:02:03:00:40 vid 0 to fdb: -2 sja1105 spi2.0: port 2 failed to read back entry for 00:01:02:03:00:46 vid 0: -ENOENT sja1105 spi2.0: port 2 failed to add 00:01:02:03:00:46 vid 0 to fdb: -2 Luckily what is going on does not require a major rework in the driver. The sja1105_dynamic_config_read() function sends multiple SPI buffers to the peripheral until the operation completes. We should not do anything until the hardware clears the VALID bit. But since there is no locking (i.e. right now we are implicitly serialized by the rtnl_mutex, but if we remove that), it might be possible that the process which performs the dynamic config read is preempted and another one performs a dynamic config write. What will happen in that case is that sja1105_dynamic_config_read(), when it resumes, expects to see VALIDENT set for the entry it reads back. But it won't. This can be corrected by introducing a mutex for serializing SPI accesses to the dynamic config interface which should be atomic with respect to each other. Signed-off-by: Vladimir Oltean --- drivers/net/dsa/sja1105/sja1105.h | 2 ++ drivers/net/dsa/sja1105/sja1105_dynamic_config.c | 12 ++++++++++-- drivers/net/dsa/sja1105/sja1105_main.c | 1 + 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/drivers/net/dsa/sja1105/sja1105.h b/drivers/net/dsa/sja1105/sja1105.h index 2e899c9f036d..78624851d1f8 100644 --- a/drivers/net/dsa/sja1105/sja1105.h +++ b/drivers/net/dsa/sja1105/sja1105.h @@ -248,6 +248,8 @@ struct sja1105_private { * the switch doesn't confuse them with one another. */ struct mutex mgmt_lock; + /* Serializes access to the dynamic config interface */ + struct mutex dynamic_config_lock; struct devlink_region **regions; struct sja1105_cbs_entry *cbs; struct mii_bus *mdio_base_t1; diff --git a/drivers/net/dsa/sja1105/sja1105_dynamic_config.c b/drivers/net/dsa/sja1105/sja1105_dynamic_config.c index 32ec34f181de..7729d3f8b7f5 100644 --- a/drivers/net/dsa/sja1105/sja1105_dynamic_config.c +++ b/drivers/net/dsa/sja1105/sja1105_dynamic_config.c @@ -1283,12 +1283,16 @@ int sja1105_dynamic_config_read(struct sja1105_private *priv, ops->entry_packing(packed_buf, entry, PACK); /* Send SPI write operation: read config table entry */ + mutex_lock(&priv->dynamic_config_lock); rc = sja1105_xfer_buf(priv, SPI_WRITE, ops->addr, packed_buf, ops->packed_size); - if (rc < 0) + if (rc < 0) { + mutex_unlock(&priv->dynamic_config_lock); return rc; + } rc = sja1105_dynamic_config_wait_complete(priv, &cmd, ops); + mutex_unlock(&priv->dynamic_config_lock); if (rc < 0) return rc; @@ -1349,12 +1353,16 @@ int sja1105_dynamic_config_write(struct sja1105_private *priv, ops->entry_packing(packed_buf, entry, PACK); /* Send SPI write operation: read config table entry */ + mutex_lock(&priv->dynamic_config_lock); rc = sja1105_xfer_buf(priv, SPI_WRITE, ops->addr, packed_buf, ops->packed_size); - if (rc < 0) + if (rc < 0) { + mutex_unlock(&priv->dynamic_config_lock); return rc; + } rc = sja1105_dynamic_config_wait_complete(priv, &cmd, ops); + mutex_unlock(&priv->dynamic_config_lock); if (rc < 0) return rc; diff --git a/drivers/net/dsa/sja1105/sja1105_main.c b/drivers/net/dsa/sja1105/sja1105_main.c index 05ba65042b5f..dbfbb949a485 100644 --- a/drivers/net/dsa/sja1105/sja1105_main.c +++ b/drivers/net/dsa/sja1105/sja1105_main.c @@ -3285,6 +3285,7 @@ static int sja1105_probe(struct spi_device *spi) priv->ds = ds; mutex_init(&priv->ptp_data.lock); + mutex_init(&priv->dynamic_config_lock); mutex_init(&priv->mgmt_lock); rc = sja1105_parse_dt(priv); From patchwork Tue Aug 24 11:40:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 12454845 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 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,URIBL_BLOCKED,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 6128BC4320E for ; Tue, 24 Aug 2021 11:41:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4D94C613AB for ; Tue, 24 Aug 2021 11:41:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236909AbhHXLmY (ORCPT ); Tue, 24 Aug 2021 07:42:24 -0400 Received: from mail-eopbgr80072.outbound.protection.outlook.com ([40.107.8.72]:17383 "EHLO EUR04-VI1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S236775AbhHXLmL (ORCPT ); Tue, 24 Aug 2021 07:42:11 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jsPZEFVbvqTdANN8um3Yp5xM4pojF3zrFUfCKwiXN5UncKaLUQyT92MEXTEtm4lFWJWr6RUK2yDfz71Sbw/Db8whIsQBE9sB8OAUSL1WYdqMp+xiJXv1vs2jIkRf6QflvS6r2+Jgxyl9EFPr9xrIEmjtk6/SeMyfNKIxE1uanAirmqq0aRQUDIM2C+iUBemQNY53lNG91M7wDRP5fM1lLyNpbYwtYDMGzsF+8I/k22UHN8PGpPlWoRx8Oq/KBFTIR3lSQoZ4hkZPGEH3yqcNAgTP4vCuxoWQLvdT+YuDD1m7IZYci6thWztELaeym4LuE73DBSD49/ny/RaVCCJvxw== 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=4/DfRfgxiFR2oP4mZD9EDUYD6S5gJ05WI2BI60CtH/U=; b=JaisdOUznEaciNmud5y5zyE6jiXK5SCyJh2ucf+ktHyvsgfynRYEXGdDOU6JQzfRxlqp4GVXMA6DFBoEmDakJ9wV2wz36AJHChWyUAopOFTH/Q/fYUIoEpnaGpklO9jKQ6fBxqcvGneAt9DS4P2till87RmDVbNeEFzuxSV60gkQYs7fN/KXQn4z2OH8r3mJM/fEXFsFj96+xUGZMqVx2GvbPGPbXWPUGIlF6gQy+8quzPFnb6Iaw1DAqSXbCBrWxD2T4bi7vqs3VN79tCFur3Dfaz5FMdO5SItlyu/Hjy5BIXaNxyMyk6XPIJHWeRstjlP9Sq8OiUO2Dv1r49cYAA== 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=4/DfRfgxiFR2oP4mZD9EDUYD6S5gJ05WI2BI60CtH/U=; b=S/uaawWe4CBZpSTU7sXdkyNKEQm3HnhBAQFlC9WDNQXQKgNyJ8nb16RFpJsTPzO92qStwdIvpt4oiE3T0xuAoz07ykfPKdI3xeE88WRk296zUiSUAWstPIuGxm97SabXxFgOqalbjLguflhwGFTdA2pnVeNt8b6gSVO8Deymxjk= 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 VI1PR04MB5696.eurprd04.prod.outlook.com (2603:10a6:803:e7::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.19; Tue, 24 Aug 2021 11:41:18 +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.4436.025; Tue, 24 Aug 2021 11:41:18 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org Cc: Florian Fainelli , Andrew Lunn , Vivien Didelot , Vladimir Oltean , UNGLinuxDriver@microchip.com, DENG Qingfang , Kurt Kanzenbach , Hauke Mehrtens , Woojung Huh , Sean Wang , Landen Chao , Alexandre Belloni , George McCollister , John Crispin , Aleksander Jan Bajkowski , Egil Hjelmeland , Oleksij Rempel Subject: [RFC PATCH net-next 3/8] net: mscc: ocelot: serialize access to the MAC table Date: Tue, 24 Aug 2021 14:40:44 +0300 Message-Id: <20210824114049.3814660-4-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210824114049.3814660-1-vladimir.oltean@nxp.com> References: <20210824114049.3814660-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: FR0P281CA0083.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1e::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 (188.25.144.60) by FR0P281CA0083.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1e::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4457.6 via Frontend Transport; Tue, 24 Aug 2021 11:41:17 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 75808a37-5b73-46c7-ee4f-08d966f4168c X-MS-TrafficTypeDiagnostic: VI1PR04MB5696: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: SOthDhAIatxXZHf9Plcki0nbDLkpQDWdT0ueNZfgLrnAhGyW6Xs1dq+2OKwFejJ/ubKx2gRmunm3Q55lONC5kLlBGIP9KLsrVKWzYqA7RXb9agKhHMt709t9iQqbHtDNTKwk3MvkBOavsUZGpAzNdZu49LP3hm8B8h9eI65NxhkyzaSjj7MicAolejo7g54MlZQreRXlsNlF/3Q7+ls1jgC6gJBYqAVRRSo7F6iaSCofPFGwpjQ/cYtRhjiqK1iXo+uhwm+QnZnA8Sjl0gThs5T75zuE/yiOJopA9TM27iSyXxYO3oikjdV6RzU//aiac3yZeJvIyk3NNExZ7d3kNGjMhR5DGEjYSDl2BfeS3mF3tESVCC6wPAw0OC17mu8zqiQkOfJd7qCaG+69tg2FEKND0XAyqaVsHuPDekJ0FMR6/GN+G+vXhZl11e61ke1guhW+p/sZOUpngHdsiMEvruQ89hB5tQ5ejIvgC1yAu08Vjh1ajIZXL2IHBG7QOjgNtHCBO5yZQvDWlNmMKH0z/HQ10nKAh13jDytUT/Vxp3bqhORqla4TW/0v6C0A9NEF0GfWu8uKAIujm6hyllbZ271Gez7ckIMeerMWKFIz/Rxr+BtRJGKRRHpAan9UcKPtkSt3c7UWL50VMqKqYjwYqpklSGgnHyYFGVLQQ0i0ikt2rSFsixmB8jThlBfqNwlTFaLz1hfLLfTzHQFFkctMUQ== 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)(366004)(346002)(396003)(136003)(39850400004)(376002)(52116002)(4326008)(478600001)(5660300002)(6916009)(66476007)(66556008)(26005)(83380400001)(1076003)(36756003)(66946007)(6486002)(6666004)(6512007)(7416002)(6506007)(186003)(8676002)(8936002)(2616005)(86362001)(44832011)(38100700002)(38350700002)(956004)(2906002)(54906003)(316002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Ef4GXr9CCj6exwSOHXUZJjBnqgEg46w+ZkK/PG7MTfQPT59drsc3SzjILMicFwlNApz88Ho8vmaPeycKnl3FV/6zDrrnXV4lLolGgzca+x3hzwqg729X5EZ1TNMO9B8sxm/rMlOf6OHIra1+3O7NprSx6pMDXMiX2ipIe8ixtKu1qWD44QnWjnwr0qaOLhE1/x2/Wo6llpqvTMLgQo6PINNcoPRUD6jOoI0Fg5JuUbz0gmDfTuIyz2m6kPY3LndzivPdKmMmgrzqGy3M1gS0kGqzgb1PHisH7dVthnTupACK7soIxhEcE62FR38gSoVjAOXW8z+1Jlo1AsvJlZFo3HSm2qOz1OaYJX+oSQLDJCu3QB8ZNYr0ClqifwAFvhLp6sAZq+87ta42Bg8tfqFuZhRzyFAu23u4hAUgbzLX7l9Uer10vzPwJ1ixyqTNZVJpkyazKak8QmL7/xsUAT4RK/UdSIAUJy4nPuBUF3TH7rajxoWpmk7ab93vjN8nZC6DJsgdy2Yu+rOLuXoTLTOymeCIJGqEY6qszN30/j6MmT8A0Q4gaVCoR8rRpbCQyti1JzsrZOLhyR0HRiTWLtGU/Zz4pGfIq/3foUzQecQHn3R54uExwqBSQTY4SObU4L2K/xdYVERnyrolTrNO2+3bqy1eQ5MFr3RI1xVBSQ5hAIgPH3/W+mlAVcNkwnd7FOZdmHrLI06htRzhVO52zEhjI6lNxQz1mKG1xcJoCy3XWFJcV0wx6Se+0W1pNRQOhGmz6hUt/e4rgSExl6On9S+epGYTZpkkpoIksQtNwdxUE7gPTxR4Xip9J54Q5xUQsLpiH2iu/bm61ZhawaIMzDRsTTIA9lX6USXsMDJAdvUrAC37kewaabnJx+G4d5+qR+8jz0CjYEXzJSnuO+fqFLtxSpJAXsWR+4FMPaZvVVAhdpKcR3foJtGerH2yYtcYfsa+4MVpco4NCUei0kzAHEA41e0SZpFFCVthnxF8kB60rXRjQuGrUderrBFeJcW4gEkIEIH27kGOMtvJxnpyxgFFb+fj72/RjPLE5IYGL52Ii3oMXi17IC+9awhPL692DHLCUIaXmyNjscUrhGm1WjMNH4BFIIbCoWh5t4ehKf8W0F50UkrMu23j5M7uZ23hmus/pY7xTtC6qpMu+xmuO6TkYFhXIs5JP/oSgxX569W6LJr+t8aCol60lL5KQC60Gu5X8f4sWSBiRxByxSyO1C70OBwR8T1UXuwKjSfDhGL2I1bZKwai9jmsoVrU5ni32h8izcdrZ44JC3awoHvc6MgP/zp/3oC0C9Ai4Y2HtYpTissEa2ltEpE+rOFy0M5+BJRE X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 75808a37-5b73-46c7-ee4f-08d966f4168c X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Aug 2021 11:41:18.7343 (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: pOe54dQeEsOvsOb86Esh4LBR0+XDs7T/HcEQgRtvD1Sf3DlPo5ea3O1IBGCO/foaXoElUywNY4ZT1iAFIoTCLA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB5696 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC DSA would like to remove the rtnl_lock from its SWITCHDEV_FDB_{ADD,DEL}_TO_DEVICE handlers, and the felix driver uses the same MAC table functions as ocelot. This means that the MAC table functions will no longer be implicitly serialized with respect to each other by the rtnl_mutex, we need to add a dedicated lock in ocelot for the non-atomic operations of selecting a MAC table row, reading/writing what we want and polling for completion. Signed-off-by: Vladimir Oltean --- drivers/net/ethernet/mscc/ocelot.c | 53 +++++++++++++++++++++++------- include/soc/mscc/ocelot.h | 3 ++ 2 files changed, 44 insertions(+), 12 deletions(-) diff --git a/drivers/net/ethernet/mscc/ocelot.c b/drivers/net/ethernet/mscc/ocelot.c index c581b955efb3..9f481cf19931 100644 --- a/drivers/net/ethernet/mscc/ocelot.c +++ b/drivers/net/ethernet/mscc/ocelot.c @@ -20,11 +20,13 @@ struct ocelot_mact_entry { enum macaccess_entry_type type; }; +/* Must be called with &ocelot->mact_lock held */ static inline u32 ocelot_mact_read_macaccess(struct ocelot *ocelot) { return ocelot_read(ocelot, ANA_TABLES_MACACCESS); } +/* Must be called with &ocelot->mact_lock held */ static inline int ocelot_mact_wait_for_completion(struct ocelot *ocelot) { u32 val; @@ -36,6 +38,7 @@ static inline int ocelot_mact_wait_for_completion(struct ocelot *ocelot) TABLE_UPDATE_SLEEP_US, TABLE_UPDATE_TIMEOUT_US); } +/* Must be called with &ocelot->mact_lock held */ static void ocelot_mact_select(struct ocelot *ocelot, const unsigned char mac[ETH_ALEN], unsigned int vid) @@ -67,6 +70,7 @@ int ocelot_mact_learn(struct ocelot *ocelot, int port, ANA_TABLES_MACACCESS_ENTRYTYPE(type) | ANA_TABLES_MACACCESS_MAC_TABLE_CMD(MACACCESS_CMD_LEARN); unsigned int mc_ports; + int err; /* Set MAC_CPU_COPY if the CPU port is used by a multicast entry */ if (type == ENTRYTYPE_MACv4) @@ -79,18 +83,28 @@ int ocelot_mact_learn(struct ocelot *ocelot, int port, if (mc_ports & BIT(ocelot->num_phys_ports)) cmd |= ANA_TABLES_MACACCESS_MAC_CPU_COPY; + mutex_lock(&ocelot->mact_lock); + ocelot_mact_select(ocelot, mac, vid); /* Issue a write command */ ocelot_write(ocelot, cmd, ANA_TABLES_MACACCESS); - return ocelot_mact_wait_for_completion(ocelot); + err = ocelot_mact_wait_for_completion(ocelot); + + mutex_unlock(&ocelot->mact_lock); + + return err; } EXPORT_SYMBOL(ocelot_mact_learn); int ocelot_mact_forget(struct ocelot *ocelot, const unsigned char mac[ETH_ALEN], unsigned int vid) { + int err; + + mutex_lock(&ocelot->mact_lock); + ocelot_mact_select(ocelot, mac, vid); /* Issue a forget command */ @@ -98,7 +112,11 @@ int ocelot_mact_forget(struct ocelot *ocelot, ANA_TABLES_MACACCESS_MAC_TABLE_CMD(MACACCESS_CMD_FORGET), ANA_TABLES_MACACCESS); - return ocelot_mact_wait_for_completion(ocelot); + err = ocelot_mact_wait_for_completion(ocelot); + + mutex_unlock(&ocelot->mact_lock); + + return err; } EXPORT_SYMBOL(ocelot_mact_forget); @@ -114,7 +132,9 @@ static void ocelot_mact_init(struct ocelot *ocelot) | ANA_AGENCTRL_LEARN_IGNORE_VLAN, ANA_AGENCTRL); - /* Clear the MAC table */ + /* Clear the MAC table. We are not concurrent with anyone, so + * holding &ocelot->mact_lock is pointless. + */ ocelot_write(ocelot, MACACCESS_CMD_INIT, ANA_TABLES_MACACCESS); } @@ -1028,6 +1048,7 @@ int ocelot_port_fdb_do_dump(const unsigned char *addr, u16 vid, } EXPORT_SYMBOL(ocelot_port_fdb_do_dump); +/* Must be called with &ocelot->mact_lock held */ static int ocelot_mact_read(struct ocelot *ocelot, int port, int row, int col, struct ocelot_mact_entry *entry) { @@ -1078,33 +1099,40 @@ static int ocelot_mact_read(struct ocelot *ocelot, int port, int row, int col, int ocelot_fdb_dump(struct ocelot *ocelot, int port, dsa_fdb_dump_cb_t *cb, void *data) { + int err = 0; int i, j; + /* We could take the lock just around ocelot_mact_read, but doing so + * thousands of times in a row seems rather pointless and inefficient. + */ + mutex_lock(&ocelot->mact_lock); + /* Loop through all the mac tables entries. */ for (i = 0; i < ocelot->num_mact_rows; i++) { for (j = 0; j < 4; j++) { struct ocelot_mact_entry entry; bool is_static; - int ret; - ret = ocelot_mact_read(ocelot, port, i, j, &entry); + err = ocelot_mact_read(ocelot, port, i, j, &entry); /* If the entry is invalid (wrong port, invalid...), * skip it. */ - if (ret == -EINVAL) + if (err == -EINVAL) continue; - else if (ret) - return ret; + else if (err) + break; is_static = (entry.type == ENTRYTYPE_LOCKED); - ret = cb(entry.mac, entry.vid, is_static, data); - if (ret) - return ret; + err = cb(entry.mac, entry.vid, is_static, data); + if (err) + break; } } - return 0; + mutex_unlock(&ocelot->mact_lock); + + return err; } EXPORT_SYMBOL(ocelot_fdb_dump); @@ -2085,6 +2113,7 @@ int ocelot_init(struct ocelot *ocelot) mutex_init(&ocelot->stats_lock); mutex_init(&ocelot->ptp_lock); + mutex_init(&ocelot->mact_lock); spin_lock_init(&ocelot->ptp_clock_lock); snprintf(queue_name, sizeof(queue_name), "%s-stats", dev_name(ocelot->dev)); diff --git a/include/soc/mscc/ocelot.h b/include/soc/mscc/ocelot.h index 06706a9fd5b1..682cd058096c 100644 --- a/include/soc/mscc/ocelot.h +++ b/include/soc/mscc/ocelot.h @@ -674,6 +674,9 @@ struct ocelot { struct delayed_work stats_work; struct workqueue_struct *stats_queue; + /* Lock for serializing access to the MAC table */ + struct mutex mact_lock; + struct workqueue_struct *owq; u8 ptp:1; From patchwork Tue Aug 24 11:40:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 12454843 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 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,URIBL_BLOCKED,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 A2F98C4338F for ; Tue, 24 Aug 2021 11:41:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 82AF2613AB for ; Tue, 24 Aug 2021 11:41:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236903AbhHXLmW (ORCPT ); Tue, 24 Aug 2021 07:42:22 -0400 Received: from mail-eopbgr80078.outbound.protection.outlook.com ([40.107.8.78]:43248 "EHLO EUR04-VI1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S236774AbhHXLmL (ORCPT ); Tue, 24 Aug 2021 07:42:11 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hZaOj0x7xLP9dm7RD6shpQIblPwgB9VOXhCbgGPC/Map5KlDGSvvTkPYs9nekMGW8NxauXLJEDqyWtWvpF2USj82obO+xmiDaRLkcM2ylz3cSxaBuPGbTgoAMvaK4rZCKP8yshArTdWw+LNaivKxJ1yXY5cUPaN7FOD1CTfO018tCUt9GBy5Q0/srzAcqRbfFvaw6/M8o6scpIKiUGE5eWr2EuMLJNUVP9l+CWR5H96PlTVusahsvVgY3Y1Umc8pw0UU11OEfs/ylbRrmNiQgMAS44NcQVAVV3wO735A9DSuRDwIlCinOgIOQHKRnZFRgTs2YpmXCPgXdqUInZIBhg== 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=m4Ugnd81hKhHlTpRVY8Nb2stkXAxgneolJ9hOoPr6Xc=; b=GLdiiT6G7ZahyZ2uUPX56t9mCuZVTZSavms1m+9SOu1YScOWF1kuouQB7YuxcRUXXyPeXaJjXi1JAMctJX4Ihfcv2BHYAbUW7Yp4XV/RrXlmvDldCxzEt5EwZIbMH6YW/tcNjHTpvEco/MI8yS0Ks+rMxJOcOmSlqtFYhtjR8ccplPZ+0SA1mv3RzKkGnyYPBhvmXxkeeftNqc3iiF0VYN1yvmXNnCyEJS3E/wI3yKKByZbTeOHEDINL04Q/r+F17keVuitSZhreoo2aL+FjmdyJpgkAL8lXoMl2vGpjSkVz0Ez/H1F8vOyqVAmCTkGBWs+nRSxir6As46sHGgqWfw== 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=m4Ugnd81hKhHlTpRVY8Nb2stkXAxgneolJ9hOoPr6Xc=; b=is6QJ/FVLUBsyxUTBEufrdOzAtCJWr00sjwR18S2fbBjodp1qSOX2IreviWax92Nbl8MqxQv4O8eVIsNXFFZWos9+gdlUG7pseDO3E5qcVElr3/0LF2QQbSPMKsgI205f0MHkdimJYbR48LjWh419uIH0IKC/YbBrLnNnxzjERw= 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 VI1PR04MB5696.eurprd04.prod.outlook.com (2603:10a6:803:e7::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.19; Tue, 24 Aug 2021 11:41:20 +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.4436.025; Tue, 24 Aug 2021 11:41:20 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org Cc: Florian Fainelli , Andrew Lunn , Vivien Didelot , Vladimir Oltean , UNGLinuxDriver@microchip.com, DENG Qingfang , Kurt Kanzenbach , Hauke Mehrtens , Woojung Huh , Sean Wang , Landen Chao , Alexandre Belloni , George McCollister , John Crispin , Aleksander Jan Bajkowski , Egil Hjelmeland , Oleksij Rempel Subject: [RFC PATCH net-next 4/8] net: dsa: introduce locking for the address lists on CPU and DSA ports Date: Tue, 24 Aug 2021 14:40:45 +0300 Message-Id: <20210824114049.3814660-5-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210824114049.3814660-1-vladimir.oltean@nxp.com> References: <20210824114049.3814660-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: FR0P281CA0083.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1e::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 (188.25.144.60) by FR0P281CA0083.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1e::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4457.6 via Frontend Transport; Tue, 24 Aug 2021 11:41:18 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 34b58d73-2128-4661-b8a7-08d966f4175b X-MS-TrafficTypeDiagnostic: VI1PR04MB5696: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: FZAC3pD5nHWW05vMGx3a53f7y+XErsNM+xphIhwus5+tKN0SWaGUD105RI6YMmnkEU42Wmapilld68+kBEt11Xws9lEKu9tZb8edYxxUpSYBmNxm0n9x9LQdi4sTyQYGA/al6dkDqI5Pw6iQYHqgsRBwJvlcvtnPnbia4GI/AWEQg9YKql1gUcMdAkTeupL8zC3HFQixPW8JF2XvMzJUmFaZgZMudVJgJEYuuINfYzzb7D4Dq2H2Z8dq2WHObc/t/0LjKZTI6RcjgUJf8mJr+I5gHNmzorvuJDGapsThplHRIWY5S/DvcszFuKDAM9CjCqagPHeJSZxdRSr6+nuL4Gr4gdtPrR3CwPAoiUAM6S0C2qBYunYT8CyD5n316j7ATkWq+03/8Me24DnPV72hJPWURpQRmI6Twu/HIhK2cKaBYHG+CPNwtNWefa24XIenXG2qiDAEYa1zbgv1CpBFGI1GoWC29RVSP1dHXMHsfp0XZZzhFFI1auaDC7kJzi+KmxkyRVZ1uuzgFq8GXjv4o3unGfsiLn7FMCTMqa9n0gWKp2TWyBriEKAkdPghzYXPemHovGMiTaEVTgASCTonfYNXsZiGJ+dfl1EVibB2UL0mrSzYjL0KxelYXFIzx9dP5dlo9O8dDN5B1SlkaNWGOEfDyF2KdPNys1/2V8H/huEmO18afxsbcBpeGx8MNbymRhQdekqEdKdutf18+CN5NA== 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)(366004)(346002)(396003)(136003)(39850400004)(376002)(52116002)(4326008)(478600001)(5660300002)(6916009)(66476007)(66556008)(26005)(83380400001)(1076003)(36756003)(66946007)(6486002)(6666004)(6512007)(7416002)(6506007)(186003)(8676002)(8936002)(2616005)(86362001)(44832011)(38100700002)(38350700002)(956004)(2906002)(54906003)(316002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: vrGTC4Ihhunp88mC6+4ktqtxnQfJf10M3B7QcYD3ZdatayTD6B0MYm2PUpGaxNh1GykhzsRCB28W5wmPhcUcL9ujqz5+ADo+Rw6Pn4E9u9MPSWzy+2h/3uUlZEBVfFQuHF6nt/987/jlmxh6lW3OJVPHCF9kDKHsGo83CobbJDAfhi8RKXD4JTBXxOh15pkorniqFN8H/6LE6NDbHNr5cf4q6ntoCsuU8Isw201Zx7QK6rD9B2xVPA7fktaYSo92ohMc1rIrYZDu+4PIkLH/3JHQoSk+6ibw4w6f0bV8FxGO8gDuV8RuhS7DrVi2Xhp1Qoi3VYxw93JRPd40lxNb40AXbjZ9lsGctrnDXAam4LPigCRjqmft6x72lJQRd1TOBR9aZ3Vy6/7WyLPZBAV+tDEwjKKZ57YfyS5TxuytHUq1SEOtqqL7x1hHlTUN4SvxcSXfOQ6KrgTFi6b2EzIywj+R7nwic68hhh/Vk3SXe8iuvJ/RxPJPEQLJqpzSs2Xd1daNdystddTk+80mPshkwYeBmOOLTpfC2E4MCQlHfrrl90h+2PXEFJF+mwwqeK78u4j8cz4ayIenaGbDTVPjuLn6JMjdE2XnT7MYP0upXkCEZPSxpVhU4mq5n6i7t2XjvKnfKugoqqy6sL5Wu+wJNBShO5+LSU+EjQj0DOX4JaHrU2hgJ6F0lQGEzCJafbmRHk5HnSTE82ADSwxCYy32U982GfgZ/IqZSYOxtASRRKFNG/+fq4ZZbPBlSXIVTmW02OpySuom/mjQ/NFhZ/kugK/15ZC2w1LLfQz/FMH8WG0l/4dJfdsokoice7LZAMCZ3lm9/t6m++99zF17O1QKI43IE4mVIkIgTTcBlOJQeiqavmz+fYynhgq5mPm1+75N797yw1bnGLX9tt6Xl2ehGb/osgqu8ZVIEWYZaehtsShpJNF16cXPM2gtPHUTJtcLUa1etIQUMDchzBkVkmeNDkzRglF4/E2Jj1D5WG12oA1Bw9Z+A1mE0nmEeTbjMhwfwN05BXsD4p2aZaR1cwNlMYG+DIvsPsJb41dp007RRAz8kSzvveoPlq87QVsbNhrqrV2CEGbGcUHRC+uxlzBOj2DuTuz7Enk88xaw6Z7bi2egP1AYDz10MSEyv/hAzS7V4n9Yhf+b6YkiH/WZlZ78d7Esh1EiJNzFSGwlExgpDFdHGgRltpsFNiq66v8h8puKgG7eaYvVnr9K3AQmZRM2MMiK/e3Vzx2cA7IojZ48r9zSOxtjze02W6Vh3/KRTFCRimlHP1OyPOuBq989Bf+I+eztTSB12cHTAl3VM/edjRLHNOZTy5QgXoJHFzwtusNs X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 34b58d73-2128-4661-b8a7-08d966f4175b X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Aug 2021 11:41:20.1365 (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: RfrQVEfVLA4HbbaoCeWCcvMifr+p5/Q6QspZVYA2pcTO+Z2SZTFAcBrNq8QbgkhxYXcjFqxfzOjkNa+n7pcqzQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB5696 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Now that the rtnl_mutex is going away for dsa_port_{host_,}fdb_{add,del}, no one is serializing access to the address lists that DSA keeps for the purpose of reference counting on shared ports (CPU and cascade ports). It can happen for one dsa_switch_do_fdb_del to do list_del on a dp->fdbs element while another dsa_switch_do_fdb_{add,del} is traversing dp->fdbs. We need to avoid that. Currently dp->mdbs is not at risk, because dsa_switch_do_mdb_{add,del} still runs under the rtnl_mutex. But it would be nice if it would not depend on that being the case. So let's introduce a mutex per port (the address lists are per port too) and share it between dp->mdbs and dp->fdbs. The place where we put the locking is interesting. It could be tempting to put a DSA-level lock which still serializes calls to .port_fdb_{add,del}, but it would still not avoid concurrency with other driver code paths that are currently under rtnl_mutex (.port_fdb_dump, .port_fast_age). So it would add a very false sense of security (and adding a global switch-wide lock in DSA to resynchronize with the rtnl_lock is also counterproductive and hard). So the locking is intentionally done only where the dp->fdbs and dp->mdbs lists are traversed. That means, from a driver perspective, that .port_fdb_add will be called with the dp->addr_lists_lock mutex held on the CPU port, but not held on user ports. This is done so that driver writers are not encouraged to rely on any guarantee offered by dp->addr_lists_lock. Signed-off-by: Vladimir Oltean --- include/net/dsa.h | 1 + net/dsa/dsa2.c | 1 + net/dsa/switch.c | 76 ++++++++++++++++++++++++++++++++--------------- 3 files changed, 54 insertions(+), 24 deletions(-) diff --git a/include/net/dsa.h b/include/net/dsa.h index f9a17145255a..bed1fbc0215c 100644 --- a/include/net/dsa.h +++ b/include/net/dsa.h @@ -285,6 +285,7 @@ struct dsa_port { /* List of MAC addresses that must be forwarded on this port. * These are only valid on CPU ports and DSA links. */ + struct mutex addr_lists_lock; struct list_head fdbs; struct list_head mdbs; diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c index 1b2b25d7bd02..8ddf10e27d85 100644 --- a/net/dsa/dsa2.c +++ b/net/dsa/dsa2.c @@ -435,6 +435,7 @@ static int dsa_port_setup(struct dsa_port *dp) if (dp->setup) return 0; + mutex_init(&dp->addr_lists_lock); INIT_LIST_HEAD(&dp->fdbs); INIT_LIST_HEAD(&dp->mdbs); diff --git a/net/dsa/switch.c b/net/dsa/switch.c index 1c797ec8e2c2..40e28eedac59 100644 --- a/net/dsa/switch.c +++ b/net/dsa/switch.c @@ -214,26 +214,30 @@ static int dsa_switch_do_mdb_add(struct dsa_switch *ds, int port, { struct dsa_port *dp = dsa_to_port(ds, port); struct dsa_mac_addr *a; - int err; + int err = 0; /* No need to bother with refcounting for user ports */ if (!(dsa_port_is_cpu(dp) || dsa_port_is_dsa(dp))) return ds->ops->port_mdb_add(ds, port, mdb); + mutex_lock(&dp->addr_lists_lock); + a = dsa_mac_addr_find(&dp->mdbs, mdb->addr, mdb->vid); if (a) { refcount_inc(&a->refcount); - return 0; + goto out; } a = kzalloc(sizeof(*a), GFP_KERNEL); - if (!a) - return -ENOMEM; + if (!a) { + err = -ENOMEM; + goto out; + } err = ds->ops->port_mdb_add(ds, port, mdb); if (err) { kfree(a); - return err; + goto out; } ether_addr_copy(a->addr, mdb->addr); @@ -241,7 +245,10 @@ static int dsa_switch_do_mdb_add(struct dsa_switch *ds, int port, refcount_set(&a->refcount, 1); list_add_tail(&a->list, &dp->mdbs); - return 0; +out: + mutex_unlock(&dp->addr_lists_lock); + + return err; } static int dsa_switch_do_mdb_del(struct dsa_switch *ds, int port, @@ -249,29 +256,36 @@ static int dsa_switch_do_mdb_del(struct dsa_switch *ds, int port, { struct dsa_port *dp = dsa_to_port(ds, port); struct dsa_mac_addr *a; - int err; + int err = 0; /* No need to bother with refcounting for user ports */ if (!(dsa_port_is_cpu(dp) || dsa_port_is_dsa(dp))) return ds->ops->port_mdb_del(ds, port, mdb); + mutex_lock(&dp->addr_lists_lock); + a = dsa_mac_addr_find(&dp->mdbs, mdb->addr, mdb->vid); - if (!a) - return -ENOENT; + if (!a) { + err = -ENOENT; + goto out; + } if (!refcount_dec_and_test(&a->refcount)) - return 0; + goto out; err = ds->ops->port_mdb_del(ds, port, mdb); if (err) { refcount_inc(&a->refcount); - return err; + goto out; } list_del(&a->list); kfree(a); - return 0; +out: + mutex_unlock(&dp->addr_lists_lock); + + return err; } static int dsa_switch_do_fdb_add(struct dsa_switch *ds, int port, @@ -279,26 +293,30 @@ static int dsa_switch_do_fdb_add(struct dsa_switch *ds, int port, { struct dsa_port *dp = dsa_to_port(ds, port); struct dsa_mac_addr *a; - int err; + int err = 0; /* No need to bother with refcounting for user ports */ if (!(dsa_port_is_cpu(dp) || dsa_port_is_dsa(dp))) return ds->ops->port_fdb_add(ds, port, addr, vid); + mutex_lock(&dp->addr_lists_lock); + a = dsa_mac_addr_find(&dp->fdbs, addr, vid); if (a) { refcount_inc(&a->refcount); - return 0; + goto out; } a = kzalloc(sizeof(*a), GFP_KERNEL); - if (!a) - return -ENOMEM; + if (!a) { + err = -ENOMEM; + goto out; + } err = ds->ops->port_fdb_add(ds, port, addr, vid); if (err) { kfree(a); - return err; + goto out; } ether_addr_copy(a->addr, addr); @@ -306,7 +324,10 @@ static int dsa_switch_do_fdb_add(struct dsa_switch *ds, int port, refcount_set(&a->refcount, 1); list_add_tail(&a->list, &dp->fdbs); - return 0; +out: + mutex_unlock(&dp->addr_lists_lock); + + return err; } static int dsa_switch_do_fdb_del(struct dsa_switch *ds, int port, @@ -314,29 +335,36 @@ static int dsa_switch_do_fdb_del(struct dsa_switch *ds, int port, { struct dsa_port *dp = dsa_to_port(ds, port); struct dsa_mac_addr *a; - int err; + int err = 0; /* No need to bother with refcounting for user ports */ if (!(dsa_port_is_cpu(dp) || dsa_port_is_dsa(dp))) return ds->ops->port_fdb_del(ds, port, addr, vid); + mutex_lock(&dp->addr_lists_lock); + a = dsa_mac_addr_find(&dp->fdbs, addr, vid); - if (!a) - return -ENOENT; + if (!a) { + err = -ENOENT; + goto out; + } if (!refcount_dec_and_test(&a->refcount)) - return 0; + goto out; err = ds->ops->port_fdb_del(ds, port, addr, vid); if (err) { refcount_inc(&a->refcount); - return err; + goto out; } list_del(&a->list); kfree(a); - return 0; +out: + mutex_unlock(&dp->addr_lists_lock); + + return err; } static int dsa_switch_host_fdb_add(struct dsa_switch *ds, From patchwork Tue Aug 24 11:40:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 12454847 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 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,URIBL_BLOCKED,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 85848C4338F for ; Tue, 24 Aug 2021 11:41:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 64832613AB for ; Tue, 24 Aug 2021 11:41:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236876AbhHXLmZ (ORCPT ); Tue, 24 Aug 2021 07:42:25 -0400 Received: from mail-eopbgr80078.outbound.protection.outlook.com ([40.107.8.78]:43248 "EHLO EUR04-VI1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S236803AbhHXLmO (ORCPT ); Tue, 24 Aug 2021 07:42:14 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=U53a8pmtLg5EH5gDCnv3yuJK1r9TCCXXEc2wJGhzxUuvhxk4q+xOABN7FUDg41lN7cw0dpIaBD/qi+UhWkEtxke5k915QsUfz4sVkGmjI/MA0stkU8R2n+1ZGuMh/TejhyJUXXTb9Va1ejj6r7KveZR7c7BCCsEluzVyVpQMdECvo2G0oxD6E2N2jPUZsPFpUUYXF2aJ/Xx08Dakq/UBxpYzNS3qGkgQGScwBP7EtWCTsX3eTC3zWSxYHOK1mf3GedHMDNnx/hwLc0Jw4uLYLGNVl6m5fsEoje9MNuQ9Tmsqh5PlyAV1k+C++ZwMQHkYOztWpP3veeXjvYyCjZwmLw== 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=1MLoEG/rnDqVFrRVQuKAgy3tKTMZTYxjQ2iWsAUtwgw=; b=ZUWOhinC2e3D1a7u1M8NI0C9VOFkwfqJ4ZO7FCPOtct0HcZtO8V6Av9lvQsaQnOeIjjfqaQjPfa4qjBwj25VftmZswv/SK5IwUTdcgt2Skf6ZjGUOjvkNF7WQyp+FpeY1lBmijDnFTed5nAl95WRWwvSm1j13ejrEhzkAyogAGgqB+zP76rtEmPa/oVszXkMqVXGgl6R9GDHrMTFH/o/YTC29QuT2L4in7ZVWFwZ7SJWLtO4lMYo6j+M8TvWelCMs9axMRDuPKeVu8FKpWa2pM0/ufTD0ZYWQBSBee0pLUp4rL4aChuwM+0KjcDPTeWMtCHiD2D4RrKDdrnqGr1pyw== 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=1MLoEG/rnDqVFrRVQuKAgy3tKTMZTYxjQ2iWsAUtwgw=; b=qx21YIy4+9svLSmublr0VNwH/Xy/UWlxcWNObGB1+FerT1IDsCxi04FWqwsYAtXkbn8mnrex49ZfX4x4mU73OHgPWZvm8r/k45Svvucpkf3qSh8+N5cbE+cBVXAQ/C39B5VCM5AIjl4upG/w/4JnrxnB+2IsKosDZwwz2hxlShA= 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 VI1PR04MB5696.eurprd04.prod.outlook.com (2603:10a6:803:e7::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.19; Tue, 24 Aug 2021 11:41:21 +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.4436.025; Tue, 24 Aug 2021 11:41:21 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org Cc: Florian Fainelli , Andrew Lunn , Vivien Didelot , Vladimir Oltean , UNGLinuxDriver@microchip.com, DENG Qingfang , Kurt Kanzenbach , Hauke Mehrtens , Woojung Huh , Sean Wang , Landen Chao , Alexandre Belloni , George McCollister , John Crispin , Aleksander Jan Bajkowski , Egil Hjelmeland , Oleksij Rempel Subject: [RFC PATCH net-next 5/8] net: dsa: drop rtnl_lock from dsa_slave_switchdev_event_work Date: Tue, 24 Aug 2021 14:40:46 +0300 Message-Id: <20210824114049.3814660-6-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210824114049.3814660-1-vladimir.oltean@nxp.com> References: <20210824114049.3814660-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: FR0P281CA0083.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1e::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 (188.25.144.60) by FR0P281CA0083.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1e::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4457.6 via Frontend Transport; Tue, 24 Aug 2021 11:41:20 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 3c95c00a-84b0-4e76-7115-08d966f41832 X-MS-TrafficTypeDiagnostic: VI1PR04MB5696: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6430; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: q3ieuOD15rLjv8GNVwC0WbdX1tbW/KXlrqdq/NYmXDy2b5b9IRMUAelf/uHWJE2nfCJJYh745ji+wUyldd+miUS0i4ggIgAZNxxr+WZXITOlTDFOJlEeKeVeRVZqD6fMEd/PK36B57qxIs2nVuW8ZQe2mz+CVy12jZUYPZuZbxUegNN9iUyppRC05oCzJVSMJRy58uYtSdgyrun0THyQSetldPkgbwJfCrofrPtuH+YbrwoCMGFCeOBzLbcxQ/JL2CNFDPw+ertFpiTXJ3xcfTIBfi0VY3+D1VGXbgetx7Po0ufLJsa46Dg1SYC+1JDP+7ZDhAkdLQ0jgANNGBvKxWxGzWD+qJrg5+2/SZPzhWJmorRs9ZNx5Mc5pBvFjM8rK3HcaI+MDdGDskOP41KNOxdWMaz1p70VS88JbGftvj0LawRoZoVhpI4ylc3xgPVsxhp+D2STv5LpH8/z+J7TqFsEyQu+/92UvEXzd8Gvfa1XdILATleOYrybi8AyZBT4FpW3VCeCec+0hshHSMCi08xIGKmQ/D3b51FFcWbpD8yzevP99L+0+gPwOS9s5m6s6zjCbjCZZhTUp6e2ExTJ7hs6jFM0f2Cl8yoSdZcEu8DifLry7mUVgAAva3mPtST8yG1R4yU5YgDNA9Kvy9BnnLHyC4hDHB4rAIrN5f2cy6qSIEShSBUhRM//IXC4Tulh2j/XpV/VKftF9sWAFI3Nbw== 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)(366004)(346002)(396003)(136003)(39850400004)(376002)(52116002)(4326008)(478600001)(5660300002)(6916009)(66476007)(66556008)(26005)(83380400001)(1076003)(36756003)(66946007)(6486002)(6666004)(6512007)(7416002)(6506007)(186003)(8676002)(8936002)(2616005)(86362001)(44832011)(38100700002)(38350700002)(956004)(2906002)(54906003)(316002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 48Qjl3ZBzyZQRFJXaNWyCRHIc8H6wqhwKJqk8FUhY4WxHhn647ka3Wz/fX5Zckjeu7mGmwJLZZIRsIB6TDyExcik1yUuco58A6SGz18NGAFPJ46rpuiuX79cTJE6UOmzpUUWtPEMWb486Y/XmpM8DJBpXZQC0lpcjuab8GfD3H5A2iGm/0Om37ckk/MbEzdliCySNf3uTPCc0q/CNbOaVrDhVCdgyFdIdexd7DJe/k7MO9xOt9dykhoy6crcpp4m6mFkihRLrAuRE+f8NoDmWPNfrFk6UZeU/KBTLQtXEfHbB0YQkVDyUCJrBMCnyrfkQZK0WCwqk8ZC7+dhW9bJMFuG9VGajOH2YM0EntYm33QMgbrbBbrv/2kpkWvcHRfsh1lpsYNTPXsGMonpVwCpahRmMXNXYwcgwzZCMX/WSEbMfyn3kgbUqPksywNSwexN57KS9h7FOLRcrMY9us1fRnojes0CDP4VIzoDJH0k8TDnl29qvW57BlpHz1X1NeL2qD3ZXsqHIiwKJnqK7GesRKFz0C5Ej3kmNVLkbJ/ZUTcZxL2n61tT65gnQVGtPC+L+Cbyr/xiKpQbljF7r1WH5LHu0GrE3JcipAurSIw6ftNeBs+a4I8m54QjxjtWQHYlPotQitd8skDKrzWhovbNCe0eUTvx3YXW/T9fDtM6wTpY5OLoJ/FYpyX4Tlf01jjZsAzimbzxfKa+2LbfMnp+QEZArxM8yJqN+IhPFMCUmqkgb21E2JVfAoiaohdzweklo7zzJmIxt9GchTYEpiHhBYvAuyXHTqOSy8k7c/QgaO9YczUbROwCfIJc4z3xBIIjklwnknwRYP22kUjIZLY6FE1vgBFsRfuILXsrU9k6o3QJ3BgDBO+1zvUV7nAGADr1IiXkg4mqa8P20DetuXjF1k6MekhzcK2phZbJfrMtcKDzL16AiqLegQM7XauQQj+AcpQfM9qvMqxD0vsgByRzbVWzZ+zKqvnRXQSAxR4EjaXylZVTpeajB2azBqYh67tQGoa55wsipz5OkRHZKXfiCIfj6RUZ2Z3mvMj+P8oh+7Hmtw2gw0wGJ+XXuxjqdmofIzziqAAQ1mEcl9CE5A6igScXSz37zAk3BcB7eBlwcHw3YHYMUXRTW16jnO5vr1oUpSW1aWEOcgLpjWoxVocIVMMkOW/PFS+ZJySvNUDHFzc8ug/phpYxtFKLlkHotWad4uVlEYtn58lOdFKudPAiqn3ePxK71Nzfzg69aXXjLJBK8BEGCKYV46lM2AhS9yShrClQ+CLsWPYZTc9j00qRv2sAHLqNSv5okWSdnQkPG854MiwcXKb9TNMSKKMUsL5D X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3c95c00a-84b0-4e76-7115-08d966f41832 X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Aug 2021 11:41:21.4867 (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: x5uoLMkB4eTfCAcRllI9TYEFvUAgCCDtuDrDP/BcQbk29rL+IW0KkJKeg8T3sDcK2gRin3qEYqqZmpNZWEzObw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB5696 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC After talking with Ido Schimmel, it became clear that rtnl_lock is not actually required for anything that is done inside the SWITCHDEV_FDB_{ADD,DEL}_TO_DEVICE deferred work handlers. The reason why it was probably added by Arkadi Sharshevsky in commit c9eb3e0f8701 ("net: dsa: Add support for learning FDB through notification") was to offer the same locking/serialization guarantees as .ndo_fdb_{add,del} and avoid reworking any drivers. DSA has implemented .ndo_fdb_add and .ndo_fdb_del until commit b117e1e8a86d ("net: dsa: delete dsa_legacy_fdb_add and dsa_legacy_fdb_del") - that is to say, until fairly recently. But those methods have been deleted, so now we are free to drop the rtnl_lock as well. Note that exposing DSA switch drivers to an unlocked method which was previously serialized by the rtnl_mutex is a potentially dangerous affair. Driver writers couldn't ensure that their internal locking scheme does the right thing even if they wanted. We could err on the side of paranoia and introduce a switch-wide lock inside the DSA framework, but that seems way overreaching. Instead, we could check as many drivers for regressions as we can, fix those first, then let this change go in once it is assumed to be fairly safe. Signed-off-by: Vladimir Oltean --- net/dsa/slave.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/net/dsa/slave.c b/net/dsa/slave.c index 662ff531d4e2..53394fb43d67 100644 --- a/net/dsa/slave.c +++ b/net/dsa/slave.c @@ -2381,7 +2381,6 @@ static void dsa_slave_switchdev_event_work(struct work_struct *work) dp = dsa_to_port(ds, switchdev_work->port); - rtnl_lock(); switch (switchdev_work->event) { case SWITCHDEV_FDB_ADD_TO_DEVICE: if (switchdev_work->host_addr) @@ -2416,7 +2415,6 @@ static void dsa_slave_switchdev_event_work(struct work_struct *work) break; } - rtnl_unlock(); dev_put(switchdev_work->dev); kfree(switchdev_work); From patchwork Tue Aug 24 11:40:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 12454849 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 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,URIBL_BLOCKED,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 9BEDBC432BE for ; Tue, 24 Aug 2021 11:41:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 84BB9613AB for ; Tue, 24 Aug 2021 11:41:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236910AbhHXLm0 (ORCPT ); Tue, 24 Aug 2021 07:42:26 -0400 Received: from mail-eopbgr80072.outbound.protection.outlook.com ([40.107.8.72]:17383 "EHLO EUR04-VI1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S236805AbhHXLmO (ORCPT ); Tue, 24 Aug 2021 07:42:14 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kvTD5cZlKHA/vC5c0GQrvMDAO9IllX5JgbZ+KjvcX8N3l4BSizHCNKUSHbVTT8wMuPcE4HwqJgNUBbl/zi+s5bKCxeB6sV8PnWo0GGJGIQ/67YLg3VOVIprzbiECe1sRC6xbxGLyY0JI4Y4REwi62eOtQeutDkXiyEXPByXoriKUtfJX6vG0768Q1e2dJTjON6TyItzUro55lq82VOmkVU+sn/t58LXY5OLz4AHdzeIu3hFMJYhy232dn4CSAzolRTBWQezWiXOVmuHKVa1mi52mJnya3VOX3zhJtS8V4ll2rIWkgjdtFhTl4T23EPRMzi6SuYC0dcjeRGXfOFE7SA== 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=uo7LVho/kFD/bfGRA6FWrHB4Us/8LmkEQ8QHsCtz8Cw=; b=aYHR0wrgUkdZoNBEWGeNyXc80m1J8YESymXLpnyXJUEwcCRtZxnGWI9jNHX5dHF8v3I8hSApvwp4C5E940RHa0MxYZNZ/fF/uEp29qqMRl6a43JbzInUIHTzAxVAHssUfxZB7+DTE+nwmo0cFTm9qggwwWKZGO6YS003f0hLC3g7eRm4jgowsR9RFZpzrPHCjsueHBDjTigFKeu93x/dt49TCq0csPpTMnv2oJFIfb0rngNmu0+pkl8z1PLd+8Q7IjlN3EsEtUklEpnD9u+cHwOXciyVzSLXUC3vNTybcOUDWGMCQHqRQOUmCc6uMtRvmsKm0LrTWU7cBePtd77fvA== 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=uo7LVho/kFD/bfGRA6FWrHB4Us/8LmkEQ8QHsCtz8Cw=; b=FRf0gue1ZuMU3IzNy565eSt4vMYaMtc7GTglbCLkM5MklV0LgB+aSm6VmWwv0gMI7SNTVPEUBSLtZSwWjlqgWMb7oJQWk56ikP9cYYRjODS+IZjQOLEZQrkMjBTgPucNwDjuiQHGaew3SsWT5nYBncLPu/Wm/t9LCPEVK9G0eq8= 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 VI1PR04MB5696.eurprd04.prod.outlook.com (2603:10a6:803:e7::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.19; Tue, 24 Aug 2021 11:41:22 +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.4436.025; Tue, 24 Aug 2021 11:41:22 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org Cc: Florian Fainelli , Andrew Lunn , Vivien Didelot , Vladimir Oltean , UNGLinuxDriver@microchip.com, DENG Qingfang , Kurt Kanzenbach , Hauke Mehrtens , Woojung Huh , Sean Wang , Landen Chao , Alexandre Belloni , George McCollister , John Crispin , Aleksander Jan Bajkowski , Egil Hjelmeland , Oleksij Rempel Subject: [RFC PATCH net-next 6/8] net: dsa: flush switchdev workqueue when leaving the bridge Date: Tue, 24 Aug 2021 14:40:47 +0300 Message-Id: <20210824114049.3814660-7-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210824114049.3814660-1-vladimir.oltean@nxp.com> References: <20210824114049.3814660-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: FR0P281CA0083.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1e::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 (188.25.144.60) by FR0P281CA0083.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1e::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4457.6 via Frontend Transport; Tue, 24 Aug 2021 11:41:21 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a225940b-0d0d-4a56-9fdb-08d966f418f7 X-MS-TrafficTypeDiagnostic: VI1PR04MB5696: 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: D8MgFHXJMLLKfwkH80Yg+a5dqRPdPgEAo6u/IrwTvdnebaNSO/Sg9rwmHMIygX56G3xCaCuqZNt5lkBTVmBW+zLc2hNP/XIryhiV9vyrUuorYe6gDjZzhoIvj2GPaOCXQ2K7RqTtmPbCIlx5R2vSpC976p7VEp8GAVNcRQsgTI99Z8ddYdwsZHtEBrSTkLTFvyWTp/9ahipCgRrmxT5JrBr6sRXmfWWB8mGg2lCsyfm+ZDIf5OOB5D+jkI0WGaDs3kwu/1NXhslYCScxiMOEtk3i8fXwPTrLLr8PU39sFV22uPZgTXrJyqswDZhiBvAf6rIfTrywx86C/E2HJ1qinkSH1kCdJKRaXwu5HlDiVxVGIhGSyYwLDyFQUwpQMqUOukZloyJnIQfCGC4FB0oT5xYYoGK9vRifGVBhA9Jo3c0w/eqIC1nPRBL/sfAoc6vh08G2lI3IVxsgRYWp1R2EoGY+SgBbosZC1N8FbLr29KvGAxAHbVfYZVVIPXUwr22zxmhhFAUjPkvlbsC/CcXq3hGhk+z6E5ZglfOLPU7ORFZEm2j2D/nEW4scSXlnDfjtpDRK6GXzRTlkYtDbc3T9jvirFwhKIAj5O71e6+bT1o95XYV9vtb6wTrawe/e2yxMB6xQ0PX4A+6zcU8SmNExjjvQKkkXxD/5Mus+DIdVU9ISXUh6IF7LP6gWOKDtd2gKyT31qdRdxCZsI6vQAH/lNAxQYHT1mta0+xnGvkShtvTG4z90xD+/coUB8ULaVodtkotwRkRziDH5qGD1D7aztA== 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)(366004)(346002)(396003)(136003)(39850400004)(376002)(52116002)(966005)(4326008)(478600001)(5660300002)(6916009)(66476007)(66556008)(26005)(83380400001)(1076003)(36756003)(66946007)(6486002)(6666004)(6512007)(7416002)(6506007)(186003)(8676002)(8936002)(2616005)(86362001)(44832011)(38100700002)(38350700002)(956004)(2906002)(54906003)(316002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: hDySbr6IwGD3RR2FyUZHYgcqOQTQnaQUMdjfaLoUBRUORwesUvlfMuRCrW+gdu9Ukv7LXuA73xTXrf+wamLIelTpbCp9369KUx6UosK0LuICOTSn8OsVITIqXRdTVv4HDfsXQ7Wc6nqPNUx+5Vgtu2ARd5NXWuN48W9fbRKDUQtZPIs/mz8TY3kp8+j4hAzDPvne6QwBv0Di/jICHMjMOTIsmEy2z7mMT6pEieHpjxPtdEWa1lrBVZLeiLSblay/km6mpLUs19mLkc6/fz3xEPcBY+m9VBRAnWuvFED2SU9IUALs6XxtutBjIGmHl9/BmTPU6cJeqZwbWQ1craDVlXLvSrSaAg2hL+xENE3OsvDEe04PL+tgkcNwwsFCsh9un0EzmeSiSU6q9yaCZLAevURj2N2G/0zYOCFfB7zxvZwo8QUf2/FlYhVpk2VHbvhtmlVvJH+5TJ3J5USwCaHPYh3+9XSJfb2yGz6sm/YSTqmueX9QEi1wluUwubApoN+VX+Rl8Jzn1Ti53DkqECHJ2LYH3BHnAz4+TX1SoAneloyNk1KZTlL4ZyZ/yEDsddS4RQ9N061xH53nxqG1UjAz2gqWzQxekat7iYSlOn5Z7YdC7kH1nLvfKV2j8HSY5oLmXGfMtrwHTw//0q9T5IQMk9RSyQBjYEpwlunTINSPAq1Kx4QcnEaoAF9nuYhITpL5whdfNnXxvo7mmnVGzpInKkZudzbjV8/uEGKpD/moQ1oeJHGTu8uaBpdShgB6B79OjkgTmEGE8MnqqkOcOvJnBFWOp9/EpYm68997qmHucSFPK4CWq2zo5VSnKu7651KtpogP2w4LNpd9+BJU0TpgDNFbFUIIkvJAaWxOLVaIUXyglY8oh5KrNM9sCJN1gyl6kwIljkkjjOPxmLHNXUvFWQYLqkoioPtePZanAkxvHSVcQe/FcrTjnhee+SfDfSx6rZH1naV08WBMu7CnWfZ6yoSnYcV/sY6aCFTr2UvSGirpg9LwRLHiAyFbsDSZqVA/zsAS988vdeTsHkebrHvtcTyqvZaTN/Y0qQZn6YdRz6hhU+ovIywsKexE9tKF0QTozsuZh7AIW1gs7ti3UY+RyP1rGRDmtyhSokTM+jwt0zjbGlT62+dWrSOCevz1FS2o+C/8spzVamuB+cYL0YS39hsplNmTzmX+2+s9U3jqH3F3T6QwMuzhucj0UA28cmZBrGwxEUIWrSMIcAaFxndCLuhXMhv3fRSqOdv8U0CPtKYuTTpvmYj1c3AzZTbF6pgQpe7qSfQmeEaLaNI0IszKP+n1iMaI3OWhhwd0wEa3WeZnwSDyV83Tns+yQl+gZ+Nn X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: a225940b-0d0d-4a56-9fdb-08d966f418f7 X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Aug 2021 11:41:22.8179 (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: 9Xq92tuHw4qCTver4AnC/qAtem2YqeWG8ZjTpXc22hRyhJL35LJ6Ja+X78OawygQ+qA6GRasjv+XZ5bp8wuSAw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB5696 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC DSA is preparing to offer switch drivers an API through which they can associate each FDB entry with a struct net_device *bridge_dev. This can be used to perform FDB isolation (the FDB lookup performed on the ingress of a standalone, or bridged port, should not find an FDB entry that is present in the FDB of another bridge). In preparation of that work, DSA needs to ensure that by the time we call the switch .port_fdb_add and .port_fdb_del methods, the dp->bridge_dev pointer is still valid, i.e. the port is still a bridge port. Currently this is true for .port_fdb_add, but not guaranteed to be true for .port_fdb_del. This is because the SWITCHDEV_FDB_{ADD,DEL}_TO_DEVICE API requires drivers that must have sleepable context to handle those events to schedule the deferred work themselves. DSA does this through the dsa_owq. It can happen that a port leaves a bridge, del_nbp() flushes the FDB on that port, SWITCHDEV_FDB_DEL_TO_DEVICE is notified in atomic context, DSA schedules its deferred work, but del_nbp() finishes unlinking the bridge as a master from the port before DSA's deferred work is run. Fundamentally, the port must not be unlinked from the bridge until all FDB deletion deferred work items have been flushed. The bridge must wait for the completion of these hardware accesses. I have tried to address this issue centrally in switchdev by making SWITCHDEV_FDB_DEL_TO_DEVICE deferred (=> blocking) at the switchdev level, which would offer implicit synchronization with del_nbp: https://patchwork.kernel.org/project/netdevbpf/cover/20210820115746.3701811-1-vladimir.oltean@nxp.com/ but it seems that any attempt to modify switchdev's behavior and make the events blocking there would introduce undesirable side effects in other switchdev consumers. The most undesirable behavior seems to be that switchdev_deferred_process_work() takes the rtnl_mutex itself, which would be worse off than having the rtnl_mutex taken individually from drivers which is what we have now. So to offer the needed guarantee to DSA switch drivers, I have come up with a compromise solution that does not require switchdev rework: we already have a hook at the last moment in time when the bridge is still an upper of ours: the NETDEV_PRECHANGEUPPER handler. We can flush the dsa_owq manually from there, which makes all FDB deletions synchronous. Major problem: the NETDEV_PRECHANGEUPPER event runs with rtnl_mutex held, so flushing dsa_owq would deadlock if dsa_slave_switchdev_event_work would take the rtnl_mutex too. So not only would it be desirable to drop the rtnl_lock from DSA, it is actually mandatory to do so. This change requires ACKs from driver maintainers, since we expose switches to a method which is now unlocked and can trigger concurrency issue in the access to hardware. I've eyeballed the existing drivers, and have needed to patch sja1105 and felix/ocelot. I am also looking at the b53 driver where the ARL ops are unlocked. The other drivers do seem to have a mutex of sorts, but I am fairly skeptical that its serialization features have really been put to the test (knowing that the rtnl_mutex serialized accesses already). So any regression test from drivers that implement: - .port_fdb_add - .port_fdb_del - .port_fdb_dump - .port_mdb_add - .port_mdb_del - .port_fast_age is appreciated. Signed-off-by: Vladimir Oltean --- net/dsa/dsa.c | 5 +++++ net/dsa/dsa_priv.h | 2 ++ net/dsa/port.c | 2 ++ 3 files changed, 9 insertions(+) diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c index 1dc45e40f961..8e7207c85d61 100644 --- a/net/dsa/dsa.c +++ b/net/dsa/dsa.c @@ -345,6 +345,11 @@ bool dsa_schedule_work(struct work_struct *work) return queue_work(dsa_owq, work); } +void dsa_flush_work(void) +{ + flush_workqueue(dsa_owq); +} + int dsa_devlink_param_get(struct devlink *dl, u32 id, struct devlink_param_gset_ctx *ctx) { diff --git a/net/dsa/dsa_priv.h b/net/dsa/dsa_priv.h index 33ab7d7af9eb..1dc28ad4b8a8 100644 --- a/net/dsa/dsa_priv.h +++ b/net/dsa/dsa_priv.h @@ -170,6 +170,8 @@ void dsa_tag_driver_put(const struct dsa_device_ops *ops); const struct dsa_device_ops *dsa_find_tagger_by_name(const char *buf); bool dsa_schedule_work(struct work_struct *work); +void dsa_flush_work(void); + const char *dsa_tag_protocol_to_str(const struct dsa_device_ops *ops); static inline int dsa_tag_protocol_overhead(const struct dsa_device_ops *ops) diff --git a/net/dsa/port.c b/net/dsa/port.c index 616330a16d31..65ce114b9fc8 100644 --- a/net/dsa/port.c +++ b/net/dsa/port.c @@ -380,6 +380,8 @@ void dsa_port_pre_bridge_leave(struct dsa_port *dp, struct net_device *br) switchdev_bridge_port_unoffload(brport_dev, dp, &dsa_slave_switchdev_notifier, &dsa_slave_switchdev_blocking_notifier); + + dsa_flush_work(); } void dsa_port_bridge_leave(struct dsa_port *dp, struct net_device *br) From patchwork Tue Aug 24 11:40:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 12454851 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 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,URIBL_BLOCKED,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 BBCE2C4338F for ; Tue, 24 Aug 2021 11:41:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A5F37613AB for ; Tue, 24 Aug 2021 11:41:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236928AbhHXLma (ORCPT ); Tue, 24 Aug 2021 07:42:30 -0400 Received: from mail-eopbgr80078.outbound.protection.outlook.com ([40.107.8.78]:43248 "EHLO EUR04-VI1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S236792AbhHXLmQ (ORCPT ); Tue, 24 Aug 2021 07:42:16 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YCiNSjYoSXI/WTwuZhhEhIGbo3hoe8uv5DoZ7txFHFisi3EiOwaIeWGRg7/6sSHNi+cPWxrYwZ8HiaMpxSuJYk2d4JZ40bR2ScHquAVBg11vedbejNPaTm+Cx1AYVTkZ4GF2mySUbdlNvuyYGa/2hks1jNQCbwYTDNSsumJACWdVzBFZoYcb6fTZk2lQnZxj8OxEIpH3DXgFKjcymmPaYmu0yTZ6CXsQ8qNiL/SgtrGGkdxnkBSPr1UwD9t5IhtRjycgwgHSzZmG+iap2jnlt564nmJq/lXKHpQ474+1wYlrmYXGg3D6ESq26+u0/Vx0XrMx9mIV9VU6DgEeq/BTuQ== 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=julJjQ5thhy4WTbSi++wwssjpxuglr6L/wHoMXBpEI0=; b=aYc9ZVRp+Jh0dekuBzI49P2FkUj+K7p6h3MUJ5ickhL5w1z+Kbm9P+N8yOVam21mEwNzsW9OuV5AKX8U9R7kFhOaCSyZUfmTlRZrgjWG9XnhSr40hn45jT+4fsZLaaTkZ7S/RSPTdrTMjAS/f0hlzkWjAUgBIP4nsaDL70oQMOeiofp2S+u/KfPINixGvCkiVZFDKNH4F9twos9r/UpcSQvy2r2N1YpG6v0/ABdsBvSjF6sgC8OCP9vFYQplCTjx3PuwwVLCY1zVRyF0nQnCemCQP1DyzkR98gPHLu52cXwHHNa67TwRMECI3mbdNg23qCTE4bdXYK4ievLniyDvkQ== 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=julJjQ5thhy4WTbSi++wwssjpxuglr6L/wHoMXBpEI0=; b=E3XWAa1zsSXByAoHVzErjmHo8SAYHl5e7roKPibJzoj9liywMgnEfL9egDKeHWknpMx0b3OaLdwl7pxOBhy66b/Jlfqgi443U6CX2aw6zQ9TXWk+qXLQg4bWlZUuWzK2O7i8zDJ6266nczAXqgwk+ib4YQ7BRns9ocQ0qpcBrc8= 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 VI1PR04MB5696.eurprd04.prod.outlook.com (2603:10a6:803:e7::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.19; Tue, 24 Aug 2021 11:41:24 +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.4436.025; Tue, 24 Aug 2021 11:41:24 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org Cc: Florian Fainelli , Andrew Lunn , Vivien Didelot , Vladimir Oltean , UNGLinuxDriver@microchip.com, DENG Qingfang , Kurt Kanzenbach , Hauke Mehrtens , Woojung Huh , Sean Wang , Landen Chao , Alexandre Belloni , George McCollister , John Crispin , Aleksander Jan Bajkowski , Egil Hjelmeland , Oleksij Rempel Subject: [RFC PATCH net-next 7/8] selftests: lib: forwarding: allow tests to not require mz and jq Date: Tue, 24 Aug 2021 14:40:48 +0300 Message-Id: <20210824114049.3814660-8-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210824114049.3814660-1-vladimir.oltean@nxp.com> References: <20210824114049.3814660-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: FR0P281CA0083.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1e::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 (188.25.144.60) by FR0P281CA0083.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1e::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4457.6 via Frontend Transport; Tue, 24 Aug 2021 11:41:23 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8da4861f-5f61-4dcd-c0a1-08d966f419cb X-MS-TrafficTypeDiagnostic: VI1PR04MB5696: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1079; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 3cv4L+tDJTf+aO5X4jwdGO7RRoPIfg4LAVAAb3vRSJlDpwxUPRFkxQZk9XZsi0ZAxwjHXwOZmEmFuKtLPwP0DYxf4rgmliyFsOak9mVL7vknqB2d/xaHXhE29kA7ktCb/rHUGOcQ3Zqjo5JrpXjI1/DzYOSskSC8XzElYoUtMT47hRuGnITXpYT33z9PrJDY0M3LgisWrUpsST30wxWMRquOoPASPWkc60cfYdU8GGVuIYYZM5xneVnAlzIdO1y52zlBWc3ur8TTe4CBKB/fVzwv9h/qU+Kyretk8ZS8dbIymwYHuXlzeFzksdrnkCsowrdU67uHd5Ieu/65ZZ9VAc6jwRNVVlxr2ZE0jrK1zKaboGvvXjfYlm8MuFlvxElqVf0tNLbnmgOU9YWXwRc8G4Qq+qgs27S9nj0GFuvylF8Xz+oQI4sGBzj5IEgaiNyvC3FEDcyIjD+jHWYhA5jVggfHx8ROg8of5B3sIYUjUB6dgx3ChtfBTUL9Vp12nngvlznqKAsrlAvSq1bw5e1kMiI+JViQ4wfuU5hCGh53E/vrABVAwLY+zUuHXEPoz3QXwz6InDMV+9cPEk/LqGoj+KIsJvyjhSycuvEqhYtfmNgOz03lVrIofyF422K5Mlh4/1jy30yjvJ0XIG6nM7gySHHzGxyL3hPJ6MvPc/Ftk/Rw4Bm2z5LFOPaygR0QxvBB5p0ShICRRYApuyHq4RRXYQ== 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)(366004)(346002)(396003)(136003)(39850400004)(376002)(52116002)(4326008)(478600001)(5660300002)(6916009)(66476007)(66556008)(26005)(83380400001)(1076003)(36756003)(66946007)(6486002)(6666004)(6512007)(7416002)(6506007)(186003)(8676002)(8936002)(2616005)(86362001)(44832011)(38100700002)(38350700002)(956004)(2906002)(54906003)(316002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: XDEPxSxFxJGNQ01W1dXQOuqthYWtfKFcSTnl6CgVM/MhvHhOaXvFlXT6lGFLQ6sJygUwtjI3gO+C/f02QHCRuEdrAkG6ZcvOEA42hKLno85Qm3r1rgq+LH/yUBnxQpnE/KrYyCXD/3s1mMceVXXk0Ul81Y4WZZDGrQBYBQTP0xBFBYUqP/XnCsa1zGIRd6mQzIfC6Bs39jP8t7caNA1kjnHF2FUX6ZypXhFp1DTotlOtw2zFYbGPMUyinWC4wSe9A4wXYQFjDd67qeayQjUrQaGWQdx5DKk27Svq/BqiyDOzkJRGrwJ/oMVhnao888Af8vpbLXxDWPVnqazRR7aKjLqw740hbAI/bZjcvWadWdgCsc+EZc1JJ/+blWDMwrTAE1HK2kUwIaEOSOuNGid+tOHMjSo/WiySqZ8tPt1IlFR2tEwhugpPFJY1VuUxUdA3h0TKWhqUOKM3rxqqED6T91wRBc3uqnDUL4+sBDV6uHgymwDR2z1IGtyPE6i2Y+oAC39vnLNqenvySS1rhxRr3wTke9ZTYpFI4DB6NlR2PC2K3ghw+LcKPiclDqR2OMyBOBEU/uUBh+ffpfzRNLAI+Wpcipjs8du+5rZmLnXqLjl54qcjk6wUIgRhHDbkxm+AA6gxuxXaDWkAsfkgpmEcbiOHwVKGVPtIXxTI57Xvws39YPEzbnrcJx1etRtuOj0eKE3ExjTzbI5N4NFf8w9SUtnBYJGRRwTxMCLRij97I1+Ysp2iygLLD/HhNtzL/MPriOs03hVk7/qQZfKPptR/p5IdCFow4/60Bb1cYelDaP+uf0xurIkeWmwPUlaAU5LbhHZMqDrAYsN2cV63HLacq/1/i4a+L4TMFS9u7OH1R+kCTjBxk8p9evfRGQ+ERyTuYpmI9Wx7Llb+cMmRJW3GY+kTsPMHQfVU0IeVtl/O4O8XPLLiHInNeG7o78ypOO3eLZqaLhpzE1QFOqgi8/a/ZUyeXSP4l9UhJ+NPVgxxCGj2lpTUkOGHLMgP4voHD7xUtxzq1psNaIYk5MAkgN35JIGEPxD6cAxDhAqSsWMtaXcrYedjr1imOD8TNqKqSCj+PmB31emHkB1xuK5RmXs9na4h2/ZlLB5Im7XJXcBX8YZrF3/DhJ/Leq7p+nGZPOM+5p+VoY1k9UNJ1YfP8GUSauEMmzaJiyhManK48DdRmWBVarfVGmbIp2VbuXmwuECihrr51q+MXVMxvNTL/q6ul6Gg9uHPfhsTAnqCQEyyXHXOfJ7HRTClVNlzI7jrxA2KpCg4GCB60aN6cMxeVz34RgYQiiy3QvoM0xIHu6LkpXOJXd0wvBMDFdlyFC6Q+DB2 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8da4861f-5f61-4dcd-c0a1-08d966f419cb X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Aug 2021 11:41:24.1851 (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: /uqZeUX1+8YALbga8LCwn9Uc37SezlmYyZ1L+WV2T6lQJLSP9TzOtwJhHpvRbNE/soD3s5/ldf8XhDLNwxgUfg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB5696 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC These programs are useful, but not all selftests require them. Additionally, on embedded boards without package management (things like buildroot), installing mausezahn or jq is not always as trivial as downloading a package from the web. So it is actually a bit annoying to require programs that are not used. Introduce options that can be set by scripts to not enforce these dependencies. For compatibility, default to "yes". Signed-off-by: Vladimir Oltean --- tools/testing/selftests/net/forwarding/lib.sh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/net/forwarding/lib.sh b/tools/testing/selftests/net/forwarding/lib.sh index 42e28c983d41..b937472d2e17 100644 --- a/tools/testing/selftests/net/forwarding/lib.sh +++ b/tools/testing/selftests/net/forwarding/lib.sh @@ -20,6 +20,8 @@ MC_CLI=${MC_CLI:=smcroutectl} PING_TIMEOUT=${PING_TIMEOUT:=5} WAIT_TIMEOUT=${WAIT_TIMEOUT:=20} INTERFACE_TIMEOUT=${INTERFACE_TIMEOUT:=600} +REQUIRE_JQ=${REQUIRE_JQ:=yes} +REQUIRE_MZ=${REQUIRE_MZ:=yes} relative_path="${BASH_SOURCE%/*}" if [[ "$relative_path" == "${BASH_SOURCE}" ]]; then @@ -138,8 +140,12 @@ require_command() fi } -require_command jq -require_command $MZ +if [[ "$REQUIRE_JQ" = "yes" ]]; then + require_command jq +fi +if [[ "$REQUIRE_MZ" = "yes" ]]; then + require_command $MZ +fi if [[ ! -v NUM_NETIFS ]]; then echo "SKIP: importer does not define \"NUM_NETIFS\"" From patchwork Tue Aug 24 11:40:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 12454841 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 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,URIBL_BLOCKED,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 E7C4DC432BE for ; Tue, 24 Aug 2021 11:41:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CFB08613BD for ; Tue, 24 Aug 2021 11:41:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236885AbhHXLmU (ORCPT ); Tue, 24 Aug 2021 07:42:20 -0400 Received: from mail-eopbgr140059.outbound.protection.outlook.com ([40.107.14.59]:35148 "EHLO EUR01-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S236781AbhHXLmL (ORCPT ); Tue, 24 Aug 2021 07:42:11 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GM6bGaEniJNC80CPdZm3xVhwteVHbs5RGv4v7y0cTeSw18wA5qSxFBDYTwqA1uEZ36S9Sl5gEace43LrUJxbhzKwaVFy3bEbwrOyN+y3RxQGCsc6W+TTbNv+zrVlgRL9HyHls4r9ogTgXX25Tg5lXWPaHtNdTKEiQgGKtsA6yh7SPb1U91+3i0ktWD7GB6qsqiJGHUXPMHJbE5CRQfm9zli1GTkP8r62krLGtxhv8K4bdOF3FCNX7sMQo1I5Q26ifeiBNry29St9j3oUc1HT++85jiYkTKFP/u6cS6S+Cs/uYtsODFlmICWm8xik2fWY5IDPVYLCuMJuP9L6nxaJhg== 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=6zYHwQs9eClKuTbenfncX6ggQq2V/kVMCgpGj+9AXqI=; b=HMcGvtk8wr7mT21G/AFr32CDOygcbm+ouRd6vKGnB0zfllt7ResQU81N8BJdVwYTPutEi/UBtG5UhrIuYetROEVvg811cHTBxtQykvTOPF152uXGNBImQf4y4ccLBCE8/o2A9lf8xJX8G9H4tC+bmnflurKZ4D2tJ9+XM5wUdCmWiiBLVXc6Q/TdxErFMwNYXFWUiJwbmM9/cOxbYCjujifWqmYR+DmUbtWoITOBzaAohS7feO+Dr4qQH+iwZ/GcVbGELNl+HV/lgzmWyOScXSOwE6cjq/W4d7CmCHUgzZ2N7o9E8kE8u2S9zHgLWlxAtTPu5IBa4E0Qkigp/+EkSQ== 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=6zYHwQs9eClKuTbenfncX6ggQq2V/kVMCgpGj+9AXqI=; b=gxhkq3ux8ResW6VvTkkuiFpXvHDOFrJzMbb8bMIi2c6oTKjjQvSl2SZYqxCeagLOVPYjNxYSrhUQiZqHLp18Deljmd2fqlN5CSQFKOBQC2093fNESpn1wsi7E1Cou4NHuNv7f6uH7Ab3IeYcgC5dJdchAx6ARqlOL9IT/w9OgKg= 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 VI1PR04MB3070.eurprd04.prod.outlook.com (2603:10a6:802:4::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.22; Tue, 24 Aug 2021 11:41:25 +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.4436.025; Tue, 24 Aug 2021 11:41:25 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org Cc: Florian Fainelli , Andrew Lunn , Vivien Didelot , Vladimir Oltean , UNGLinuxDriver@microchip.com, DENG Qingfang , Kurt Kanzenbach , Hauke Mehrtens , Woojung Huh , Sean Wang , Landen Chao , Alexandre Belloni , George McCollister , John Crispin , Aleksander Jan Bajkowski , Egil Hjelmeland , Oleksij Rempel Subject: [RFC PATCH net-next 8/8] selftests: net: dsa: add a stress test for unlocked FDB operations Date: Tue, 24 Aug 2021 14:40:49 +0300 Message-Id: <20210824114049.3814660-9-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210824114049.3814660-1-vladimir.oltean@nxp.com> References: <20210824114049.3814660-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: FR0P281CA0083.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1e::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 (188.25.144.60) by FR0P281CA0083.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1e::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4457.6 via Frontend Transport; Tue, 24 Aug 2021 11:41:24 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 238e44d3-ff3e-40ee-ef72-08d966f41a90 X-MS-TrafficTypeDiagnostic: VI1PR04MB3070: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: VQMz4I+ufN2EqdEavoGF84kxYXgmbJeLRdYpE2uuoHdw8vjcOKGF9X4nqre6XXbrKM0lMwEVrX6tc5WYM8Dv+SWAut2X6mwhi+cDDFBioGqzWtLufZL9Lip4M9W6d8ADE98LB9hJWik4R4javh3fP1dcq81A4zUPVJFLp2FXWthgoNwIXuDf3J57cShhsgrL6EAEseIX6zzncYF8X1uAmvKdYV9zlgWzPiYqN7CGiMC5AOXFq3d+UqPmx49rbv1/viYPKBZmjPBft8b9YnKMSDnwK+lmSbGMLWKOm5UTkjtlNfqCvtCgF6rrCwV95UZX1WODa/HhZFPFzcriiyBwb+qJUL2y11s9hpvSLihsmw76UVdeYbSwivJ7U1usdHhv8daafwzeXFhBxzrXqOvy1qeKetZnO7wXdFKtDjO9Dp/dq6xqESwUuoUwJ1ccVhAnWbPhWUJ4jIa4HR/9PkdmEv1bjwoTx0F7bqgdis8zgyyr/heFbDnVRdpfOtb4n8gaVJxYkE75CcclrbYs/zbDtUhwx8YYs+TJ7gsuc7Tn0+nIiDEY4iKYpSPy/f+RbZgJ5AzFvbD6IQf697stwyAfwz6OlKNm9mdANUt2iYUpnJXFvpl2eucN0sWURtjALbuTXEsnamPuEhKePQKPhnY4DwGnyONO9csqJtkXX6Xi/ZwT5/a1eEznESmmPdwezyZb/ejWGBgvbYa9JigJqgQPnQ== 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)(346002)(376002)(366004)(396003)(39850400004)(136003)(6486002)(8676002)(66556008)(66946007)(186003)(5660300002)(66476007)(6512007)(4326008)(86362001)(1076003)(956004)(36756003)(26005)(2616005)(6916009)(316002)(6506007)(52116002)(44832011)(8936002)(478600001)(6666004)(38350700002)(38100700002)(83380400001)(54906003)(7416002)(2906002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: dvBR75Kp6m/qTlaiNBMFxeYf+XvbV9oo3x2yamF0Da4fx0NT5MlYhEWcX977Ixur48kuG+e4uCdeJTBv/vQ2M0i8wenuu+3ILkoUVmwqUV3DRg6BGGcTNvdzIWc/9nFHCOqNhsRsW9Q/IlYMnO3N4TYXO84etihp4WTwYzwi2xUY9EAMtShMPt9uWYBwAbCCmTYRZlsNbDzk2aVAm+3XT+AySFaOc/GQj7JSjX5rxe0Iuk9xjE6ekwHLC3XsGw0KkH3yH9BTqDJhHIArDUzRJcHH5mvZ+Zz2TR+zm490fjvdOrn/uPIEL6aRA+lgfasJSuBDiMHCn5sWwQO20uRqgNQw6XojK4nBKzTy4ND7F0FZIt2FbQoVy2y8hCMDfO1hO81tvfYXxkkkKNnXstYE+4J6/JK9HHbkcaV+fE/C9YQ5H5qol9/4ar7qBb46Cu+PjTikaAf+EkOtWL/wdLHWqV66J8fgtZddFp8eNdtS1hqW1kFFDnBLZFQ6DgqqjHJd1ebrvTwD9qqXkVBvRQbXYoO+vue/bFvgQ1IiPewWmA7m2584tTQlNusa6Ko16LAv9lw4NKBQVxqc4BHxgZgyK+39RmyoiTVw/lsaQNLA60gCM/Xgyog78vCeLlVbAyIRaKPrQ2cE1uT/ll5T+/yDO1z+TCCzBKQY3bwoFTELQRugCvydVdAdg5xqDrvBbbxrZOAASKeKDK5oPjL7F6jEmiS1OxM1hXo5i2wVEbyG8WeS6urJqC08Hh5bWmW9MOmzsfNnCpUMB9VRJNgGXJyyuGSf2MZnAtEp5+WEOey0IPvF0hkyLZPV54UI/xP16vNUEbjEelZbx3kKjnlnxqr/2bv6G4EypendTyXIBnI/r9w/+BN5wi2bsr7q0OTrQ7HVWuzmvfgODSjUYjdhbSuWXESnfligO/ZiSi8RpkO1SD2Mu/GpfHK1LoQAOuxd8GE1AEUXOSSRIgRLx0+THAAcIBSypX51k/vBX6C1mR5lVkPKzeEnsLtPL5N2ISTZdBGw6eGqOZUDSKi2bWrhQ03TNZVHZE9ZRQ3d3JqMQfouOMQnWEbsLIhrD7qMql8NTLe4w9cV0cpB+h3m8DLoLw6dohD6i8oaY9dMDgDhuNPf3jv7mwirg+D7j9VgFp2oPVu6+lRCgjjc3M1LgSWE9a/hw2gfS5MA2vIsWW/f4ibMUSc8YmR7FvNcycjimtOORwHBEm+Euany9FQvLsMSjTEzLCjS2vQmYtWfM2Z9/SASNTvZ6CkakhnFtg/n9t0fNYitb5bSGqafjYvXfU75EMq2vYMm7DVJK/VN0OSVwgxEfZuSRaBfqyklz6j+Dmb9QPPr X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 238e44d3-ff3e-40ee-ef72-08d966f41a90 X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Aug 2021 11:41:25.5074 (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: UFAhKNqir5GbWvXaElLH0X7idTjRKegVLtptd8wzfXz8zqMfQpx9qQqYwPUmb5bqkbX5aaKBq3VsUKrgUbK4Qw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB3070 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC This test is a bit strange in that it is perhaps more manual than others: it does not transmit a clear OK/FAIL verdict, because user space does not have synchronous feedback from the kernel. If a hardware access fails, it is in deferred context. Nonetheless, on sja1105 I have used it successfully to find and solve a concurrency issue, so it can be used as a starting point for other driver maintainers too. Signed-off-by: Vladimir Oltean --- MAINTAINERS | 1 + .../drivers/net/dsa/test_bridge_fdb_stress.sh | 48 +++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100755 tools/testing/selftests/drivers/net/dsa/test_bridge_fdb_stress.sh diff --git a/MAINTAINERS b/MAINTAINERS index 06e39d3eba93..23b65ef5f11a 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -12958,6 +12958,7 @@ F: include/linux/dsa/ F: include/linux/platform_data/dsa.h F: include/net/dsa.h F: net/dsa/ +F: tools/testing/selftests/drivers/net/dsa/ NETWORKING [GENERAL] M: "David S. Miller" diff --git a/tools/testing/selftests/drivers/net/dsa/test_bridge_fdb_stress.sh b/tools/testing/selftests/drivers/net/dsa/test_bridge_fdb_stress.sh new file mode 100755 index 000000000000..cdb7f9ca2251 --- /dev/null +++ b/tools/testing/selftests/drivers/net/dsa/test_bridge_fdb_stress.sh @@ -0,0 +1,48 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 + +# Bridge FDB entries can be offloaded to DSA switches without holding the +# rtnl_mutex. Traditionally this mutex has conferred drivers implicit +# serialization, which means their code paths are not well tested in the +# presence of concurrency. +# This test creates a background task that stresses the FDB by adding and +# deleting an entry many times in a row without the rtnl_mutex held. +# It then tests the driver resistance to concurrency by calling .ndo_fdb_dump +# (with rtnl_mutex held) from a foreground task. +# Since either the FDB dump or the additions/removals can fail, but the +# additions and removals are performed in deferred as opposed to process +# context, we cannot simply check for user space error codes. + +WAIT_TIME=1 +NUM_NETIFS=1 +REQUIRE_JQ="no" +REQUIRE_MZ="no" +NETIF_CREATE="no" +lib_dir=$(dirname $0)/../../../net/forwarding +source $lib_dir/lib.sh + +cleanup() { + echo "Cleaning up" + ip link del br0 + kill $pid + killall bash + echo "Please check kernel log for errors" +} +trap 'cleanup' EXIT + +eth=${NETIFS[p1]} + +ip link del br0 2&>1 >/dev/null || : +ip link add br0 type bridge && ip link set $eth master br0 + +(while :; do + bridge fdb add 00:01:02:03:04:05 dev $eth master static + bridge fdb del 00:01:02:03:04:05 dev $eth master static +done) & +pid=$! + +for i in $(seq 1 50); do + bridge fdb show > /dev/null + sleep 3 + echo "$((${i} * 2))% complete..." +done