From: John Ogness <john.ogness@linutronix.de>
To: Petr Mladek <pmladek@suse.com>
Cc: Sergey Senozhatsky <senozhatsky@chromium.org>,
Steven Rostedt <rostedt@goodmis.org>,
Andrew Murray <amurray@thegoodpenguin.co.uk>,
Chris Down <chris@chrisdown.name>,
linux-kernel@vger.kernel.org, Jonathan Corbet <corbet@lwn.net>,
Shuah Khan <skhan@linuxfoundation.org>,
linux-doc@vger.kernel.org
Subject: [PATCH printk 3/3] printk: Support setting console sync mode via console=
Date: Fri, 10 Jul 2026 16:51:53 +0206 [thread overview]
Message-ID: <20260710144609.194487-4-john.ogness@linutronix.de> (raw)
In-Reply-To: <20260710144609.194487-1-john.ogness@linutronix.de>
Extend the console= kernel command line argument to support specifying
sync mode at boot time. This is achieved by introducing a new "sync"
option that can be passed within a console= cmdline argument.
For example, assuming the first serial device should be a console using
sync mode:
console=ttyS0,115200,sync
Signed-off-by: John Ogness <john.ogness@linutronix.de>
Co-authored-by: Chris Down <chris@chrisdown.name>
---
Documentation/admin-guide/serial-console.rst | 8 ++
kernel/printk/console_cmdline.h | 1 +
kernel/printk/printk.c | 79 ++++++++++++++++++++
3 files changed, 88 insertions(+)
diff --git a/Documentation/admin-guide/serial-console.rst b/Documentation/admin-guide/serial-console.rst
index 1609e7479249f..37cbd9581c53a 100644
--- a/Documentation/admin-guide/serial-console.rst
+++ b/Documentation/admin-guide/serial-console.rst
@@ -32,6 +32,14 @@ The format of this option is::
and F is flow control ('r' for RTS). Default is
9600n8. The maximum baudrate is 115200.
+ One can also specify extra options (comma-separated)
+ to modify console printing behavior. The "sync" extra
+ option will cause console printing on that console to
+ be synchronous (printed in the context of the printk()
+ caller). This could cause adverse timing side-effects
+ for the system, but can be useful in certain debugging
+ scenarios.
+
You can specify multiple console= options on the kernel command line.
The behavior is well defined when each device type is mentioned only once.
diff --git a/kernel/printk/console_cmdline.h b/kernel/printk/console_cmdline.h
index 0ab573b6d4dc2..ce4709f7a1b0c 100644
--- a/kernel/printk/console_cmdline.h
+++ b/kernel/printk/console_cmdline.h
@@ -8,6 +8,7 @@ struct console_cmdline
int index; /* Minor dev. to use */
char devname[32]; /* DEVNAME:0.0 style device name */
bool user_specified; /* Specified by command line vs. platform */
+ bool sync; /* Print in sync mode */
char *options; /* Options for the driver */
#ifdef CONFIG_A11Y_BRAILLE_CONSOLE
char *brl_options; /* Options for braille driver */
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index e82e864a4d672..e53ac5554e5eb 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -2567,6 +2567,81 @@ static void set_user_specified(struct console_cmdline *c, bool user_specified)
console_set_on_cmdline = 1;
}
+/**
+ * find_and_remove_console_option - Find and remove a named option from console options string
+ * @options: The console options string (will be modified in-place)
+ * @key: The option name to find (e.g., "loglevel")
+ * @val_buf: Buffer to store the option value (if present)
+ * @val_buf_size: Size of @val_buf
+ *
+ * This function searches for a named option in a comma-separated options string
+ * (e.g., "9600n8,loglevel:3,sync"). If found, it extracts the value
+ * (the part after ':') and removes the entire option from the string.
+ *
+ * If an option does not support values, @val_buf should be NULL, in which
+ * case no value part is extracted and any user provided ':' is considered part
+ * of the option key.
+ *
+ * The function modifies @options in-place by:
+ * 1. Temporarily null-terminating option names and values during parsing
+ * 2. Restoring separators if the option isn't found
+ * 3. Removing the found option by shifting the remaining string
+ *
+ * Return: true if the option was found and removed, false otherwise
+ */
+static bool find_and_remove_console_option(char *options, const char *key,
+ char *val_buf, size_t val_buf_size)
+{
+ bool found = false, first = true;
+ char *option, *next = options;
+
+ while ((option = strsep(&next, ","))) {
+ char *value = NULL;
+
+ if (val_buf) {
+ value = strchr(option, ':');
+ if (value)
+ *(value++) = '\0';
+ }
+
+ if (strcmp(option, key) == 0) {
+ found = true;
+ if (value) {
+ if (strlen(value) >= val_buf_size) {
+ pr_warn("Cannot copy console option value for %s:%s: not enough space (%zu)\n",
+ option, value, val_buf_size);
+ found = false;
+ } else {
+ strscpy(val_buf, value, val_buf_size);
+ }
+ } else if (val_buf) {
+ *val_buf = '\0';
+ }
+ }
+
+ if (found)
+ break;
+
+ if (next)
+ *(next - 1) = ',';
+ if (value)
+ *(value - 1) = ':';
+
+ first = false;
+ }
+
+ if (found) {
+ if (next)
+ memmove(option, next, strlen(next) + 1);
+ else if (first)
+ *option = '\0';
+ else
+ *--option = '\0';
+ }
+
+ return found;
+}
+
static int __add_preferred_console(const char *name, const short idx,
const char *devname, char *options,
char *brl_options, bool user_specified)
@@ -2609,6 +2684,7 @@ static int __add_preferred_console(const char *name, const short idx,
strscpy(c->name, name);
if (devname)
strscpy(c->devname, devname);
+ c->sync = find_and_remove_console_option(options, "sync", NULL, 0);
c->options = options;
set_user_specified(c, user_specified);
braille_set_options(c, brl_options);
@@ -3932,6 +4008,9 @@ static int try_enable_preferred_console(struct console *newcon,
if (_braille_register_console(newcon, c))
return 0;
+ if (c->sync)
+ newcon->flags |= CON_SYNC;
+
err = console_call_setup(newcon, c->options);
if (err)
return err;
--
2.47.3
next prev parent reply other threads:[~2026-07-10 14:46 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-10 14:45 [PATCH printk 0/3] Introduce sync mode John Ogness
2026-07-10 14:45 ` John Ogness [this message]
2026-07-10 21:05 ` 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=20260710144609.194487-4-john.ogness@linutronix.de \
--to=john.ogness@linutronix.de \
--cc=amurray@thegoodpenguin.co.uk \
--cc=chris@chrisdown.name \
--cc=corbet@lwn.net \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pmladek@suse.com \
--cc=rostedt@goodmis.org \
--cc=senozhatsky@chromium.org \
--cc=skhan@linuxfoundation.org \
/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