* [PATCH] x86/boot: Simplify boot stack setup
@ 2024-03-21 18:05 Brian Gerst
2024-03-21 19:28 ` [tip: x86/boot] " tip-bot2 for Brian Gerst
2024-03-22 11:47 ` [PATCH] " H. Peter Anvin
0 siblings, 2 replies; 3+ messages in thread
From: Brian Gerst @ 2024-03-21 18:05 UTC (permalink / raw)
To: linux-kernel, x86
Cc: Ingo Molnar, Thomas Gleixner, Borislav Petkov, H . Peter Anvin,
Xin Li, Brian Gerst
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>
---
arch/x86/include/asm/processor.h | 6 ++----
arch/x86/kernel/head_32.S | 11 +----------
arch/x86/kernel/head_64.S | 2 +-
arch/x86/kernel/vmlinux.lds.S | 3 +++
arch/x86/xen/xen-head.S | 2 +-
5 files changed, 8 insertions(+), 16 deletions(-)
diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
index 438c0c8f596a..89ed5237e79f 100644
--- a/arch/x86/include/asm/processor.h
+++ b/arch/x86/include/asm/processor.h
@@ -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);
diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
index b50f3641c4d6..a9de527ba5c4 100644
--- a/arch/x86/kernel/head_32.S
+++ b/arch/x86/kernel/head_32.S
@@ -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:
diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
index d8198fbd70e5..b11526869a40 100644
--- a/arch/x86/kernel/head_64.S
+++ b/arch/x86/kernel/head_64.S
@@ -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
diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
index a20409b0a3f2..d430880175f2 100644
--- a/arch/x86/kernel/vmlinux.lds.S
+++ b/arch/x86/kernel/vmlinux.lds.S
@@ -167,6 +167,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
diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
index 04101b984f24..758bcd47b72d 100644
--- a/arch/x86/xen/xen-head.S
+++ b/arch/x86/xen/xen-head.S
@@ -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.
*
base-commit: e1826833c3a9abb9d1fe4b938eca0e25eeafb39f
--
2.44.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* [tip: x86/boot] x86/boot: Simplify boot stack setup
2024-03-21 18:05 [PATCH] x86/boot: Simplify boot stack setup Brian Gerst
@ 2024-03-21 19:28 ` tip-bot2 for Brian Gerst
2024-03-22 11:47 ` [PATCH] " H. Peter Anvin
1 sibling, 0 replies; 3+ messages in thread
From: tip-bot2 for Brian Gerst @ 2024-03-21 19:28 UTC (permalink / raw)
To: linux-tip-commits
Cc: Brian Gerst, Ingo Molnar, Kees Cook, Uros Bizjak, Linus Torvalds,
Andy Lutomirski, x86, linux-kernel
The following commit has been merged into the x86/boot branch of tip:
Commit-ID: 2cb16181a1d1f93a88f2b4640e7638fc0549da93
Gitweb: https://git.kernel.org/tip/2cb16181a1d1f93a88f2b4640e7638fc0549da93
Author: Brian Gerst <brgerst@gmail.com>
AuthorDate: Thu, 21 Mar 2024 14:05:06 -04:00
Committer: Ingo Molnar <mingo@kernel.org>
CommitterDate: Thu, 21 Mar 2024 20:17:54 +01:00
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 <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 | 6 ++----
arch/x86/kernel/head_32.S | 11 +----------
arch/x86/kernel/head_64.S | 2 +-
arch/x86/kernel/vmlinux.lds.S | 3 +++
arch/x86/xen/xen-head.S | 2 +-
5 files changed, 8 insertions(+), 16 deletions(-)
diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
index 811548f..7fa01d9 100644
--- a/arch/x86/include/asm/processor.h
+++ b/arch/x86/include/asm/processor.h
@@ -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);
diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
index b50f364..a9de527 100644
--- a/arch/x86/kernel/head_32.S
+++ b/arch/x86/kernel/head_32.S
@@ -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:
diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
index d8198fb..b115268 100644
--- a/arch/x86/kernel/head_64.S
+++ b/arch/x86/kernel/head_64.S
@@ -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
diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
index 56451fd..91085c3 100644
--- a/arch/x86/kernel/vmlinux.lds.S
+++ b/arch/x86/kernel/vmlinux.lds.S
@@ -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
diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
index 04101b9..758bcd4 100644
--- a/arch/x86/xen/xen-head.S
+++ b/arch/x86/xen/xen-head.S
@@ -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.
*
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] x86/boot: Simplify boot stack setup
2024-03-21 18:05 [PATCH] x86/boot: Simplify boot stack setup Brian Gerst
2024-03-21 19:28 ` [tip: x86/boot] " tip-bot2 for Brian Gerst
@ 2024-03-22 11:47 ` H. Peter Anvin
1 sibling, 0 replies; 3+ messages in thread
From: H. Peter Anvin @ 2024-03-22 11:47 UTC (permalink / raw)
To: Brian Gerst, linux-kernel, x86
Cc: Ingo Molnar, Thomas Gleixner, Borislav Petkov, Xin Li
On March 21, 2024 11:05:06 AM PDT, Brian Gerst <brgerst@gmail.com> wrote:
>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>
>---
> arch/x86/include/asm/processor.h | 6 ++----
> arch/x86/kernel/head_32.S | 11 +----------
> arch/x86/kernel/head_64.S | 2 +-
> arch/x86/kernel/vmlinux.lds.S | 3 +++
> arch/x86/xen/xen-head.S | 2 +-
> 5 files changed, 8 insertions(+), 16 deletions(-)
>
>diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
>index 438c0c8f596a..89ed5237e79f 100644
>--- a/arch/x86/include/asm/processor.h
>+++ b/arch/x86/include/asm/processor.h
>@@ -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);
>diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
>index b50f3641c4d6..a9de527ba5c4 100644
>--- a/arch/x86/kernel/head_32.S
>+++ b/arch/x86/kernel/head_32.S
>@@ -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:
>diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
>index d8198fbd70e5..b11526869a40 100644
>--- a/arch/x86/kernel/head_64.S
>+++ b/arch/x86/kernel/head_64.S
>@@ -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
>diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
>index a20409b0a3f2..d430880175f2 100644
>--- a/arch/x86/kernel/vmlinux.lds.S
>+++ b/arch/x86/kernel/vmlinux.lds.S
>@@ -167,6 +167,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
>diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
>index 04101b984f24..758bcd47b72d 100644
>--- a/arch/x86/xen/xen-head.S
>+++ b/arch/x86/xen/xen-head.S
>@@ -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.
> *
>
>base-commit: e1826833c3a9abb9d1fe4b938eca0e25eeafb39f
Acked-by: H. Peter Anvin (Intel) <hpa@zytor.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-03-22 11:48 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-21 18:05 [PATCH] x86/boot: Simplify boot stack setup Brian Gerst
2024-03-21 19:28 ` [tip: x86/boot] " tip-bot2 for Brian Gerst
2024-03-22 11:47 ` [PATCH] " H. Peter Anvin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®