From patchwork Sun Oct 24 17:17: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: 12580369 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C5EB8C433F5 for ; Sun, 24 Oct 2021 17:18:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AC7D560FC3 for ; Sun, 24 Oct 2021 17:18:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231508AbhJXRUv (ORCPT ); Sun, 24 Oct 2021 13:20:51 -0400 Received: from mail-am6eur05on2041.outbound.protection.outlook.com ([40.107.22.41]:63681 "EHLO EUR05-AM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229821AbhJXRUt (ORCPT ); Sun, 24 Oct 2021 13:20:49 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YVsN8EtexzDzb1MLdSpnPwTw6Z8xxn9fwwwbdMm94n3OBai/CySWLympnHO7CqNsoaDMDTte2x8tGs/4+gPPI6N2An9yDVY+hyntLBjXDB/dEznsZMVf18ICVcKOHIB/nwBtHhjlBXnfWYkD0NRq0G5Jee16JGtfWaVhA588mNI/WpMHYyviQTGOpfeuvigAtsdl7DPamDi31My9wpBjt/5mhxz7VhAllOlZCMq+cpJ2EhnlvEbSHRgj1GGPHSGmrRuN2XbBD+dQjygVFiVS4lDBlTmF0dXABrSYQNXrShwzgRTx06NuYSdk3g0nW1hcKujAs9yXdeaFgBqzTWc5Sw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=f6ZCEjHkWSDUcZxGe0OhuNiBOTjyaajPFV+EeSvSE38=; b=BwV88jpgAPVknbte+oydoky4BgsUuk0R6vpTPdlhsaOHJlqv0K6MM5yVQoDHFn2ZnJ6TsbcgkQ4cRNZJi9KGNS+3ikZVQHv4NySqXT4Zl4Gu2L9ehKbHnjzZhJhOaTKupzuRa+JTnYOkELfrVZel1ObbzoAhct1J49R30W7M6+sxw4ZR43crmuK6nbrxQFKHczfafDuxuNWKUMpqop67br+b2hypZEk2r/jywWn9VbGEhtfQxcrB4Tja/tJeyMzgAJJIUSlv3ly12ueFwXvpyJFGRuNql5FxubHX026KwsBYRlepHupk/OZ+xltsrPDbeM2ZapS46K+VczdaU7me7Q== 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=f6ZCEjHkWSDUcZxGe0OhuNiBOTjyaajPFV+EeSvSE38=; b=AX+GEh4VY7KmQtpf1Vt669f+Lypdi5X795EF1FxXLag5Dyyxro+L2dC0CXOuOJ/jliqgyPUhITENVqb+ftp000epeKcBCH6QewFakeFP4Wu7n632+jJ8wVAbd9AZlFISb+7kWYVnX2fP3j9I+02wVX5yevToPptfPqox9nYpKTk= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) by VI1PR0402MB3552.eurprd04.prod.outlook.com (2603:10a6:803:9::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.18; Sun, 24 Oct 2021 17:18:27 +0000 Received: from VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::e157:3280:7bc3:18c4]) by VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::e157:3280:7bc3:18c4%5]) with mapi id 15.20.4628.020; Sun, 24 Oct 2021 17:18:27 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org Cc: "David S. Miller" , Jakub Kicinski , 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 , Prasanna Vengateshan , Ansuel Smith , =?utf-8?q?Alvin_=C5=A0ipraga?= , Claudiu Manoil Subject: [PATCH v5 net-next 01/10] net: dsa: avoid refcount warnings when ->port_{fdb,mdb}_del returns error Date: Sun, 24 Oct 2021 20:17:48 +0300 Message-Id: <20211024171757.3753288-2-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211024171757.3753288-1-vladimir.oltean@nxp.com> References: <20211024171757.3753288-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: AM6P193CA0123.EURP193.PROD.OUTLOOK.COM (2603:10a6:209:85::28) To VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) MIME-Version: 1.0 Received: from localhost.localdomain (188.25.174.251) by AM6P193CA0123.EURP193.PROD.OUTLOOK.COM (2603:10a6:209:85::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.18 via Frontend Transport; Sun, 24 Oct 2021 17:18:25 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: dd57cf6b-0128-4491-c83c-08d997124abb X-MS-TrafficTypeDiagnostic: VI1PR0402MB3552: 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: T8+dJMOE/80os5qkHVrjTKraZJmcLVAfS3OkPFVMUl0U65Aed0n/BVUqVJ8XTlVPRMXLm3efHLc8lY6dLPkQdyRWWRd0HS3u8HLp0GMzD1nl/EX2mTDcG6PdCbCn1k8BZ1MPJEmiHK5pUATFEv9LzO8ZtoIZ+4ThmfkQDxcwADiGf4def+x7JsPCSdQT52kyY/q0HW+yJN/8Kp9pDiDcJL25gz7nvvGCA+SjJcGMuh2tbMfwUh4blbLOH45IARDPKjxh8KA287yJYEOE8TSwhrkHOLK9c1oxYSxVY0x+MGJ3Y16HxG+UcXENtnd3uPVCL1eSebFHDFPc/6342JHUHAa84QPe+7zm0r9yKsoWZ75TBXMdcJxs3i1QlASWQUOHiQ93G9ktveY6tDWX3HXQpPPmibEG8KGl/1eMbtpcHIzajVmlxtss7+36jxPFcoHtcOPQdaKyIeR4CeP7zAHtNkOV1spc6pZDDgRQKgUe9GFOk7E0SWi/AbqZ9wOwfj9EiymLPltl+yMxLfBgYuzKTa3j4oUD2jmYErMcPa/PpIYerqSu6jLWUlh66ObV7UQyyQY7vqzcYE5dgYotjlGEotZlhp3rszwYluvXO6RJOnVYG6x1fd9E02RclOws2iJwoSYok0FFd/G4Om993Tx7wzvzJC9mWGEQ2Jcw01u7tFt81W6nKHY/1jnBrEeS7TATUI4/AiIeEN9Q27XB0JGD1w== 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)(6916009)(6666004)(316002)(54906003)(6512007)(38350700002)(38100700002)(26005)(2616005)(6486002)(956004)(36756003)(86362001)(7416002)(8936002)(1076003)(186003)(8676002)(508600001)(44832011)(83380400001)(2906002)(66476007)(6506007)(66556008)(52116002)(5660300002)(4326008)(66946007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: LSO1q1zHZ76J1yS2ecLHtExrZzUBB4tVs3gGVYx9qfvaBrUb+cC0Xry6E99nJlt1S+l1I87lETWl2MC3wrI3NsY08RTbWyI5HWjP3NLQT0xLuH8jKpzE+RqRANlqjohyjueqnPHJFutqdVw+sf2c292xyGTrnqMb0hHKLhmhXiAHXBjfd7VV/+yfwDKQWa0F5He9irBn9teKapaUnZOS58B+5pyn57+BMSZ8BBaJ61h9sq/8dNtq7bmEWaBp8TD4N+SQdwD4YS/mFx7posnesozAlunqlFIcjPaq4hopThABby0qKBTgdeIpXwqYdIbC3BeLHsBBB8fr91jU55vp+qm6gPiO4Cys1jkddO5mvzkvugbFBYunuFBy3gArAFc+vpa7hCOqg1lG9rGgjp88NRYpToVbRkXSq16wfOYh5lakOfmkmLRFHw949DsttWRvhpAkWWnLnO7jJiVACOBk7bA8yv4PK7nrOoygHwYbnqgI/Q7h2KQUvSjWphSqHsy0CIAwoRbvAgsjemnkJelW3unFxnMyC086SJsbFTOHhv1ZzTmnBWgdOuOOQH5zOGy3nH4/jrBjqqKCFYif5Jl/aSZnYEHLPFJ1Kaz5VcD4SONi8fQ1tI9yvgF8mqepJpeAF8pxXUwd1UD2H8z4ROCMMBQ5Z5ZNwdIVG9HQslHZrs+ku7JbDEAQ7Wid2tX5rlI4JCocqMwHqmqrAYvtyGZ9PmMD5Jvf4ztDd5+O+vwvrPmHVp2i8oq3XQFzMy5LuA9ZFXv4OsRq84nk8B74nX8naQbNb3VIhLSTqfk0G8lVOWEscVH+QNNnampw7XJaPAyrUHPfDTVcsSk7hFpIRtuJlzU09JGJqFlUh8tGTfZnjaR65rCEZ26HA6LoYINrgQ6zwy1XGKRrI5QLqOBTzl96P5DLEJp1pfTq+xh9UFlYkLh2rbjrOqoh+yvL2gLXb2rSXymd8WdITy95y3iWSznO22DTApsJ+eDgt2xmZJQTzzUT7KmG7ua5jmIjFBNVrqD0yC9F0bzwpKPXvqDmm2S+Qqr7M0riJhNAobTt0weR962V72wjF0CMq9HlvBk/WPSIgqle9J5NwKymZnNGF1agpORxd8NjXGDHXd+TIL93eE6KQatljOgDWLqtdrJhEDw0zO9ppQETe10OJJ/lNpqGXfsHQibMNQQej9QAyzBwTSWR6VA2WHGl9awsNOByPhORayIAS+HXxidW6P/U2++vMj4Bjwd7aUyNg0IgmBO/tYBzOVta+5O23Gh/i2dAJLGngTH7xpigUdAV5D75xT/zKYdxLX3JZAOpD0tacKWF4XF3ceanjfMqct0DoSQ2sV5rx5o1aP4NthnMKKg791tWj7hssz+VGK4VsEf4PvCexU4qBGdWoFUMGyov6+QEIhpAbhXRKtEv2VD1Et+7lmx/LWLlAF5oHiuEX8WYM/mT9iS07i3e1NnuJLbZ//3/zbxrOKEpDNTQhvFPYcvh0kPW2IGHyDuW+xhsmc0r5y52RVv2KNFrnwgNbFnXmzJFV43TrpE454i/09EwDmfv2eJDKRU6Bwozs0VUmDppB0MTSwpG5YU7NoSbuHNYkQiZtcndRErTZrAwu3VQ3fnjr7zTf+8nTM2DczRYud/cm8aA3hE= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: dd57cf6b-0128-4491-c83c-08d997124abb X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Oct 2021 17:18:27.1090 (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: 0RvIqETbJD0FkrEtlUVqKsvZSs/TB4hpbwzvycGyjo299uomDup3VgGq9d6A2u/aQGcybUqG1aicPmU89Vtv7w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0402MB3552 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org At present, when either of ds->ops->port_fdb_del() or ds->ops->port_mdb_del() return a non-zero error code, we attempt to save the day and keep the data structure associated with that switchdev object, as the deletion procedure did not complete. However, the way in which we do this is suspicious to the checker in lib/refcount.c, who thinks it is buggy to increment a refcount that became zero, and that this is indicative of a use-after-free. Fixes: 161ca59d39e9 ("net: dsa: reference count the MDB entries at the cross-chip notifier level") Signed-off-by: Vladimir Oltean --- v4->v5: patch is new. This is a minor fix and slightly unrelated to the series, but my other patches touch this area and there isn't enough time until the merge window to wait for another net -> net-next merge. I've annotated it with a Fixes: tag and sent it to net-next (also made it the first patch), in the idea that if it could be picked up by AUTOSEL it would be nice, and if not, the problem it fixes isn't so critical anyway. net/dsa/switch.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/dsa/switch.c b/net/dsa/switch.c index 2b1b21bde830..8f8ed8248c2c 100644 --- a/net/dsa/switch.c +++ b/net/dsa/switch.c @@ -266,7 +266,7 @@ static int dsa_port_do_mdb_del(struct dsa_port *dp, err = ds->ops->port_mdb_del(ds, port, mdb); if (err) { - refcount_inc(&a->refcount); + refcount_set(&a->refcount, 1); return err; } @@ -333,7 +333,7 @@ static int dsa_port_do_fdb_del(struct dsa_port *dp, const unsigned char *addr, err = ds->ops->port_fdb_del(ds, port, addr, vid); if (err) { - refcount_inc(&a->refcount); + refcount_set(&a->refcount, 1); return err; } From patchwork Sun Oct 24 17:17: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: 12580371 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 36711C433F5 for ; Sun, 24 Oct 2021 17:18:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1B8F760E75 for ; Sun, 24 Oct 2021 17:18:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230520AbhJXRU4 (ORCPT ); Sun, 24 Oct 2021 13:20:56 -0400 Received: from mail-am6eur05on2062.outbound.protection.outlook.com ([40.107.22.62]:57952 "EHLO EUR05-AM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231481AbhJXRUx (ORCPT ); Sun, 24 Oct 2021 13:20:53 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gSVG181AP1ePvY/zucqUMA9LYuyUZmt2LU9tKiR6OqCRwAoiy59iNtekgp/tvd8AEqSBxBBbrqUvUIeEkh0SMxW4f1a6hKr7f8Nfm8iyI9Xoq313KCLf+DrScTUyi26JP9ix3b0zrzdaCoDr01N4F05aZb28yhT7iZc2fdRS91zgO35yVeRq3qQgPDUyrDZm6zRozMHR3hVreSuDcfSAT7OCQ9FwRw9NAVXlTfNZEx1QqHPPsV2/dSoUeq7LBFd1bgOGj1F7jzcZZc59iL4khVNkbZJOOlSninwTWhUYtpexDyf/8SjhsQqqvIlQmfeF9P0nmafW/UVuoccc2u1BjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=WTFXxD6Y98RsdCw5gmJ4qs+ze/l0MmXH55q7J4eClDw=; b=fw6sRtgxFIoeN12pi3zJEhca/KzX2jYGodUZX64LovUu9yokVLgXhQrK7zRFbnkvkYQPU1kljiOl97THC7RBamWpO5zre1MrcHZajQsgd8AYLzAgE1Nsl5tpOYrA26tkdGttWbnfvz09BtZnIEFek9vsjXl1oGEE2ddKEqdrwoJ/Br41hal8USI0xt//+KN37jNn4UXLygtL1j3BQL14QgnetwHd+HbVO2CuTa4Khw//zUP0alOw/HXI3n5eSdbU1AcUlfolnri2yL5unHNX1Wyda0d7zRX7Xlh+6oJHrfpwRZRsD0G3mulEDevPyZoAxR60U5Czhftzd0dOdc0klQ== 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=WTFXxD6Y98RsdCw5gmJ4qs+ze/l0MmXH55q7J4eClDw=; b=poyWdxgFbfhCo83QfkNiV4rb+BbWSTFihX/OW4cNhrSeBBVtxcvsn9Dqu5Gcedy/9nUxBLYIVZh9+Kx05aXbQnhe/Nqi9Bk5P0XieZfBEV16iIJVEvTZAYpLiNHVqWX/OrFJYCh9LCNQmDYuOjtJSqFN0WrJ9HYjI9REbCeNnhg= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) by VI1PR0402MB3552.eurprd04.prod.outlook.com (2603:10a6:803:9::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.18; Sun, 24 Oct 2021 17:18:29 +0000 Received: from VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::e157:3280:7bc3:18c4]) by VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::e157:3280:7bc3:18c4%5]) with mapi id 15.20.4628.020; Sun, 24 Oct 2021 17:18:29 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org Cc: "David S. Miller" , Jakub Kicinski , 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 , Prasanna Vengateshan , Ansuel Smith , =?utf-8?q?Alvin_=C5=A0ipraga?= , Claudiu Manoil Subject: [PATCH v5 net-next 02/10] net: dsa: sja1105: wait for dynamic config command completion on writes too Date: Sun, 24 Oct 2021 20:17:49 +0300 Message-Id: <20211024171757.3753288-3-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211024171757.3753288-1-vladimir.oltean@nxp.com> References: <20211024171757.3753288-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: AM6P193CA0123.EURP193.PROD.OUTLOOK.COM (2603:10a6:209:85::28) To VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) MIME-Version: 1.0 Received: from localhost.localdomain (188.25.174.251) by AM6P193CA0123.EURP193.PROD.OUTLOOK.COM (2603:10a6:209:85::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.18 via Frontend Transport; Sun, 24 Oct 2021 17:18:27 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 30507183-ab00-4729-837a-08d997124be8 X-MS-TrafficTypeDiagnostic: VI1PR0402MB3552: 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: m1vhBMIjS2xwI/T4S5etRZFAK+g2JQBB9INZsCh5dZJPJt4+1CuE8+h71KPGBtQhJpsx8pMUiz5GagwdLecVKW0B8UCKpWtF8Ybomv0XUMp/GDV/OHJEQHHYGvc5W3cGEeqIufRg+BPcm86OEE1dtu6Qdk6FfT7zoyEnrcTOahOChDCB9opDNEi2URaJ/MxImDa77pUpXynQuPMnXIdm0JCJoFGa/sVIrPJXe4H7N6K7e4nG0pfVcQbtFr3CQd+dypofX+wmAKIFSLQBrCWJGrhPDYEnV3Nm/Ut3nOqc3Oyc7B0boS9DfWeGZ9KIVmWRIbFNgoqJHmMc5cpoJ9VffJ4J3VHGl/WIyRbzSsV0Q5Xc3wb2ffSuU6q+vrL5yC/xKBvmRoop11rnQL58fqCuR4Rj31LykBCAUOip9dEryM+3sOirUsD2JJsYJRsGttwWmGERy5A8+9zLY4g+OZ4CrPMoSU2gMFkXv3Yn3MxAhWNkJF08JETpUZIst3AEJQkJf2bwSCfcAV3GizT/OzvW9nyiPPPO02Gy5eSPn17d53q5R/FeT367Frtmtes4SHZvnqavMHOJw136XuiVyfD8IyGjdetRF10JNtntkiCYp9qQRMfw7c/dA1InIQSsQcenpMmmRPr+7LGYeha78oVJ/JS24SuXTPNKZgZiMyR2Azju2tOIoIxXBKcC5hG4GXxL6Z3ZM9ZEAZKkpCz4lDLg5w== 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)(6916009)(6666004)(316002)(54906003)(6512007)(38350700002)(38100700002)(26005)(2616005)(6486002)(956004)(36756003)(86362001)(7416002)(8936002)(1076003)(186003)(8676002)(508600001)(44832011)(83380400001)(2906002)(66476007)(6506007)(66556008)(52116002)(5660300002)(4326008)(66946007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-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zyV/MYih2g/vjdxykUjuN4Qs36ls5p6avoU/MkvcQJ/1ZfNVojoDI2pn+Bt/BsF/r8ot4Ynhh0/gaHbQx5DfoqD4tfBspQi5FmJVNs6GBYM3BmhUDdyo61Y0zqkQfelsQeJS99DZxwyHx5+Aw655rBMtbLBqr5CZniDS1pSSqQDr3KRjEA//4v7eBcvm4PYpVwYgW9x/vWbgTrC8c/At3Ml9m6ldHQxrflgFMCl04+dpi5HJ20Ukoe/ucf62KSFeLTn2bD9xFOA2QCLP1uIr6nXQRHAqPhqSkt8P6pKVwoDiOxHFFEsPwGJluNkRkYCxNTs6mLXCNJNBToC+7Jdn4k3fG2S4400H7cWEVUkK+bXlq0oNR57Kxn5w1O+VcWSJBRKO4fJpB7Th6IFU8Ccgm8V6SFMKiUpijEvtL6I0VRLVcNgIIih/q/YOs0KhIroy1BX499ZG774o1hV3i73Zyw6DuHemca7OuA9yHHa1g3gpo3nLzHHbahlCVJbSCsVO1v8lRr+qa+rmnubvImiluRGKh84xG1U4EOYl4FxlGbWvkQMcHANEEwNZw9TyD1C0R6LfiLQwqLghUjuFaopYWhSQ= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 30507183-ab00-4729-837a-08d997124be8 X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Oct 2021 17:18:28.9669 (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: 6ejFCOL77K2jXWuAElUha0dyG8n+pO5CpQTE7CM9lGp38QVa2bp7LTz727Onwb9OhtJcs/ShTVJQ3FuRN74Lzg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0402MB3552 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org 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 --- v1->v5: none .../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 Sun Oct 24 17:17:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 12580373 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 696BFC433EF for ; Sun, 24 Oct 2021 17:18:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4D1416103D for ; Sun, 24 Oct 2021 17:18:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231700AbhJXRU6 (ORCPT ); Sun, 24 Oct 2021 13:20:58 -0400 Received: from mail-am6eur05on2062.outbound.protection.outlook.com ([40.107.22.62]:57952 "EHLO EUR05-AM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229821AbhJXRU5 (ORCPT ); Sun, 24 Oct 2021 13:20:57 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CFFaU7RnXiX718tkohdrBTtgmN74XHxPf5+W+MJ8/XnLCQEJYZMDoXOc4sfevIKQ3eWi7/ZhUO3YeSE460C7yaWPNyjUAVjLzm+DBiKo1fDU/AwJ1uXuiwgq8ZaLsCVo2TknS17hVhbq4PYg8FnkplkVhxlHjTtMEh/mWru/vKeLgoRvdJt6TAq/4gVZTie6qUf4QPwdVv0xBJvw4i6dbOZe6oKJ359UiQ2AZ4MV945U2QWvAgxA5Z8esAuBMP/U/moLBSj81DJxFj1vmf6e2W+hOGm5I405/6t0x7f50Lz1PsQotGOFH2snpWcGdT8WwlkekZMsLtv0hLCSXXPoow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=dcsNOwsJG5F1wgxp+1PmzQukHBuZc7BsBduVI7R73S0=; b=maKac9KYi2zQewCHyC9+5sJS7ndPt4L3bhxZLwo66xoPuY6/bllZZcEkQGWNP+MIIqv/yp+7YclKHeSoXOA440rh5IsabC2ccHNHHad1fnVAC9Sn6+8JNU1/DqkdA2cVNvZDUmPZZGfmEPzyEuMEEDEgKirIIHhS3Iti6j0QIn0gqFBefBz/cQBr0+3I/QrgOxqX7yl6OpGaBiFNn8eYVPzI3GTY6dFDEU2v1q4ExZuLqGt7S9CJmDyiY/OxKkNULQxy82Y2gqs56PkSMIaeH89z7SWDJU/XYooBLEC+zynp1W0Cj+s+hQKAbozqJmVwDUYAY6jJFLBhU7VAEtUuTA== 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=dcsNOwsJG5F1wgxp+1PmzQukHBuZc7BsBduVI7R73S0=; b=pQ4URDz4lYVT9aUpFcBRlevJioPnntwmuiPw8vtmHWhNg7ieOgw/2MGQfVmqYeWPX26ZRdL0zvm9m3lX2PJwg6GcbYA9cWUch2sCwZ/zLzQ1Z4m1GsaxIIBpPXMxGkryRl+3wQnwSY4RazhuFkQ5o4GKqVx2UNDSsiWPjEqA4QY= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) by VI1PR0402MB3552.eurprd04.prod.outlook.com (2603:10a6:803:9::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.18; Sun, 24 Oct 2021 17:18:30 +0000 Received: from VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::e157:3280:7bc3:18c4]) by VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::e157:3280:7bc3:18c4%5]) with mapi id 15.20.4628.020; Sun, 24 Oct 2021 17:18:30 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org Cc: "David S. Miller" , Jakub Kicinski , 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 , Prasanna Vengateshan , Ansuel Smith , =?utf-8?q?Alvin_=C5=A0ipraga?= , Claudiu Manoil Subject: [PATCH v5 net-next 03/10] net: dsa: sja1105: serialize access to the dynamic config interface Date: Sun, 24 Oct 2021 20:17:50 +0300 Message-Id: <20211024171757.3753288-4-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211024171757.3753288-1-vladimir.oltean@nxp.com> References: <20211024171757.3753288-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: AM6P193CA0123.EURP193.PROD.OUTLOOK.COM (2603:10a6:209:85::28) To VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) MIME-Version: 1.0 Received: from localhost.localdomain (188.25.174.251) by AM6P193CA0123.EURP193.PROD.OUTLOOK.COM (2603:10a6:209:85::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.18 via Frontend Transport; Sun, 24 Oct 2021 17:18:29 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 768af97b-b2f3-49a6-dc28-08d997124d03 X-MS-TrafficTypeDiagnostic: VI1PR0402MB3552: 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: Kb3pfr6OHIKkFwxD/Nm/eIE2Nqbt8gqwQGqzQ9eOVc/8EbSFlKOhSzw42devecEez1LtcmRcIncFtbE/xh8srtAFvKaNNWKHnIthyqCYY/JiGJoUkgum8lbGDU8yyLZ1TEgkHVcCwP0THfqNfj83AsvB7Z61g4bEvgOzUa+bDh5dNVN3bhvj508k1jEbjAy2jA+5968uva0PxIqc1rksYlkTVMb7SDSjdZDerzFFCBOIdVhtxzmzXy41WfX1LU9xCMH8XBQadX09IavW7COJY0HTuiVNc9SG944JkVdJUaHvqBDmr2R5Hlwd/yxEgpkkhXHw8NyCzPl2aa42gRweF87QysDnqv40pvr6BPl2Z9gryPXOJ29az0lDVd9nQ7w/W3Y70KO/xSFqf9aOqZtyTHVFoLdp9ugQa18gdC9BRbk7cBa2Bg1648/Se7PszDgqQWmwE5Hosbrwuy/qT26hHInAyfSF0IDT0xlS4ZmRGGBZmO4vzbRGjPlwK/Id49AyT6g3rZuCBnBCfx/yltBq9iUxgfc+0LH7rO5F9vHtZX7Fo4e6sC5ujCOeRX9pFdnqc7CpU2NbdvnaIE86m8glQxqBepY56wS3Dg/NhZteUF+k6ZbmA88T2uGyGG+54SPumrawb7T7H+0WMoHQHqsU+rnxo0E4/aO3ZrssWEvOFzNLsG43OPHxseMmJ+sFr4pC3n3vSy87kia/L9+MiuNuBi0BP7xfUnBwESnkTzcG7bQ= 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)(6916009)(6666004)(316002)(54906003)(6512007)(38350700002)(38100700002)(26005)(2616005)(6486002)(956004)(36756003)(86362001)(7416002)(8936002)(1076003)(186003)(8676002)(508600001)(44832011)(83380400001)(2906002)(66476007)(6506007)(66556008)(52116002)(5660300002)(4326008)(66946007)(290074003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: EKOQKpuywIonAjn4e4kKGCD2J2mxxEYBaD9kFVXt68f5XulVD3jOqRWFfWvSfe0/s+Ryd0l+/9kM/u7x4YsXTtpuNTcVecZ5sqA7Lv/8K9VJUid4soktVoc0td9JENTI1yvKakEE+bHQA8YD88ollF26KbDsCxrJYGqhMJFbdOXcvVRY3DbWq3ZX1ORp2l8H0VBtytwxFEXIUklEqkqsI8lVPspZbWQa3+TuO/NHdsU12b01VRXJFg5Vw+tJZOPQ7jr3BX3Cs6v/BZlGDUsFQEdGhkQXondY44qFAZLe8b4r27XlHrZj7zB3gcYv2uvrF78VCRv6loAye/r7aDV6qvYKlrIy2ZDouI7FPxwnuFbe+oq+r2Chi7OdvKxyHM9oXLAE9hGhiXTxPHRW9kqCffmRB9sj4O6CXq1tMM9wfpB7sClppjmHX3r2V4I1eZxmOucc/8Qi3zH1gSw9yS9mxcJYwNzopsWC30EPXWloVcUvPNY3pf/mECTONOT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5dMBAopc3NprrjavWTE/5AdAcoaPvwlrB0xMA6MkatbWfaK9MOfk= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 768af97b-b2f3-49a6-dc28-08d997124d03 X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Oct 2021 17:18:30.8688 (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: oQhM2EYbwESz7Vt6zPgw+SxC/qwKNxkpYdgs4afAs8ADVUI/VxJ0LBK+8EbrshwMrSXRov/CLXrr1AIpX3oelQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0402MB3552 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org 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 Reviewed-by: Florian Fainelli --- v1->v5: none 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 808419f3b808..21dba16af097 100644 --- a/drivers/net/dsa/sja1105/sja1105.h +++ b/drivers/net/dsa/sja1105/sja1105.h @@ -261,6 +261,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 70ece441b3b8..d6788a010024 100644 --- a/drivers/net/dsa/sja1105/sja1105_main.c +++ b/drivers/net/dsa/sja1105/sja1105_main.c @@ -3366,6 +3366,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 Sun Oct 24 17:17:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 12580375 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A3277C433EF for ; Sun, 24 Oct 2021 17:18:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 853D960F57 for ; Sun, 24 Oct 2021 17:18:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231733AbhJXRVA (ORCPT ); Sun, 24 Oct 2021 13:21:00 -0400 Received: from mail-am6eur05on2062.outbound.protection.outlook.com ([40.107.22.62]:57952 "EHLO EUR05-AM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231658AbhJXRU6 (ORCPT ); Sun, 24 Oct 2021 13:20:58 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Uz+Xdsw0SjyCo4dvy8Np8Q2iIWjaf6WMfp7RQiYpZXVCMcBM2qlgOeM3ebYo+eRyZ4xi9GRaP4YTZzMKnA2BkB6N8xVWCJ7Cu9FhjI4tu5rXky1ORM2sBXV/Bncy2U58F0uPqeMnC5QyPu1qAv1jrfyON+U/r4xnzjhdl36VUUNi9Fu77UKLMEVwJSFvXCSGqxVYNlxoDTPRgpw2B0MjmegkamCfJ2iv8r+q7KS9yPBxv27BNrang4C/hbrgjc4pzuwR+DVOLbmFDBLuTp/V0U6w6x8IAOir+I7Lby7+wuZWxKyghwe8J8/aBmxVDMwLnrf/Nt8xMPtv4qGQC6VQVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=DGm6OnOEC21Dt30CP4YeiqV7nWs97IVRQwAsXPHL+zw=; b=kbsuXYD1etlG/E6sgoAXqWoNZ4yoNM0q06l4vcK3iwHKLlJapaBA4zPTuaFMuZe27oodsUPZblj4oXDCRngXSY5iNZRS3J6T5+VswSfzLZi/Abu3810OuEm/WFBCrkcspsYrZC32bpLzQuPbUW+5KVqGZ6VzVzebpGyvu0+F8qNKZjTQNWAnzZrbexPZmJNY/cvGgtke7pKwys2N7yZLNcmEjfuNHoeTvCm4QaP96NZgu/6mrQns8soLsJ5W5QgS/y0A5+ZPVkAKpA8LIIVbR1s0oxbMqHg7O99ji6wB9xM9K8ZUKvgWSuaoyxeO38CQpVBCA/jw2qrk9xwUt9XfmQ== 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=DGm6OnOEC21Dt30CP4YeiqV7nWs97IVRQwAsXPHL+zw=; b=GlUG4+coy2TVcXARJNZfLyzjpFijSx2jo97wqWksOHxlMYH/6b2rXsePfEfqebPocKA9trQffOu5ZCtpSqF/txbge/BXPyIX4cwaERmORQA4AP9lJImJufniSjn2pPhtIaAF90mo3/cl0MRsEt7byAPF5hv4lK45qPXuqsG/yAw= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) by VI1PR0402MB3552.eurprd04.prod.outlook.com (2603:10a6:803:9::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.18; Sun, 24 Oct 2021 17:18:32 +0000 Received: from VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::e157:3280:7bc3:18c4]) by VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::e157:3280:7bc3:18c4%5]) with mapi id 15.20.4628.020; Sun, 24 Oct 2021 17:18:32 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org Cc: "David S. Miller" , Jakub Kicinski , 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 , Prasanna Vengateshan , Ansuel Smith , =?utf-8?q?Alvin_=C5=A0ipraga?= , Claudiu Manoil Subject: [PATCH v5 net-next 04/10] net: mscc: ocelot: serialize access to the MAC table Date: Sun, 24 Oct 2021 20:17:51 +0300 Message-Id: <20211024171757.3753288-5-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211024171757.3753288-1-vladimir.oltean@nxp.com> References: <20211024171757.3753288-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: AM6P193CA0123.EURP193.PROD.OUTLOOK.COM (2603:10a6:209:85::28) To VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) MIME-Version: 1.0 Received: from localhost.localdomain (188.25.174.251) by AM6P193CA0123.EURP193.PROD.OUTLOOK.COM (2603:10a6:209:85::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.18 via Frontend Transport; Sun, 24 Oct 2021 17:18:31 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 23c37e72-e5e9-4adf-fbe3-08d997124e26 X-MS-TrafficTypeDiagnostic: VI1PR0402MB3552: 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: ksYFNEt9LNl708VmgqL4FyFXfYZAVQUm5uBkIDw/bcE5j6nnfDHQgcv3QZeJHMvSORIfx/V1fewtdvQGeFev8XON88Jay2DUZFcotIO+aIVLzKBrTtac2HyMl9XIkIslg9JxghyTN7pwNH3vrHWItW6pylf6bQCIAmzCZ3HACQrmkAvrxYiBu0kzoyNUNDmxpX09xhZNiVbfrZO+2WZM7urSKcsLx+lfSGSZJEhAjLO84+PVjjPKTSBXVv0i9ecpTI4Klz1lu9pVJX5k4a3KIKmz80b7Pd/NuE8/M6HZ0Oms4muiusZAdtQLOO+B7qmnT9ZTA7/mmnV19YeupET80qNNDiz7ehYxvtN+JEHYQhV3aGGEEUp8HfbKTCg9Oxq5l59vZVNSZ+b51DMgygdfc7sfRiR5AETPmFYUUnbz81QOFKQZfsemEV5E0FhLpuHzTpUgDQUHETza7Gt2PnnMnWEYCbBh4YN3KAu4y+pF49kuGGvT8J2Pyfjp6eeq5Feps035N+QwR/X4i9uUi+gx8jfIM+8lrnzvj0co6v68X/TT5qK171P8qGm6nHHA6iyCXGCwfMSldJQ6BsycAY5YEWBKXYmD7upw+PDJfbsO4Gp1t9dohItPKMp6rYzNkjWQ8OCUQvtDvbdmPHUL3xu9WKi3pdnCzB2qwIjkH5ehFngrVAUdq3dSxAG+2d0FJPE+j+r5XCteUXCahWNISlec3g== 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)(6916009)(6666004)(316002)(54906003)(6512007)(38350700002)(38100700002)(26005)(2616005)(6486002)(956004)(36756003)(86362001)(7416002)(8936002)(1076003)(186003)(8676002)(508600001)(44832011)(83380400001)(2906002)(66476007)(6506007)(66556008)(52116002)(5660300002)(4326008)(66946007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: vEOAIn4kLtC5ROPK3mQ0YSffmFzBywKDvXxKh/tnWtwXGk86r2Y5InOcUz6MhM72ss1F4kH2T/E6Z+omfQoTLkAHklmMxYyVqSoKpExLr1IqWfNztxfs9siV1Hx6v+TMDl/nFhdnSdM7AsC4l8fr18CeXdGP5J2B27ul1L/Hn2yKdUFao5OgEaOCC7uOJfD5DqtZ0K2phb5PvWzKWMUqoK8O5ID4bA9yflNNI6l1yuQ9x466alinR7d/dxf/ixqFZ+d1D0rCc4RMHnGBnPwfhlXQGWTPJTTxHheLYjdNRV0xbkSJQJnJa8rvvRkxVYeTtZswJAlPPdb13dPG0vuMuSkcIKDBqjRgdYiQ6rh2CGBgE/gEkvv3IyIINkmvPPLCAB/uPqTu6ti7l/d7GtNyYwN9ajYzvCgFd742feL+9k1RUq8vyHJt5ZXC5hpXMgEUmWKD64/WfU3So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a09yjYaM5YhGnEIRrIcldJwtCXQAScf0PUa6Iy+D0y9nuFXMoxYS2SCKCiH0LmGR3vA4Ye7I9hRFlSsjMrsZnMjTp408SMnmTcGJA5c= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 23c37e72-e5e9-4adf-fbe3-08d997124e26 X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Oct 2021 17:18:32.7987 (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: nBiJfnnIKY6rLLjN+zZYaYTh1iwVppb+wJTX4RJK8Zs3fDCAxtQsOrwy9bEH3HIa/srA2syii1ysznG8YTaRhA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0402MB3552 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org 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 Reviewed-by: Florian Fainelli --- v3->v4: use __must_hold v4->v5: revert changes made in v4 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 4e5ae687d2e2..e6c18b598d5c 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; }; +/* Caller must hold &ocelot->mact_lock */ static inline u32 ocelot_mact_read_macaccess(struct ocelot *ocelot) { return ocelot_read(ocelot, ANA_TABLES_MACACCESS); } +/* Caller must hold &ocelot->mact_lock */ 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); } +/* Caller must hold &ocelot->mact_lock */ 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); } @@ -1170,6 +1190,7 @@ int ocelot_port_fdb_do_dump(const unsigned char *addr, u16 vid, } EXPORT_SYMBOL(ocelot_port_fdb_do_dump); +/* Caller must hold &ocelot->mact_lock */ static int ocelot_mact_read(struct ocelot *ocelot, int port, int row, int col, struct ocelot_mact_entry *entry) { @@ -1220,33 +1241,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); @@ -2231,6 +2259,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); spin_lock_init(&ocelot->ts_id_lock); snprintf(queue_name, sizeof(queue_name), "%s-stats", diff --git a/include/soc/mscc/ocelot.h b/include/soc/mscc/ocelot.h index 9b872da0c246..fef3a36b0210 100644 --- a/include/soc/mscc/ocelot.h +++ b/include/soc/mscc/ocelot.h @@ -675,6 +675,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 Sun Oct 24 17:17:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 12580377 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5D10CC433F5 for ; Sun, 24 Oct 2021 17:18:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 445176103D for ; Sun, 24 Oct 2021 17:18:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231694AbhJXRVF (ORCPT ); Sun, 24 Oct 2021 13:21:05 -0400 Received: from mail-am6eur05on2062.outbound.protection.outlook.com ([40.107.22.62]:57952 "EHLO EUR05-AM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231722AbhJXRU7 (ORCPT ); Sun, 24 Oct 2021 13:20:59 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XW+9U6pVSAf6BJr2Kj8a6fU/2dp72/BTsH6kxKBL3+/oaIbwbmTjUwFRaDWXWxhN2Pep8sY4htUAnZ5ojLSPAA7GBi8CmETiQXcwNYE68uKzJgFhgQjh0Ws4EwgPkM67VFWXJkdyQ4fahU/Eo/XzZ6Lcjl3FaW7fS/7K5Iix3HOpjigjXce3rOAHdKT4EhR17uJOxVpzEYDWoW2wfoLEvoo4Dhu87A4JVBbW0Av+0EkK8TxdPpeygBRus/iTkSiX+98mL0HRsBJfHvAGXMvMhN5SjjG4HYgzgWsuA15qI9xRm0NjM2cVD8q7S+lCF+yBEoAvZWlfQafgr9kENe84Ew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Tvfr3WGvmQ8qzx7BveEKan7WyK5HZF3GuDvHnhgBrUU=; b=BigfToBkR18vAm6aGfsA9vCS2XnYjFyAjjLAw+mU/2fkF0K3c6G7afPEmsCHxeHKnqNmyQAWSc1M7CEfgP9A9yJWGVpEEdVRt0E8XmTFjfZunKg+bszMWiKRUy9Bz/FZhV6FGU78BINgjDVKXLjilGHsnHuW4kghcCJRR0+ItJsM/AWJFKK61NuW77mGrvs4WIsv/yAPdm2/pmKtwUXmC71S2RNxNDs6p0n1fG2xBVuLWSlTRodreX3sf+SC/t6Ne4QUBkk3c0gmx/3mcprgaKEVD4tRR8LnK33yYrTDBUBl6yOsfogJETKeGAP/uS+Bt+zSyRi3DjoHYiDwzAZSAw== 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=Tvfr3WGvmQ8qzx7BveEKan7WyK5HZF3GuDvHnhgBrUU=; b=jFn/AyagMY+Bgyvb+HFFgaDU3F+bt1Ux8psQf+GcELulI9ye5Bgj20pRT2tF7CC3Fq65XsBa7TOR1ZlNOh5o+9GNubjwnMGvGkpAkBKUbNcVbxdx7/e8C+E56cYHPMkC1vMIINdermJNgqfIhxSe2eHxlUWBradvc+iwiruwPGU= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) by VI1PR0402MB3552.eurprd04.prod.outlook.com (2603:10a6:803:9::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.18; Sun, 24 Oct 2021 17:18:34 +0000 Received: from VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::e157:3280:7bc3:18c4]) by VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::e157:3280:7bc3:18c4%5]) with mapi id 15.20.4628.020; Sun, 24 Oct 2021 17:18:34 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org Cc: "David S. Miller" , Jakub Kicinski , 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 , Prasanna Vengateshan , Ansuel Smith , =?utf-8?q?Alvin_=C5=A0ipraga?= , Claudiu Manoil Subject: [PATCH v5 net-next 05/10] net: dsa: b53: serialize access to the ARL table Date: Sun, 24 Oct 2021 20:17:52 +0300 Message-Id: <20211024171757.3753288-6-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211024171757.3753288-1-vladimir.oltean@nxp.com> References: <20211024171757.3753288-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: AM6P193CA0123.EURP193.PROD.OUTLOOK.COM (2603:10a6:209:85::28) To VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) MIME-Version: 1.0 Received: from localhost.localdomain (188.25.174.251) by AM6P193CA0123.EURP193.PROD.OUTLOOK.COM (2603:10a6:209:85::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.18 via Frontend Transport; Sun, 24 Oct 2021 17:18:33 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1297cc72-1616-4ac6-39b2-08d997124f4e X-MS-TrafficTypeDiagnostic: VI1PR0402MB3552: 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: ZIIurYiz3ywlY+pq21/5kgO1hAw5DCr0jqC7jDq7r/CbddqPyPS/r+qzR77SpZRGwmn/Rn+SiSex5ZZFRqxc0B+6oV1R5GM90Rpd2D/B1SBK7G+0o1jTGixWmeQj2fPc3F868yeggl6bXKOfjA+dH0UMzC0rhwKOf50Jsue5+/wwFZJENCtZ698pFXzHGvzZ5ng7ogFLQsefPac0vJhkOl8A7pm20QP7njV5pEo/O/hxKkXJ7ZxSXHQG8tCxoBznveNC5/qDBAyeM9QqmauY4OzorQXnDqjnRaWlp9SAmepD5hHJGp/4JmUufbSqLUyoXHQriiOw6u1JTCLZcEFthwiq9K+a4WJoagLUBo+YCouvX8mduvC9T1+QKJ7+TYQFVJ748B8sRaeQdUf9gYuJdkB5RFasKp26Okj6IAlyyOh6FORJcVv/WaaK/Duu3/Lr5ZzzqkqhOz28LjGkNf4OkdyGJqV/NCJZk/0Nq4MqRPUZrruFXnUyywXyDlb2La7jQhk2VgOwblVqWwx9tQWrnpPVnr9+KsEVz2uBiaUoTWNGhoCE2Nli8qYYwClCZdKlbdlxYxWmXSTHycnEtMoosxnrMeHgZX2JssE6PBZHYv+0SjKDHQUtVLc5SDew6WnXSr94+dB9jZYVnsk+8kabOif2CXbzyWurZ13x1R/izKgIaaCPjy8TYGOZa7gqPXOX73Q5wxeFIQyqS84Rb3wKMQ== 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)(6916009)(6666004)(316002)(54906003)(6512007)(38350700002)(38100700002)(26005)(2616005)(6486002)(956004)(36756003)(86362001)(7416002)(8936002)(1076003)(186003)(8676002)(508600001)(44832011)(83380400001)(2906002)(66476007)(6506007)(66556008)(52116002)(5660300002)(4326008)(66946007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Vv5si5Kng3zCzcnQpmpF8t02jmSYXT9g51o1vuhJ8Vp2wCiOf1cB1ugd5noRFfINrC/7rPVHhsMmt/csX6TaOtrzVxlpXCoVrWRBZj3t7XYSKg1KYQ/+s6XlGXCOkageVqjiRuR23up+80oXAeYIsm3mE9LsKS78swyexYweTjZLir/w69sKpYTiNppGye2R6pOqsX/m8YkhBrF9xrjS8wBW1yqucwS/oChiXlJaFj45khXGJ50s2uCSOyUxW7BAYJppgyfcdo+KBGeXcvqnhYLI3IB2kez9j+jXqrA9qYPKQ55xb/G1jMaFhZsNtSF20GC+GRF675LL+HUMMWVMGu9HKrze9N6xDhyct+29eSP5s00N1AVHMXtagWxb26jmesd6IfHtfdeO3fGLS3Q3E2keGrOyj4awrF1F3KL3LmdxQWCtkRKhxd9WbEN66Eal5ON2Q0z9PpB+SvBtXyXIxj1cRDWaaXtfg+QXsiZbVKKYUc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tZoE+7v7+xo3eOgagF/F8G4hvRDwTqdAH0jF9W3qVSyKiNbgKOzt/o8BEFYfHt2OrHTvSpdc= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1297cc72-1616-4ac6-39b2-08d997124f4e X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Oct 2021 17:18:34.6647 (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: cqPaNPtkKhgcgI5sdMc9Z31zQ4hcPL2L6+TZmqTCVYa98BnAxdcxawrl31Q9ZPprjOMj/ikV3Jryt7Yn22Sqww== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0402MB3552 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org The b53 driver performs non-atomic transactions to the ARL table when adding, deleting and reading FDB and MDB entries. Traditionally these were all serialized by the rtnl_lock(), but now it is possible that DSA calls ->port_fdb_add and ->port_fdb_del without holding that lock. So the driver must have its own serialization logic. Add a mutex and hold it from all entry points (->port_fdb_{add,del,dump}, ->port_mdb_{add,del}). Signed-off-by: Vladimir Oltean Reviewed-by: Florian Fainelli --- v2->v3: unlock arl_mutex centrally in b53_fdb_dump v3->v4: use __must_hold v4->v5: revert changes made in v4 drivers/net/dsa/b53/b53_common.c | 36 +++++++++++++++++++++++++------- drivers/net/dsa/b53/b53_priv.h | 1 + 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/drivers/net/dsa/b53/b53_common.c b/drivers/net/dsa/b53/b53_common.c index 06279ba64cc8..651ac72eed7f 100644 --- a/drivers/net/dsa/b53/b53_common.c +++ b/drivers/net/dsa/b53/b53_common.c @@ -1544,7 +1544,7 @@ int b53_vlan_del(struct dsa_switch *ds, int port, } EXPORT_SYMBOL(b53_vlan_del); -/* Address Resolution Logic routines */ +/* Address Resolution Logic routines. Caller must hold &dev->arl_mutex. */ static int b53_arl_op_wait(struct b53_device *dev) { unsigned int timeout = 10; @@ -1709,6 +1709,7 @@ int b53_fdb_add(struct dsa_switch *ds, int port, const unsigned char *addr, u16 vid) { struct b53_device *priv = ds->priv; + int ret; /* 5325 and 5365 require some more massaging, but could * be supported eventually @@ -1716,7 +1717,11 @@ int b53_fdb_add(struct dsa_switch *ds, int port, if (is5325(priv) || is5365(priv)) return -EOPNOTSUPP; - return b53_arl_op(priv, 0, port, addr, vid, true); + mutex_lock(&priv->arl_mutex); + ret = b53_arl_op(priv, 0, port, addr, vid, true); + mutex_unlock(&priv->arl_mutex); + + return ret; } EXPORT_SYMBOL(b53_fdb_add); @@ -1724,8 +1729,13 @@ int b53_fdb_del(struct dsa_switch *ds, int port, const unsigned char *addr, u16 vid) { struct b53_device *priv = ds->priv; + int ret; - return b53_arl_op(priv, 0, port, addr, vid, false); + mutex_lock(&priv->arl_mutex); + ret = b53_arl_op(priv, 0, port, addr, vid, false); + mutex_unlock(&priv->arl_mutex); + + return ret; } EXPORT_SYMBOL(b53_fdb_del); @@ -1782,6 +1792,8 @@ int b53_fdb_dump(struct dsa_switch *ds, int port, int ret; u8 reg; + mutex_lock(&priv->arl_mutex); + /* Start search operation */ reg = ARL_SRCH_STDN; b53_write8(priv, B53_ARLIO_PAGE, B53_ARL_SRCH_CTL, reg); @@ -1789,18 +1801,18 @@ int b53_fdb_dump(struct dsa_switch *ds, int port, do { ret = b53_arl_search_wait(priv); if (ret) - return ret; + break; b53_arl_search_rd(priv, 0, &results[0]); ret = b53_fdb_copy(port, &results[0], cb, data); if (ret) - return ret; + break; if (priv->num_arl_bins > 2) { b53_arl_search_rd(priv, 1, &results[1]); ret = b53_fdb_copy(port, &results[1], cb, data); if (ret) - return ret; + break; if (!results[0].is_valid && !results[1].is_valid) break; @@ -1808,6 +1820,8 @@ int b53_fdb_dump(struct dsa_switch *ds, int port, } while (count++ < b53_max_arl_entries(priv) / 2); + mutex_unlock(&priv->arl_mutex); + return 0; } EXPORT_SYMBOL(b53_fdb_dump); @@ -1816,6 +1830,7 @@ int b53_mdb_add(struct dsa_switch *ds, int port, const struct switchdev_obj_port_mdb *mdb) { struct b53_device *priv = ds->priv; + int ret; /* 5325 and 5365 require some more massaging, but could * be supported eventually @@ -1823,7 +1838,11 @@ int b53_mdb_add(struct dsa_switch *ds, int port, if (is5325(priv) || is5365(priv)) return -EOPNOTSUPP; - return b53_arl_op(priv, 0, port, mdb->addr, mdb->vid, true); + mutex_lock(&priv->arl_mutex); + ret = b53_arl_op(priv, 0, port, mdb->addr, mdb->vid, true); + mutex_unlock(&priv->arl_mutex); + + return ret; } EXPORT_SYMBOL(b53_mdb_add); @@ -1833,7 +1852,9 @@ int b53_mdb_del(struct dsa_switch *ds, int port, struct b53_device *priv = ds->priv; int ret; + mutex_lock(&priv->arl_mutex); ret = b53_arl_op(priv, 0, port, mdb->addr, mdb->vid, false); + mutex_unlock(&priv->arl_mutex); if (ret) dev_err(ds->dev, "failed to delete MDB entry\n"); @@ -2670,6 +2691,7 @@ struct b53_device *b53_switch_alloc(struct device *base, mutex_init(&dev->reg_mutex); mutex_init(&dev->stats_mutex); + mutex_init(&dev->arl_mutex); return dev; } diff --git a/drivers/net/dsa/b53/b53_priv.h b/drivers/net/dsa/b53/b53_priv.h index 544101e74bca..579da74ada64 100644 --- a/drivers/net/dsa/b53/b53_priv.h +++ b/drivers/net/dsa/b53/b53_priv.h @@ -107,6 +107,7 @@ struct b53_device { struct mutex reg_mutex; struct mutex stats_mutex; + struct mutex arl_mutex; const struct b53_io_ops *ops; /* chip specific data */ From patchwork Sun Oct 24 17:17:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 12580379 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8ED6CC433F5 for ; Sun, 24 Oct 2021 17:18:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 76F8B60E75 for ; Sun, 24 Oct 2021 17:18:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231765AbhJXRVJ (ORCPT ); Sun, 24 Oct 2021 13:21:09 -0400 Received: from mail-am6eur05on2062.outbound.protection.outlook.com ([40.107.22.62]:57952 "EHLO EUR05-AM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231684AbhJXRVF (ORCPT ); Sun, 24 Oct 2021 13:21:05 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jEyfnjg6234Ok/NpMKH20zqezRksXS3JUklIG2d8Gn+f3eNZ6fxrT/dutCAC1a7bfRAAI0AOfivrzVCvO9byL4eUrAP/RCnnwargpvCTuSQM+xxjYDHe7Ic7NorDNLt5/r1IAOO/AWW/SmR+k3c4/Qzwi1MRm99KNrZCXcn+Cfd/5AWun2Jaj2YctemYtJFkH3yjt/+l0uLYoGLpVCjkEycXTWWpZv4+d/G1Tu3qbpQo5Dpi+3cv+1ZXDvCA9wehl7la9EzKN196MeyU3dlouu0epGR+LRMu44+lp6esHqiGYCrc3tVBLjLkP30hjhuPJXetdY7q4BgjPQa3tnY6bA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=h7lBnpFYrtc6djAupnyaNsXnaoEAdK35uBV7rqFrUoM=; b=UQvOfBezl/MOv13JNplneLPkbgETElUvIr0jnLrXqAgUwo/5fGr6v1OlnQz2ejxRM6AF9mkLHOYMnUKChsZbS7isqy/e2gV7l1vwIBXt4e6YADFekMvlAtlVtCxl6DpCXxtrHn0lqKwmQsb+vMHR+i6B2W/xpITgiuSDgYYvnYkdvZlTMq6H8nGoMKTwba3Xi9dlnrA83dMlCw86R6PB/K6/AnMXW6i0xqTIp5yVlN5K2yoH+HQq1cN7Igo6BzYZBhpCnxdis1nvE7865LM7MOPiOq6HF0oqoL2z+t/xAjZLA43K0UvfId9nwJdfpLNo0PqBydgv3RLDwCI+SeXY+g== 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=h7lBnpFYrtc6djAupnyaNsXnaoEAdK35uBV7rqFrUoM=; b=Hpg//tX+cug1nEagxCPBvUZebBsU6GevM7I4Z7msxy3wvXry/mGmoqN0RkiFMJq3b5rTicEu9K5ouZZHuLJwp7ItvhYvHlYhhxgUjWsKyNqm2zb60BfBTDAqAdW5ICrQ5jF0N6lblw7qQJx8ObijCI6pEjgG5MMbdsZwVBN5nkU= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) by VI1PR0402MB3552.eurprd04.prod.outlook.com (2603:10a6:803:9::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.18; Sun, 24 Oct 2021 17:18:36 +0000 Received: from VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::e157:3280:7bc3:18c4]) by VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::e157:3280:7bc3:18c4%5]) with mapi id 15.20.4628.020; Sun, 24 Oct 2021 17:18:36 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org Cc: "David S. Miller" , Jakub Kicinski , 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 , Prasanna Vengateshan , Ansuel Smith , =?utf-8?q?Alvin_=C5=A0ipraga?= , Claudiu Manoil Subject: [PATCH v5 net-next 06/10] net: dsa: lantiq_gswip: serialize access to the PCE registers Date: Sun, 24 Oct 2021 20:17:53 +0300 Message-Id: <20211024171757.3753288-7-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211024171757.3753288-1-vladimir.oltean@nxp.com> References: <20211024171757.3753288-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: AM6P193CA0123.EURP193.PROD.OUTLOOK.COM (2603:10a6:209:85::28) To VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) MIME-Version: 1.0 Received: from localhost.localdomain (188.25.174.251) by AM6P193CA0123.EURP193.PROD.OUTLOOK.COM (2603:10a6:209:85::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.18 via Frontend Transport; Sun, 24 Oct 2021 17:18:34 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ff83b70c-b9f4-4398-077b-08d99712506a X-MS-TrafficTypeDiagnostic: VI1PR0402MB3552: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:949; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: dfoPnra3poGjytfHHMDM0S+eYkGayeLyB55KA4UcDaBs1frX78Feuhf1HV1xmx33MUyGO0bynWFkXUUZj/0f1QVejs8LJbSdKihlp/scPz2XYETLISxE5s3prnA6kpVcPsFJGTCKVoujbiJwdATsxgGK3srPeaVDlEm8TwG49RmBm88aEWgAGIEqwU58IkOeAv647qCUaUdE1gv50MsJ0Eyi7Mr07kAdSoDsrwgZg0VoOrE8ZgRW6wFcuvql50YF4zn+8P7QGjtKK7HPoE51K5CHP8gH0M9HJmi/OnJtSezf1A2r9WAGuxUnvd5WyNcvVgVrQNSJEmZ/eZrpvf6A43WzJDf8Sns2qjN7zh6q5HjUuCx2MQYKBZLkvsgPL689GTMAjHbvspy6ovbj8yXbx62qKXUe+f4eVfjyiIXz3aW/kfZJEximw+Xd/WxMaG1YMWsRQbZYNiQtuEHOTVqGiKr+aANQh1u5Jg50ugo5LFjnrqULtkw+IFrTSEq2YEmZvn06zkA+zh7xhnHPmN6HL1MVTd6snPwVUv/D356eVzTg/UK81g3MXnT8XuTOjXqEjtNWEzDGy/eMyVS5/zEXhHyvs790lD0VgtkHJZXYGHKZd6KToQeme4W30qWDC/Cp3wKxF5YzDkKka8JiKF6lMrTnCWWtJ0bPFWarTa8LSTAXTmYzBLutf0OUnyiqt6K6UGcBn8u5GLtKmiXDk6xaQQ== 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)(6916009)(6666004)(316002)(54906003)(6512007)(38350700002)(38100700002)(26005)(2616005)(6486002)(956004)(36756003)(86362001)(7416002)(8936002)(1076003)(186003)(8676002)(508600001)(44832011)(83380400001)(2906002)(66476007)(6506007)(66556008)(52116002)(5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pV0FD27eFsGzVve2ObYVCsEGetC5e7h7bD1wFKTM7o/LdcHnlvpNMJdVrtDW+v9fAwJ6vBON4J0IsjodzDkJsIm3pmdq4/2XW6VxTBxE3Hg5sCLEEq72/UvptsTbuGZcRqKfSA/2UQC21Ja2qVKLBuGb9dFXHOKdMGHYxEVJ5HPqomdGuDFRogPD2MU3GuWDzeGmq8R2WC9929jXMBbG/uiAniABaV8d/3IHX6u0Yi500ckNH7mbxEM43LEmcVpGdwu7DFMSS4GSGbp0t1E/WoMPR81cdzR4Sa0616iEh94Wz+uVs9bU+unrzcYqLxyL+VzUikjCHmZhoPg7YH+J7n+jOkP1LoumjNWmOxO35iXhtP9R5voOR9iwjkS1RWoHjjsN90hf6W0ITDDCHXOK5LGPdQTT1Nzx7c4AdS4kldIf9cPRD6HtLzSvrsYnX1vw88gwlaJom/Hy6dJF47DBw/jtm39k5PoqEX7E/o4brxz14GRblVm4injHj+6CMo2i4TL7tKfrYwdx3H0afuF6HCUp4OI4pJgFBMY2RLv0LzB1Yv2u4nY5u9l1G9XM3YN8kXPNsXfEu2q0IB1jU4x8s7OD6WAoAcIPZdq2n/FVhBJf6DBgja8SrnACIL3TlEQrdfyKtLJ+U9afDUbKC0KWY= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: ff83b70c-b9f4-4398-077b-08d99712506a X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Oct 2021 17:18:36.5336 (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: EAFVK9jyIB09cpy8QspMsVPNIjXKcLl9AyAo/IbKRr765etlsp4QL1UPpdQyRaywQYj0wgLqyK0RJdJLtEFTeQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0402MB3552 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org The GSWIP switch accesses various bridging layer tables (VLANs, FDBs, forwarding rules) indirectly through PCE registers. These hardware accesses are non-atomic, being comprised of several register reads and writes. These accesses are currently serialized by the rtnl_lock, but DSA is changing its driver API and that lock will no longer be held when calling ->port_fdb_add() and ->port_fdb_del(). So this driver needs to serialize the access to the PCE registers using its own locking scheme. This patch adds that. Note that the driver also uses the gswip_pce_load_microcode() function to load a static configuration for the packet classification engine into a table using the same registers. It is currently not protected, but since that configuration is only done from the dsa_switch_ops :: setup method, there is no risk of it being concurrent with other operations. Signed-off-by: Vladimir Oltean Acked-by: Hauke Mehrtens --- v3->v4: call mutex_init v4->v5: slightly reword the commit message according to Hauke's indications drivers/net/dsa/lantiq_gswip.c | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/drivers/net/dsa/lantiq_gswip.c b/drivers/net/dsa/lantiq_gswip.c index dbd4486a173f..1a96df70d1e8 100644 --- a/drivers/net/dsa/lantiq_gswip.c +++ b/drivers/net/dsa/lantiq_gswip.c @@ -276,6 +276,7 @@ struct gswip_priv { int num_gphy_fw; struct gswip_gphy_fw *gphy_fw; u32 port_vlan_filter; + struct mutex pce_table_lock; }; struct gswip_pce_table_entry { @@ -523,10 +524,14 @@ static int gswip_pce_table_entry_read(struct gswip_priv *priv, u16 addr_mode = tbl->key_mode ? GSWIP_PCE_TBL_CTRL_OPMOD_KSRD : GSWIP_PCE_TBL_CTRL_OPMOD_ADRD; + mutex_lock(&priv->pce_table_lock); + err = gswip_switch_r_timeout(priv, GSWIP_PCE_TBL_CTRL, GSWIP_PCE_TBL_CTRL_BAS); - if (err) + if (err) { + mutex_unlock(&priv->pce_table_lock); return err; + } gswip_switch_w(priv, tbl->index, GSWIP_PCE_TBL_ADDR); gswip_switch_mask(priv, GSWIP_PCE_TBL_CTRL_ADDR_MASK | @@ -536,8 +541,10 @@ static int gswip_pce_table_entry_read(struct gswip_priv *priv, err = gswip_switch_r_timeout(priv, GSWIP_PCE_TBL_CTRL, GSWIP_PCE_TBL_CTRL_BAS); - if (err) + if (err) { + mutex_unlock(&priv->pce_table_lock); return err; + } for (i = 0; i < ARRAY_SIZE(tbl->key); i++) tbl->key[i] = gswip_switch_r(priv, GSWIP_PCE_TBL_KEY(i)); @@ -553,6 +560,8 @@ static int gswip_pce_table_entry_read(struct gswip_priv *priv, tbl->valid = !!(crtl & GSWIP_PCE_TBL_CTRL_VLD); tbl->gmap = (crtl & GSWIP_PCE_TBL_CTRL_GMAP_MASK) >> 7; + mutex_unlock(&priv->pce_table_lock); + return 0; } @@ -565,10 +574,14 @@ static int gswip_pce_table_entry_write(struct gswip_priv *priv, u16 addr_mode = tbl->key_mode ? GSWIP_PCE_TBL_CTRL_OPMOD_KSWR : GSWIP_PCE_TBL_CTRL_OPMOD_ADWR; + mutex_lock(&priv->pce_table_lock); + err = gswip_switch_r_timeout(priv, GSWIP_PCE_TBL_CTRL, GSWIP_PCE_TBL_CTRL_BAS); - if (err) + if (err) { + mutex_unlock(&priv->pce_table_lock); return err; + } gswip_switch_w(priv, tbl->index, GSWIP_PCE_TBL_ADDR); gswip_switch_mask(priv, GSWIP_PCE_TBL_CTRL_ADDR_MASK | @@ -600,8 +613,12 @@ static int gswip_pce_table_entry_write(struct gswip_priv *priv, crtl |= GSWIP_PCE_TBL_CTRL_BAS; gswip_switch_w(priv, crtl, GSWIP_PCE_TBL_CTRL); - return gswip_switch_r_timeout(priv, GSWIP_PCE_TBL_CTRL, - GSWIP_PCE_TBL_CTRL_BAS); + err = gswip_switch_r_timeout(priv, GSWIP_PCE_TBL_CTRL, + GSWIP_PCE_TBL_CTRL_BAS); + + mutex_unlock(&priv->pce_table_lock); + + return err; } /* Add the LAN port into a bridge with the CPU port by @@ -2106,6 +2123,7 @@ static int gswip_probe(struct platform_device *pdev) priv->ds->priv = priv; priv->ds->ops = priv->hw_info->ops; priv->dev = dev; + mutex_init(&priv->pce_table_lock); version = gswip_switch_r(priv, GSWIP_VERSION); np = dev->of_node; From patchwork Sun Oct 24 17:17:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 12580385 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6B32EC433EF for ; Sun, 24 Oct 2021 17:19:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5475E60E75 for ; Sun, 24 Oct 2021 17:19:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231872AbhJXRVk (ORCPT ); Sun, 24 Oct 2021 13:21:40 -0400 Received: from mail-am6eur05on2062.outbound.protection.outlook.com ([40.107.22.62]:57952 "EHLO EUR05-AM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231757AbhJXRVK (ORCPT ); Sun, 24 Oct 2021 13:21:10 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Pqeq5CzltkNc5xIlL9wWuuT1JtAhD7omNesLw76OEMwtoyVOY0YMYWpt/SglSBg0PNmZvDkhJZdS5ZLTLMqW3eETfvBzsgpHAzNfFZ6qP4Rqfy3tuypYWFKpBFGmUw90MGv89Qo/vKkciNE2pn/k0rttX+7kDv2p0uA8aGkX6/zVhkdYiG5QvOQMqN1mfExPOCcW+Srg6EUZdVstKgMWMO5VfzBFaMDfcrD2gmp1S9VY73uEhFVcxj/nuyV8orH2XhFF93vFu6AKIwulj5bNTAAzNSNCTTKlpUjesvs2vm7AVdt5EkKo7emDGNHYSQPIEHCZdYh8YcRb65oHq2+r5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=230hBZAYnrtPlET8NYvN0IvxYRdbMZOfo02GgFOSeg0=; b=gibcyHNHyNfWaHv3m8FXTf8+PzzcLI6YYHRUI3V0snWDXHx31thlABvSYox6qhJNuaEYKMxYAkYD42cH6Fcq2Fo4POt/4mEYc1GV7o80MTBt/n2g4XoNa/3FiOIpw4NHl00T0AZq2B2HxV9CdfH2Vp/kUXCEkN3f+KJyV2hcyNgB2EnfyDsj1dsAWtvfInwU6rgaig82m7dbg22m1zIcnl3KnzSoyIyTlP0FHdT9flRnOHq2faidiGdi8DQ7Hbt7aPTEGnCgbz0i+t9B4qKJT0D/NEmCZuPjr/oiTE7MHphicpvD/0wZhGCbJJAo6pvfDGh7xyUb4fI2NYcrsY1EYw== 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=230hBZAYnrtPlET8NYvN0IvxYRdbMZOfo02GgFOSeg0=; b=M4DkTAy8/Zz7gh4oW6Nfa3YmulQTrOU1BQh5Gu8ek1QQEUeiwIEvHj6fOodgYHzdFWGri6sS5D/99HOBsXqoxccchsh1yWdbue5taJfhut251r9Vqn8M80KH3qZFUaCpXn3qVUDwhU1Zgo6aJSZh1qiNA6aMEZetVaaYRJSgQQk= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) by VI1PR0402MB3552.eurprd04.prod.outlook.com (2603:10a6:803:9::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.18; Sun, 24 Oct 2021 17:18:38 +0000 Received: from VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::e157:3280:7bc3:18c4]) by VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::e157:3280:7bc3:18c4%5]) with mapi id 15.20.4628.020; Sun, 24 Oct 2021 17:18:38 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org Cc: "David S. Miller" , Jakub Kicinski , 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 , Prasanna Vengateshan , Ansuel Smith , =?utf-8?q?Alvin_=C5=A0ipraga?= , Claudiu Manoil Subject: [PATCH v5 net-next 07/10] net: dsa: introduce locking for the address lists on CPU and DSA ports Date: Sun, 24 Oct 2021 20:17:54 +0300 Message-Id: <20211024171757.3753288-8-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211024171757.3753288-1-vladimir.oltean@nxp.com> References: <20211024171757.3753288-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: AM6P193CA0123.EURP193.PROD.OUTLOOK.COM (2603:10a6:209:85::28) To VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) MIME-Version: 1.0 Received: from localhost.localdomain (188.25.174.251) by AM6P193CA0123.EURP193.PROD.OUTLOOK.COM (2603:10a6:209:85::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.18 via Frontend Transport; Sun, 24 Oct 2021 17:18:36 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 3b8281f5-4974-4d40-6027-08d997125185 X-MS-TrafficTypeDiagnostic: VI1PR0402MB3552: 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: AOsZUUNTynJM4iaCvYK7qUeWRzmV14M0KnvxRu100fdZdfgj4eiZqZrEquKJfQW+vSnMnX6NV7lMaD4eNufbruJtIgq3Mdo+psrD8RukAfe0NycTfDIyfKEB7dhVP+dgYrkfF4jc7W8hINzfWg6qHWsv0PXa+1rgB7QByrc9p4YdzJ0xF3q0Ygy4hm0cVA0BTuEu/hqArIS2Nw/GQqGQmP4CKnFKjEuAEJDpvCCPBWCJDsTEAhMKIboCo4QUs0BOLzP/UuvZE299eaEn7VGMb52NFSemFsjTOwTPdHZc95E7pwczMc4NRN7hcBuaGVqVI9AXTv6t02WW0hPzRYUz5Wzl+aaqbkCokqPB4OyWbwUX4F89yVbuoWM+4djND++emVXTAF+pvSTaNgGA9iDyLVPtXy5SN56NIlBMYOtMt2XP93hyEz2PGmNCUZ7VutLGgx1g9/HsbkbRRhdP8P5smeh60TCQuGxrgcQl3DKeBIXqSpPvqO23CrNMJyANk8LDrLzxn1aXzzpELGGEmmKHC3RYJqSNmyfUeG/qp/yQmreCHp2uhF8TOwa4xU/FSkf7mmmzX6P8Fd0nRSv2/myc/f7XC1lFaw76U46GWdjVlrp+wuUnmRsc9QRiQRnVWeAMwoMKDxCx2TqZT468Md7M9NYmCx0JdHxQBg6fN7/vB7os9nveWAkQTWSItGfnBQbg6QpO32Se1R1PjJqpsgbg9Q== 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)(6916009)(6666004)(316002)(54906003)(6512007)(38350700002)(38100700002)(26005)(2616005)(6486002)(956004)(36756003)(86362001)(7416002)(8936002)(1076003)(186003)(8676002)(508600001)(44832011)(83380400001)(2906002)(66476007)(6506007)(66556008)(52116002)(5660300002)(4326008)(66946007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 8fTls2eTpts0HV+yEcSx4WkxgiNR8jCzi0H+9NFk5W1ecYcntKB6qeFNCWMxnJVUab93fD2ZeavzKKGXE/qfru732449NEQCJNrvYZP00CLiltV2XCFUCCHAjG7VrJXfxhazGLtRbU+iM20RIrxp94pI3mVeWVJ6GzCnx9I8FSR2XxcbfFbKnsjm4goVS+2yZba8zVM0l2aZqlTDZASlIG4aEPTcv/Qpt6qjCQVNBCJMM3zEMeJISdpe3V9pN8rImJ0KGKKpjzqgGLEP3KH3NDvDOfM3ab5ZNt0EzHC2z6ZzTGnLTckbmX4AcettqEJ4MgEhFG2QUhWGnbnHBvtwuZ+cEH9gk31n/DJO5oKjbRfAsIksxknSnjXncEI4R347T3lclysKPkqthfEUGocEfJhgAIxDIsURUwdpOkLOTNW3oL/oMU+OCOcJzzbulBPX6fdf9QFKG5BRvhBzjye0vRTkEAG3kxZbl17z12aTAikxTasfNe5XiclEDg0uQcot4hkBhUH1bkRzE/+rpGeuILX1GsYx8zd7URfWSnezk5Wi3LnUnfF2TFso+0uvLAqoBzKy/PcIskmksnjHBef2p77366Cb2cfDJ6IGnmv97oMEobVEsUWAcWm3UlA5FJ7nG/C5i8WabkUT3MNn1u7DbFGauV/lCMOA49Qp1YmlYHSCYROCxQ+1eOdfXYYqTiZIDIw1RpOBgR6maDJvXYRNmx5P89BHcXkO8r70Oly5uuqrQIiqnqAa6t4xR67AWP21xpTD42jQb+SfKIAn8LUDwCW/8xE0Lpin0Qnn0c1rv8gb9OxPmfbJ90cslpaEh1e9pejxvuqUdLe77E9G5mtrpBZm3WetynbLf3yEJnofrgNnhKQg0+fPN7qQPxDQNw7BwDcHTuAaCWU6IZICuv1xLdVHXR/qhw9jdE2h/7HUhoHXke0iOKo4yefIZUGOiJm00CBniGWI80X4E5Bpg7S4JlmiLmOKfOIxyBRMS5OVVJwYV3/UiiXpTR7gK4KlCCQePshh6GPmg8BWX9wTK9jw2ttd4Y6/dQp7lobB0JgSrSeEvvI86aqR+eeI3/jBRHTuEkVy99Qm8wiZV9P6FO//1Id/P7Kk95y0tuUvIjVZEUNiO8wFrl/8UO9/wQsPjH9qTZ7jqdJ+stIMbS1RajPVpVEBYR6Fep9G+54MNYCCF3Nr2jHWZsLJNgNsbzTsdJ/leLZ3n1qLiR9oulm+jznTNYfr+cewiVaGrmZwe3PvyPba+FzTaW6ml+HmjGTl3J5CgV6R8lAAJreAPhbUjmT38MLp3p9DxXQXgJJC2spRP4dlr+gkFY/DOBujPywIp0NfdZ2C/PybLPwVuPgjXKKkZT7WgfxTCeMSuoX9rHUu1bRFePmA1Xamwhv+iY9HDS0fbCk9DgSWV1Zkb2pywqO4LVrGJS9SlcQpd+iluW0/rSyTVbDMMLQ/LdPhA+06u3lflSZIQtOOI+f18xJ852X6ImndvCxYHYptJDkmmNobgFcMOIT+pDHuIbFCZavwIZnCWVPOQBtXC8umzpwDk7kvNAY6Wsd//gy86FgtyWbtUigl6IoC/IXAus/uY4gn7Lh2Y/w2FXt/cH3GZgx469ibq1fqyKbAazNOvy8Yc1VFXO0= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3b8281f5-4974-4d40-6027-08d997125185 X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Oct 2021 17:18:38.3915 (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: t0KNIDmKKlXoW2HS2Hg2Zjhs4Fuw3/e5Wlb3T40N3QC/QWnM4arhZ+K/qqnCN/kfq4JNJs3g3qTw8E+E+qdVFA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0402MB3552 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org 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 Reviewed-by: Florian Fainelli --- v1->v4: none v4->v5: rebase over new patch 01/10. 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 1cd9c2461f0d..badd214f7470 100644 --- a/include/net/dsa.h +++ b/include/net/dsa.h @@ -287,6 +287,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 f5270114dcb8..826957b6442b 100644 --- a/net/dsa/dsa2.c +++ b/net/dsa/dsa2.c @@ -433,6 +433,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 8f8ed8248c2c..bb155a16d454 100644 --- a/net/dsa/switch.c +++ b/net/dsa/switch.c @@ -215,26 +215,30 @@ static int dsa_port_do_mdb_add(struct dsa_port *dp, struct dsa_switch *ds = dp->ds; struct dsa_mac_addr *a; int port = dp->index; - 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); @@ -242,7 +246,10 @@ static int dsa_port_do_mdb_add(struct dsa_port *dp, 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_port_do_mdb_del(struct dsa_port *dp, @@ -251,29 +258,36 @@ static int dsa_port_do_mdb_del(struct dsa_port *dp, struct dsa_switch *ds = dp->ds; struct dsa_mac_addr *a; int port = dp->index; - 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_set(&a->refcount, 1); - return err; + goto out; } list_del(&a->list); kfree(a); - return 0; +out: + mutex_unlock(&dp->addr_lists_lock); + + return err; } static int dsa_port_do_fdb_add(struct dsa_port *dp, const unsigned char *addr, @@ -282,26 +296,30 @@ static int dsa_port_do_fdb_add(struct dsa_port *dp, const unsigned char *addr, struct dsa_switch *ds = dp->ds; struct dsa_mac_addr *a; int port = dp->index; - 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); @@ -309,7 +327,10 @@ static int dsa_port_do_fdb_add(struct dsa_port *dp, const unsigned char *addr, 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_port_do_fdb_del(struct dsa_port *dp, const unsigned char *addr, @@ -318,29 +339,36 @@ static int dsa_port_do_fdb_del(struct dsa_port *dp, const unsigned char *addr, struct dsa_switch *ds = dp->ds; struct dsa_mac_addr *a; int port = dp->index; - 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_set(&a->refcount, 1); - 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 Sun Oct 24 17:17:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 12580381 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7449FC433EF for ; Sun, 24 Oct 2021 17:18:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5DE9D60F57 for ; Sun, 24 Oct 2021 17:18:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231766AbhJXRVM (ORCPT ); Sun, 24 Oct 2021 13:21:12 -0400 Received: from mail-am6eur05on2071.outbound.protection.outlook.com ([40.107.22.71]:35552 "EHLO EUR05-AM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S230426AbhJXRVE (ORCPT ); Sun, 24 Oct 2021 13:21:04 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mIWHONvfZIhiB486esYPMb6TLPstBs17rWfGEZqtWhQX2PvVsQ+MmYNF5BTRTQlJVdjP1/paiO9LfuTM4nHQ31TfQ0aXQLBYNAlP4F54cMvoINzEyeOQfi9OQFLNWmS4TavuYfiUD+DR1dCr431xdvhtfhLcoBzJYmhzfwdArVCGKrr5ZkbKc7Db4YbxnRfRueP4ePx92bV8ibl8vyDWzF43xtWmzhSSzo28za9zlNvXKjiRBiOtInUdyFRpaItRZCgL/CMaa6HyrkcxY71NPDFA20ChnVybR5GpoQaFfHWTebpaaN41fUSKkzdAlvlztyx2R9ofHyA4Fz1mr/ha2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=tBDsL9rFEzOE+N05o+H5pPZzyw+f2fkQtQ74UrthfI0=; b=cN2Fc/5TrAEgpv3OjnucDlhIfQ2pfp+FWGQIz8KEDQ3XIzHsFIREIClnODZvTIwXtQvi5bBHqjkgxuP3TKGelAtRDfRsZVHK+dy/+I2YshyclBGM1OBElUvX/HwJAULlRIvInQrZdX+5CzICr4SUG1X3UNDnKhNsffmbvG/NJy4nu79fAPy6Q6LjXPl9lVmrngPm54Ks7c7BrKYpKizHdto1HtWgKH9tHZNk+qClPe9gV4R8QfZp68c0066Rg5CP/oIne0lNpuGpsig+D7Ag+RkwOqXlVpGr27CXF3FSBRtOBq4Ea8jnSnO1Xj2yd1J0AUC7LFjXGKrhJ49JcRPsSA== 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=tBDsL9rFEzOE+N05o+H5pPZzyw+f2fkQtQ74UrthfI0=; b=q7NytyoxKail9+y7LMwZtJrLmN62+dLwkWJoOm+FF+J/F2FeRbjMySKv7krXumCdOcXzCPOw2PO1icdMGukj/ynas0LiMkFVfdrSowQIlVuKVTIgKUs7lv2iEXDPajRijTWXEt2STCagK3lcFZqYDCU1NupGrJpEVSnPNfHuZwM= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) by VI1PR0401MB2510.eurprd04.prod.outlook.com (2603:10a6:800:54::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.18; Sun, 24 Oct 2021 17:18:40 +0000 Received: from VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::e157:3280:7bc3:18c4]) by VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::e157:3280:7bc3:18c4%5]) with mapi id 15.20.4628.020; Sun, 24 Oct 2021 17:18:40 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org Cc: "David S. Miller" , Jakub Kicinski , 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 , Prasanna Vengateshan , Ansuel Smith , =?utf-8?q?Alvin_=C5=A0ipraga?= , Claudiu Manoil Subject: [PATCH v5 net-next 08/10] net: dsa: drop rtnl_lock from dsa_slave_switchdev_event_work Date: Sun, 24 Oct 2021 20:17:55 +0300 Message-Id: <20211024171757.3753288-9-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211024171757.3753288-1-vladimir.oltean@nxp.com> References: <20211024171757.3753288-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: AM6P193CA0123.EURP193.PROD.OUTLOOK.COM (2603:10a6:209:85::28) To VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) MIME-Version: 1.0 Received: from localhost.localdomain (188.25.174.251) by AM6P193CA0123.EURP193.PROD.OUTLOOK.COM (2603:10a6:209:85::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.18 via Frontend Transport; Sun, 24 Oct 2021 17:18:38 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 51363080-89d8-4950-2977-08d9971252a3 X-MS-TrafficTypeDiagnostic: VI1PR0401MB2510: 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: whUxfm9xBPQagvbpgKivReFKeB/xWEtO9KQfczPWZNKPWXA9nzvgfbdgxwqkRmAefTIVfzWp2yDdShYWXbfata+Niw99FUCsM64cxc697wZlMDSLH1PtQ7lH2r7Dh5Be+HBdMuAMtWYITNv+qeYwu6C0vi+r7f1oAHoT/HoJUov60XHWU0TS//buZiywPEWac2fuWu3vBDQNEE46QRmUhw4Yggz99OxBvWYGznxiWXc/pgbDdj8vT8AxpfEo4+0aJ8ybAqwaLJqHKueM0Nz9hoC6Je7qCtUTJVerDh1gUnCB3jWHd8imHInhqOiF0dRWIMVma3ut/v9RLrGHImpGT6Bv7XSpA+z+3YB+DFjuycHdPxmxwmcPo0RTPBrp4XWcjLleViAwjesjZM13dzjsqQ3DucSWWHetYgeagFoRblqX6vIgY7vTyflblDO98cI1phDzMKVEnCwLASgnXjAuuHMtHct4FHCpZYvR1LoXYrwoqyOGEeKQy7z09SK8xKnbVPYJznUx8/UqsT9MLjzVU37l9+hYdl8OlCNrkQUotbHkI2dVDgWFOKIUrrRLXC0pKpQlnB7Xbu53UntIHfvHkXjrhnPOFk0KLhLgbPFHL6L+eOkEJu+4H1NOtwabM951Do8i1ZfMvyHrU0lKgnsxESJK17WRWc2y9NwzTM0RDDJfXn8PeiuHBUN8XYVP8AVtSvF8213sUXJKflUgbRdc7g== 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)(36756003)(66946007)(66476007)(8936002)(7416002)(316002)(54906003)(4326008)(956004)(1076003)(66556008)(5660300002)(6512007)(6666004)(6506007)(83380400001)(44832011)(38350700002)(38100700002)(8676002)(6486002)(6916009)(86362001)(508600001)(52116002)(186003)(26005)(2906002)(2616005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: MtEMDgMvve9pD41J6l18XCbUN1JDp/6l0mh3FjrcFAVXgRVTukgSzikh2iFiK2xW7WbclNLDXmx0ILFsixfU98l58H/QzA/xQDQK23R2DyRhSEKfPVgmT0x6X91DOZX2hXu68IFZrMnWHjuXYqK7LXZhu+kwahpZ/wbhB6pGc74uM4IKnIMZRhJJefJ9kvQbHlkLi4WvCvOE1TSf2OM3DWrQyWBYRcvMFczusVHqDRJpjbzuVZwOiz1W/CsS0oHJ75rjad2m8WOMJUdyF2k38K4nBE8gn9ITqeb9HhF7vetF25ySTvMmyk3nUKU/vRqTfmwUBGQKdjn8kiax4uOD0a8GpCmiCkiPujqeqgNLGtC5XK/9e4empa90daFSdFdJeadsrZY/mZoRCSvPVmYG1c5hvNSrYSwlR0EKLF8Rd95axyQQK7V7qsjaRL7GjF7BeEXhfzT+mPLoOagDKyg7EJ/GEqcMcbXm49a4+b1W4pMIzZakkxI2QYkAFvSW8QWldWo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5cp3QOvIjQh/hidLYixqgeerw6bHw= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 51363080-89d8-4950-2977-08d9971252a3 X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Oct 2021 17:18:40.2505 (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: 1PVeKEsF7QiUaE4tofR+lWPn9cOj8yOxLAE4D1Th8FIvXTFtBNAjVT01sNOSQ71B9P4gzaD0ZkqxvSCDyhhlDg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0401MB2510 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org 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 Reviewed-by: Florian Fainelli --- v1->v5: none net/dsa/slave.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/net/dsa/slave.c b/net/dsa/slave.c index 9d9fef668eba..adcfb2cb4e61 100644 --- a/net/dsa/slave.c +++ b/net/dsa/slave.c @@ -2413,7 +2413,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) @@ -2448,7 +2447,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 Sun Oct 24 17:17:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 12580383 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4076FC433EF for ; Sun, 24 Oct 2021 17:19:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 22AF760E75 for ; Sun, 24 Oct 2021 17:19:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231867AbhJXRVg (ORCPT ); Sun, 24 Oct 2021 13:21:36 -0400 Received: from mail-am6eur05on2071.outbound.protection.outlook.com ([40.107.22.71]:35552 "EHLO EUR05-AM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S230492AbhJXRVJ (ORCPT ); Sun, 24 Oct 2021 13:21:09 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HC34Z2BAEyhIMvAY7UDo/3vpTnkYN+IdRHTXoSrCQ0TOCU0ipeAnkBKv0UkAumKSVF2OAnHVmqwCUH41H7H/AZu90InyaZ9KuQfZ1wVpLgb+giacthQsoGetrvEsMoNFVFxESyanxQ+hjGbXCtBI6nXDB7DsFLR+3dzTJoiMO4si8ouiqed/OhppcYkcPp7fdbckw731ikzKG7184IZNGgVVCO6pZ9kceXy+21mBfqXQM6YIkG2Xa6DBmrFwpYCmj2QKsIHh/m9Z31qntogqHe7oZg3tEVqlMAHvSdw4v0j2ICxpz2fOt0qoQuMpJlPTwXr8x+AX5ppbtiCI4Pu5dw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=7r3WVFO/H5uaAfhweT5TOwYQsf35ds3Hfjak7kZX3Ag=; b=eyph5ohyGZNIH+0fiBmM2TLAG84wde/BIAqpGX38nGCFAFL/VIS/xkcaFDo5owD+y1jGkxdc8HAROTjTW8lFEtUIyr/yrbXmXZ4Fqx6j/I1oKWYXKdMGKIYSn8y3hCfhV64XJAyP7kHmTtI4VtRZlmiZGQ0KG4YtLZtQgSWkxv7/CL5NZAMuf5kbGVb2MeMFajfQQp6YXBr5MlYw+aRRbNpAYQzqLJgAj+vF1tfgwwsqkXTO+5hehtQ98e/D44AVePy6a46aIDbTJ6t+C0M6CdvqtrT/y1SdBHT/vLC8/YZ6p57x0ltDyPVzOzSJq2Z0MlB7RyVfPOkfph+igRKM5g== 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=7r3WVFO/H5uaAfhweT5TOwYQsf35ds3Hfjak7kZX3Ag=; b=FSPEuj2cWnkbtFZbzwCY9oGW5zRWj8x99+1kUTZi3oEz7LjLzCXfr5OYdimew/Cau/8UDkFriJTD0K9shxSMdNmTRESmdeGLWRw+5ibiwxPECIT9LeGu4D5vbuY9j9dw1QmmshwfPge4kMw8DDdZZXHm9YwbnPVVhNAmixFUaHo= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) by VI1PR0401MB2510.eurprd04.prod.outlook.com (2603:10a6:800:54::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.18; Sun, 24 Oct 2021 17:18:42 +0000 Received: from VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::e157:3280:7bc3:18c4]) by VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::e157:3280:7bc3:18c4%5]) with mapi id 15.20.4628.020; Sun, 24 Oct 2021 17:18:42 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org Cc: "David S. Miller" , Jakub Kicinski , 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 , Prasanna Vengateshan , Ansuel Smith , =?utf-8?q?Alvin_=C5=A0ipraga?= , Claudiu Manoil , Nikolay Aleksandrov , Ido Schimmel , Guillaume Nault , Po-Hsu Lin Subject: [PATCH v5 net-next 09/10] selftests: lib: forwarding: allow tests to not require mz and jq Date: Sun, 24 Oct 2021 20:17:56 +0300 Message-Id: <20211024171757.3753288-10-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211024171757.3753288-1-vladimir.oltean@nxp.com> References: <20211024171757.3753288-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: AM6P193CA0123.EURP193.PROD.OUTLOOK.COM (2603:10a6:209:85::28) To VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) MIME-Version: 1.0 Received: from localhost.localdomain (188.25.174.251) by AM6P193CA0123.EURP193.PROD.OUTLOOK.COM (2603:10a6:209:85::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.18 via Frontend Transport; Sun, 24 Oct 2021 17:18:40 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b8295321-e050-447f-6e54-08d9971253e1 X-MS-TrafficTypeDiagnostic: VI1PR0401MB2510: 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: BBPg+O5XTBvsRKAzHCJtACCAbgMK8rCSKC6huVzyT03fnCVqHFIhYEM39Z7jSvxk6/oKGyvqf4Bre/X0KQHCFoBAKLI+JGcs5FKSe3RXv7p+/lWDGw/ukHhvpnTKR/NBjlbPQzU3C61YSo6XwABGxF2SFHjWEgDdoGCRM/sG4N53Rtou7Dm202a0NN0sK1y8j3+NTezf01cX+lZEuED30DM7D09F5qPkzwFVC7ZxVok6RWeLdsuclcibRtDRKJLDOfwx9ystHgfgKr3x8ROAX175uN9rGt7WWF9qyrCRQGFkai7qBEzldymK6kuNBkSmvP5ibBqwOCZ/QxdarcrY77Tq+Z7spNS0bkfm2/QVcpbliKLEs4f0ybVxuXEB5YahlEbR2hyXWrKF5kXMP0q13qK4zGBj0TUyIUzrVoYbopH8vo1im2P/t2ux3tRvQ6SIC9jrcaJVXAWZI0KTZXzsnzkitavwJaWy2ZjmY/b9lJ6m6ktNNVSn26vlZGTNXU3n/f0Wi73/DCnLo1qcWkWoMjH9caDmKvlc6i3X2wb4I6D5UDJQdmShSB0FK5D1hmv5zm74ySZpJ69iIk4xD9Gy5t2JO3ibaDhKb1edWiHDK6Myn6PlI3eevxtvD4U9ZhN49h0OdHrkqterPbVqmJgG/paNGoR1RPclw5Yaa5BHsvjwUjMB2oPVpIJFWGcpqhPbIAC/uqCwrhzTDgBqmj2JYA== 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)(36756003)(66946007)(66476007)(8936002)(7416002)(316002)(54906003)(4326008)(956004)(1076003)(66556008)(5660300002)(6512007)(6666004)(6506007)(83380400001)(44832011)(38350700002)(38100700002)(8676002)(6486002)(6916009)(86362001)(508600001)(52116002)(186003)(26005)(2906002)(2616005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: iZsbormCaMrC7PuLwTltpJNW1jszK7sCyn5WWH+tnfSY7pkD5PEwNPFFNz7tcaJLnKdBofVuC1s+/ZJFeVQCoF9udso/oo7STJ86eVk8cDTZmKzE/90xIm9fx76rXuRWO6yQJCCF8500SQ09a+KktinmFEJxE5Bq9Xxfwz90yIlkK9LQHjHHp5YSWp1cKJL6cxtDKNYJ3ODAwYJBIs34grsZG66M4rAK8rYOGdHEcCfWbAex0opUp65ORSCArof3u7PTOekkSQWRPjajV7qY9zdc+49Pv34yYWT/pppduUH7KuaIzMkEAD7CltDHWgaQyTGXOEGViLH53JkZ2nJtPxsMJTlxtcS+78km4YsNJrj/VElIYxlrlqOGcjVV04wSazUlkOKJoXUCjd0MLFuaLfy7zKsb8YSm6q6/XG4DYSu+xPpqsgOTGkIIM+GyC09cv7PWQ9gxpIepEbP6pcjGDFg/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ecxQoJnGC6O1VQpr11jSnRlin8Qkh+4PvakBXFW4dvzF98Rqc7aJEiDJHX45nEB/QtAQCF8/CVrCZ9S0tT9F74= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: b8295321-e050-447f-6e54-08d9971253e1 X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Oct 2021 17:18:42.3563 (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: AnQTMaNq8MfPQmZzdvy2gsTyuwhacUO34nirBXYsdh8cPVgAjsNQO8LRQgwHKkUMFKjldXVjWEnP9EkPjS5O5Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0401MB2510 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org 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". Cc: Nikolay Aleksandrov Cc: Ido Schimmel Cc: Guillaume Nault Cc: Po-Hsu Lin Signed-off-by: Vladimir Oltean Reviewed-by: Florian Fainelli Reviewed-by: Ido Schimmel --- v1->v5: none 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 92087d423bcf..520d8b53464b 100644 --- a/tools/testing/selftests/net/forwarding/lib.sh +++ b/tools/testing/selftests/net/forwarding/lib.sh @@ -23,6 +23,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 @@ -141,8 +143,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 Sun Oct 24 17:17:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 12580387 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2DCA9C433F5 for ; Sun, 24 Oct 2021 17:19:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 00CC960F57 for ; Sun, 24 Oct 2021 17:19:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231722AbhJXRVy (ORCPT ); Sun, 24 Oct 2021 13:21:54 -0400 Received: from mail-am6eur05on2071.outbound.protection.outlook.com ([40.107.22.71]:35552 "EHLO EUR05-AM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231851AbhJXRVd (ORCPT ); Sun, 24 Oct 2021 13:21:33 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YcV4cvmlqbUqQ5yxAItCdacDiJPRKf9OEKnl4cHfQ1pvWTcas8QDHvOyJVFKgytg5J3QoSzX712KEiLj7fgmyRZbW91usUFpKzFrNdgUFhOeWDSsi5WHSXvbQn9z4crBp+uGBFgBl+Ba64LVD3iWN3WD2LzHCo/4DMaiaHihc/v/yqHJNu1XauVR8X7MFzezxUxEptRMyg7xc2jqD1hy4ZCpqcK3L7IahjIBXCdjHo6m5CjGHp9Jadmk/YIpgCllPIdTPmy8vJSZVCGdwOzKCN8MJaA+uJ92OYoQlPb4vK8ftGtrzneiaxd/rG/ZEz8lLfqtAgM86eBV/rguRZk9KA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=/mc+KQ3MF36WZzSjX7TRpMA6EqZGroNvko7gBXDlt/Q=; b=cVgDuf+y6QnVwtVfS+QvCRyBresXQSdJ8mHcpsaHcnQQb1fqlb8wpG+eq+4WDvSNGNJn0+IEf/4K94h5IgRwH/2qEmVbvtiOd4dpISqlH11qkB5dd+2r9fRwY6GASwmEZ4M6OUKsfG63urTazTYza02h3ujVUNAaspg87p2MocFuAYLi5CqC9eLFtfBpT56FCEf/k9Kc1SfaBn7J72tCnsgUfc5xWzskd+WzPLSnR9wTUrQXA4gKtedncbgs+mOtrab+t9lV2cNnkrokUN2Sd70lh9j/EeMB2cXSRji5gu/wdpbudQ00yTbvRVW4+LZcsbw6T+Hr/Pbyw4Gz0p6WPw== 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=/mc+KQ3MF36WZzSjX7TRpMA6EqZGroNvko7gBXDlt/Q=; b=eP0Vuw9L9x7jPDVxM00j6V7n+jRh2EgQTNW6ui46IzrfZczuhV9Ys2KeRphAtnLxZkcqodGky4fxzJottMjH3f96rNLJWhSMgYj6i01GU/3WfVpyfd6AF/Dy575UapwG+tijukihSnvEGrWu5HbgPLtaRkvby5ZYVhvqmAtuZvg= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) by VI1PR0401MB2510.eurprd04.prod.outlook.com (2603:10a6:800:54::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.18; Sun, 24 Oct 2021 17:18:44 +0000 Received: from VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::e157:3280:7bc3:18c4]) by VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::e157:3280:7bc3:18c4%5]) with mapi id 15.20.4628.020; Sun, 24 Oct 2021 17:18:44 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org Cc: "David S. Miller" , Jakub Kicinski , 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 , Prasanna Vengateshan , Ansuel Smith , =?utf-8?q?Alvin_=C5=A0ipraga?= , Claudiu Manoil Subject: [PATCH v5 net-next 10/10] selftests: net: dsa: add a stress test for unlocked FDB operations Date: Sun, 24 Oct 2021 20:17:57 +0300 Message-Id: <20211024171757.3753288-11-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211024171757.3753288-1-vladimir.oltean@nxp.com> References: <20211024171757.3753288-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: AM6P193CA0123.EURP193.PROD.OUTLOOK.COM (2603:10a6:209:85::28) To VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) MIME-Version: 1.0 Received: from localhost.localdomain (188.25.174.251) by AM6P193CA0123.EURP193.PROD.OUTLOOK.COM (2603:10a6:209:85::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.18 via Frontend Transport; Sun, 24 Oct 2021 17:18:42 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6abb1788-de7a-4ca1-48e7-08d997125500 X-MS-TrafficTypeDiagnostic: VI1PR0401MB2510: 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: f2F9y0J1+XLBV5QRZPGgUN5aWT0DyVCGZEBSzY8ozY02qAGKTyHg0GR7krzNBkA52szw7x9ZkWbGdGGbklx4wmA5cKktzo52HRXAMirCLOq/O65L12dcDNBa1ea1hLmQTXF7Hnu5UUzSUubs/81w0Rgy+pP30fWv6A3GzCdU5Ie+6hN/43ddQvllqygktqoSwgmTRGsT2IOLCwPDLZ81THN0PvqcunasUOIlI26Vkm60IPptzifMWDGUEUyEjHKWRbZb0qJwfAmZdHBVffdqiRyEkaI0D4XblWMUmmXXp7upwwkcNgct862CRDrXov9bt3yNWUB41YQDfBFV38Hd/8a4z30MQwjAAdIwRqRWIp1j4eatcGX6wyAXBqx7R889M90gM+paLvkXb98iSthzdmx+Y6oAXmfobU9mxkOROESa6WeOukz0bHL0P7WQiKNRKRiecrlflx2u7q/EpT9vfsFJ/jsPKi9VGOmO/GJby2HUI9oi5cROd1ounn4P1DaD421klxXrFcmhgzxE3FUAZg1FvXV9PUsK/ehCZjx9EVBcQXn/mHjwbGEfGcUctlYqaPywMc6XTVD63j+o7f23oBiYHolUohO+Fr+S07WtSndCtXqpPwX2mXa20Jakp4VgtM2d+YMr+34WOZw08rudJigwgWisYgrPgRAkJ32k5rK4JuYtzh/2poFxKwpH9ClmEjIv+bPdrH9IpUc1BURFWA== 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)(36756003)(66946007)(66476007)(8936002)(7416002)(316002)(54906003)(4326008)(956004)(1076003)(66556008)(5660300002)(6512007)(6666004)(6506007)(83380400001)(44832011)(38350700002)(38100700002)(8676002)(6486002)(6916009)(86362001)(508600001)(52116002)(186003)(26005)(2906002)(2616005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: jNyabPm10jTPe//NBn5lCHOvkYODf//r65tv8L0unE+UWSwvH/HVs4yF2oAmqiPzQnBUg1c0k7fdGUzSU+RkyX3YNHBQOMHyXeRkCxzbQCM80AFULOt409iHK3Gsor1x2wMbkXyUujO/gFlQhP0bgcL105SRvJXAcUWTZTS2DVD6e8uJ2+dlbeefIBAqLPtaP8vOY1xm+lnneTTWyTUygb/mE2ZtnW4brGzYSJYFx5yAmbvGrA3TItNiZ1+/fEZJFZ397mLWKNA0dqsd0Dim8vEoVuezOG5QGof3vB2goOav48dTsOTnmiP07Lu8tauWxPgrULwln07pH3oztnkKhQsNrTDOuRE9YCa/77X60R0xtHf93c1JpiEgUXGV1aQ13FOFbMgewsDeUKrWZ3Qx6PmVZJVVcQXZ4f5/SqYkpYauM4fdUH0dkVuOOTUCRHJuf7OHKFrjYAfLEly8Ch+1y/FMpbku8IPiRdocgkJAFQjjg0hGimOszMexvwg9OBI95/cMvr9e0gT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M+tkCEvXc27nJl/zCiZRgU4LVOboox100837Q= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6abb1788-de7a-4ca1-48e7-08d997125500 X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Oct 2021 17:18:44.2372 (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: XzxB8sJSppid/lNCh1zz13ijWMvJKuG3St6mLXkODwiQBzThTCZELGMT7xW0u7+hKMsOhYf75x0xboslNS5qjg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0401MB2510 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org 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 Reviewed-by: Florian Fainelli --- v3->v4: - use "wait $pid" instead of "killall bash" :-/ - reorder "ip link del br0" and waiting for the background task on cleanup v4->v5: none MAINTAINERS | 1 + .../drivers/net/dsa/test_bridge_fdb_stress.sh | 47 +++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100755 tools/testing/selftests/drivers/net/dsa/test_bridge_fdb_stress.sh diff --git a/MAINTAINERS b/MAINTAINERS index c5aa142d4b3a..975086c5345d 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -13056,6 +13056,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..dca8be6092b9 --- /dev/null +++ b/tools/testing/selftests/drivers/net/dsa/test_bridge_fdb_stress.sh @@ -0,0 +1,47 @@ +#!/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" + kill $pid && wait $pid &> /dev/null + ip link del br0 + 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