aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorSamuel Holland <samuel.holland@sifive.com>2024-08-29 13:22:36 -0700
committerAnup Patel <anup@brainfault.org>2024-09-23 18:12:39 +0530
commitbeef2f693785499153b00f330d0205f91c3add4e (patch)
tree1f3a0985f4c3c763fb58ad8bc084eccb4d0cffd0 /lib
parent00093a20004baf6826d843ac3ff6e8e7c5d06b13 (diff)
downloadopensbi-beef2f693785499153b00f330d0205f91c3add4e.zip
opensbi-beef2f693785499153b00f330d0205f91c3add4e.tar.gz
opensbi-beef2f693785499153b00f330d0205f91c3add4e.tar.bz2
lib: sbi: Respect scounteren when emulating the time CSR
This optimization creates a correctness issue, as it prevents supervisor software from restricting VS-mode or U-mode access to the time CSR for its own purposes. Closes: https://github.com/riscv-software-src/opensbi/issues/370 Fixes: ebc8ebc0f846 ("lib: sbi: Improve HPM CSR read/write emulation") Signed-off-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/sbi/sbi_emulate_csr.c5
1 files changed, 2 insertions, 3 deletions
diff --git a/lib/sbi/sbi_emulate_csr.c b/lib/sbi/sbi_emulate_csr.c
index 869c81f..3adec78 100644
--- a/lib/sbi/sbi_emulate_csr.c
+++ b/lib/sbi/sbi_emulate_csr.c
@@ -66,12 +66,11 @@ int sbi_emulate_csr_read(int csr_num, struct sbi_trap_regs *regs,
*csr_val = csr_read(CSR_MCYCLE);
break;
case CSR_TIME:
+ if (!hpm_allowed(csr_num - CSR_CYCLE, prev_mode, virt))
+ return SBI_ENOTSUPP;
/*
* We emulate TIME CSR for both Host (HS/U-mode) and
* Guest (VS/VU-mode).
- *
- * Faster TIME CSR reads are critical for good performance
- * in S-mode software so we don't check CSR permissions.
*/
*csr_val = (virt) ? sbi_timer_virt_value():
sbi_timer_value();