From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 35AEC4C62; Mon, 23 Jun 2025 21:18:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750713536; cv=none; b=Jxpk/fIXBWxm8DAg2o5EMZb1xhE+bsMJtr8KVAd0yrK8gKRNnDGitS9ea0wfZcIpgxeTbS3QR3S57X8eVxNwgDBVy7Fy3KJLtAhVwG9zT/A+S/bfebZXRUzOFd4bv5fGbJj5uJTgrqy4wbYzttrKqW3xJQ2ULKuG5wADa4WEvTg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750713536; c=relaxed/simple; bh=JU43upnr4MzMJzT52veZN8nG+MeISef27o5uYnivFQc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fPJlmDfL85IA6HZGPK/j84jymS3tDWiTM7pl3F5eDcV1MdXTojnxwjgett9GBvjrOcx0uQiaa7xbXBboJJgeeBKxfsjdayxJgjxAFFOgHD/MqCyQ4esymur5ZFXv/00ZoI4kkLx44LU6qg3hiKSk44gXiqDS1x2UB9zau4WhRig= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=Uww/6bG5; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="Uww/6bG5" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BFE62C4CEEA; Mon, 23 Jun 2025 21:18:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1750713536; bh=JU43upnr4MzMJzT52veZN8nG+MeISef27o5uYnivFQc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Uww/6bG5BM2D7x0WM7jpaLuLiw5If+DCPIvAQuU4dzweGFm46bPs1OeFlnVPhjsbn y8evBPLJ+6M6fGxMAKFzMVCXHXYVtIducRAcKm6H0Skaceg1TFrJV1N6FnPqP2+lAh V/3jepLq2TOf3Skyqo5ecZEdN+2RICIT5fcDvC2o= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, stable , Mathias Nyman Subject: [PATCH 5.10 151/355] usb: Flush altsetting 0 endpoints before reinitializating them after reset. Date: Mon, 23 Jun 2025 15:05:52 +0200 Message-ID: <20250623130631.243987109@linuxfoundation.org> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250623130626.716971725@linuxfoundation.org> References: <20250623130626.716971725@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: Mathias Nyman commit 89bb3dc13ac29a563f4e4c555e422882f64742bd upstream. usb core avoids sending a Set-Interface altsetting 0 request after device reset, and instead relies on calling usb_disable_interface() and usb_enable_interface() to flush and reset host-side of those endpoints. xHCI hosts allocate and set up endpoint ring buffers and host_ep->hcpriv during usb_hcd_alloc_bandwidth() callback, which in this case is called before flushing the endpoint in usb_disable_interface(). Call usb_disable_interface() before usb_hcd_alloc_bandwidth() to ensure URBs are flushed before new ring buffers for the endpoints are allocated. Otherwise host driver will attempt to find and remove old stale URBs from a freshly allocated new ringbuffer. Cc: stable Fixes: 4fe0387afa89 ("USB: don't send Set-Interface after reset") Signed-off-by: Mathias Nyman Link: https://lore.kernel.org/r/20250514132520.225345-1-mathias.nyman@linux.intel.com Signed-off-by: Greg Kroah-Hartman --- drivers/usb/core/hub.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) --- a/drivers/usb/core/hub.c +++ b/drivers/usb/core/hub.c @@ -6014,6 +6014,7 @@ static int usb_reset_and_verify_device(s struct usb_hub *parent_hub; struct usb_hcd *hcd = bus_to_hcd(udev->bus); struct usb_device_descriptor descriptor; + struct usb_interface *intf; struct usb_host_bos *bos; int i, j, ret = 0; int port1 = udev->portnum; @@ -6074,6 +6075,18 @@ static int usb_reset_and_verify_device(s if (!udev->actconfig) goto done; + /* + * Some devices can't handle setting default altsetting 0 with a + * Set-Interface request. Disable host-side endpoints of those + * interfaces here. Enable and reset them back after host has set + * its internal endpoint structures during usb_hcd_alloc_bandwith() + */ + for (i = 0; i < udev->actconfig->desc.bNumInterfaces; i++) { + intf = udev->actconfig->interface[i]; + if (intf->cur_altsetting->desc.bAlternateSetting == 0) + usb_disable_interface(udev, intf, true); + } + mutex_lock(hcd->bandwidth_mutex); ret = usb_hcd_alloc_bandwidth(udev, udev->actconfig, NULL, NULL); if (ret < 0) { @@ -6105,12 +6118,11 @@ static int usb_reset_and_verify_device(s */ for (i = 0; i < udev->actconfig->desc.bNumInterfaces; i++) { struct usb_host_config *config = udev->actconfig; - struct usb_interface *intf = config->interface[i]; struct usb_interface_descriptor *desc; + intf = config->interface[i]; desc = &intf->cur_altsetting->desc; if (desc->bAlternateSetting == 0) { - usb_disable_interface(udev, intf, true); usb_enable_interface(udev, intf, true); ret = 0; } else {