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 X-Spam-Level: X-Spam-Status: No, score=-5.2 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 53061C433ED for ; Wed, 12 May 2021 21:26:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1DACC613B5 for ; Wed, 12 May 2021 21:26:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346632AbhELV1t (ORCPT ); Wed, 12 May 2021 17:27:49 -0400 Received: from netrider.rowland.org ([192.131.102.5]:52223 "HELO netrider.rowland.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1381449AbhELTeY (ORCPT ); Wed, 12 May 2021 15:34:24 -0400 Received: (qmail 944437 invoked by uid 1000); 12 May 2021 15:33:13 -0400 Date: Wed, 12 May 2021 15:33:13 -0400 From: Alan Stern To: Peter Chen Cc: Felipe Balbi , USB mailing list Subject: Re: Disconnect race in Gadget core Message-ID: <20210512193313.GA943744@rowland.harvard.edu> References: <20210510152426.GE863718@rowland.harvard.edu> <87zgx2fskr.fsf@kernel.org> <20210510193849.GB873147@rowland.harvard.edu> <20210511025322.GA23868@nchen> <20210511191538.GC908414@rowland.harvard.edu> <20210512093748.GA17479@nchen> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210512093748.GA17479@nchen> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org On Wed, May 12, 2021 at 05:37:48PM +0800, Peter Chen wrote: > On 21-05-11 15:15:38, Alan Stern wrote: > > I suppose we could do something similar for the composite driver, for > > gadgets that don't use configfs. > > Originally, I intended to do at composite.c to cover all gadget drivers, but > I can't find a good way to use usb_composite_dev existing spinlock to do that. It isn't necessary to use a spinlock. RCU should work. > Since most of users already used configfs, I chose to fix it at configfs directly. > If we want to fix it for legacy gadget drivers (drivers at drivers/usb/gadget/legacy/). > > For .setup & .suspend, we could delay 10ms after usb_gadget_disconnect, ensure > hardware has triggered related interrupt, and we need to let all UDC drivers to > add udc->gadget->irq, in that case, the pending threaded interrupt will be handled > at synchronize_irq at usb_gadget_remove_driver. > For .disconnect, we could use cdev->config to judge if the first .disconnect > has run. I'm not very worried about setup. There should never be any setup events when the pull-up is off. Disconnect, reset, and suspend are the main problems. > > But what about legacy gadgets? Are > > there any still around that don't use either configfs or the composite > > framework? > > I only find raw_gadget.c that doesn't use composite framework, and it doesn't implement > many usb_gadget_driver callbacks, eg, .disconnect and .suspend. For .setup, we could > use above solutions for legacy composite driver. Okay, that's good. Alan Stern