diff mbox series

console: Add console=auto option

Message ID 20180816141055.451-1-prarit@redhat.com (mailing list archive)
State Superseded, archived
Headers show
Series console: Add console=auto option | expand

Commit Message

Prarit Bhargava Aug. 16, 2018, 2:10 p.m. UTC
ACPI may contain an SPCR table that defines a default system console.
On ARM if the table is present then the SPCR console is enabled by default.
On x86 the SPCR console is used if 'earlycon' (no parameters) is
specified as a kernel parameter and is used only as the early console.
To use the SPCR data as a console a user must boot with 'earlycon',
grep logs & specify a console= kernel parameter, and then reboot again.

Add 'console=auto' that enables a firmware or hardware console, and on
x86 enable the SPCR console if 'console=auto' is specified.

Tested on systems with and without an ACPI SPCR.  The following kernel
parameters were also tested:

console=ttyS0,115200    		works
earlycon                		works (early console only)
console=auto            		works (full console as expected)
no console or earlycon arguments	works (no output as expected)

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
Cc: Mark Salter <msalter@redhat.com>
Cc: Al Stone <ahs3@redhat.com>
Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net>
Cc: Len Brown <len.brown@intel.com>
Cc: Pavel Machek <pavel@ucw.cz>
Cc: x86@kernel.org
Cc: Petr Mladek <pmladek@suse.com>
Cc: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Kees Cook <keescook@chromium.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-pm@vger.kernel.org
---
 Documentation/admin-guide/kernel-parameters.txt |  1 +
 arch/x86/kernel/acpi/boot.c                     |  5 +++++
 include/linux/console.h                         |  1 +
 kernel/printk/printk.c                          | 10 ++++++++++
 4 files changed, 17 insertions(+)

Comments

Greg KH Aug. 16, 2018, 3:09 p.m. UTC | #1
On Thu, Aug 16, 2018 at 10:10:55AM -0400, Prarit Bhargava wrote:
> ACPI may contain an SPCR table that defines a default system console.
> On ARM if the table is present then the SPCR console is enabled by default.
> On x86 the SPCR console is used if 'earlycon' (no parameters) is
> specified as a kernel parameter and is used only as the early console.
> To use the SPCR data as a console a user must boot with 'earlycon',
> grep logs & specify a console= kernel parameter, and then reboot again.
> 
> Add 'console=auto' that enables a firmware or hardware console, and on
> x86 enable the SPCR console if 'console=auto' is specified.
> 
> Tested on systems with and without an ACPI SPCR.  The following kernel
> parameters were also tested:
> 
> console=ttyS0,115200    		works
> earlycon                		works (early console only)
> console=auto            		works (full console as expected)
> no console or earlycon arguments	works (no output as expected)
> 
> Signed-off-by: Prarit Bhargava <prarit@redhat.com>
> Cc: Mark Salter <msalter@redhat.com>
> Cc: Al Stone <ahs3@redhat.com>
> Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net>
> Cc: Len Brown <len.brown@intel.com>
> Cc: Pavel Machek <pavel@ucw.cz>
> Cc: x86@kernel.org
> Cc: Petr Mladek <pmladek@suse.com>
> Cc: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
> Cc: Steven Rostedt <rostedt@goodmis.org>
> Cc: Kees Cook <keescook@chromium.org>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: linux-pm@vger.kernel.org
> ---
>  Documentation/admin-guide/kernel-parameters.txt |  1 +
>  arch/x86/kernel/acpi/boot.c                     |  5 +++++
>  include/linux/console.h                         |  1 +
>  kernel/printk/printk.c                          | 10 ++++++++++
>  4 files changed, 17 insertions(+)
> 
> diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
> index a32f2a126791..dd057224f33b 100644
> --- a/Documentation/admin-guide/kernel-parameters.txt
> +++ b/Documentation/admin-guide/kernel-parameters.txt
> @@ -635,6 +635,7 @@
>  
>  		hvc<n>	Use the hypervisor console device <n>. This is for
>  			both Xen and PowerPC hypervisors.
> +		auto	[X86] Enable ACPI SPCR console
>  
>  		If the device connected to the port is not a TTY but a braille
>  		device, prepend "brl," before the device type, for instance
> diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
> index 3b20607d581b..fb2616ba3b21 100644
> --- a/arch/x86/kernel/acpi/boot.c
> +++ b/arch/x86/kernel/acpi/boot.c
> @@ -1771,3 +1771,8 @@ void __init arch_reserve_mem_area(acpi_physical_address addr, size_t size)
>  	e820__range_add(addr, size, E820_TYPE_ACPI);
>  	e820__update_table_print();
>  }
> +
> +void __init arch_console_setup(void)
> +{
> +	acpi_parse_spcr(false, true);
> +}

<snip>

> +int arch_console_setup(void);

Function does not match its prototype :(

How did you build this successfully?
Prarit Bhargava Aug. 16, 2018, 3:28 p.m. UTC | #2
On 08/16/2018 11:09 AM, Greg Kroah-Hartman wrote:
> On Thu, Aug 16, 2018 at 10:10:55AM -0400, Prarit Bhargava wrote:
>> ACPI may contain an SPCR table that defines a default system console.
>> On ARM if the table is present then the SPCR console is enabled by default.
>> On x86 the SPCR console is used if 'earlycon' (no parameters) is
>> specified as a kernel parameter and is used only as the early console.
>> To use the SPCR data as a console a user must boot with 'earlycon',
>> grep logs & specify a console= kernel parameter, and then reboot again.
>>
>> Add 'console=auto' that enables a firmware or hardware console, and on
>> x86 enable the SPCR console if 'console=auto' is specified.
>>
>> Tested on systems with and without an ACPI SPCR.  The following kernel
>> parameters were also tested:
>>
>> console=ttyS0,115200    		works
>> earlycon                		works (early console only)
>> console=auto            		works (full console as expected)
>> no console or earlycon arguments	works (no output as expected)
>>
>> Signed-off-by: Prarit Bhargava <prarit@redhat.com>
>> Cc: Mark Salter <msalter@redhat.com>
>> Cc: Al Stone <ahs3@redhat.com>
>> Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net>
>> Cc: Len Brown <len.brown@intel.com>
>> Cc: Pavel Machek <pavel@ucw.cz>
>> Cc: x86@kernel.org
>> Cc: Petr Mladek <pmladek@suse.com>
>> Cc: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
>> Cc: Steven Rostedt <rostedt@goodmis.org>
>> Cc: Kees Cook <keescook@chromium.org>
>> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
>> Cc: linux-pm@vger.kernel.org
>> ---
>>  Documentation/admin-guide/kernel-parameters.txt |  1 +
>>  arch/x86/kernel/acpi/boot.c                     |  5 +++++
>>  include/linux/console.h                         |  1 +
>>  kernel/printk/printk.c                          | 10 ++++++++++
>>  4 files changed, 17 insertions(+)
>>
>> diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
>> index a32f2a126791..dd057224f33b 100644
>> --- a/Documentation/admin-guide/kernel-parameters.txt
>> +++ b/Documentation/admin-guide/kernel-parameters.txt
>> @@ -635,6 +635,7 @@
>>  
>>  		hvc<n>	Use the hypervisor console device <n>. This is for
>>  			both Xen and PowerPC hypervisors.
>> +		auto	[X86] Enable ACPI SPCR console
>>  
>>  		If the device connected to the port is not a TTY but a braille
>>  		device, prepend "brl," before the device type, for instance
>> diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
>> index 3b20607d581b..fb2616ba3b21 100644
>> --- a/arch/x86/kernel/acpi/boot.c
>> +++ b/arch/x86/kernel/acpi/boot.c
>> @@ -1771,3 +1771,8 @@ void __init arch_reserve_mem_area(acpi_physical_address addr, size_t size)
>>  	e820__range_add(addr, size, E820_TYPE_ACPI);
>>  	e820__update_table_print();
>>  }
>> +
>> +void __init arch_console_setup(void)
>> +{
>> +	acpi_parse_spcr(false, true);
>> +}
> 
> <snip>
> 
>> +int arch_console_setup(void);
> 
> Function does not match its prototype :(
> 
> How did you build this successfully?

Weird, it compiles on my system?

I'll fix it though.

P.

>
Steven Rostedt Aug. 16, 2018, 3:33 p.m. UTC | #3
On Thu, 16 Aug 2018 11:28:24 -0400
Prarit Bhargava <prarit@redhat.com> wrote:

> On 08/16/2018 11:09 AM, Greg Kroah-Hartman wrote:
> > On Thu, Aug 16, 2018 at 10:10:55AM -0400, Prarit Bhargava wrote:  
> >> ACPI may contain an SPCR table that defines a default system console.
> >> On ARM if the table is present then the SPCR console is enabled by default.
> >> On x86 the SPCR console is used if 'earlycon' (no parameters) is
> >> specified as a kernel parameter and is used only as the early console.
> >> To use the SPCR data as a console a user must boot with 'earlycon',
> >> grep logs & specify a console= kernel parameter, and then reboot again.
> >>
> >> Add 'console=auto' that enables a firmware or hardware console, and on
> >> x86 enable the SPCR console if 'console=auto' is specified.
> >>
> >> Tested on systems with and without an ACPI SPCR.  The following kernel
> >> parameters were also tested:
> >>
> >> console=ttyS0,115200    		works
> >> earlycon                		works (early console only)
> >> console=auto            		works (full console as expected)
> >> no console or earlycon arguments	works (no output as expected)
> >>
> >> Signed-off-by: Prarit Bhargava <prarit@redhat.com>
> >> Cc: Mark Salter <msalter@redhat.com>
> >> Cc: Al Stone <ahs3@redhat.com>
> >> Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net>
> >> Cc: Len Brown <len.brown@intel.com>
> >> Cc: Pavel Machek <pavel@ucw.cz>
> >> Cc: x86@kernel.org
> >> Cc: Petr Mladek <pmladek@suse.com>
> >> Cc: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
> >> Cc: Steven Rostedt <rostedt@goodmis.org>
> >> Cc: Kees Cook <keescook@chromium.org>
> >> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> >> Cc: linux-pm@vger.kernel.org
> >> ---
> >>  Documentation/admin-guide/kernel-parameters.txt |  1 +
> >>  arch/x86/kernel/acpi/boot.c                     |  5 +++++
> >>  include/linux/console.h                         |  1 +
> >>  kernel/printk/printk.c                          | 10 ++++++++++
> >>  4 files changed, 17 insertions(+)
> >>
> >> diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
> >> index a32f2a126791..dd057224f33b 100644
> >> --- a/Documentation/admin-guide/kernel-parameters.txt
> >> +++ b/Documentation/admin-guide/kernel-parameters.txt
> >> @@ -635,6 +635,7 @@
> >>  
> >>  		hvc<n>	Use the hypervisor console device <n>. This is for
> >>  			both Xen and PowerPC hypervisors.
> >> +		auto	[X86] Enable ACPI SPCR console
> >>  
> >>  		If the device connected to the port is not a TTY but a braille
> >>  		device, prepend "brl," before the device type, for instance
> >> diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
> >> index 3b20607d581b..fb2616ba3b21 100644
> >> --- a/arch/x86/kernel/acpi/boot.c
> >> +++ b/arch/x86/kernel/acpi/boot.c
> >> @@ -1771,3 +1771,8 @@ void __init arch_reserve_mem_area(acpi_physical_address addr, size_t size)
> >>  	e820__range_add(addr, size, E820_TYPE_ACPI);
> >>  	e820__update_table_print();
> >>  }
> >> +
> >> +void __init arch_console_setup(void)
> >> +{
> >> +	acpi_parse_spcr(false, true);
> >> +}  
> > 
> > <snip>
> >   
> >> +int arch_console_setup(void);  
> > 
> > Function does not match its prototype :(
> > 
> > How did you build this successfully?  
> 
> Weird, it compiles on my system?

Are you compiling with ACPI enabled?

It would still compile without it and use the properly prototyped
"weak" function.

-- Steve

> 
> I'll fix it though.
>
Prarit Bhargava Aug. 16, 2018, 5:23 p.m. UTC | #4
On 08/16/2018 11:33 AM, Steven Rostedt wrote:
> On Thu, 16 Aug 2018 11:28:24 -0400
> Prarit Bhargava <prarit@redhat.com> wrote:
> 
>> On 08/16/2018 11:09 AM, Greg Kroah-Hartman wrote:
>>> On Thu, Aug 16, 2018 at 10:10:55AM -0400, Prarit Bhargava wrote:  
>>>> ACPI may contain an SPCR table that defines a default system console.
>>>> On ARM if the table is present then the SPCR console is enabled by default.
>>>> On x86 the SPCR console is used if 'earlycon' (no parameters) is
>>>> specified as a kernel parameter and is used only as the early console.
>>>> To use the SPCR data as a console a user must boot with 'earlycon',
>>>> grep logs & specify a console= kernel parameter, and then reboot again.
>>>>
>>>> Add 'console=auto' that enables a firmware or hardware console, and on
>>>> x86 enable the SPCR console if 'console=auto' is specified.
>>>>
>>>> Tested on systems with and without an ACPI SPCR.  The following kernel
>>>> parameters were also tested:
>>>>
>>>> console=ttyS0,115200    		works
>>>> earlycon                		works (early console only)
>>>> console=auto            		works (full console as expected)
>>>> no console or earlycon arguments	works (no output as expected)
>>>>
>>>> Signed-off-by: Prarit Bhargava <prarit@redhat.com>
>>>> Cc: Mark Salter <msalter@redhat.com>
>>>> Cc: Al Stone <ahs3@redhat.com>
>>>> Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net>
>>>> Cc: Len Brown <len.brown@intel.com>
>>>> Cc: Pavel Machek <pavel@ucw.cz>
>>>> Cc: x86@kernel.org
>>>> Cc: Petr Mladek <pmladek@suse.com>
>>>> Cc: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
>>>> Cc: Steven Rostedt <rostedt@goodmis.org>
>>>> Cc: Kees Cook <keescook@chromium.org>
>>>> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
>>>> Cc: linux-pm@vger.kernel.org
>>>> ---
>>>>  Documentation/admin-guide/kernel-parameters.txt |  1 +
>>>>  arch/x86/kernel/acpi/boot.c                     |  5 +++++
>>>>  include/linux/console.h                         |  1 +
>>>>  kernel/printk/printk.c                          | 10 ++++++++++
>>>>  4 files changed, 17 insertions(+)
>>>>
>>>> diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
>>>> index a32f2a126791..dd057224f33b 100644
>>>> --- a/Documentation/admin-guide/kernel-parameters.txt
>>>> +++ b/Documentation/admin-guide/kernel-parameters.txt
>>>> @@ -635,6 +635,7 @@
>>>>  
>>>>  		hvc<n>	Use the hypervisor console device <n>. This is for
>>>>  			both Xen and PowerPC hypervisors.
>>>> +		auto	[X86] Enable ACPI SPCR console
>>>>  
>>>>  		If the device connected to the port is not a TTY but a braille
>>>>  		device, prepend "brl," before the device type, for instance
>>>> diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
>>>> index 3b20607d581b..fb2616ba3b21 100644
>>>> --- a/arch/x86/kernel/acpi/boot.c
>>>> +++ b/arch/x86/kernel/acpi/boot.c
>>>> @@ -1771,3 +1771,8 @@ void __init arch_reserve_mem_area(acpi_physical_address addr, size_t size)
>>>>  	e820__range_add(addr, size, E820_TYPE_ACPI);
>>>>  	e820__update_table_print();
>>>>  }
>>>> +
>>>> +void __init arch_console_setup(void)
>>>> +{
>>>> +	acpi_parse_spcr(false, true);
>>>> +}  
>>>
>>> <snip>
>>>   
>>>> +int arch_console_setup(void);  
>>>
>>> Function does not match its prototype :(
>>>
>>> How did you build this successfully?  
>>
>> Weird, it compiles on my system?
> 
> Are you compiling with ACPI enabled?
> 

Yes, CONFIG_ACPI is enabled.

> It would still compile without it and use the properly prototyped
> "weak" function.

I did this:

1.  git co linux.git
2.  git am 0001-console-Add-console-auto-option.patch
3.  make -j224

and I have a clean compile with no warnings or errors.  My config is the
standard Fedora .config so it has CONFIG_ACPI enabled and CONFIG_ACPI_SPCR_TABLE
enabled.

IMO the compile should have warned or error'd out.  Is there a possibility that
some subtlety of weak functions that causes this to not be an error?

In any case, I've changed the prototype and other functions to void and am
finishing up retesting.

P.

> 
> -- Steve
> 
>>
>> I'll fix it though.
>>
diff mbox series

Patch

diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
index a32f2a126791..dd057224f33b 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -635,6 +635,7 @@ 
 
 		hvc<n>	Use the hypervisor console device <n>. This is for
 			both Xen and PowerPC hypervisors.
+		auto	[X86] Enable ACPI SPCR console
 
 		If the device connected to the port is not a TTY but a braille
 		device, prepend "brl," before the device type, for instance
diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
index 3b20607d581b..fb2616ba3b21 100644
--- a/arch/x86/kernel/acpi/boot.c
+++ b/arch/x86/kernel/acpi/boot.c
@@ -1771,3 +1771,8 @@  void __init arch_reserve_mem_area(acpi_physical_address addr, size_t size)
 	e820__range_add(addr, size, E820_TYPE_ACPI);
 	e820__update_table_print();
 }
+
+void __init arch_console_setup(void)
+{
+	acpi_parse_spcr(false, true);
+}
diff --git a/include/linux/console.h b/include/linux/console.h
index dfd6b0e97855..b802f62289a9 100644
--- a/include/linux/console.h
+++ b/include/linux/console.h
@@ -181,6 +181,7 @@  extern int is_console_locked(void);
 extern int braille_register_console(struct console *, int index,
 		char *console_options, char *braille_options);
 extern int braille_unregister_console(struct console *);
+int arch_console_setup(void);
 #ifdef CONFIG_TTY
 extern void console_sysfs_notify(void);
 #else
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 247808333ba4..b74eba44183e 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -2078,6 +2078,11 @@  static int __init console_msg_format_setup(char *str)
 }
 __setup("console_msg_format=", console_msg_format_setup);
 
+int __init __weak arch_console_setup(void)
+{
+	return 0;
+}
+
 /*
  * Set up a console.  Called via do_early_param() in init/main.c
  * for each "console=" parameter in the boot command line.
@@ -2088,6 +2093,11 @@  static int __init console_setup(char *str)
 	char *s, *options, *brl_options = NULL;
 	int idx;
 
+	if (!strcmp(str, "auto")) {
+		arch_console_setup();
+		return 1;
+	}
+
 	if (_braille_console_setup(&str, &brl_options))
 		return 1;