All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] x86/boot: move early_serial_base to .data section
@ 2019-05-07  6:00 Pingfan Liu
  2019-05-07  6:01 ` [PATCH 2/2] x86/boot: push console_init forward Pingfan Liu
  2019-05-07  8:28 ` [PATCH 1/2] x86/boot: move early_serial_base to .data section Ingo Molnar
  0 siblings, 2 replies; 4+ messages in thread
From: Pingfan Liu @ 2019-05-07  6:00 UTC (permalink / raw)
  To: x86
  Cc: Pingfan Liu, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	H. Peter Anvin, Jordan Borgner, linux-kernel

arch/x86/boot/compressed/head_64.S clears BSS after relocated. If early
serial is set up before clearing BSS, the early_serial_base will be reset
to 0.

Initializing early_serial_base as -1 to push it to .data section.

Signed-off-by: Pingfan Liu <kernelfans@gmail.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Jordan Borgner <mail@jordan-borgner.de>
Cc: linux-kernel@vger.kernel.org
---
 arch/x86/boot/compressed/early_serial_console.c | 2 +-
 arch/x86/boot/early_serial_console.c            | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/boot/compressed/early_serial_console.c b/arch/x86/boot/compressed/early_serial_console.c
index 261e81f..624e334 100644
--- a/arch/x86/boot/compressed/early_serial_console.c
+++ b/arch/x86/boot/compressed/early_serial_console.c
@@ -1,5 +1,5 @@
 #include "misc.h"
 
-int early_serial_base;
+int early_serial_base = -1;
 
 #include "../early_serial_console.c"
diff --git a/arch/x86/boot/early_serial_console.c b/arch/x86/boot/early_serial_console.c
index 023bf1c..d8de15a 100644
--- a/arch/x86/boot/early_serial_console.c
+++ b/arch/x86/boot/early_serial_console.c
@@ -149,6 +149,6 @@ void console_init(void)
 {
 	parse_earlyprintk();
 
-	if (!early_serial_base)
+	if (early_serial_base <= 0)
 		parse_console_uart8250();
 }
-- 
2.7.4


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

* [PATCH 2/2] x86/boot: push console_init forward
  2019-05-07  6:00 [PATCH 1/2] x86/boot: move early_serial_base to .data section Pingfan Liu
@ 2019-05-07  6:01 ` Pingfan Liu
  2019-05-07  8:28 ` [PATCH 1/2] x86/boot: move early_serial_base to .data section Ingo Molnar
  1 sibling, 0 replies; 4+ messages in thread
From: Pingfan Liu @ 2019-05-07  6:01 UTC (permalink / raw)
  To: x86
  Cc: Pingfan Liu, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	H. Peter Anvin, Jordan Borgner, linux-kernel

At the very early boot stage, early console is badly needed. Push its
initialization as early as possible, just after stack is ready.

Signed-off-by: Pingfan Liu <kernelfans@gmail.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Jordan Borgner <mail@jordan-borgner.de>
Cc: linux-kernel@vger.kernel.org
---
 arch/x86/boot/compressed/early_serial_console.c | 7 +++++++
 arch/x86/boot/compressed/head_64.S              | 4 ++++
 arch/x86/boot/compressed/misc.c                 | 1 -
 3 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/arch/x86/boot/compressed/early_serial_console.c b/arch/x86/boot/compressed/early_serial_console.c
index 624e334..223954a 100644
--- a/arch/x86/boot/compressed/early_serial_console.c
+++ b/arch/x86/boot/compressed/early_serial_console.c
@@ -3,3 +3,10 @@
 int early_serial_base = -1;
 
 #include "../early_serial_console.c"
+
+void early_console_init(void *rmode)
+{
+	boot_params = rmode;
+	console_init();
+	debug_putstr("early console is ready\n");
+}
diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
index fafb75c..e4a25f9 100644
--- a/arch/x86/boot/compressed/head_64.S
+++ b/arch/x86/boot/compressed/head_64.S
@@ -323,6 +323,10 @@ ENTRY(startup_64)
 	subq	$1b, %rdi
 
 	call	adjust_got
