Skip to contentSkip to conversation

x86: Rename __{start,end}_init_task to __{start,end}_init_stack

PATCH Superseded Xin Li (Intel) 3 participants 4 messages Mar 18, 2024 – Mar 22, 2024

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 x86: Rename __{start,end}_init_task to __{start,end}_init_stack

The stack of a task has been separated from the memory of a task_struct struture for a long time on x86, as a result __{start,end}_init_task no longer mark the start and end of the init_task structure, but its stack only.

Rename __{start,end}_init_task to __{start,end}_init_stack.

Note other architectures are not affected because __{start,end}_init_task are used on x86 only.

---

Change since v1:
* Revert an accident insane change, init_task to init_stack (Jürgen Groß).

---
 arch/x86/include/asm/processor.h  | 4 ++--
 arch/x86/kernel/head_64.S         | 2 +-
 arch/x86/xen/xen-head.S           | 2 +-
 include/asm-generic/vmlinux.lds.h | 6 +++---
 4 files changed, 7 insertions(+), 7 deletions(-)
arch/x86/include/asm/processor.h +2 -2
index 811548f131f4..8b3a3f3bb859 100644
@@ -636,10 +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 __end_init_stack[];
 
 #define INIT_THREAD {							\
-	.sp	= (unsigned long)&__end_init_task -			\
+	.sp	= (unsigned long)&__end_init_stack -			\
 		  TOP_OF_KERNEL_STACK_PADDING -				\
 		  sizeof(struct pt_regs),				\
 }
arch/x86/kernel/head_64.S +1 -1
index d8198fbd70e5..c7babd7ebb0f 100644
@@ -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	(__end_init_stack - TOP_OF_KERNEL_STACK_PADDING - PTREGS_SIZE)(%rip), %rsp
 
 	/* Setup GSBASE to allow stack canary access for C code */
 	movl	$MSR_GS_BASE, %ecx
arch/x86/xen/xen-head.S +1 -1
index 04101b984f24..43eadf03f46d 100644
@@ -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	(__end_init_stack - TOP_OF_KERNEL_STACK_PADDING - PTREGS_SIZE)(%rip), %rsp
 
 	/* Set up %gs.
 	 *
include/asm-generic/vmlinux.lds.h +3 -3
index 514d3002ad8a..cdfdcca23045 100644
@@ -399,13 +399,13 @@
 
 #define INIT_TASK_DATA(align)						\
 	. = ALIGN(align);						\
-	__start_init_task = .;						\
+	__start_init_stack = .;						\
 	init_thread_union = .;						\
 	init_stack = .;							\
 	KEEP(*(.data..init_task))					\
 	KEEP(*(.data..init_thread_info))				\
-	. = __start_init_task + THREAD_SIZE;				\
-	__end_init_task = .;
+	. = __start_init_stack + THREAD_SIZE;				\
+	__end_init_stack = .;
 
 #define JUMP_TABLE_DATA							\
 	. = ALIGN(8);							\

base-commit: 7e19a79344df2ed5e106091c29338962261b0290

Signature · 1 line
2.44.0
maintainer Reviewed-by on v2 1/1
#1 lore raw
Quoted 11 lines · Xin Li (Intel)

The stack of a task has been separated from the memory of a task_struct struture for a long time on x86, as a result __{start,end}_init_task no longer mark the start and end of the init_task structure, but its stack only.

Rename __{start,end}_init_task to __{start,end}_init_stack.

Note other architectures are not affected because __{start,end}_init_task are used on x86 only.

Juergen

#2 lore raw
In reply to Xin Li (Intel)
Quoted 13 lines · Xin Li (Intel)

The stack of a task has been separated from the memory of a task_struct struture for a long time on x86, as a result __{start,end}_init_task no longer mark the start and end of the init_task structure, but its stack only.

Rename __{start,end}_init_task to __{start,end}_init_stack.

Note other architectures are not affected because __{start,end}_init_task are used on x86 only.

---

Quoted 8 lines

Change since v1:
* Revert an accident insane change, init_task to init_stack (Jürgen Groß).

---
 arch/x86/include/asm/processor.h  | 4 ++--
 arch/x86/kernel/head_64.S         | 2 +-
 arch/x86/xen/xen-head.S           | 2 +-
 include/asm-generic/vmlinux.lds.h | 6 +++---
 4 files changed, 7 insertions(+), 7 deletions(-)

Note that this is now in conflict with this cleanup by Brian Gerst:

2cb16181a1d1 x86/boot: Simplify boot stack setup

... which removed __end_init_task[] entirely.

Thanks,

Ingo

author
#3 lore raw
Quoted 25 lines · Ingo Molnar
Quoted 13 lines · Xin Li (Intel)

The stack of a task has been separated from the memory of a task_struct struture for a long time on x86, as a result __{start,end}_init_task no longer mark the start and end of the init_task structure, but its stack only.

Rename __{start,end}_init_task to __{start,end}_init_stack.

Note other architectures are not affected because __{start,end}_init_task are used on x86 only.

---

Quoted 8 lines

Change since v1:
* Revert an accident insane change, init_task to init_stack (Jürgen Groß).

---
  arch/x86/include/asm/processor.h  | 4 ++--
  arch/x86/kernel/head_64.S         | 2 +-
  arch/x86/xen/xen-head.S           | 2 +-
  include/asm-generic/vmlinux.lds.h | 6 +++---
  4 files changed, 7 insertions(+), 7 deletions(-)
Quoted 3 lines

Note that this is now in conflict with this cleanup by Brian Gerst:

2cb16181a1d1 x86/boot: Simplify boot stack setup

I like this patch, which does something that I'm also doing, further x86_64 doesn't have the concept of TOP_OF_KERNEL_STACK_PADDING, and I guess it was extended from x86_32 but defined to 0 just for code consistency.

Yes, FRED code uses TOP_OF_KERNEL_STACK_PADDING, but a FRED event frame could contain different amount of information for different event types,
e.g., #MCE could push extra bytes of information, or perhaps even for different instances of the same event type. Thus the size of an event frame pushed by a FRED CPU is not fixed and the address of the pt_regs structure that is used to save the user level context of current task is not at a fixed offset from the top of current task kernel stack.

Quoted 2 lines

.. which removed __end_init_task[] entirely.

Not really, but __end_init_task[] is only used to initialize __top_init_kernel_stack.

I will rebase and send v3.

Thanks!
Xin