From c42b25f27262ad3f37fdb80612189bf41a729c0d Mon Sep 17 00:00:00 2001 From: Vincent Donnefort Date: Tue, 29 Apr 2025 10:56:03 +0100 Subject: [PATCH] ANDROID: KVM: arm64: Fix pKVM alloc get_free_chunk Due to the best_available_size variable not being set on the first found chunk, the function would not return the most optimal chunk if this chunk is the first one from the list. Bug: 414541590 Bug: 357781595 Bug: 273748186 Fixes: 08477328e7ae ("ANDROID: KVM: arm64: Add a heap allocator for the pKVM hyp") Reported-by: Hiroyuki Katsura Change-Id: I96f3ce6c48cded5102b0973e004779842e252e58 Signed-off-by: Vincent Donnefort --- arch/arm64/kvm/hyp/nvhe/alloc.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/arch/arm64/kvm/hyp/nvhe/alloc.c b/arch/arm64/kvm/hyp/nvhe/alloc.c index e29db651cfe1..853b543a7142 100644 --- a/arch/arm64/kvm/hyp/nvhe/alloc.c +++ b/arch/arm64/kvm/hyp/nvhe/alloc.c @@ -523,7 +523,7 @@ static struct chunk_hdr * get_free_chunk(struct hyp_allocator *allocator, size_t size) { struct chunk_hdr *chunk, *best_chunk = NULL; - size_t best_available_size = allocator->size; + size_t best_available_size = SIZE_MAX; list_for_each_entry(chunk, &allocator->chunks, node) { size_t available_size = chunk->mapped_size + @@ -534,11 +534,6 @@ get_free_chunk(struct hyp_allocator *allocator, size_t size) if (chunk_size(size) > available_size) continue; - if (!best_chunk) { - best_chunk = chunk; - continue; - } - if (best_available_size <= available_size) continue;