]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
x86/boot: Simplify boot stack setup
authorBrian Gerst <brgerst@gmail.com>
Thu, 21 Mar 2024 18:05:06 +0000 (14:05 -0400)
committerIngo Molnar <mingo@kernel.org>
Thu, 21 Mar 2024 19:17:54 +0000 (20:17 +0100)
Define the symbol __top_init_kernel_stack instead of duplicating
the offset from __end_init_task in multiple places.

Signed-off-by: Brian Gerst <brgerst@gmail.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: Kees Cook <keescook@chromium.org>
Cc: Uros Bizjak <ubizjak@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Andy Lutomirski <luto@kernel.org>
Link: https://lore.kernel.org/r/20240321180506.89030-1-brgerst@gmail.com
arch/x86/include/asm/processor.h
arch/x86/kernel/head_32.S
arch/x86/kernel/head_64.S
arch/x86/kernel/vmlinux.lds.S
arch/x86/xen/xen-head.S

index 811548f131f4e30418bedfdf98f1f302fc06723d..7fa01d951365ed13c6984666b685091fa07e912d 100644 (file)
@@ -636,12 +636,10 @@ static __always_inline void prefetchw(const void *x)
 #define KSTK_ESP(task)         (task_pt_regs(task)->sp)
 
 #else
-extern unsigned long __end_init_task[];
+extern unsigned long __top_init_kernel_stack[];
 
 #define INIT_THREAD {                                                  \
-       .sp     = (unsigned long)&__end_init_task -                     \
-                 TOP_OF_KERNEL_STACK_PADDING -                         \
-                 sizeof(struct pt_regs),                               \
+       .sp     = (unsigned long)&__top_init_kernel_stack,              \
 }
 
 extern unsigned long KSTK_ESP(struct task_struct *task);
index b50f3641c4d6de0d576efca319432640cf83cd08..a9de527ba5c4ac6185459da2f49816f165e3e5da 100644 (file)
@@ -44,9 +44,6 @@
 #define X86_CAPABILITY new_cpu_data+CPUINFO_x86_capability
 #define X86_VENDOR_ID  new_cpu_data+CPUINFO_x86_vendor_id
 
-
-#define SIZEOF_PTREGS 17*4
-
 /*
  * Worst-case size of the kernel mapping we need to make:
  * a relocatable kernel can live anywhere in lowmem, so we need to be able
@@ -488,13 +485,7 @@ SYM_DATA_END(initial_page_table)
 
 .data
 .balign 4
-/*
- * The SIZEOF_PTREGS gap is a convention which helps the in-kernel unwinder
- * reliably detect the end of the stack.
- */
-SYM_DATA(initial_stack,
-               .long init_thread_union + THREAD_SIZE -
-               SIZEOF_PTREGS - TOP_OF_KERNEL_STACK_PADDING)
+SYM_DATA(initial_stack, .long __top_init_kernel_stack)
 
 __INITRODATA
 int_msg:
index d8198fbd70e54ea9da8355614b7b05963acb6cdf..b11526869a40984e51d2be307d63a54912330bbf 100644 (file)
@@ -66,7 +66,7 @@ SYM_CODE_START_NOALIGN(startup_64)
        mov     %rsi, %r15
 
        /* Set up the stack for verify_cpu() */
-       leaq    (__end_init_task - TOP_OF_KERNEL_STACK_PADDING - PTREGS_SIZE)(%rip), %rsp
+       leaq    __top_init_kernel_stack(%rip), %rsp
 
        /* Setup GSBASE to allow stack canary access for C code */
        movl    $MSR_GS_BASE, %ecx
index 56451fd2099e718b6cf89fde074980042aa3096a..91085c3430de61206078ef377c1e8394d631ffb2 100644 (file)
@@ -172,6 +172,9 @@ SECTIONS
                /* init_task */
                INIT_TASK_DATA(THREAD_SIZE)
 
+               /* equivalent to task_pt_regs(&init_task) */
+               __top_init_kernel_stack = __end_init_task - TOP_OF_KERNEL_STACK_PADDING - PTREGS_SIZE;
+
 #ifdef CONFIG_X86_32
                /* 32 bit has nosave before _edata */
                NOSAVE_DATA
index 04101b984f24dab88bb020add4afe4774628e627..758bcd47b72d3211ffb7026f8dfd438090174d7d 100644 (file)
@@ -49,7 +49,7 @@ SYM_CODE_START(startup_xen)
        ANNOTATE_NOENDBR
        cld
 
-       leaq    (__end_init_task - TOP_OF_KERNEL_STACK_PADDING - PTREGS_SIZE)(%rip), %rsp
+       leaq    __top_init_kernel_stack(%rip), %rsp
 
        /* Set up %gs.
         *