* [PATCH usb-next v4] usb: gadget: pxa27x_udc: fix request completion locking on PREEMPT_RT
@ 2026-12-05 23:22 Xinsheng Zhu
2026-12-05 23:36 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Xinsheng Zhu @ 2026-12-05 23:22 UTC (permalink / raw)
To: linux-usb
Cc: nkapron, gregkh, daniel, haojian.zhuang, robert.jarzmik, bigeasy,
clrkwllms, rostedt, linux-arm-kernel, linux-rt-devel
req_done() explicitly disables local interrupts around
usb_gadget_giveback_request(). The completion callback may acquire
spinlocks, which become sleeping locks on PREEMPT_RT and cannot be
acquired with interrupts disabled.
Use spin_unlock() and spin_lock() around the giveback, following
the locking pattern introduced in commit 8d63c83d8eb9
("USB: gadget: dummy-hcd: Fix locking bug in RT-enabled kernels")
and commit 09bf21bf5249 ("usbip: Fix locking bug in RT-enabled kernels").
This keeps interrupts disabled during the giveback on non-RT kernels
without explicitly disabling them on PREEMPT_RT.
Require ep->lock to be held when calling req_done(),
ep_end_in_req() and ep_end_out_req(). Acquire the lock in the
previously unlocked EP0 completion paths to protect both request
removal and endpoint statistics updates.
pxa_ep_dequeue() drops ep->lock after finding the request but
before removing it from the queue. A concurrent completion may
retire and free the request in this window. Keep ep->lock held
across the request lookup and removal.
Remove the now unnecessary pflags parameter from the completion
helpers, update their kernel-doc and add lockdep_assert_held()
to req_done() to check its locking contract.
Fixes: 5e23e90f3388 ("USB: pxa27x_udc: Fix deadlocks on request queueing")
Signed-off-by: Xinsheng Zhu <xinsheng.zhu.ny@gmail.com>
---
Changes in v4:
- Require ep->lock to be held on entry to req_done(),
ep_end_in_req() and ep_end_out_req().
- Move lock acquisition to the previously unlocked EP0 completion
paths to also protect endpoint statistics updates.
- Remove the locked parameter from the completion helpers.
- Add lockdep_assert_held() to req_done().
- Update the corresponding kernel-doc and call sites.
v3: https://lore.kernel.org/r/20261205214738.93588-1-xinsheng.zhu.ny@gmail.com
drivers/usb/gadget/udc/pxa27x_udc.c | 84 ++++++++++++++---------------
1 file changed, 42 insertions(+), 42 deletions(-)
diff --git a/drivers/usb/gadget/udc/pxa27x_udc.c b/drivers/usb/gadget/udc/pxa27x_udc.c
index 9fd079cb65c6..32285d66393e 100644
--- a/drivers/usb/gadget/udc/pxa27x_udc.c
+++ b/drivers/usb/gadget/udc/pxa27x_udc.c
@@ -650,16 +650,15 @@ static void ep_del_request(struct pxa_ep *ep, struct pxa27x_request *req)
* @ep: pxa physical endpoint
* @req: pxa request
* @status: usb request status sent to gadget API
- * @pflags: flags of previous spinlock_irq_save() or NULL if no lock held
*
- * Context: ep->lock held if flags not NULL, else ep->lock released
+ * Context: ep->lock held with spin_lock_irqsave().
*
- * Retire a pxa27x usb request. Endpoint must be locked.
+ * Retire a pxa27x usb request. Temporarily release the endpoint
+ * lock around the completion callback and return with it held.
*/
-static void req_done(struct pxa_ep *ep, struct pxa27x_request *req, int status,
- unsigned long *pflags)
+static void req_done(struct pxa_ep *ep, struct pxa27x_request *req, int status)
{
- unsigned long flags;
+ lockdep_assert_held(&ep->lock);
ep_del_request(ep, req);
if (likely(req->req.status == -EINPROGRESS))
@@ -672,48 +671,46 @@ static void req_done(struct pxa_ep *ep, struct pxa27x_request *req, int status,
&req->req, status,
req->req.actual, req->req.length);
- if (pflags)
- spin_unlock_irqrestore(&ep->lock, *pflags);
- local_irq_save(flags);
+ spin_unlock(&ep->lock);
usb_gadget_giveback_request(&req->udc_usb_ep->usb_ep, &req->req);
- local_irq_restore(flags);
- if (pflags)
- spin_lock_irqsave(&ep->lock, *pflags);
+ spin_lock(&ep->lock);
}
/**
* ep_end_out_req - Ends endpoint OUT request
* @ep: physical endpoint
* @req: pxa request
- * @pflags: flags of previous spinlock_irq_save() or NULL if no lock held
*
- * Context: ep->lock held or released (see req_done())
+ * Context: ep->lock held with spin_lock_irqsave().
*
* Ends endpoint OUT request (completes usb request).
*/
-static void ep_end_out_req(struct pxa_ep *ep, struct pxa27x_request *req,
- unsigned long *pflags)
+static void ep_end_out_req(struct pxa_ep *ep, struct pxa27x_request *req)
{
inc_ep_stats_reqs(ep, !USB_DIR_IN);
- req_done(ep, req, 0, pflags);
+ req_done(ep, req, 0);
}
/**
* ep0_end_out_req - Ends control endpoint OUT request (ends data stage)
* @ep: physical endpoint
* @req: pxa request
- * @pflags: flags of previous spinlock_irq_save() or NULL if no lock held
*
- * Context: ep->lock held or released (see req_done())
+ * Context: ep->lock not held.
*
* Ends control endpoint OUT request (completes usb request), and puts
* control endpoint into idle state
*/
-static void ep0_end_out_req(struct pxa_ep *ep, struct pxa27x_request *req,
- unsigned long *pflags)
+static void ep0_end_out_req(struct pxa_ep *ep, struct pxa27x_request *req)
{
+ unsigned long flags;
+
set_ep0state(ep->dev, OUT_STATUS_STAGE);
- ep_end_out_req(ep, req, pflags);
+
+ spin_lock_irqsave(&ep->lock, flags);
+ ep_end_out_req(ep, req);
+ spin_unlock_irqrestore(&ep->lock, flags);
+
ep0_idle(ep->dev);
}
@@ -721,35 +718,36 @@ static void ep0_end_out_req(struct pxa_ep *ep, struct pxa27x_request *req,
* ep_end_in_req - Ends endpoint IN request
* @ep: physical endpoint
* @req: pxa request
- * @pflags: flags of previous spinlock_irq_save() or NULL if no lock held
*
- * Context: ep->lock held or released (see req_done())
+ * Context: ep->lock held with spin_lock_irqsave().
*
* Ends endpoint IN request (completes usb request).
*/
-static void ep_end_in_req(struct pxa_ep *ep, struct pxa27x_request *req,
- unsigned long *pflags)
+static void ep_end_in_req(struct pxa_ep *ep, struct pxa27x_request *req)
{
inc_ep_stats_reqs(ep, USB_DIR_IN);
- req_done(ep, req, 0, pflags);
+ req_done(ep, req, 0);
}
/**
* ep0_end_in_req - Ends control endpoint IN request (ends data stage)
* @ep: physical endpoint
* @req: pxa request
- * @pflags: flags of previous spinlock_irq_save() or NULL if no lock held
*
- * Context: ep->lock held or released (see req_done())
+ * Context: ep->lock not held.
*
* Ends control endpoint IN request (completes usb request), and puts
* control endpoint into status state
*/
-static void ep0_end_in_req(struct pxa_ep *ep, struct pxa27x_request *req,
- unsigned long *pflags)
+static void ep0_end_in_req(struct pxa_ep *ep, struct pxa27x_request *req)
{
+ unsigned long flags;
+
set_ep0state(ep->dev, IN_STATUS_STAGE);
- ep_end_in_req(ep, req, pflags);
+
+ spin_lock_irqsave(&ep->lock, flags);
+ ep_end_in_req(ep, req);
+ spin_unlock_irqrestore(&ep->lock, flags);
}
/**
@@ -770,7 +768,7 @@ static void nuke(struct pxa_ep *ep, int status)
spin_lock_irqsave(&ep->lock, flags);
while (!list_empty(&ep->queue)) {
req = list_entry(ep->queue.next, struct pxa27x_request, queue);
- req_done(ep, req, status, &flags);
+ req_done(ep, req, status);
}
spin_unlock_irqrestore(&ep->lock, flags);
}
@@ -1108,7 +1106,9 @@ static int pxa_ep_queue(struct usb_ep *_ep, struct usb_request *_req,
switch (dev->ep0state) {
case WAIT_ACK_SET_CONF_INTERF:
if (length == 0) {
- ep_end_in_req(ep, req, NULL);
+ spin_lock_irqsave(&ep->lock, flags);
+ ep_end_in_req(ep, req);
+ spin_unlock_irqrestore(&ep->lock, flags);
} else {
ep_err(ep, "got a request of %d bytes while"
"in state WAIT_ACK_SET_CONF_INTERF\n",
@@ -1121,12 +1121,12 @@ static int pxa_ep_queue(struct usb_ep *_ep, struct usb_request *_req,
case IN_DATA_STAGE:
if (!ep_is_full(ep))
if (write_ep0_fifo(ep, req))
- ep0_end_in_req(ep, req, NULL);
+ ep0_end_in_req(ep, req);
break;
case OUT_DATA_STAGE:
if ((length == 0) || !epout_has_pkt(ep))
if (read_ep0_fifo(ep, req))
- ep0_end_out_req(ep, req, NULL);
+ ep0_end_out_req(ep, req);
break;
default:
ep_err(ep, "odd state %s to send me a request\n",
@@ -1180,9 +1180,9 @@ static int pxa_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req)
break;
}
- spin_unlock_irqrestore(&ep->lock, flags);
if (!rc)
- req_done(ep, req, -ECONNRESET, NULL);
+ req_done(ep, req, -ECONNRESET);
+ spin_unlock_irqrestore(&ep->lock, flags);
return rc;
}
@@ -1993,13 +1993,13 @@ static void handle_ep0(struct pxa_udc *udc, int fifo_irq, int opc_irq)
if (req && !ep_is_full(ep))
completed = write_ep0_fifo(ep, req);
if (completed)
- ep0_end_in_req(ep, req, NULL);
+ ep0_end_in_req(ep, req);
break;
case OUT_DATA_STAGE: /* SET_DESCRIPTOR */
if (epout_has_pkt(ep) && req)
completed = read_ep0_fifo(ep, req);
if (completed)
- ep0_end_out_req(ep, req, NULL);
+ ep0_end_out_req(ep, req);
break;
case STALL:
ep_write_UDCCSR(ep, UDCCSR0_FST);
@@ -2074,9 +2074,9 @@ static void handle_ep(struct pxa_ep *ep)
if (completed) {
if (is_in)
- ep_end_in_req(ep, req, &flags);
+ ep_end_in_req(ep, req);
else
- ep_end_out_req(ep, req, &flags);
+ ep_end_out_req(ep, req);
}
} while (completed);
base-commit: 9357829ac604c28510b71b154cb6630af81226ff
--
2.54.0 (Apple Git-157)
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH usb-next v4] usb: gadget: pxa27x_udc: fix request completion locking on PREEMPT_RT
2026-12-05 23:22 [PATCH usb-next v4] usb: gadget: pxa27x_udc: fix request completion locking on PREEMPT_RT Xinsheng Zhu
@ 2026-12-05 23:36 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-12-05 23:36 UTC (permalink / raw)
To: Xinsheng Zhu, linux-usb
> req_done() explicitly disables local interrupts around
> usb_gadget_giveback_request(). The completion callback may acquire
> spinlocks, which become sleeping locks on PREEMPT_RT and cannot be
> acquired with interrupts disabled.
>
> Use spin_unlock() and spin_lock() around the giveback, following
> the locking pattern introduced in commit 8d63c83d8eb9
> ("USB: gadget: dummy-hcd: Fix locking bug in RT-enabled kernels")
> and commit 09bf21bf5249 ("usbip: Fix locking bug in RT-enabled kernels").
> This keeps interrupts disabled during the giveback on non-RT kernels
> without explicitly disabling them on PREEMPT_RT.
>
> Require ep->lock to be held when calling req_done(),
> ep_end_in_req() and ep_end_out_req(). Acquire the lock in the
> previously unlocked EP0 completion paths to protect both request
> removal and endpoint statistics updates.
>
> pxa_ep_dequeue() drops ep->lock after finding the request but
> before removing it from the queue. A concurrent completion may
> retire and free the request in this window. Keep ep->lock held
> across the request lookup and removal.
>
> Remove the now unnecessary pflags parameter from the completion
> helpers, update their kernel-doc and add lockdep_assert_held()
> to req_done() to check its locking contract.
>
> Fixes: 5e23e90f3388 ("USB: pxa27x_udc: Fix deadlocks on request queueing")
> Signed-off-by: Xinsheng Zhu <xinsheng.zhu.ny@gmail.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261205232247.38270-1-xinsheng.zhu.ny@gmail.com?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-05 23:36 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-05 23:22 [PATCH usb-next v4] usb: gadget: pxa27x_udc: fix request completion locking on PREEMPT_RT Xinsheng Zhu
2026-12-05 23:36 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox