Skip to contentSkip to conversation

x86/head_64.S: remove redundant check that kernel address is 2M aligned

RFC PATCH In review Alexander Kuleshov 2 participants 3 messages Jan 22, 2016 – Jan 23, 2016 x86

lore
Share & tools
lore
#0 lore raw

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
index ffdc0e8..4967cba 100644
@@ -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
#1 lore raw
Quoted 18 lines · Alexander Kuleshov

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 -0
index ffdc0e8..4967cba 100644
@@ -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

#2 lore raw

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
jnz bad_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.