FAILED: patch "[PATCH] USB: gadget: dummy-hcd: Fix locking bug in RT-enabled kernels" failed to apply to 5.4-stable tree
Subsystems (2)
[email protected]
maintainerThe patch below does not apply to the 5.4-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-5.4.y
git checkout FETCH_HEAD
git cherry-pick -x 8d63c83d8eb922f6c316320f50c82fa88d099bea
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2025091724-yeast-sublet-dc69@gregkh' --subject-prefix 'PATCH 5.4.y' HEAD^..
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 8d63c83d8eb922f6c316320f50c82fa88d099bea Mon Sep 17 00:00:00 2001
From: Alan Stern <[email protected]>
Date: Mon, 25 Aug 2025 12:00:22 -0400
Subject: [PATCH] USB: gadget: dummy-hcd: Fix locking bug in RT-enabled kernels
Yunseong Kim and the syzbot fuzzer both reported a problem in RT-enabled kernels caused by the way dummy-hcd mixes interrupt management and spin-locking. The pattern was:
local_irq_save(flags); spin_lock(&dum->lock); ... spin_unlock(&dum->lock); ... // calls usb_gadget_giveback_request() local_irq_restore(flags);
The code was written this way because usb_gadget_giveback_request() needs to be called with interrupts disabled and the private lock not held.
While this pattern works fine in non-RT kernels, it's not good when RT is enabled. RT kernels handle spinlocks much like mutexes; in particular, spin_lock() may sleep. But sleeping is not allowed while local interrupts are disabled.
To fix the problem, rewrite the code to conform to the pattern used elsewhere in dummy-hcd and other UDC drivers:
spin_lock_irqsave(&dum->lock, flags); ... spin_unlock(&dum->lock); usb_gadget_giveback_request(...); spin_lock(&dum->lock); ... spin_unlock_irqrestore(&dum->lock, flags);
This approach satisfies the RT requirements.
drivers/usb/gadget/udc/dummy_hcd.c +4 -4
@@ -765,8 +765,7 @@ static int dummy_dequeue(struct usb_ep *_ep, struct usb_request *_req)if (!dum->driver)return -ESHUTDOWN ; -local_irq_save (flags); -spin_lock (&dum->lock); +spin_lock_irqsave (&dum->lock, flags);list_for_each_entry (iter, &ep->queue, queue) {if (&iter->req != _req)continue ;
@@ -776,15 +775,16 @@ static int dummy_dequeue(struct usb_ep *_ep, struct usb_request *_req) retval =0 ;break ; } -spin_unlock (&dum->lock);if (retval ==0 ) {dev_dbg (udc_dev (dum),"dequeued req %p from %s, len %d buf %p\n" , req, _ep->name, _req->length, _req->buf); +spin_unlock (&dum->lock);usb_gadget_giveback_request (_ep, _req); +spin_lock (&dum->lock); } -local_irq_restore (flags); +spin_unlock_irqrestore (&dum->lock, flags);return retval; }
Sasha Levin
maintainerPATCH 1/2 usb: gadget: dummy_hcd: remove usage of list iterator past the loop body
From: Jakob Koschel <[email protected]>
[ Upstream commit 7975f080d3557725160a878b1a64339043ba3d91 ]
To move the list iterator variable into the list_for_each_entry_*() macro in the future it should be avoided to use the list iterator variable after the loop body.
To *never* use the list iterator variable after the loop it was concluded to use a separate iterator variable [1].
Stable-dep-of: 8d63c83d8eb9 ("USB: gadget: dummy-hcd: Fix locking bug in RT-enabled kernels")
--- drivers/usb/gadget/udc/dummy_hcd.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
drivers/usb/gadget/udc/dummy_hcd.c +9 -8
@@ -748,7 +748,7 @@ static int dummy_dequeue(struct usb_ep *_ep, struct usb_request *_req)struct dummy *dum;int retval = -EINVAL ;unsigned long flags; -struct dummy_request *req =NULL ; +struct dummy_request *req =NULL , *iter;if (!_ep || !_req)return retval;
@@ -760,13 +760,14 @@ static int dummy_dequeue(struct usb_ep *_ep, struct usb_request *_req)local_irq_save (flags);spin_lock (&dum->lock); -list_for_each_entry (req, &ep->queue, queue) { -if (&req->req == _req) { -list_del_init (&req->queue); - _req->status = -ECONNRESET ; - retval =0 ; -break ; - } +list_for_each_entry (iter, &ep->queue, queue) { +if (&iter->req != _req) +continue ; +list_del_init (&iter->queue); + _req->status = -ECONNRESET ; + req = iter; + retval =0 ; +break ; }spin_unlock (&dum->lock);
Signature · 1 line
2.51.0
Sasha Levin
maintainerPATCH 2/2 USB: gadget: dummy-hcd: Fix locking bug in RT-enabled kernels
From: Alan Stern <[email protected]>
[ Upstream commit 8d63c83d8eb922f6c316320f50c82fa88d099bea ]
Yunseong Kim and the syzbot fuzzer both reported a problem in RT-enabled kernels caused by the way dummy-hcd mixes interrupt management and spin-locking. The pattern was:
local_irq_save(flags); spin_lock(&dum->lock); ... spin_unlock(&dum->lock); ... // calls usb_gadget_giveback_request() local_irq_restore(flags);
The code was written this way because usb_gadget_giveback_request() needs to be called with interrupts disabled and the private lock not held.
While this pattern works fine in non-RT kernels, it's not good when RT is enabled. RT kernels handle spinlocks much like mutexes; in particular, spin_lock() may sleep. But sleeping is not allowed while local interrupts are disabled.
To fix the problem, rewrite the code to conform to the pattern used elsewhere in dummy-hcd and other UDC drivers:
spin_lock_irqsave(&dum->lock, flags); ... spin_unlock(&dum->lock); usb_gadget_giveback_request(...); spin_lock(&dum->lock); ... spin_unlock_irqrestore(&dum->lock, flags);
This approach satisfies the RT requirements.
--- drivers/usb/gadget/udc/dummy_hcd.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/usb/gadget/udc/dummy_hcd.c +4 -4
@@ -758,8 +758,7 @@ static int dummy_dequeue(struct usb_ep *_ep, struct usb_request *_req)if (!dum->driver)return -ESHUTDOWN ; -local_irq_save (flags); -spin_lock (&dum->lock); +spin_lock_irqsave (&dum->lock, flags);list_for_each_entry (iter, &ep->queue, queue) {if (&iter->req != _req)continue ;
@@ -769,15 +768,16 @@ static int dummy_dequeue(struct usb_ep *_ep, struct usb_request *_req) retval =0 ;break ; } -spin_unlock (&dum->lock);if (retval ==0 ) {dev_dbg (udc_dev (dum),"dequeued req %p from %s, len %d buf %p\n" , req, _ep->name, _req->length, _req->buf); +spin_unlock (&dum->lock);usb_gadget_giveback_request (_ep, _req); +spin_lock (&dum->lock); } -local_irq_restore (flags); +spin_unlock_irqrestore (&dum->lock, flags);return retval; }
Signature · 1 line
2.51.0