From 2c4041228e4e75347718d0b25bd3f730b63babb8 Mon Sep 17 00:00:00 2001 From: Todd Kjos Date: Sat, 1 Feb 2025 00:10:28 +0000 Subject: [PATCH] Revert "BACKPORT: RISC-V: Stop relying on GCC's register allocator's hueristics" This reverts commit f06e9ec979554937a5526cf5ab759b1d6ba342f6. Breaks 64-bit riscv builds in kernelci Bug: 393656515 Change-Id: I3a4cf13f4ebde7d84f4d9b6f88729b7afb9735f7 Signed-off-by: Todd Kjos --- arch/riscv/include/asm/current.h | 5 ++--- arch/riscv/kernel/process.c | 5 ++--- arch/riscv/kernel/stacktrace.c | 7 +++---- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/arch/riscv/include/asm/current.h b/arch/riscv/include/asm/current.h index f3d89c418638..44dcf7fc15ee 100644 --- a/arch/riscv/include/asm/current.h +++ b/arch/riscv/include/asm/current.h @@ -17,8 +17,6 @@ struct task_struct; -register struct task_struct *riscv_current_is_tp __asm__("tp"); - /* * This only works because "struct thread_info" is at offset 0 from "struct * task_struct". This constraint seems to be necessary on other architectures @@ -28,7 +26,8 @@ register struct task_struct *riscv_current_is_tp __asm__("tp"); */ static __always_inline struct task_struct *get_current(void) { - return riscv_current_is_tp; + register struct task_struct *tp __asm__("tp"); + return tp; } #define current get_current() diff --git a/arch/riscv/kernel/process.c b/arch/riscv/kernel/process.c index 652ba81e4fa2..9d4b4098874b 100644 --- a/arch/riscv/kernel/process.c +++ b/arch/riscv/kernel/process.c @@ -22,8 +22,6 @@ #include #include -unsigned long gp_in_global __asm__("gp"); - extern asmlinkage void ret_from_fork(void); extern asmlinkage void ret_from_kernel_thread(void); @@ -111,8 +109,9 @@ int copy_thread_tls(unsigned long clone_flags, unsigned long usp, /* p->thread holds context to be restored by __switch_to() */ if (unlikely(p->flags & PF_KTHREAD)) { /* Kernel thread */ + const register unsigned long gp __asm__ ("gp"); memset(childregs, 0, sizeof(struct pt_regs)); - childregs->gp = gp_in_global; + childregs->gp = gp; childregs->sstatus = SR_SPP | SR_SPIE; /* Supervisor, irqs on */ p->thread.ra = (unsigned long)ret_from_kernel_thread; diff --git a/arch/riscv/kernel/stacktrace.c b/arch/riscv/kernel/stacktrace.c index 7d145ae70416..5ba4d23971fd 100644 --- a/arch/riscv/kernel/stacktrace.c +++ b/arch/riscv/kernel/stacktrace.c @@ -19,8 +19,6 @@ struct stackframe { unsigned long ra; }; -register unsigned long sp_in_global __asm__("sp"); - void notrace walk_stackframe(struct task_struct *task, struct pt_regs *regs, bool (*fn)(unsigned long, void *), void *arg) { @@ -31,7 +29,7 @@ void notrace walk_stackframe(struct task_struct *task, struct pt_regs *regs, sp = user_stack_pointer(regs); pc = instruction_pointer(regs); } else if (task == NULL || task == current) { - const register unsigned long current_sp = sp_in_global; + const register unsigned long current_sp __asm__ ("sp"); fp = (unsigned long)__builtin_frame_address(0); sp = current_sp; pc = (unsigned long)walk_stackframe; @@ -75,7 +73,8 @@ void notrace walk_stackframe(struct task_struct *task, sp = user_stack_pointer(regs); pc = instruction_pointer(regs); } else if (task == NULL || task == current) { - sp = sp_in_global; + const register unsigned long current_sp __asm__ ("sp"); + sp = current_sp; pc = (unsigned long)walk_stackframe; } else { /* task blocked in __switch_to */