riscv: add hardware error trap handler support
Subsystems (2)
PATCH 1/1 riscv: add hardware error trap handler support
From: Rui Qi <[email protected]>
adds 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.
--- arch/riscv/include/asm/asm-prototypes.h | 1 + arch/riscv/kernel/entry.S | 1 + arch/riscv/kernel/traps.c | 2 ++ 3 files changed, 4 insertions(+)
arch/riscv/include/asm/asm-prototypes.h +1 -0
@@ -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);
arch/riscv/kernel/entry.S +1 -0
@@ -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
arch/riscv/kernel/traps.c +2 -0
@@ -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,
Signature · 1 line
2.20.1
PATCH 1/1 riscv: add hardware error trap handler support
Hi all, could we loop in a few more reviewers to get broader feedback on this series
Paul Walmsley
maintainerHi,
On Mon, 2 Feb 2026, "$(name)" <$(mail address)> wrote:
Looks like your mail user agent is broken - can you fix that, please?
Quoted 10 lines
From: Rui Qi <[email protected]>
adds support for handling hardware error traps (exception code 19) in the RISC-V architecture. The changes include:
- Add
do_trap_hardware_errorfunction declaration inasm-prototypes.h
- Add hardware error trap vector entry inentry.Sexception vector table
- Implementdo_trap_hardware_errorhandler intraps.cthat generates SIGBUS withBUS_MCEERR_ARfor hardware errors
Quoted 5 lines
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 <[email protected]>
Thanks, queued for v7.1.
- Paul