Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2988806imu; Sun, 9 Dec 2018 14:24:56 -0800 (PST) X-Google-Smtp-Source: AFSGD/UxC/8W7jI7JaKZhmqfFJQG2puQV3vt2zsbUwiWAkmXKYbpVB+IU+oDqq+2KAn1rO44wY2g X-Received: by 2002:a17:902:e085:: with SMTP id cb5mr9788645plb.24.1544394296373; Sun, 09 Dec 2018 14:24:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544394296; cv=none; d=google.com; s=arc-20160816; b=RXW1sciksIQH4COZL6SWu4XwUNywmBq3PGc9DBxuHw17OwtwMpfVaYKMMLRgJsg1xZ 6fuQ4j9rUD5A4O+a0V7O20LjZsftZJJQpVyt/WhqWj1rBdf0zuYxGGRedyrqt0gg3LMh KHVOdcyFQPq0l3tLlkeUA7Xb9cVcaa/r+PwJSIUwX82TZEgszSJdSgg2MvcAgkfwP6xF RjrLESzwI7J3REV2VLTgbkiM8vuAMtn56GTqAAJSKCJAw9sSv+JeEuF7R9oKnm1qjEYS C67z3M8Y770YxJtRnhKgfqlPCD4S4MI2Xj/Ycv1Hf/FP/9d1e9PehnicYVgPmVl74teP vJRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition; bh=FxX1rdys7PTRBoAQGnGlFYkaziIk4Y8jwMZ8Enuo394=; b=QWZTrV2/JuKufANNp+HSjJ/6kZvsSG2NgjWa5C5T3Z6ejB99DKISiK1l8mk/3TggI6 YI1S5VcX3Bhf6PhImfGDj6+lxz093+asy7CEc/TEpTQ5TCM4aGIUiFQCyZH/LzNtDmBX Gel5kmyL0uMbd1T0Jw3DRB7nUy/Ava9TjRwvB83QvQ7rNOfXns/u9ILa716J1FrUxyJ/ TMOi55Uq8UcItNIcSw1WrK95FlshkB/SVf4U2LhGeqgNiZulQNNYLlmq97r1OKwHwM/9 C0Dad6g8nRndx94fHs6rSZVZA8qT9CrEFsVJLQf3GKZ1MZmFeXw2ONXjXwE1sKz1AK/T fliQ== 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 r196si8128195pgr.311.2018.12.09.14.24.41; Sun, 09 Dec 2018 14:24:56 -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 S1728576AbeLIWX2 (ORCPT + 99 others); Sun, 9 Dec 2018 17:23:28 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:35092 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726301AbeLIVzT (ORCPT ); Sun, 9 Dec 2018 16:55:19 -0500 Received: from pub.yeoldevic.com ([81.174.156.145] helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1gW72h-0002io-Rq; Sun, 09 Dec 2018 21:55:16 +0000 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1gW72e-0003S5-Og; Sun, 09 Dec 2018 21:55:12 +0000 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Felipe Balbi" , "Alan Stern" , "D. Ziesche" Date: Sun, 09 Dec 2018 21:50:33 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) X-Patchwork-Hint: ignore Subject: [PATCH 3.16 172/328] USB: net2280: Fix erroneous synchronization change In-Reply-To: X-SA-Exim-Connect-IP: 81.174.156.145 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.62-rc1 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 Signed-off-by: Felipe Balbi [bwh: Backported to 3.16: - Drop inapplicable change to disconnection handling in handle_stat1_irqs() - Adjust filename, context] Signed-off-by: Ben Hutchings --- --- a/drivers/usb/gadget/net2280.c +++ b/drivers/usb/gadget/net2280.c @@ -1399,11 +1399,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; } @@ -1948,8 +1951,11 @@ stop_activity (struct net2280 *dev, stru 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); } @@ -2452,6 +2458,8 @@ next_endpoints: | (1 << 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; @@ -2494,6 +2502,7 @@ static void handle_stat1_irqs (struct ne tmp = (1 << SUSPEND_REQUEST_CHANGE_INTERRUPT); if (stat & tmp) { writel (tmp, &dev->regs->irqstat1); + spin_unlock(&dev->lock); if (stat & (1 << SUSPEND_REQUEST_INTERRUPT)) { if (dev->driver->suspend) dev->driver->suspend (&dev->gadget); @@ -2504,6 +2513,7 @@ static void handle_stat1_irqs (struct ne dev->driver->resume (&dev->gadget); /* at high speed, note erratum 0133 */ } + spin_lock(&dev->lock); stat &= ~tmp; }