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: 273748186
Fixes: 08477328e7ae ("ANDROID: KVM: arm64: Add a heap allocator for the pKVM hyp")
Reported-by: Hiroyuki Katsura <hk590@cam.ac.uk>
Signed-off-by: Vincent Donnefort <vdonnefort@google.com>
(cherry picked from https://android-review.googlesource.com/q/commit:e6f1cbbab1843a62714bf19329cbabf43adbd297)
Merged-In: Ia873c8d075025a9aa759057f46c7c8fe8ce20fb8
Change-Id: Ia873c8d075025a9aa759057f46c7c8fe8ce20fb8
This commit is contained in:
Vincent Donnefort
2025-06-11 17:38:59 +01:00
parent 4ec55296c6
commit 3148030c78

View File

@@ -556,7 +556,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);