Linux USB
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Alexandru Ardelean" <aardelean@taladin.ro>, linux-usb@vger.kernel.org
Subject: Re: [PATCH v2 1/2] Revert "usb: musb: Fix hardware lockup on first Rx endpoint request"
Date: Tue, 24 Nov 2026 15:16:30 +0000	[thread overview]
Message-ID: <sashiko-outbox-231395@kernel.org> (raw)
In-Reply-To: <20261124150344.69264-2-aardelean@taladin.ro>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] usb: musb: lock inversion in musb_ep_restart() via
  musb_run_resume_work()
--

commit d72e1bdec5562f8d7f92be2dcf471e3639a440ee
Author: Alexandru Ardelean <aardelean@taladin.ro>

Revert "usb: musb: Fix hardware lockup on first Rx endpoint request"

This commit reverts commit 3fc137386c46 ("usb: musb: Fix hardware lockup on
first Rx endpoint request"), restoring the call to rxstate() in
musb_ep_restart() for RX requests instead of flushing the Rx FIFO.

> diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c
> index 016d3f3fc1e05..dd67ab97df9d8 100644
> --- a/drivers/usb/musb/musb_gadget.c
> +++ b/drivers/usb/musb/musb_gadget.c
> @@ -1162,19 +1162,12 @@ void musb_free_request(struct usb_ep *ep, struct usb_request *req)
>   */
>  void musb_ep_restart(struct musb *musb, struct musb_request *req)
>  {
> -	u16 csr;
> -	void __iomem *epio = req->ep->hw_ep->regs;
> -
>  	trace_musb_req_start(req);
>  	musb_ep_select(musb->mregs, req->epnum);
> -	if (req->tx) {
> +	if (req->tx)
>  		txstate(musb, req);
> -	} else {
> -		csr = musb_readw(epio, MUSB_RXCSR);
> -		csr |= MUSB_RXCSR_FLUSHFIFO | MUSB_RXCSR_P_WZC_BITS;
> -		musb_writew(epio, MUSB_RXCSR, csr);
> -		musb_writew(epio, MUSB_RXCSR, csr);
> -	}
> +	else
> +		rxstate(musb, req);
>  }

[Severity: Medium]
Can calling rxstate() from musb_ep_restart() invert the musb->lock ->
musb->list_lock lock order and deadlock when invoked via
musb_run_resume_work()?

When an RX request is queued while runtime suspended,
musb_queue_resume_work() queues musb_ep_restart_resume_work() on
musb->pending_list.  On resume, musb_run_resume_work() runs with
musb->lock and musb->list_lock held.  If rxstate() completes the request
synchronously (for example, a zero-length RX request or a PIO read that
satisfies the transfer), it calls musb_g_giveback(), which drops and
re-acquires musb->lock while musb->list_lock remains held:

CPU0                                  CPU1
----                                  ----
musb_runtime_resume()
  lock(&musb->lock)
  musb_run_resume_work()
    lock(&musb->list_lock)
    musb_ep_restart_resume_work()
      musb_ep_restart()
        rxstate()
          musb_g_giveback()
            unlock(&musb->lock)
            usb_gadget_giveback_request()
                                      musb_gadget_queue()
                                        lock(&musb->lock)
                                        musb_queue_resume_work()
                                          lock(&musb->list_lock)
            lock(&musb->lock)

 *** DEADLOCK ***

If the gadget's completion callback instead re-queues a request via
usb_ep_queue() -> musb_gadget_queue() -> musb_queue_resume_work(), the
same CPU also deadlocks trying to acquire musb->list_lock recursively.
This remains present after the follow-up commit "usb: musb: gadget: mask
the MUSB IRQ while complete() runs".

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261124150344.69264-1-aardelean@taladin.ro?part=1

  reply	other threads:[~2026-11-24 15:16 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-24 15:03 [PATCH v2 0/2] usb: musb: gadget: fix lost Rx packet on first OUT request Alexandru Ardelean
2026-11-24 15:03 ` [PATCH v2 1/2] Revert "usb: musb: Fix hardware lockup on first Rx endpoint request" Alexandru Ardelean
2026-11-24 15:16   ` sashiko-bot [this message]
2026-11-24 15:03 ` [PATCH v2 2/2] usb: musb: gadget: mask the MUSB IRQ while complete() runs Alexandru Ardelean

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-231395@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=aardelean@taladin.ro \
    --cc=linux-usb@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox