From: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
To: "Hubert Wiśniewski" <hubert.wisniewski.25632@gmail.com>
Cc: "Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Ferry Toth" <ftoth@exalondelft.nl>,
"Hardik Gajjar" <hgajjar@de.adit-jv.com>,
"Kees Cook" <kees@kernel.org>,
"Justin Stitt" <justinstitt@google.com>,
"Richard Acayan" <mailingradian@gmail.com>,
"Jeff Johnson" <quic_jjohnson@quicinc.com>,
"Ricardo B. Marliere" <ricardo@marliere.net>,
"David S. Miller" <davem@davemloft.net>,
"Eric Dumazet" <edumazet@google.com>,
"Toke Høiland-Jørgensen" <toke@redhat.com>,
linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3] usb: gadget: u_ether: Use __netif_rx() in rx_callback()
Date: Fri, 27 Sep 2024 16:12:00 +0200 [thread overview]
Message-ID: <20240927141200.xMZ53xm5@linutronix.de> (raw)
In-Reply-To: <a7a132ff61a4533ce463ec088e15e3156c3ce39b.camel@gmail.com>
On 2024-09-27 15:33:35 [+0200], Hubert Wiśniewski wrote:
> On Thu, 2024-09-26 at 21:39 +0200, Hubert Wiśniewski wrote:
> > I'm a bit at loss here. The deadlock seems to be unrelated to netif_rx()
> > (which is not being called in the interrupt context after all), yet
> > replacing it with __netif_rx() fixes the lockup (though a warning is still
> > generated, which suggests that the patch does not completely fix the
> > issue).
>
> Well, never mind. After some investigation, I think the problem is as
> follows:
>
> 1. musb_g_giveback() releases the musb lock using spin_unlock(). The lock
> is now released, but hardirqs are still disabled.
>
> 2. Then, usb_gadget_giveback_request() is called, which in turn calls
> rx_complete(). This does not happen in the interrupt context, so netif_rx()
> disables bottom havles, then enables them using local_bh_enable().
>
> 3. This leads to calling __local_bh_enable_ip(), which gives off a warning
> (the first backtrace) that hardirqs are disabled. Then, hardirqs are
> disabled (again?), and then enabled (as they should have been in the first
> place).
>
> 4. After usb_gadget_giveback_request() returns, musb_g_giveback() acquires
> the musb lock using spin_lock(). This does not disable hardirqs, so they
> are still enabled.
>
> 5. While the musb lock is acquired, an interrupt occurs. It is handled by
> dsps_interrupt(), which acquires the musb lock. A deadlock occurs.
This all makes sense so far.
> Replacing netif_rx() with __netif_rx() apparently fixes this part, as it
> does not lead to any change of hardirq state. There is still one problem
> though: rx_complete() is usually called from the interrupt context, except
> when the network interface is brought up.
__netif_rx() has an assert which should complain if you use
__netif_rx(). Further in this case you pass the skb to backlog but never
kick it for processing. Which means it is delayed until a random
interrupt notices and processes it.
> I think one solution would be to make musb_g_giveback() use
> spin_unlock_irqrestore() and spin_lock_irqsave(), but I would need to pass
> the flags to it somehow. Also, I am not sure how that would influence other
> drivers using musb.
I would also suggest to do this since the other solution is not safe/
correct. There is the ->busy assignment which should cover for the most
cases. If you drop the lock without enabling interrupts then the
interrupt can't do anything to the EP and other enqueue/ dequeue
invocation is not possible if run on UP. On the other hand am335x was
used on PREEMPT_RT and it runs a UP machine into SMP so that should be
covered :)
While looking at it, dequeue/ enqueue during complete callback looks
safe due to the busy flag.
Sebastian
next prev parent reply other threads:[~2024-09-27 14:12 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-17 13:56 [PATCH v3] usb: gadget: u_ether: Use __netif_rx() in rx_callback() Hubert Wiśniewski
2024-09-17 14:36 ` Sebastian Andrzej Siewior
2024-09-26 19:39 ` Hubert Wiśniewski
2024-09-27 13:33 ` Hubert Wiśniewski
2024-09-27 14:12 ` Sebastian Andrzej Siewior [this message]
2024-10-01 14:06 ` Hubert Wiśniewski
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=20240927141200.xMZ53xm5@linutronix.de \
--to=bigeasy@linutronix.de \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=ftoth@exalondelft.nl \
--cc=gregkh@linuxfoundation.org \
--cc=hgajjar@de.adit-jv.com \
--cc=hubert.wisniewski.25632@gmail.com \
--cc=justinstitt@google.com \
--cc=kees@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=mailingradian@gmail.com \
--cc=quic_jjohnson@quicinc.com \
--cc=ricardo@marliere.net \
--cc=toke@redhat.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox