From: Petr Mladek <pmladek@suse.com>
To: John Ogness <john.ogness@linutronix.de>
Cc: Sergey Senozhatsky <senozhatsky@chromium.org>,
Steven Rostedt <rostedt@goodmis.org>,
Thomas Gleixner <tglx@linutronix.de>,
linux-kernel@vger.kernel.org,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Subject: boot console: was: Re: [PATCH printk v1 11/18] printk: nobkl: Introduce printer threads
Date: Wed, 5 Apr 2023 12:48:25 +0200 [thread overview]
Message-ID: <ZC1R+fzuTNodWvfY@alley> (raw)
In-Reply-To: <20230302195618.156940-12-john.ogness@linutronix.de>
On Thu 2023-03-02 21:02:11, John Ogness wrote:
> From: Thomas Gleixner <tglx@linutronix.de>
>
> Add the infrastructure to create a printer thread per console along
> with the required thread function, which is takeover/handover aware.
>
> --- a/kernel/printk/internal.h
> +++ b/kernel/printk/internal.h
> @@ -75,6 +77,55 @@ u64 cons_read_seq(struct console *con);
> void cons_nobkl_cleanup(struct console *con);
> bool cons_nobkl_init(struct console *con);
> bool cons_alloc_percpu_data(struct console *con);
> +void cons_kthread_create(struct console *con);
> +
> +/*
> + * Check if the given console is currently capable and allowed to print
> + * records. If the caller only works with certain types of consoles, the
> + * caller is responsible for checking the console type before calling
> + * this function.
> + */
> +static inline bool console_is_usable(struct console *con, short flags)
> +{
> + if (!(flags & CON_ENABLED))
> + return false;
> +
> + if ((flags & CON_SUSPENDED))
> + return false;
> +
> + /*
> + * The usability of a console varies depending on whether
> + * it is a NOBKL console or not.
> + */
> +
> + if (flags & CON_NO_BKL) {
> + if (have_boot_console)
> + return false;
I am not sure if this is the right place to discuss it.
Different patches add pieces that are part of the puzzle.
Anyway, how are the NOBKL consoles supposed to work when a boot console
is still registered, please?
I see that a later patch adds:
asmlinkage int vprintk_emit(int facility, int level,
const struct dev_printk_info *dev_info,
const char *fmt, va_list args)
{
[...]
/*
* Flush the non-BKL consoles. This only leads to direct atomic
* printing for non-BKL consoles that do not have a printer
* thread available. Otherwise the printer thread will perform
* the printing.
*/
cons_atomic_flush(&wctxt, true);
[...]
}
This patch adds cons_kthread_create(). And it refuses to create
the kthread as long as there is a boot console registered.
Finally, a later added cons_atomic_flush() ignores consoles where
console_is_usable() returns false:
void cons_atomic_flush(struct cons_write_context *printk_caller_wctxt, bool skip_unsafe)
{
[...]
for_each_console_srcu(con) {
[...]
if (!console_is_usable(con, flags))
continue;
It looks to me that NOBKL consoles will not show anything as long as
a boot console is registered.
And the boot console might never be removed when "keep_bootcon"
parameter is used.
Sigh, this looks like a non-trivial problem. I see it as a combination
of two things:
+ NOBKL consoles are independent. And this is actually one
big feature.
+ There is no 1:1 relation between boot and real console using
the same output device (serial port). I mean that
register_console() is not able to match which real console
is replacing a particular boot console.
As a result, we could not easily synchronize boot and the related real
console against each other.
I see three possible solutions:
A) Ignore this problem. People are most likely using only one boot
console. And the real console will get enabled "immediately"
after this console gets removed. So that there should not be
any gap.
The only problem is that people use more real consoles. And
also unrelated real consoles will not see anything.
I guess that people might notice that they do not see anything
on ttyX console until ttySX replaces an early serial console.
And they might consider this as a regression.
B) Allow to match boot and real consoles using the same output device
and properly synchronize them against each other.
It might mean:
+ sharing the same atomic lock (atomic_state)
+ sharing the same device (port) lock
+ avoid running both at the same time by a careful
switch during the registration of the real console
, where sharing the same port lock might theoretically be done
without 1:1 matching of the related console drivers. They
would use the same port->lock spin_lock.
This might also fix the ugly race during console registration
when we unregister the boot console too early or too late.
The switch between a boot and the related real console might be
always smooth.
The problem is that it might be pretty complicated to achieve
this.
C) Synchronize also NOBKL consoles using console_sem until
all boot consoles are removed and kthreads started.
I might actually be pretty easy. It might be enough to
move cons_flush_all() from vprintk_emit() into
console_flush_all() that is called under console_lock().
I think that we need to keep cons_flush_all() in vprintk_emit()
to emit the messages directly in EMERGENCY and PANIC modes.
But we do not need or must not call it there when there is
still a boot console. We would know that it will called later
from console_unlock() in this case.
My preferences:
+ A probably is not acceptable. It would make me feel very
uncomfortable, definitely.
+ B looks like the best solution but it might be very hard to achieve.
+ C seems to be good enough for now.
I think that C is the only realistic way to go unless there is another
reasonable solution.
Best Regards,
Petr
next prev parent reply other threads:[~2023-04-05 10:48 UTC|newest]
Thread overview: 92+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-02 19:56 [PATCH printk v1 00/18] threaded/atomic console support John Ogness
2023-03-02 19:56 ` [PATCH printk v1 01/18] kdb: do not assume write() callback available John Ogness
2023-03-07 14:57 ` Petr Mladek
2023-03-07 16:34 ` Doug Anderson
2023-03-09 10:52 ` Daniel Thompson
2023-03-09 11:26 ` Petr Mladek
2023-03-09 11:30 ` Daniel Thompson
2023-03-02 19:56 ` [PATCH printk v1 02/18] printk: Add NMI check to down_trylock_console_sem() John Ogness
2023-03-07 16:05 ` Petr Mladek
2023-03-17 11:37 ` John Ogness
2023-04-13 13:42 ` Petr Mladek
2023-03-02 19:56 ` [PATCH printk v1 03/18] printk: Consolidate console deferred printing John Ogness
2023-03-08 13:15 ` Petr Mladek
2023-03-17 13:05 ` John Ogness
2023-04-13 15:15 ` Petr Mladek
2023-03-02 19:56 ` [PATCH printk v1 04/18] printk: Add per-console suspended state John Ogness
2023-03-08 14:40 ` Petr Mladek
2023-03-17 13:22 ` John Ogness
2023-04-14 9:56 ` Petr Mladek
2023-03-02 19:56 ` [PATCH printk v1 05/18] printk: Add non-BKL console basic infrastructure John Ogness
2023-03-09 14:08 ` global states: was: " Petr Mladek
2023-03-17 13:29 ` John Ogness
2023-03-09 15:32 ` naming: " Petr Mladek
2023-03-17 13:39 ` John Ogness
2023-03-21 16:04 ` union: was: " Petr Mladek
2023-03-27 16:28 ` John Ogness
2023-03-28 8:20 ` Petr Mladek
2023-03-28 9:42 ` John Ogness
2023-03-28 12:52 ` Petr Mladek
2023-03-28 13:47 ` Steven Rostedt
2023-03-02 19:56 ` [PATCH printk v1 06/18] printk: nobkl: Add acquire/release logic John Ogness
2023-03-06 9:07 ` Dan Carpenter
2023-03-06 9:39 ` John Ogness
2023-03-13 16:07 ` Petr Mladek
2023-03-17 14:56 ` John Ogness
2023-03-20 16:10 ` Petr Mladek
2023-03-17 17:34 ` simplify: was: " Petr Mladek
2023-03-21 15:36 ` Petr Mladek
2023-04-02 18:39 ` John Ogness
2023-03-02 19:56 ` [PATCH printk v1 07/18] printk: nobkl: Add buffer management John Ogness
2023-03-21 16:38 ` Petr Mladek
2023-03-23 13:38 ` John Ogness
2023-03-23 15:25 ` Petr Mladek
2023-03-02 19:56 ` [PATCH printk v1 08/18] printk: nobkl: Add sequence handling John Ogness
2023-03-27 15:45 ` Petr Mladek
2023-03-02 19:56 ` [PATCH printk v1 09/18] printk: nobkl: Add print state functions John Ogness
2023-03-29 13:58 ` buffer write race: " Petr Mladek
2023-03-29 14:33 ` John Ogness
2023-03-30 11:54 ` Petr Mladek
2023-03-29 14:05 ` misc details: was: " Petr Mladek
2023-03-02 19:56 ` [PATCH printk v1 10/18] printk: nobkl: Add emit function and callback functions for atomic printing John Ogness
2023-03-03 0:19 ` kernel test robot
2023-03-03 10:55 ` John Ogness
2023-03-31 10:29 ` dropped handling: was: " Petr Mladek
2023-03-31 10:36 ` semantic: " Petr Mladek
[not found] ` <87edp29kvq.fsf@jogness.linutronix.de>
[not found] ` <ZCraqrkqFtsfLWuP@alley>
[not found] ` <87ilecsrvl.fsf@jogness.linutronix.de>
2023-04-04 14:09 ` Petr Mladek
2023-03-02 19:56 ` [PATCH printk v1 11/18] printk: nobkl: Introduce printer threads John Ogness
2023-03-03 1:23 ` kernel test robot
2023-03-03 10:56 ` John Ogness
2023-04-05 10:48 ` Petr Mladek [this message]
2023-04-06 8:09 ` wakeup synchronization: was: " Petr Mladek
2023-04-06 9:46 ` port lock: " Petr Mladek
2023-04-20 9:55 ` Petr Mladek
2023-04-20 10:33 ` John Ogness
2023-04-20 13:33 ` Petr Mladek
2023-04-21 16:15 ` Petr Mladek
2023-04-06 13:19 ` misc: " Petr Mladek
2023-04-13 13:28 ` (k)thread: " Petr Mladek
2023-03-02 19:56 ` [PATCH printk v1 12/18] printk: nobkl: Add printer thread wakeups John Ogness
2023-04-12 9:38 ` Petr Mladek
2023-03-02 19:56 ` [PATCH printk v1 13/18] printk: nobkl: Add write context storage for atomic writes John Ogness
2023-03-02 19:56 ` [PATCH printk v1 14/18] printk: nobkl: Provide functions for atomic write enforcement John Ogness
2023-04-12 14:53 ` Petr Mladek
2023-03-02 19:56 ` [PATCH printk v1 15/18] printk: nobkl: Stop threads on shutdown/reboot John Ogness
2023-04-13 9:03 ` Petr Mladek
2023-03-02 19:56 ` [PATCH printk v1 16/18] kernel/panic: Add atomic write enforcement to warn/panic John Ogness
2023-04-13 10:08 ` Petr Mladek
2023-04-13 12:13 ` John Ogness
2023-04-14 10:10 ` Petr Mladek
2023-03-02 19:56 ` [PATCH printk v1 17/18] rcu: Add atomic write enforcement for rcu stalls John Ogness
2023-04-13 12:10 ` Petr Mladek
2023-03-02 19:56 ` [PATCH printk v1 18/18] printk: Perform atomic flush in console_flush_on_panic() John Ogness
2023-04-13 12:20 ` Petr Mladek
2023-03-02 19:58 ` [PATCH printk v1 00/18] serial: 8250: implement non-BKL console John Ogness
2023-03-28 13:33 ` locking API: was: " Petr Mladek
2023-03-28 13:57 ` John Ogness
2023-03-28 15:10 ` Petr Mladek
2023-03-28 21:47 ` John Ogness
2023-03-29 8:03 ` Petr Mladek
2023-03-28 13:59 ` [PATCH printk v1 00/18] POC: serial: 8250: implement nbcon console John Ogness
2023-03-09 10:55 ` [PATCH printk v1 00/18] threaded/atomic console support Daniel Thompson
2023-03-09 11:14 ` 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=ZC1R+fzuTNodWvfY@alley \
--to=pmladek@suse.com \
--cc=gregkh@linuxfoundation.org \
--cc=john.ogness@linutronix.de \
--cc=linux-kernel@vger.kernel.org \
--cc=rostedt@goodmis.org \
--cc=senozhatsky@chromium.org \
--cc=tglx@linutronix.de \
/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.