Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp4594381rwb; Wed, 17 Aug 2022 02:49:43 -0700 (PDT) X-Google-Smtp-Source: AA6agR52NVt7guRzDv2XmhH1rbNxYrnht6c4zGlr6B0kXEq03eXv3WKAo34HzdPSflrN+SMMQNXK X-Received: by 2002:a17:902:9b85:b0:16e:cc02:b9b2 with SMTP id y5-20020a1709029b8500b0016ecc02b9b2mr25807102plp.74.1660729783409; Wed, 17 Aug 2022 02:49:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660729783; cv=none; d=google.com; s=arc-20160816; b=RaSL9/X8WabTpeLCCgYTnJM6ZAolb66mbllblkA00Id5SdPBVDwUg5pPFL3/YMDsoC I8gwT1G86KnYHAj6W1LIxXXfgRgEdFNjVSPZZ7dqocnMdUGHhITrbHZagosrsPfTW/Cf KU3DiUEC7gEZKw4o3OUDKVh1BxUqFe+Te33PklbkkDcqyiQubIYFeUZWmodKp56nXB2p kotGvibunKVYyCY52PEcI/OOUkfDdivx7CAlrwKnY0kh3u1zPTHVZjGez2MhKks0KLVa pGw8m7SkS2gXyN8GDvEDaOQQOEWcIQnZ7LtBjx+Ond5KbrmKkgO3Bh6hSyhtjIEObIad D+5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version; bh=5jBoVbzGQCtyTY7INNBLuSnir7aONmr2lpezFOUi2gc=; b=VUAowAzEUDIAzyT9kQLGURSpdDArKYkD3txtukehNzgjc2VCriymDkPV0fU9fMuKDU bOpa+YnI/xvOMPONkHVpoGQlCBDG09xxsZZLUKGowXXYyS3TNiwFVs9rgNyR8TYAMgzD u7mlNnvhJxIFidyonPqliFGDuNeyPUtZ7+1TS0INjxrhqOUoeepQ2krQSuymSwlE7wtM g5LHJ3Yj+qJ8KC53eRf1VSiGv6L/NPqOgWTTsR3Tigg8OMtYETXSaNM+96c90XDqvrQJ tGbggW5gFzyIRKr22nVp2ZAgSaQgh9AF1wbn9x4Q7+1sOJJXaJFdyubKRV5hbyr0P0ac lOQA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o9-20020a17090a678900b001f545bd9696si1275334pjj.106.2022.08.17.02.49.32; Wed, 17 Aug 2022 02:49:43 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231858AbiHQJSS (ORCPT + 99 others); Wed, 17 Aug 2022 05:18:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44422 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229627AbiHQJSQ (ORCPT ); Wed, 17 Aug 2022 05:18:16 -0400 Received: from mail-qk1-f177.google.com (mail-qk1-f177.google.com [209.85.222.177]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 755A79FD6; Wed, 17 Aug 2022 02:18:15 -0700 (PDT) Received: by mail-qk1-f177.google.com with SMTP id f4so7938959qkl.7; Wed, 17 Aug 2022 02:18:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc; bh=5jBoVbzGQCtyTY7INNBLuSnir7aONmr2lpezFOUi2gc=; b=lLSrBv8hiFKI883hC067WvGXRYdsRz0QVMSuz6IaK3BRJoMX3mz5kO+XyLY45EqUCu VaL1+WMLuordp2GbfygQ+NxnSc3etUO7uCEzxrrsynfz7YIaAy3nw9Cb1VWCHGekJCZz ue/DpCO21zOqAbXQNLzeV0hMO6YIYLJzfvi+4ik/bRW+O6waygROAKO/aeXJqd4u+C3B wAM2vQqvEhdVWzvKPHVDXe/4DczcXmUaUPlwxNtq8qtth2cAN1rVc4NlgYNsFuvqUjLG o572gIJuos2KLiu2RAI99dhH2HABnK2BPg51TspFs7rL1HNaeRE6zdv1UHQiDWqC6xNN hjDg== X-Gm-Message-State: ACgBeo0EnGGbkVIfzplgd25rV2gSLSWd8g9AfvaUkEfWIEjUZ+I3MLxN hOFVw2AcaHr/XOdTjsupRrv1w4pRRIV/eg== X-Received: by 2002:a05:620a:2181:b0:6bb:50a1:222e with SMTP id g1-20020a05620a218100b006bb50a1222emr7436719qka.151.1660727894435; Wed, 17 Aug 2022 02:18:14 -0700 (PDT) Received: from mail-yw1-f171.google.com (mail-yw1-f171.google.com. [209.85.128.171]) by smtp.gmail.com with ESMTPSA id do7-20020a05620a2b0700b006a6ebde4799sm14162434qkb.90.2022.08.17.02.18.12 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 17 Aug 2022 02:18:13 -0700 (PDT) Received: by mail-yw1-f171.google.com with SMTP id 00721157ae682-33387bf0c4aso110701447b3.11; Wed, 17 Aug 2022 02:18:12 -0700 (PDT) X-Received: by 2002:a5b:bcd:0:b0:68f:b4c0:7eca with SMTP id c13-20020a5b0bcd000000b0068fb4c07ecamr3297004ybr.202.1660727892477; Wed, 17 Aug 2022 02:18:12 -0700 (PDT) MIME-Version: 1.0 References: <20220801233403.258871-1-f.fainelli@gmail.com> <27016cc0-f228-748b-ea03-800dda4e5f0c@samsung.com> <8c21e530-8e8f-ce2a-239e-9d3a354996cf@gmail.com> In-Reply-To: From: Geert Uytterhoeven Date: Wed, 17 Aug 2022 11:18:00 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH net] net: phy: Warn about incorrect mdio_bus_phy_resume() state To: Florian Fainelli Cc: Marek Szyprowski , netdev , Steve Glendinning , Doug Berger , Andrew Lunn , Heiner Kallweit , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , open list , Linux-Renesas , Sergey Shtylyov Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no 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 Hi Florian, On Wed, Aug 17, 2022 at 4:28 AM Florian Fainelli wrote: > On 8/16/2022 6:20 AM, Geert Uytterhoeven wrote: > > On Fri, Aug 12, 2022 at 6:39 PM Florian Fainelli wrote: > >> On 8/12/22 04:19, Marek Szyprowski wrote: > >>> On 02.08.2022 01:34, Florian Fainelli wrote: > >>>> Calling mdio_bus_phy_resume() with neither the PHY state machine set to > >>>> PHY_HALTED nor phydev->mac_managed_pm set to true is a good indication > >>>> that we can produce a race condition looking like this: > >>>> > >>>> CPU0 CPU1 > >>>> bcmgenet_resume > >>>> -> phy_resume > >>>> -> phy_init_hw > >>>> -> phy_start > >>>> -> phy_resume > >>>> phy_start_aneg() > >>>> mdio_bus_phy_resume > >>>> -> phy_resume > >>>> -> phy_write(..., BMCR_RESET) > >>>> -> usleep() -> phy_read() > >>>> > >>>> with the phy_resume() function triggering a PHY behavior that might have > >>>> to be worked around with (see bf8bfc4336f7 ("net: phy: broadcom: Fix > >>>> brcm_fet_config_init()") for instance) that ultimately leads to an error > >>>> reading from the PHY. > >>>> > >>>> Fixes: fba863b81604 ("net: phy: make PHY PM ops a no-op if MAC driver manages PHY PM") > >>>> Signed-off-by: Florian Fainelli > >>> > >>> This patch, as probably intended, triggers a warning during system > >>> suspend/resume cycle in the SMSC911x driver. I've observed it on ARM > >>> Juno R1 board on the kernel compiled from next-202208010: > >>> > >>> ------------[ cut here ]------------ > >>> WARNING: CPU: 1 PID: 398 at drivers/net/phy/phy_device.c:323 > >>> mdio_bus_phy_resume+0x34/0xc8 > > > > I am seeing the same on the ape6evm and kzm9g development > > boards with smsc911x Ethernet, and on various boards with Renesas > > Ethernet (sh_eth or ravb) if Wake-on-LAN is disabled. > > > >> Yes this is catching an actual issue in the driver in that the PHY state > >> machine is still running while the system is trying to suspend. We could > >> go about fixing it in a different number of ways, though I believe this > >> one is probably correct enough to work and fix the warning: > > > >> --- a/drivers/net/ethernet/smsc/smsc911x.c > >> +++ b/drivers/net/ethernet/smsc/smsc911x.c > >> @@ -1037,6 +1037,8 @@ static int smsc911x_mii_probe(struct net_device *dev) > >> return ret; > >> } > >> > >> + /* Indicate that the MAC is responsible for managing PHY PM */ > >> + phydev->mac_managed_pm = true; > >> phy_attached_info(phydev); > >> > >> phy_set_max_speed(phydev, SPEED_100); > >> @@ -2587,6 +2589,8 @@ static int smsc911x_suspend(struct device *dev) > >> if (netif_running(ndev)) { > >> netif_stop_queue(ndev); > >> netif_device_detach(ndev); > >> + if (!device_may_wakeup(dev)) > >> + phy_suspend(dev->phydev); > >> } > >> > >> /* enable wake on LAN, energy detection and the external PME > >> @@ -2628,6 +2632,8 @@ static int smsc911x_resume(struct device *dev) > >> if (netif_running(ndev)) { > >> netif_device_attach(ndev); > >> netif_start_queue(ndev); > >> + if (!device_may_wakeup(dev)) > >> + phy_resume(dev->phydev); > >> } > >> > >> return 0; > > > > Thanks for your patch, but unfortunately this does not work on ape6evm > > and kzm9g, where the smsc911x device is connected to a power-managed > > bus. It looks like the PHY registers are accessed while the device > > is already suspended, causing a crash during system suspend: > > Does it work better if you replace phy_suspend() with phy_stop() and > phy_resume() with phy_start()? Thank you, much better! Tested-by: Geert Uytterhoeven Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds