KVM: arm64: iommu: smmu: VM teardown for stage-1
When a VM is teardown, it may still have pages in mapped in it's
IOMMU, these pages are refcounted and never reclaimed.
To cleanly teardown IOMMUs from VMs, 2 operations are needed:
- Clear STE/CDs to have invalid configs implemented by
kvm_iommu_force_detach_dev
- Free all page tables used and decrement the refcount for page
mapped, Implemented in kvm_iommu_free_guest_domains, to avoid
walking all domain space, we add nr_domains for hyp_vm so we exit
early once all domains are freed. Another apporach that requires
dynamic allocation is to have a list of domains belong to the
hyp_vm.
One difference between teardown and other IOMMU operations, is that
the hyp_vcpu is not loaded, so pkvm_get_loaded_hyp_vcpu() can't be
used in reclaim path.
A new per-cpu variable is added to mark the context of teardown
operation.
Signed-off-by: Mostafa Saleh <smostafa@google.com>
8 files changed