Skip to contentSkip to conversation

instant reboot caused by 194a9749c73d650c0

DISCUSSION Eric Dumazet 3 participants 6 messages Apr 15, 2018 – Apr 17, 2018 x86

lore
Share & tools
lore
#0 lore raw

Hi Kirill

For some reason, my hosts instantly crash at boot time, with absolutely no log on console.

Bisection pointed to :

$ git bisect bad
194a9749c73d650c0b1dfdee04fb0bdf0a888ba8 is the first bad commit
commit 194a9749c73d650c0b1dfdee04fb0bdf0a888ba8
Author: Kirill A. Shutemov <[email protected]>
Date:   Mon Mar 12 13:02:46 2018 +0300

x86/boot/compressed/64: Handle 5-level paging boot if kernel is above 4G

This patch addresses a shortcoming in current boot process on machines that supports 5-level paging.

If a bootloader enables 64-bit mode with 4-level paging, we might need to switch over to 5-level paging. The switching requires the disabling paging. It works fine if kernel itself is loaded below 4G.

But if the bootloader put the kernel above 4G (not sure if anybody does this), we would lose control as soon as paging is disabled, because the code becomes unreachable to the CPU.

This patch implements a trampoline in lower memory to handle this situation.

We only need the memory for a very short time, until the main kernel image sets up own page tables.

We go through the trampoline even if we don't have to: if we're already in 5-level paging mode or if we don't need to switch to it. This way the trampoline gets tested on every boot.

Cc Andy Lutomirski <[email protected]>
Cc Andy Lutomirski <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Brian Gerst <[email protected]>
Cc Cyrill Gorcunov <[email protected]>
Cc Denys Vlasenko <[email protected]>
Cc H. Peter Anvin <[email protected]>
Cc Josh Poimboeuf <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Matthew Wilcox <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Thomas Gleixner <[email protected]>

Reverting this patch solves the problem for me.

Thanks.

#1 lore raw
Quoted 6 lines · Eric Dumazet

Hi Kirill

For some reason, my hosts instantly crash at boot time, with absolutely no log on console.

Bisection pointed to :

Quoted 7 lines
$ git bisect bad
194a9749c73d650c0b1dfdee04fb0bdf0a888ba8 is the first bad commit
commit 194a9749c73d650c0b1dfdee04fb0bdf0a888ba8
Author: Kirill A. Shutemov <[email protected]>
Date:   Mon Mar 12 13:02:46 2018 +0300

x86/boot/compressed/64: Handle 5-level paging boot if kernel is above 4G

Could you please send your .config? These early boot problems are sometimes build and Kconfig environment sensitive.

A high level description of your hardware and the distro you are using would also be useful.

Kirill, I'm curious about this change:

-       /* Calculate address we are running at */
-       call    1f
-1:     popl    %edi
-       subl    $1b, %edi
+       /* Calculate address of paging_enabled() once we are executing in the 

trampoline */
+ leal paging_enabled - trampoline_32bit_src + TRAMPOLINE_32BIT_CODE_OFFSET(%ecx), %eax

Here we change the calculation from a "discover where we are executing" method to a calculation method (which is fundamentally more fragile) - why?

Thanks,

Ingo

#2 lore raw
Quoted 15 lines · Ingo Molnar
Quoted 12 lines · Eric Dumazet

Hi Kirill

For some reason, my hosts instantly crash at boot time, with absolutely no log on console.

Bisection pointed to :

$ git bisect bad
194a9749c73d650c0b1dfdee04fb0bdf0a888ba8 is the first bad commit
commit 194a9749c73d650c0b1dfdee04fb0bdf0a888ba8
Author: Kirill A. Shutemov <[email protected]>
Date:   Mon Mar 12 13:02:46 2018 +0300
Quoted 7 lines
Quoted 1 line

x86/boot/compressed/64: Handle 5-level paging boot if kernel is above 4G

Could you please send your .config? These early boot problems are sometimes build and Kconfig environment sensitive.

A high level description of your hardware and the distro you are using would also be useful.

And how do you start the kernel? EFI? Legacy boot? kexec?

Quoted 11 lines

Kirill, I'm curious about this change:

(quoted diff) +1 -4
-       /* Calculate address we are running at */
-       call    1f
-1:     popl    %edi
-       subl    $1b, %edi
+       /* Calculate address of paging_enabled() once we are executing in the 

trampoline */
+ leal paging_enabled - trampoline_32bit_src + TRAMPOLINE_32BIT_CODE_OFFSET(%ecx), %eax

Quoted 2 lines

Here we change the calculation from a "discover where we are executing" method to a calculation method (which is fundamentally more fragile) - why?

I guess, I tried to save one register -- %rdi is used for return from trampoline.

But you're right there's no reason to do this and it may be more fragile.

Eric, could you check if the patch makes any difference?

arch/x86/boot/compressed/head_64.S +4 -1
index fca012baba19..395c122ef70b 100644
@@ -562,7 +562,10 @@ ENTRY(trampoline_32bit_src)
 	movl	%eax, %cr4
 
 	/* Calculate address of paging_enabled() once we are executing in the trampoline */
-	leal	paging_enabled - trampoline_32bit_src + TRAMPOLINE_32BIT_CODE_OFFSET(%ecx), %eax
+	call	1f
+1:	popl	%eax
+	subl	$1b, %eax
+	leal	paging_enabled(%eax), %eax
 
 	/* Prepare the stack for far return to Long Mode */
 	pushl	$__KERNEL_CS
arch/x86/boot/compressed/pgtable.h +1 -1
index 91f75638f6e6..6ff7e81b5628 100644
@@ -6,7 +6,7 @@
 #define TRAMPOLINE_32BIT_PGTABLE_OFFSET	0
 
 #define TRAMPOLINE_32BIT_CODE_OFFSET	PAGE_SIZE
-#define TRAMPOLINE_32BIT_CODE_SIZE	0x60
+#define TRAMPOLINE_32BIT_CODE_SIZE	0x70
 
 #define TRAMPOLINE_32BIT_STACK_END	TRAMPOLINE_32BIT_SIZE
 
Signature · 1 line
 Kirill A. Shutemov
#3 lore raw
Quoted 69 lines · Kirill A. Shutemov
Quoted 15 lines · Ingo Molnar
Quoted 12 lines · Eric Dumazet

Hi Kirill

For some reason, my hosts instantly crash at boot time, with absolutely no log on console.

Bisection pointed to :

$ git bisect bad
194a9749c73d650c0b1dfdee04fb0bdf0a888ba8 is the first bad commit
commit 194a9749c73d650c0b1dfdee04fb0bdf0a888ba8
Author: Kirill A. Shutemov <[email protected]>
Date:   Mon Mar 12 13:02:46 2018 +0300
Quoted 7 lines
Quoted 1 line

x86/boot/compressed/64: Handle 5-level paging boot if kernel is above 4G

Could you please send your .config? These early boot problems are sometimes build and Kconfig environment sensitive.

A high level description of your hardware and the distro you are using would also be useful.

And how do you start the kernel? EFI? Legacy boot? kexec?

Quoted 11 lines

Kirill, I'm curious about this change:

(quoted diff) +1 -4
-       /* Calculate address we are running at */
-       call    1f
-1:     popl    %edi
-       subl    $1b, %edi
+       /* Calculate address of paging_enabled() once we are executing in the 

trampoline */
+ leal paging_enabled - trampoline_32bit_src + TRAMPOLINE_32BIT_CODE_OFFSET(%ecx), %eax

Quoted 2 lines

Here we change the calculation from a "discover where we are executing" method to a calculation method (which is fundamentally more fragile) - why?

I guess, I tried to save one register -- %rdi is used for return from trampoline.

But you're right there's no reason to do this and it may be more fragile.

Eric, could you check if the patch makes any difference?

arch/x86/boot/compressed/head_64.S +4 -1
index fca012baba19..395c122ef70b 100644
@@ -562,7 +562,10 @@ ENTRY(trampoline_32bit_src)
 	movl	%eax, %cr4
 
 	/* Calculate address of paging_enabled() once we are executing in the trampoline */
-	leal	paging_enabled - trampoline_32bit_src + TRAMPOLINE_32BIT_CODE_OFFSET(%ecx), %eax
+	call	1f
+1:	popl	%eax
+	subl	$1b, %eax
+	leal	paging_enabled(%eax), %eax
 
 	/* Prepare the stack for far return to Long Mode */
 	pushl	$__KERNEL_CS
arch/x86/boot/compressed/pgtable.h +0 -0
index 91f75638f6e6..6ff7e81b5628 100644

arch/x86/boot/compressed/pgtable.h line 12

Quoted 8 lines
arch/x86/boot/compressed/pgtable.h +1 -1
@@ -6,7 +6,7 @@
 #define TRAMPOLINE_32BIT_PGTABLE_OFFSET	0
 
 #define TRAMPOLINE_32BIT_CODE_OFFSET	PAGE_SIZE
-#define TRAMPOLINE_32BIT_CODE_SIZE	0x60
+#define TRAMPOLINE_32BIT_CODE_SIZE	0x70
 
 #define TRAMPOLINE_32BIT_STACK_END	TRAMPOLINE_32BIT_SIZE
 

Hi Kirill

This patch did not help.

In the mean time, Greg told me that using gcc-4.9 instead of our old gcc-4.7 based toolchain was working better.

Thanks !

#4 lore raw
Quoted 5 lines · Eric Dumazet

On 04/16/2018 02:15 AM, Kirill A. Shutemov wrote:
In the mean time, Greg told me that using gcc-4.9 instead of our old gcc-4.7 based toolchain was working better.

Hm. Are you saing that switching from gcc-4.7 to gcc-4.9 fixed the issue for you? That's worth investigating.

Signature · 1 line
 Kirill A. Shutemov
#5 lore raw
Quoted 9 lines · Kirill A. Shutemov
Quoted 5 lines · Eric Dumazet

On 04/16/2018 02:15 AM, Kirill A. Shutemov wrote:
In the mean time, Greg told me that using gcc-4.9 instead of our old gcc-4.7 based toolchain was working better.

Hm. Are you saing that switching from gcc-4.7 to gcc-4.9 fixed the issue for you? That's worth investigating.

Checked kernel build with gcc-4.6 and it boots fine...

Signature · 1 line
 Kirill A. Shutemov