Skip to contentSkip to conversation

RISC-V: KVM: make CY, TM, and IR counters accessible in VU mode

PATCH In review Mayuresh Chitale 4 participants 4 messages Jan 31, 2022 – Feb 2, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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 a33c72faf2d73 ("RISC-V: KVM: Implement VCPU create, init and

destroy functions")

Cc stable at vger.kernel.org
---
 arch/riscv/kvm/vcpu.c | 4 ++++
 1 file changed, 4 insertions(+)
arch/riscv/kvm/vcpu.c +4 -0
index 0c5239e05721..caaf824347b9 100644
@@ -90,6 +90,7 @@ int kvm_arch_vcpu_precreate(struct kvm *kvm, unsigned int id)
 int kvm_arch_vcpu_create(struct kvm_vcpu *vcpu)
 {
 	struct kvm_cpu_context *cntx;
+	struct kvm_vcpu_csr *reset_csr = &vcpu->arch.guest_reset_csr;
 
 	/* Mark this VCPU never ran */
 	vcpu->arch.ran_atleast_once = false;
@@ -106,6 +107,9 @@ int kvm_arch_vcpu_create(struct kvm_vcpu *vcpu)
 	cntx->hstatus |= HSTATUS_SPVP;
 	cntx->hstatus |= HSTATUS_SPV;
 
+	/* By default, make CY, TM, and IR counters accessible in VU mode */
+	reset_csr->scounteren=0x7;
+
 	/* Setup VCPU timer */
 	kvm_riscv_vcpu_timer_init(vcpu);
 
Signature · 1 line
2.25.1
maintainer
#1 lore raw
Quoted 5 lines · Mayuresh Chitale

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.

Quoted 7 lines

To fix this, we should make CY, TM, and IR counters accessibile by default in VU mode (similar to OpenSBI).

Fixes a33c72faf2d73 ("RISC-V: KVM: Implement VCPU create, init and

destroy functions")

Cc stable at vger.kernel.org

Thanks, I have queued this for fixes.

Regards,
Anup

Quoted 29 lines
---
 arch/riscv/kvm/vcpu.c | 4 ++++
 1 file changed, 4 insertions(+)
arch/riscv/kvm/vcpu.c +4 -1
index 0c5239e05721..caaf824347b9 100644
@@ -90,6 +90,7 @@ int kvm_arch_vcpu_precreate(struct kvm *kvm, unsigned int id)
 int kvm_arch_vcpu_create(struct kvm_vcpu *vcpu)
 {
        struct kvm_cpu_context *cntx;
+       struct kvm_vcpu_csr *reset_csr = &vcpu->arch.guest_reset_csr;
 
        /* Mark this VCPU never ran */
        vcpu->arch.ran_atleast_once = false;
@@ -106,6 +107,9 @@ int kvm_arch_vcpu_create(struct kvm_vcpu *vcpu)
        cntx->hstatus |= HSTATUS_SPVP;
        cntx->hstatus |= HSTATUS_SPV;
 
+       /* By default, make CY, TM, and IR counters accessible in VU mode */
+       reset_csr->scounteren=0x7;
+
        /* Setup VCPU timer */
        kvm_riscv_vcpu_timer_init(vcpu);
 
--

2.25.1

#2 lore raw
Quoted 11 lines · Anup Patel
Quoted 8 lines · Mayuresh Chitale

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).

Quoted 6 lines
Quoted 4 lines
Fixes a33c72faf2d73 ("RISC-V: KVM: Implement VCPU create, init and

destroy functions")

Cc stable at vger.kernel.org

Thanks, I have queued this for fixes.

The formatting is clearly wrong...

Quoted 17 lines

Regards,
Anup

Quoted 14 lines

---
arch/riscv/kvm/vcpu.c | 4 ++++

1 file changed, 4 insertions(+)
arch/riscv/kvm/vcpu.c +1 -0
index 0c5239e05721..caaf824347b9 100644
@@ -90,6 +90,7 @@ int kvm_arch_vcpu_precreate(struct kvm *kvm, unsigned int id)
 int kvm_arch_vcpu_create(struct kvm_vcpu *vcpu)
 {
       struct kvm_cpu_context *cntx;
+       struct kvm_vcpu_csr *reset_csr = &vcpu->arch.guest_reset_csr;
 
Quoted 8 lines

arch/riscv/kvm/vcpu.c int kvm_arch_vcpu_create(struct kvm_vcpu *vcpu) · line 111

Quoted 8 lines
arch/riscv/kvm/vcpu.c +2 -0
       /* Mark this VCPU never ran */
       vcpu->arch.ran_atleast_once = false;
@@ -106,6 +107,9 @@ int kvm_arch_vcpu_create(struct kvm_vcpu *vcpu)
       cntx->hstatus |= HSTATUS_SPVP;
       cntx->hstatus |= HSTATUS_SPV;
 
+       /* By default, make CY, TM, and IR counters accessible in VU mode */
+       reset_csr->scounteren=0x7;

... here

Jess

Quoted 12 lines
Quoted 7 lines
arch/riscv/kvm/vcpu.c +1 -1
+
       /* Setup VCPU timer */
       kvm_riscv_vcpu_timer_init(vcpu);
 
--

2.25.1

_______________________________________________
linux-riscv mailing list
linux-riscv at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

#3 lore raw
Quoted 13 lines · Jessica Clarke
Quoted 11 lines · Anup Patel
Quoted 8 lines · Mayuresh Chitale

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).

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Fixes a33c72faf2d73 ("RISC-V: KVM: Implement VCPU create, init and

destroy functions")

Cc stable at vger.kernel.org

Thanks, I have queued this for fixes.

The formatting is clearly wrong...

I have updated this in my fixes queue.

Quoted 24 lines
Quoted 24 lines

Regards,
Anup

Quoted 20 lines

---
arch/riscv/kvm/vcpu.c | 4 ++++

1 file changed, 4 insertions(+)
arch/riscv/kvm/vcpu.c +1 -0
index 0c5239e05721..caaf824347b9 100644
@@ -90,6 +90,7 @@ int kvm_arch_vcpu_precreate(struct kvm *kvm, unsigned int id)
 int kvm_arch_vcpu_create(struct kvm_vcpu *vcpu)
 {
       struct kvm_cpu_context *cntx;
+       struct kvm_vcpu_csr *reset_csr = &vcpu->arch.guest_reset_csr;
 
       /* Mark this VCPU never ran */
       vcpu->arch.ran_atleast_once = false;
@@ -106,6 +107,9 @@ int kvm_arch_vcpu_create(struct kvm_vcpu *vcpu)
       cntx->hstatus |= HSTATUS_SPVP;
       cntx->hstatus |= HSTATUS_SPV;
 
Quoted 4 lines
Quoted 2 lines

arch/riscv/kvm/vcpu.c int kvm_arch_vcpu_create(struct kvm_vcpu *vcpu) · line 111

Quoted 2 lines
arch/riscv/kvm/vcpu.c +2 -0
+       /* By default, make CY, TM, and IR counters accessible in VU mode */
+       reset_csr->scounteren=0x7;

... here

Same as above, I have updated this my queue as well.

Thanks,
Anup

Quoted 16 lines

Jess

Quoted 12 lines
Quoted 7 lines
arch/riscv/kvm/vcpu.c +1 -1
+
       /* Setup VCPU timer */
       kvm_riscv_vcpu_timer_init(vcpu);
 
--

2.25.1

_______________________________________________
linux-riscv mailing list
linux-riscv at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv