Received: by 2002:ac0:8c9a:0:0:0:0:0 with SMTP id r26csp1866134ima; Sat, 2 Feb 2019 09:02:47 -0800 (PST) X-Google-Smtp-Source: AHgI3IaOULnQdWYXfo+K73NBx3ntnILL3TLYXYwqH8TUsCH70U+9vqS+kvnZG6ZVQRNxjcUrKQLx X-Received: by 2002:a65:534b:: with SMTP id w11mr6773724pgr.125.1549126967787; Sat, 02 Feb 2019 09:02:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549126967; cv=none; d=google.com; s=arc-20160816; b=Z6YbD6ApM2gPthEBNWRSjzKiv+dHRwr9bOgmKi5iwY5+Q62SQowcy93h5Japyvyxef ldA+FB8gDdc+GPTy22RvLY6/OO50DzkschcxvG6nu6ARrN/roODIjl08+6nxzMqvsUiT etYvteLt19ygS8GuPg7yip/Uj3ZmpzU4Z77w4vXyLBdQHyoK8CXfprjq172sASG+SoJg UNW2lTEgyYkGK8QOPsQgX33WtNdhUZrhKigucr3Z4w0QJOf87tq8gMgGQRS3s4qftFyS LEhU/w3JFzD8GhOv5wtJ/C+T13HpwaZZjPIZkqFYZaRJMEWGSsaznt6anRyMuWVMA2Sb BQTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:in-reply-to :subject:cc:to:from:date; bh=Dh17jwaeaM1j66pK3pjBdc5dLrB3dBIB58+zRksrysc=; b=Gu46qByxjyiG8FzADwXzMHYaJaXVnc8xciVoqk4h1TWWtNg3UHaATmhIJ0yBoEnVgq cAxe7wELb1l/v9mcYbnbsUI2d54P04KPo15HU5dikHtWbXAYmBDFmdc8jCQsyAeSjvAO FFC/I80+EtTmeRjLXIckzworn529ZZVjCsjUgpfJe8LbVc8oD3V8bMk3ZPcVYZ5FpEUG 2LpuFcbGl4tuAz4cJjfcXqdTNh4BK8nD2NhIGpnMZFfgjF/NKOc1+kfzo02j8GQ/gS8f nApgV5j5Jds4ADB7XLfVwh2691g2tBn+2eCSOw51gU9iSRWvraZGzJf/RAtf4Mghxv0z CKpg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t186si10819528pfd.68.2019.02.02.09.02.23; Sat, 02 Feb 2019 09:02:47 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726483AbfBBRAJ (ORCPT + 99 others); Sat, 2 Feb 2019 12:00:09 -0500 Received: from netrider.rowland.org ([192.131.102.5]:55695 "HELO netrider.rowland.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1726055AbfBBRAJ (ORCPT ); Sat, 2 Feb 2019 12:00:09 -0500 Received: (qmail 14372 invoked by uid 500); 2 Feb 2019 12:00:08 -0500 Received: from localhost (sendmail-bs@127.0.0.1) by localhost with SMTP; 2 Feb 2019 12:00:08 -0500 Date: Sat, 2 Feb 2019 12:00:08 -0500 (EST) From: Alan Stern X-X-Sender: stern@netrider.rowland.org To: John Stultz cc: Felipe Balbi , Zeng Tao , Jack Pham , Thinh Nguyen , Chen Yu , lkml , Linux USB List , Greg Kroah-Hartman Subject: Re: Frequent dwc3 crashes on suspend or reboot since 5.0-rc1 In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 1 Feb 2019, John Stultz wrote: > Hey all, > Since the 5.0 merge window opened, I've been tripping on frequent > dwc3 crashes on reboot and suspend, which I've added an example to the > bottom of this mail. > > I've dug in a little bit and sort of have a sense of whats going on. > > In ffs_epfile_io(): > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/usb/gadget/function/f_fs.c#n1065 > > The completion done is setup on the stack: > DECLARE_COMPLETION_ONSTACK(done); > > Then later we setup a request and queue it: > req->context = &done; > ... > ret = usb_ep_queue(ep->ep, req, GFP_ATOMIC); > > Then wait for it: > if (unlikely(wait_for_completion_interruptible(&done))) { > /* > * To avoid race condition with ffs_epfile_io_complete, > * dequeue the request first then check > * status. usb_ep_dequeue API should guarantee no race > * condition with req->complete callback. > */ > usb_ep_dequeue(ep->ep, req); This code contains a bug: It assumes that usb_ep_dequeue() waits until the request has been completed. You should insert wait_for_completion(&done); right here. > interrupted = ep->status < 0; > } > > The problem is, that we end up being interrupted, supposedly dequeue > the request, and exit. > > But then (or in parallel) the irq triggers and we try calling > complete() on the context pointer which points to now random stack > space, which results in the panic. This is the natural result of not waiting for the request to complete. > It seems like something is wrong with usb_ep_dequeue not really > stopping the irq from happening? Certainly. usb_ep_dequeue() just speeds up the process of completing the request; it doesn't wait for that process to finish. Alan Stern > If I revert all the changes to dwc3 back to 4.20, I don't see the issue. > > I'll do some bisection to try to narrow things down, but I wanted to > see if this was a known issue or if anyone had immediate ideas as to > what might be wrong. > > thanks > -john