Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp5534866pxb; Wed, 26 Jan 2022 14:23:16 -0800 (PST) X-Google-Smtp-Source: ABdhPJxcULcGnjLegJdsxk73ejyiws8xyxHGlicpJxMd/vKXaKPVsfAVfwjyWMxawyYUojL8R7iN X-Received: by 2002:a17:907:60cd:: with SMTP id hv13mr672525ejc.684.1643235796410; Wed, 26 Jan 2022 14:23:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643235796; cv=none; d=google.com; s=arc-20160816; b=iIDFXeH2Ty4lU5B/sNjcaJAAjP2MiUkLYPHNMO3oI8bmFSFQhck3QjiyNHD2V5dhNp QCIsnnPjTD28Uh/LL2OAsctW7A3KBPNoG8baduXBj2t9rjci0VAVMqFcGbaUGRftcJZl AUV+3AUOKiKXd2kK2wUaX6rOpE7yWOlQnRcnuI5WOT6XXc5YelMcnJUTHJJLXzO0ff28 txh4PYplPW+OE+itzDS3nDUovgoKAhz5h1eqFROBojK1fyWXeIhr9HKpcYJXZVFn5bqw aoFgb4c0ghKP0RZC0Kl9Dd8fT2bzijNYV9siuomH8MtF7gmc8iCCE5dk9rQUvhDXoFUW s8qw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=/5U/f01hoysCmf4bFzZvFu0I/Psix+HdShMDXAHWJOA=; b=U/SS0Mc+50NykJiyIGBxBIo2Nyc44FqSmwM2jktE74bfIgM1BVnnkP39DJaQqWNasO ifWwpQkVa4NR6HM67JJJPJpi8NS5IPwMd2tV9swD4wSNnP1K+knOqItGTkuCm58YcsFq HukTpj4ZffuiOOm+3I0rKBQz1OYPTFQ3UvJ9oWjZeCPpj5j1X7V0RGR2jRXnSXnc44x+ +K0/j2AZAZTF4Tq19huc/mer01oeNRaS2tsNIe6LWIyJSjlSgP/TtGP+1Z62sAvUTgg9 wN1lGttxp19eACjSl7+Xo6fayx8nDZ3TUPtgDz6Wu/nC9WeSNHZMPudT6VZl+SIPSnUN PFJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=QKMFT5JI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y20si310352edd.608.2022.01.26.14.22.50; Wed, 26 Jan 2022 14:23:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=QKMFT5JI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243831AbiAZRi4 (ORCPT + 99 others); Wed, 26 Jan 2022 12:38:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47210 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243822AbiAZRit (ORCPT ); Wed, 26 Jan 2022 12:38:49 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1DAF9C06161C; Wed, 26 Jan 2022 09:38:46 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 60134B81CAE; Wed, 26 Jan 2022 17:38:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 88173C340E3; Wed, 26 Jan 2022 17:38:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1643218723; bh=EFdscSLnaWLhYVWNI1QN+bbNVEh+ATXkGkbBTAYxJVU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=QKMFT5JIOjKA4WSdOxxZoprP9S5gopg2K0wTG2r2HrnH2fsvbccXZe4hjNxu0SYAp jIB1k3adqafrenS5Z1NabRPOFMZusn6sg3UQK4nhtpDtH9jBVmxDLsEHSdiptXmV62 li8OruZAgJdla3Dhv4Lzvp0EG3z9qgP1lx2cyEINGkFpaIXjW1la+H3FojZRBG5Xtk vcE4nEGqnx9HFaG2qUCjcDKWDIKa+Wiu6k28OK8BKoFR4VhE4X5AF2jxxaXNOBsV0N JSmpjuPNfitBM3tsSB/2PNgtRaqaryeZi+ma42g9YcyiBkLZiLp7N6TfD9qVdkJJhO +2H1WnvFufsbw== Date: Thu, 27 Jan 2022 01:31:05 +0800 From: Jisheng Zhang To: Samuel Holland , Joakim Zhang Cc: Giuseppe Cavallaro , Alexandre Torgue , Jose Abreu , "David S . Miller" , Jakub Kicinski , Maxime Ripard , Chen-Yu Tsai , Jernej Skrabec , Maxime Coquelin , netdev@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-stm32@st-md-mailman.stormreply.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH] net: stmmac: dwmac-sun8i: fix double disable and unprepare "stmmaceth" clk Message-ID: References: <20220123132805.758-1-jszhang@kernel.org> <38c41c04-abde-4d55-ed7c-515b6bba9c54@sholland.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jan 27, 2022 at 12:00:42AM +0800, Jisheng Zhang wrote: > On Wed, Jan 26, 2022 at 11:12:28PM +0800, Jisheng Zhang wrote: > > On Sun, Jan 23, 2022 at 01:43:37PM -0600, Samuel Holland wrote: > > > On 1/23/22 7:28 AM, Jisheng Zhang wrote: > > > > Fix warnings on Allwinner D1 platform: > > > > > > > > [ 1.604695] ------------[ cut here ]------------ > > > > [ 1.609328] bus-emac already disabled > > > > [ 1.613015] WARNING: CPU: 0 PID: 38 at drivers/clk/clk.c:952 clk_core_disable+0xcc/0xec > > > > [ 1.621039] CPU: 0 PID: 38 Comm: kworker/u2:1 Not tainted 5.14.0-rc4#1 > > > > [ 1.627653] Hardware name: Allwinner D1 NeZha (DT) > > > > [ 1.632443] Workqueue: events_unbound deferred_probe_work_func > > > > [ 1.638286] epc : clk_core_disable+0xcc/0xec > > > > [ 1.642561] ra : clk_core_disable+0xcc/0xec > > > > [ 1.646835] epc : ffffffff8023c2ec ra : ffffffff8023c2ec sp : ffffffd00411bb10 > > > > [ 1.654054] gp : ffffffff80ec9988 tp : ffffffe00143a800 t0 : ffffffff80ed6a6f > > > > [ 1.661272] t1 : ffffffff80ed6a60 t2 : 0000000000000000 s0 : ffffffe001509e00 > > > > [ 1.668489] s1 : 0000000000000001 a0 : 0000000000000019 a1 : ffffffff80e80bd8 > > > > [ 1.675707] a2 : 00000000ffffefff a3 : 00000000000000f4 a4 : 0000000000000002 > > > > [ 1.682924] a5 : 0000000000000001 a6 : 0000000000000030 a7 : 00000000028f5c29 > > > > [ 1.690141] s2 : 0000000000000800 s3 : ffffffe001375000 s4 : ffffffe01fdf7a80 > > > > [ 1.697358] s5 : ffffffe001375010 s6 : ffffffff8001fc10 s7 : ffffffffffffffff > > > > [ 1.704577] s8 : 0000000000000001 s9 : ffffffff80ecb248 s10: ffffffe001b80000 > > > > [ 1.711794] s11: ffffffe001b80760 t3 : 0000000000000062 t4 : ffffffffffffffff > > > > [ 1.719012] t5 : ffffffff80e0f6d8 t6 : ffffffd00411b8f0 > > > > [ 1.724321] status: 8000000201800100 badaddr: 0000000000000000 cause: 0000000000000003 > > > > [ 1.732233] [] clk_core_disable+0xcc/0xec > > > > [ 1.737810] [] clk_disable+0x38/0x78 > > > > [ 1.742956] [] worker_thread+0x1a8/0x4d8 > > > > [ 1.748451] [] stmmac_remove_config_dt+0x1c/0x4c > > > > [ 1.754646] [] sun8i_dwmac_probe+0x378/0x82c > > > > [ 1.760484] [] worker_thread+0x1a8/0x4d8 > > > > [ 1.765975] [] platform_probe+0x64/0xf0 > > > > [ 1.771382] [] really_probe.part.0+0x8c/0x30c > > > > [ 1.777305] [] __driver_probe_device+0xa0/0x148 > > > > [ 1.783402] [] driver_probe_device+0x38/0x138 > > > > [ 1.789324] [] __device_attach_driver+0xd0/0x170 > > > > [ 1.795508] [] __driver_attach_async_helper+0xbc/0xc0 > > > > [ 1.802125] [] bus_for_each_drv+0x68/0xb4 > > > > [ 1.807701] [] __device_attach+0xd8/0x184 > > > > [ 1.813277] [] bus_probe_device+0x98/0xbc > > > > [ 1.818852] [] deferred_probe_work_func+0x90/0xd4 > > > > [ 1.825122] [] process_one_work+0x1e4/0x390 > > > > [ 1.830872] [] worker_thread+0x31c/0x4d8 > > > > [ 1.836362] [] kthreadd+0x94/0x188 > > > > [ 1.841335] [] kthreadd+0x94/0x188 > > > > [ 1.846304] [] process_one_work+0x38c/0x390 > > > > [ 1.852054] [] kthread+0x124/0x160 > > > > [ 1.857021] [] set_kthread_struct+0x5c/0x60 > > > > [ 1.862770] [] ret_from_syscall_rejected+0x8/0xc > > > > [ 1.868956] ---[ end trace 8d5c6046255f84a0 ]--- > > > > [ 1.873675] ------------[ cut here ]------------ > > > > [ 1.878366] bus-emac already unprepared > > > > [ 1.882378] WARNING: CPU: 0 PID: 38 at drivers/clk/clk.c:810 clk_core_unprepare+0xe4/0x168 > > > > [ 1.890673] CPU: 0 PID: 38 Comm: kworker/u2:1 Tainted: G W 5.14.0-rc4 #1 > > > > [ 1.898674] Hardware name: Allwinner D1 NeZha (DT) > > > > [ 1.903464] Workqueue: events_unbound deferred_probe_work_func > > > > [ 1.909305] epc : clk_core_unprepare+0xe4/0x168 > > > > [ 1.913840] ra : clk_core_unprepare+0xe4/0x168 > > > > [ 1.918375] epc : ffffffff8023d6cc ra : ffffffff8023d6cc sp : ffffffd00411bb10 > > > > [ 1.925593] gp : ffffffff80ec9988 tp : ffffffe00143a800 t0 : 0000000000000002 > > > > [ 1.932811] t1 : ffffffe01f743be0 t2 : 0000000000000040 s0 : ffffffe001509e00 > > > > [ 1.940029] s1 : 0000000000000001 a0 : 000000000000001b a1 : ffffffe00143a800 > > > > [ 1.947246] a2 : 0000000000000000 a3 : 00000000000000f4 a4 : 0000000000000001 > > > > [ 1.954463] a5 : 0000000000000000 a6 : 0000000005fce2a5 a7 : 0000000000000001 > > > > [ 1.961680] s2 : 0000000000000800 s3 : ffffffff80afeb90 s4 : ffffffe01fdf7a80 > > > > [ 1.968898] s5 : ffffffe001375010 s6 : ffffffff8001fc10 s7 : ffffffffffffffff > > > > [ 1.976115] s8 : 0000000000000001 s9 : ffffffff80ecb248 s10: ffffffe001b80000 > > > > [ 1.983333] s11: ffffffe001b80760 t3 : ffffffff80b39120 t4 : 0000000000000001 > > > > [ 1.990550] t5 : 0000000000000000 t6 : ffffffe001600002 > > > > [ 1.995859] status: 8000000201800120 badaddr: 0000000000000000 cause: 0000000000000003 > > > > [ 2.003771] [] clk_core_unprepare+0xe4/0x168 > > > > [ 2.009609] [] clk_unprepare+0x24/0x3c > > > > [ 2.014929] [] stmmac_remove_config_dt+0x24/0x4c > > > > [ 2.021125] [] sun8i_dwmac_probe+0x378/0x82c > > > > [ 2.026965] [] worker_thread+0x1a8/0x4d8 > > > > [ 2.032463] [] platform_probe+0x64/0xf0 > > > > [ 2.037871] [] really_probe.part.0+0x8c/0x30c > > > > [ 2.043795] [] __driver_probe_device+0xa0/0x148 > > > > [ 2.049892] [] driver_probe_device+0x38/0x138 > > > > [ 2.055815] [] __device_attach_driver+0xd0/0x170 > > > > [ 2.061999] [] __driver_attach_async_helper+0xbc/0xc0 > > > > [ 2.068616] [] bus_for_each_drv+0x68/0xb4 > > > > [ 2.074193] [] __device_attach+0xd8/0x184 > > > > [ 2.079769] [] bus_probe_device+0x98/0xbc > > > > [ 2.085345] [] deferred_probe_work_func+0x90/0xd4 > > > > [ 2.091616] [] process_one_work+0x1e4/0x390 > > > > [ 2.097367] [] worker_thread+0x31c/0x4d8 > > > > [ 2.102858] [] kthreadd+0x94/0x188 > > > > [ 2.107830] [] kthreadd+0x94/0x188 > > > > [ 2.112800] [] process_one_work+0x38c/0x390 > > > > [ 2.118551] [] kthread+0x124/0x160 > > > > [ 2.123520] [] set_kthread_struct+0x5c/0x60 > > > > [ 2.129268] [] ret_from_syscall_rejected+0x8/0xc > > > > [ 2.135455] ---[ end trace 8d5c6046255f84a1 ]--- > > > > > > > > the dwmmac-sun8i driver will get the "stmmaceth" clk as tx_clk during > > > > driver initialization. If stmmac_dvr_probe() fails due to various > > > > reasons, sun8i_dwmac_exit() will disable and unprepare the "stmmaceth" > > > > clk, then stmmac_remove_config_dt() will disable and unprepare the > > > > clk again. > > > > > > This should still be balanced, because both stmmac_probe_config_dt and > > > sun8i_dwmac_init prepare/enable the clock, so the dwmac-sun8i glue layer calls > > > stmmac_dvr_probe with the clock having an enable count of 2. It looks like the > > > underlying issue is that commit 5ec55823438e ("net: stmmac: add clocks > > > management for gmac driver") introduces unbalanced runtime PM. > > > > I added some printk then retested, the problem is triggered as below: > > > > stmmac_probe_config_dt() enable the clk > > sun8i_dwmac_init() enble the clk again > > stmmac_dvr_probe() succeed, but it calls pm_runtime_put(), so rpm will > > disable the clk > > sun8i_dwmac_reset() fails due to various reason > > sun8i_dwmac_exit() disable the clk, this is fine > > stmmac_remove_config_dt() disable the clk again, so ccf complains. > > > > The key here is: whether we should let stmmac_dvr_probe() calls > > pm_runtime_put() or let stmmac users to determine whether we could > > let rpm go? > > If we keep current behavior: stmmac users need to take care > > the code after stmmac_dvr_probe, including error handling code path, > > if we touch access registers, we need to call pm_runtime_get_sync() > > firstly. > > > > Since the commit 5ec55823438e has been in for a long time, I'll submit > > a patch to follow this way. > > > > After reading the code and commit history, I found some users suffering > from the runtimepm issues, for example, dwmac-rk.c, so I changed my > idea. I think it's better to let stmmac users to call pm_runtime_put(): > > First of all, only the users know whether it's safe to finally > keep the mac runtime suspended after probe. > > Secondly, if the users need to do platform specific operations after > stmmac_dvr_probe(), especially needs to access some registers, we have > to resume the mac firstly. The error handling code path also needs to > take care of it. It looks a bit strange resume immediately resume the > mac after suspending it. > > Any suggestion is welcome. > > PS: Since this would partially revert commit 5ec55823438e, I add Joakim > into the email thread. > If we keep current behavior as is, and let stmmac users to take care necessary runtime resume before specific handling, we need similar patch as dwmac-sun8i below for all stmmac users, especially the error handling path: diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c index 09644ab0d87a..ef2acea3d036 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -1254,6 +1255,7 @@ static int sun8i_dwmac_probe(struct platform_device *pdev) ndev = dev_get_drvdata(&pdev->dev); priv = netdev_priv(ndev); + pm_runtime_get_sync(&pdev->dev); /* The mux must be registered after parent MDIO * so after stmmac_dvr_probe() */ @@ -1272,12 +1274,15 @@ static int sun8i_dwmac_probe(struct platform_device *pdev) goto dwmac_remove; } + pm_runtime_put(&pdev->dev); + return 0; dwmac_mux: reset_control_put(gmac->rst_ephy); clk_put(gmac->ephy_clk); dwmac_remove: + pm_runtime_put_noidle(&pdev->dev); stmmac_dvr_remove(&pdev->dev); dwmac_exit: sun8i_dwmac_exit(pdev, gmac); diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index 8ded4be08b00..2f9bd1eacb81 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -7133,6 +7133,10 @@ int stmmac_dvr_remove(struct device *dev) netdev_info(priv->dev, "%s: removing driver", __func__); + pm_runtime_get_sync(dev); + pm_runtime_disable(dev); + pm_runtime_put_noidle(dev); + stmmac_stop_all_dma(priv); stmmac_mac_set(priv, priv->ioaddr, false); netif_carrier_off(ndev); @@ -7151,8 +7155,6 @@ int stmmac_dvr_remove(struct device *dev) if (priv->plat->stmmac_rst) reset_control_assert(priv->plat->stmmac_rst); reset_control_assert(priv->plat->stmmac_ahb_rst); - pm_runtime_put(dev); - pm_runtime_disable(dev); if (priv->hw->pcs != STMMAC_PCS_TBI && priv->hw->pcs != STMMAC_PCS_RTBI) stmmac_mdio_unregister(ndev);