lib: sbi: respect scounteren when emulating timeh
PATCH 1/1 lib: sbi: respect scounteren when emulating timeh
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 <[email protected]>
--- lib/sbi/sbi_emulate_csr.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
lib/sbi/sbi_emulate_csr.c +2 -1
@@ -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 ;
Signature · 7 lines
2.34.1 -- opensbi mailing list [email protected] http://lists.infradead.org/mailman/listinfo/opensbi
Quoted 7 lines · Ben Zong-You Xie
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 <[email protected]>
LGTM.
Reviewed-by Anup Patel <[email protected]>
Applied this patch to the riscv/opensbi repo.
Thanks,
Anup
Quoted 26 lines
--- lib/sbi/sbi_emulate_csr.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)lib/sbi/sbi_emulate_csr.c +2
-2@@ -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
[email protected]
http://lists.infradead.org/mailman/listinfo/opensbi
Signature · 3 lines
opensbi mailing list [email protected] http://lists.infradead.org/mailman/listinfo/opensbi