Linux Serial subsystem development
 help / color / mirror / Atom feed
From: Petr Mladek <pmladek@suse.com>
To: John Ogness <john.ogness@linutronix.de>
Cc: "Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Jiri Slaby" <jirislaby@kernel.org>,
	"Andy Shevchenko" <andy.shevchenko@gmail.com>,
	"Sebastian Andrzej Siewior" <bigeasy@linutronix.de>,
	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>,
	"Fushuai Wang" <wangfushuai@baidu.com>,
	"Kees Cook" <kees@kernel.org>,
	"Stepan Ionichev" <sozdayvek@gmail.com>,
	linux-serial@vger.kernel.org
Subject: Re: [PATCH tty v9 1/2] serial: 8250: Switch to nbcon console, take 2
Date: Thu, 30 Jul 2026 10:27:17 +0200	[thread overview]
Message-ID: <amsK5UPlzthyZJqD@pathway.suse.cz> (raw)
In-Reply-To: <87o6fwms02.fsf@jogness.linutronix.de>

On Fri 2026-07-24 15:39:49, John Ogness wrote:
> On 2026-07-24, Sashiko wrote:
> >> diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
> >> index 8c241ec7f4f29..855a7aa48c2d2 100644
> >> --- a/drivers/tty/serial/8250/8250_port.c
> >> +++ b/drivers/tty/serial/8250/8250_port.c
> >> @@ -3198,13 +3218,28 @@ void serial8250_set_defaults(struct uart_8250_port *up)
> >>  }
> >>  EXPORT_SYMBOL_GPL(serial8250_set_defaults);
> >>  
> >> -void serial8250_fifo_wait_for_lsr_thre(struct uart_8250_port *up, unsigned int count)
> >> +void serial8250_fifo_wait_for_lsr_thre(struct uart_8250_port *up,
> >> +				       struct nbcon_write_context *wctxt,
> >> +				       unsigned int count)
> >>  {
> >>  	unsigned int i;
> >>  
> >> +	/*
> >> +	 * For console writing, enter/exit an unsafe section for each byte
> >> +	 * in order to pass the ownership as quickly as possible if a higher
> >> +	 * priority context wants ownership. Otherwise, an attempt to take
> >> +	 * over the ownership might timeout. The new owner will wait for
> >> +	 * UART_LSR_THRE before reusing the fifo.
> >> +	 */
> >>  	for (i = 0; i < count; i++) {
> >> +		if (wctxt && !nbcon_enter_unsafe(wctxt))
> >> +			return;
> >> +
> >>  		if (wait_for_lsr(up, UART_LSR_THRE))
> >>  			return;
> >
> > Does this early return on success bypass the cleanup of the unsafe
> > section?
> >
> > If wait_for_lsr() returns true, wouldn't
> > serial8250_fifo_wait_for_lsr_thre() return immediately without calling
> > nbcon_exit_unsafe(wctxt)?
> >
> > Could this resource leak of the nbcon unsafe state prevent other
> > contexts from taking over ownership?
> 
> It simply has the effect of joining this unsafe section with the next
> one. In this case it really wouldn't matter. But still, it was not my
> intention. I will fix this for v10.
> 
> How I plan for it to look for v10:
> 
> 	for (i = 0; i < count; i++) {
> 		bool tx_ready;
> 
> 		if (wctxt && !nbcon_enter_unsafe(wctxt))
> 			return;
> 
> 		tx_ready = wait_for_lsr(up, UART_LSR_THRE);
> 
> 		if (wctxt)
> 			nbcon_exit_unsafe(wctxt);
> 
> 		if (tx_ready)
> 			break;
> 	}
> 
> I am wondering if we should add a WARN_ON_ONCE() to nbcon_enter_unsafe()
> if the context is already unsafe. It is a simple one-liner. That would
> at least catch these kinds of mistakes during runtime. (I would do that
> in a separate printk patch, not in this series.)

Yup, makes sense.

Best Regards,
Petr

  reply	other threads:[~2026-07-30  8:27 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-24 10:36 [PATCH tty v9 0/2] Convert 8250 to NBCON, take 2 John Ogness
2026-07-24 10:36 ` [PATCH tty v9 1/2] serial: 8250: Switch to nbcon console, " John Ogness
2026-07-24 13:33   ` John Ogness
2026-07-30  8:27     ` Petr Mladek [this message]
2026-07-24 10:36 ` [PATCH tty v9 2/2] Revert "serial: 8250: drop lockdep annotation from serial8250_clear_IER()" 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=amsK5UPlzthyZJqD@pathway.suse.cz \
    --to=pmladek@suse.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=bigeasy@linutronix.de \
    --cc=gregkh@linuxfoundation.org \
    --cc=hvilleneuve@dimonoff.com \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=jirislaby@kernel.org \
    --cc=john.ogness@linutronix.de \
    --cc=kees@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --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