asahi.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: Hector Martin <marcan@marcan.st>
To: Bin Meng <bmeng.cn@gmail.com>, Marek Vasut <marex@denx.de>
Cc: Mark Kettenis <kettenis@openbsd.org>, Neal Gompa <neal@gompa.dev>,
	 u-boot@lists.denx.de, asahi@lists.linux.dev,
	 Hector Martin <marcan@marcan.st>
Subject: [PATCH v2 3/8] usb: xhci: Allow context state errors when halting an endpoint
Date: Sun, 29 Oct 2023 15:37:40 +0900	[thread overview]
Message-ID: <20231029-usb-fixes-1-v2-3-623533f6316e@marcan.st> (raw)
In-Reply-To: <20231029-usb-fixes-1-v2-0-623533f6316e@marcan.st>

There is a race where an endpoint may halt by itself while we are trying
to halt it, which results in a context state error. See xHCI 4.6.9 which
mentions this case.

This also avoids BUGging when we attempt to stop an endpoint which was
already stopped to begin with, which is probably a bug elsewhere but
not a good reason to crash.

Signed-off-by: Hector Martin <marcan@marcan.st>
---
 drivers/usb/host/xhci-ring.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index d21e76e0bdb6..e02a6e300c4f 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -545,6 +545,7 @@ static void abort_td(struct usb_device *udev, int ep_index)
 	struct xhci_ctrl *ctrl = xhci_get_ctrl(udev);
 	struct xhci_ring *ring =  ctrl->devs[udev->slot_id]->eps[ep_index].ring;
 	union xhci_trb *event;
+	xhci_comp_code comp;
 	trb_type type;
 	u64 addr;
 	u32 field;
@@ -573,10 +574,11 @@ static void abort_td(struct usb_device *udev, int ep_index)
 		printf("abort_td: Expected a TRB_TRANSFER TRB first\n");
 	}
 
+	comp = GET_COMP_CODE(le32_to_cpu(event->event_cmd.status));
 	BUG_ON(type != TRB_COMPLETION ||
 		TRB_TO_SLOT_ID(le32_to_cpu(event->event_cmd.flags))
-		!= udev->slot_id || GET_COMP_CODE(le32_to_cpu(
-		event->event_cmd.status)) != COMP_SUCCESS);
+		!= udev->slot_id || (comp != COMP_SUCCESS && comp
+		!= COMP_CTX_STATE));
 	xhci_acknowledge_event(ctrl);
 
 	addr = xhci_trb_virt_to_dma(ring->enq_seg,

-- 
2.41.0


  parent reply	other threads:[~2023-10-29  6:38 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-29  6:37 [PATCH v2 0/8] USB fixes: xHCI error handling Hector Martin
2023-10-29  6:37 ` [PATCH v2 1/8] usb: xhci: Guard all calls to xhci_wait_for_event Hector Martin
2023-10-29 14:32   ` Marek Vasut
2023-10-29  6:37 ` [PATCH v2 2/8] usb: xhci: Better error handling in abort_td() Hector Martin
2023-10-29 14:33   ` Marek Vasut
2023-10-29  6:37 ` Hector Martin [this message]
2023-10-29 14:34   ` [PATCH v2 3/8] usb: xhci: Allow context state errors when halting an endpoint Marek Vasut
2023-10-29  6:37 ` [PATCH v2 4/8] usb: xhci: Recover from halted bulk endpoints Hector Martin
2023-10-29 14:35   ` Marek Vasut
2023-10-29  6:37 ` [PATCH v2 5/8] usb: xhci: Fail on attempt to queue TRBs to a halted endpoint Hector Martin
2023-10-29 14:35   ` Marek Vasut
2023-10-29  6:37 ` [PATCH v2 6/8] usb: xhci: Do not panic on event timeouts Hector Martin
2023-10-29 14:35   ` Marek Vasut
2023-10-29  6:37 ` [PATCH v2 7/8] usb: xhci: Fix DMA address calculation in queue_trb Hector Martin
2023-10-29 14:35   ` Marek Vasut
2023-10-29  6:37 ` [PATCH v2 8/8] usb: xhci: Add more debugging Hector Martin
2023-10-29 14:36   ` Marek Vasut
2023-10-29 16:21 ` [PATCH v2 0/8] USB fixes: xHCI error handling Neal Gompa

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231029-usb-fixes-1-v2-3-623533f6316e@marcan.st \
    --to=marcan@marcan.st \
    --cc=asahi@lists.linux.dev \
    --cc=bmeng.cn@gmail.com \
    --cc=kettenis@openbsd.org \
    --cc=marex@denx.de \
    --cc=neal@gompa.dev \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).