Skip to contentSkip to conversation

x86: Allow early_printk to use console style param like 115200n8

RFC PATCH In review Steven Rostedt 4 participants 9 messages Jul 3, 2015 – Jul 6, 2015 x86

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 x86: Allow early_printk to use console style param like 115200n8

When I enable early_printk on a kernel, I cut and paste the console= input and add to earlyprintk parameter. But I notice recently that ktest has not been detecting triple faults. The way it detects it, is by seeing the kernel banner "Linux version .." with a different kernel version pop up. Then I noticed that early printk was no longer working on my console, which was why ktest was not seeing it.

I bisected it down and it was added to 4.0 with this commit:

commit ea9e9d802902 ("Specify PCI based UART for earlyprintk")

because it converted the simple_strtoul() that converts the baud number into a kstrtoul(). The problem with this is, I had as my baud rate, 115200n8 (acceptable for console=ttyS0), but because of the "n8", the kstrtoul() doesn't parse the baud rate and returns an error, which sets the baud rate to the default 9600. This explains the garbage on my screen.

Now, earlyprintk= kernel parameter does not say it accepts that format. Thus, one answer would simply be me changing my kernel parameters to remove the "n8" since it isn't parsed anyway. But I wonder if other people run into this, and it seems strange that the two consoles for serial accepts different input.

I could also extend this to have earlyprintk do something with that "n8" or whatever it has and have it match the console parsing (which, BTW, still uses simple_strtoul(), as I guess it has to).

This patch just makes my old kernel parameter parsing work like it use to. Although, if someone were to use a hex number starting with "0x", this patch would break it. That could be fixed too (hence the RFC).

---

arch/x86/kernel/early_printk.c +10 -0
index a62536a1be88..83d375148565 100644
@@ -17,6 +17,7 @@
 #include <asm/intel-mid.h>
 #include <asm/pgtable.h>
 #include <linux/usb/ehci_def.h>
+#include <linux/ctype.h>
 #include <linux/efi.h>
 #include <asm/efi.h>
 #include <asm/pci_x86.h>
@@ -189,6 +190,15 @@ static __init void early_serial_init(char *s)
 	}
 
 	if (*s) {
+		char *p;
+		/*
+		 * In case the input is like console with text after the baud
+		 * rate. e.g. 115200n8. kstrtoul() will error on such input.
+		 */
+		for (p = s; *p && isdigit(*p); p++)
+			;
+		*p = 0;
+
 		if (kstrtoul(s, 0, &baud) < 0 || baud == 0)
 			baud = DEFAULT_BAUD;
 	}
#1 lore raw
Quoted 10 lines · Steven Rostedt

When I enable early_printk on a kernel, I cut and paste the console= input and add to earlyprintk parameter. But I notice recently that ktest has not been detecting triple faults. The way it detects it, is by seeing the kernel banner "Linux version .." with a different kernel version pop up. Then I noticed that early printk was no longer working on my console, which was why ktest was not seeing it.

I bisected it down and it was added to 4.0 with this commit:

commit ea9e9d802902 ("Specify PCI based UART for earlyprintk")

Ugh, this commit changed x86 code but was not Cc:-ed to any x86 maintainer, and the title was pretty misleading as well...

