ANDROID: KVM: arm64: Fix hyp_alloc(0)

As the name suggests, MIN_ALLOC is the minimum allocation. Make sure
that hyp_alloc(0) always uses that value. Without this, the newly
allocated chunk would look like it is free (alloc_size == 0), so the
allocator would be able to merge or recycle it.

Bug: 424172976
Bug: 357781595
Bug: 273748186
Fixes: 08477328e7 ("ANDROID: KVM: arm64: Add a heap allocator for the pKVM hyp")
Reported-by: Hiroyuki Katsura <hk590@cam.ac.uk>
Change-Id: Ia873c8d075025a9aa759057f46c7c8fe8ce20fb8
Signed-off-by: Vincent Donnefort <vdonnefort@google.com>
This commit is contained in:
Vincent Donnefort
2025-06-11 17:38:59 +01:00
parent e365f69928
commit e6f1cbbab1

View File

@@ -551,7 +551,7 @@ void *hyp_alloc(size_t size)
unsigned long chunk_addr;
int missing_map, ret = 0;
size = ALIGN(size, MIN_ALLOC);
size = ALIGN(size ?: MIN_ALLOC, MIN_ALLOC);
hyp_spin_lock(&allocator->lock);