summaryrefslogtreecommitdiff
path: root/arch/riscv/kvm
diff options
context:
space:
mode:
authorAtish Patra <atishp@rivosinc.com>2023-02-07 12:55:25 +0300
committerAnup Patel <anup@brainfault.org>2023-02-07 18:05:58 +0300
commitf04bafb52f580552dc22bfb5b7af9a5dbcc2254f (patch)
treef1b41709a765c9e9d26ba6d2db7f87acb7aabc7b /arch/riscv/kvm
parent470926a2900cfdc39b300d87a0ccdf037fa67b9a (diff)
downloadlinux-f04bafb52f580552dc22bfb5b7af9a5dbcc2254f.tar.xz
RISC-V: KVM: Disable all hpmcounter access for VS/VU mode
Any guest must not get access to any hpmcounter including cycle/instret without any checks. We achieve that by disabling all the bits except TM bit in hcounteren. However, instret and cycle access for guest user space can be enabled upon explicit request (via ONE REG) or on first trap from VU mode to maintain ABI requirement in the future. This patch doesn't support that as ONE REG interface is not settled yet. Reviewed-by: Andrew Jones <ajones@ventanamicro.com> Reviewed-by: Anup Patel <anup@brainfault.org> Signed-off-by: Atish Patra <atishp@rivosinc.com> Signed-off-by: Anup Patel <anup@brainfault.org>
Diffstat (limited to 'arch/riscv/kvm')
-rw-r--r--arch/riscv/kvm/main.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/arch/riscv/kvm/main.c b/arch/riscv/kvm/main.c
index 58c5489d3031..c5d400f36f8d 100644
--- a/arch/riscv/kvm/main.c
+++ b/arch/riscv/kvm/main.c
@@ -49,7 +49,8 @@ int kvm_arch_hardware_enable(void)
hideleg |= (1UL << IRQ_VS_EXT);
csr_write(CSR_HIDELEG, hideleg);
- csr_write(CSR_HCOUNTEREN, -1UL);
+ /* VS should access only the time counter directly. Everything else should trap */
+ csr_write(CSR_HCOUNTEREN, 0x02);
csr_write(CSR_HVIP, 0);