The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* Re: [PATCH usb-next v2] usb: gadget: pxa27x_udc: fix locking in req_done() on PREEMPT_RT
       [not found] <20261205063000.75015-1-xinsheng.zhu.ny@gmail.com>
@ 2026-12-05  6:42 ` sashiko-bot
  0 siblings, 0 replies; only message in thread
From: sashiko-bot @ 2026-12-05  6:42 UTC (permalink / raw)
  To: Xinsheng Zhu, linux-usb; +Cc: linux-rt-devel, linux-kernel

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Low] usb: gadget: pxa27x_udc: unused pflags pointer kept as bool in
  req_done()
- [Low] usb: gadget: pxa27x_udc: commit message omits pxa_ep_dequeue()
  lock change
--

commit 5f58fa50b677bda0e909e4f97a6e3ac181b4d2f2
Author: Xinsheng Zhu <xinsheng.zhu.ny@gmail.com>

> usb: gadget: pxa27x_udc: fix locking in req_done() on PREEMPT_RT
>
> 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.
>
> When pflags is NULL, acquire ep->lock before ep_del_request() to
> protect the request removal and status update. Release the lock
> and restore the interrupt state before returning.
>
> Fixes: 5e23e90f3388 ("USB: pxa27x_udc: Fix deadlocks on request queueing")
> Signed-off-by: Xinsheng Zhu <xinsheng.zhu.ny@gmail.com>

[Severity: Low]
Should the commit message also describe the locking change in
pxa_ep_dequeue()?

The diff keeps ep->lock held across the request lookup and the call to
req_done(), closing a race where an interrupt could complete and free the
request between lookup and removal.  That change is currently only noted
under Changes in v2 below the tearline, which git am strips.

> diff --git a/drivers/usb/gadget/udc/pxa27x_udc.c b/drivers/usb/gadget/udc/pxa27x_udc.c
> index 9fd079cb65c6b..2c4e46533999b 100644
> --- a/drivers/usb/gadget/udc/pxa27x_udc.c
> +++ b/drivers/usb/gadget/udc/pxa27x_udc.c
> @@ -650,17 +650,23 @@ 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
> + * @pflags: non-NULL if the caller holds ep->lock with spin_lock_irqsave(),
> + *          NULL otherwise
>   *
> - * Context: ep->lock held if flags not NULL, else ep->lock released
> + * Context: ep->lock held if @pflags is non-NULL, otherwise unlocked.
>   *
> - * Retire a pxa27x usb request. Endpoint must be locked.
> + * Retire a pxa27x usb request. Acquire the endpoint lock if needed
> + * and temporarily release it around the completion callback.
> + * Return with the original lock state restored.
>   */
>  static void req_done(struct pxa_ep *ep, struct pxa27x_request *req, int status,
>  	unsigned long *pflags)
>  {
>  	unsigned long	flags;
>  
> +	if (!pflags)
> +		spin_lock_irqsave(&ep->lock, flags);
> +
>  	ep_del_request(ep, req);
>  	if (likely(req->req.status == -EINPROGRESS))
>  		req->req.status = status;
> @@ -672,20 +678,20 @@ 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);
> +
> +	if (!pflags)
> +		spin_unlock_irqrestore(&ep->lock, flags);
>  }

[Severity: Low]
Can pflags be replaced now that req_done() never dereferences it?

After switching to spin_unlock() and spin_lock() around the giveback,
pflags is only used as a boolean in req_done() and its wrappers, forcing
locked callers to pass &flags as a dummy sentinel.  The conditional
locking also triggers lock-context imbalance warnings in static analyzers.

In addition, ep0_end_out_req() and ep0_end_in_req() still take pflags
even though every call site passes NULL.  Splitting req_done() into a
locked helper and an unlocked wrapper (and dropping the parameter from
those two helpers) would make the locking contract explicit.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261205063000.75015-1-xinsheng.zhu.ny@gmail.com?part=1

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-12-05  6:42 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20261205063000.75015-1-xinsheng.zhu.ny@gmail.com>
2026-12-05  6:42 ` [PATCH usb-next v2] usb: gadget: pxa27x_udc: fix locking in req_done() on PREEMPT_RT sashiko-bot

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