From: Eliav Farber <farbere@amazon.com>
To: John Ogness <john.ogness@linutronix.de>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Jiri Slaby <jirislaby@kernel.org>
Cc: Petr Mladek <pmladek@suse.com>,
Steven Rostedt <rostedt@goodmis.org>,
Sergey Senozhatsky <senozhatsky@chromium.org>,
<printk@lists.linux.dev>, <linux-serial@vger.kernel.org>,
<linux-kernel@vger.kernel.org>, Eliav Farber <farbere@amazon.com>
Subject: Re: [PATCH] serial: core: Don't spin for nbcon ownership with the port lock held
Date: Tue, 1 Dec 2026 14:58:19 +0000 [thread overview]
Message-ID: <20261201145819.10941-1-farbere@amazon.com> (raw)
In-Reply-To: <87zeuq1b6j.fsf@jogness.linutronix.de>
On 2026-11-30, John Ogness <john.ogness@linutronix.de> wrote:
>> uart_port_lock() and its variants take the port lock and then spin until
>> they own the nbcon console context, which synchronizes port->lock users
>> against the write_atomic() callback. The context is requested at
>> NBCON_PRIO_NORMAL, and while another CPU is in panic that request is
>> always refused, so the spin never ends.
>
> It is always refused because it is not a reacquire.
>
> Commit 571c1ea91a73 ("printk: nbcon: Allow reacquire during panic") only
> considered the reacquire situation.
Right. I will reword it to:
During a panic on another CPU the only acquire still allowed is a
reacquire by the context that lost ownership, see commit
571c1ea91a73 ("printk: nbcon: Allow reacquire during panic"). The
wrapper's acquire is not one, so it is always refused and the spin
never ends.
> Any foreign panic that occurs between the port-lock and ownership
> acquire can cause this.
Yes. I will put that in the commit log.
>> - This may belong in printk instead. [...]
>
> I do not think the reacquire fix should extend to general port
> locking. [...]
OK, I will drop that note.
> Should these instead reuse the trylock variants? For example:
>
> static inline void uart_port_lock(struct uart_port *up)
> {
> while (!uart_port_trylock(up))
> cpu_relax();
> }
Tested this and it fixes the stall. The irq variant has no counterpart
though, so it needs a new uart_port_trylock_irq() on spin_trylock_irq().
> Or perhaps in order to allow non-nbcon drivers to remain minimally
> affected in behavior:
>
> static inline void uart_port_lock(struct uart_port *up)
> {
> if (!__uart_port_using_nbcon(up)) {
> spin_lock(&up->lock);
> return;
> }
That one cannot be used as written. __uart_port_using_nbcon() starts
with lockdep_assert_held_once(&up->lock), and the up->cons reads below
it are only safe under the port lock, as the comment there says.
The patch as posted already leaves non-nbcon ports alone: such a port
takes spin_lock() and one __uart_port_using_nbcon() test that returns
false, which is what __uart_port_nbcon_acquire() did.
If you want the trylock wrappers reused anyway, this keeps the assert
valid and leaves the normal path on spin_lock():
static inline void uart_port_lock(struct uart_port *up)
{
spin_lock(&up->lock);
if (__uart_port_nbcon_try_acquire(up))
return;
spin_unlock(&up->lock);
while (!uart_port_trylock(up))
cpu_relax();
}
Which one do you want in v2?
Eliav
next prev parent reply other threads:[~2026-12-01 14:58 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 15:51 [PATCH] serial: core: Don't spin for nbcon ownership with the port lock held Eliav Farber
2026-11-30 16:09 ` sashiko-bot
2026-11-30 17:28 ` John Ogness
2026-12-01 14:58 ` Eliav Farber [this message]
2026-12-01 16:29 ` John Ogness
2026-12-02 5:24 ` Farber, Eliav
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=20261201145819.10941-1-farbere@amazon.com \
--to=farbere@amazon.com \
--cc=gregkh@linuxfoundation.org \
--cc=jirislaby@kernel.org \
--cc=john.ogness@linutronix.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=pmladek@suse.com \
--cc=printk@lists.linux.dev \
--cc=rostedt@goodmis.org \
--cc=senozhatsky@chromium.org \
/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.