Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp6963288rwp; Tue, 18 Jul 2023 08:09:34 -0700 (PDT) X-Google-Smtp-Source: APBJJlHwF21WdBt/8jLJRg9fGBL/YeTxGDmmP9Up2E7YPi1tq+K6BdPXAEpP6IVgVUfEzTL8k4YY X-Received: by 2002:a05:6512:3e10:b0:4f3:d682:7b1c with SMTP id i16-20020a0565123e1000b004f3d6827b1cmr12896167lfv.45.1689692974488; Tue, 18 Jul 2023 08:09:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689692974; cv=none; d=google.com; s=arc-20160816; b=I4STtsk1eROt2fVEzzwTJQD1Q+PEa9+tC6S3ZniA3zxKT3f+3hE/4YAhrYmHBVC38l q93hjd0TWNOM8f61e1Ams5ijFqtyoQgf4ssD0QJaJ/HcrmJncZ8vQz2O082vul4N4yd/ EjBm3SMtCX1bEU4ebsKoYbnAXmV6QF3KFzDcmcf7iiQf7g+kxUWjpwOKrnlvzBK9qg91 yi8jfXcQLDTmpK6eUkG5drVV34RXT2277tXZe1N6sayeYEw1Nf6+xlsX1kxTAaBs1Me6 pheSmfSMbsKU6vFRICaQSS2duGbHVQZSjASSmda8bpWgJ446FUz7K0GVLjXmE+3vAr9x sK1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=XL5HpWpvSZ6bXIocoWJRq1XHyxJYL5lSUA7SoP9MkaA=; fh=FQpGiJqXcDAKdIeOpDvf0PXe5BQsBpqV61wNNvIszzM=; b=ISruFvtM5HbrRRY+tPaf8RyhUEVCXKR317fKNYVblr3Wc/a+NJz1lS9Wkzc9i1EuGM OOZ+epNm/xEjdyzdIErQIAiMdjE365Ik+m+4Z27kzDGdLaWSwk3zhEPETq9AHiHfgrXn 0gfRvkLXLFsKgN2DUYYUn/D2SHPmDuAbhVtQ7/aePQracaykGg6aYt2QfQAAoVCqyw6O ilCEijj3c6z592lUDp4NUGlkPqbuxTu1HS3fr1QVH88wfFszhFw4Cq0u9hTIWioBA2Op DWg74oAaiJyFt2npH94cAWQdIE1DfsC/fa0Uff+NAHRq8WXoujoIEsBnerz/xDr5BPDh jy2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail (test mode) header.i=@armlinux.org.uk header.s=pandora-2019 header.b=1T01Z0Vt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=armlinux.org.uk Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c6-20020aa7df06000000b005214c004891si1337227edy.577.2023.07.18.08.09.10; Tue, 18 Jul 2023 08:09:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=fail (test mode) header.i=@armlinux.org.uk header.s=pandora-2019 header.b=1T01Z0Vt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=armlinux.org.uk Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232403AbjGRObZ (ORCPT + 99 others); Tue, 18 Jul 2023 10:31:25 -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) 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, SPF_HELO_NONE,SPF_NONE,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 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!