From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ej1-f45.google.com (mail-ej1-f45.google.com [209.85.218.45]) (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 F1A6D3DD539 for ; Mon, 4 May 2026 23:33:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.45 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777937613; cv=none; b=dXWDnkf6Kniu8SKyUAD+szxsgAeHKpPA6t6icbnDqjB2UYv19dcZnaszZLkOdnlZzcwfp1E0YKo9F89S9X6MNLs1nzPyFwW7CqSYmKg1+F8rfpcLJcNK+FjBN2vGHRCwNRg2Piro/2+EsavivEWZJKJdbUMz/YeKxdcnTJx2eQg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777937613; c=relaxed/simple; bh=bqRrm3879Svv52QqYWelCIlsClvl8DNCQvOp2/0bjWA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=DvUABmeLjGAdrnAC0XxCuUA0yAK+U9sBRTICC7wXHOSEw8FLSPCOHyzQg1f+PLesW3mZgJM5xivDRTCbEOsV83KvGNxd/e86MedsLLVVnJelTJMaIQpBymVDpMnFLdNS0WsOJ6WLV+GHxQudCRffS6zxlIgPUZZKMFNOFpQ6av8= 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=LSR0uRjZ; arc=none smtp.client-ip=209.85.218.45 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="LSR0uRjZ" Received: by mail-ej1-f45.google.com with SMTP id a640c23a62f3a-bc1f0830f44so262812466b.0 for ; Mon, 04 May 2026 16:33:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777937610; x=1778542410; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=2/yyOFGwhnkUdJViXV/uZtVhX9EjoCfTIEWlX83FbgY=; b=LSR0uRjZFUCH5m/JCJFDxatLaXXOBPnyJ55EylZ2AKKdY8d3ZEu9T0eHlxSKKWQ+By PIgvo28z4IKF9f9mV8RFkTVJ3k/xs8TM6vp+bjQTG+lExAmTH5jlfOuW0/+EaGFvIRt4 Wt4B8Hdj4QumJh/MikjGDvr7oGcwv49WzJByB/bxXbCCpcOF9fb5iw77YFER8Lkan7S8 iinMIFGpViI6jvaINp1U242YmoiUJAWmaR7EKnY5byILp4np2bHJvMfJEn1RpwVasqzh 6XZUwMozIFpDngQchq4p4RQMX3/7lXOAVIgyjyp/77hPNm4c8nfgY+dfcF6dyomme7e9 vONQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777937610; x=1778542410; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=2/yyOFGwhnkUdJViXV/uZtVhX9EjoCfTIEWlX83FbgY=; b=Msa4KysLobMDBbDXCscHt7nAqkVlSbVyXt0w69lxhLXZJZQMjmfevoywJqX+6cDBTu iio1gWcD7lpqirQ7vcCNFH/A+6jj+Oy02gF9veC3xvZf9ZUeIhW/0xLZFFc5EqWJBj8C zpLnJ4mNN1Smi7Z9AFKOXzprx7SvpSd4f/fBgFn31SE+t0QJjFJT/gTSD593yLw+TjSV koEyiVOzZWI4SjIx6ChakdPDB0F4cwbrzpvFeuWuXbc3xD/oFYSeW3Ik30z3muEWvxFT mO8z1Qgj2d4VzGF5abO2aJUt9zlCK/+xX58Viz7M0VUs8HQ6eCDDzKIpLjzKVbXrpNYt 8DQw== X-Forwarded-Encrypted: i=1; AFNElJ+khCQ7DX8dE50l8dH5el81dtLy9g2cQs3qLotdtcmYw59cshH2TozUFnphD6xx7Yn3PsOpK+l/xwpRoV8=@vger.kernel.org X-Gm-Message-State: AOJu0YwMl1fVZx1Ex0/fL+cHW0I2kwQO4YrgPVnWwaEzfFhZ35+GW/k0 E3lhUl9Maw8uUitfVRu1U7x2hMqVmvbxT1QBN6BISUHY9fNfwRPtGHjU X-Gm-Gg: AeBDieuqfX91PyJg5QoeBnmB35/K9gacIw+/2Lhk49YLitkcFiYAjkJH4AD50Q9NuRm HUwh4LgwGOICo20pKsgfSlwsrqpPdhqUo+AKPDcgSk8VTfa1KZQ3YHcFByDooMlgicimXcQ9uex lom0pSBeN3dT86bcdI1XRAhelDuJNsRcJn1mXr06sAiUfObGdD0zrOkdY2LKmgYBAnCii1KwxGC eugLZlLV8xYPWPc6jkNPdaCXPL4NF7e/O72apVpRnLizLDhD9dz7a4khfRn6bokxbnodfyunA7Q Mp+eXkS3kjgsFARPkr3U/9BfoHCSziX3qSDisVSPVbGKg6Ncc9L3Iluaq7oiT1fmBAzghCZf9a9 rrsdx4jWTU9mecHc5iHSaBgVNQ6wCvecImv18A6pm2Ly+cYlaOwys4iQUAUjw4zbyPcgzsfMTRg V6BneblUzZGeHlTXGutjliKC9RF97MoAR+SNpJOTvGU7E2Uw9E/u+j603SQPiCSKrC5xPpp+M4M XW/8YUc0B5L8b6zCuxk0fJ4O5+sXf5wdTzNxUc/bry4VSE5Ch2lkOzRwtbDTxu4joQ2 X-Received: by 2002:a17:907:6b89:b0:ba6:79c0:c743 with SMTP id a640c23a62f3a-bc3d1338a8amr86860966b.11.1777937610178; Mon, 04 May 2026 16:33:30 -0700 (PDT) Received: from nick-GTR-Pro.arnhem.chello.nl (2001-1c00-3281-1680-7a55-36ff-fe02-cdba.cable.dynamic.v6.ziggo.nl. [2001:1c00:3281:1680:7a55:36ff:fe02:cdba]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-bbe6aa4d524sm445224366b.26.2026.05.04.16.33.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 May 2026 16:33:28 -0700 (PDT) From: Nicola Lunghi To: mathias.nyman@intel.com, michal.pecio@gmail.com, niklas.neronin@linux.intel.com, gregkh@linuxfoundation.org Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Nicola Lunghi Subject: [PATCH 2/2] usb: xhci: fix CFC sequential scheduling lost on ring drain race Date: Tue, 5 May 2026 01:31:44 +0200 Message-ID: <20260504233143.10242-4-nick83ola@gmail.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260504233143.10242-2-nick83ola@gmail.com> References: <20260504233143.10242-2-nick83ola@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=UTF-8 Content-Transfer-Encoding: 8bit On CFC-capable xHCI controllers, xhci_queue_isoc_tx_prepare() uses next_frame_id for sequential isochronous scheduling only when the endpoint ring is non-empty and the endpoint is running. If all TDs are returned before the next URB is submitted (a ring drain race made more likely by fast TD-skip on xHCI 1.1+ controllers), the condition fails and the URB is scheduled ASAP — potentially many frames ahead of where the stream should continue, creating a gap. Extend the condition to also use next_frame_id when a periodic completion is in progress for the endpoint, covering the transient window where the ring is empty but the stream has not actually stopped. Guard with URB_ISO_ASAP to preserve explicit ASAP scheduling. Link: https://bugzilla.kernel.org/show_bug.cgi?id=220748 Assisted-by: Claude:claude-sonnet-4-6 sparse checkpatch Signed-off-by: Nicola Lunghi --- drivers/usb/host/xhci-ring.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index 03e47db82092..116a2dcd0bb2 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -4308,14 +4308,24 @@ int xhci_queue_isoc_tx_prepare(struct xhci_hcd *xhci, gfp_t mem_flags, */ check_interval(urb, ep_ctx); - /* Calculate the start frame and put it in urb->start_frame. */ - if ((xhci->hcc_params & HCC_CFC) && !list_empty(&ep_ring->td_list)) { - if (GET_EP_CTX_STATE(ep_ctx) == EP_STATE_RUNNING) { - urb->start_frame = xep->next_frame_id; - goto skip_start_over; - } + /* + * Calculate the start frame and put it in urb->start_frame. + * On CFC-capable controllers, use sequential scheduling from + * next_frame_id whenever the stream is running or a completion + * is in progress (ring transiently empty due to drain race). + * Skip this for explicit URB_ISO_ASAP requests. + */ + if ((xhci->hcc_params & HCC_CFC) && + !(urb->transfer_flags & URB_ISO_ASAP) && + (!list_empty(&ep_ring->td_list) || + hcd_periodic_completion_in_progress(xhci_to_hcd(xhci), urb->ep))) { + urb->start_frame = xep->next_frame_id; + goto skip_start_over; } + xhci_dbg(xhci, "isoc: CFC sequential skipped for slot %u ep %u (ring_empty=%d), using ASAP\n", + slot_id, ep_index, list_empty(&ep_ring->td_list)); + start_frame = readl(&xhci->run_regs->microframe_index); start_frame &= 0x3fff; /* -- 2.51.0