Skip to content

Commit

Permalink
xtensa: selectively init interrupt stack at boot
Browse files Browse the repository at this point in the history
During arch_kernel_init(), the interrupt stack is being
initialized. However, if the current in-use stack is
the interrupt stack, it would wipe all the data up to
that point in stack, and might result in crash. So skip
initializing the interrupt stack if the current stack
pointer is within the boundary of interrupt stack.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
  • Loading branch information
dcpleung authored and pull[bot] committed Jan 24, 2024
1 parent 6499251 commit 8000cb0
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions arch/xtensa/include/kernel_arch_func.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,22 @@ static ALWAYS_INLINE void arch_kernel_init(void)
XTENSA_WSR(ZSR_CPU_STR, cpu0);

#ifdef CONFIG_INIT_STACKS
memset(Z_KERNEL_STACK_BUFFER(z_interrupt_stacks[0]), 0xAA,
K_KERNEL_STACK_SIZEOF(z_interrupt_stacks[0]));
char *stack_start = Z_KERNEL_STACK_BUFFER(z_interrupt_stacks[0]);
size_t stack_sz = K_KERNEL_STACK_SIZEOF(z_interrupt_stacks[0]);
char *stack_end = stack_start + stack_sz;

uint32_t sp;

__asm__ volatile("mov %0, sp" : "=a"(sp));

/* Only clear the interrupt stack if the current stack pointer
* is not within the interrupt stack. Or else we would be
* wiping the in-use stack.
*/
if (((uintptr_t)sp < (uintptr_t)stack_start) ||
((uintptr_t)sp >= (uintptr_t)stack_end)) {
memset(stack_start, 0xAA, stack_sz);
}
#endif

#ifdef CONFIG_XTENSA_MMU
Expand Down

0 comments on commit 8000cb0

Please sign in to comment.