[RFC PATCH 11/23] lib: sbi: dbtr: handle temporary shmem map and unmap errors
Yu-Chien Peter Lin
peter.lin at sifive.com
Mon Nov 30 02:11:35 PST 2026
The debug trigger calls access the S-mode shared memory between
sbi_hart_protection_temp_map_range() and
sbi_hart_protection_temp_unmap_range() but ignore both return values.
With Smepmp the temporary mapping is verified and can fail, and M-mode
must not touch the shared memory without a valid mapping.
Return SBI_ERR_FAILED without accessing the shared memory when the
mapping fails, and report a failed unmap instead of returning success.
When a call already fails for another reason, keep that error code.
Signed-off-by: Yu-Chien Peter Lin <peter.lin at sifive.com>
---
lib/sbi/sbi_dbtr.c | 28 ++++++++++++++++++----------
1 file changed, 18 insertions(+), 10 deletions(-)
diff --git a/lib/sbi/sbi_dbtr.c b/lib/sbi/sbi_dbtr.c
index c97e625f..ae757f8a 100644
--- a/lib/sbi/sbi_dbtr.c
+++ b/lib/sbi/sbi_dbtr.c
@@ -657,8 +657,9 @@ int sbi_dbtr_read_trig(unsigned long smode,
shmem_base = hart_shmem_base(hs);
- sbi_hart_protection_temp_map_range((unsigned long)shmem_base,
- trig_count * sizeof(*entry));
+ if (sbi_hart_protection_temp_map_range((unsigned long)shmem_base,
+ trig_count * sizeof(*entry)))
+ return SBI_ERR_FAILED;
for_each_trig_entry(shmem_base, trig_count, typeof(*entry), entry) {
xmit = &entry->data;
trig = INDEX_TO_TRIGGER((_idx + trig_idx_base));
@@ -671,8 +672,9 @@ int sbi_dbtr_read_trig(unsigned long smode,
xmit->tdata2 = cpu_to_lle(trig->tdata2);
xmit->tdata3 = cpu_to_lle(trig->tdata3);
}
- sbi_hart_protection_temp_unmap_range((unsigned long)shmem_base,
- trig_count * sizeof(*entry));
+ if (sbi_hart_protection_temp_unmap_range((unsigned long)shmem_base,
+ trig_count * sizeof(*entry)))
+ return SBI_ERR_FAILED;
return SBI_SUCCESS;
}
@@ -702,8 +704,9 @@ int sbi_dbtr_install_trig(unsigned long smode,
return SBI_ERR_NO_SHMEM;
shmem_base = hart_shmem_base(hs);
- sbi_hart_protection_temp_map_range((unsigned long)shmem_base,
- trig_count * sizeof(*entry));
+ if (sbi_hart_protection_temp_map_range((unsigned long)shmem_base,
+ trig_count * sizeof(*entry)))
+ return SBI_ERR_FAILED;
/*
* SBI v3.0 sec 19.4 requires SBI_ERR_NOT_SUPPORTED when a trigger
@@ -801,8 +804,9 @@ int sbi_dbtr_install_trig(unsigned long smode,
}
- sbi_hart_protection_temp_unmap_range((unsigned long)shmem_base,
- trig_count * sizeof(*entry));
+ if (sbi_hart_protection_temp_unmap_range((unsigned long)shmem_base,
+ trig_count * sizeof(*entry)))
+ return SBI_ERR_FAILED;
return SBI_SUCCESS;
}
@@ -885,7 +889,9 @@ int sbi_dbtr_update_trig(unsigned long smode,
tdata3_impl = tdata_implemented(CSR_TDATA3);
for_each_trig_entry(shmem_base, trig_count, typeof(*entry), entry) {
- sbi_hart_protection_temp_map_range((unsigned long)entry, sizeof(*entry));
+ if (sbi_hart_protection_temp_map_range((unsigned long)entry,
+ sizeof(*entry)))
+ return SBI_ERR_FAILED;
trig_idx = entry->id.idx;
if (trig_idx >= hs->total_trigs) {
@@ -915,7 +921,9 @@ int sbi_dbtr_update_trig(unsigned long smode,
}
dbtr_trigger_setup(trig, &entry->data);
- sbi_hart_protection_temp_unmap_range((unsigned long)entry, sizeof(*entry));
+ if (sbi_hart_protection_temp_unmap_range((unsigned long)entry,
+ sizeof(*entry)))
+ return SBI_ERR_FAILED;
dbtr_trigger_enable(trig);
}
--
2.43.7
More information about the opensbi
mailing list