From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 533ECC001DC for ; Wed, 19 Jul 2023 06:11:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=e6VriyerOyWThC7mnRJJUzSDJLVNIBQhlgD/6dhiP8s=; b=OCspZtxezI2iVG EsghyGcwN21AoeH/MqBKw6dLDzPBYa2bGPYJ5AAlh/JBpT+5yKG5SEpRLvS9W5FZBPdwjcguPcetX Q9Xug7dRmqyw/0c1Jn1P3ml/dmsL7uVDzaZXFgzyXmskKjujHFfcBh22dfVWbEQmNj88ZChps+VP0 wLFMk9MkRseZKWExLpECqzAQZ7LajserYZCyKehby0a4XegkQTyFW6EJLFkipKFzPNDzK85I8PE1b XOBgFtRgp/2dL1/b/+IuHyvK/dEqjwoBRLlytmgqVDbM7fI9Rn+Hx1NcSEwgALgl8w8XV7jDbfOv/ +a9HgrRgmyljY8XXJuUg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qM0Ov-005aL6-0O; Wed, 19 Jul 2023 06:11:05 +0000 Received: from desiato.infradead.org ([90.155.92.199]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qM0Op-005aHw-1w for linux-arm-kernel@bombadil.infradead.org; Wed, 19 Jul 2023 06:10:59 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=XL5HpWpvSZ6bXIocoWJRq1XHyxJYL5lSUA7SoP9MkaA=; b=PVxGhj11iCN4nEoS97nioAlXBu HadMy+bl4Skas49hEeVrAgTcPOT7aRO2OC7ozSWmIPoRheT7jcSMKnPZNOyaXv7pcqk7tWzt0PLeB 3n0Y9G+2MrpPeirj+n1SduXc12Gl5vP6kMrogB0dQnkBqvj44EGVGcWgW5PcG8NmwsUWy3nR42Fr4 vP+MbVNUJ6oVeSqBPkjCL9tPewiqZ2fcaaIa6cDwjIm9xKlryxrowUqs2evHNL1g1EVFHW2OpjCiI Tmjdbg/NDUnwSiOtK+gT/I90ktznnOrGx2YFMa6opnS9VnXDHFu66w3isGCWuCsO4YSzybYdfZF/z kZiyStPg==; Received: from pandora.armlinux.org.uk ([2001:4d48:ad52:32c8:5054:ff:fe00:142]) by desiato.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qLlm7-00Bdkl-0B for linux-arm-kernel@lists.infradead.org; Tue, 18 Jul 2023 14:34:05 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=armlinux.org.uk; s=pandora-2019; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=XL5HpWpvSZ6bXIocoWJRq1XHyxJYL5lSUA7SoP9MkaA=; b=1T01Z0VtbWfEgVQgd7NQ64UAZh EOzIk/fiDOXv1fS+d/KyaJdEnbIoVXqbVX0dcJgReaJfVk4wPhZewzegSQwKtKTXgtQxmqnNn+CFw IKdDKxYI2BUTcyJ9MHPTDbcHzYeJKoVuatsHjFv6/fITu/IKRAysCnqotbNGmObz9MG6L2a5ud7w+ ZrA72n/yuWglqXXdVZOLgRrkuca/EOOHZjENHlcH94soqFtkSn77PF86iNTnhMGNBzcvRjjLouJBh JG1njiXJJg98GleMFHzYQ9YlNo4X8kmXcsZLUYq1vEh/ROK6hgUtLRuIDaROIoegCb3xUI3qk849M CRfqNvjg==; Received: from shell.armlinux.org.uk ([fd8f:7570:feb6:1:5054:ff:fe00:4ec]:49238) by pandora.armlinux.org.uk with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1qLljE-0005oW-1J; Tue, 18 Jul 2023 15:31:04 +0100 Received: from linux by shell.armlinux.org.uk with local (Exim 4.94.2) (envelope-from ) id 1qLljD-00036w-Cz; Tue, 18 Jul 2023 15:31:03 +0100 Date: Tue, 18 Jul 2023 15:31:03 +0100 From: "Russell King (Oracle)" To: Vladimir Oltean Cc: netdev@vger.kernel.org, "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Andrew Lunn , Florian Fainelli , Maxim Georgiev , Horatiu Vultur , =?iso-8859-1?Q?K=F6ry?= Maincent , Maxime Chevallier , Richard Cochran , Vadim Fedorenko , Gerhard Engleder , Hangbin Liu , 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: Re: [PATCH v8 net-next 10/12] net: transfer rtnl_lock() requirement from ethtool_set_ethtool_phy_ops() to caller Message-ID: References: <20230717152709.574773-1-vladimir.oltean@nxp.com> <20230717152709.574773-11-vladimir.oltean@nxp.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20230717152709.574773-11-vladimir.oltean@nxp.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230718_153403_334479_F01E24F5 X-CRM114-Status: GOOD ( 17.47 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Mon, Jul 17, 2023 at 06:27:07PM +0300, Vladimir Oltean wrote: > 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. > > Note that phy_exit() wasn't performing the opposite teardown of > phy_init(). Reverse mdio_bus_init() with ethtool_set_ethtool_phy_ops(), > so that this is now the case. To me, this looks buggy. > @@ -3451,11 +3452,14 @@ 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) > return rc; If mdio_bus_init() fails, and phylib is built as a module, then we leave ethtool_phy_ops pointing into module space that has potentially been freed or re-used for another module. This error path needs to properly clean up. The same is also true for the other failure paths in phy_init() which already do not cater for their failures leaving a dangling pointer in ethtool_phy_ops. This should probably be fixed first in a separate patch for the net tree. Thanks. -- RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last! _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A9CD1EB64DA for ; Tue, 18 Jul 2023 14:31:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233050AbjGROb1 (ORCPT ); Tue, 18 Jul 2023 10:31:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50952 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233011AbjGRObW (ORCPT ); Tue, 18 Jul 2023 10:31:22 -0400 Received: from pandora.armlinux.org.uk (pandora.armlinux.org.uk [IPv6:2001:4d48:ad52:32c8:5054:ff:fe00:142]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 910261BC6; Tue, 18 Jul 2023 07:31:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=armlinux.org.uk; s=pandora-2019; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=XL5HpWpvSZ6bXIocoWJRq1XHyxJYL5lSUA7SoP9MkaA=; b=1T01Z0VtbWfEgVQgd7NQ64UAZh EOzIk/fiDOXv1fS+d/KyaJdEnbIoVXqbVX0dcJgReaJfVk4wPhZewzegSQwKtKTXgtQxmqnNn+CFw IKdDKxYI2BUTcyJ9MHPTDbcHzYeJKoVuatsHjFv6/fITu/IKRAysCnqotbNGmObz9MG6L2a5ud7w+ ZrA72n/yuWglqXXdVZOLgRrkuca/EOOHZjENHlcH94soqFtkSn77PF86iNTnhMGNBzcvRjjLouJBh JG1njiXJJg98GleMFHzYQ9YlNo4X8kmXcsZLUYq1vEh/ROK6hgUtLRuIDaROIoegCb3xUI3qk849M CRfqNvjg==; Received: from shell.armlinux.org.uk ([fd8f:7570:feb6:1:5054:ff:fe00:4ec]:49238) by pandora.armlinux.org.uk with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1qLljE-0005oW-1J; Tue, 18 Jul 2023 15:31:04 +0100 Received: from linux by shell.armlinux.org.uk with local (Exim 4.94.2) (envelope-from ) id 1qLljD-00036w-Cz; Tue, 18 Jul 2023 15:31:03 +0100 Date: Tue, 18 Jul 2023 15:31:03 +0100 From: "Russell King (Oracle)" To: Vladimir Oltean Cc: netdev@vger.kernel.org, "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Andrew Lunn , Florian Fainelli , Maxim Georgiev , Horatiu Vultur , =?iso-8859-1?Q?K=F6ry?= Maincent , Maxime Chevallier , Richard Cochran , Vadim Fedorenko , Gerhard Engleder , Hangbin Liu , 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: Re: [PATCH v8 net-next 10/12] net: transfer rtnl_lock() requirement from ethtool_set_ethtool_phy_ops() to caller Message-ID: References: <20230717152709.574773-1-vladimir.oltean@nxp.com> <20230717152709.574773-11-vladimir.oltean@nxp.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230717152709.574773-11-vladimir.oltean@nxp.com> Sender: Russell King (Oracle) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jul 17, 2023 at 06:27:07PM +0300, Vladimir Oltean wrote: > 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. > > Note that phy_exit() wasn't performing the opposite teardown of > phy_init(). Reverse mdio_bus_init() with ethtool_set_ethtool_phy_ops(), > so that this is now the case. To me, this looks buggy. > @@ -3451,11 +3452,14 @@ 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) > return rc; If mdio_bus_init() fails, and phylib is built as a module, then we leave ethtool_phy_ops pointing into module space that has potentially been freed or re-used for another module. This error path needs to properly clean up. The same is also true for the other failure paths in phy_init() which already do not cater for their failures leaving a dangling pointer in ethtool_phy_ops. This should probably be fixed first in a separate patch for the net tree. Thanks. -- RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!