+	pushq	%rsi
+	movq	%rsi, %rdi
+	call	early_console_init
+	popq	%rsi
 
 	/*
 	 * At this point we are in long mode with 4-level paging enabled,
diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
index cafc6aa..475a3c6 100644
--- a/arch/x86/boot/compressed/misc.c
+++ b/arch/x86/boot/compressed/misc.c
@@ -368,7 +368,6 @@ asmlinkage __visible void *extract_kernel(void *rmode, memptr heap,
 	lines = boot_params->screen_info.orig_video_lines;
 	cols = boot_params->screen_info.orig_video_cols;
 
-	console_init();
 	debug_putstr("early console in extract_kernel\n");
 
 	free_mem_ptr     = heap;	/* Heap */
-- 
2.7.4


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

* Re: [PATCH 1/2] x86/boot: move early_serial_base to .data section
  2019-05-07  6:00 [PATCH 1/2] x86/boot: move early_serial_base to .data section Pingfan Liu
  2019-05-07  6:01 ` [PATCH 2/2] x86/boot: push console_init forward Pingfan Liu
@ 2019-05-07  8:28 ` Ingo Molnar
  2019-05-08  4:42   ` Pingfan Liu
  1 sibling, 1 reply; 4+ messages in thread
From: Ingo Molnar @ 2019-05-07  8:28 UTC (permalink / raw)
  To: Pingfan Liu, H. Peter Anvin, Borislav Petkov, Thomas Gleixner,
	Peter Zijlstra, Kees Cook
  Cc: x86, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	H. Peter Anvin, Jordan Borgner, linux-kernel


* Pingfan Liu <kernelfans@gmail.com> wrote:

> arch/x86/boot/compressed/head_64.S clears BSS after relocated. If early
> serial is set up before clearing BSS, the early_serial_base will be reset
> to 0.
> 
> Initializing early_serial_base as -1 to push it to .data section.

I'm wondering whether it's wise to clear the BSS after relocation to 
begin with. It already gets cleared once, and an implicit zeroing of all 
fields on kernel relocation sounds dubious to me.

Is there a strong reason for that? I.e. is there some uninitialized or 
otherwise important-to-clear data there?

Thanks,

	Ingo

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

* Re: [PATCH 1/2] x86/boot: move early_serial_base to .data section
  2019-05-07  8:28 ` [PATCH 1/2] x86/boot: move early_serial_base to .data section Ingo Molnar
@ 2019-05-08  4:42   ` Pingfan Liu
  0 siblings, 0 replies; 4+ messages in thread
From: Pingfan Liu @ 2019-05-08  4:42 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: H. Peter Anvin, Borislav Petkov, Thomas Gleixner, Peter Zijlstra,
	Kees Cook, x86, Ingo Molnar, Jordan Borgner, LKML

On Tue, May 7, 2019 at 4:28 PM Ingo Molnar <mingo@kernel.org> wrote:
>
>
> * Pingfan Liu <kernelfans@gmail.com> wrote:
>
> > arch/x86/boot/compressed/head_64.S clears BSS after relocated. If early
> > serial is set up before clearing BSS, the early_serial_base will be reset
> > to 0.
> >
> > Initializing early_serial_base as -1 to push it to .data section.
>
> I'm wondering whether it's wise to clear the BSS after relocation to
> begin with. It already gets cleared once, and an implicit zeroing of all
> fields on kernel relocation sounds dubious to me.
>
After reading the code more closely, I think that the BSS is not fully
initialized to 0, exception the stack and heap.

Furthermore the BSS is not copied to the target address. We just copy [0, _bss).
> Is there a strong reason for that? I.e. is there some uninitialized or
> otherwise important-to-clear data there?
>
I guess the reason may be stack or heap can contain some position
dependent data. (While in practice, there is no such kind of data in
the code now days)

Thanks,
Pingfan

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

end of thread, other threads:[~2019-05-08  4:43 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-07  6:00 [PATCH 1/2] x86/boot: move early_serial_base to .data section Pingfan Liu
2019-05-07  6:01 ` [PATCH 2/2] x86/boot: push console_init forward Pingfan Liu
2019-05-07  8:28 ` [PATCH 1/2] x86/boot: move early_serial_base to .data section Ingo Molnar
2019-05-08  4:42   ` Pingfan Liu

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.