[PATCH 10/18] dbtr: Avoid crash in sbi_debug_read_triggers
Nicholas Piggin
npiggin at gmail.com
Thu Mar 12 22:19:39 PDT 2026
Not all trigger types make tdata2 or tdata3 csrs available to read.
This can result in crash in the SBI_EXT_DBTR_TRIGGER_READ ecall.
Fix this by using csr_read_allowed() to read those csrs. In the case of
a trap nothing needs to be done since the caller will know those values
are unavailable, based on the trigger type returned in tdata1.
Signed-off-by: Nicholas Piggin <npiggin at gmail.com>
---
lib/sbi/sbi_dbtr.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/lib/sbi/sbi_dbtr.c b/lib/sbi/sbi_dbtr.c
index 6efd5435..f72c76f2 100644
--- a/lib/sbi/sbi_dbtr.c
+++ b/lib/sbi/sbi_dbtr.c
@@ -575,6 +575,8 @@ int sbi_dbtr_read_trig(unsigned long smode,
sbi_hart_protection_map_range((unsigned long)shmem_base,
trig_count * sizeof(*entry));
for_each_trig_entry(shmem_base, trig_count, typeof(*entry), entry) {
+ struct sbi_trap_info trap = {0};
+
xmit = &entry->data;
trig = INDEX_TO_TRIGGER((_idx + trig_idx_base));
@@ -582,8 +584,8 @@ int sbi_dbtr_read_trig(unsigned long smode,
if (trig->state & RV_DBTR_BIT_MASK(TS, MAPPED)) {
csr_write(CSR_TSELECT, trig->index);
trig->tdata1 = csr_read(CSR_TDATA1);
- trig->tdata2 = csr_read(CSR_TDATA2);
- trig->tdata3 = csr_read(CSR_TDATA3);
+ trig->tdata2 = csr_read_allowed(CSR_TDATA2, &trap);
+ trig->tdata3 = csr_read_allowed(CSR_TDATA3, &trap);
xmit->tdata1 = cpu_to_lle(trig->tdata1);
xmit->tdata2 = cpu_to_lle(trig->tdata2);
xmit->tdata3 = cpu_to_lle(trig->tdata3);
--
2.51.0
More information about the opensbi
mailing list