Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1605133

Re: [PATCH v2] usb: hub: Do not attempt to autosuspend disconnected devices

Path csiph.com!news.mixmin.net!news.unit0.net!news.panservice.it!diesel.cu.mi.it!bofh.it!news.nic.it!robomod
From Guenter Roeck <linux@roeck-us.net>
Newsgroups linux.kernel
Subject Re: [PATCH v2] usb: hub: Do not attempt to autosuspend disconnected devices
Date Mon, 20 Mar 2017 22:20:02 +0100
Message-ID <tncSC-22N-17@gated-at.bofh.it> (permalink)
References <tn8YH-7Pz-45@gated-at.bofh.it> <tncSC-22N-19@gated-at.bofh.it>
X-Original-To Alan Stern <stern@rowland.harvard.edu>
Dkim-Signature v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=roeck-us.net; s=default; h=In-Reply-To:Content-Type:MIME-Version:References :Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To:Content-Transfer-Encoding :Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=l5Pyw/oih2PltdPFxNZw3vSiAeBE1qx59IBgnyh5VTs=; b=1unUCc23Ue8mhnxAcXYSN34ahE vPkq/IyIWObFQ3K8aO9nolJY3t5B2lmlBrjInPHw30AhYha8fFEfwFgb8NFalCMI8Qx/M4qwMOWdX aX+F2HsGmDVxO0zMZSRSPS1WUFo/hqE2FnLmNnaOL6u6NxRWbe0AU/39yBXaBoBwd0K75BFPYlzw+ 95P8MFOC3yn/NIYRS6nzjHEPSoKlUalYkNJluv5sgaQZ4QhmXb9QHqZAkFUC8llHwMYIcR45GpmE3 ZhVXAe0inetyqxiT9BClr+wYZxUhK7Zo9brnTrJdEpnIC/l+djT8FW0WWfcg58Wdi66pTtemYtKDX QdvmT+7A==;
MIME-Version 1.0
Content-Type text/plain; charset=us-ascii
Content-Disposition inline
User-Agent Mutt/1.5.24 (2015-08-30)
X-Authenticated_Sender guenter@roeck-us.net
X-Outgoing-Spam-Status No, score=-1.0
X-Antiabuse This header was added to track abuse, please include it with any abuse report
X-Antiabuse Primary Hostname - bh-25.webhostbox.net
X-Antiabuse Original Domain - vger.kernel.org
X-Antiabuse Originator/Caller UID/GID - [47 12] / [47 12]
X-Antiabuse Sender Address Domain - roeck-us.net
X-Get-Message-Sender-Via bh-25.webhostbox.net: authenticated_id: guenter@roeck-us.net
X-Authenticated-Sender bh-25.webhostbox.net: guenter@roeck-us.net
Sender robomod@news.nic.it
List-ID <linux-kernel.vger.kernel.org>
X-Mailing-List linux-kernel@vger.kernel.org
Approved robomod@news.nic.it
Lines 82
Organization linux.* mail to news gateway
X-Original-Cc Greg Kroah-Hartman <gregkh@linuxfoundation.org>, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Douglas Anderson <dianders@chromium.org>, Brian Norris <briannorris@chromium.org>
X-Original-Date Mon, 20 Mar 2017 14:16:56 -0700
X-Original-Message-ID <20170320211656.GA1308@roeck-us.net>
X-Original-References <1490025036-6578-1-git-send-email-linux@roeck-us.net> <Pine.LNX.4.44L0.1703201710030.2274-100000@netrider.rowland.org>
X-Original-Sender linux-kernel-owner@vger.kernel.org
Xref csiph.com linux.kernel:1605133

Show key headers only | View raw


On Mon, Mar 20, 2017 at 05:12:20PM -0400, Alan Stern wrote:
> On Mon, 20 Mar 2017, Guenter Roeck wrote:
> 
> > While running a bind/unbind stress test with the dwc3 usb driver on rk3399,
> > the following crash was observed.
> > 
> > Unable to handle kernel NULL pointer dereference at virtual address 00000218
> > pgd = ffffffc00165f000
> > [00000218] *pgd=000000000174f003, *pud=000000000174f003,
> > 				*pmd=0000000001750003, *pte=00e8000001751713
> 
> ...
> 
> > Code analysis shows that intf is set to NULL in usb_disable_device() prior
> > to setting actconfig to NULL. At the same time, usb_runtime_idle() does not
> > lock the usb device, and neither does any of the functions in the
> > traceback. This means that there is no protection against a race condition
> > where usb_disable_device() is removing dev->actconfig->interface[] pointers
> > while those are being accessed from autosuspend_check().
> > 
> > To solve the problem, synchronize and validate device state between
> > autosuspend_check() and usb_disconnect().
> > 
> > Signed-off-by: Guenter Roeck <linux@roeck-us.net>
> > ---
> > v2: Do not disable autosuspend in usb_disconnect(). Instead, check the
> >     usb device state in autosuspend_check().
> >     In usb_disconnect(), call pm_runtime_barrier() earlier, immediately
> >     after changing the USB device state.
> > 
> >  drivers/usb/core/driver.c | 3 +++
> >  drivers/usb/core/hub.c    | 7 +++++++
> >  2 files changed, 10 insertions(+)
> > 
> > diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c
> > index 7ebdf2a4e8fe..eb87a259d55c 100644
> > --- a/drivers/usb/core/driver.c
> > +++ b/drivers/usb/core/driver.c
> > @@ -1781,6 +1781,9 @@ static int autosuspend_check(struct usb_device *udev)
> >  	int			w, i;
> >  	struct usb_interface	*intf;
> >  
> > +	if (udev->state == USB_STATE_NOTATTACHED)
> > +		return -ENODEV;
> > +
> >  	/* Fail if autosuspend is disabled, or any interfaces are in use, or
> >  	 * any interface drivers require remote wakeup but it isn't available.
> >  	 */
> > diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
> > index 57bb427c8878..fd80513aaeff 100644
> > --- a/drivers/usb/core/hub.c
> > +++ b/drivers/usb/core/hub.c
> > @@ -2084,6 +2084,13 @@ void usb_disconnect(struct usb_device **pdev)
> >  	 * this quiesces everything except pending urbs.
> >  	 */
> >  	usb_set_device_state(udev, USB_STATE_NOTATTACHED);
> > +
> > +	/*
> > +	 * Ensure that the pm runtime code knows that the USB device
> > +	 * is in the process of being disconnected.
> > +	 */
> > +	pm_runtime_barrier(&udev->dev);
> > +
> >  	dev_info(&udev->dev, "USB disconnect, device number %d\n",
> >  			udev->devnum);
> >  
> 
> Very minor nit: I would place the pm_runtime_barrier() after the 
> dev_info(), so that we would know the device is going away if anything 
> should go wrong during the barrier call.
> 
Makes sense. I'll change that and resend.

Thanks,
Guenter

> Aside from that,
> 
> Acked-by: Alan Stern <stern@rowland.harvard.edu>
> 
> Alan Stern
> 

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH v2] usb: hub: Do not attempt to autosuspend disconnected devices Guenter Roeck <linux@roeck-us.net> - 2017-03-20 18:10 +0100
  Re: [PATCH v2] usb: hub: Do not attempt to autosuspend disconnected  devices Guenter Roeck <linux@roeck-us.net> - 2017-03-20 22:20 +0100
  Re: [PATCH v2] usb: hub: Do not attempt to autosuspend disconnected  devices Alan Stern <stern@rowland.harvard.edu> - 2017-03-20 22:20 +0100

csiph-web