mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-08 20:07:46 +09:00
ANDROID: KVM: arm64: Refactor code for reclaiming guest memory into a function
Tidies up code and enables the reuse of this function. No functional change intended. Bug: 232070947 Signed-off-by: Fuad Tabba <tabba@google.com> Change-Id: I3a93dd0284e3c177b12d0cabf5e99747dceb0fb4
This commit is contained in:
@@ -738,16 +738,27 @@ err:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void teardown_donated_memory(struct kvm_hyp_memcache *mc, void *addr,
|
||||||
|
size_t size)
|
||||||
|
{
|
||||||
|
u64 pfn = hyp_phys_to_pfn(__hyp_pa(addr));
|
||||||
|
u64 nr_pages = size >> PAGE_SHIFT;
|
||||||
|
void *start;
|
||||||
|
|
||||||
|
memset(addr, 0, size);
|
||||||
|
|
||||||
|
for (start = addr; start < addr + size; start += PAGE_SIZE)
|
||||||
|
push_hyp_memcache(mc, start, hyp_virt_to_phys);
|
||||||
|
|
||||||
|
WARN_ON(__pkvm_hyp_donate_host(pfn, nr_pages));
|
||||||
|
}
|
||||||
|
|
||||||
int __pkvm_teardown_shadow(int shadow_handle)
|
int __pkvm_teardown_shadow(int shadow_handle)
|
||||||
{
|
{
|
||||||
struct kvm_hyp_memcache *mc;
|
struct kvm_hyp_memcache *mc;
|
||||||
struct kvm_shadow_vm *vm;
|
struct kvm_shadow_vm *vm;
|
||||||
struct kvm *host_kvm;
|
struct kvm *host_kvm;
|
||||||
size_t shadow_size;
|
|
||||||
int err;
|
int err;
|
||||||
u64 pfn;
|
|
||||||
u64 nr_pages;
|
|
||||||
void *addr;
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
/* Lookup then remove entry from the shadow table. */
|
/* Lookup then remove entry from the shadow table. */
|
||||||
@@ -763,6 +774,8 @@ int __pkvm_teardown_shadow(int shadow_handle)
|
|||||||
goto err_unlock;
|
goto err_unlock;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
host_kvm = vm->host_kvm;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Clear the tracking for last_loaded_vcpu for all cpus for this vm in
|
* Clear the tracking for last_loaded_vcpu for all cpus for this vm in
|
||||||
* case the same addresses for those vcpus are reused for future vms.
|
* case the same addresses for those vcpus are reused for future vms.
|
||||||
@@ -782,22 +795,14 @@ int __pkvm_teardown_shadow(int shadow_handle)
|
|||||||
hyp_spin_unlock(&shadow_lock);
|
hyp_spin_unlock(&shadow_lock);
|
||||||
|
|
||||||
/* Reclaim guest pages, and page-table pages */
|
/* Reclaim guest pages, and page-table pages */
|
||||||
mc = &vm->host_kvm->arch.pkvm.teardown_mc;
|
mc = &host_kvm->arch.pkvm.teardown_mc;
|
||||||
reclaim_guest_pages(vm, mc);
|
reclaim_guest_pages(vm, mc);
|
||||||
drain_shadow_vcpus(vm->shadow_vcpus, vm->created_vcpus, mc);
|
drain_shadow_vcpus(vm->shadow_vcpus, vm->created_vcpus, mc);
|
||||||
unpin_host_vcpus(vm->shadow_vcpus, vm->created_vcpus);
|
unpin_host_vcpus(vm->shadow_vcpus, vm->created_vcpus);
|
||||||
|
|
||||||
/* Push the metadata pages to the teardown memcache */
|
teardown_donated_memory(mc, vm, vm->shadow_area_size);
|
||||||
shadow_size = vm->shadow_area_size;
|
|
||||||
host_kvm = vm->host_kvm;
|
|
||||||
memset(vm, 0, shadow_size);
|
|
||||||
for (addr = vm; addr < ((void *)vm + shadow_size); addr += PAGE_SIZE)
|
|
||||||
push_hyp_memcache(mc, addr, hyp_virt_to_phys);
|
|
||||||
hyp_unpin_shared_mem(host_kvm, host_kvm + 1);
|
|
||||||
|
|
||||||
pfn = hyp_phys_to_pfn(__hyp_pa(vm));
|
hyp_unpin_shared_mem(host_kvm, host_kvm + 1);
|
||||||
nr_pages = shadow_size >> PAGE_SHIFT;
|
|
||||||
WARN_ON(__pkvm_hyp_donate_host(pfn, nr_pages));
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
err_unlock:
|
err_unlock:
|
||||||
|
|||||||
Reference in New Issue
Block a user