( That patch should have been split into at least two parts: the generic
earlyprintk changes affecting all modes, and the 'pciserial' enablement. Anyway, that's water down the bridge. )

Quoted 5 lines

because it converted the simple_strtoul() that converts the baud number into a kstrtoul(). The problem with this is, I had as my baud rate, 115200n8 (acceptable for console=ttyS0), but because of the "n8", the kstrtoul() doesn't parse the baud rate and returns an error, which sets the baud rate to the default 9600. This explains the garbage on my screen.

ugh. I bet it also breaks the earlyprintk=ttyS0..,keep format?

Quoted 4 lines

Now, earlyprintk= kernel parameter does not say it accepts that format. Thus, one answer would simply be me changing my kernel parameters to remove the "n8" since it isn't parsed anyway. But I wonder if other people run into this, and it seems strange that the two consoles for serial accepts different input.

So why not revert to the known-working simple_strtoul()? I don't see this as an improvement:

arch/x86/kernel/early_printk.c static __init void early_serial_init(char *s) · line 203

Quoted 10 lines
arch/x86/kernel/early_printk.c +8 -0
+		/*
+		 * In case the input is like console with text after the baud
+		 * rate. e.g. 115200n8. kstrtoul() will error on such input.
+		 */
+		for (p = s; *p && isdigit(*p); p++)
+			;
+		*p = 0;
+
 		if (kstrtoul(s, 0, &baud) < 0 || baud == 0)
 			baud = DEFAULT_BAUD;

Over the old:

		baud = simple_strtoul(s, &e, 0);

Thanks,

Ingo

#2 lore raw
Quoted 12 lines · On Sat, 4 Jul 2015 13:03:59 +0200 Ingo Molnar <[email protected]> wrote:

arch/x86/kernel/early_printk.c static __init void early_serial_init(char *s) · line 203

Quoted 10 lines
arch/x86/kernel/early_printk.c +8 -0
+		/*
+		 * In case the input is like console with text after the baud
+		 * rate. e.g. 115200n8. kstrtoul() will error on such input.
+		 */
+		for (p = s; *p && isdigit(*p); p++)
+			;
+		*p = 0;
+
 		if (kstrtoul(s, 0, &baud) < 0 || baud == 0)
 			baud = DEFAULT_BAUD;

This was actually one of those cases where I wanted to show that keeping the old function around is better than the alternative ;-)

If people say we need to phase out simple_strtoull(), then I wanted to show what kinds of hacks we will have if that happens.

I was hoping that someone would point out that simple_strtoull() is a better solution. :)

-- Steve

#3 lore raw
Quoted 17 lines · Steven Rostedt
Quoted 12 lines · On Sat, 4 Jul 2015 13:03:59 +0200 Ingo Molnar <[email protected]> wrote:

arch/x86/kernel/early_printk.c static __init void early_serial_init(char *s) · line 203

Quoted 10 lines
arch/x86/kernel/early_printk.c +8 -0
+		/*
+		 * In case the input is like console with text after the baud
+		 * rate. e.g. 115200n8. kstrtoul() will error on such input.
+		 */
+		for (p = s; *p && isdigit(*p); p++)
+			;
+		*p = 0;
+
 		if (kstrtoul(s, 0, &baud) < 0 || baud == 0)
 			baud = DEFAULT_BAUD;
Quoted 8 lines

This was actually one of those cases where I wanted to show that keeping the old function around is better than the alternative ;-)

If people say we need to phase out simple_strtoull(), then I wanted to show what kinds of hacks we will have if that happens.

I was hoping that someone would point out that simple_strtoull() is a better solution. :)

LOL :)

Ingo

#4 lore raw
In reply to Steven Rostedt
Quoted 17 lines · Steven Rostedt
Quoted 12 lines · On Sat, 4 Jul 2015 13:03:59 +0200 Ingo Molnar <[email protected]> wrote:

arch/x86/kernel/early_printk.c static __init void early_serial_init(char *s) · line 203

Quoted 10 lines
arch/x86/kernel/early_printk.c +8 -0
+		/*
+		 * In case the input is like console with text after the baud
+		 * rate. e.g. 115200n8. kstrtoul() will error on such input.
+		 */
+		for (p = s; *p && isdigit(*p); p++)
+			;
+		*p = 0;
+
 		if (kstrtoul(s, 0, &baud) < 0 || baud == 0)
 			baud = DEFAULT_BAUD;
Quoted 8 lines

This was actually one of those cases where I wanted to show that keeping the old function around is better than the alternative ;-)

If people say we need to phase out simple_strtoull(), then I wanted to show what kinds of hacks we will have if that happens.

I was hoping that someone would point out that simple_strtoull() is a better solution. :)

And made worse by the fact that checkpatch flags simple_strtoul* as obsolete, so people keep submitting junk like above [1] in an effort to escape the checkpatch warning.

Which I pointed out to Joe back in Feb. (https://lkml.org/lkml/2015/2/25/217)

Regards,
Peter Hurley

[1] or this recent submission

Quoted 24 lines · Peter Hurley
Quoted 8 lines · Bin Gao
(quoted diff) +8 -0
+{
+	char str[4]; /* max 3 chars, plus a NULL terminator */
+	char *p = options;
+	int i = 0;
+
+	while (*p) {
+		if (i >= 4)
+			return -EINVAL;

Review

Quoted 10 lines
(quoted diff) +10 -0
+
+		if (*p == delimiter) {
+			str[i++] = 0;
+			if (endp)
+				*endp = p + 1;
+			return kstrtou8(str, 10, val); /* decimal, no hex */
+		}
+
+		str[i++] = *p++;
+	}

Is all this to avoid using simple_strtoul()?
If yes, I'd rather you use simple_strtoul() like the rest of the console code and ignore the (misguided) advice that simple_strtoul() is obsolete.

#5 lore raw
Quoted 24 lines · Peter Hurley
Quoted 23 lines · Steven Rostedt
Quoted 12 lines · On Sat, 4 Jul 2015 13:03:59 +0200 Ingo Molnar <[email protected]> wrote:

arch/x86/kernel/early_printk.c static __init void early_serial_init(char *s) · line 203

Quoted 10 lines
arch/x86/kernel/early_printk.c +8 -0
+		/*
+		 * In case the input is like console with text after the baud
+		 * rate. e.g. 115200n8. kstrtoul() will error on such input.
+		 */
+		for (p = s; *p && isdigit(*p); p++)
+			;
+		*p = 0;
+
 		if (kstrtoul(s, 0, &baud) < 0 || baud == 0)
 			baud = DEFAULT_BAUD;

This was actually one of those cases where I wanted to show that keeping the old function around is better than the alternative ;-)

If people say we need to phase out simple_strtoull(), then I wanted to show what kinds of hacks we will have if that happens.

Quoted 8 lines
Quoted 2 lines

I was hoping that someone would point out that simple_strtoull() is a better solution. :)

And made worse by the fact that checkpatch flags simple_strtoul* as obsolete, so people keep submitting junk like above [1] in an effort to escape the checkpatch warning.

Which I pointed out to Joe back in Feb. (https://lkml.org/lkml/2015/2/25/217)

So this kind of checkpatch-driven crap really needs to stop.

Thanks,

Ingo

#6 lore raw
In reply to Ingo Molnar
Quoted 17 lines · On Sat, 4 Jul 2015 13:03:59 +0200 Ingo Molnar <[email protected]> wrote:

So why not revert to the known-working simple_strtoul()? I don't see this as an improvement:

arch/x86/kernel/early_printk.c static __init void early_serial_init(char *s) · line 203

Quoted 10 lines
arch/x86/kernel/early_printk.c +8 -0
+		/*
+		 * In case the input is like console with text after the baud
+		 * rate. e.g. 115200n8. kstrtoul() will error on such input.
+		 */
+		for (p = s; *p && isdigit(*p); p++)
+			;
+		*p = 0;
+
 		if (kstrtoul(s, 0, &baud) < 0 || baud == 0)
 			baud = DEFAULT_BAUD;

Over the old:

Quoted 2 lines
		baud = simple_strtoul(s, &e, 0);

That was what I actually did first, but then saw this:

* Returns 0 on success, -ERANGE on overflow and -EINVAL on parsing error.
* Used as a replacement for the obsolete simple_strtoull. Return code must
* be checked.

in lib/kstrtox.c and thought that it seems that we are trying to phase out that function. Personally, I prefer keeping it for instances like this.

So by all means, put back the simple_strtoul(); I would like that too.

-- Steve

#7 lore raw

PATCH 1/1 x86: Allow early_printk to use console style param like 115200n8

In reply to Steven Rostedt

When I enable early_printk on a kernel, I cut and paste the console= input and add to earlyprintk parameter. But I notice recently that ktest has not been detecting triple faults. The way it detects it, is by seeing the kernel banner "Linux version .." with a different kernel version pop up. Then I noticed that early printk was no longer working on my console, which was why ktest was not seeing it.

I bisected it down and it was added to 4.0 with this commit:

commit ea9e9d802902 ("Specify PCI based UART for earlyprintk")

because it converted the simple_strtoul() that converts the baud number into a kstrtoul(). The problem with this is, I had as my baud rate, 115200n8 (acceptable for console=ttyS0), but because of the "n8", the kstrtoul() doesn't parse the baud rate and returns an error, which sets the baud rate to the default 9600. This explains the garbage on my screen.

Now, earlyprintk= kernel parameter does not say it accepts that format. Thus, one answer would simply be me changing my kernel parameters to remove the "n8" since it isn't parsed anyway. But I wonder if other people run into this, and it seems strange that the two consoles for serial accepts different input.

I could also extend this to have earlyprintk do something with that "n8" or whatever it has and have it match the console parsing (which, BTW, still uses simple_strtoul(), as I guess it has to).

This patch just makes my old kernel parameter parsing work like it use to.

Although, simple_strtoull() is considered obsolete, it is the only standard string parsing function that parses a number that is attached to text. Ironically, commit ea9e9d802902 also added several calls to simple_strtoul()!

---

arch/x86/kernel/early_printk.c +1 -1
index a62536a1be88..033a2ca06ea8 100644
@@ -189,7 +189,7 @@ static __init void early_serial_init(char *s)
 	}
 
 	if (*s) {
-		if (kstrtoul(s, 0, &baud) < 0 || baud == 0)
+		if ((baud = simple_strtoull(s, &e, 0)) == 0 || s == e)
 			baud = DEFAULT_BAUD;
 	}
 
