From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.52 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796379612; b=EU9nkEBq9zQJ+ttEbk0ivJu79z5Tph7IIlbirH3psh4LNfSmRdLIvYXPB8EOOSOEqESv n1bJMA42VcFabWeD0leFr2d9tvKHN1vZ3Mn7mG6i9woexCWmjd8+ClMPC2xmOxILJ0bkY FJMR8ULVSTlO+viI1xuMB75Jde6BcdmzFaKetZABCIFJVWeT47skbecrLSnZGfF3YKnJD /6pJGtUkFrx1EUKlIU8wy3tqnN7VQFfksFGGiPaAonBDROQyF87MhyhvpQPfWgll3UqDG GIkm4IjQWaIZ+BWGhr9kF/ivgYRFmExbxh/S4+RcRsUkDruYEbSiiYSxi7t39Pz/+EQ== 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=a4XuCTPUQN5SamJ63sidML4EAkO504Iz1hFlegLnogGOEksCU6r2dVdAui70QUZ7OvJL UtJxypyi4Or26JlPvy2XmR6Ei2fWy/fwYD7+RoU0ggdAzYIWC91BaplJnVvtX1DRzX4L6 Xem5WTxm5PtzeuRhacR7SYwlruuJncDjsaE3qNw0YZis7mYIYZFw0yquSHfX44w3Jii9Y tQnyOclOveEH0E/RIo5wuqGnAIBZTsD1EwMaczzewFMIryJ49pWhLwBEkbV87H2tEKRQv g2uFhMNrLnHql0AwllzGyTJhfVWUeTVwtEyFHzCTIDc1X8wF/xd+5qi0356LpwWMsEg== 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.52 Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) (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 BBF7B606A330 for ; Fri, 4 Dec 2026 10:20:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org BBF7B606A330 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-f52.google.com with SMTP id 5b1f17b1804b1-4bb606491faso2652865e9.3 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=oryD6rjtiEzUgcAtYZ4zc+Kd6J3BCjFm1+HSE46NpXOUhy2WsDFm+cCWY5B9ffe1QG UkMs3lYXn5BZ5lJBhvRjI1pA35rMHd90OaV1cR1uEEqi3VnNINtloxd4FBqCewHQ0uqT 2DlB3KHBXNaakcBsLeKy+cvnmXwPLOmENUM08NjZefaZ/LRvPpipsFb0KTXAe533zmTb z2OsW8p+7B6dQjExp9ehFM2GjKdc7X/3d6CeY1Pm54El+/FGKWlDC/DrKAG93ByEgWhn WyFAjykQSZjgPS0jNGJ31g/1/SwFqc138j4UcE1xmTNcRTRecgQpAlF3qMoxGtCb5lcG IgOw== X-Forwarded-Encrypted: i=1; AL+hErHwE/CN8YKM/3zMR053JTQN/yQ8gFJkN9tKQ71/na3FY1eHuHJHumggKTQmQCpl+p3ub+GXiPZviHY=@vger.kernel.org X-Gm-Message-State: APuU4Z8U3MCqMwu9sWw3B6pz0nQwez7HTq25UUwOETh2P+PVaAzglvV/ TV5Ne2f7xfvBYYokKi7zM9dPyA8RT6pAPZE+1fAkhFxtYTwg7bFohwVA X-Gm-Gg: AZFdTZf8Fj1kQlQ2TKPxys6dmTpKJyNCLwdaBhk5zbx8piJUY/5X85HyzHhErJkf5Na Yr6D/zwGM9P/fZ+KuVT+F1+s2DHjL1LUUDs7M6WXr2pgejIQ0vpKzbZml3+OXOilUyZMhTTCku6 s6jMPxzHmFjfrWTlskebt6E3gNs1Soq9uOo54l1iZu5+QwURAL97Y68dSmpzU8pkVLlc5PGbTTl p3KFWK6pU5/6Emy51T23nDxMibk8aXCbUot1x0nk0Cx5/VdWhYPl0+jKdCewE2PCQuzke1SnWaZ 2JnoSUl7VWn80ZS/TsfUT2Ttw2nB7ix/JBdwPi/IH2rkeQaDXR4bc1fwDj1gShSWODpfzBw4Pb5 VYB+sHHKZVWFzX47Ek+C4zEipFEEiYgINjiZWtl0ptFK5VJX+h7I4m4fnjk2uzClh8Le+ySZCC/ HSxpWSNLGq6tF58Jy0fLqh5HyooxgAccMtN+l9xyWBfe/tjvOjobkleruFKarVSA1aEuVUK6bOK dyjH7XRkYft0bh4N0dTViFXxIGMGrrIz/A9kkauiTUpGydr/3fMcz2E5IbrD8udLPXVjWL6ZApT xkq2UNYkzJ/LL+7X8M3gcrqppvD2SmD3lX/aSg== 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-usb@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 > >