mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2 1/1] x86/fred: Fix init_task thread stack pointer initialization
@ 2024-03-04  8:33 Xin Li (Intel)
  2024-03-06 18:28 ` Xin Li
  2024-03-07 11:04 ` [tip: x86/fred] " tip-bot2 for Xin Li (Intel)
  0 siblings, 2 replies; 4+ messages in thread
From: Xin Li (Intel) @ 2024-03-04  8:33 UTC (permalink / raw)
  To: linux-kernel, xen-devel
  Cc: tglx, mingo, bp, dave.hansen, x86, hpa, jgross, boris.ostrovsky,
	arnd, andrew.cooper3, brgerst

As TOP_OF_KERNEL_STACK_PADDING is defined as 0 on x86_64, no one noticed
it's missing in the calculation of the .sp field in INIT_THREAD until it
is defined to 16 with CONFIG_X86_FRED=y.

Subtract TOP_OF_KERNEL_STACK_PADDING from the .sp field of INIT_THREAD.

Fixes: 65c9cc9e2c14 ("x86/fred: Reserve space for the FRED stack frame")
Fixes: 3adee777ad0d ("x86/smpboot: Remove initial_stack on 64-bit")
Reported-by: kernel test robot <oliver.sang@intel.com>
Closes: https://lore.kernel.org/oe-lkp/202402262159.183c2a37-lkp@intel.com
Signed-off-by: Xin Li (Intel) <xin@zytor.com>
---

Change Since v1:
* Apply offset TOP_OF_KERNEL_STACK_PADDING to all uses of __end_init_task
  (Brian Gerst).
---
 arch/x86/include/asm/processor.h | 6 ++++--
 arch/x86/kernel/head_64.S        | 3 ++-
 arch/x86/xen/xen-head.S          | 2 +-
 3 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
index 26620d7642a9..17fe81998ce4 100644
--- a/arch/x86/include/asm/processor.h
+++ b/arch/x86/include/asm/processor.h
@@ -664,8 +664,10 @@ static __always_inline void prefetchw(const void *x)
 #else
 extern unsigned long __end_init_task[];
 
-#define INIT_THREAD {							    \
-	.sp	= (unsigned long)&__end_init_task - sizeof(struct pt_regs), \
+#define INIT_THREAD {							\
+	.sp	= (unsigned long)&__end_init_task -			\
+		  TOP_OF_KERNEL_STACK_PADDING -				\
+		  sizeof(struct pt_regs),				\
 }
 
 extern unsigned long KSTK_ESP(struct task_struct *task);
diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
index d4918d03efb4..c38e43589046 100644
--- a/arch/x86/kernel/head_64.S
+++ b/arch/x86/kernel/head_64.S
@@ -26,6 +26,7 @@
 #include <asm/apicdef.h>
 #include <asm/fixmap.h>
 #include <asm/smp.h>
+#include <asm/thread_info.h>
 
 /*
  * We are not able to switch in one step to the final KERNEL ADDRESS SPACE
@@ -66,7 +67,7 @@ SYM_CODE_START_NOALIGN(startup_64)
 	mov	%rsi, %r15
 
 	/* Set up the stack for verify_cpu() */
-	leaq	(__end_init_task - PTREGS_SIZE)(%rip), %rsp
+	leaq	(__end_init_task - TOP_OF_KERNEL_STACK_PADDING - PTREGS_SIZE)(%rip), %rsp
 
 	leaq	_text(%rip), %rdi
 
diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
index a0ea285878db..04101b984f24 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 - PTREGS_SIZE)(%rip), %rsp
+	leaq	(__end_init_task - TOP_OF_KERNEL_STACK_PADDING - PTREGS_SIZE)(%rip), %rsp
 
 	/* Set up %gs.
 	 *

base-commit: e13841907b8fda0ae0ce1ec03684665f578416a8
-- 
2.44.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2 1/1] x86/fred: Fix init_task thread stack pointer initialization
  2024-03-04  8:33 [PATCH v2 1/1] x86/fred: Fix init_task thread stack pointer initialization Xin Li (Intel)
@ 2024-03-06 18:28 ` Xin Li
  2024-03-06 20:39   ` H. Peter Anvin
  2024-03-07 11:04 ` [tip: x86/fred] " tip-bot2 for Xin Li (Intel)
  1 sibling, 1 reply; 4+ messages in thread
From: Xin Li @ 2024-03-06 18:28 UTC (permalink / raw)
  To: linux-kernel, xen-devel
  Cc: tglx, mingo, bp, dave.hansen, x86, hpa, jgross, boris.ostrovsky,
	arnd, andrew.cooper3, brgerst

On 3/4/2024 12:33 AM, Xin Li (Intel) wrote:
> As TOP_OF_KERNEL_STACK_PADDING is defined as 0 on x86_64, no one noticed
> it's missing in the calculation of the .sp field in INIT_THREAD until it
> is defined to 16 with CONFIG_X86_FRED=y.
> 
> Subtract TOP_OF_KERNEL_STACK_PADDING from the .sp field of INIT_THREAD.
> 
> Fixes: 65c9cc9e2c14 ("x86/fred: Reserve space for the FRED stack frame")
> Fixes: 3adee777ad0d ("x86/smpboot: Remove initial_stack on 64-bit")
> Reported-by: kernel test robot <oliver.sang@intel.com>
> Closes: https://lore.kernel.org/oe-lkp/202402262159.183c2a37-lkp@intel.com
> Signed-off-by: Xin Li (Intel) <xin@zytor.com>
> ---

Should this fix, if it looks good, be included for the coming merge
window?

Thanks!
     Xin

> 
> Change Since v1:
> * Apply offset TOP_OF_KERNEL_STACK_PADDING to all uses of __end_init_task
>    (Brian Gerst).
> ---
>   arch/x86/include/asm/processor.h | 6 ++++--
>   arch/x86/kernel/head_64.S        | 3 ++-
>   arch/x86/xen/xen-head.S          | 2 +-
>   3 files changed, 7 insertions(+), 4 deletions(-)
> 
> diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
> index 26620d7642a9..17fe81998ce4 100644
> --- a/arch/x86/include/asm/processor.h
> +++ b/arch/x86/include/asm/processor.h
> @@ -664,8 +664,10 @@ static __always_inline void prefetchw(const void *x)
>   #else
>   extern unsigned long __end_init_task[];
>   
> -#define INIT_THREAD {							    \
> -	.sp	= (unsigned long)&__end_init_task - sizeof(struct pt_regs), \
> +#define INIT_THREAD {							\
> +	.sp	= (unsigned long)&__end_init_task -			\
> +		  TOP_OF_KERNEL_STACK_PADDING -				\
> +		  sizeof(struct pt_regs),				\
>   }
>   
>   extern unsigned long KSTK_ESP(struct task_struct *task);
> diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
> index d4918d03efb4..c38e43589046 100644
> --- a/arch/x86/kernel/head_64.S
> +++ b/arch/x86/kernel/head_64.S
> @@ -26,6 +26,7 @@
>   #include <asm/apicdef.h>
>   #include <asm/fixmap.h>
>   #include <asm/smp.h>
> +#include <asm/thread_info.h>
>   
>   /*
>    * We are not able to switch in one step to the final KERNEL ADDRESS SPACE
> @@ -66,7 +67,7 @@ SYM_CODE_START_NOALIGN(startup_64)
>   	mov	%rsi, %r15
>   
>   	/* Set up the stack for verify_cpu() */
> -	leaq	(__end_init_task - PTREGS_SIZE)(%rip), %rsp
> +	leaq	(__end_init_task - TOP_OF_KERNEL_STACK_PADDING - PTREGS_SIZE)(%rip), %rsp
>   
>   	leaq	_text(%rip), %rdi
>   
> diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
> index a0ea285878db..04101b984f24 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 - PTREGS_SIZE)(%rip), %rsp
> +	leaq	(__end_init_task - TOP_OF_KERNEL_STACK_PADDING - PTREGS_SIZE)(%rip), %rsp
>   
>   	/* Set up %gs.
>   	 *
> 
> base-commit: e13841907b8fda0ae0ce1ec03684665f578416a8


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2 1/1] x86/fred: Fix init_task thread stack pointer initialization
  2024-03-06 18:28 ` Xin Li
@ 2024-03-06 20:39   ` H. Peter Anvin
  0 siblings, 0 replies; 4+ messages in thread
From: H. Peter Anvin @ 2024-03-06 20:39 UTC (permalink / raw)
  To: Xin Li, linux-kernel, xen-devel
  Cc: tglx, mingo, bp, dave.hansen, x86, jgross, boris.ostrovsky, arnd,
	andrew.cooper3, brgerst

On March 6, 2024 10:28:25 AM PST, Xin Li <xin@zytor.com> wrote:
>On 3/4/2024 12:33 AM, Xin Li (Intel) wrote:
>> As TOP_OF_KERNEL_STACK_PADDING is defined as 0 on x86_64, no one noticed
>> it's missing in the calculation of the .sp field in INIT_THREAD until it
>> is defined to 16 with CONFIG_X86_FRED=y.
>> 
>> Subtract TOP_OF_KERNEL_STACK_PADDING from the .sp field of INIT_THREAD.
>> 
>> Fixes: 65c9cc9e2c14 ("x86/fred: Reserve space for the FRED stack frame")
>> Fixes: 3adee777ad0d ("x86/smpboot: Remove initial_stack on 64-bit")
>> Reported-by: kernel test robot <oliver.sang@intel.com>
>> Closes: https://lore.kernel.org/oe-lkp/202402262159.183c2a37-lkp@intel.com
>> Signed-off-by: Xin Li (Intel) <xin@zytor.com>
>> ---
>
>Should this fix, if it looks good, be included for the coming merge
>window?
>
>Thanks!
>    Xin
>
>> 
>> Change Since v1:
>> * Apply offset TOP_OF_KERNEL_STACK_PADDING to all uses of __end_init_task
>>    (Brian Gerst).
>> ---
>>   arch/x86/include/asm/processor.h | 6 ++++--
>>   arch/x86/kernel/head_64.S        | 3 ++-
>>   arch/x86/xen/xen-head.S          | 2 +-
>>   3 files changed, 7 insertions(+), 4 deletions(-)
>> 
>> diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
>> index 26620d7642a9..17fe81998ce4 100644
>> --- a/arch/x86/include/asm/processor.h
>> +++ b/arch/x86/include/asm/processor.h
>> @@ -664,8 +664,10 @@ static __always_inline void prefetchw(const void *x)
>>   #else
>>   extern unsigned long __end_init_task[];
>>   -#define INIT_THREAD {							    \
>> -	.sp	= (unsigned long)&__end_init_task - sizeof(struct pt_regs), \
>> +#define INIT_THREAD {							\
>> +	.sp	= (unsigned long)&__end_init_task -			\
>> +		  TOP_OF_KERNEL_STACK_PADDING -				\
>> +		  sizeof(struct pt_regs),				\
>>   }
>>     extern unsigned long KSTK_ESP(struct task_struct *task);
>> diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
>> index d4918d03efb4..c38e43589046 100644
>> --- a/arch/x86/kernel/head_64.S
>> +++ b/arch/x86/kernel/head_64.S
>> @@ -26,6 +26,7 @@
>>   #include <asm/apicdef.h>
>>   #include <asm/fixmap.h>
>>   #include <asm/smp.h>
>> +#include <asm/thread_info.h>
>>     /*
>>    * We are not able to switch in one step to the final KERNEL ADDRESS SPACE
>> @@ -66,7 +67,7 @@ SYM_CODE_START_NOALIGN(startup_64)
>>   	mov	%rsi, %r15
>>     	/* Set up the stack for verify_cpu() */
>> -	leaq	(__end_init_task - PTREGS_SIZE)(%rip), %rsp
>> +	leaq	(__end_init_task - TOP_OF_KERNEL_STACK_PADDING - PTREGS_SIZE)(%rip), %rsp
>>     	leaq	_text(%rip), %rdi
>>   diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
>> index a0ea285878db..04101b984f24 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 - PTREGS_SIZE)(%rip), %rsp
>> +	leaq	(__end_init_task - TOP_OF_KERNEL_STACK_PADDING - PTREGS_SIZE)(%rip), %rsp
>>     	/* Set up %gs.
>>   	 *
>> 
>> base-commit: e13841907b8fda0ae0ce1ec03684665f578416a8
>

Absolutely.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [tip: x86/fred] x86/fred: Fix init_task thread stack pointer initialization
  2024-03-04  8:33 [PATCH v2 1/1] x86/fred: Fix init_task thread stack pointer initialization Xin Li (Intel)
  2024-03-06 18:28 ` Xin Li
@ 2024-03-07 11:04 ` tip-bot2 for Xin Li (Intel)
  1 sibling, 0 replies; 4+ messages in thread
From: tip-bot2 for Xin Li (Intel) @ 2024-03-07 11:04 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: kernel test robot, Xin Li (Intel), Thomas Gleixner, x86, linux-kernel

The following commit has been merged into the x86/fred branch of tip:

Commit-ID:     c416b5bac6ad6ffe21e36225553b82ff2ec1558c
Gitweb:        https://git.kernel.org/tip/c416b5bac6ad6ffe21e36225553b82ff2ec1558c
Author:        Xin Li (Intel) <xin@zytor.com>
AuthorDate:    Mon, 04 Mar 2024 00:33:33 -08:00
Committer:     Thomas Gleixner <tglx@linutronix.de>
CommitterDate: Thu, 07 Mar 2024 11:55:36 +01:00

x86/fred: Fix init_task thread stack pointer initialization

As TOP_OF_KERNEL_STACK_PADDING was defined as 0 on x86_64, it went
unnoticed that the initialization of the .sp field in INIT_THREAD and some
calculations in the low level startup code do not take the padding into
account.

FRED enabled kernels require a 16 byte padding, which means that the init
task initialization and the low level startup code use the wrong stack
offset.

Subtract TOP_OF_KERNEL_STACK_PADDING in all affected places to adjust for
this.

Fixes: 65c9cc9e2c14 ("x86/fred: Reserve space for the FRED stack frame")
Fixes: 3adee777ad0d ("x86/smpboot: Remove initial_stack on 64-bit")
Reported-by: kernel test robot <oliver.sang@intel.com>
Signed-off-by: Xin Li (Intel) <xin@zytor.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Closes: https://lore.kernel.org/oe-lkp/202402262159.183c2a37-lkp@intel.com
Link: https://lore.kernel.org/r/20240304083333.449322-1-xin@zytor.com
---
 arch/x86/include/asm/processor.h | 6 ++++--
 arch/x86/kernel/head_64.S        | 3 ++-
 arch/x86/xen/xen-head.S          | 2 +-
 3 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
index 26620d7..17fe819 100644
--- a/arch/x86/include/asm/processor.h
+++ b/arch/x86/include/asm/processor.h
@@ -664,8 +664,10 @@ static __always_inline void prefetchw(const void *x)
 #else
 extern unsigned long __end_init_task[];
 
-#define INIT_THREAD {							    \
-	.sp	= (unsigned long)&__end_init_task - sizeof(struct pt_regs), \
+#define INIT_THREAD {							\
+	.sp	= (unsigned long)&__end_init_task -			\
+		  TOP_OF_KERNEL_STACK_PADDING -				\
+		  sizeof(struct pt_regs),				\
 }
 
 extern unsigned long KSTK_ESP(struct task_struct *task);
diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
index d4918d0..c38e435 100644
--- a/arch/x86/kernel/head_64.S
+++ b/arch/x86/kernel/head_64.S
@@ -26,6 +26,7 @@
 #include <asm/apicdef.h>
 #include <asm/fixmap.h>
 #include <asm/smp.h>
+#include <asm/thread_info.h>
 
 /*
  * We are not able to switch in one step to the final KERNEL ADDRESS SPACE
@@ -66,7 +67,7 @@ SYM_CODE_START_NOALIGN(startup_64)
 	mov	%rsi, %r15
 
 	/* Set up the stack for verify_cpu() */
-	leaq	(__end_init_task - PTREGS_SIZE)(%rip), %rsp
+	leaq	(__end_init_task - TOP_OF_KERNEL_STACK_PADDING - PTREGS_SIZE)(%rip), %rsp
 
 	leaq	_text(%rip), %rdi
 
diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
index a0ea285..04101b9 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 - PTREGS_SIZE)(%rip), %rsp
+	leaq	(__end_init_task - TOP_OF_KERNEL_STACK_PADDING - PTREGS_SIZE)(%rip), %rsp
 
 	/* Set up %gs.
 	 *

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-03-07 11:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-04  8:33 [PATCH v2 1/1] x86/fred: Fix init_task thread stack pointer initialization Xin Li (Intel)
2024-03-06 18:28 ` Xin Li
2024-03-06 20:39   ` H. Peter Anvin
2024-03-07 11:04 ` [tip: x86/fred] " tip-bot2 for Xin Li (Intel)

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®