[PATCH v3 3/4] lib: sbi_pmu: unmap shared memory on the reserved event_idx path
Anup Patel
anup at brainfault.org
Sun Oct 25 22:05:26 PDT 2026
On Thu, Sep 10, 2026 at 10:57 AM liutong <liutong at iscas.ac.cn> wrote:
>
> 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>
Another patch doing a similar patch is already merged hence
ignoring this patch.
In the future, please watch for duplicate changes and comment
sooner.
Regards,
Anup
> ---
> 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
>
>
> --
> opensbi mailing list
> opensbi at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/opensbi
More information about the opensbi
mailing list