From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.46]) (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 4DB454457C9 for ; Tue, 4 Aug 2026 10:03:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.46 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785837802; cv=none; b=sWSGKiNeh/IiYBWeFk4QzpiTD9p0lY9lx/HC1AF1bITOCw0SHCvpBjMFt57IgBUySKkQDR383vwdQ5jwXxTtsjElau9OWweGCnGUD4kaUzbMTCOxcmKc9Bvr8ZKXeN+ERG4FmCDGP2v3A2sVw9SEv8eiF4IVyX7jIaPSmrJmX3A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785837802; c=relaxed/simple; bh=MU350OP6kB1rEDUkj+DOlrGzj1MoS0IisNveTm2dqus=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=bmSB6Xzj9nT7NsI9MU/ygY8XeoZsZm/McKoUa3bkY0PSyl11zmA+DucigpbVrVeTqci0uhFQU/Y8itta/J57+ZTIE3TcmzY9YTtYh0sDuP0N9Pk/kTgCgc5GGJn9nKijo7vG3jqkUH6tb/a9tcgGZL1hjA7/Mr5DGNfHqCMUsHM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=kDmfPnO2; arc=none smtp.client-ip=209.85.221.46 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.b="kDmfPnO2" Received: by mail-wr1-f46.google.com with SMTP id ffacd0b85a97d-47f6609c657so2192148f8f.2 for ; Tue, 04 Aug 2026 03:03:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785837798; x=1786442598; 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=mKNdCd7BfihSdT/4/OO50sBOOdXqsgqCXHHpY928Dwk=; b=kDmfPnO2ovj/FFsT4TngDNbAfrHWNcx9h7a1sB6WZAMAbEsmDAb8OFvXqxpcceXAJ0 nvJ/rDu2MEMEHT/TRdcVgW963VpwftwcVDlnlSzl83oK1+s8WEBtFiHsjdKSBvDfOq3L VKQZDZUhXimT1CTaz/ZREW/HKsiq8AxYiQlq1TroWAoYOZRzTv8GAtM5HsDu3VvvGOKC 1FQynDqaSlSepFl3Ux1jvCa2gH9hdUChGm8/DL6TU2fJoB0R54o3POx3+pjrlmZPSfxi je+2zfs0DQQYYsbz0wOtGPf0KlhAQFuJzkhivHws3VyO8S3Q13FjwTkPsHkHeeTUb4BE 1AUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785837798; x=1786442598; 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=mKNdCd7BfihSdT/4/OO50sBOOdXqsgqCXHHpY928Dwk=; b=QlFCAlTD2zx4sU0o6xCJ3KC1mqK9Ja8WQ7Qgb1QZZhqgw5hRxLU01H9jasOb/NseIH zMVrqRvuDxG96Tnx7ZG6h0eU1pInsvBDm4CRnkKQtssFaFuyphbQ34ybDGA6l/qHMrse Dz9YA575+oGf4JXoRRbtoVZ3brc+df+tws084ccNM2iDVi0vceNULgnNF3OfBHpn9f++ ZQqZY+xQQG/5a08uR/jTYy25LI2QmrCRJrGcnLV5wlNQ8HPPIKNRB5MtpBvh65GYMbAz 6GdLcCPNKPRAgVQnSdvn0yCMzep/pcINWA0DjwieWL3djGHA9fHvOk9A7/mKMoSJeHnZ tXYQ== X-Forwarded-Encrypted: i=1; AHgh+Ro2TIwEw2IDSJr+IDHNcTF4zfhts/k6RoR2Bu2kJn60w/RPHoru0A0Sla5i//krEdwSHGEo4xlYf1hrnl8=@vger.kernel.org X-Gm-Message-State: AOJu0Yz5JfDjrMKX911+Dju0MI/f3syQX1eaXiV2sAQ/W5QZ5PYolysI vp74dYMVoDdTWuAK1Jm6rX0SpR1/nixbhvprp6FXmthVGBLGW4k/Suv/YImUGA== X-Gm-Gg: AR+sD12rgUaH0p0a5B+sVKvpH8ZI7/oe5jNSLIDf9HvVEvMNhVIbSCyOGPNkX1Tz6M3 sHOpWGLOWexAISK5tKOu6Q9yGOgtyqxvSY0vYCz3kHmM4XKuDVicu+oF1ag8U7fjx0flzCKsGO4 r3QozpYZ8Y9QLXNsGVLSN3voQCO9e7hKMPeyX+IA0/vFiSDKQoQGSpHrHc76Zh5F1E6PHhg0hh3 3KZmwtoXq4dUyHf7YUhyoDa2ISRfVshsdE6pHUkDzRloELI91nQbmhT7VFP29IZm4H4xsA8Pn9I Yak6JiLY7b9v6ku8xi2EyuwoUR1fFDsT6DRqV8QeEXFzAU5rUykXj6FqKr/ibh8lmorFGTwWv0B m01ZXVX0zEm0+hk/s8c2UfpdC3iGSZsWO+7adV3yKUlNaI6Y6yMCWrkkZiTktjKYReufj4QluxD BoV6VQdHcLteps+nYMFKVvez7fw0GKwrLW1IPQDxu8YxhpzMxFhKqVoZVer3VL/OZhgCocxEyE X-Received: by 2002:a05:6000:4693:b0:45e:73eb:5119 with SMTP id ffacd0b85a97d-47fd72d4819mr26233578f8f.22.1785837798381; Tue, 04 Aug 2026 03:03:18 -0700 (PDT) Received: from foxbook (bgt135.neoplus.adsl.tpnet.pl. [83.28.83.135]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-47fd42d91bfsm44715531f8f.15.2026.08.04.03.03.17 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Tue, 04 Aug 2026 03:03:18 -0700 (PDT) Date: Tue, 4 Aug 2026 12:03:14 +0200 From: Michal Pecio To: Mathias Nyman , Greg Kroah-Hartman Cc: Bart Nagel , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/5] usb: xhci: Guarantee URB giveback on Ring Underrun/Overrun Message-ID: <20260804120314.0a3203e7.michal.pecio@gmail.com> In-Reply-To: <20260804120110.01bda0e2.michal.pecio@gmail.com> References: <20260804120110.01bda0e2.michal.pecio@gmail.com> 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-Transfer-Encoding: 7bit In this case we know that the xHC has released ownership of all missed TDs, we only don't know which were missed and which were queued later. URBs are queued atomically, so we can safely give back all TDs of the currently executing URB. Unlike the previous policy, this does actually ensure that the class driver will learn about the error and won't see all of its URBs still in progress when all TDs are missed on xHCI 1.0. Signed-off-by: Michal Pecio --- drivers/usb/host/xhci-ring.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index 38a0f895553a..8eed56b72c30 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -2630,6 +2630,7 @@ static int handle_tx_event(struct xhci_hcd *xhci, unsigned int slot_id; int ep_index; struct xhci_td *td = NULL; + struct urb *missed_urb = NULL; dma_addr_t ep_trb_dma; union xhci_trb *ep_trb; int status = -EINPROGRESS; @@ -2849,26 +2850,31 @@ static int handle_tx_event(struct xhci_hcd *xhci, return 0; /* - * TD was missed, skip it. Core already initialized frame->status - * to -EXDEV and frame->actual_length to 0, nothing more to do. + * If skip flag is still set at xrun, we are on xHCI 1.0 and our TRB + * pointer is zero again. All missed TDs can be given back, but we + * don't know which were missed and which were queued after the xrun + * occurred. We can safely give back the first pending URB. */ - xhci_dequeue_td(xhci, td, ep_ring, 0); + if (ring_xrun_event) { + if (!missed_urb) + missed_urb = td->urb; - if (!list_empty(&ep_ring->td_list)) { - if (ring_xrun_event) { - /* - * If we are here, we are on xHCI 1.0 host with no - * idea how many TDs were missed or where the xrun - * occurred. New TDs may have been added after the - * xrun, so skip only one TD to be safe. - */ - xhci_dbg(xhci, "Skipped one TD for slot %u ep %u", + if (td->urb != missed_urb) { + xhci_dbg(xhci, "Skipped one URB for slot %u ep %u", slot_id, ep_index); return 0; } - continue; } + /* + * TD was missed, skip it. Core already initialized frame->status + * to -EXDEV and frame->actual_length to 0, nothing more to do. + */ + xhci_dequeue_td(xhci, td, ep_ring, 0); + + if (!list_empty(&ep_ring->td_list)) + continue; + xhci_dbg(xhci, "All TDs skipped for slot %u ep %u. Clear skip flag.\n", slot_id, ep_index); ep->skip = false; -- 2.48.1