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: Re: [PATCH printk v1 04/18] printk: Add per-console suspended state
Date: Wed, 8 Mar 2023 15:40:02 +0100 [thread overview]
Message-ID: <ZAieQtcs7YEuCCDa@alley> (raw)
In-Reply-To: <20230302195618.156940-5-john.ogness@linutronix.de>
On Thu 2023-03-02 21:02:04, John Ogness wrote:
> Currently the global @console_suspended is used to determine if
> consoles are in a suspended state. Its primary purpose is to allow
> usage of the console_lock when suspended without causing console
> printing. It is synchronized by the console_lock.
>
> Rather than relying on the console_lock to determine suspended
> state, make it an official per-console state that is set within
> console->flags. This allows the state to be queried via SRCU.
>
> @console_suspended will continue to exist, but now only to implement
> the console_lock/console_unlock trickery and _not_ to represent
> the suspend state of a particular console.
>
> --- a/include/linux/console.h
> +++ b/include/linux/console.h
> @@ -153,6 +153,8 @@ static inline int con_debug_leave(void)
> * receiving the printk spam for obvious reasons.
> * @CON_EXTENDED: The console supports the extended output format of
> * /dev/kmesg which requires a larger output buffer.
> + * @CON_SUSPENDED: Indicates if a console is suspended. If true, the
> + * printing callbacks must not be called.
> */
> enum cons_flags {
> CON_PRINTBUFFER = BIT(0),
> @@ -162,6 +164,7 @@ enum cons_flags {
> CON_ANYTIME = BIT(4),
> CON_BRL = BIT(5),
> CON_EXTENDED = BIT(6),
> + CON_SUSPENDED = BIT(7),
We have to show it in /proc/consoles, see fs/proc/consoles.c.
> --- a/kernel/printk/printk.c
> +++ b/kernel/printk/printk.c
> @@ -2563,10 +2563,26 @@ MODULE_PARM_DESC(console_no_auto_verbose, "Disable console loglevel raise to hig
> */
> void suspend_console(void)
> {
> + struct console *con;
> +
> if (!console_suspend_enabled)
> return;
> pr_info("Suspending console(s) (use no_console_suspend to debug)\n");
> pr_flush(1000, true);
> +
> + console_list_lock();
> + for_each_console(con)
> + console_srcu_write_flags(con, con->flags | CON_SUSPENDED);
> + console_list_unlock();
> +
> + /*
> + * Ensure that all SRCU list walks have completed. All printing
> + * contexts must be able to see that they are suspended so that it
> + * is guaranteed that all printing has stopped when this function
> + * completes.
> + */
> + synchronize_srcu(&console_srcu);
> +
> console_lock();
> console_suspended = 1;
> up_console_sem();
> @@ -2574,11 +2590,26 @@ void suspend_console(void)
>
> void resume_console(void)
> {
> + struct console *con;
> +
> if (!console_suspend_enabled)
> return;
> down_console_sem();
> console_suspended = 0;
> console_unlock();
> +
> + console_list_lock();
> + for_each_console(con)
> + console_srcu_write_flags(con, con->flags & ~CON_SUSPENDED);
> + console_list_unlock();
> +
> + /*
> + * Ensure that all SRCU list walks have completed. All printing
> + * contexts must be able to see they are no longer suspended so
> + * that they are guaranteed to wake up and resume printing.
> + */
> + synchronize_srcu(&console_srcu);
> +
The setting of the global "console_suspended" and per-console
CON_SUSPENDED flag is not synchronized. As a result, they might
become inconsistent:
CPU0 CPU1
suspend_console()
console_list_lock();
# set CON_SUSPENDED
console_list_unlock();
console_resume()
down_console_sem();
console_suspended = 0;
console_unlock();
console_list_lock()
# clear CON_SUSPENDED
console_list_unlock();
console_lock();
console_suspended = 1;
up_console_sem();
I think that we could just remove the global "console_suspended" flag.
IMHO, it used to be needed to avoid moving the global "console_seq" forward
when the consoles were suspended. But it is not needed now with the
per-console con->seq. console_flush_all() skips consoles when
console_is_usable() fails and it bails out when there is no progress.
It seems that both console_flush_all() and console_unlock() would
handle this correctly.
Hmm, it would change the behavior of console_lock() and console_trylock().
They would set "console_locked" and "console_may_schedule" even when
the consoles are suspended. But it should be OK:
+ "console_may_schedule" actually should be set according
to the context where console_unlock() will be called.
+ "console_locked" seems to be used only in WARN_CONSOLE_UNLOCKED().
I could imagine a corner case where, for example, "vt" code does
not print the warning because it works as it works. But it does
not make much sense. IMHO, such a code should get fixed. And it
is just a warning after all.
> pr_flush(1000, true);
> }
>
> @@ -3712,14 +3745,7 @@ static bool __pr_flush(struct console *con, int timeout_ms, bool reset_on_progre
> }
> console_srcu_read_unlock(cookie);
>
> - /*
> - * If consoles are suspended, it cannot be expected that they
> - * make forward progress, so timeout immediately. @diff is
> - * still used to return a valid flush status.
> - */
> - if (console_suspended)
> - remaining = 0;
Heh, I though that this might cause regression, e.g. non-necessary
delays during suspend.
But it actually works because "diff" is counted only for usable
consoles. It will stay "0" if there is no usable console.
I wonder if it would make sense to add a comment somewhere,
e.g. above the later check:
+ /* diff is zero also when there is no usable console. */
if (diff == 0 || remaining == 0)
break;
Anyway, we should update the comment above pr_flush():
- * Return: true if all enabled printers are caught up.
+ * Return: true if all usable printers are caught up.
> - else if (diff != last_diff && reset_on_progress)
> + if (diff != last_diff && reset_on_progress)
> remaining = timeout_ms;
>
> console_unlock();
Best Regards,
Petr
next prev parent reply other threads:[~2023-03-08 14:42 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 [this message]
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 ` boot console: was: " Petr Mladek
2023-04-06 8:09 ` wakeup synchronization: " 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=ZAieQtcs7YEuCCDa@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.