Skip to content

Commit 2cb1618

Browse files
Brian GerstIngo Molnar
authored andcommitted
x86/boot: Simplify boot stack setup
Define the symbol __top_init_kernel_stack instead of duplicating the offset from __end_init_task in multiple places. Signed-off-by: Brian Gerst <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Cc: Kees Cook <[email protected]> Cc: Uros Bizjak <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Andy Lutomirski <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 4ae3dc8 commit 2cb1618

File tree

5 files changed

+8
-16
lines changed

5 files changed

+8
-16
lines changed

arch/x86/include/asm/processor.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -636,12 +636,10 @@ static __always_inline void prefetchw(const void *x)
636636
#define KSTK_ESP(task) (task_pt_regs(task)->sp)
637637

638638
#else
639-
extern unsigned long __end_init_task[];
639+
extern unsigned long __top_init_kernel_stack[];
640640

641641
#define INIT_THREAD { \
642-
.sp = (unsigned long)&__end_init_task - \
643-
TOP_OF_KERNEL_STACK_PADDING - \
644-
sizeof(struct pt_regs), \
642+
.sp = (unsigned long)&__top_init_kernel_stack, \
645643
}
646644

647645
extern unsigned long KSTK_ESP(struct task_struct *task);

arch/x86/kernel/head_32.S

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,6 @@
4444
#define X86_CAPABILITY new_cpu_data+CPUINFO_x86_capability
4545
#define X86_VENDOR_ID new_cpu_data+CPUINFO_x86_vendor_id
4646

47-
48-
#define SIZEOF_PTREGS 17*4
49-
5047
/*
5148
* Worst-case size of the kernel mapping we need to make:
5249
* a relocatable kernel can live anywhere in lowmem, so we need to be able
@@ -488,13 +485,7 @@ SYM_DATA_END(initial_page_table)
488485

489486
.data
490487
.balign 4
491-
/*
492-
* The SIZEOF_PTREGS gap is a convention which helps the in-kernel unwinder
493-
* reliably detect the end of the stack.
494-
*/
495-
SYM_DATA(initial_stack,
496-
.long init_thread_union + THREAD_SIZE -
497-
SIZEOF_PTREGS - TOP_OF_KERNEL_STACK_PADDING)
488+
SYM_DATA(initial_stack, .long __top_init_kernel_stack)
498489

499490
__INITRODATA
500491
int_msg:

arch/x86/kernel/head_64.S

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ SYM_CODE_START_NOALIGN(startup_64)
6666
mov %rsi, %r15
6767

6868
/* Set up the stack for verify_cpu() */
69-
leaq (__end_init_task - TOP_OF_KERNEL_STACK_PADDING - PTREGS_SIZE)(%rip), %rsp
69+
leaq __top_init_kernel_stack(%rip), %rsp
7070

7171
/* Setup GSBASE to allow stack canary access for C code */
7272
movl $MSR_GS_BASE, %ecx

arch/x86/kernel/vmlinux.lds.S

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,9 @@ SECTIONS
172172
/* init_task */
173173
INIT_TASK_DATA(THREAD_SIZE)
174174

175+
/* equivalent to task_pt_regs(&init_task) */
176+
__top_init_kernel_stack = __end_init_task - TOP_OF_KERNEL_STACK_PADDING - PTREGS_SIZE;
177+
175178
#ifdef CONFIG_X86_32
176179
/* 32 bit has nosave before _edata */
177180
NOSAVE_DATA

arch/x86/xen/xen-head.S

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ SYM_CODE_START(startup_xen)
4949
ANNOTATE_NOENDBR
5050
cld
5151

52-
leaq (__end_init_task - TOP_OF_KERNEL_STACK_PADDING - PTREGS_SIZE)(%rip), %rsp
52+
leaq __top_init_kernel_stack(%rip), %rsp
5353

5454
/* Set up %gs.
5555
*

0 commit comments

Comments
 (0)