mirror of
https://github.com/torvalds/linux.git
synced 2026-07-28 01:55:51 +02:00
KVM: arm64: Hook up reclaim hypercall to pkvm_pgtable_stage2_destroy()
During teardown of a protected guest, its memory pages must be reclaimed from the hypervisor by issuing the '__pkvm_reclaim_dying_guest_page' hypercall. Add a new helper, __pkvm_pgtable_stage2_reclaim(), which is called during the VM teardown operation to reclaim pages from the hypervisor and drop the GUP pin on the host. Tested-by: Fuad Tabba <tabba@google.com> Tested-by: Mostafa Saleh <smostafa@google.com> Signed-off-by: Will Deacon <will@kernel.org> Link: https://patch.msgid.link/20260330144841.26181-17-will@kernel.org Signed-off-by: Marc Zyngier <maz@kernel.org>
This commit is contained in:
parent
0bf5f4d400
commit
4e6e03f9ea
|
|
@ -328,6 +328,32 @@ int pkvm_pgtable_stage2_init(struct kvm_pgtable *pgt, struct kvm_s2_mmu *mmu,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int __pkvm_pgtable_stage2_reclaim(struct kvm_pgtable *pgt, u64 start, u64 end)
|
||||||
|
{
|
||||||
|
struct kvm *kvm = kvm_s2_mmu_to_kvm(pgt->mmu);
|
||||||
|
pkvm_handle_t handle = kvm->arch.pkvm.handle;
|
||||||
|
struct pkvm_mapping *mapping;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
for_each_mapping_in_range_safe(pgt, start, end, mapping) {
|
||||||
|
struct page *page;
|
||||||
|
|
||||||
|
ret = kvm_call_hyp_nvhe(__pkvm_reclaim_dying_guest_page,
|
||||||
|
handle, mapping->gfn);
|
||||||
|
if (WARN_ON(ret))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
page = pfn_to_page(mapping->pfn);
|
||||||
|
WARN_ON_ONCE(mapping->nr_pages != 1);
|
||||||
|
unpin_user_pages_dirty_lock(&page, 1, true);
|
||||||
|
account_locked_vm(current->mm, 1, false);
|
||||||
|
pkvm_mapping_remove(mapping, &pgt->pkvm_mappings);
|
||||||
|
kfree(mapping);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int __pkvm_pgtable_stage2_unshare(struct kvm_pgtable *pgt, u64 start, u64 end)
|
static int __pkvm_pgtable_stage2_unshare(struct kvm_pgtable *pgt, u64 start, u64 end)
|
||||||
{
|
{
|
||||||
struct kvm *kvm = kvm_s2_mmu_to_kvm(pgt->mmu);
|
struct kvm *kvm = kvm_s2_mmu_to_kvm(pgt->mmu);
|
||||||
|
|
@ -361,6 +387,9 @@ void pkvm_pgtable_stage2_destroy_range(struct kvm_pgtable *pgt,
|
||||||
kvm->arch.pkvm.is_dying = true;
|
kvm->arch.pkvm.is_dying = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (kvm_vm_is_protected(kvm))
|
||||||
|
__pkvm_pgtable_stage2_reclaim(pgt, addr, addr + size);
|
||||||
|
else
|
||||||
__pkvm_pgtable_stage2_unshare(pgt, addr, addr + size);
|
__pkvm_pgtable_stage2_unshare(pgt, addr, addr + size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user