All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Xinsheng Zhu" <xinsheng.zhu.ny@gmail.com>, linux-usb@vger.kernel.org
Cc: linux-rt-devel@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [PATCH usb-next v2] usb: gadget: pxa27x_udc: fix locking in req_done() on PREEMPT_RT
Date: Sat, 05 Dec 2026 06:42:36 +0000	[thread overview]
Message-ID: <sashiko-outbox-251139@kernel.org> (raw)
In-Reply-To: <20261205063000.75015-1-xinsheng.zhu.ny@gmail.com>

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

      reply	other threads:[~2026-12-05  6:42 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-05  6:30 [PATCH usb-next v2] usb: gadget: pxa27x_udc: fix locking in req_done() on PREEMPT_RT Xinsheng Zhu
2026-12-05  6:42 ` sashiko-bot [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-251139@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rt-devel@lists.linux.dev \
    --cc=linux-usb@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=xinsheng.zhu.ny@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.