From 3148030c78fb8af1f5ea644cf11a2810955596d3 Mon Sep 17 00:00:00 2001 From: Vincent Donnefort Date: Wed, 11 Jun 2025 17:38:59 +0100 Subject: [PATCH] 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 Signed-off-by: Vincent Donnefort (cherry picked from https://android-review.googlesource.com/q/commit:e6f1cbbab1843a62714bf19329cbabf43adbd297) Merged-In: Ia873c8d075025a9aa759057f46c7c8fe8ce20fb8 Change-Id: Ia873c8d075025a9aa759057f46c7c8fe8ce20fb8 --- arch/arm64/kvm/hyp/nvhe/alloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm64/kvm/hyp/nvhe/alloc.c b/arch/arm64/kvm/hyp/nvhe/alloc.c index dc1a7371b694..13f77784e3be 100644 --- a/arch/arm64/kvm/hyp/nvhe/alloc.c +++ b/arch/arm64/kvm/hyp/nvhe/alloc.c @@ -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);