From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.48 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796379612; b=3RZ+jnC5F1Lejngu5e6oeLty0LGLt2MD46d6xf/LPIUvhUC+oH45sqxVQWe9zQ3xTrj1 j4Bmc53cglQwtA0Vjc12KBGs7hUrzPKopK0eV7wXfaG0ZcbeSSge18tRNf7b7ReOjAA54 DTyXkiaUzJQ7zkNBC2USmL/ffJEPSjWPYyBiGNtaJWpZWlvucJLuSRIMPGt98NMN0Fh22 G3I8NPfANxiuVt9hyecHSIcR9YXWmLG2vCVljAsqroP2cGu3GVLFDOsmGzl+6+a+94MXO x7i5+J6SwpewH++LomBMvSyFfF76hMfW1RIQilhq47BDmczSO42QC3U6jfG6O7ImvvQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796379612; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type:Content-Transfer-Encoding; bh=jxYGq4KT43HpPAswpc+Bt9oGzlOuhiakJRGmR07EPCY=; b=5ZTc2Bpci0ZMxXkMxx3ZugI/TvrLkvnauEYhnCgwltHY68Bboh8A8Kcw/ZsCR5gMuJ33 sXL9EU6KA3MLjvj1oMZvGRyTepnSNOVBLjQWumEsCoUdZ2X0qldWB47B8gq36x5YQ0Gpn w4eYPqfnOzZamu1wwWvi9BbOb0GdavFbmyz90haWTd/a7YxwuGp7XKk8pC0GTyoYkfCJD o5BSO3JOth/wbOxipfvjU7S9Tv88fthi7DbpaVaZSHmG5dIyL/FWQi6Kbd555hZ4BSydL +Fer1/yUlUhtL/4fGSt+bDj+cvhKGvsG+2v17Fx2IK3gOoAmCJc1w/an429t1fsed5g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=fVGVVSxh; arc=none smtp.remote-ip=209.85.128.48 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B1FB2606A322 for ; Fri, 4 Dec 2026 10:20:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B1FB2606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=fVGVVSxh Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-4bb702a7548so3141445e9.1 for ; Fri, 04 Dec 2026 02:20:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796379610; x=1796984410; darn=vger.kernel.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=jxYGq4KT43HpPAswpc+Bt9oGzlOuhiakJRGmR07EPCY=; b=fVGVVSxh+qvylWWp25gTLVV1jMD7LBZDEO+60q4NTOoFlWRL03Jk5LYYmNL/2QAjc5 EX8n7d9mHakb+dz5d5DMNybEw8OlmAfW73XCzkqhkQsv2qvRxhUEjAm2wzI6Q+mddUza 1sPmfN6KXZh7yiV15g+7PAyVb7ZY6RtI2H52x3diN5UXXwIDek+A4h5pGFA+itV6fk8L ogHEWpBfE4xrTiZ8UbcCne350Z3o5sxCe2mukWTtEX2p3OEV6v8qwwx+CZtDHjGDCwYm ZndnoqohftzbPMO0a7zWO5Lxp4qMdQIPRGsh1hZH9i4hQBtBEG2jcG6AU7hsYqfpzeMl X3Bw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796379610; x=1796984410; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=jxYGq4KT43HpPAswpc+Bt9oGzlOuhiakJRGmR07EPCY=; b=wkrDyxR95dwjYxCp1wCUckzAr3UsnoJKF1fF0b/sFkdRJ9rO2N56klrOPeYnqEhK68 ab0XY1b6pPnbbM98MwJu4lRhvbROd2OiZxfbzdkRDkAIYYCXXr65l46XPpyjv7ybd0ny MdAtlMyyTCAC/LPTLaGKe2hOkOxZZ36CSuYArYn+xJ+K9tSy2dIiFx8dB79Xg1zpeHYO kCDF4YJlOlO5tuEhY0x4oEJzpenGh2h8ri9VUOabZs89ZBaNh4jmflxFQ7s+bFwOnm7c IYWQjeWfal9sLFKLVRx8H5ZpXDpiQzKEnyLtPAV5K4VOA6pXOq5ojn3A/jtdk7PGgWBV biiQ== X-Forwarded-Encrypted: i=1; AL+hErGUx9roThCGYKIEtLFy2lRueO8ycNaAnWW3Pi7YUBFduKjgWtJTg337do5mOjIl26HqsHF+LmsXqjHN270=@vger.kernel.org X-Gm-Message-State: APuU4Z+Qua3/HVZBSAcJMZvv8KPAIFZTGHltSHrvbt2h6AAGb7maecbp 3ETac1qo4IV44mxzBxx02Vo1pP6fxMMT1uI+JvTYiianBt4x/QcIHLLD X-Gm-Gg: AZFdTZfoDwdmncDwey3YmhZorbeL4zqV9hg4abz6CKp6CU+m3+18atAz9CvkctIvyj6 hYMmAJMWyd+l+tun32Nv1BkKtjgdLd3sbSB8hL1OCIkmbEvsBb64VSllDLxSoSXr0wUwKyPmEwD sLTxzbbX7KK2LDAFFMuVi0EOqFX/Ku/0ArfnQFTjo3K13B2Oh/GSHgSq2KNhBA7yfXkOs1Q7hjk UfQYPSyWPiNWaILt/Wn+wRclrCyhy0CZiX7WjFccG+x0y/iYkUBjOmll7ZCwT9tQgm01MVZqheW 8VyAlCm01MCh82EpqJ5XN1Ko6lop073bqS6rfzqY33PLrB3ZPJ+AQ+prDTR4AHk1HYVQhd3dEnx CkWCNCr8Hyvwpid/Eig8JybhMVKWNrQLq+2e8GPAAYunjoiGSQC3+gyYbgOwlUfLQs/I15mNS3O YPdTOOSZACMmqnDSgDosoGhFjaNZfmukxzFL4OMz7tPG4Am+l04namqTsPsFNKJLbAbElqJR+h4 G6rzcGk67T3SXJ/IXVOyHjUx9AdJoX5MylwS06nb3CPkLKpv34izAgVlfrYSWDMMKWrUKhFCJgT NJmtvrfSfaqpj1kHx0edOtCn0NivFdyox7lVzA== X-Received: by 2002:a05:600d:82e1:b0:4bb:6a5a:7824 with SMTP id 5b1f17b1804b1-4bbeb8eece0mr28761835e9.30.1796379609865; Fri, 04 Dec 2026 02:20:09 -0800 (PST) Received: from foxbook (bfj60.neoplus.adsl.tpnet.pl. [83.28.47.60]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bbeb6f0085sm32875495e9.4.2026.12.04.02.20.08 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Fri, 04 Dec 2026 02:20:09 -0800 (PST) Date: Fri, 4 Dec 2026 11:20:11 +0100 From: Michal Pecio To: Pengfei Lv Cc: Alan Stern , gregkh@linuxfoundation.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, xuhaiyang5@hisilicon.com, xuetao09@huawei.com, caiyadong@huawei.com, suzhuangluan@hisilicon.com Subject: Re: [PATCH v4] usb: core: hub: Re-guess ep0 maxpacket size after reset Message-ID: <20261204112011.663f9028.michal.pecio@gmail.com> In-Reply-To: References: <20261109093935.2634235-1-lvpengfei20@huawei.com> <20261110033038.2882473-1-lvpengfei20@huawei.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Mon, 16 Nov 2026 13:56:08 -0500, Alan Stern wrote: > On Tue, Nov 10, 2026 at 11:30:38AM +0800, Pengfei Lv wrote: > > Per USB 2.0 spec section 5.5.3, the ep0 maxpacket size is fixed for > > all device speeds except full-speed devices, where it can be 8, 16, > > 32, or 64 bytes and can only be determined by reading the device > > descriptor. During initial enumeration the USB core guesses 64 bytes > > for full-speed devices; after reading the descriptor, the real value > > is stored in udev->ep0.desc.wMaxPacketSize and applied to hardware by > > usb_ep0_reinit(). > > > > Commit ff33299ec8bb ("USB: core: Fix race by not overwriting > > udev->descriptor in hub_port_init()") guarded the ep0 maxpacket guess > > block with "if (initial)", so on the reset path the guess is skipped > > and the host keeps using the value from the previous enumeration. If > > a buggy full-speed device responds with one 8-byte packet and NAKs > > all further polling, the HC doesn't recognize a short transfer but > > keeps polling for the rest of the descriptor till unlink, and the > > device cannot be re-enumerated. > > > > This was observed in production on a 6.6 LTS kernel with a full-speed > > USB banking token (bMaxPacketSize0 = 8) in a virtual-machine USB > > passthrough scenario; the reset re-enumeration hangs 100% of the time > > after the VM issues USBDEVFS_RESET. The device is not strictly > > compliant (it should continue answering IN tokens), but this class of > > USB banking token is widely deployed in enterprise environments, and > > the regression breaks a configuration that previously worked. > > > > The 18-byte GET_DESCRIPTOR that runs after SET_ADDRESS (wLength=18) > > is unaffected: the device sends the full 18 bytes as 8 + 8 + 2, and > > the final 2-byte packet is always a short packet regardless of > > maxpacket. This is why the device completes initial enumeration yet > > hangs on reset re-enumeration. > > > > Fix this by removing the "if (initial)" guard so that the ep0 > > maxpacket size is re-guessed on every reset, and by calling > > usb_ep0_reinit() right after the maxpacket size is re-guessed so that > > the re-guessed value is applied to hardware before the GET_DESCRIPTOR > > data stage. > > > > Fixes: ff33299ec8bb ("USB: core: Fix race by not overwriting udev->descriptor in hub_port_init()") > > Cc: stable@vger.kernel.org > > Signed-off-by: Pengfei Lv > > > > --- > > > > v4: Per further review by Alan Stern, move the usb_ep0_reinit() call > > to right after the ep0 maxpacket re-guess block. Each layer does the > > right thing on its own side. > > > > v3: https://lore.kernel.org/linux-usb/20261109093935.2634235-1-lvpengfei20@huawei.com/ > > --- > > Pending other comments by Michal Pecio: > > Acked-by: Alan Stern FYI, the xHCI bug Sashiko complained about should be fixed by e214556a001a in usb-linus, so this patch is expected to work now. I gave both patches a quick test and they don't seem to trigger anything weird, though I would still suggest testing them on any hardware and LTS kernels you care about, just in case. Regards, Michal > > drivers/usb/core/hub.c | 48 +++++++++++++++++++++--------------------- > > 1 file changed, 24 insertions(+), 24 deletions(-) > > > > diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c > > index 199d3f535a89..e3d8ee3271cb 100644 > > --- a/drivers/usb/core/hub.c > > +++ b/drivers/usb/core/hub.c > > @@ -4969,33 +4969,33 @@ hub_port_init(struct usb_hub *hub, struct usb_device *udev, int port1, > > } > > oldspeed = udev->speed; > > > > - if (initial) { > > - /* USB 2.0 section 5.5.3 talks about ep0 maxpacket ... > > - * it's fixed size except for full speed devices. > > + /* USB 2.0 section 5.5.3 talks about ep0 maxpacket ... > > + * it's fixed size except for full speed devices. > > + */ > > + switch (udev->speed) { > > + case USB_SPEED_SUPER_PLUS: > > + case USB_SPEED_SUPER: > > + udev->ep0.desc.wMaxPacketSize = cpu_to_le16(512); > > + break; > > + case USB_SPEED_HIGH: /* fixed at 64 */ > > + udev->ep0.desc.wMaxPacketSize = cpu_to_le16(64); > > + break; > > + case USB_SPEED_FULL: /* 8, 16, 32, or 64 */ > > + /* to determine the ep0 maxpacket size, try to read > > + * the device descriptor to get bMaxPacketSize0 and > > + * then correct our initial guess. > > */ > > - switch (udev->speed) { > > - case USB_SPEED_SUPER_PLUS: > > - case USB_SPEED_SUPER: > > - udev->ep0.desc.wMaxPacketSize = cpu_to_le16(512); > > - break; > > - case USB_SPEED_HIGH: /* fixed at 64 */ > > - udev->ep0.desc.wMaxPacketSize = cpu_to_le16(64); > > - break; > > - case USB_SPEED_FULL: /* 8, 16, 32, or 64 */ > > - /* to determine the ep0 maxpacket size, try to read > > - * the device descriptor to get bMaxPacketSize0 and > > - * then correct our initial guess. > > - */ > > - udev->ep0.desc.wMaxPacketSize = cpu_to_le16(64); > > - break; > > - case USB_SPEED_LOW: /* fixed at 8 */ > > - udev->ep0.desc.wMaxPacketSize = cpu_to_le16(8); > > - break; > > - default: > > - goto fail; > > - } > > + udev->ep0.desc.wMaxPacketSize = cpu_to_le16(64); > > + break; > > + case USB_SPEED_LOW: /* fixed at 8 */ > > + udev->ep0.desc.wMaxPacketSize = cpu_to_le16(8); > > + break; > > + default: > > + goto fail; > > } > > > > + usb_ep0_reinit(udev); > > + > > speed = usb_speed_string(udev->speed); > > > > /* > > -- > > 2.34.1 > >