[PATCH] lib: sbi: respect scounteren when emulating timeh

Anup Patel anup at brainfault.org
Fri Sep 4 01:19:16 PDT 2026


On Wed, Aug 5, 2026 at 3:04 PM Ben Zong-You Xie <ben717 at andestech.com> wrote:
>
> beef2f693785 ("lib: sbi: Respect scounteren when emulating the time
> CSR") restored it for TIME only, so on RV32 supervisor software still
> cannot restrict U-mode or VS-mode access to time: rdtime traps as
> intended while rdtimeh keeps returning the upper half.
>
> Signed-off-by: Ben Zong-You Xie <ben717 at andestech.com>

LGTM.

Reviewed-by: Anup Patel <anup at brainfault.org>

Applied this patch to the riscv/opensbi repo.

Thanks,
Anup

> ---
>  lib/sbi/sbi_emulate_csr.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/lib/sbi/sbi_emulate_csr.c b/lib/sbi/sbi_emulate_csr.c
> index c2253c82c527..4558abffb81a 100644
> --- a/lib/sbi/sbi_emulate_csr.c
> +++ b/lib/sbi/sbi_emulate_csr.c
> @@ -90,7 +90,8 @@ int sbi_emulate_csr_read(int csr_num, struct sbi_trap_regs *regs,
>                 *csr_val = csr_read(CSR_MCYCLEH);
>                 break;
>         case CSR_TIMEH:
> -               /* Refer comments on TIME CSR above. */
> +               if (!hpm_allowed(csr_num - CSR_CYCLEH, prev_mode, virt))
> +                       return SBI_ENOTSUPP;
>                 *csr_val = (virt) ? sbi_timer_virt_value() >> 32:
>                                     sbi_timer_value() >> 32;
>                 break;
> --
> 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