forked from Mirrors/opensbi
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: ebc8ebc0f8
("lib: sbi: Improve HPM CSR read/write emulation")
Signed-off-by: Samuel Holland <samuel.holland@sifive.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
This commit is contained in:

committed by
Anup Patel

parent
00093a2000
commit
beef2f6937
@@ -66,12 +66,11 @@ int sbi_emulate_csr_read(int csr_num, struct sbi_trap_regs *regs,
|
|||||||
*csr_val = csr_read(CSR_MCYCLE);
|
*csr_val = csr_read(CSR_MCYCLE);
|
||||||
break;
|
break;
|
||||||
case CSR_TIME:
|
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
|
* We emulate TIME CSR for both Host (HS/U-mode) and
|
||||||
* Guest (VS/VU-mode).
|
* 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():
|
*csr_val = (virt) ? sbi_timer_virt_value():
|
||||||
sbi_timer_value();
|
sbi_timer_value();
|
||||||
|
Reference in New Issue
Block a user