Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2697934rwd; Wed, 17 May 2023 13:10:21 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6ytbcq1feMD/nh9YprbCgOKL0wmhvTzlW/LGP1jZsjM4O/y55FIY3lA2uVI0yhavQ9VLec X-Received: by 2002:a05:6a00:2313:b0:646:3c2:4d30 with SMTP id h19-20020a056a00231300b0064603c24d30mr1043804pfh.30.1684354221658; Wed, 17 May 2023 13:10:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684354221; cv=none; d=google.com; s=arc-20160816; b=Ch9P/Ta+KRDzvCUeL7NcxDbyFaZoMI05SMMyLpOQE18JdkL822Hm4wv5uLUTHzEEeQ 8agrtRSBT1ec5jIa6DyA31LHCoh9pH6mofq+XuxxZVn5Rm6vXSwQMij518es5n0j1fe2 qUpOyLoqnB3FGvECKWJ+emLJ/ET9ybqkXjD3yfdwN8/GD6oLHrQVxQM46jaweUWQjwa+ Db240HMqIzGZl7jEFz7TBC+Vj1J6f8t0BtpHFxsFfkzlhSJN/soyr0vZ2pG7ygIhXB55 eIYCe526Ckldt9y5qQpxBMDEOOe+I1qAbYwDoIBDB/JWZeH9hoo962TZRziY+43TbPre pc3g== 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-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=qixDBjDShweJUBSguOokH6l7Y4T5qQBYUL7heyCeqPE=; b=H/D4wLR7JJwVReI9xfZpxsYfxnNEiEEYlLNKNii4gefWyjptMrQIe1B3HO7bUjgPt5 zZtpPtnYnLICXxyckkNOLcAdEcilUmImY4ncJtFvD9/k0dAc5RpST14by8pIj7q4OZ1J qHnqHL0+Ku1JK2EMLQekwzEG6YEYdoAAo90Q4nzAsU/6UACWkPcPAOl25UdYFoJ5Hiys bwwLpfarGL85ldXrJ6HxJfBighr3kusGsiOmsKZyHbjB81ShPLMOkDOh47O0AWg+5ljC zieZg/p5gtmo3NZcod5IGO6W1J1EfaLC2tdbrGge0fxDl+bBF5hrPDiYt2Fpsoniunbx Y7oQ== 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 r17-20020a638f51000000b005073e3342eesi10387233pgn.143.2023.05.17.13.10.07; Wed, 17 May 2023 13:10:21 -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 S229487AbjEQUBd (ORCPT + 99 others); Wed, 17 May 2023 16:01:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42128 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229497AbjEQUBb (ORCPT ); Wed, 17 May 2023 16:01:31 -0400 Received: from netrider.rowland.org (netrider.rowland.org [192.131.102.5]) by lindbergh.monkeyblade.net (Postfix) with SMTP id 3049F5B8E for ; Wed, 17 May 2023 13:01:29 -0700 (PDT) Received: (qmail 887386 invoked by uid 1000); 17 May 2023 16:01:28 -0400 Date: Wed, 17 May 2023 16:01:28 -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, peter.chen@freescale.com, balbi@ti.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, Francesco Dolcini Subject: Re: [PATCH v1] usb: gadget: udc: core: Offload usb_udc_vbus_handler processing Message-ID: References: <20230517115955.1078339-1-badhri@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: 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 Wed, May 17, 2023 at 10:19:25AM -0700, Badhri Jagan Sridharan wrote: > On Wed, May 17, 2023 at 7:44 AM Alan Stern wrote: > > > > On Wed, May 17, 2023 at 11:59:55AM +0000, Badhri Jagan Sridharan wrote: > > > chipidea udc calls usb_udc_vbus_handler from udc_start gadget > > > ops causing a deadlock. Avoid this by offloading usb_udc_vbus_handler > > > processing. > > > > Surely that is the wrong approach. > > > > The real problem here is that usb_udc_vbus_handler() gets called from > > within a udc_start routine. But this is totally unnecessary, because > > the UDC core will call usb_udc_connect_control_locked() itself, later on > > during gadget_bind_driver(). > > Hi Alan, > > usb_udc_vbus_handler sets the udc->vbus flag as well apart from > calling usb_udc_connect_control_locked(). So, removing usb_udc_vbus_handler > from chip specific start callback might prevent the controller from > starting. > > void usb_udc_vbus_handler(struct usb_gadget *gadget, bool status) > { > struct usb_udc *udc = gadget->udc; > > mutex_lock(&udc->connect_lock); > if (udc) { > udc->vbus = status; > usb_udc_connect_control_locked(udc); Then add "udc->vbus = true;" at the appropriate spot in gadget_bind_driver(). Alan Stern PS: I just noticed that in max3420_udc.c, the max_3420_vbus_handler() function calls usb_udc_vbus_handler() from within an interrupt handler. This won't work, since interrupt handlers aren't allowed to sleep and therefore can't lock mutexes.