[PATCH 0/4] riscv: Frame pointer fixes and enhancements

Samuel Holland samuel.holland at sifive.com
Wed May 29 17:15:55 PDT 2024


This series improves frame pointer support in the RISC-V kernel. Patch 1
fixes a bug in 32-bit kernels. Patch 2 prepares for patch 3, which fixes
several places where the kernel clobbers the frame pointer. Patch 4
saves a frame record in the exception entry assembly so the kernel can
unwind past exceptions. Here's an example of what the result looks like:

  [  150.315343] sysrq: Show backtrace of all active CPUs
  [  150.319827] sysrq: CPU0:
  [  150.322063] Call Trace:
  [  150.324684] [<ffffffff800059fa>] show_stack+0x2c/0x38
  [  150.329757] [<ffffffff803e0228>] sysrq_handle_showallcpus+0x78/0xbc
  [  150.336014] [<ffffffff803dfc52>] __handle_sysrq+0x152/0x15e
  [  150.341601] [<ffffffff803e0a88>] write_sysrq_trigger+0xa4/0xba
  [  150.347221] [<ffffffff80182638>] proc_reg_write+0x3e/0x80
  [  150.352787] [<ffffffff8012885e>] vfs_write+0xd8/0x302
  [  150.357625] [<ffffffff80128ba8>] ksys_write+0x58/0xaa
  [  150.362856] [<ffffffff80128c10>] __riscv_sys_write+0x16/0x1e
  [  150.368317] [<ffffffff80005650>] syscall_handler+0x1c/0x28
  [  150.373986] [<ffffffff807372c8>] do_trap_ecall_u+0x64/0xb0
  [  150.379431] [<ffffffff8073e91c>] ret_from_exception+0x0/0x70
  [  150.385207] sysrq: CPU1: backtrace skipped as idling
  [  150.385210] sysrq: CPU2: backtrace skipped as idling
  [  150.385213] sysrq: CPU3:
  [  150.397294] Call Trace:
  [  150.399717] [<ffffffff800059fa>] show_stack+0x2c/0x38
  [  150.404756] [<ffffffff803e02e6>] showacpu+0x56/0x84
  [  150.409620] [<ffffffff8009959e>] __flush_smp_call_function_queue+0x13a/0x1d2
  [  150.416657] [<ffffffff8009968c>] generic_smp_call_function_single_interrupt+0xe/0x16
  [  150.424390] [<ffffffff8000886c>] handle_IPI+0x38/0x74
  [  150.429424] [<ffffffff800659ce>] handle_percpu_devid_irq+0x82/0x106
  [  150.435678] [<ffffffff80060b72>] generic_handle_domain_irq+0x1c/0x2a
  [  150.442019] [<ffffffff8006b9de>] ipi_mux_process+0x6e/0xd6
  [  150.447490] [<ffffffff8000af48>] sbi_ipi_handle+0x30/0x46
  [  150.452876] [<ffffffff80060b72>] generic_handle_domain_irq+0x1c/0x2a
  [  150.459217] [<ffffffff80341936>] riscv_intc_irq+0x22/0x60
  [  150.464602] [<ffffffff807373b0>] handle_riscv_irq+0x30/0x4e
  [  150.470161] [<ffffffff8073736a>] do_irq+0x1a/0x30
  [  150.474851] [<ffffffff8073e91c>] ret_from_exception+0x0/0x70
  [  150.480497] [<ffffffff8033c5a0>] __percpu_counter_sum+0xbe/0xd0
  [  150.486403] [<ffffffff8033c5a0>] __percpu_counter_sum+0xbe/0xd0
  [  150.492310] [<ffffffff8000eac0>] __mmdrop+0xc8/0x208
  [  150.497260] [<ffffffff80038922>] finish_task_switch+0x120/0x198
  [  150.503167] [<ffffffff80739668>] __schedule+0x444/0x6c8
  [  150.508378] [<ffffffff80739a16>] preempt_schedule_common+0x18/0x32
  [  150.514546] [<ffffffff80739222>] preempt_schedule+0x22/0x24
  [  150.520105] [<ffffffff803e026a>] sysrq_handle_showallcpus+0xba/0xbc
  [  150.526359] [<ffffffff803dfc52>] __handle_sysrq+0x152/0x15e
  [  150.531917] [<ffffffff803e0a88>] write_sysrq_trigger+0xa4/0xba
  [  150.537737] [<ffffffff80182638>] proc_reg_write+0x3e/0x80
  [  150.543122] [<ffffffff8012885e>] vfs_write+0xd8/0x302
  [  150.548160] [<ffffffff80128ba8>] ksys_write+0x58/0xaa
  [  150.553197] [<ffffffff80128c10>] __riscv_sys_write+0x16/0x1e
  [  150.558847] [<ffffffff80005650>] syscall_handler+0x1c/0x28
  [  150.564316] [<ffffffff807372c8>] do_trap_ecall_u+0x64/0xb0
  [  150.569788] [<ffffffff8073e91c>] ret_from_exception+0x0/0x70


Samuel Holland (4):
  riscv: Fix 32-bit call_on_irq_stack() frame pointer ABI
  riscv: entry: Balance vector context nesting
  riscv: entry: Do not clobber the frame pointer
  riscv: entry: Save a frame record for exceptions

 arch/riscv/include/asm/processor.h  |  9 ++++-
 arch/riscv/include/asm/ptrace.h     |  5 +++
 arch/riscv/include/asm/stacktrace.h |  5 ---
 arch/riscv/kernel/asm-offsets.c     | 10 ++---
 arch/riscv/kernel/entry.S           | 60 +++++++++++++++--------------
 arch/riscv/kernel/head.S            |  6 +--
 arch/riscv/kernel/process.c         |  5 +--
 arch/riscv/kernel/stacktrace.c      |  9 -----
 8 files changed, 53 insertions(+), 56 deletions(-)

-- 
2.44.1




More information about the linux-riscv mailing list