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=-16.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham 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 BF436C433E6 for ; Tue, 5 Jan 2021 13:36:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8DB2022AAE for ; Tue, 5 Jan 2021 13:36:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729641AbhAENgJ (ORCPT ); Tue, 5 Jan 2021 08:36:09 -0500 Received: from mail.kernel.org ([198.145.29.99]:36266 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726707AbhAENgI (ORCPT ); Tue, 5 Jan 2021 08:36:08 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4F37C225AC; Tue, 5 Jan 2021 13:35:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1609853728; bh=ER7oX2qdsWqz4DG0yItHR0XwIVuxNomoqXYtb296gG8=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=LF1L4Zd9vxvl98aYLL2yIjBOrqixIhlmhZqqd6FXgteRWE8tNVbiMtMctJmRU+V+g 8Uzq/0c5eH9PyZb4UPpn4LkbG3PbFWbXz2M7Go8wS3EOOXDuneaZklU4me9bzCf83/ 9Nn/0I/wCDwuivahELoowdDmd52EyrLmjlgcfwzqkyYk29lyapRU8OTCMMUsWhoa1L dVhI+dHkCx5TkgzFm+Z1m0JFFC4VREzp9G/3MxBXIOuwkuWuw8ed7GtTtB2KHoFRtY q/2rEXqnJTckfAZjq5J/xQYMn9Hl3JwIM7NrleY0tjVzU+cbCr6v4aU6pkeeIObqip BkUe918LvXoCw== From: Felipe Balbi To: Thinh Nguyen , Thinh Nguyen , Greg Kroah-Hartman , "linux-usb@vger.kernel.org" Cc: John Youn , "stable@vger.kernel.org" Subject: Re: [PATCH v2] usb: dwc3: gadget: Clear wait flag on dequeue In-Reply-To: References: <87turvczg4.fsf@kernel.org> Date: Tue, 05 Jan 2021 15:35:23 +0200 Message-ID: <87h7nvcxr8.fsf@kernel.org> MIME-Version: 1.0 Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org Hi, Thinh Nguyen writes: >> Thinh Nguyen writes: >>> If an active transfer is dequeued, then the endpoint is freed to start a >>> new transfer. Make sure to clear the endpoint's transfer wait flag for >>> this case. >>> >>> Cc: stable@vger.kernel.org >>> Fixes: e0d19563eb6c ("usb: dwc3: gadget: Wait for transfer completion") >>> Signed-off-by: Thinh Nguyen >>> --- >>> Changes in v2: >>> - Only clear the wait flag if the selected request is of an active transfer. >>> Otherwise, any dequeue will change the endpoint's state even if it's for >>> some random request. >>> >>> drivers/usb/dwc3/gadget.c | 2 ++ >>> 1 file changed, 2 insertions(+) >>> >>> diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c >>> index 78cb4db8a6e4..9a00dcaca010 100644 >>> --- a/drivers/usb/dwc3/gadget.c >>> +++ b/drivers/usb/dwc3/gadget.c >>> @@ -1763,6 +1763,8 @@ static int dwc3_gadget_ep_dequeue(struct usb_ep *ep, >>> list_for_each_entry_safe(r, t, &dep->started_list, list) >>> dwc3_gadget_move_cancelled_request(r); >>> >>> + dep->flags &= ~DWC3_EP_WAIT_TRANSFER_COMPLETE; >> I'm not sure this is correct. This could create a race condition between >> clearing this bit and getting the transfer complete interrupt. It also >> seems to break the assumptions made by >> dwc3_gadget_endpoint_trbs_complete() (actually its users), specially >> regarding ISOC endpoints. >> >> Have you verified all transfer types with this commit? >> > > It shouldn't race. It's protected by the spinlock irq and it doesn't > matter whether dwc3_gadget_endpoint_trbs_complete() or this dequeue > function clears it first. The flag DWC3_EP_WAIT_TRANSFER_COMPLETE is > only applicable to stream transfer as the driver needs to wait for 1 > stream to finish before starting another. > > This is verified with our test environment (which includes UASP CV and > others). Fair enough, I'll take your word for it :-) Acked-by: Felipe Balbi -- balbi