FROMLIST: KVM: arm64: Sort the hypervisor memblocks

We will soon need to check if a Physical Address belongs to a memblock
at EL2, so make sure to sort them so this can be done efficiently.

Acked-by: Will Deacon <will@kernel.org>
Signed-off-by: Quentin Perret <qperret@google.com>
Link: https://lore.kernel.org/r/20210315143536.214621-28-qperret@google.com
Bug: 178098380
Change-Id: I76ba1085c0ca1fd79e07bf37d12527947b10a0ee
This commit is contained in:
Quentin Perret
2021-03-15 14:35:27 +00:00
parent 1e798d4121
commit 1d349d64ba

View File

@@ -6,6 +6,7 @@
#include <linux/kvm_host.h> #include <linux/kvm_host.h>
#include <linux/memblock.h> #include <linux/memblock.h>
#include <linux/sort.h>
#include <asm/kvm_host.h> #include <asm/kvm_host.h>
@@ -18,6 +19,23 @@ static unsigned int *hyp_memblock_nr_ptr = &kvm_nvhe_sym(hyp_memblock_nr);
phys_addr_t hyp_mem_base; phys_addr_t hyp_mem_base;
phys_addr_t hyp_mem_size; phys_addr_t hyp_mem_size;
static int cmp_hyp_memblock(const void *p1, const void *p2)
{
const struct memblock_region *r1 = p1;
const struct memblock_region *r2 = p2;
return r1->base < r2->base ? -1 : (r1->base > r2->base);
}
static void __init sort_memblock_regions(void)
{
sort(hyp_memory,
*hyp_memblock_nr_ptr,
sizeof(struct memblock_region),
cmp_hyp_memblock,
NULL);
}
static int __init register_memblock_regions(void) static int __init register_memblock_regions(void)
{ {
struct memblock_region *reg; struct memblock_region *reg;
@@ -29,6 +47,7 @@ static int __init register_memblock_regions(void)
hyp_memory[*hyp_memblock_nr_ptr] = *reg; hyp_memory[*hyp_memblock_nr_ptr] = *reg;
(*hyp_memblock_nr_ptr)++; (*hyp_memblock_nr_ptr)++;
} }
sort_memblock_regions();
return 0; return 0;
} }