[PATCH v2 0/5] LoongArch: KVM: Add separate vmid support

From: Bibo Mao

Date: Wed Aug 05 2026 - 22:15:40 EST


LoongArch KVM hypervisor supports two-level MMU, vpid index is used
for stage1 MMU and vmid index is used for stage2 MMU.

On 3A5000, vmid must be the same with vpid. On 3A6000 platform vmid
may separate from vpid. There are such advantages if separated vmid
is supported.
1. One VM uses one vmid, vCPUs on the same VM can share the same vmid.
2. If one vCPU switch between different physical CPUs, old vmid can be
still useful if it is not expired.
3. For remote tlb flush, it is to flush TLBs which are mapping
GPA --> HPA, only vmid need update and vpid need not.

Here add separate vmid feature support, vmid feature detecting method
comes from CPUCFG8 capability when LVZ is enabled.
---
v1 ... v2:
1. Move vmid together with vpid in patch1, rename it with hw_vmid.
2. Rename kvm_check_vcpuid() with __kvm_check_vpid(), and function
kvm_check_vmid() with __kvm_check_vmid().
3. Merge part of patch 2, patch 3/4 together.
4. Use bit8 of CPUCFG8 as guestid capability rather than LVZ version,
since it is hard to decide whether this feature exists with high LVZ
version in future.
5. Set cpu bit with vcpu->kvm->arch.tlb_flush_pending rather than
using add request KVM_REQ_TLB_FLUSH_GPA, it needs flush TLB on CPU
where page fault happens and vCPU maybe migrates to other CPUs.
---
Bibo Mao (5):
LoongArch: KVM: Add vmid support for stage2 MMU
LoongArch: KVM: Add separate vCPU and VM id update function
LoongArch: KVM: Add separate vmid feature support
LoongArch: KVM: Implement vmid updating logic
LoongArch: KVM: Enable separate vmid feature

arch/loongarch/include/asm/kvm_host.h | 10 ++++
arch/loongarch/include/asm/loongarch.h | 5 ++
arch/loongarch/kernel/asm-offsets.c | 1 +
arch/loongarch/kernel/cpu-probe.c | 6 +++
arch/loongarch/kvm/main.c | 70 ++++++++++++++++++++++++--
arch/loongarch/kvm/mmu.c | 23 ++++++++-
arch/loongarch/kvm/switch.S | 5 +-
arch/loongarch/kvm/tlb.c | 19 ++++++-
arch/loongarch/kvm/vcpu.c | 3 +-
9 files changed, 131 insertions(+), 11 deletions(-)


base-commit: c21bb4193868a8de71fc4693fa741e195fdf5d86
--
2.39.3