x86/head_64.S: remove redundant check that kernel address is 2M aligned
RFC PATCH 1/1 x86/head_64.S: remove redundant check that kernel address is 2M aligned
We check that the base address of the kernel is 2M aligned in the arch/x86/kernel/head_65.S right after jump to the decompressed kernel. But we already have a check in the decompress_kernel() which validates that kernel location is MIN_KERNEL_ALIGN aligned which is 2M too for x86_64.
--- arch/x86/kernel/head_64.S | 6 ------ 1 file changed, 6 deletions(-)
arch/x86/kernel/head_64.S +0 -6
@@ -75,12 +75,6 @@ startup_64: leaq _text(%rip), %rbp subq $_text - __START_KERNEL_map, %rbp - /* Is the address not 2M aligned? */ - movq %rbp, %rax - andl $~PMD_PAGE_MASK, %eax - testl %eax, %eax - jnz bad_address - /* * Is the address too large? */
Signature · 1 line
2.7.0.25.gfc10eb5
Quoted 18 lines · Alexander Kuleshov
We check that the base address of the kernel is 2M aligned in the
arch/x86/kernel/head_65.Sright after jump to the decompressed kernel. But we already have a check in thedecompress_kernel()which validates that kernel location isMIN_KERNEL_ALIGNaligned which is 2M too forx86_64.Signed-off-by Alexander Kuleshov <[email protected]>--- arch/x86/kernel/head_64.S | 6 ------ 1 file changed, 6 deletions(-)arch/x86/kernel/head_64.S +0
-0@@ -75,12 +75,6 @@ startup_64: leaq _text(%rip), %rbp subq $_text - __START_KERNEL_map, %rbp
arch/x86/kernel/head_64.S startup_64: · line 80
Quoted 10 lines
arch/x86/kernel/head_64.S +0
-6- /* Is the address not 2M aligned? */ - movq %rbp, %rax - andl $~PMD_PAGE_MASK, %eax - testl %eax, %eax - jnz bad_address - /* * Is the address too large? */
I think we still need to do the check, in case we came from a 64-bit bootloader that directly jumped to startup_64. However, this check can be simplified to:
testl $~PMD_PAGE_MASK, %ebp
jnz bad_address
--
Brian Gerst
Hello Brian,
Quoted 11 lines · Brian Gerst
arch/x86/kernel/head_64.S startup_64: · line 80
Quoted 10 lines
arch/x86/kernel/head_64.S +0
-6- /* Is the address not 2M aligned? */ - movq %rbp, %rax - andl $~PMD_PAGE_MASK, %eax - testl %eax, %eax - jnz bad_address - /* * Is the address too large? */
Quoted 6 lines
I think we still need to do the check, in case we came from a 64-bit bootloader that directly jumped to
startup_64. However, this check can be simplified to:testl $~PMD_PAGE_MASK, %ebp
jnzbad_address
Ah, ok, in this way we can't trust a bootloader. I just thought that 64-bit entry point is startup_64 from arch/x86/boot/compressed/head_64.S
Thank you.