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: 08477328e7 ("ANDROID: KVM: arm64: Add a heap allocator for the pKVM hyp")
Reported-by: Hiroyuki Katsura <hk590@cam.ac.uk>
Change-Id: I96f3ce6c48cded5102b0973e004779842e252e58
Signed-off-by: Vincent Donnefort <vdonnefort@google.com>
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user