[PATCH v3 3/4] lib: sbi_pmu: unmap shared memory on the reserved event_idx path

liutong liutong at iscas.ac.cn
Wed Sep 9 22:26:28 PDT 2026


sbi_pmu_event_get_info() maps the S-mode shared memory into M-mode
before walking the event array and unmaps it when the walk is done.
The reserved-bit check inside the loop returns directly and skips the
unmap, so a request with a must-be-zero bit set in event_idx leaves the
mapping in place after the ecall returns.

Unmap before returning, as the other error paths in this function do.

Fixes: d97cfb33ae1a ("lib: sbi_pmu: Return invalid param error for reserved event_idx bits")
Signed-off-by: liutong <liutong at iscas.ac.cn>
---
New in v3, not part of the v2 series.

Noticed while rebasing the patch before this one onto the current error
code handling in this function.

 lib/sbi/sbi_pmu.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/lib/sbi/sbi_pmu.c b/lib/sbi/sbi_pmu.c
index 54da5c24..d8e5ea01 100644
--- a/lib/sbi/sbi_pmu.c
+++ b/lib/sbi/sbi_pmu.c
@@ -1120,8 +1120,11 @@ int sbi_pmu_event_get_info(unsigned long shmem_phys_lo, unsigned long shmem_phys
 	for (i = 0; i < num_events; i++) {
 		event_idx = einfo[i].event_idx;
 		/* Any must-be-zero event_idx bits set should return INVALID_PARAM per-spec */
-		if (event_idx & SBI_PMU_EVENT_IDX_MBZ_MASK)
+		if (event_idx & SBI_PMU_EVENT_IDX_MBZ_MASK) {
+			sbi_hart_protection_temp_unmap_range(shmem_phys_lo,
+							     shmem_size);
 			return SBI_ERR_INVALID_PARAM;
+		}
 		event_type = pmu_event_validate(phs, event_idx, einfo[i].event_data);
 		if (event_type < 0) {
 			einfo[i].output = 0;
-- 
2.34.1




More information about the opensbi mailing list