[RFC PATCH 14/23] lib: sbi: pmu: handle temporary shmem map and unmap errors
Yu-Chien Peter Lin
peter.lin at sifive.com
Mon Nov 30 02:11:38 PST 2026
sbi_pmu_event_get_info() accesses the S-mode event info array between
sbi_hart_protection_temp_map_range() and
sbi_hart_protection_temp_unmap_range() but ignores both return values.
With Smepmp the temporary mapping is verified and can fail, and M-mode
must not touch the array without a valid mapping.
Return SBI_ERR_FAILED without accessing the array when the mapping
fails, and report a failed unmap instead of returning success. When
an earlier error exists, keep that error code.
Signed-off-by: Yu-Chien Peter Lin <peter.lin at sifive.com>
---
lib/sbi/sbi_pmu.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/lib/sbi/sbi_pmu.c b/lib/sbi/sbi_pmu.c
index f33238d8..1a5a80ba 100644
--- a/lib/sbi/sbi_pmu.c
+++ b/lib/sbi/sbi_pmu.c
@@ -1136,7 +1136,8 @@ int sbi_pmu_event_get_info(unsigned long shmem_phys_lo, unsigned long shmem_phys
SBI_DOMAIN_READ | SBI_DOMAIN_WRITE))
return SBI_ERR_INVALID_ADDRESS;
- sbi_hart_protection_temp_map_range(shmem_phys_lo, shmem_size);
+ if (sbi_hart_protection_temp_map_range(shmem_phys_lo, shmem_size))
+ return SBI_ERR_FAILED;
einfo = (struct sbi_pmu_event_info *)(shmem_phys_lo);
for (i = 0; i < num_events; i++) {
@@ -1190,7 +1191,9 @@ int sbi_pmu_event_get_info(unsigned long shmem_phys_lo, unsigned long shmem_phys
}
out_unmap:
- sbi_hart_protection_temp_unmap_range(shmem_phys_lo, shmem_size);
+ if (sbi_hart_protection_temp_unmap_range(shmem_phys_lo, shmem_size) &&
+ !ret)
+ ret = SBI_ERR_FAILED;
return ret;
}
--
2.43.7
More information about the opensbi
mailing list