Skip to content

Commit 200ed34

Browse files
keestsbogend
authored andcommitted
mips: 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: Thomas Bogendoerfer <tsbogend@alpha.franken.de> Cc: Marc Zyngier <maz@kernel.org> Cc: Guenter Roeck <linux@roeck-us.net> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Yanteng Si <siyanteng01@gmail.com> Cc: linux-mips@vger.kernel.org Signed-off-by: Kees Cook <keescook@chromium.org> Signed-off-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
1 parent 455481f commit 200ed34

4 files changed

Lines changed: 5 additions & 5 deletions

File tree

arch/mips/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ config MIPS
44
default y
55
select ARCH_32BIT_OFF_T if !64BIT
66
select ARCH_BINFMT_ELF_STATE if MIPS_FP_SUPPORT
7+
select ARCH_HAS_CURRENT_STACK_POINTER
78
select ARCH_HAS_DEBUG_VIRTUAL if !64BIT
89
select ARCH_HAS_FORTIFY_SOURCE
910
select ARCH_HAS_KCOV

arch/mips/include/asm/thread_info.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ static inline struct thread_info *current_thread_info(void)
6969
return __current_thread_info;
7070
}
7171

72+
register unsigned long current_stack_pointer __asm__("sp");
73+
7274
#endif /* !__ASSEMBLY__ */
7375

7476
/* thread information allocation */

arch/mips/kernel/irq.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,8 @@ void __init init_IRQ(void)
7575
#ifdef CONFIG_DEBUG_STACKOVERFLOW
7676
static inline void check_stack_overflow(void)
7777
{
78-
unsigned long sp;
78+
unsigned long sp = current_stack_pointer;
7979

80-
__asm__ __volatile__("move %0, $sp" : "=r" (sp));
8180
sp &= THREAD_MASK;
8281

8382
/*

arch/mips/lib/uncached.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@ unsigned long run_uncached(void *func)
4040
register long ret __asm__("$2");
4141
long lfunc = (long)func, ufunc;
4242
long usp;
43-
long sp;
44-
45-
__asm__("move %0, $sp" : "=r" (sp));
43+
long sp = current_stack_pointer;
4644

4745
if (sp >= (long)CKSEG0 && sp < (long)CKSEG2)
4846
usp = CKSEG1ADDR(sp);

0 commit comments

Comments
 (0)