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 42B1A256C6F; Mon, 7 Apr 2025 18:11:38 +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=1744049498; cv=none; b=UGLUzik/wETINCZByrBFHUhg3d1wbMJTvTF0w7eHoh/GO+Kdh8oWmvRYTS987bIGzkVfHNKavSx+o6vxsSOsjbZyyWOqMNap8Ndhayyo/hR8ihc+rTXsAMXUzCnEKVg7pny8R6uMy4mpsk6XCRkmhVVPbVxUVzWZv/CRyQrlxCs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744049498; c=relaxed/simple; bh=4fVTnmb0jmz2e7BEnPlNZKpTLF9WLXdX5Icc+2nPd80=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=iMuyqUCI1cRrVJJhIflKrV4akcs1zrP3VA2Ae4bhhrw4MDWrwb4Tie4iOsSLh/rtCm9YJp7iSbpzfd31zAH/r6Dixthdv2urzNqZvEv5sml50mMu9PZjJtnUq2m1IgFDNmsgP77z7yw2AjNvLXqaL/QV17Pk4ETqSGZZzhcGveY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Pv4aRmvw; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Pv4aRmvw" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3A396C4CEE7; Mon, 7 Apr 2025 18:11:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744049498; bh=4fVTnmb0jmz2e7BEnPlNZKpTLF9WLXdX5Icc+2nPd80=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Pv4aRmvwoQqy3HcJHTts4us2ytnRWjyEwnLjG+V6l2ycjRwYK1hHoyBSwTAzF4/Io 9NyuZd3Mkj6sKh9dtWqTl6++RYdCvyooc/tP56RH8+KodJCDZrPdqqB9YSUb8AAwZ8 Rb2v4OWJ5TSFwgvvLevpFGn30v6VbbgRtC/aF713lsMW03eiGhoV4Jc3+Y8kk0d+rP 4CXaFvMUcDLK3ZozUoVm0yUpZP5pkXzPmgE78WXlG8lMbeyqcuuq1gA7DEvNEbXedS fdsH6xilfcqWCOBwt8iet1bMhPM9uI33DU7+zKPhNSIIVQkghR3VbXSBjSg4rE0IyO mh767Mdvn3UVg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Michal Pecio , Mathias Nyman , Greg Kroah-Hartman , Sasha Levin , mathias.nyman@intel.com, linux-usb@vger.kernel.org Subject: [PATCH AUTOSEL 6.14 18/31] usb: xhci: Avoid Stop Endpoint retry loop if the endpoint seems Running Date: Mon, 7 Apr 2025 14:10:34 -0400 Message-Id: <20250407181054.3177479-18-sashal@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250407181054.3177479-1-sashal@kernel.org> References: <20250407181054.3177479-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.14.1 Content-Transfer-Encoding: 8bit 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 d3dd1ecaf6208..076c4c397ca4a 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -1198,16 +1198,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