From patchwork Thu Sep 14 15:34:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Russell King (Oracle)" X-Patchwork-Id: 13385635 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 79AA61CFA1 for ; Thu, 14 Sep 2023 15:34:33 +0000 (UTC) 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 CBD48CE for ; Thu, 14 Sep 2023 08:34:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=armlinux.org.uk; s=pandora-2019; h=Sender:Content-Type:MIME-Version: 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:In-Reply-To:References:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=oaKfQGpMMn72gwZ88Ye3fR6rJs56XMRuBIxQGzbcdM0=; b=ZNtFGrgLSDILYlMTU1kKruTrg9 gTKWKH7NHWDTUt2AuUdYDGxZuXBlECFrjVG4tJQ1zaEcjxLVTcErnCeUfGhPoqnd9B7rTRnrkx6x0 hCduaYpKA7WSCSsvqYGmdUyyR/eV5JC4U4F1Cp5qZcYLjspcpyf1yc8O0DrhOVBzl5oOEPiqPx9sw d5hpUaFR+Bg/7tUYimFzRC+/6myGmqo1RRFaGwGaSVmcw0WLH7LeW47p2fdb6NRneWQrbBSC/V+Sd SLh2hqMXz+7IppgBK2DiDaIwsY73A/uXhY6FU0sxiVc1Mmv3DdPZ0i8459HioxhiFTQ9MWPBDoFOG EP1dIEtw==; Received: from shell.armlinux.org.uk ([fd8f:7570:feb6:1:5054:ff:fe00:4ec]:60278) by pandora.armlinux.org.uk with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1qgoME-0004VO-2D; Thu, 14 Sep 2023 16:34:18 +0100 Received: from linux by shell.armlinux.org.uk with local (Exim 4.94.2) (envelope-from ) id 1qgoMD-0004sp-NR; Thu, 14 Sep 2023 16:34:17 +0100 Date: Thu, 14 Sep 2023 16:34:17 +0100 From: "Russell King (Oracle)" To: Andrew Lunn , Heiner Kallweit Cc: chenhao418@huawei.com, "David S. Miller" , Eric Dumazet , Jakub Kicinski , Jijie Shao , lanhao@huawei.com, liuyonglong@huawei.com, netdev@vger.kernel.org, Paolo Abeni , shenjian15@huawei.com, wangjie125@huawei.com, wangpeiyang1@huawei.com Subject: [PATCH net-next 0/7] net: phy: avoid race when erroring stopping PHY Message-ID: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline Sender: Russell King (Oracle) X-Patchwork-Delegate: kuba@kernel.org This series addresses a problem reported by Jijie Shao where the PHY state machine can race with phy_stop() leading to an incorrect state. The issue centres around phy_state_machine() dropping the phydev->lock mutex briefly, which allows phy_stop() to get in half-way through the state machine, and when the state machine resumes, it overwrites phydev->state with a value incompatible with a stopped PHY. This causes a subsequent phy_start() to issue a warning. We address this firstly by using versions of functions that do not take tne lock, moving them into the locked region. The only function that this can't be done with is phy_suspend() which needs to call into the driver without taking the lock. For phy_suspend(), we split the state machine into two parts - the initial part which runs under the phydev->lock, and the second part which runs without the lock. We finish off by using the split state machine in phy_stop() which removes another unnecessary unlock-lock sequence from phylib. Changes from RFC: - Added Jijie Shao's tested-by drivers/net/phy/phy.c | 204 +++++++++++++++++++++++++++----------------------- 1 file changed, 110 insertions(+), 94 deletions(-)