Skip to contentSkip to conversation

RISC-V: KVM: Don't clear hgatp CSR in kvm_arch_vcpu_put()

PATCH In review Anup Patel 2 participants 2 messages Mar 17, 2022 – Apr 4, 2022

Subsystems (4)
lore
Share & tools
lore

Anup Patel

author
#0 lore raw

PATCH 1/1 RISC-V: KVM: Don't clear hgatp CSR in kvm_arch_vcpu_put()

We might have RISC-V systems (such as QEMU) where VMID is not part of the TLB entry tag so these systems will have to flush all TLB enteries upon any change in hgatp.VMID.

Currently, we zero-out hgatp CSR in kvm_arch_vcpu_put() and we re-program hgatp CSR in kvm_arch_vcpu_load(). For above described systems, this will flush all TLB enteries whenever VCPU exits to user-space hence reducing performance.

This patch fixes above described performance issue by not clearing hgatp CSR in kvm_arch_vcpu_put().

Fixes 34bde9d8b9e6 ("RISC-V: KVM: Implement VCPU world-switch")
Cc stable at vger.kernel.org
---
 arch/riscv/kvm/vcpu.c | 2 --
 1 file changed, 2 deletions(-)
arch/riscv/kvm/vcpu.c +0 -2
index 624166004e36..6785aef4cbd4 100644
@@ -653,8 +653,6 @@ void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu)
 				     vcpu->arch.isa);
 	kvm_riscv_vcpu_host_fp_restore(&vcpu->arch.host_context);
 
-	csr_write(CSR_HGATP, 0);
-
 	csr->vsstatus = csr_read(CSR_VSSTATUS);
 	csr->vsie = csr_read(CSR_VSIE);
 	csr->vstvec = csr_read(CSR_VSTVEC);
Signature · 1 line
2.25.1
maintainer
#1 lore raw
Quoted 10 lines · Anup Patel

We might have RISC-V systems (such as QEMU) where VMID is not part of the TLB entry tag so these systems will have to flush all TLB entries upon any change in hgatp.VMID.

Currently, we zero-out hgatp CSR in kvm_arch_vcpu_put() and we re-program hgatp CSR in kvm_arch_vcpu_load(). For above described systems, this will flush all TLB entries whenever VCPU exits to user-space hence reducing performance.

Quoted 6 lines

This patch fixes above described performance issue by not clearing hgatp CSR in kvm_arch_vcpu_put().

Fixes 34bde9d8b9e6 ("RISC-V: KVM: Implement VCPU world-switch")
Cc stable at vger.kernel.org

I have queued this patch for RC fixes.

Thanks,
Anup

Quoted 20 lines
---
 arch/riscv/kvm/vcpu.c | 2 --
 1 file changed, 2 deletions(-)
arch/riscv/kvm/vcpu.c +0 -3
index 624166004e36..6785aef4cbd4 100644
@@ -653,8 +653,6 @@ void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu)
                                     vcpu->arch.isa);
        kvm_riscv_vcpu_host_fp_restore(&vcpu->arch.host_context);
 
-       csr_write(CSR_HGATP, 0);
-
        csr->vsstatus = csr_read(CSR_VSSTATUS);
        csr->vsie = csr_read(CSR_VSIE);
        csr->vstvec = csr_read(CSR_VSTVEC);
--

2.25.1