From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qv1-f51.google.com (mail-qv1-f51.google.com [209.85.219.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D3F3D37188F for ; Sun, 15 Mar 2026 18:24:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773599048; cv=none; b=qQ3hLLmrHJLrLgMmngQGwNyVGXmMfhSQqDoMhzZ4BhmJL7HEAOgU1QuJAaFgA2BQK7K5kVyyeddYcGNaymqoXK0L/QYg+b1z/ldq9mtlQR2EhyHBpTbc96odJUWkhg/55suMoPD3R6fy0R81SadiPme+XuEA/HydY0JXE6QYxpE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773599048; c=relaxed/simple; bh=xhknvPSZEJamjwfC6E7xqNbP5Lcu+fQ9sgFybkiurc8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=JSgY7fuk5/T+YIPFDp1pxc79V0tZGfLdYSnlwUmtxeI1Qayd2P9QH1lLcl0tB01RQKUT0vTd4cADMIkKEarpeIl3a0hZMyzZbDCc2TZI1PoqDc5/zHhTeuJ6v1uTyxygaMMLzRgkGnsm2lA81D7HVSE7PeafaPgpA4UQ0qQJ2+4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=rowland.harvard.edu; spf=fail smtp.mailfrom=g.harvard.edu; dkim=pass (2048-bit key) header.d=rowland.harvard.edu header.i=@rowland.harvard.edu header.b=iB7wCJpB; arc=none smtp.client-ip=209.85.219.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=rowland.harvard.edu Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=g.harvard.edu Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rowland.harvard.edu header.i=@rowland.harvard.edu header.b="iB7wCJpB" Received: by mail-qv1-f51.google.com with SMTP id 6a1803df08f44-89c50491cf9so4031806d6.0 for ; Sun, 15 Mar 2026 11:24:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rowland.harvard.edu; s=google; t=1773599046; x=1774203846; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=TIW5TAlAjLsCnvPOmmDoGfbXCgAP9kJ4BYzswK9qnNk=; b=iB7wCJpBp0vgUONT5uPhslTJDd7610rnDMV/x0fOoMuNtQwAaIB3WZbXZHCnbYgcFl 0V+I8SxCHwa1BsaCNg6L1JlwP5hzB1otg5eUKp+qrmVlBrdJ0BANH7wAKEdAF+AvC3fE ncIyxShC/GDY9Nq3URcplqSj3pkrx+TJDB0Q+KIDFOu5zZgy8me11HILZnmvJKQ9g9tD ufYkOiHR/cSSXdrDyXLLd+D7odR+UFXySiJMn/55EIrBzQ4It06JWpwyYCzEkRmH8wh/ UR9BkDj4aocTn4Dd0yhsghk/xa+1inJXZ963uCAMMFVwB93QKDC53beutYQm6nLybec9 Wnfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773599046; x=1774203846; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TIW5TAlAjLsCnvPOmmDoGfbXCgAP9kJ4BYzswK9qnNk=; b=oGGKkIMJa9qpsYMiDq/xVjp/BxGXliLPWBlhhYuwlyaRS2AwjreSD8MD10t5bmELa+ uPiEUX5HAZFW+HnIzHEP7La2jVo2YLaa84ZPCdNyNQs+qqik1a1xut2UzA/TB1oYn++B PBttaGRn0HnCfOCJjl4nl2cvy5HI39QtFbfEIxDIM92+m/V/GNtPqNHFXFyyZ2d2hJcL KLkcNxeb3tlYCcOeiXyFNtw/oOXjzieSkHjOJzAZB2C07jTLH9PCY7ydV3agLepOY0yu G3GusP7JKBcAUUQHkC/ovtv+yiHA+yGBPg95C41yFXazKAT9Be5JEIpmv3IsMUo998mp 48WQ== X-Forwarded-Encrypted: i=1; AJvYcCVVWHhqA9uQTo75dvax09l8RCzHKsKA8lcG8Z33h7PYjYc4fUA8d5etP9PsrTnphmEKcggR01icV3/dj0E=@vger.kernel.org X-Gm-Message-State: AOJu0YxLZFhfqzv5LFHeo59jkUDd8J3JPJa6sZqiHosfVGlfb3+fmZiS qXm3XQJ82b039DU1n4tQIjuYI/IT5cjVVqcLypTy5Z2tvBhaXEzF1EO9t0y85YFvTA== X-Gm-Gg: ATEYQzxFTTkG8Ibcws4bZGGqYD8mR1BcF9UZQsu/vfuxfxLfFV/1IHE8jculC6df1Id ZsFvqvtNy4Daxq4/gZbwXtnra37blck9mTqlHFAo37np9Ihz6iJTBBfw0Elb2L/dWs7JaEUEAiR TjVrY64K6wufNl7uYD0HfYSLQuKTVkUPzgbFsTXswGOQXDHI2bQWAFDjlk9yiwcEwTHl5ywvowe 1n/KplS/96okwopJz48LVx5xjdGdftMbl/ViYoFO8OGKsGPGWiFgpjiywQFjDOm2M+H84Auappj rcA4Lz0Lg29gRnyShtQ25kJ+dI3AKdzyy9uHV/y0RbGYxOMx5DZn9Jr8Qrwb5rlOy99dkdthApk 0gyNKhrLLdoTFZ2KV9LBDshdXsF0GUzth+XkJGYxYHxHStEVq15lab1mJiUr4FNqujc2gpjzUF+ UiJ4fXGLGbHWi7zLpKl4HoaCON X-Received: by 2002:a05:6214:e4c:b0:899:fa7f:7155 with SMTP id 6a1803df08f44-89a81d44d25mr169761946d6.5.1773599045763; Sun, 15 Mar 2026 11:24:05 -0700 (PDT) Received: from rowland.harvard.edu ([2601:19b:d01:d210::687c]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-89c5246e77asm3689836d6.27.2026.03.15.11.24.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Mar 2026 11:24:04 -0700 (PDT) Date: Sun, 15 Mar 2026 14:24:02 -0400 From: Alan Stern To: Sebastian Urban Cc: gregkh@linuxfoundation.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] usb: gadget: dummy_hcd: fix premature URB completion when ZLP follows partial transfer Message-ID: References: <9f2c403b-5955-4e6b-a356-330cebead7ed@rowland.harvard.edu> <20260315151045.1155850-1-surban@surban.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260315151045.1155850-1-surban@surban.net> On Sun, Mar 15, 2026 at 04:10:45PM +0100, Sebastian Urban wrote: > When a gadget request is only partially transferred in transfer() > because the per-frame bandwidth budget is exhausted, the loop advances > to the next queued request. If that next request is a zero-length > packet (ZLP), len evaluates to zero and the code takes the > unlikely(len == 0) path, which sets is_short = 1. This bypasses the > bandwidth guard ("limit < ep->ep.maxpacket && limit < len") that > lives in the else branch and would otherwise break out of the loop for > non-zero requests. The is_short path then completes the URB before all > data from the first request has been transferred. > > Reproducer (bulk IN, high speed): > > Device side (FunctionFS with Linux AIO): > 1. Queue a 65024-byte write via io_submit (127 * 512, i.e. a > multiple of the HS bulk max packet size). > 2. Immediately queue a zero-length write (ZLP) via io_submit. > > Host side: > 3. Submit a 65536-byte bulk IN URB. > > Expected: URB completes with actual_length = 65024. > Actual: URB completes with actual_length = 53248, losing 11776 > bytes that leak into subsequent URBs. > > At high speed the per-frame budget is 53248 bytes (512 * 13 * 8). > The 65024-byte request exhausts this budget after 53248 bytes, leaving > the request incomplete (req->req.actual < req->req.length). Neither > the request nor the URB is finished, and rescan is 0, so the loop > advances to the ZLP. For the ZLP, dev_len = 0, so len = min(12288, 0) > = 0, taking the unlikely(len == 0) path and setting is_short = 1. > The is_short handler then sets *status = 0, completing the URB with > only 53248 of the expected 65024 bytes. > > Fix this by breaking out of the loop when the current request has > remaining data (req->req.actual < req->req.length). The request > resumes on the next timer tick, preserving correct data ordering. > > Signed-off-by: Sebastian Urban > --- Reviewed-by: Alan Stern > Changes in v2: > - Rewrote commit message to describe the specific ZLP-after-partial-transfer > scenario rather than overstating the general case (Alan Stern). > - Added reproducer and step-by-step code path walkthrough. > > drivers/usb/gadget/udc/dummy_hcd.c | 6 ++++++ > 1 file changed, 6 insertions(+) > > diff --git a/drivers/usb/gadget/udc/dummy_hcd.c b/drivers/usb/gadget/udc/dummy_hcd.c > index 1cefca660..0eead4a85 100644 > --- a/drivers/usb/gadget/udc/dummy_hcd.c > +++ b/drivers/usb/gadget/udc/dummy_hcd.c > @@ -1534,6 +1534,12 @@ static int transfer(struct dummy_hcd *dum_hcd, struct urb *urb, > /* rescan to continue with any other queued i/o */ > if (rescan) > goto top; > + > + /* request not fully transferred; stop iterating to > + * preserve data ordering across queued requests. > + */ > + if (req->req.actual < req->req.length) > + break; > } > return sent; > } > -- > 2.53.0