Skip to contentSkip to conversation

lib: sbi_trap_v_ldst: Redirect unhandled traps

PATCH Applied Michael Ellerman 2 participants 2 messages May 29 – Jun 15

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lib: sbi_trap_v_ldst: Redirect unhandled traps

When SBI is built with a compiler that doesn't support vector, the misaligned vector load/store emulation is not built in, the handlers are just stubs.

Currently the stubs just return 0, causing sbi_trap_emulate_load() to return without incrementing mepc, meaning the instruction will just fault again, an infinite loop.

Fix the stubs to use sbi_trap_redirect(), which forwards the trap to the previous mode, allowing it to be handled there.

Fixes c2acc5e5 ("lib: sbi_misaligned_ldst: Add handling of vector load/store")
---
 lib/sbi/sbi_trap_v_ldst.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
lib/sbi/sbi_trap_v_ldst.c +4 -2
index f4d469dcf28884d0eecb4fdec61eee25895d55a0..1e4336f9db23e7b972d3430cdc52addb0fcdb817 100644
@@ -334,11 +334,13 @@ int sbi_misaligned_v_st_emulator(int wlen, union sbi_ldst_data in_val,
 int sbi_misaligned_v_ld_emulator(int rlen, union sbi_ldst_data *out_val,
 				 struct sbi_trap_context *tcntx)
 {
-	return 0;
+	/* Unable to emulate, send trap to previous mode. */
+	return sbi_trap_redirect(&tcntx->regs, &tcntx->trap);
 }
 int sbi_misaligned_v_st_emulator(int wlen, union sbi_ldst_data in_val,
 				 struct sbi_trap_context *tcntx)
 {
-	return 0;
+	/* Unable to emulate, send trap to previous mode. */
+	return sbi_trap_redirect(&tcntx->regs, &tcntx->trap);
 }
 #endif /* OPENSBI_CC_SUPPORT_VECTOR */

---
base-commit: 547a5bbda7c3ec0096a6c87809851f8c2df047d1
change-id: 20260530-trap-redirect-4a66fae8aaff

Signature · 3 lines
opensbi mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/opensbi
Reviewed-by on v1 1/1 Applied
#1 lore raw
Quoted 9 lines · Michael Ellerman

When SBI is built with a compiler that doesn't support vector, the misaligned vector load/store emulation is not built in, the handlers are just stubs.

Currently the stubs just return 0, causing sbi_trap_emulate_load() to return without incrementing mepc, meaning the instruction will just fault again, an infinite loop.

Quoted 5 lines

Fix the stubs to use sbi_trap_redirect(), which forwards the trap to the previous mode, allowing it to be handled there.

Fixes c2acc5e5 ("lib: sbi_misaligned_ldst: Add handling of vector load/store")

LGTM.

Applied this patch to the riscv/opensbi repo.

Thanks,
Anup

Quoted 34 lines
---
 lib/sbi/sbi_trap_v_ldst.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
lib/sbi/sbi_trap_v_ldst.c +4 -3
index f4d469dcf28884d0eecb4fdec61eee25895d55a0..1e4336f9db23e7b972d3430cdc52addb0fcdb817 100644
@@ -334,11 +334,13 @@ int sbi_misaligned_v_st_emulator(int wlen, union sbi_ldst_data in_val,
 int sbi_misaligned_v_ld_emulator(int rlen, union sbi_ldst_data *out_val,
                                 struct sbi_trap_context *tcntx)
 {
-       return 0;
+       /* Unable to emulate, send trap to previous mode. */
+       return sbi_trap_redirect(&tcntx->regs, &tcntx->trap);
 }
 int sbi_misaligned_v_st_emulator(int wlen, union sbi_ldst_data in_val,
                                 struct sbi_trap_context *tcntx)
 {
-       return 0;
+       /* Unable to emulate, send trap to previous mode. */
+       return sbi_trap_redirect(&tcntx->regs, &tcntx->trap);
 }
 #endif /* OPENSBI_CC_SUPPORT_VECTOR */
 
---

base-commit: 547a5bbda7c3ec0096a6c87809851f8c2df047d1
change-id: 20260530-trap-redirect-4a66fae8aaff

--
opensbi mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/opensbi

Signature · 3 lines
opensbi mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/opensbi