Re: VT-less kernels, and /dev/console on x86

From: Petr Mladek
Date: Thu Sep 12 2024 - 09:27:52 EST


On Thu 2024-09-12 08:29:26, nerdopolis wrote:
> On Tuesday, August 20, 2024 9:29:36 AM EDT Petr Mladek wrote:
> > On Mon 2024-08-19 11:50:39, nerdopolis wrote:
> > > On Monday, August 19, 2024 11:09:35 AM EDT Steven Rostedt wrote:
> > > > On Sun, 18 Aug 2024 10:30:22 -0400
> > > > nerdopolis <bluescreen_avenger@xxxxxxxxxxx> wrote:
> > > > > On Sunday, August 18, 2024 8:33:25 AM EDT nerdopolis wrote:
> > > > > > On Sunday, August 18, 2024 1:12:14 AM EDT Greg KH wrote:
> > > > > > > On Sat, Aug 17, 2024 at 08:09:20PM -0400, nerdopolis wrote:
> > > > > > > > I originally brought this up on linux-serial, but I think it makes more sense
> > > > > > > > that it's part of how printk console device selection works. Without VTs, while
> > > > > > > > most software is able to handle the situation, some userspace programs expect
> > > > > > > > /dev/console to still be responsive. Namely systemd. It calls isatty() against
> > > > > > > > /dev/console, and since /dev/console on VT-less systems currently defaults to
> > > > > > > > /dev/ttyS0, and when /dev/ttyS0 is disconnected, the ioctl's fail, and it
> > > > > > > > refuses to write log messages to it.
> > > > > > > >
> > > Would something like this below be more acceptable? I didn't test it yet, but
> > > just the theory. I am thinking that this could have more use to allow a
> > > preferred to be set...
> > >
> > > diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
> > > index dddb15f48d59..c1554a789de8 100644
> > > --- a/kernel/printk/printk.c
> > > +++ b/kernel/printk/printk.c
> > > @@ -3712,6 +3712,11 @@ void __init console_init(void)
> > > initcall_t call;
> > > initcall_entry_t *ce;
> > >
> > > +#ifdef CONFIG_DEFAULT_CONSOLE_HINT_BOOL
> > > + if (!strstr(boot_command_line, "console="))
> > > + add_preferred_console(CONFIG_DEFAULT_CONSOLE_HINT, 0, NULL);
> > > +#endif
> > > +
> > > /* Setup the default TTY line discipline. */
> > > n_tty_init();
> >
> > This is better. But it does not handle some situations. For example,
> > default console might also by defined by:
> >
> > + scpr, see acpi_parse_spcr()
> > + device tree, see of_console_check()
> > + netconsole=, it is hidden in init_netconsole()
> >
> > I tried to handle this another way. The "ttynull" console was
> > added when /dev/console could not be opened in console_on_rootfs(),
> > see the commit 757055ae8dedf5333af17b ("init/console: Use ttynull
> > as a fallback when there is no console").
> >
> > But it did not work well and we had to revert the change, see
> > the commit a91bd6223ecd46addc71ee6f ("Revert "init/console: Use
> > ttynull as a fallback when there is no console").
> >
> Out of curiosity, would the upcoming nbcon work fix the race conditions or
> problems that were seen in 757055ae8dedf5333af17b ?

Not really. The nbcon work affects the context and locking used for
flushing of the consoles. It does _not_ affect the registration. And
it does _not_ affect how the consoles are associated with /dev/console.

Best Regards,
Petr