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=-9.1 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_PASS,URIBL_BLOCKED,USER_AGENT_NEOMUTT 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 1CB0FC282C8 for ; Mon, 28 Jan 2019 20:16:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D24882171F for ; Mon, 28 Jan 2019 20:16:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="vM/I4GWe" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726862AbfA1UQR (ORCPT ); Mon, 28 Jan 2019 15:16:17 -0500 Received: from mail-wr1-f66.google.com ([209.85.221.66]:41866 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726805AbfA1UQR (ORCPT ); Mon, 28 Jan 2019 15:16:17 -0500 Received: by mail-wr1-f66.google.com with SMTP id x10so19518821wrs.8 for ; Mon, 28 Jan 2019 12:16:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=PXltsOO/SbbFicRQq95ug3gbHGUCfdc2x2rrK73UTBE=; b=vM/I4GWej2yJ3pHiSdxeJ3dPPDAWo9VyovztGu8cVdbmJyx1hNH1kRl2giAgBwaXZQ x3KrypKrGuXMdJWYzqf4t6+obLzUq42TrSEr6tmWu0RXuq7fzBsLza5DRTJ4wZ7w+8As 4M4/mgVppPbCISE1S1i9Jf2fZr8+g7B40aASk2WkLWRCRO+txJUjJkqgJIskPoy73KQ9 lXT7kSui6DIIpvm7w+O8Svxv5ld215JWUNBZ5SL50JsuLq4JmSNfhmhV9YAh1GIRffx4 NeDBkUtFLT5E6IdloqlcjNx7pN/GOzhbRJBTykt1i0+Rfd+bgBPy78b7ZaxYSQs4rqkR FD6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=PXltsOO/SbbFicRQq95ug3gbHGUCfdc2x2rrK73UTBE=; b=tC49qvgrTCFPdKzleY9F51IkqU83Tu1AGDH/2uL4F9wjhBh0OSrZPZzFp+E6Ur1Al+ 3Wd+5gr0XNpWg1OfukacRnVJTH3bE9IlfYg/9GkO4yMclmtOaAhW3yaXkHSyRaRM1XIh 1bdV/WcRLxvtgGGMXL98TGxOcTPqTRmaOF8Sts99Haejpkdx5sI2kSSKfBiwOJrMaakY nPZcK4cw9juCVY2UC6fg76kpmPPpaUKOMgc8ECGZ15SquouBdFPrw1WzfHaSMDvUr1c+ oB55fCiea8oj7XNvgsWFAssiUsZKZDc6UyUmInM++Yn47HR5lsH+G9T5BpZALgSZ8gRO Ci6w== X-Gm-Message-State: AJcUukfM6QNi7+7yxllpbCdtOE7h3yzo3UiJyNpBYDaaBrWqUp6+5kIg fNv2qUxZ8t1rBNbHKDxPWRk= X-Google-Smtp-Source: ALg8bN6GrVXwz41zJLH5gVFZs2rXUL8AMoeBFU2ssX9GJhToqAgkC2msbPAsFnAEoMa8Pl+vZET/9A== X-Received: by 2002:adf:ec50:: with SMTP id w16mr23840708wrn.171.1548706574970; Mon, 28 Jan 2019 12:16:14 -0800 (PST) Received: from debian (cpc101300-bagu16-2-0-cust362.1-3.cable.virginm.net. [86.21.41.107]) by smtp.gmail.com with ESMTPSA id h131sm685835wmd.17.2019.01.28.12.16.13 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 28 Jan 2019 12:16:14 -0800 (PST) Date: Mon, 28 Jan 2019 20:16:12 +0000 From: Sudip Mukherjee To: gregkh@linuxfoundation.org Cc: mathias.nyman@linux.intel.com, chunfeng.yun@mediatek.com, jackp@codeaurora.org, joel@jms.id.au, peter.chen@nxp.com, stable@vger.kernel.org, sunjianguo1@huawei.com, treding@nvidia.com Subject: Re: FAILED: patch "[PATCH] xhci: Fix leaking USB3 shared_hcd at xhci removal" failed to apply to 4.14-stable tree Message-ID: <20190128201612.jdrmywkp4xulmpnc@debian> References: <154339720422655@kroah.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="mg2quyo6npe4rfvv" Content-Disposition: inline In-Reply-To: <154339720422655@kroah.com> User-Agent: NeoMutt/20170113 (1.7.2) Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org --mg2quyo6npe4rfvv Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hi Greg, On Wed, Nov 28, 2018 at 10:26:44AM +0100, gregkh@linuxfoundation.org wrote: > > The patch below does not apply to the 4.14-stable tree. > If someone wants it applied there, or to any other stable or longterm > tree, then please email the backport, including the original git commit > id to . The attached backported patch should apply to 4.14-stable tree. The original patch was also changing drivers/usb/host/xhci-histb.c which is not needed in v4.14.y as that file was created in v4.18 by: c508f41da078 ("xhci: hisilicon: support HiSilicon STB xHCI host controller") -- Regards Sudip --mg2quyo6npe4rfvv Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0001-xhci-Fix-leaking-USB3-shared_hcd-at-xhci-removal.patch" >From 103fd0c5188d19284967e1019588700e2b2a6a67 Mon Sep 17 00:00:00 2001 From: Mathias Nyman Date: Fri, 9 Nov 2018 17:21:17 +0200 Subject: [PATCH] xhci: Fix leaking USB3 shared_hcd at xhci removal commit f068090426ea8d72c408ebd42953a82a88e2282c upstream Ensure that the shared_hcd pointer is valid when calling usb_put_hcd() The shared_hcd is removed and freed in xhci by first calling usb_remove_hcd(xhci->shared_hcd), and later usb_put_hcd(xhci->shared_hcd) Afer commit fe190ed0d602 ("xhci: Do not halt the host until both HCD have disconnected their devices.") the shared_hcd was never properly put as xhci->shared_hcd was set to NULL before usb_put_hcd(xhci->shared_hcd) was called. shared_hcd (USB3) is removed before primary hcd (USB2). While removing the primary hcd we might need to handle xhci interrupts to cleanly remove last USB2 devices, therefore we need to set xhci->shared_hcd to NULL before removing the primary hcd to let xhci interrupt handler know shared_hcd is no longer available. xhci-plat.c, xhci-histb.c and xhci-mtk first create both their hcd's before adding them. so to keep the correct reverse removal order use a temporary shared_hcd variable for them. For more details see commit 4ac53087d6d4 ("usb: xhci: plat: Create both HCDs before adding them") Fixes: fe190ed0d602 ("xhci: Do not halt the host until both HCD have disconnected their devices.") Cc: Joel Stanley Cc: Chunfeng Yun Cc: Thierry Reding Cc: Jianguo Sun Cc: Reported-by: Jack Pham Tested-by: Jack Pham Tested-by: Peter Chen Signed-off-by: Mathias Nyman Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sudip Mukherjee --- drivers/usb/host/xhci-mtk.c | 6 ++++-- drivers/usb/host/xhci-pci.c | 1 + drivers/usb/host/xhci-plat.c | 6 ++++-- drivers/usb/host/xhci-tegra.c | 1 + drivers/usb/host/xhci.c | 2 -- 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/drivers/usb/host/xhci-mtk.c b/drivers/usb/host/xhci-mtk.c index 510d28a9d190..35aecbcac6f7 100644 --- a/drivers/usb/host/xhci-mtk.c +++ b/drivers/usb/host/xhci-mtk.c @@ -724,14 +724,16 @@ static int xhci_mtk_remove(struct platform_device *dev) struct xhci_hcd_mtk *mtk = platform_get_drvdata(dev); struct usb_hcd *hcd = mtk->hcd; struct xhci_hcd *xhci = hcd_to_xhci(hcd); + struct usb_hcd *shared_hcd = xhci->shared_hcd; - usb_remove_hcd(xhci->shared_hcd); + usb_remove_hcd(shared_hcd); + xhci->shared_hcd = NULL; xhci_mtk_phy_power_off(mtk); xhci_mtk_phy_exit(mtk); device_init_wakeup(&dev->dev, false); usb_remove_hcd(hcd); - usb_put_hcd(xhci->shared_hcd); + usb_put_hcd(shared_hcd); usb_put_hcd(hcd); xhci_mtk_sch_exit(mtk); xhci_mtk_clks_disable(mtk); diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c index 0fbc549cc55c..1de006aebec5 100644 --- a/drivers/usb/host/xhci-pci.c +++ b/drivers/usb/host/xhci-pci.c @@ -370,6 +370,7 @@ static void xhci_pci_remove(struct pci_dev *dev) if (xhci->shared_hcd) { usb_remove_hcd(xhci->shared_hcd); usb_put_hcd(xhci->shared_hcd); + xhci->shared_hcd = NULL; } /* Workaround for spurious wakeups at shutdown with HSW */ diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c index 830dd0dbbce0..108a212294bf 100644 --- a/drivers/usb/host/xhci-plat.c +++ b/drivers/usb/host/xhci-plat.c @@ -332,14 +332,16 @@ static int xhci_plat_remove(struct platform_device *dev) struct usb_hcd *hcd = platform_get_drvdata(dev); struct xhci_hcd *xhci = hcd_to_xhci(hcd); struct clk *clk = xhci->clk; + struct usb_hcd *shared_hcd = xhci->shared_hcd; xhci->xhc_state |= XHCI_STATE_REMOVING; - usb_remove_hcd(xhci->shared_hcd); + usb_remove_hcd(shared_hcd); + xhci->shared_hcd = NULL; usb_phy_shutdown(hcd->usb_phy); usb_remove_hcd(hcd); - usb_put_hcd(xhci->shared_hcd); + usb_put_hcd(shared_hcd); if (!IS_ERR(clk)) clk_disable_unprepare(clk); diff --git a/drivers/usb/host/xhci-tegra.c b/drivers/usb/host/xhci-tegra.c index 32ddafe7af87..28df32d85671 100644 --- a/drivers/usb/host/xhci-tegra.c +++ b/drivers/usb/host/xhci-tegra.c @@ -1178,6 +1178,7 @@ static int tegra_xusb_remove(struct platform_device *pdev) usb_remove_hcd(xhci->shared_hcd); usb_put_hcd(xhci->shared_hcd); + xhci->shared_hcd = NULL; usb_remove_hcd(tegra->hcd); usb_put_hcd(tegra->hcd); diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index 930eecd86429..c78de07c4d00 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -669,8 +669,6 @@ static void xhci_stop(struct usb_hcd *hcd) /* Only halt host and free memory after both hcds are removed */ if (!usb_hcd_is_primary_hcd(hcd)) { - /* usb core will free this hcd shortly, unset pointer */ - xhci->shared_hcd = NULL; mutex_unlock(&xhci->mutex); return; } -- 2.11.0 --mg2quyo6npe4rfvv--