[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <f6cdf21a-642f-458c-85c1-0c2e1526f539@rowland.harvard.edu>
Date: Fri, 15 Aug 2025 21:51:39 -0400
From: Alan Stern <stern@...land.harvard.edu>
To: Yunseong Kim <ysk@...lloc.com>
Cc: linux-usb@...r.kernel.org, gregkh@...uxfoundation.org,
Andrey Konovalov <andreyknvl@...gle.com>,
Shuah Khan <skhan@...uxfoundation.org>,
Thomas Gleixner <tglx@...utronix.de>,
Sebastian Andrzej Siewior <bigeasy@...utronix.de>,
Clark Williams <clrkwllms@...nel.org>,
Steven Rostedt <rostedt@...dmis.org>,
linux-rt-users@...r.kernel.org, linux-kernel@...r.kernel.org,
syzkaller@...glegroups.com
Subject: Re: [BUG] usbip: vhci: Sleeping function called from invalid context
in vhci_urb_enqueue on PREEMPT_RT
On Sat, Aug 16, 2025 at 10:29:34AM +0900, Yunseong Kim wrote:
> While testing a PREEMPT_RT enabled kernel (based on v6.17.0-rc1),
> I encountered a "BUG: sleeping function called from invalid context"
> error originating from the USB/IP VHCI driver.
>
> On PREEMPT_RT configurations, standard spin_lock() calls are replaced by
> rt_spin_lock(). Since rt_spin_lock() may sleep when contended, it must not
> be called from an atomic context (e.g., with interrupts disabled).
>
> The issue occurs within the vhci_urb_enqueue function This function
> explicitly disables local interrupts using local_irq_disable() immediately
> before calling usb_hcd_giveback_urb(), adhering to HCD requirements.
...
> This error reported after this work:
> It occurs after going through the code below:
>
> static int vhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flags)
> {
>
> ...
>
> no_need_unlink:
> spin_unlock_irqrestore(&vhci->lock, flags);
> if (!ret) {
> /* usb_hcd_giveback_urb() should be called with
> * irqs disabled
> */
> local_irq_disable(); // <--- Entering atomic context (IRQs disabled)
> usb_hcd_giveback_urb(hcd, urb, urb->status);
> local_irq_enable();
> }
> return ret;
> }
>
> static void mon_bus_complete(struct mon_bus *mbus, struct urb *urb, int status)
> {
> ...
> spin_lock_irqsave(&mbus->lock, flags);
^
------------------^
> ...
> }
>
> When called with interrupts disabled, usb_hcd_giveback_urb() eventually
> leads to mon_complete() in the USB monitoring, if usbmon is enabled,
> via __usb_hcd_giveback_urb().
>
> mon_complete() attempts to acquire a lock via spin_lock(), observed in the
> trace within the inlined mon_bus_complete.
Look again. mon_bus_complete() calls spin_lock_irqsave(), not
spin_lock().
Is the kernel tree that you are using different from Linus's tree?
Alan Stern
Powered by blists - more mailing lists