Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp2510972imm; Mon, 24 Sep 2018 05:42:10 -0700 (PDT) X-Google-Smtp-Source: ACcGV62+Oc7ZluS7VMjgKWETYZK2w3joGVXuVhwyk/rzlrWUou0bGfAaS7gBGelmJzHyzjTNj3if X-Received: by 2002:a63:ad44:: with SMTP id y4-v6mr9327069pgo.138.1537792930014; Mon, 24 Sep 2018 05:42:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537792929; cv=none; d=google.com; s=arc-20160816; b=sKu1GgNw2WyiCw9H/rdrAYlS8v2bR2y5riclIKtFOMMn2KmnP5LdIZO1EttRUPAMJo GGaaNf374GMN2+0B3Bk+TSah90hdc4uCOy8pApxvYT0TjbVbAHppylbc7Il23dBkyY5P AX2goKpZehTJhetV7FZb2H9lrGVvR5pnqQ0cTkkq7lnNVmjs7b87zCusA+AABlArspY/ 64mqAjWY8jukotD8LRLAFF26R5Q+hsxOdO5UeBfJwYI9XotUmRCL8vNrN/GywLP1C60n OB5Nn4hPJ1CPjBGMgk8YECnq/KbDILAmyRTjSGSvIYVI+9kU3AGFBNQ8YEIxb82oWoDL Rytw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from; bh=2QadcZ3e6rU2xKMYYmUua3nAdjdfQ3fx0qoCf1P+WQo=; b=iU2WJEOIF5QcY6HEqCPg2ndNaigmYuQhgJEDF5GVuLJSYu6C4JW534zjsNdOm1GWCD LRiZwxOFtg+O9swQuOfHSzGGjotLfrrEOmMSv+T9zAv8Z2HwnM5X6hT4q5CkItOzRHgx cWEVwGQYa/TELjcOPU/xoqheI8s0ND3NRHx7KZ5SOrGxGu80WBdXieP4FNj7nJm/6Hen UyVAB5vmp8xqr1+/3+zIZUY9t+V/JH61OQJclNEv/xxXqiMxojNDnG4iVVmiQVZmitPJ UEWb7FD0/OpZvGNMpGF6J5wuln8di8sCSDJd+FfbddozxyyircZaSevfewntefX3SgXO HF/A== 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 z22-v6si30720521pgv.323.2018.09.24.05.41.54; Mon, 24 Sep 2018 05:42:09 -0700 (PDT) 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 S2388682AbeIXSmy (ORCPT + 99 others); Mon, 24 Sep 2018 14:42:54 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:59066 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388675AbeIXSmx (ORCPT ); Mon, 24 Sep 2018 14:42:53 -0400 Received: from localhost (ip-213-127-77-73.ip.prioritytelecom.net [213.127.77.73]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 2B488109F; Mon, 24 Sep 2018 12:40:54 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alan Stern , "D. Ziesche" , Felipe Balbi Subject: [PATCH 4.18 127/235] USB: net2280: Fix erroneous synchronization change Date: Mon, 24 Sep 2018 13:51:53 +0200 Message-Id: <20180924113118.699783973@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180924113103.999624566@linuxfoundation.org> References: <20180924113103.999624566@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Alan Stern commit dec3c23c9aa1815f07d98ae0375b4cbc10971e13 upstream. Commit f16443a034c7 ("USB: gadgetfs, dummy-hcd, net2280: fix locking for callbacks") was based on a serious misunderstanding. It introduced regressions into both the dummy-hcd and net2280 drivers. The problem in dummy-hcd was fixed by commit 7dbd8f4cabd9 ("USB: dummy-hcd: Fix erroneous synchronization change"), but the problem in net2280 remains. Namely: the ->disconnect(), ->suspend(), ->resume(), and ->reset() callbacks must be invoked without the private lock held; otherwise a deadlock will occur when the callback routine tries to interact with the UDC driver. This patch largely is a reversion of the relevant parts of f16443a034c7. It also drops the private lock around the calls to ->suspend() and ->resume() (something the earlier patch forgot to do). This is safe from races with device interrupts because it occurs within the interrupt handler. Finally, the patch changes where the ->disconnect() callback is invoked when net2280_pullup() turns the pullup off. Rather than making the callback from within stop_activity() at a time when dropping the private lock could be unsafe, the callback is moved to a point after the lock has already been dropped. Signed-off-by: Alan Stern Fixes: f16443a034c7 ("USB: gadgetfs, dummy-hcd, net2280: fix locking for callbacks") Reported-by: D. Ziesche Tested-by: D. Ziesche CC: Signed-off-by: Felipe Balbi Signed-off-by: Greg Kroah-Hartman --- drivers/usb/gadget/udc/net2280.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) --- a/drivers/usb/gadget/udc/net2280.c +++ b/drivers/usb/gadget/udc/net2280.c @@ -1545,11 +1545,14 @@ static int net2280_pullup(struct usb_gad writel(tmp | BIT(USB_DETECT_ENABLE), &dev->usb->usbctl); } else { writel(tmp & ~BIT(USB_DETECT_ENABLE), &dev->usb->usbctl); - stop_activity(dev, dev->driver); + stop_activity(dev, NULL); } spin_unlock_irqrestore(&dev->lock, flags); + if (!is_on && dev->driver) + dev->driver->disconnect(&dev->gadget); + return 0; } @@ -2466,8 +2469,11 @@ static void stop_activity(struct net2280 nuke(&dev->ep[i]); /* report disconnect; the driver is already quiesced */ - if (driver) + if (driver) { + spin_unlock(&dev->lock); driver->disconnect(&dev->gadget); + spin_lock(&dev->lock); + } usb_reinit(dev); } @@ -3341,6 +3347,8 @@ next_endpoints: BIT(PCI_RETRY_ABORT_INTERRUPT)) static void handle_stat1_irqs(struct net2280 *dev, u32 stat) +__releases(dev->lock) +__acquires(dev->lock) { struct net2280_ep *ep; u32 tmp, num, mask, scratch; @@ -3381,12 +3389,14 @@ static void handle_stat1_irqs(struct net if (disconnect || reset) { stop_activity(dev, dev->driver); ep0_start(dev); + spin_unlock(&dev->lock); if (reset) usb_gadget_udc_reset (&dev->gadget, dev->driver); else (dev->driver->disconnect) (&dev->gadget); + spin_lock(&dev->lock); return; } } @@ -3405,6 +3415,7 @@ static void handle_stat1_irqs(struct net tmp = BIT(SUSPEND_REQUEST_CHANGE_INTERRUPT); if (stat & tmp) { writel(tmp, &dev->regs->irqstat1); + spin_unlock(&dev->lock); if (stat & BIT(SUSPEND_REQUEST_INTERRUPT)) { if (dev->driver->suspend) dev->driver->suspend(&dev->gadget); @@ -3415,6 +3426,7 @@ static void handle_stat1_irqs(struct net dev->driver->resume(&dev->gadget); /* at high speed, note erratum 0133 */ } + spin_lock(&dev->lock); stat &= ~tmp; }