[PATCH] riscv: remove code for !CONFIG_FRAME_POINTER

Vineet Gupta vineetg at rivosinc.com
Thu Oct 21 09:51:42 PDT 2021


while frame pointer generates horrible code it is a necessary evil on
RISC-V as the only way to unwind stack.

In fact Kconfig unconditonally selects ARCH_WANT_FRAME_POINTERS, so
any code for handling !FRAME_POINTER is essentially dead weight.

And while here remove redundant setting of -fno-omit-frame-pointer as
this is enabled by generic code for CONFIG_FRAME_POINTER

Signed-off-by: Vineet Gupta <vineetg at rivosinc.com>
---
 arch/riscv/Makefile            |  3 ---
 arch/riscv/kernel/stacktrace.c | 37 ++--------------------------------
 2 files changed, 2 insertions(+), 38 deletions(-)

diff --git a/arch/riscv/Makefile b/arch/riscv/Makefile
index a0b8259c7098..a4329035c341 100644
--- a/arch/riscv/Makefile
+++ b/arch/riscv/Makefile
@@ -65,9 +65,6 @@ endif
 ifeq ($(CONFIG_CMODEL_MEDANY),y)
 	KBUILD_CFLAGS += -mcmodel=medany
 endif
-ifeq ($(CONFIG_PERF_EVENTS),y)
-        KBUILD_CFLAGS += -fno-omit-frame-pointer
-endif
 
 KBUILD_CFLAGS_MODULE += $(call cc-option,-mno-relax)
 
diff --git a/arch/riscv/kernel/stacktrace.c b/arch/riscv/kernel/stacktrace.c
index 315db3d0229b..63f471278401 100644
--- a/arch/riscv/kernel/stacktrace.c
+++ b/arch/riscv/kernel/stacktrace.c
@@ -16,13 +16,13 @@
 
 register unsigned long sp_in_global __asm__("sp");
 
-#ifdef CONFIG_FRAME_POINTER
-
 void notrace walk_stackframe(struct task_struct *task, struct pt_regs *regs,
 			     bool (*fn)(void *, unsigned long), void *arg)
 {
 	unsigned long fp, sp, pc;
 
+        BUILD_BUG_ON(!IS_ENABLED(CONFIG_FRAME_POINTER));
+
 	if (regs) {
 		fp = frame_pointer(regs);
 		sp = user_stack_pointer(regs);
@@ -65,39 +65,6 @@ void notrace walk_stackframe(struct task_struct *task, struct pt_regs *regs,
 	}
 }
 
-#else /* !CONFIG_FRAME_POINTER */
-
-void notrace walk_stackframe(struct task_struct *task,
-	struct pt_regs *regs, bool (*fn)(void *, unsigned long), void *arg)
-{
-	unsigned long sp, pc;
-	unsigned long *ksp;
-
-	if (regs) {
-		sp = user_stack_pointer(regs);
-		pc = instruction_pointer(regs);
-	} else if (task == NULL || task == current) {
-		sp = sp_in_global;
-		pc = (unsigned long)walk_stackframe;
-	} else {
-		/* task blocked in __switch_to */
-		sp = task->thread.sp;
-		pc = task->thread.ra;
-	}
-
-	if (unlikely(sp & 0x7))
-		return;
-
-	ksp = (unsigned long *)sp;
-	while (!kstack_end(ksp)) {
-		if (__kernel_text_address(pc) && unlikely(!fn(arg, pc)))
-			break;
-		pc = (*ksp++) - 0x4;
-	}
-}
-
-#endif /* CONFIG_FRAME_POINTER */
-
 static bool print_trace_address(void *arg, unsigned long pc)
 {
 	const char *loglvl = arg;
-- 
2.30.2




More information about the linux-riscv mailing list