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

Ben Zong-You Xie <[email protected]>
Newsgroups org.infradead.lists.opensbi
Message-ID <[email protected]>
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(-)

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
[email protected]
http://lists.infradead.org/mailman/listinfo/opensbi
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.