Skip to content

Commit 92652cf

Browse files
committed
xtensa: Implement "current_stack_pointer"
To follow the existing per-arch conventions replace open-coded uses of asm "sp" as "current_stack_pointer". This will let it be used in non-arch places (like HARDENED_USERCOPY). Cc: Chris Zankel <chris@zankel.net> Cc: Marc Zyngier <maz@kernel.org> Cc: linux-xtensa@linux-xtensa.org Signed-off-by: Kees Cook <keescook@chromium.org> Acked-by: Max Filippov <jcmvbkbc@gmail.com> Link: https://lore.kernel.org/lkml/CAMo8BfJFJE-n3=AF+pb9_6oF3gzxX7a+7aBrASHjjNX5byqDqw@mail.gmail.com
1 parent 2792d84 commit 92652cf

4 files changed

Lines changed: 8 additions & 6 deletions

File tree

arch/xtensa/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ config XTENSA
33
def_bool y
44
select ARCH_32BIT_OFF_T
55
select ARCH_HAS_BINFMT_FLAT if !MMU
6+
select ARCH_HAS_CURRENT_STACK_POINTER
67
select ARCH_HAS_DMA_PREP_COHERENT if MMU
78
select ARCH_HAS_SYNC_DMA_FOR_CPU if MMU
89
select ARCH_HAS_SYNC_DMA_FOR_DEVICE if MMU

arch/xtensa/include/asm/current.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ static inline struct task_struct *get_current(void)
2626

2727
#define current get_current()
2828

29+
register unsigned long current_stack_pointer __asm__("a1");
30+
2931
#else
3032

3133
#define GET_CURRENT(reg,sp) \

arch/xtensa/include/asm/stacktrace.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ struct stackframe {
1919

2020
static __always_inline unsigned long *stack_pointer(struct task_struct *task)
2121
{
22-
unsigned long *sp;
22+
unsigned long sp;
2323

2424
if (!task || task == current)
25-
__asm__ __volatile__ ("mov %0, a1\n" : "=a"(sp));
25+
sp = current_stack_pointer;
2626
else
27-
sp = (unsigned long *)task->thread.sp;
27+
sp = task->thread.sp;
2828

29-
return sp;
29+
return (unsigned long *)sp;
3030
}
3131

3232
void walk_stackframe(unsigned long *sp,

arch/xtensa/kernel/irq.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,8 @@ asmlinkage void do_IRQ(int hwirq, struct pt_regs *regs)
3636
#ifdef CONFIG_DEBUG_STACKOVERFLOW
3737
/* Debugging check for stack overflow: is there less than 1KB free? */
3838
{
39-
unsigned long sp;
39+
unsigned long sp = current_stack_pointer;
4040

41-
__asm__ __volatile__ ("mov %0, a1\n" : "=a" (sp));
4241
sp &= THREAD_SIZE - 1;
4342

4443
if (unlikely(sp < (sizeof(thread_info) + 1024)))

0 commit comments

Comments
 (0)