Skip to content

Commit de1d7b6

Browse files
mdchitaleavpatel
authored andcommitted
RISC-V: KVM: make CY, TM, and IR counters accessible in VU mode
Those applications that run in VU mode and access the time CSR cause a virtual instruction trap as Guest kernel currently does not initialize the scounteren CSR. To fix this, we should make CY, TM, and IR counters accessibile by default in VU mode (similar to OpenSBI). Fixes: a33c72f ("RISC-V: KVM: Implement VCPU create, init and destroy functions") Cc: stable@vger.kernel.org Signed-off-by: Mayuresh Chitale <mchitale@ventanamicro.com> Signed-off-by: Anup Patel <anup@brainfault.org>
1 parent 6455317 commit de1d7b6

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

arch/riscv/kvm/vcpu.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ int kvm_arch_vcpu_precreate(struct kvm *kvm, unsigned int id)
9090
int kvm_arch_vcpu_create(struct kvm_vcpu *vcpu)
9191
{
9292
struct kvm_cpu_context *cntx;
93+
struct kvm_vcpu_csr *reset_csr = &vcpu->arch.guest_reset_csr;
9394

9495
/* Mark this VCPU never ran */
9596
vcpu->arch.ran_atleast_once = false;
@@ -106,6 +107,9 @@ int kvm_arch_vcpu_create(struct kvm_vcpu *vcpu)
106107
cntx->hstatus |= HSTATUS_SPVP;
107108
cntx->hstatus |= HSTATUS_SPV;
108109

110+
/* By default, make CY, TM, and IR counters accessible in VU mode */
111+
reset_csr->scounteren = 0x7;
112+
109113
/* Setup VCPU timer */
110114
kvm_riscv_vcpu_timer_init(vcpu);
111115

0 commit comments

Comments
 (0)