Re: [PATCH v3 0/3] LoongArch: KVM: Add separate vmid support

From: Huacai Chen

Date: Sat Oct 03 2026 - 00:02:59 EST


Applied, thanks.


Huacai

On Mon, Aug 31, 2026 at 5:54 PM Bibo Mao <maobibo@xxxxxxxxxxx> wrote:
>
> 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.
> ---
> v2 ... v3:
> 1. Merge patch 1-2 into one and patch 3-4 into one.
> 2. Return directly and do not update vmid in function __kvm_check_vmid()
> if feature cpu_has_guestid is disabled by AI agent review.
> 3. In function kvm_arch_disable_virtualization_cpu disable feature
> CSR_GTLBC_USES2TGID, similiar with enable cpu virtualization,
> the same from AI agent review.
> 4. Rename USEVMID with USES2TGID, VMID is KVM software word and S2TGID
> is hardware word.
> 5. Set cpu bit with vcpu->kvm->arch.tlb_flush_pending with
> KVM_REQ_TLB_FLUSH, similiar with request KVM_REQ_TLB_FLUSH_GPA.
>
> 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 (3):
> LoongArch: KVM: Add vmid support for stage2 MMU
> 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 | 71 ++++++++++++++++++++++++--
> arch/loongarch/kvm/mmu.c | 30 +++++++++--
> arch/loongarch/kvm/switch.S | 5 +-
> arch/loongarch/kvm/tlb.c | 19 ++++++-
> 8 files changed, 135 insertions(+), 12 deletions(-)
>
>
> base-commit: 73e3f0710014fe6d4ed98cfc02292f6121db7558
> --
> 2.39.3
>