public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Florian Fainelli <f.fainelli@gmail.com>
To: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Marek Szyprowski <m.szyprowski@samsung.com>,
	netdev <netdev@vger.kernel.org>,
	Steve Glendinning <steve.glendinning@shawell.net>,
	Doug Berger <opendmb@gmail.com>, Andrew Lunn <andrew@lunn.ch>,
	Heiner Kallweit <hkallweit1@gmail.com>,
	Russell King <linux@armlinux.org.uk>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	open list <linux-kernel@vger.kernel.org>,
	Linux-Renesas <linux-renesas-soc@vger.kernel.org>,
	Sergey Shtylyov <s.shtylyov@omp.ru>
Subject: Re: [PATCH net] net: phy: Warn about incorrect mdio_bus_phy_resume() state
Date: Tue, 16 Aug 2022 19:28:28 -0700	[thread overview]
Message-ID: <c1301f39-9202-5eee-a0f6-9c0b66f2dccf@gmail.com> (raw)
In-Reply-To: <CAMuHMdV8vsbFx+nikAwn1po1-PeZVhzotMaLLk+wXNquZceaRQ@mail.gmail.com>



On 8/16/2022 6:20 AM, Geert Uytterhoeven wrote:
> Hi Florian,
> 
> On Fri, Aug 12, 2022 at 6:39 PM Florian Fainelli <f.fainelli@gmail.com> 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 <f.fainelli@gmail.com>
>>>
>>> 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()?
-- 
Florian

  reply	other threads:[~2022-08-17  2:28 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20220812111948eucas1p2bf97e7f4558eb024f419346367a87b45@eucas1p2.samsung.com>
2022-08-01 23:34 ` [PATCH net] net: phy: Warn about incorrect mdio_bus_phy_resume() state Florian Fainelli
2022-08-04  2:40   ` patchwork-bot+netdevbpf
2022-08-12 11:19   ` Marek Szyprowski
2022-08-12 16:32     ` Florian Fainelli
2022-08-16 11:18       ` Marek Szyprowski
2022-08-16 13:20       ` Geert Uytterhoeven
2022-08-17  2:28         ` Florian Fainelli [this message]
2022-08-17  9:18           ` Geert Uytterhoeven
2022-08-17 11:32             ` Marek Szyprowski
2022-09-19 14:51         ` Geert Uytterhoeven
2022-09-22 12:31   ` Jakub Kicinski
2022-09-22 15:29     ` Florian Fainelli

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c1301f39-9202-5eee-a0f6-9c0b66f2dccf@gmail.com \
    --to=f.fainelli@gmail.com \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=geert@linux-m68k.org \
    --cc=hkallweit1@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=m.szyprowski@samsung.com \
    --cc=netdev@vger.kernel.org \
    --cc=opendmb@gmail.com \
    --cc=pabeni@redhat.com \
    --cc=s.shtylyov@omp.ru \
    --cc=steve.glendinning@shawell.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox