aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKees Cook <[email protected]>2022-03-09 14:09:39 -0800
committerThomas Bogendoerfer <[email protected]>2022-03-14 15:02:53 +0100
commitb847bd64ea9f484510e27065cb2bccc58d9b829b (patch)
tree6ee0d94d6ce3516b2047ecf0bfcab2148afcc273
parent4d409ca3e5107a1b300d0f36550d61c5da4fd8a7 (diff)
MIPS: Only use current_stack_pointer on GCC
Unfortunately, Clang did not have support for "sp" as a global register definition, and was crashing after the addition of current_stack_pointer. This has been fixed in Clang 14, but earlier Clang versions need to avoid this code, so add a versioned test and revert back to the open-coded asm instances. Fixes Clang build error: fatal error: error in backend: Invalid register name global variable Fixes: 200ed341b864 ("mips: Implement "current_stack_pointer"") Reported-by: Nathan Chancellor <[email protected]> Reviewed-by: Nathan Chancellor <[email protected]> Link: https://lore.kernel.org/lkml/[email protected] Cc: Thomas Bogendoerfer <[email protected]> Cc: Marc Zyngier <[email protected]> Cc: Guenter Roeck <[email protected]> Cc: Yanteng Si <[email protected]> Cc: [email protected] Signed-off-by: Kees Cook <[email protected]> Reviewed-by: Nick Desaulniers <[email protected]> Signed-off-by: Thomas Bogendoerfer <[email protected]>
-rw-r--r--arch/mips/Kconfig2
-rw-r--r--arch/mips/include/asm/thread_info.h2
-rw-r--r--arch/mips/kernel/irq.c3
-rw-r--r--arch/mips/lib/uncached.c4
4 files changed, 8 insertions, 3 deletions
diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
index 3f58b45fc953..0dae5f1e61cc 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -4,7 +4,7 @@ config MIPS
default y
select ARCH_32BIT_OFF_T if !64BIT
select ARCH_BINFMT_ELF_STATE if MIPS_FP_SUPPORT
- select ARCH_HAS_CURRENT_STACK_POINTER
+ select ARCH_HAS_CURRENT_STACK_POINTER if !CC_IS_CLANG || CLANG_VERSION >= 140000
select ARCH_HAS_DEBUG_VIRTUAL if !64BIT
select ARCH_HAS_FORTIFY_SOURCE
select ARCH_HAS_KCOV
diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
index 4463348d2372..ecae7470faa4 100644
--- a/arch/mips/include/asm/thread_info.h
+++ b/arch/mips/include/asm/thread_info.h
@@ -69,7 +69,9 @@ static inline struct thread_info *current_thread_info(void)
return __current_thread_info;
}
+#ifdef CONFIG_ARCH_HAS_CURRENT_STACK_POINTER
register unsigned long current_stack_pointer __asm__("sp");
+#endif
#endif /* !__ASSEMBLY__ */
diff --git a/arch/mips/kernel/irq.c b/arch/mips/kernel/irq.c
index fc313c49a417..5e11582fe308 100644
--- a/arch/mips/kernel/irq.c
+++ b/arch/mips/kernel/irq.c
@@ -75,8 +75,9 @@ void __init init_IRQ(void)
#ifdef CONFIG_DEBUG_STACKOVERFLOW
static inline void check_stack_overflow(void)
{
- unsigned long sp = current_stack_pointer;
+ unsigned long sp;
+ __asm__ __volatile__("move %0, $sp" : "=r" (sp));
sp &= THREAD_MASK;
/*
diff --git a/arch/mips/lib/uncached.c b/arch/mips/lib/uncached.c
index f8d4ca046c3e..f80a67c092b6 100644
--- a/arch/mips/lib/uncached.c
+++ b/arch/mips/lib/uncached.c
@@ -40,7 +40,9 @@ unsigned long run_uncached(void *func)
register long ret __asm__("$2");
long lfunc = (long)func, ufunc;
long usp;
- long sp = current_stack_pointer;
+ long sp;
+
+ __asm__("move %0, $sp" : "=r" (sp));
if (sp >= (long)CKSEG0 && sp < (long)CKSEG2)
usp = CKSEG1ADDR(sp);