There is a missing kvm_arm_vmid_update() before the __load_stage2() in __kvm_at_s1e01_fast(). The bug affects nested virtualization on arm64. In KVM a "stage 2" refers to the VM's page table mappings. The __kvm_at_s1e01_fast() function emulates the AT instruction, which translates a virtual address the way the MMU would and returns the result. Each stage 2 has a VMID, which the hardware uses to tag TLB and walk-cache entries, so that one VM never uses another's entries. There are only 2^8 or 2^16 VMIDs, which is quite limited, so vmid.c hands them out by generation. When they run out, a rollover starts a new generation and flushes the TLBs: the VMIDs active on a CPU at that moment are kept, and every other VMID can be given to another VM. The kvm_arm_vmid_update() function checks the VMID's generation, takes a new VMID if it is from an old generation, and marks it as active on this CPU. Without this, the shadow MMU's VMID could be an old one that now belongs to another VM, or a rollover on another CPU could hand it to another VM while we are using it. Either way the AT fills TLB entries tagged with another VM's VMID. To fix this, call kvm_arm_vmid_update() to update the VMID before loading the shadow stage 2. That marks it as active on the CPU. Then at the end of the function, undo that. Restore the original VMID as active while checking for and handling rollover. Fixes: 477e89cabb14 ("KVM: arm64: nv: Add basic emulation of AT S1E{0,1}{R,W}") Cc: stable@vger.kernel.org Signed-off-by: Dan Carpenter --- v2: Unchanged --- arch/arm64/kvm/at.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kvm/at.c b/arch/arm64/kvm/at.c index 9dfabd0586e2..5924cfa01bd4 100644 --- a/arch/arm64/kvm/at.c +++ b/arch/arm64/kvm/at.c @@ -1476,6 +1476,7 @@ static u64 __kvm_at_s1e01_fast(struct kvm_vcpu *vcpu, u32 op, u64 vaddr) } } write_sysreg_el1(vcpu_read_sys_reg(vcpu, SCTLR_EL1), SYS_SCTLR); + kvm_arm_vmid_update(&mmu->vmid); __load_stage2(mmu); skip_mmu_switch: @@ -1523,8 +1524,11 @@ static u64 __kvm_at_s1e01_fast(struct kvm_vcpu *vcpu, u32 op, u64 vaddr) write_sysreg_hcr(HCR_HOST_VHE_FLAGS); - if (mmu_cs) + if (mmu_cs) { + kvm_arm_vmid_update(&vcpu->arch.hw_mmu->vmid); + config.vttbr = kvm_get_vttbr(vcpu->arch.hw_mmu); __mmu_config_restore(&config); + } return par; } -- 2.53.0