Skip to content

Commit c416b5b

Browse files
xinli-intelKAGA-KOKO
authored andcommitted
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: 65c9cc9 ("x86/fred: Reserve space for the FRED stack frame") Fixes: 3adee77 ("x86/smpboot: Remove initial_stack on 64-bit") Reported-by: kernel test robot <[email protected]> Signed-off-by: Xin Li (Intel) <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Closes: https://lore.kernel.org/oe-lkp/[email protected] Link: https://lore.kernel.org/r/[email protected]
1 parent e138419 commit c416b5b

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

arch/x86/include/asm/processor.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -664,8 +664,10 @@ static __always_inline void prefetchw(const void *x)
664664
#else
665665
extern unsigned long __end_init_task[];
666666

667-
#define INIT_THREAD { \
668-
.sp = (unsigned long)&__end_init_task - sizeof(struct pt_regs), \
667+
#define INIT_THREAD { \
668+
.sp = (unsigned long)&__end_init_task - \
669+
TOP_OF_KERNEL_STACK_PADDING - \
670+
sizeof(struct pt_regs), \
669671
}
670672

671673
extern unsigned long KSTK_ESP(struct task_struct *task);

arch/x86/kernel/head_64.S

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <asm/apicdef.h>
2727
#include <asm/fixmap.h>
2828
#include <asm/smp.h>
29+
#include <asm/thread_info.h>
2930

3031
/*
3132
* 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)
6667
mov %rsi, %r15
6768

6869
/* Set up the stack for verify_cpu() */
69-
leaq (__end_init_task - PTREGS_SIZE)(%rip), %rsp
70+
leaq (__end_init_task - TOP_OF_KERNEL_STACK_PADDING - PTREGS_SIZE)(%rip), %rsp
7071

7172
leaq _text(%rip), %rdi
7273

arch/x86/xen/xen-head.S

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ SYM_CODE_START(startup_xen)
4949
ANNOTATE_NOENDBR
5050
cld
5151

52-
leaq (__end_init_task - PTREGS_SIZE)(%rip), %rsp
52+
leaq (__end_init_task - TOP_OF_KERNEL_STACK_PADDING - PTREGS_SIZE)(%rip), %rsp
5353

5454
/* Set up %gs.
5555
*

0 commit comments

Comments
 (0)