From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5E4E72AE96; Tue, 29 Apr 2025 17:58:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745949488; cv=none; b=S+X9Vuoo9V97k19wqk2Ov3YKP3n8nyFtfEfynI/mr31qYJgvph8TGlO9yv99o/pLLiNQ5jAgtXZSIpboDQ8X7L0SBysYSU7p6uT1F1QxS9Jlt7qSPLTxHJuOjPF8eW1zaRzVWTT6Owg0uj0WJMX1kInoFjBFq9a4cENct+hdt6g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745949488; c=relaxed/simple; bh=Qw26Oz5uopgj9MYpqzMmMhSGzJbvA++hKlhk0iR3hUM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZaF7JJYcoA83Kjd/Yu13G9tvZmNrHCOOex+kvtybJvg1g/5o/hJ37KkHqd6WSNFTYGLlRBKs0QQ11Enop/RBevLYkD5v5gX1Pq/emHnivEF68VqNJpylCrpGgza0uha0Hei/rULScAbe9t7P7r8y3XwoVsT0BVHMbOU/8oxb094= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=HZrCuHOG; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="HZrCuHOG" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E5EF0C4CEE3; Tue, 29 Apr 2025 17:58:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1745949488; bh=Qw26Oz5uopgj9MYpqzMmMhSGzJbvA++hKlhk0iR3hUM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HZrCuHOGQcAWEoEpCmJ+EZVaXb8F4evg/ivbECvWtdn5WN8xda/vIanu7scSY/2iU N3VCWHVMyTL6fCLDdxEiPyNYulxK6r5BmD1dZLKeaSAnpsuhA2SRaDzZIYiXWe+UOy cFsqPM1ftNNL18Xz/VRu1zRJgkujiCvKBjq/dZPQ= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Michal Pecio , Mathias Nyman , Sasha Levin Subject: [PATCH 5.15 334/373] usb: xhci: Avoid Stop Endpoint retry loop if the endpoint seems Running Date: Tue, 29 Apr 2025 18:43:31 +0200 Message-ID: <20250429161136.869931099@linuxfoundation.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250429161123.119104857@linuxfoundation.org> References: <20250429161123.119104857@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Michal Pecio [ Upstream commit 28a76fcc4c85dd39633fb96edb643c91820133e3 ] Nothing prevents a broken HC from claiming that an endpoint is Running and repeatedly rejecting Stop Endpoint with Context State Error. Avoid infinite retries and give back cancelled TDs. No such cases known so far, but HCs have bugs. Signed-off-by: Michal Pecio Signed-off-by: Mathias Nyman Link: https://lore.kernel.org/r/20250311154551.4035726-4-mathias.nyman@linux.intel.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/usb/host/xhci-ring.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index 64bf50ea62a49..cd94b0a4e0211 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -1183,16 +1183,19 @@ static void xhci_handle_cmd_stop_ep(struct xhci_hcd *xhci, int slot_id, * Stopped state, but it will soon change to Running. * * Assume this bug on unexpected Stop Endpoint failures. - * Keep retrying until the EP starts and stops again, on - * chips where this is known to help. Wait for 100ms. + * Keep retrying until the EP starts and stops again. */ - if (time_is_before_jiffies(ep->stop_time + msecs_to_jiffies(100))) - break; fallthrough; case EP_STATE_RUNNING: /* Race, HW handled stop ep cmd before ep was running */ xhci_dbg(xhci, "Stop ep completion ctx error, ctx_state %d\n", GET_EP_CTX_STATE(ep_ctx)); + /* + * Don't retry forever if we guessed wrong or a defective HC never starts + * the EP or says 'Running' but fails the command. We must give back TDs. + */ + if (time_is_before_jiffies(ep->stop_time + msecs_to_jiffies(100))) + break; command = xhci_alloc_command(xhci, false, GFP_ATOMIC); if (!command) -- 2.39.5