linux/virt/kvm/arm/arm.c
/**
 * update_vttbr - Update the VTTBR with a valid VMID before the guest runs
 * @kvm	The guest that we are about to run
 *
 * Called from kvm_arch_vcpu_ioctl_run before entering the guest to ensure the
 * VM has a valid VMID, otherwise assigns a new one and flushes corresponding
 * caches and TLBs.
 */
Update the VTTBR with a valid VMID before the guest runs
@kvm The guest that we are about to run

Called from kvm_arch_vcpu_ioctl_run before entering the guest to ensure the
VM has a valid VMID, otherwise assigns a new one and flushes corresponding
caches and TLBs.
Update the VTTBR with a valid VMID before the guest runs @kvm The guest that we are about to run Called from kvm_arch_vcpu_ioctl_run before entering the guest to ensure the VM has a valid VMID otherwise assigns a new one and flushes corresponding caches and TLBs .
static void update_vttbr(struct kvm *kvm)
{
	phys_addr_t pgd_phys;
	u64 vmid;
	bool new_gen;
	read_lock(&kvm_vmid_lock);
	new_gen = need_new_vmid_gen(kvm);
	read_unlock(&kvm_vmid_lock);
	if (!new_gen)
		return;
	write_lock(&kvm_vmid_lock);
	if (!need_new_vmid_gen(kvm)) {
		write_unlock(&kvm_vmid_lock);
		return;
	}
	if (unlikely(kvm_next_vmid == 0)) {
		atomic64_inc(&kvm_vmid_gen);
		kvm_next_vmid = 1;
		force_vm_exit(cpu_all_mask);
		kvm_call_hyp(__kvm_flush_vm_context);
	}
	kvm->arch.vmid_gen = atomic64_read(&kvm_vmid_gen);
	kvm->arch.vmid = kvm_next_vmid;
	kvm_next_vmid++;
	kvm_next_vmid &= (1 << kvm_vmid_bits) - 1;
	pgd_phys = virt_to_phys(kvm->arch.pgd);
	BUG_ON(pgd_phys & ~VTTBR_BADDR_MASK);
	vmid = ((u64)(kvm->arch.vmid) << VTTBR_VMID_SHIFT) & VTTBR_VMID_MASK(kvm_vmid_bits);
	kvm->arch.vttbr = kvm_phys_to_vttbr(pgd_phys) | vmid;
	write_unlock(&kvm_vmid_lock);
}
static void update_vttbr ( struct kvm * kvm ) { phys_addr_t pgd_phys ; u64 vmid ; bool new_gen ; read_lock ( & kvm_vmid_lock ) ; new_gen = need_new_vmid_gen ( kvm ) ; read_unlock ( & kvm_vmid_lock ) ; if ( ! new_gen ) return ; write_lock ( & kvm_vmid_lock ) ; if ( ! need_new_vmid_gen ( kvm ) ) { write_unlock ( & kvm_vmid_lock ) ; return ; } if ( unlikely ( kvm_next_vmid == 0 ) ) { atomic64_inc ( & kvm_vmid_gen ) ; kvm_next_vmid = 1 ; force_vm_exit ( cpu_all_mask ) ; kvm_call_hyp ( __kvm_flush_vm_context ) ; } kvm -> arch . vmid_gen = atomic64_read ( & kvm_vmid_gen ) ; kvm -> arch . vmid = kvm_next_vmid ; kvm_next_vmid ++ ; kvm_next_vmid &= ( 1 << kvm_vmid_bits ) - 1 ; pgd_phys = virt_to_phys ( kvm -> arch . pgd ) ; BUG_ON ( pgd_phys & ~ VTTBR_BADDR_MASK ) ; vmid = ( ( u64 ) ( kvm -> arch . vmid ) << VTTBR_VMID_SHIFT ) & VTTBR_VMID_MASK ( kvm_vmid_bits ) ; kvm -> arch . vttbr = kvm_phys_to_vttbr ( pgd_phys ) | vmid ; write_unlock ( & kvm_vmid_lock ) ; }
update_vttbr - Update the VTTBR with a valid VMID before the guest runs
 @kvm The guest that we are about to run
update_vttbr - Update the VTTBR with a valid VMID before the guest runs @kvm The guest that we are about to run
/*
	 * We need to re-check the vmid_gen here to ensure that if another vcpu
	 * already allocated a valid vmid for this vm, then this vcpu should
	 * use the same vmid.
	 */ /* First user of a new VMID generation? */ /*
		 * On SMP we know no other CPUs can use this CPU's or each
		 * other's VMID after force_vm_exit returns since the
		 * kvm_vmid_lock blocks them from reentry to the guest.
		 */ /*
		 * Now broadcast TLB + ICACHE invalidation over the inner
		 * shareable domain to make sure all data structures are
		 * clean.
		 */ /* update vttbr to be used with the new vmid */