Skip to contentSkip to conversation

lib: sbi: respect scounteren when emulating timeh

PATCH Applied Ben Zong-You Xie 2 participants 2 messages Aug 5 – Sep 4

lore
Share & tools
lore
#0 lore raw

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.

---
 lib/sbi/sbi_emulate_csr.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
lib/sbi/sbi_emulate_csr.c +2 -1
index c2253c82c527..4558abffb81a 100644
@@ -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
Reviewed-by on v1 1/1 Applied
#1 lore raw
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.

LGTM.

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
index c2253c82c527..4558abffb81a 100644
@@ -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