]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
riscv: add hardware error trap handler support
authorRui Qi <qirui.001@bytedance.com>
Sat, 4 Apr 2026 01:28:47 +0000 (19:28 -0600)
committerPaul Walmsley <pjw@kernel.org>
Sun, 5 Apr 2026 00:42:44 +0000 (18:42 -0600)
Add support for handling hardware error traps (exception code 19)
in the RISC-V architecture. The changes include:

- Add do_trap_hardware_error function declaration in asm-prototypes.h
- Add hardware error trap vector entry in entry.S exception vector table
- Implement do_trap_hardware_error handler in traps.c that generates
  SIGBUS with BUS_MCEERR_AR for hardware errors

This enables proper handling of hardware error exceptions that may occur
in RISC-V systems, providing appropriate error reporting and signal
generation for user space processes.

Signed-off-by: Rui Qi <qirui.001@bytedance.com>
Link: https://patch.msgid.link/20260202094200.53735-1-qirui.001@bytedance.com
[pjw@kernel.org: clean up commit message slightly]
Signed-off-by: Paul Walmsley <pjw@kernel.org>
arch/riscv/include/asm/asm-prototypes.h
arch/riscv/kernel/entry.S
arch/riscv/kernel/traps.c

index 41ec5cdec3673cc410fedf2542b6a6ffd2da5e98..5b90ba5314ee9bb4569c2026d08c0c49ab0e74d0 100644 (file)
@@ -40,6 +40,7 @@ asmlinkage void riscv_v_context_nesting_end(struct pt_regs *regs);
 #define DECLARE_DO_ERROR_INFO(name)    asmlinkage void name(struct pt_regs *regs)
 
 DECLARE_DO_ERROR_INFO(do_trap_unknown);
+DECLARE_DO_ERROR_INFO(do_trap_hardware_error);
 DECLARE_DO_ERROR_INFO(do_trap_insn_misaligned);
 DECLARE_DO_ERROR_INFO(do_trap_insn_fault);
 DECLARE_DO_ERROR_INFO(do_trap_insn_illegal);
index 60eb221296a604694c5f936d0c23c637dc44298e..d011fb51c59a042092326a23da346d21926aa592 100644 (file)
@@ -498,6 +498,7 @@ SYM_DATA_START_LOCAL(excp_vect_table)
        RISCV_PTR do_trap_unknown /* cause=16 */
        RISCV_PTR do_trap_unknown /* cause=17 */
        RISCV_PTR do_trap_software_check /* cause=18 is sw check exception */
+       RISCV_PTR do_trap_hardware_error /* hardware error (19) */
 SYM_DATA_END_LABEL(excp_vect_table, SYM_L_LOCAL, excp_vect_table_end)
 
 #ifndef CONFIG_MMU
index 5fb57fad188a9a089b0d1415c3a417306ffb0a41..7cdb5b26d03dff577c4eb68adf6cf8e63dda9ff4 100644 (file)
@@ -165,6 +165,8 @@ asmlinkage __visible __trap_section void name(struct pt_regs *regs)         \
 
 DO_ERROR_INFO(do_trap_unknown,
        SIGILL, ILL_ILLTRP, "unknown exception");
+DO_ERROR_INFO(do_trap_hardware_error,
+       SIGBUS, BUS_MCEERR_AR, "hardware error");
 DO_ERROR_INFO(do_trap_insn_misaligned,
        SIGBUS, BUS_ADRALN, "instruction address misaligned");
 DO_ERROR_INFO(do_trap_insn_fault,