From patchwork Tue Aug 1 14:28:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 13336819 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 76EC823BDC for ; Tue, 1 Aug 2023 14:30:01 +0000 (UTC) Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2086.outbound.protection.outlook.com [40.107.20.86]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5833F2D43; Tue, 1 Aug 2023 07:29:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Z8FWlOifJxbYOaufSY9oiJpNPbOtKD9OIQTFh5PvPF9wGnA8TEVbIxKOYDo1k86hS0dsWwT/P5Iw+iPyev2rApfeXODPwu40lLYb6lyTelmPyNtzZcR2nCEvx4GIqMxQZewcU82gAqptVVAO9vlc2MiWiQJDfwrlX1KWRd+ifDui+YVzEVD9riEXzao32R4HrwbqW7bJV7EbmgOL90RTUSkJNLVoRu8OnCgGvILT1Ru7C2gn2ZFubgmNa06V3TKVk4WOAYyqseYhvVJ2gDdPp6xZ7JuV1tTcpe8E6bO9m9Zhe06jpBds8G2E1TD4jEz5Om+zHRGyPGquqKbIIs6jHQ== 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=63i4RIO0hRqAdpqxIzyNOwO1JsLOxgr196bQsQPuJ6Y=; b=M/m53WsJay9vg/oK8lm/lenDB2P6TKICfnUSs/0Jzjtbl3YZig/ebZ4vIN3BRCBMAGld2+mVNcnaTbsxi0R8v96hrF5D8hfcY+9RQuZ/kwElrdhIS49cOUsoBWndSc5JvaBjvn9l22RFYR4dtROh/ChVmUZsE0eD8RZAx2KtBkgdm6tCtDoz0YOPJDEBJbPMKXt+Dkvvit7jjLlIDi8nY/JOe8lbf2WDQrz21X5geAjR4imHv4xd08mxJXh+75Fhvby5CY01R7qLGueawRT4vYWmsGTbtEJFVgy9D6Hql1Ad76jol5FLq+KgDxh2rattyve2bWVhlqwjsySP+pnAlw== 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=63i4RIO0hRqAdpqxIzyNOwO1JsLOxgr196bQsQPuJ6Y=; b=n7kIw30rsNXjn8Ev71hmQsQfbPw6b3ueaHxi1y6ACT7C2ggmtoTWEw19PMV3B4tTIIJCGtLgP4YhRvtEbOO5wF7QoKJX2z2F61/wYdKglk3PNBQSvuwuUKykzDVmtqDgUKSoPSXQ74CPFEEgkEBycPk99c7Y6DPaMbbhaWIkq4k= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM0PR04MB6452.eurprd04.prod.outlook.com (2603:10a6:208:16d::21) by VI1PR04MB10028.eurprd04.prod.outlook.com (2603:10a6:800:1db::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.43; Tue, 1 Aug 2023 14:29:42 +0000 Received: from AM0PR04MB6452.eurprd04.prod.outlook.com ([fe80::6074:afac:3fae:6194]) by AM0PR04MB6452.eurprd04.prod.outlook.com ([fe80::6074:afac:3fae:6194%4]) with mapi id 15.20.6631.043; Tue, 1 Aug 2023 14:29:42 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org Cc: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Andrew Lunn , Florian Fainelli , Maxim Georgiev , Horatiu Vultur , =?utf-8?q?K=C3=B6ry_Maincent?= , Maxime Chevallier , Richard Cochran , Vadim Fedorenko , Gerhard Engleder , Hangbin Liu , Russell King , Heiner Kallweit , Jacob Keller , Jay Vosburgh , Andy Gospodarek , Wei Fang , Shenwei Wang , Clark Wang , NXP Linux Team , UNGLinuxDriver@microchip.com, Lars Povlsen , Steen Hegelund , Daniel Machon , Simon Horman , Casper Andersson , Sergey Organov , Michal Kubecek , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v9 net-next 10/12] net: transfer rtnl_lock() requirement from ethtool_set_ethtool_phy_ops() to caller Date: Tue, 1 Aug 2023 17:28:22 +0300 Message-Id: <20230801142824.1772134-11-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230801142824.1772134-1-vladimir.oltean@nxp.com> References: <20230801142824.1772134-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: AM0PR04CA0027.eurprd04.prod.outlook.com (2603:10a6:208:122::40) To AM0PR04MB6452.eurprd04.prod.outlook.com (2603:10a6:208:16d::21) Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM0PR04MB6452:EE_|VI1PR04MB10028:EE_ X-MS-Office365-Filtering-Correlation-Id: f42c4530-c5c8-45e9-f855-08db929bbe92 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: W9lyGaZEldL6SJA0qHzRwa2XzBbdNtY1PqR+uCiBKJ3MDT37Rig432T1tdWmYHtaPfeWo1+6c7NiRJRfq0lIP9BNCz1oS5ZVGI0qCZpXLpfCU3iACaYiT0ifIzJijnTezosJV6XsndS8v3r89D/7KB8mKn9WFt+nQHyspaxTi0fG/96Cb5VOhLHhQfyEaBT+WgkHMIXrmvBGbeFvl0lO0rM9VfIYJvUnlz9cUR4XUiqCI43kmlf4vIWTdOrqWzl+wlogM47GLokGCcCg2WTtVAr8YfoUsZd5Qk0T40B2ndxh4GQus8Z6ek0tDy5wY/FuqBli+HxDOdmKQgQW3uDGvjvR2/p5zOo2mXHGLnvVJ+TR39aJwPh5nP4HLGI7sMefXu+Fv/HhZye1GR38esTZvzALNmgSmG+YqcZcoAiZna0Cy/x7qgKmxR1M8npDbtuzQIeoaRqomqRARk+w9F3z3bVq1L1c0oq4HgF1NcyewcTlPXwmp3/U1VKs/di6Pe6Uj+wzvNabcub5PjFhFcyyLp6N/wPyvlCwXz43k9TOZwv9J2uRGhLCgfHwfN73iUEUiZGvZnNynmifFFmvz0ypgFgHmIX9cKjXlIxxlz9q52Z9mZOze6yn0/JE9QaT2y7s X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM0PR04MB6452.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(366004)(136003)(376002)(346002)(39860400002)(396003)(451199021)(66476007)(66946007)(6916009)(66556008)(2906002)(4326008)(44832011)(5660300002)(7406005)(54906003)(41300700001)(316002)(7416002)(2616005)(52116002)(6486002)(6666004)(26005)(8936002)(6506007)(1076003)(8676002)(186003)(83380400001)(478600001)(36756003)(38100700002)(38350700002)(6512007)(86362001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 7TS74d4mUtkRc4jqGMZufG4sHrqlqKmtR8mciPa9S1cMNoPkMO2hhNe8qgV5gtDgXprgxT9JwjzkaiV6n2KRyv6F+H23Sz9EF35Oh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KiDZG9Ud7bxGxVy3vDEpa6gC/2tf8GrcH4ET30dg1ave8TCWEnyZjmzRzimdiuPGRXoosZfgE9BoJjHWEo72W6iQsji93Zp/6ZjDF3M3jeRjxamIYwv0XpEyLwePH3BybX5ZkaFseH+d//KPSrk5umETcb8hv7LhXexyBrgshN/A5A4o/YjTveJlUKVS4sgtnwclkxyvWu3NVoD7XIwsCY7EyGONYWPkAnd+hJX8x1oXGyCQacSH9fa8On1Ew16iA7XmTp+1JTSBgs194JWXayWQxk7I1IqrB4vMfN4zUPujec0iFTMNb8URDPwN3fR4AN6SJyX9/gblaqAeAH+1GbPTt9ymE2+eG6TUlIGYOtohkDiS3MaMK9oN+sDICOPb4RS9nEphrAq57bHmwkY1OFXhFd0o7Q4Zu5CEO0jwHBNBWLiyB60g== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: f42c4530-c5c8-45e9-f855-08db929bbe92 X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB6452.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Aug 2023 14:29:41.9508 (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: zZ/dKAaceddiaqDhbVUGwSb/K/ORzdXN9SH3uOFYuwhwvh2YE6YHB0lFLvh/Q/K9X8QccM2Q4QNLupVW+le0Vg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB10028 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org phy_init() and phy_exit() will have to do more stuff under rtnl_lock() in a future change. Since rtnl_unlock() -> netdev_run_todo() does a lot of stuff under the hood, it's a pity to lock and unlock the rtnetlink mutex twice in a row. Change the calling convention such that the only caller of ethtool_set_ethtool_phy_ops(), phy_device.c, provides a context where the rtnl_mutex is already acquired. Signed-off-by: Vladimir Oltean --- Changes in v9: - Rebased on top of 1c613beaf877 ("net: phy: prevent stale pointer dereference in phy_init()") Changes in v8: - Patch is new drivers/net/phy/phy_device.c | 7 +++++++ net/ethtool/common.c | 3 +-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 61921d4dbb13..98b8ac28e5a1 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -3451,7 +3452,9 @@ static int __init phy_init(void) { int rc; + rtnl_lock(); ethtool_set_ethtool_phy_ops(&phy_ethtool_phy_ops); + rtnl_unlock(); rc = mdio_bus_init(); if (rc) @@ -3474,7 +3477,9 @@ static int __init phy_init(void) err_mdio_bus: mdio_bus_exit(); err_ethtool_phy_ops: + rtnl_lock(); ethtool_set_ethtool_phy_ops(NULL); + rtnl_unlock(); return rc; } @@ -3484,7 +3489,9 @@ static void __exit phy_exit(void) phy_driver_unregister(&genphy_c45_driver); phy_driver_unregister(&genphy_driver); mdio_bus_exit(); + rtnl_lock(); ethtool_set_ethtool_phy_ops(NULL); + rtnl_unlock(); } subsys_initcall(phy_init); diff --git a/net/ethtool/common.c b/net/ethtool/common.c index 5fb19050991e..f5598c5f50de 100644 --- a/net/ethtool/common.c +++ b/net/ethtool/common.c @@ -665,9 +665,8 @@ const struct ethtool_phy_ops *ethtool_phy_ops; void ethtool_set_ethtool_phy_ops(const struct ethtool_phy_ops *ops) { - rtnl_lock(); + ASSERT_RTNL(); ethtool_phy_ops = ops; - rtnl_unlock(); } EXPORT_SYMBOL_GPL(ethtool_set_ethtool_phy_ops);