From patchwork Tue Feb 15 12:33:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 542992 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A4784C433FE for ; Tue, 15 Feb 2022 12:32:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234513AbiBOMcT (ORCPT ); Tue, 15 Feb 2022 07:32:19 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:38840 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230356AbiBOMcT (ORCPT ); Tue, 15 Feb 2022 07:32:19 -0500 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF259107D33; Tue, 15 Feb 2022 04:32:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1644928329; x=1676464329; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=KkBlnmLKLUYXvnLYGVy9PBO4HTSjyp0rWzHy7zNqLxA=; b=ah+R7gvfpyLWBqOy/Hr+zXMPR3kbfIPmTiK8283jscQeNYnJAOK8btV+ 8IDS1CXX9VGROa63uHMuq+8RdrMMqARfO0mUxvVXqhGBqpt6YD1pygfzg DIqtKfCjvTBs8nYUR/KJ6d4SYIAzkYqyWtfo3P7XBKEhPe5kRKreTmPzR KBbpLgsX5Y/NmjMVDGytvLP8ATv5HqrTda2gh1NGaBx2k1EvETSQtpuzs CjWHJJwYh9AS/MGNXJ9+IxQNTbxhfNDzeTNC/OjmI871oF6ABNDXE4GDU FOhShUSMPrfBVQafVLF2auAI/DiUeWF2ddTue4uATO1A9z3gWih+qUeFE g==; X-IronPort-AV: E=McAfee;i="6200,9189,10258"; a="250082436" X-IronPort-AV: E=Sophos;i="5.88,370,1635231600"; d="scan'208";a="250082436" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Feb 2022 04:32:09 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,370,1635231600"; d="scan'208";a="703641745" Received: from mattu-haswell.fi.intel.com ([10.237.72.199]) by orsmga005.jf.intel.com with ESMTP; 15 Feb 2022 04:32:07 -0800 From: Mathias Nyman To: Cc: , Puma Hsu , stable@vger.kernel.org, Mathias Nyman Subject: [PATCH 1/2] xhci: re-initialize the HC during resume if HCE was set Date: Tue, 15 Feb 2022 14:33:19 +0200 Message-Id: <20220215123320.1253947-2-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220215123320.1253947-1-mathias.nyman@linux.intel.com> References: <20220215123320.1253947-1-mathias.nyman@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org From: Puma Hsu When HCE(Host Controller Error) is set, it means an internal error condition has been detected. Software needs to re-initialize the HC, so add this check in xhci resume. Cc: stable@vger.kernel.org Signed-off-by: Puma Hsu Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index dc357cabb265..04ec2de158bf 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -1091,6 +1091,7 @@ int xhci_resume(struct xhci_hcd *xhci, bool hibernated) int retval = 0; bool comp_timer_running = false; bool pending_portevent = false; + bool reinit_xhc = false; if (!hcd->state) return 0; @@ -1107,10 +1108,11 @@ int xhci_resume(struct xhci_hcd *xhci, bool hibernated) set_bit(HCD_FLAG_HW_ACCESSIBLE, &xhci->shared_hcd->flags); spin_lock_irq(&xhci->lock); - if ((xhci->quirks & XHCI_RESET_ON_RESUME) || xhci->broken_suspend) - hibernated = true; - if (!hibernated) { + if (hibernated || xhci->quirks & XHCI_RESET_ON_RESUME || xhci->broken_suspend) + reinit_xhc = true; + + if (!reinit_xhc) { /* * Some controllers might lose power during suspend, so wait * for controller not ready bit to clear, just as in xHC init. @@ -1143,12 +1145,17 @@ int xhci_resume(struct xhci_hcd *xhci, bool hibernated) spin_unlock_irq(&xhci->lock); return -ETIMEDOUT; } - temp = readl(&xhci->op_regs->status); } - /* If restore operation fails, re-initialize the HC during resume */ - if ((temp & STS_SRE) || hibernated) { + temp = readl(&xhci->op_regs->status); + + /* re-initialize the HC on Restore Error, or Host Controller Error */ + if (temp & (STS_SRE | STS_HCE)) { + reinit_xhc = true; + xhci_warn(xhci, "xHC error in resume, USBSTS 0x%x, Reinit\n", temp); + } + if (reinit_xhc) { if ((xhci->quirks & XHCI_COMP_MODE_QUIRK) && !(xhci_all_ports_seen_u0(xhci))) { del_timer_sync(&xhci->comp_mode_recovery_timer); From patchwork Tue Feb 15 12:33:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 543295 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B3E95C433F5 for ; Tue, 15 Feb 2022 12:32:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237348AbiBOMcV (ORCPT ); Tue, 15 Feb 2022 07:32:21 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:38854 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230356AbiBOMcV (ORCPT ); Tue, 15 Feb 2022 07:32:21 -0500 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9DBBA107D33; Tue, 15 Feb 2022 04:32:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1644928331; x=1676464331; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=EM5eCCQn4Q/NVsLKS9eCO+fnF0DKH0tg68IuQmF81NU=; b=EBOCtmKnCvFWwAKntHcI/IzIkuBhZikTYxSBGgIirjM58IhGrmSVt/Rt 1Dvi/O+bnHmC9IXjRH11y2XVP9x4QBW7VvEDpAtUPRW1apd483C66qGCZ DAzSGrAFN87fQxIicuI1f8LKNr7ISPThGZZlWehs/j4ydKE53bCDyDf48 eO+mzTSEx5g/Z1fwkyD3d3/6TlFsu4Vg39Ngjl5sONVuw3Wkn5gE4UE55 pR2U+cGgGhLB25DYyuR7d3rqauie7rwZkib9NvB9ojY2Pao48nl37dV1X 5k/WcDvRIczaXQRPHYZ7fAWWxIuqnGqOB2zsRUSkcB0kDJkeBczCYWqWl A==; X-IronPort-AV: E=McAfee;i="6200,9189,10258"; a="250082443" X-IronPort-AV: E=Sophos;i="5.88,370,1635231600"; d="scan'208";a="250082443" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Feb 2022 04:32:11 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,370,1635231600"; d="scan'208";a="703641765" Received: from mattu-haswell.fi.intel.com ([10.237.72.199]) by orsmga005.jf.intel.com with ESMTP; 15 Feb 2022 04:32:09 -0800 From: Mathias Nyman To: Cc: , Hongyu Xie , stable@vger.kernel.org, Mathias Nyman Subject: [PATCH 2/2] xhci: Prevent futile URB re-submissions due to incorrect return value. Date: Tue, 15 Feb 2022 14:33:20 +0200 Message-Id: <20220215123320.1253947-3-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220215123320.1253947-1-mathias.nyman@linux.intel.com> References: <20220215123320.1253947-1-mathias.nyman@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org From: Hongyu Xie The -ENODEV return value from xhci_check_args() is incorrectly changed to -EINVAL in a couple places before propagated further. xhci_check_args() returns 4 types of value, -ENODEV, -EINVAL, 1 and 0. xhci_urb_enqueue and xhci_check_streams_endpoint return -EINVAL if the return value of xhci_check_args <= 0. This causes problems for example r8152_submit_rx, calling usb_submit_urb in drivers/net/usb/r8152.c. r8152_submit_rx will never get -ENODEV after submiting an urb when xHC is halted because xhci_urb_enqueue returns -EINVAL in the very beginning. [commit message and header edit -Mathias] Fixes: 203a86613fb3 ("xhci: Avoid NULL pointer deref when host dies.") Cc: stable@vger.kernel.org Signed-off-by: Hongyu Xie Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index 04ec2de158bf..2d378543bc3a 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -1611,9 +1611,12 @@ static int xhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flag struct urb_priv *urb_priv; int num_tds; - if (!urb || xhci_check_args(hcd, urb->dev, urb->ep, - true, true, __func__) <= 0) + if (!urb) return -EINVAL; + ret = xhci_check_args(hcd, urb->dev, urb->ep, + true, true, __func__); + if (ret <= 0) + return ret ? ret : -EINVAL; slot_id = urb->dev->slot_id; ep_index = xhci_get_endpoint_index(&urb->ep->desc); @@ -3330,7 +3333,7 @@ static int xhci_check_streams_endpoint(struct xhci_hcd *xhci, return -EINVAL; ret = xhci_check_args(xhci_to_hcd(xhci), udev, ep, 1, true, __func__); if (ret <= 0) - return -EINVAL; + return ret ? ret : -EINVAL; if (usb_ss_max_streams(&ep->ss_ep_comp) == 0) { xhci_warn(xhci, "WARN: SuperSpeed Endpoint Companion" " descriptor for ep 0x%x does not support streams\n",