ANDROID: KVM: arm64: Add a heap allocator for the pKVM hyp
Currently, memory used by the hypervisor comes from donations that are
embedded within HVCs. e.g. __pkvm_init_vm()'s hyp_vm, last_ran ... This
is not flexible at all. It means the host needs to know the size of the
hyp private structures, and there are no mechanism for guests HVCs to
allocate memory for the hyp in a similar fashion. Also, donations must
be page-aligned and use physically contiguous memory whenever more than
one page is necessary which might not be possible when the memory is
highly fragmented.
But here's a heap allocator to save the day. It works as any regular
heap allocator:
* hyp_alloc(size) : Returns a pointer in the hyp VA space.
* hyp_free(addr) : Free the previously allocated memory.
But also integrates the management of host donations to map and reclaim
dynamically the memory.
* hyp_alloc_refill(host_mc) : Admit host donations.
* hyp_alloc_reclaimable() : Number of pages that could be reclaimed.
* hyp_alloc_reclaim(mc, target) : Teardown pages up to the target.
Missing donations are signaled via the errno -ENOMEM which can be read
with:
* hyp_alloc_errno()
The meta-data are stored in the header of each chunk of allocated
memory. A hash ensures their integrity.
As long as pages are not reclaimed they are kept mapped in the heap to
speed-up subsequent allocations.
Bug: 357781595
Bug: 273748186
Change-Id: Ifa7eca06bce8e5e8af9ff32562240ab78cbcb860
Signed-off-by:
Vincent Donnefort <vdonnefort@google.com>
Loading