From: John Ogness <john.ogness@linutronix.de>
To: Petr Mladek <pmladek@suse.com>
Cc: "Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Jiri Slaby" <jirislaby@kernel.org>,
"Andy Shevchenko" <andy.shevchenko@gmail.com>,
linux-kernel@vger.kernel.org,
"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
"Andy Shevchenko" <andriy.shevchenko@linux.intel.com>,
"Hugo Villeneuve" <hvilleneuve@dimonoff.com>,
"Osama Abdelkader" <osama.abdelkader@gmail.com>,
"Stepan Ionichev" <sozdayvek@gmail.com>,
"Kees Cook" <kees@kernel.org>, "Xin Zhao" <jackzxcui1989@163.com>,
"Fushuai Wang" <wangfushuai@baidu.com>,
"Yunhui Cui" <cuiyunhui@bytedance.com>,
"Jacques Nilo" <jnilo@free.fr>,
linux-serial@vger.kernel.org
Subject: Re: [PATCH tty v6 1/2] serial: 8250: Switch to nbcon console, take 2
Date: Mon, 20 Jul 2026 18:13:39 +0206 [thread overview]
Message-ID: <87v7a9lk50.fsf@jogness.linutronix.de> (raw)
In-Reply-To: <al43iOyokb56SBF3@pathway.suse.cz>
On 2026-07-20, Petr Mladek <pmladek@suse.com> wrote:
> On Mon 2026-07-20 12:38:35, John Ogness wrote:
>> --- a/drivers/tty/serial/8250/8250_core.c
>> +++ b/drivers/tty/serial/8250/8250_core.c
>> @@ -584,6 +609,9 @@ void serial8250_suspend_port(int line)
>> struct uart_8250_port *up = &serial8250_ports[line];
>> struct uart_port *port = &up->port;
>>
>> + /* No irq_work may be queued when suspending. */
>> + up->avoid_modem_status_work = true;
>
> Do we need to synchronize this against serial8250_console_write()
> where this flag is checked, please?
Yes. @avoid_modem_status_work needs to be modified under the port->lock
to ensure that serial8250_console_write() does not queue any new
irq_work. It is evaluated in atomic context, but taking the port->lock
also acquires nbcon ownership.
I will add this for v8 (in both places where @avoid_modem_status_work is
modified).
> This might even answer the question from Sashiko AI whether
> we should flush the related irq_work() here, see
> https://sashiko.dev/#/patchset/20260720103242.7265-1-john.ogness%40linutronix.de
>
> That said, I am not sure about RT_PREEMPT. AFAIK, it handles IRQs
> in a kthread. In this case, synchronize_srcu() would not make
> sure that the irq_work was procceed.
>
> Note that Sashiko AI suggests that we might need to flush the irq_work
> even in serial8250_console_exit(). I guess that the situation is
> the same there. It is called after synchronize_srcu()...
Yes, I will add irq_work_sync() in both locations.
>> @@ -620,6 +648,12 @@ void serial8250_resume_port(int line)
>> port->uartclk = 921600*16;
>> }
>> uart_resume_port(&serial8250_reg, port);
>> +
>> + /* irq_work allowed again. Handle MSR now if pending. */
>> + up->avoid_modem_status_work = false;
>> + guard(uart_port_lock_irqsave)(port);
>> + if (uart_console(port) && up->msr_saved_flags)
>> + serial8250_modem_status(up);
>
> I would use scoped_guard() to make the scope clear. Something like:
>
> scoped_guard(uart_port_lock_irqsave, port) {
> if (uart_console(port) && up->msr_saved_flags)
> serial8250_modem_status(up);
> }
>
> Motivation: The guard() is pretty hidden. It can easily get overlooked
> when people add more code at the end of this function.
OK.
> Wait, this should not be needed if we make sure that the work
> was flushed in serial8250_suspend_port().
When !console_suspend_enabled, the driver will continue to print in
atomic mode, but will avoid the irq_work. It will however notice if
there are any MSR changes. Those changes are then handled here.
I suppose I should add an "if (!console_suspend_enabled)" to the
conditions.
>> - if (oops_in_progress)
>> - locked = uart_port_trylock_irqsave(port, &flags);
>> - else
>> - uart_port_lock_irqsave(port, &flags);
>> + if (!nbcon_enter_unsafe(wctxt))
>> + return;
>>
>> /*
>> - * First save the IER then disable the interrupts
>> + * First, save the IER, then disable the interrupts. The special
>> + * variant to clear the IER is used because console printing may
>> + * occur without holding the port lock.
>
> I would make the comment more clear when it might happen and if it is
> safe. Something like:
>
> * First, save the IER, then disable the interrupts. The special
> * variant to clear the IER is used because an emergency and panic
> * console printing is synchronized only by nbcon context without
> * holding the port lock.
OK.
>> +skip_write:
>> + /*
>> + * If ownership was lost, this context must reacquire ownership and
>> + * re-enter the unsafe section in order to perform final actions
>> + * (such as re-enabling interrupts).
>> + */
>> + if (!nbcon_can_proceed(wctxt)) {
>
> This should be:
>
> if (!nbcon_enter_unsafe(wctxt))
>
> or even better:
>
> while (!nbcon_enter_unsafe(wctxt))
> nbcon_reacquire_nobuf(wctxt);
Right. I will take the while loop variant.
Thanks for your review! (You can ignore my v7 as you caught everything
that I missed in my v7.)
John
next prev parent reply other threads:[~2026-07-20 16:07 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-20 10:32 [PATCH tty v6 0/2] Convert 8250 to NBCON, take 2 John Ogness
2026-07-20 10:32 ` [PATCH tty v6 1/2] serial: 8250: Switch to nbcon console, " John Ogness
2026-07-20 13:07 ` John Ogness
2026-07-20 14:58 ` Petr Mladek
2026-07-20 16:07 ` John Ogness [this message]
2026-07-20 10:32 ` [PATCH tty v6 2/2] serial: 8250: Revert "drop lockdep annotation from serial8250_clear_IER()" John Ogness
2026-07-20 13:10 ` John Ogness
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=87v7a9lk50.fsf@jogness.linutronix.de \
--to=john.ogness@linutronix.de \
--cc=andriy.shevchenko@linux.intel.com \
--cc=andy.shevchenko@gmail.com \
--cc=cuiyunhui@bytedance.com \
--cc=gregkh@linuxfoundation.org \
--cc=hvilleneuve@dimonoff.com \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=jackzxcui1989@163.com \
--cc=jirislaby@kernel.org \
--cc=jnilo@free.fr \
--cc=kees@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=osama.abdelkader@gmail.com \
--cc=pmladek@suse.com \
--cc=sozdayvek@gmail.com \
--cc=wangfushuai@baidu.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