Linux USB
 help / color / mirror / Atom feed
* [PATCH usb-next] usb: gadget: pxa27x_udc: fix locking in req_done() on PREEMPT_RT
@ 2026-12-05  3:13 Xinsheng Zhu
  2026-12-05  3:25 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Xinsheng Zhu @ 2026-12-05  3:13 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
spinlock_t locks, which become sleeping locks on PREEMPT_RT. Acquiring
such locks with interrupts disabled can result in a sleeping function
being called from an invalid context.

Follow the locking pattern introduced by commit 8d63c83d8eb9
("USB: gadget: dummy-hcd: Fix locking bug in RT-enabled kernels")
by using spin_unlock() and spin_lock() around the giveback. This
keeps interrupts disabled on non-RT kernels without explicitly
disabling them on PREEMPT_RT.

When pflags is NULL, establish the same interrupt state using
spin_lock_irqsave() and spin_unlock_irqrestore(). Otherwise,
reuse the caller's lock and saved interrupt state.

This preserves the original locking contract of req_done() and
leaves the endpoint queue locking unchanged.

Fixes: 5e23e90f3388 ("USB: pxa27x_udc: Fix deadlocks on request queueing")
Signed-off-by: Xinsheng Zhu <xinsheng.zhu.ny@gmail.com>
---
 drivers/usb/gadget/udc/pxa27x_udc.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/drivers/usb/gadget/udc/pxa27x_udc.c b/drivers/usb/gadget/udc/pxa27x_udc.c
index 9fd079cb65c6..774e50d00d09 100644
--- a/drivers/usb/gadget/udc/pxa27x_udc.c
+++ b/drivers/usb/gadget/udc/pxa27x_udc.c
@@ -672,13 +672,15 @@ 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);
+	if (!pflags)
+		spin_lock_irqsave(&ep->lock, 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);
+
+	if (!pflags)
+		spin_unlock_irqrestore(&ep->lock, flags);
 }
 
 /**

base-commit: 9357829ac604c28510b71b154cb6630af81226ff
-- 
2.54.0 (Apple Git-157)


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH usb-next] usb: gadget: pxa27x_udc: fix locking in req_done() on PREEMPT_RT
  2026-12-05  3:13 [PATCH usb-next] usb: gadget: pxa27x_udc: fix locking in req_done() on PREEMPT_RT Xinsheng Zhu
@ 2026-12-05  3:25 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-12-05  3:25 UTC (permalink / raw)
  To: Xinsheng Zhu, linux-usb; +Cc: linux-rt-devel, linux-kernel

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] usb: gadget: pxa27x_udc: empty ep->lock pairs and unused
  pflags in req_done()
--

commit 15927850a0e1e014c34b3d8d8f2da88f14a342f0
Author: Xinsheng Zhu <xinsheng.zhu.ny@gmail.com>

usb: gadget: pxa27x_udc: fix locking in req_done() on PREEMPT_RT

This commit replaces the explicit local_irq_save()/local_irq_restore()
calls around usb_gadget_giveback_request() in req_done() with
spin_unlock()/spin_lock() on ep->lock, acquiring and releasing ep->lock
with spin_lock_irqsave()/spin_unlock_irqrestore() when pflags is NULL.

> diff --git a/drivers/usb/gadget/udc/pxa27x_udc.c b/drivers/usb/gadget/udc/pxa27x_udc.c
> index 9fd079cb65c6b..774e50d00d090 100644
> --- a/drivers/usb/gadget/udc/pxa27x_udc.c
> +++ b/drivers/usb/gadget/udc/pxa27x_udc.c
> @@ -672,13 +672,15 @@ 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);
> +	if (!pflags)
> +		spin_lock_irqsave(&ep->lock, 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);
> +
> +	if (!pflags)
> +		spin_unlock_irqrestore(&ep->lock, flags);
>  }

[Severity: Medium]
When pflags is NULL, should req_done() avoid taking and immediately
releasing ep->lock twice with no protected code in between?

On CONFIG_PREEMPT_RT, spin_lock_irqsave() does not change interrupt state
and only acquires a sleeping rt_spin_lock().  Callers passing NULL, such
as handle_ep0() and pxa_ep_dequeue(), now add two empty ep->lock cycles
that can contend with concurrent queue operations while protecting nothing.

Meanwhile, ep_del_request() earlier in req_done() remains outside this
lock acquisition; moving it before ep_del_request() (and keeping ep->lock
held in pxa_ep_dequeue()) would protect the queue update instead of
locking empty regions.

Also, *pflags is no longer dereferenced anywhere in req_done() or its
wrappers, so keeping unsigned long *pflags as a boolean while its
kernel-doc still describes it as saved spinlock flags is misleading.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261205031306.25065-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  3:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-05  3:13 [PATCH usb-next] usb: gadget: pxa27x_udc: fix locking in req_done() on PREEMPT_RT Xinsheng Zhu
2026-12-05  3:25 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox