All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86/earlyprintk: setup earlyprintk as early as possible
@ 2015-04-06 13:17 Alexander Kuleshov
  2015-04-07  9:52 ` Ingo Molnar
  0 siblings, 1 reply; 8+ messages in thread
From: Alexander Kuleshov @ 2015-04-06 13:17 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, H. Peter Anvin, Greg Kroah-Hartman
  Cc: linux-kernel, Alexander Kuleshov

As setup_earlyprintk passed to the early_param, it will be usable only after
'parse_early_param' function will be called from the 'setup_arch'. So we have
earlyprintk during early boot and decompression. Next point after decompression
of the kernel where we can use early_printk is after call of the
'parse_early_param'.

This patch removes 'earlyprintk' from the early_param and setup it right after
boot data copying. So 'early_printk' function will be usabable after
decompression of kernel and before parse_early_param will be called.

Signed-off-by: Alexander Kuleshov <kuleshovmail@gmail.com>
---
 arch/x86/kernel/early_printk.c | 4 +---
 arch/x86/kernel/head64.c       | 1 +
 include/linux/printk.h         | 1 +
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
index a62536a..4b0577b 100644
--- a/arch/x86/kernel/early_printk.c
+++ b/arch/x86/kernel/early_printk.c
@@ -329,7 +329,7 @@ static inline void early_console_register(struct console *con, int keep_early)
 	register_console(early_console);
 }
 
-static int __init setup_early_printk(char *buf)
+int __init setup_early_printk(char *buf)
 {
 	int keep;
 
@@ -390,5 +390,3 @@ static int __init setup_early_printk(char *buf)
 	}
 	return 0;
 }
-
-early_param("earlyprintk", setup_early_printk);
diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
index c4f8d46..0141de7 100644
--- a/arch/x86/kernel/head64.c
+++ b/arch/x86/kernel/head64.c
@@ -171,6 +171,7 @@ asmlinkage __visible void __init x86_64_start_kernel(char * real_mode_data)
 	load_idt((const struct desc_ptr *)&idt_descr);
 
 	copy_bootdata(__va(real_mode_data));
+	setup_early_printk(boot_command_line);
 
 	/*
 	 * Load microcode early on BSP.
diff --git a/include/linux/printk.h b/include/linux/printk.h
index baa3f97..47e3919 100644
--- a/include/linux/printk.h
+++ b/include/linux/printk.h
@@ -115,6 +115,7 @@ int no_printk(const char *fmt, ...)
 #ifdef CONFIG_EARLY_PRINTK
 extern asmlinkage __printf(1, 2)
 void early_printk(const char *fmt, ...);
+int setup_early_printk(char *buf);
 #else
 static inline __printf(1, 2) __cold
 void early_printk(const char *s, ...) { }
-- 
2.3.3.611.g09038fc.dirty


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] x86/earlyprintk: setup earlyprintk as early as possible
  2015-04-06 13:17 [PATCH] x86/earlyprintk: setup earlyprintk as early as possible Alexander Kuleshov
@ 2015-04-07  9:52 ` Ingo Molnar
  2015-04-07 10:19   ` Alexander Kuleshov
  0 siblings, 1 reply; 8+ messages in thread
From: Ingo Molnar @ 2015-04-07  9:52 UTC (permalink / raw)
  To: Alexander Kuleshov
  Cc: Thomas Gleixner, Ingo Molnar, H. Peter Anvin, Greg Kroah-Hartman,
	linux-kernel


* Alexander Kuleshov <kuleshovmail@gmail.com> wrote:

> As setup_earlyprintk passed to the early_param, it will be usable only after
> 'parse_early_param' function will be called from the 'setup_arch'. So we have
> earlyprintk during early boot and decompression. Next point after decompression
> of the kernel where we can use early_printk is after call of the
> 'parse_early_param'.
> 
> This patch removes 'earlyprintk' from the early_param and setup it right after
> boot data copying. So 'early_printk' function will be usabable after
> decompression of kernel and before parse_early_param will be called.
> 
> Signed-off-by: Alexander Kuleshov <kuleshovmail@gmail.com>
> ---
>  arch/x86/kernel/early_printk.c | 4 +---
>  arch/x86/kernel/head64.c       | 1 +
>  include/linux/printk.h         | 1 +
>  3 files changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
> index a62536a..4b0577b 100644
> --- a/arch/x86/kernel/early_printk.c
> +++ b/arch/x86/kernel/early_printk.c
> @@ -329,7 +329,7 @@ static inline void early_console_register(struct console *con, int keep_early)
>  	register_console(early_console);
>  }
>  
> -static int __init setup_early_printk(char *buf)
> +int __init setup_early_printk(char *buf)
>  {
>  	int keep;
>  
> @@ -390,5 +390,3 @@ static int __init setup_early_printk(char *buf)
>  	}
>  	return 0;
>  }
> -
> -early_param("earlyprintk", setup_early_printk);
> diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
> index c4f8d46..0141de7 100644
> --- a/arch/x86/kernel/head64.c
> +++ b/arch/x86/kernel/head64.c
> @@ -171,6 +171,7 @@ asmlinkage __visible void __init x86_64_start_kernel(char * real_mode_data)
>  	load_idt((const struct desc_ptr *)&idt_descr);
>  
>  	copy_bootdata(__va(real_mode_data));
> +	setup_early_printk(boot_command_line);
>  
>  	/*
>  	 * Load microcode early on BSP.
> diff --git a/include/linux/printk.h b/include/linux/printk.h
> index baa3f97..47e3919 100644
> --- a/include/linux/printk.h
> +++ b/include/linux/printk.h
> @@ -115,6 +115,7 @@ int no_printk(const char *fmt, ...)
>  #ifdef CONFIG_EARLY_PRINTK
>  extern asmlinkage __printf(1, 2)
>  void early_printk(const char *fmt, ...);
> +int setup_early_printk(char *buf);
>  #else
>  static inline __printf(1, 2) __cold
>  void early_printk(const char *s, ...) { }

This looks useful.

It would be nice to test it via a well placed printk() and check that 
before the patch the message doesn't go to the serial console and 
after the patch the message indeed arrives on the early serial console 
- or something like that.

Thanks,

	Ingo

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] x86/earlyprintk: setup earlyprintk as early as possible
  2015-04-07  9:52 ` Ingo Molnar
@ 2015-04-07 10:19   ` Alexander Kuleshov
  2015-04-07 10:24     ` Ingo Molnar
  0 siblings, 1 reply; 8+ messages in thread
From: Alexander Kuleshov @ 2015-04-07 10:19 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: Thomas Gleixner, Ingo Molnar, H. Peter Anvin, Greg Kroah-Hartman, LKML

2015-04-07 15:52 GMT+06:00 Ingo Molnar <mingo@kernel.org>:
>
> It would be nice to test it via a well placed printk() and check that
> before the patch the message doesn't go to the serial console and
> after the patch the message indeed arrives on the early serial console
> - or something like that.

I have tested this patch when i wrote it and early_printk does not print
anything before the parse_early_param. But i don't know how to show this
in code in a correct way. Maybe we should to give back early_printk call
which i removed in the previous patch
(https://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git/commit/?id=91d8f0416f3989e248d3a3d3efb821eda10a85d2)?

Any one another question about this. I submited patch only for head64.c
and it does not affect kernel for i386, because i'm not sure where is
the best place to setup earlyprintk in the head32.c. I thought to put
it in the start of i386_start_kernel(void) (from head32.c) but not sure
about it.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] x86/earlyprintk: setup earlyprintk as early as possible
  2015-04-07 10:19   ` Alexander Kuleshov
@ 2015-04-07 10:24     ` Ingo Molnar
  2015-04-07 10:31       ` Alexander Kuleshov
  0 siblings, 1 reply; 8+ messages in thread
From: Ingo Molnar @ 2015-04-07 10:24 UTC (permalink / raw)
  To: Alexander Kuleshov
  Cc: Thomas Gleixner, Ingo Molnar, H. Peter Anvin, Greg Kroah-Hartman, LKML


* Alexander Kuleshov <kuleshovmail@gmail.com> wrote:

> 2015-04-07 15:52 GMT+06:00 Ingo Molnar <mingo@kernel.org>:
> >
> > It would be nice to test it via a well placed printk() and check that
> > before the patch the message doesn't go to the serial console and
> > after the patch the message indeed arrives on the early serial console
> > - or something like that.
> 
> I have tested this patch when i wrote it and early_printk does not print
> anything before the parse_early_param. But i don't know how to show this
> in code in a correct way. [...]

Just add a debug printk() for your own testing, right after the param 
initialization call, to be confident that the early console indeed 
works.

> which i removed in the previous patch
> (https://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git/commit/?id=91d8f0416f3989e248d3a3d3efb821eda10a85d2)?
> 
> Any one another question about this. I submited patch only for 
> head64.c and it does not affect kernel for i386, because i'm not 
> sure where is the best place to setup earlyprintk in the head32.c. I 
> thought to put it in the start of i386_start_kernel(void) (from 
> head32.c) but not sure about it.

I'd use i386_start_kernel() on 32-bit and x86_64_start_kernel() on 
64-bit - but I haven't tested whether it actually works.

Thanks,

	Ingo

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] x86/earlyprintk: setup earlyprintk as early as possible
  2015-04-07 10:24     ` Ingo Molnar
@ 2015-04-07 10:31       ` Alexander Kuleshov
  2015-04-07 10:33         ` Ingo Molnar
  2015-04-07 19:07         ` Yinghai Lu
  0 siblings, 2 replies; 8+ messages in thread
From: Alexander Kuleshov @ 2015-04-07 10:31 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: Thomas Gleixner, Ingo Molnar, H. Peter Anvin, Greg Kroah-Hartman, LKML

> Ingo Molnar <mingo@kernel.org>: wrote:
>
> Just add a debug printk() for your own testing, right after the param
> initialization call, to be confident that the early console indeed
> works.
>

I already tested it as you said when was writing this patch and it works.

>
> I'd use i386_start_kernel() on 32-bit and x86_64_start_kernel() on
> 64-bit - but I haven't tested whether it actually works.
>

As i already wrote, i tested it for x86_64 and it works. I will put earlyprintk
setup in the start of the i386_start_kernel, will test it with 32-bit
and resend two
patches if they will be good.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] x86/earlyprintk: setup earlyprintk as early as possible
  2015-04-07 10:31       ` Alexander Kuleshov
@ 2015-04-07 10:33         ` Ingo Molnar
  2015-04-07 19:07         ` Yinghai Lu
  1 sibling, 0 replies; 8+ messages in thread
From: Ingo Molnar @ 2015-04-07 10:33 UTC (permalink / raw)
  To: Alexander Kuleshov
  Cc: Thomas Gleixner, Ingo Molnar, H. Peter Anvin, Greg Kroah-Hartman, LKML


* Alexander Kuleshov <kuleshovmail@gmail.com> wrote:

> > Ingo Molnar <mingo@kernel.org>: wrote:
> >
> > Just add a debug printk() for your own testing, right after the param
> > initialization call, to be confident that the early console indeed
> > works.
> >
> 
> I already tested it as you said when was writing this patch and it works.

The changelog does not tell us this and it should.

Thanks,

	Ingo

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] x86/earlyprintk: setup earlyprintk as early as possible
  2015-04-07 10:31       ` Alexander Kuleshov
  2015-04-07 10:33         ` Ingo Molnar
@ 2015-04-07 19:07         ` Yinghai Lu
  2015-04-07 19:08           ` Yinghai Lu
  1 sibling, 1 reply; 8+ messages in thread
From: Yinghai Lu @ 2015-04-07 19:07 UTC (permalink / raw)
  To: Alexander Kuleshov
  Cc: Ingo Molnar, Thomas Gleixner, Ingo Molnar, H. Peter Anvin,
	Greg Kroah-Hartman, LKML

[-- Attachment #1: Type: text/plain, Size: 684 bytes --]

On Tue, Apr 7, 2015 at 3:31 AM, Alexander Kuleshov
<kuleshovmail@gmail.com> wrote:

>
> As i already wrote, i tested it for x86_64 and it works. I will put earlyprintk
> setup in the start of the i386_start_kernel, will test it with 32-bit
> and resend two
> patches if they will be good.

No, that is not enough.
early_printk would handle not only serial console with io port accessing.
You need to make sure all other path including pciserial/dbgp/efi is safe.
They are using early_ioremap, and you can not call early_ioremap()
before early_ioremap.

otherwise you may need to just search "serial string in boot command line" like
i did in moving earlycon early patch.

    Yinghai

[-- Attachment #2: setup_early_console_x1_pa_symbol_before_earlcon.patch --]
[-- Type: text/x-patch, Size: 4256 bytes --]

Subject: [PATCH -v5] x86: Setup early console as early as possible in x86_start_kernel()

Analyze "console=uart8250,io,0x3f8,115200n8" in i386_start_kernel/x86_64_start_kernel,
and call setup_early_serial8250_console() to init early serial console.

Only can handle io port kind of 8250, because mmio need ioremap.

Use boot_params.hdr.version instead of adding another variable, Suggested by hpa.
Also need to apply this one after x86 memblock patchset.

-v5: fix check when console string is last one in command line.
	should use strchrnul(,' ') instead strchr(,' ') for end searching.

Signed-off-by: Yinghai Lu <yinghai@kernel.org>
---
 arch/x86/include/asm/setup.h |    2 ++
 arch/x86/kernel/head.c       |   26 ++++++++++++++++++++++++++
 arch/x86/kernel/head32.c     |    1 +
 arch/x86/kernel/head64.c     |    5 ++++-
 kernel/printk/printk.c       |   11 +++++++----
 5 files changed, 40 insertions(+), 5 deletions(-)

Index: linux-2.6/arch/x86/include/asm/setup.h
===================================================================
--- linux-2.6.orig/arch/x86/include/asm/setup.h
+++ linux-2.6/arch/x86/include/asm/setup.h
@@ -40,6 +40,8 @@ static inline void vsmp_init(void) { }
 void setup_bios_corruption_check(void);
 
 extern unsigned long saved_video_mode;
+int setup_early_serial8250_console(char *cmdline);
+void setup_early_console(void);
 
 extern void reserve_standard_io_resources(void);
 extern void i386_reserve_resources(void);
Index: linux-2.6/arch/x86/kernel/head.c
===================================================================
--- linux-2.6.orig/arch/x86/kernel/head.c
+++ linux-2.6/arch/x86/kernel/head.c
@@ -69,3 +69,29 @@ void __init reserve_ebda_region(void)
 	/* reserve all memory between lowmem and the 1MB mark */
 	memblock_reserve(lowmem, 0x100000 - lowmem);
 }
+
+void __init setup_early_console(void)
+{
+#ifdef CONFIG_SERIAL_8250_CONSOLE
+	char constr[64], *p, *q;
+
+	/* Can not handle mmio type 8250 uart yet, too early */
+	p = strstr(boot_command_line, "console=uart8250,io,");
+	if (!p)
+		p = strstr(boot_command_line, "console=uart,io,");
+	if (!p)
+		return;
+
+	p += 8;	/* sizeof "console=" */
+	q = strchrnul(p, ' ');
+	if ((q - p) >= sizeof(constr))
+		return;
+
+	memset(constr, 0, sizeof(constr));
+	memcpy(constr, p, q - p);
+
+	lockdep_init();
+
+	setup_early_serial8250_console(constr);
+#endif
+}
Index: linux-2.6/arch/x86/kernel/head32.c
===================================================================
--- linux-2.6.orig/arch/x86/kernel/head32.c
+++ linux-2.6/arch/x86/kernel/head32.c
@@ -33,6 +33,7 @@ asmlinkage __visible void __init i386_st
 {
 	cr4_init_shadow();
 	sanitize_boot_params(&boot_params);
+	setup_early_console();
 
 	/* Call the subarch specific early setup function */
 	switch (boot_params.hdr.hardware_subarch) {
Index: linux-2.6/arch/x86/kernel/head64.c
===================================================================
--- linux-2.6.orig/arch/x86/kernel/head64.c
+++ linux-2.6/arch/x86/kernel/head64.c
@@ -171,6 +171,7 @@ asmlinkage __visible void __init x86_64_
 	load_idt((const struct desc_ptr *)&idt_descr);
 
 	copy_bootdata(__va(real_mode_data));
+	setup_early_console();
 
 	/*
 	 * Load microcode early on BSP.
@@ -192,8 +193,10 @@ asmlinkage __visible void __init x86_64_
 void __init x86_64_start_reservations(char *real_mode_data)
 {
 	/* version is always not zero if it is copied */
-	if (!boot_params.hdr.version)
+	if (!boot_params.hdr.version) {
 		copy_bootdata(__va(real_mode_data));
+		setup_early_console();
+	}
 
 	reserve_ebda_region();
 
Index: linux-2.6/kernel/printk/printk.c
===================================================================
--- linux-2.6.orig/kernel/printk/printk.c
+++ linux-2.6/kernel/printk/printk.c
@@ -2409,11 +2409,14 @@ void register_console(struct console *ne
 	struct console_cmdline *c;
 
 	if (console_drivers)
-		for_each_console(bcon)
-			if (WARN(bcon == newcon,
-					"console '%s%d' already registered\n",
-					bcon->name, bcon->index))
+		for_each_console(bcon) {
+			/* not again */
+			if (bcon == newcon) {
+				printk(KERN_INFO "console '%s%d' already registered\n",
+					bcon->name, bcon->index);
 				return;
+			}
+	}
 
 	/*
 	 * before we register a new CON_BOOT console, make sure we don't

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] x86/earlyprintk: setup earlyprintk as early as possible
  2015-04-07 19:07         ` Yinghai Lu
@ 2015-04-07 19:08           ` Yinghai Lu
  0 siblings, 0 replies; 8+ messages in thread
From: Yinghai Lu @ 2015-04-07 19:08 UTC (permalink / raw)
  To: Alexander Kuleshov
  Cc: Ingo Molnar, Thomas Gleixner, Ingo Molnar, H. Peter Anvin,
	Greg Kroah-Hartman, LKML

On Tue, Apr 7, 2015 at 12:07 PM, Yinghai Lu <yinghai@kernel.org> wrote:
> On Tue, Apr 7, 2015 at 3:31 AM, Alexander Kuleshov
> <kuleshovmail@gmail.com> wrote:
>
>>
>> As i already wrote, i tested it for x86_64 and it works. I will put earlyprintk
>> setup in the start of the i386_start_kernel, will test it with 32-bit
>> and resend two
>> patches if they will be good.
>
> No, that is not enough.
> early_printk would handle not only serial console with io port accessing.
> You need to make sure all other path including pciserial/dbgp/efi is safe.
> They are using early_ioremap, and you can not call early_ioremap()
> before early_ioremap.

They are using early_ioremap, and you can not call early_ioremap()
before early_ioremap_init.

>
> otherwise you may need to just search "serial string in boot command line" like
> i did in moving earlycon early patch.
>
>     Yinghai

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2015-04-07 19:08 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-06 13:17 [PATCH] x86/earlyprintk: setup earlyprintk as early as possible Alexander Kuleshov
2015-04-07  9:52 ` Ingo Molnar
2015-04-07 10:19   ` Alexander Kuleshov
2015-04-07 10:24     ` Ingo Molnar
2015-04-07 10:31       ` Alexander Kuleshov
2015-04-07 10:33         ` Ingo Molnar
2015-04-07 19:07         ` Yinghai Lu
2015-04-07 19:08           ` Yinghai Lu

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.