From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1F0ADC433F5 for ; Wed, 27 Apr 2022 14:00:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236997AbiD0ODW (ORCPT ); Wed, 27 Apr 2022 10:03:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47254 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236868AbiD0ODV (ORCPT ); Wed, 27 Apr 2022 10:03:21 -0400 Received: from netrider.rowland.org (netrider.rowland.org [192.131.102.5]) by lindbergh.monkeyblade.net (Postfix) with SMTP id F0F7B48E6F for ; Wed, 27 Apr 2022 07:00:09 -0700 (PDT) Received: (qmail 874063 invoked by uid 1000); 27 Apr 2022 10:00:08 -0400 Date: Wed, 27 Apr 2022 10:00:08 -0400 From: Alan Stern To: Lukas Wunner Cc: Steve Glendinning , UNGLinuxDriver@microchip.com, Oliver Neukum , "David S. Miller" , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org, linux-usb@vger.kernel.org, Andre Edich , Oleksij Rempel , Martyn Welch , Gabriel Hojda , Christoph Fritz , Lino Sanfilippo , Philipp Rosenberger , Heiner Kallweit , Andrew Lunn , Russell King Subject: Re: [PATCH net] usbnet: smsc95xx: Fix deadlock on runtime resume Message-ID: References: <6710d8c18ff54139cdc538763ba544187c5a0cee.1651041411.git.lukas@wunner.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <6710d8c18ff54139cdc538763ba544187c5a0cee.1651041411.git.lukas@wunner.de> Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On Wed, Apr 27, 2022 at 08:41:49AM +0200, Lukas Wunner wrote: > Commit 05b35e7eb9a1 ("smsc95xx: add phylib support") amended > smsc95xx_resume() to call phy_init_hw(). That function waits for the > device to runtime resume even though it is placed in the runtime resume > path, causing a deadlock. > > The problem is that phy_init_hw() calls down to smsc95xx_mdiobus_read(), > which never uses the _nopm variant of usbnet_read_cmd(). Amend it to > autosense that it's called from the runtime resume/suspend path and use > the _nopm variant if so. ... > diff --git a/drivers/net/usb/smsc95xx.c b/drivers/net/usb/smsc95xx.c > index 4ef61f6b85df..82b8feaa5162 100644 > --- a/drivers/net/usb/smsc95xx.c > +++ b/drivers/net/usb/smsc95xx.c > @@ -285,11 +285,21 @@ static void smsc95xx_mdio_write_nopm(struct usbnet *dev, int idx, int regval) > __smsc95xx_mdio_write(dev, pdata->phydev->mdio.addr, idx, regval, 1); > } > > +static bool smsc95xx_in_pm(struct usbnet *dev) > +{ > +#ifdef CONFIG_PM > + return dev->udev->dev.power.runtime_status == RPM_RESUMING || > + dev->udev->dev.power.runtime_status == RPM_SUSPENDING; > +#else > + return false; > +#endif > +} This does not do what you want. You want to know if this function is being called in the resume pathway, but all it really tells you is whether the function is being called while a resume is in progress (and it doesn't even do that very precisely because the code does not use the runtime-pm spinlock). The resume could be running in a different thread, in which case you most definitely _would_ want to want for it to complete. Alan Stern