From: Chien Kun Niu <rickyniu@google.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Mathias Nyman <mathias.nyman@intel.com>
Cc: Alan Stern <stern@rowland.harvard.edu>,
linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
Chien Kun Niu <rickyniu@google.com>
Subject: [PATCH 1/2] usb: core: hcd: Disable IRQs when taking bh->lock
Date: Fri, 13 Nov 2026 04:02:36 +0000 [thread overview]
Message-ID: <20261113041948.1280304-2-rickyniu@google.com> (raw)
In-Reply-To: <20261113041948.1280304-1-rickyniu@google.com>
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@vger.kernel.org
Signed-off-by: Chien Kun Niu <rickyniu@google.com>
---
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
prev parent reply other threads:[~2026-11-13 4:20 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-13 4:02 [PATCH 0/2] usb: Fix giveback_urb_bh deadlock on URB dequeue Chien Kun Niu
2026-11-13 4:02 ` [PATCH 2/2] xhci: Give back URB under lock in xhci_urb_dequeue() Chien Kun Niu
2026-11-13 4:02 ` Chien Kun Niu [this message]
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=20261113041948.1280304-2-rickyniu@google.com \
--to=rickyniu@google.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=mathias.nyman@intel.com \
--cc=stern@rowland.harvard.edu \
/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
all inboxes | Powered by JetHome®