All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mathias Nyman <mathias.nyman@linux.intel.com>
To: <gregkh@linuxfoundation.org>
Cc: <linux-usb@vger.kernel.org>, Chien Kun Niu <rickyniu@google.com>,
	stable@vger.kernel.org,
	Mathias Nyman <mathias.nyman@linux.intel.com>
Subject: [PATCH 03/10] xhci: Give back URB under lock in xhci_urb_dequeue()
Date: Fri, 27 Nov 2026 14:17:48 +0200	[thread overview]
Message-ID: <20261127121755.281420-4-mathias.nyman@linux.intel.com> (raw)
In-Reply-To: <20261127121755.281420-1-mathias.nyman@linux.intel.com>

From: Chien Kun Niu <rickyniu@google.com>

Before commit 36dc01657b49 ("usb: host: xhci: Support running urb
giveback in tasklet context") set HCD_BH, usb_hcd_giveback_urb() ran
urb->complete() synchronously, so xHCI had to drop xhci->lock before
giving back an URB. That commit updated xhci_giveback_urb_in_irq() to
keep xhci->lock held across usb_hcd_giveback_urb(), covering normal
completions, xhci_process_cancelled_tds(), and xhci_hc_died(), while
the open-coded err_giveback path in xhci_urb_dequeue() was missed.

Dropping xhci->lock between usb_hcd_unlink_urb_from_ep() and
usb_hcd_giveback_urb() breaks per-endpoint giveback serialization: a
concurrent xhci_urb_dequeue() or xhci_hc_died() can acquire xhci->lock
and queue a later URB onto bh->head ahead of this one, completing URBs
out of order. When spinlocks disable interrupts, unlocking first also
causes a redundant IRQ restore/save bounce into bh->lock, and without
an IRQ-safe bh->lock it exposed task-context unlinks to a same-CPU
deadlock.

Move usb_hcd_giveback_urb() before spin_unlock_irqrestore(&xhci->lock,
flags) in err_giveback to match xhci_giveback_urb_in_irq().

Fixes: 36dc01657b49 ("usb: host: xhci: Support running urb giveback in tasklet context")
Cc: stable@vger.kernel.org
Signed-off-by: Chien Kun Niu <rickyniu@google.com>
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
---
 drivers/usb/host/xhci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index b3df40f22d55..d55c8b7058ce 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -1891,8 +1891,8 @@ static int xhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
 	if (urb_priv)
 		xhci_urb_free_priv(urb_priv);
 	usb_hcd_unlink_urb_from_ep(hcd, urb);
-	spin_unlock_irqrestore(&xhci->lock, flags);
 	usb_hcd_giveback_urb(hcd, urb, -ESHUTDOWN);
+	spin_unlock_irqrestore(&xhci->lock, flags);
 	return ret;
 }
 
-- 
2.43.0


  parent reply	other threads:[~2026-11-27 12:18 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-27 12:17 [PATCH 00/10] xhci fixes for usb-linus Mathias Nyman
2026-11-27 12:17 ` [PATCH 01/10] usb: xhci: Fix ep0 maxpacket update on enabled slots Mathias Nyman
2026-11-27 12:17 ` [PATCH 02/10] xhci: check for halted host before accessing virt devices in xhci_check_args() Mathias Nyman
2026-11-30  9:08   ` Michal Pecio
2026-11-30 15:14     ` Alan Stern
2026-12-01 11:23     ` Mathias Nyman
2026-11-27 12:17 ` Mathias Nyman [this message]
2026-11-27 12:17 ` [PATCH 04/10] xhci: Fix reporting incorrect supported speeds in roothub BOS descriptor Mathias Nyman
2026-11-27 12:17 ` [PATCH 05/10] xhci: sideband: avoid use-after-free of stale virt device pointer Mathias Nyman
2026-11-27 12:17 ` [PATCH 06/10] xhci: sideband: check virt device under xhci lock when stopping endpoints Mathias Nyman
2026-11-27 12:17 ` [PATCH 07/10] usb: xhci: tegra: Fix missing semi-colon Mathias Nyman
2026-11-27 12:17 ` [PATCH 08/10] usb: xhci: Demote isoch buffer overrun message to debug level Mathias Nyman
2026-11-27 12:17 ` [PATCH 09/10] xhci: fix use-after-free for errors mid TD on empty halted rings Mathias Nyman
2026-11-30  7:13   ` Michal Pecio
2026-11-27 12:17 ` [PATCH 10/10] xhci: fix NULL pointer dereference of rhub_port in xhci_urb_enqueue() Mathias Nyman
2026-11-27 12:28 ` [PATCH 00/10] xhci fixes for usb-linus sashiko-bot

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=20261127121755.281420-4-mathias.nyman@linux.intel.com \
    --to=mathias.nyman@linux.intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=rickyniu@google.com \
    --cc=stable@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.