Skip to contentSkip to conversation

x86/boot: move early_serial_base to .data section

PATCH In review Pingfan Liu 2 participants 4 messages May 7, 2019 – May 8, 2019 x86

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 x86/boot: move early_serial_base to .data section

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.

Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
Cc Jordan Borgner <[email protected]>
---
 arch/x86/boot/compressed/early_serial_console.c | 2 +-
 arch/x86/boot/early_serial_console.c            | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
arch/x86/boot/compressed/early_serial_console.c +1 -1
index 261e81f..624e334 100644
@@ -1,5 +1,5 @@
 #include "misc.h"
 
-int early_serial_base;
+int early_serial_base = -1;
 
 #include "../early_serial_console.c"
arch/x86/boot/early_serial_console.c +1 -1
index 023bf1c..d8de15a 100644
@@ -149,6 +149,6 @@ void console_init(void)
 {
 	parse_earlyprintk();
 
-	if (!early_serial_base)
+	if (early_serial_base <= 0)
 		parse_console_uart8250();
 }
Signature · 1 line
2.7.4
#1 lore raw

PATCH 2/2 x86/boot: push console_init forward

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

Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
Cc Jordan Borgner <[email protected]>
---
 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(-)
arch/x86/boot/compressed/early_serial_console.c +7 -0
index 624e334..223954a 100644
@@ -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");
+}
arch/x86/boot/compressed/head_64.S +4 -0
index fafb75c..e4a25f9 100644
@@ -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,
arch/x86/boot/compressed/misc.c +0 -1
index cafc6aa..475a3c6 100644
@@ -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 */
Signature · 1 line
2.7.4
#2 lore raw
In reply to Pingfan Liu
Quoted 5 lines · Pingfan Liu

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

#3 lore raw
Quoted 8 lines · Ingo Molnar
Quoted 4 lines · Pingfan Liu

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.

Quoted 6 lines
Quoted 1 line

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).

Quoted 3 lines

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