[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250512064353.1535984-3-xin@zytor.com>
Date: Sun, 11 May 2025 23:43:53 -0700
From: "Xin Li (Intel)" <xin@...or.com>
To: linux-kernel@...r.kernel.org
Cc: luto@...nel.org, tglx@...utronix.de, mingo@...nel.org, bp@...en8.de,
dave.hansen@...ux.intel.com, x86@...nel.org, hpa@...or.com,
peterz@...radead.org, brgerst@...il.com
Subject: [PATCH v4 2/2] x86: Remove the padding space at top of the init stack
Because the owner of the init stack, init task, doesn't have any user
level context, there will NEVER be an actual pt_regs structure pushed
at top of the init stack.
However a zeroed pt_regs structure is created at build time and kept
at top of the init stack for task_pt_regs() to function properly with
the init task in the same manner as a normal task with user level
context.
Besides, task_pt_regs() no longer converts a fixed offset from top of
a task kernel stack to a pt_regs structure pointer, but rather returns
whatever in the thread_info.user_pt_regs field, which is initialized
at build time to '(struct pt_regs *)TOP_OF_INIT_STACK - 1' for the
init task.
As a result, there is no point to reserve any padding space at top of
the init stack, so remove the padding space.
Signed-off-by: Xin Li (Intel) <xin@...or.com>
---
arch/x86/include/asm/processor.h | 16 ++++++++++++++--
arch/x86/kernel/vmlinux.lds.S | 7 +++++--
2 files changed, 19 insertions(+), 4 deletions(-)
diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
index 42e5a6a41403..5c5378232bd4 100644
--- a/arch/x86/include/asm/processor.h
+++ b/arch/x86/include/asm/processor.h
@@ -640,8 +640,20 @@ static __always_inline void prefetchw(const void *x)
"m" (*(const char *)x));
}
-#define TOP_OF_INIT_STACK ((unsigned long)&init_stack + sizeof(init_stack) - \
- TOP_OF_KERNEL_STACK_PADDING)
+extern unsigned long __end_init_stack[];
+
+/*
+ * No need to reserve extra padding space above the pt_regs structure
+ * at top of the init stack, because its owner init task doesn't have
+ * any user level context, thus there will NEVER be an actual pt_regs
+ * structure pushed at top of the init stack.
+ *
+ * However a zeroed pt_regs structure is created at build time and kept
+ * at top of the init stack for task_pt_regs() to function properly with
+ * the init task in the same manner as a normal task with user level
+ * context.
+ */
+#define TOP_OF_INIT_STACK ((unsigned long)&__end_init_stack)
#define task_top_of_stack(task) ((unsigned long)(task_pt_regs(task) + 1))
diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
index d813f64a89d6..6266e500f7fb 100644
--- a/arch/x86/kernel/vmlinux.lds.S
+++ b/arch/x86/kernel/vmlinux.lds.S
@@ -181,8 +181,11 @@ SECTIONS
/* init_task */
INIT_TASK_DATA(THREAD_SIZE)
- /* equivalent to task_pt_regs(&init_task) */
- __top_init_kernel_stack = __end_init_stack - TOP_OF_KERNEL_STACK_PADDING - PTREGS_SIZE;
+ /*
+ * task_pt_regs(&init_task) is:
+ * '(struct pt_regs *)&__end_init_stack - 1'
+ */
+ __top_init_kernel_stack = __end_init_stack - PTREGS_SIZE;
#ifdef CONFIG_X86_32
/* 32 bit has nosave before _edata */
--
2.49.0
Powered by blists - more mailing lists