Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2231280pxb; Fri, 17 Sep 2021 05:26:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzhBs+Gt7Dj7B4XDAu1jZwHckcmbShdnJEYUN5ugNxyZqZRYKKlJgVChueB3YN05hYqkhB6 X-Received: by 2002:a02:7160:: with SMTP id n32mr7712712jaf.99.1631881593913; Fri, 17 Sep 2021 05:26:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631881593; cv=none; d=google.com; s=arc-20160816; b=vwgiSDUoB56xQrAcYrkE4MgAMoF1ihh9Qwf933ioKRBv2ENP3r3sWKhwN8QRMEEtPV nFUsefcuyq1tO0GLn7o9LzPW13WjEac2wCoVppjHBhkMhXrgXlWTUXd9gkFHXhfHn5xz XXg+swpR039wc9yThn++XoWjjVxmBlX4JDfYIWAxJHfs2p8QjBitppDb/d5fF7hMV1o7 AH7om6KkbGw4KlBgp1Or6BSFnC2XzYc32unRcrdaxARoV7evlcQI63LQB6JP+DSdE0If 5SDz6xkkZXg4tLygem7ABE993i6VMEg8UcD8cTeOONnDgtCtv6CnZSMfWeSoJ6+rr9FK 0fTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:in-reply-to:date:subject :cc:to:from:user-agent:references:dkim-signature; bh=ZGRNXLYN2+RsZ5f8SyaepWtVY0ZCG/TKSITPJnW9Pd4=; b=CrpiFVckg3oYHGo4mPyTgAvhldsmy8FLMHdT5fCWhEp7b01S+tSmcVg+1nqhHjd7Xn AIPknlAtVSI7PYJSBtp+448KqkIEnT0PUTeD3jdIkHbfXvKyU+UTTwVgq5IHUZZu5Ysj hCUe0O3JUYY42KNbYuJn4ft19rhEeLQce5UioQdF+D9+LMBI8gUX+hVFVhFwtVWDIg2U pYHbNQLXzAe0chNK79GC4GJ6X2MqofhmLwVKthsheHjXgb2M+KptEDmu9jKmCnEqhXYL xyD5igjTx8YWJjeZAt9JP3J37smr4PifgQVT+lZbZuWIgvo/91SLOeRbb6hSc1owwaEE QHLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=f6dGy72x; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d186si7518787iog.78.2021.09.17.05.26.19; Fri, 17 Sep 2021 05:26:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=f6dGy72x; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244859AbhIQF1L (ORCPT + 99 others); Fri, 17 Sep 2021 01:27:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:46398 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229704AbhIQF1L (ORCPT ); Fri, 17 Sep 2021 01:27:11 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 80134610D1; Fri, 17 Sep 2021 05:25:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1631856349; bh=TALg6JvHavNoHAdcPmExgmEAS6Di8PdSRyieWhZbOE8=; h=References:From:To:Cc:Subject:Date:In-reply-to:From; b=f6dGy72x6U5KO9aOvfBIgbBqusJDYBwW5Dkule8jM5yxTRfmDj5qWqqHIKrrHIqZT Xb9kLp7bgbWljLWp0IX/4Jg8EzlyaB31Ta4vaaEjNodBhmrzjCWZnvJOUaqO+8+Fyo BTQ1AFYmQRR2syQafsz37o5NlhrxXN2WuxSlHvTf8L01dGpd1HE8LAkCgdkcB0Y3bU pZtFL01flVwznkH4fPiEzU1/EZBWWSzMBPulXCsPPy4v0QLrlt26G/kAk0rUQvtEbh wIdJy0Lk4FNinQErJ2/h6zm1cwPcexVUaK1/ESto9MPnvO3yzIY9HGlm1FEljaE0PY +JVrOl4xQWrKQ== References: <20210917021852.2037-1-wcheng@codeaurora.org> User-agent: mu4e 1.6.5; emacs 27.2 From: Felipe Balbi To: Wesley Cheng Cc: gregkh@linuxfoundation.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] usb: dwc3: gadget: Avoid starting DWC3 gadget during UDC unbind Date: Fri, 17 Sep 2021 08:17:03 +0300 In-reply-to: <20210917021852.2037-1-wcheng@codeaurora.org> Message-ID: <87y27vai3p.fsf@kernel.org> MIME-Version: 1.0 Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, Wesley Cheng writes: > There is a race present where the DWC3 runtime resume runs in parallel > to the UDC unbind sequence. This will eventually lead to a possible > scenario where we are enabling the run/stop bit, without a valid > composition defined. > > Thread#1 (handling UDC unbind): > usb_gadget_remove_driver() > -->usb_gadget_disconnect() > -->dwc3_gadget_pullup(0) > --> continue UDC unbind sequence > -->Thread#2 is running in parallel here > > Thread#2 (handing next cable connect) > __dwc3_set_mode() > -->pm_runtime_get_sync() > -->dwc3_gadget_resume() > -->dwc->gadget_driver is NOT NULL yet > -->dwc3_gadget_run_stop(1) > --> _dwc3gadget_start() > ... > > Fix this by tracking the pullup disable routine, and avoiding resuming > of the DWC3 gadget. Once the UDC is re-binded, that will trigger the > pullup enable routine, which would handle enabling the DWC3 gadget. > > Signed-off-by: Wesley Cheng This looks okay to me, but needs to be tested by a few folks ;-) Acked-by: Felipe Balbi -- balbi