Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp741230img; Wed, 20 Mar 2019 09:53:41 -0700 (PDT) X-Google-Smtp-Source: APXvYqwbSmoy7oGlUxlNr2LmfEzTKPVgwLCZYVsI9Jaad9UxxS+tN0MCNR8EDXUuug6A3J0dDd04 X-Received: by 2002:a65:50c8:: with SMTP id s8mr8265486pgp.308.1553100821353; Wed, 20 Mar 2019 09:53:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553100821; cv=none; d=google.com; s=arc-20160816; b=nC1muBXqDewSM2Ggy/UhLh9nxRurBZbkHOjNzZwxIuE6lgH6vyZXY/hojxECMI17Rp I96JA4Xm+1mmi3dGTLPtdGq4B6Z3YAewYhYhnxxBh80AtYhOLnVf0XFrqfLeM9UOTj77 oAIrkEgoxiypWna/+bne4EE3SbxO17Vz3byo/jX/e+EK7zITY/MRUJkH/oVoNnE1e0Bm q+ZwMbMJCXeElc/vznxTew3Gie+IwFDyWXE7t3ufB7E9t6ES8FDbxv0DsCSd2lEo5xbf Ka3JMdsVy44Ti/PCXT0OCmkQU4uXQ8XH++PLRexboPwJTaF9FShk1WdnCEjbRGtpgIN6 Pshg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:in-reply-to :subject:cc:to:from:date; bh=cDFSrxqq4U0oAxGGUeDef7hqW+RJok6Ne03rxltXPec=; b=iVKJghGeBFrkvTdKm9pZ0k6lAE44IVuUvuMcEiTjLR43bWp8IXwT+vLiiXEwsWAzOu WhcUWs4/aSr1WXGvh7rdN41Yd/K3X1asN5fQ/ueOPuEgFrh3OqPOhEZNmwAGf62k5FmD nBllMCjwzn/rTwjxVXCwKwaIeLUUuq7mkWZhNpLDtqjnqqDSLRRBMwHAZib9+bOJ1ftf tX3l8z5Azyw1Jw/oguMddqbqB+gb/gvOVPbaA60lgTHmDsA6oZ8gwb4NvVVnvQXEaZdT pYco9XsNDOyHlhBibrnjtucso7BXLsHdCCCm4TxsE7AtBrUqxKa0DCNHkU0uJ6giE+5h WbLQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 97si2198375plb.407.2019.03.20.09.53.25; Wed, 20 Mar 2019 09:53:41 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726987AbfCTQwr (ORCPT + 99 others); Wed, 20 Mar 2019 12:52:47 -0400 Received: from iolanthe.rowland.org ([192.131.102.54]:33170 "HELO iolanthe.rowland.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1726123AbfCTQwr (ORCPT ); Wed, 20 Mar 2019 12:52:47 -0400 Received: (qmail 4602 invoked by uid 2102); 20 Mar 2019 12:52:46 -0400 Received: from localhost (sendmail-bs@127.0.0.1) by localhost with SMTP; 20 Mar 2019 12:52:46 -0400 Date: Wed, 20 Mar 2019 12:52:46 -0400 (EDT) From: Alan Stern X-X-Sender: stern@iolanthe.rowland.org To: John Stultz cc: fei.yang@intel.com, Felipe Balbi , Greg KH , , Vincent Pelletier , Linux USB List , lkml , Josh Gao , Alistair Strachan , Shen Jing Subject: Re: [PATCH V2] usb: gadget: f_fs: don't free buffer prematurely In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 20 Mar 2019, John Stultz wrote: > Hey Fei, > So while this patch does resolve the issues I was seeing with > mainline kernels and recent changes to adbd, Josh pointed out that it > wouldn't resolve the issues I was seeing with older kernels which is > slightly different (but still related to aio usage). > > On the older kernels I'm hitting scheduling while atomic on reboot, > which seems to be due to ffs_aio_cancel() taking a spinlock then > calling usb_ep_dequeue() which might sleep. > > It seems a fix for this was tried earlier with d52e4d0c0c428 ("usb: > gadget: ffs: Fix BUG when userland exits with submitted AIO > transfers") which was then reverted by a9c859033f6e. > > Elsewhere it seems the ffs driver takes effort to drop any locks > before calling usb_ep_dequeue(), so this seems like that should be > addressed, but it also seems like recent change to the dwc3 driver has > been made to avoid sleeping in that path (see fec9095bdef4 ("usb: > dwc3: gadget: remove wait_end_transfer")), which may be why I'm not > seeing the problem with mainline (and your patch here, of coarse). > But that also doesn't clarify if its still a potential issue w/ > non-dwc3 platforms. > > So for older kernels, do you have a suggestion of which approach is > advised? Does usb_ep_dequeue need to avoid sleeping or do we need to > rework the ffs_aio_cancel logic? usb_ep_dequeue can be called in interrupt context, meaning it is never allowed to sleep. This is mentioned in the kerneldoc: /** * usb_ep_dequeue - dequeues (cancels, unlinks) an I/O request from an endpoint * @ep:the endpoint associated with the request * @req:the request being canceled * * If the request is still active on the endpoint, it is dequeued and * eventually its completion routine is called (with status -ECONNRESET); * else a negative error code is returned. This routine is asynchronous, * that is, it may return before the completion routine runs. * * Note that some hardware can't clear out write fifos (to unlink the request * at the head of the queue) except as part of disconnecting from usb. Such * restrictions prevent drivers from supporting configuration changes, * even to configuration zero (a "chapter 9" requirement). * * This routine may be called in interrupt context. */ Alan Stern