Skip to content

Commit

Permalink
RISC-V: KVM: Disable all hpmcounter access for VS/VU mode
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
atishp04 authored and avpatel committed Feb 7, 2023
1 parent 470926a commit f04bafb
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion arch/riscv/kvm/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit f04bafb

Please sign in to comment.