From: "Xin Li (Intel)" <xin@zytor.com>
To: linux-kernel@vger.kernel.org
Cc: luto@kernel.org, tglx@linutronix.de, mingo@kernel.org,
bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org,
hpa@zytor.com, peterz@infradead.org, brgerst@gmail.com
Subject: [PATCH v2 2/3] x86: Remove the padding space at top of the init stack
Date: Tue, 18 Mar 2025 00:08:00 -0700 [thread overview]
Message-ID: <20250318070801.903045-3-xin@zytor.com> (raw)
In-Reply-To: <20250318070801.903045-1-xin@zytor.com>
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@zytor.com>
---
arch/x86/include/asm/processor.h | 16 ++++++++++++++--
arch/x86/kernel/vmlinux.lds.S | 18 ++++++++++++++++--
2 files changed, 30 insertions(+), 4 deletions(-)
diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
index 79d8df28cd59..cbb5d2158075 100644
--- a/arch/x86/include/asm/processor.h
+++ b/arch/x86/include/asm/processor.h
@@ -641,8 +641,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 ccdc45e5b759..553b65e8bb8a 100644
--- a/arch/x86/kernel/vmlinux.lds.S
+++ b/arch/x86/kernel/vmlinux.lds.S
@@ -178,8 +178,22 @@ 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;
+ /*
+ * 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.
+ *
+ * task_pt_regs(&init_task) is now:
+ * '(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.48.1
next prev parent reply other threads:[~2025-03-18 7:08 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-18 7:07 [PATCH v2 0/3] x86: Allow variable-sized event frame Xin Li (Intel)
2025-03-18 7:07 ` [PATCH v2 1/3] x86/fred: " Xin Li (Intel)
2025-03-18 7:08 ` Xin Li (Intel) [this message]
2025-03-18 7:08 ` [PATCH v2 3/3] x86: Get rid of TOP_OF_KERNEL_STACK_PADDING on x86_64 Xin Li (Intel)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250318070801.903045-3-xin@zytor.com \
--to=xin@zytor.com \
--cc=bp@alien8.de \
--cc=brgerst@gmail.com \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@kernel.org \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®