Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1116182rwd; Wed, 7 Jun 2023 11:11:16 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7FJ1gOq9ZHAHF9vAcwcv2gkFzuRHy3OuYr2pAUlXbfmueRTkh+2IQTCco/+xgVpk2GcGM0 X-Received: by 2002:a05:6a20:7d9d:b0:103:7b36:f21 with SMTP id v29-20020a056a207d9d00b001037b360f21mr4340553pzj.21.1686161475651; Wed, 07 Jun 2023 11:11:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686161475; cv=none; d=google.com; s=arc-20160816; b=NPqzJf+Pa/zqg3BMKHyw8cyf6RCsPBjXDkFHHYGPTPjWpFwnZ6uzfFbpq7schS+/Bc +aOJc2km1P6BIdP3W8Fsc+rL7w0Dc9OfpjK37ui/757MiRtyj3J2Nohrd4eMErhEThR9 qDFEWPG++8HXDAWgodHp72DB8uoksgeQ1KVf/UvpE6vtic+57etqSD0WO/31HeU+uh55 WhZ33PDBDiXcHWVEHmMt4PYQUboOwGm/257RWmc5VSKcbLYDZ5nucJtc+6FAosnRL96D cUAyg0as6rP8KXZn5lOmJt9k9lCpLe23jTszZdcQotOelO5UQlReUSV2lGq4wxcAay0R SzVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=HrEREwdZXKVokcJ0VAI3LcwUXJFXYDiUFRxDTURL9y8=; b=obJyn6cTVBECUbVxtyGb/U72aTb8ewN3Joll6R1WAmO+7om2ooJWDwhWOfGQWIBZDd WpvCfCBEcjT783EaZnZGiCe3vqS2YyMdXeTlW7I3hZ+hejAaIEVIXuWXO7NPlkNUyff7 vL+L9LfBNn5zJ63UMxvTNXsANX1pH2f7GzNZP5KzVy0gncgdCyCzlNO3suXEpYXrm0Fa nhsAB2sDUjBaBYxfjkT255rHKYia+ASc9g2TqRsZJJN2myIRilViLdD5G7vuBkPa9fow hMEl3yrDmQTZni6E2CKHdye0MDlhS9r81jRoo7v3MkzL0PM/DLYKvxSUBtoCxeBgcHvZ 8mwQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o25-20020a637319000000b0053fec3ed061si9319386pgc.718.2023.06.07.11.10.16; Wed, 07 Jun 2023 11:11:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232037AbjFGRdZ (ORCPT + 99 others); Wed, 7 Jun 2023 13:33:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37136 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231937AbjFGRdR (ORCPT ); Wed, 7 Jun 2023 13:33:17 -0400 Received: from netrider.rowland.org (netrider.rowland.org [192.131.102.5]) by lindbergh.monkeyblade.net (Postfix) with SMTP id DD1C9211B for ; Wed, 7 Jun 2023 10:32:56 -0700 (PDT) Received: (qmail 233960 invoked by uid 1000); 7 Jun 2023 13:32:55 -0400 Date: Wed, 7 Jun 2023 13:32:55 -0400 From: Alan Stern To: Badhri Jagan Sridharan Cc: gregkh@linuxfoundation.org, colin.i.king@gmail.com, xuetao09@huawei.com, quic_eserrao@quicinc.com, water.zhangjiantao@huawei.com, francesco@dolcini.it, alistair@alistair23.me, stephan@gerhold.net, bagasdotme@gmail.com, luca@z3ntu.xyz, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH v6 1/2] usb: gadget: udc: core: Offload usb_udc_vbus_handler processing Message-ID: <65faa454-c822-4163-be3d-940fb4a647c7@rowland.harvard.edu> References: <20230601031028.544244-1-badhri@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230601031028.544244-1-badhri@google.com> X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jun 01, 2023 at 03:10:27AM +0000, Badhri Jagan Sridharan wrote: > usb_udc_vbus_handler() can be invoked from interrupt context by irq > handlers of the gadget drivers, however, usb_udc_connect_control() has > to run in non-atomic context due to the following: > a. Some of the gadget driver implementations expect the ->pullup > callback to be invoked in non-atomic context. > b. usb_gadget_disconnect() acquires udc_lock which is a mutex. > > Hence offload invocation of usb_udc_connect_control() > to workqueue. > > UDC should not be pulled up unless gadget driver is bound. The new flag > "allow_connect" is now set by gadget_bind_driver() and cleared by > gadget_unbind_driver(). This prevents work item to pull up the gadget > even if queued when the gadget driver is already unbound. > > Cc: stable@vger.kernel.org > Fixes: 1016fc0c096c ("USB: gadget: Fix obscure lockdep violation for udc_mutex") > Signed-off-by: Badhri Jagan Sridharan > --- > Changes since v1: > - Address Alan Stern's comment on usb_udc_vbus_handler invocation from > atomic context: > * vbus_events_lock is now a spinlock and allocations in > * usb_udc_vbus_handler are atomic now. > > Changes since v2: > - Addressing Alan Stern's comments: > ** connect_lock is now held by callers of > * usb_gadget_pullup_update_locked() and gadget_(un)bind_driver() does > * notdirectly hold the lock. > > ** Both usb_gadget_(dis)connect() and usb_udc_vbus_handler() would > * set/clear udc->vbus and invoke usb_gadget_pullup_update_locked. > > ** Add "unbinding" to prevent new connections after the gadget is being > * unbound. > > Changes since v3: > ** Made a minor cleanup which I missed to do in v3 in > * usb_udc_vbus_handler(). > > Changes since v4: > - Addressing Alan Stern's comments: > ** usb_udc_vbus_handler() now offloads invocation of usb_udc_connect_control() > * from workqueue. > > ** Dropped vbus_events list as this was redundant. Updating to the > * latest value is suffice > > Changes since v5: > - Addressing Alan Stern's comments: > ** Squashed allow_connect logic to this patch. > ** Fixed comment length to wrap at 76 > ** Cancelling vbus_work in del_gadget() Reviewed-by: Alan Stern