LoongArch: KVM: Delay secondary mmu tlb flush until guest entry
authorBibo Mao <maobibo@loongson.cn>
Tue, 9 Jul 2024 08:25:50 +0000 (16:25 +0800)
committerHuacai Chen <chenhuacai@loongson.cn>
Tue, 9 Jul 2024 08:25:50 +0000 (16:25 +0800)
commitb5d4e2325db29e063ff23772adb5846f1299b2e2
tree15c0c7decb1640745f6195d9d90840bdff048cd9
parente306e514906c444c3678b9c94dd92584b0859859
LoongArch: KVM: Delay secondary mmu tlb flush until guest entry

With hardware assisted virtualization, there are two level HW mmu, one
is GVA to GPA mapping, the other is GPA to HPA mapping which is called
secondary mmu in generic. If there is page fault for secondary mmu,
there needs tlb flush operation indexed with fault GPA address and VMID.
VMID is stored at register CSR.GSTAT and will be reload or recalculated
before guest entry.

Currently CSR.GSTAT is not saved and restored during VCPU context
switch, instead it is recalculated during guest entry. So CSR.GSTAT is
effective only when a VCPU runs in guest mode, however it may not be
effective if the VCPU exits to host mode. Since register CSR.GSTAT may
be stale, it may records the VMID of the last schedule-out VCPU, rather
than the current VCPU.

Function kvm_flush_tlb_gpa() should be called with its real VMID, so
here move it to the guest entrance. Also an arch-specific request id
KVM_REQ_TLB_FLUSH_GPA is added to flush tlb for secondary mmu, and it
can be optimized if VMID is updated, since all guest tlb entries will
be invalid if VMID is updated.

Signed-off-by: Bibo Mao <maobibo@loongson.cn>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
arch/loongarch/include/asm/kvm_host.h
arch/loongarch/kvm/main.c
arch/loongarch/kvm/mmu.c
arch/loongarch/kvm/tlb.c
arch/loongarch/kvm/vcpu.c