[PATCH 1/2] usb: core: hcd: Disable IRQs when taking bh->lock
From: Chien Kun Niu
Date: Thu Nov 12 2026 - 23:55:40 EST
usb_hcd_giveback_urb() can be called with local interrupts enabled,
but it acquires bh->lock with plain spin_lock(). bh->lock is also
taken in hardirq context by HCD interrupt handlers and in BH context
by usb_giveback_urb_bh().
If an interrupt arrives on the same CPU while usb_hcd_giveback_urb()
holds bh->lock with IRQs enabled, it can deadlock on bh->lock in
usb_hcd_irq(), or in usb_giveback_urb_bh() on IRQ exit if the BH work
was already queued. We hit the latter during reboot when usbnet
unlinked RX URBs on a halted xHCI controller:
Call trace:
queued_spin_lock_slowpath
_raw_spin_lock_irq
usb_giveback_urb_bh
process_scheduled_works
bh_worker
workqueue_softirq_action
__do_softirq
irq_exit_rcu
el1_interrupt
_raw_spin_lock
usb_hcd_giveback_urb
xhci_urb_dequeue
unlink1
usb_hcd_unlink_urb
usb_unlink_urb
unlink_urbs [usbnet]
Use spin_lock_irqsave() and spin_unlock_irqrestore() when taking
bh->lock in usb_hcd_giveback_urb() to prevent same-CPU hardirq and
softirq re-entrancy.
Fixes: 94dfd7edfd5c ("USB: HCD: support giveback of URB in tasklet context")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Chien Kun Niu <rickyniu@xxxxxxxxxx>
---
drivers/usb/core/hcd.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index 8e8a5f59b..7bb25e7c4 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -1731,6 +1731,7 @@ static void usb_giveback_urb_bh(struct work_struct *work)
void usb_hcd_giveback_urb(struct usb_hcd *hcd, struct urb *urb, int status)
{
struct giveback_urb_bh *bh;
+ unsigned long flags;
bool running;
/* pass status to BH via unlinked */
@@ -1747,10 +1748,10 @@ void usb_hcd_giveback_urb(struct usb_hcd *hcd, struct urb *urb, int status)
else
bh = &hcd->low_prio_bh;
- spin_lock(&bh->lock);
+ spin_lock_irqsave(&bh->lock, flags);
list_add_tail(&urb->urb_list, &bh->head);
running = bh->running;
- spin_unlock(&bh->lock);
+ spin_unlock_irqrestore(&bh->lock, flags);
if (running)
;
--
2.56.0.611.g1030f0b940-goog