From 06a2c55f4c11d13a6e1b6a630a565c9ed07611aa Mon Sep 17 00:00:00 2001 From: Hongchen Zhang Date: Thu, 20 Oct 2022 14:15:30 +0800 Subject: [PATCH] LoongArch: change global registers to local registers LoongArch inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I5OHOB -------------------------------- From gcc commit 3f13154553f8 ("df-scan: remove ad-hoc handling of global regs in asms"), global registers will no longer be forced to add to the def-use chain for the following inline asm : __asm("" : "=r"(a) : "0"(c)); /* the case for RELOC_HIDE */ __asm("" : "=r"(b)); So we change to use $r21 $tp $sp as local registers,this way they can be forced to add to the def-use chain. Signed-off-by: Hongchen Zhang Signed-off-by: Xing Li Change-Id: I8ab88684ba8093f5ab84dec837d10594128ee16b --- arch/loongarch/include/asm/entry-common.h | 2 +- arch/loongarch/include/asm/percpu.h | 11 ++++++++--- arch/loongarch/include/asm/thread_info.h | 11 ++++++++--- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/arch/loongarch/include/asm/entry-common.h b/arch/loongarch/include/asm/entry-common.h index 0fe2a098ded9..a1d2ff1d0592 100644 --- a/arch/loongarch/include/asm/entry-common.h +++ b/arch/loongarch/include/asm/entry-common.h @@ -7,7 +7,7 @@ static inline bool on_thread_stack(void) { - return !(((unsigned long)(current->stack) ^ current_stack_pointer) & ~(THREAD_SIZE - 1)); + return !(((unsigned long)(current->stack) ^ current_stack_pointer()) & ~(THREAD_SIZE - 1)); } #endif diff --git a/arch/loongarch/include/asm/percpu.h b/arch/loongarch/include/asm/percpu.h index ad8d88494554..e4872bcd851c 100644 --- a/arch/loongarch/include/asm/percpu.h +++ b/arch/loongarch/include/asm/percpu.h @@ -18,14 +18,19 @@ #endif /* Use r21 for fast access */ -register unsigned long __my_cpu_offset __asm__("$r21"); +static inline unsigned long __kern_my_cpu_offset(void) +{ + register unsigned long off __asm__("$r21"); + + return off; +} +#define __my_cpu_offset __kern_my_cpu_offset() static inline void set_my_cpu_offset(unsigned long off) { - __my_cpu_offset = off; + asm volatile("move $r21, %0"::"r"(off)); csr_write64(off, PERCPU_BASE_KS); } -#define __my_cpu_offset __my_cpu_offset #define PERCPU_OP(op, asm_op, c_op) \ static inline unsigned long __percpu_##op(void *ptr, \ diff --git a/arch/loongarch/include/asm/thread_info.h b/arch/loongarch/include/asm/thread_info.h index 1be904ab3792..c9030464cbb5 100644 --- a/arch/loongarch/include/asm/thread_info.h +++ b/arch/loongarch/include/asm/thread_info.h @@ -44,14 +44,19 @@ struct thread_info { } /* How to get the thread information struct from C. */ -register struct thread_info *__current_thread_info __asm__("$tp"); - static inline struct thread_info *current_thread_info(void) { + register struct thread_info *__current_thread_info __asm__("$tp"); + return __current_thread_info; } -register unsigned long current_stack_pointer __asm__("$sp"); +static inline unsigned long current_stack_pointer(void) +{ + register unsigned long __current_stack_pointer __asm__("$sp"); + + return __current_stack_pointer; +} #endif /* !__ASSEMBLY__ */ -- GitLab