#8 lore raw

[tip:x86/urgent] x86/earlyprintk: Allow early_printk() to use console style parameters like '115200n8'

x86/earlyprintk: Allow early_printk() to use console style parameters like '115200n8'
Commit-ID:  827a82ff399523a954253dfea401af748640f0f4
Gitweb:     http://git.kernel.org/tip/827a82ff399523a954253dfea401af748640f0f4
Author:     Steven Rostedt <[email protected]>
AuthorDate: Mon, 6 Jul 2015 10:14:34 -0400
Committer:  Ingo Molnar <[email protected]>
CommitDate: Mon, 6 Jul 2015 17:33:47 +0200

x86/earlyprintk: Allow early_printk() to use console style parameters like '115200n8'

When I enable early_printk on a kernel, I cut and paste the console= input and add to earlyprintk parameter. But I notice recently that ktest has not been detecting triple faults. The way it detects it, is by seeing the kernel banner "Linux version .." with a different kernel version pop up. Then I noticed that early printk was no longer working on my console, which was why ktest was not seeing it.

I bisected it down and it was added to 4.0 with this commit:

ea9e9d802902 ("Specify PCI based UART for earlyprintk")

because it converted the simple_strtoul() that converts the baud number into a kstrtoul(). The problem with this is, I had as my baud rate, 115200n8 (acceptable for console=ttyS0), but because of the "n8", the kstrtoul() doesn't parse the baud rate and returns an error, which sets the baud rate to the default 9600. This explains the garbage on my screen.

Now, earlyprintk= kernel parameter does not say it accepts that format. Thus, one answer would simply be me changing my kernel parameters to remove the "n8" since it isn't parsed anyway. But I wonder if other people run into this, and it seems strange that the two consoles for serial accepts different input.

I could also extend this to have earlyprintk do something with that "n8" or whatever it has and have it match the console parsing (which, BTW, still uses simple_strtoul(), as I guess it has to).

This patch just makes my old kernel parameter parsing work like it use to.

Although, simple_strtoull() is considered obsolete, it is the only standard string parsing function that parses a number that is attached to text. Ironically, commit ea9e9d802902 also added several calls to simple_strtoul()!

Cc Alan Cox <[email protected]>
Cc Andy Lutomirski <[email protected]>
Cc Andy Shevchenko <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Brian Gerst <[email protected]>
Cc David Cohen <[email protected]>
Cc Denys Vlasenko <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc H. Peter Anvin <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Stuart R. Anderson <[email protected]>
Cc Thomas Gleixner <[email protected]>
[ Cleaned it up a bit. ]
---
 arch/x86/kernel/early_printk.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
arch/x86/kernel/early_printk.c +3 -1
index 89427d8..eec40f5 100644
@@ -175,7 +175,9 @@ static __init void early_serial_init(char *s)
 	}
 
 	if (*s) {
-		if (kstrtoul(s, 0, &baud) < 0 || baud == 0)
+		baud = simple_strtoull(s, &e, 0);
+
+		if (baud == 0 || s == e)
 			baud = DEFAULT_BAUD;
 	}