From 4e1deab3d9fbb7ba80e9c6c4cb8e785df33888b1 Mon Sep 17 00:00:00 2001 From: Victor Sun Date: Thu, 3 Jun 2021 20:41:42 +0800 Subject: [PATCH] HV: init paging before init e820 With this patch, the hv_e820 will be initialized after enable paging. This is because the hv_e820 will be initialized from efi mmap when system boot from uefi, which the efi mmap could be above 4G space. Tracked-On: #5626 Signed-off-by: Victor Sun Reviewed-by: Jason Chen CJ --- hypervisor/arch/x86/cpu.c | 2 +- hypervisor/arch/x86/mmu.c | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/hypervisor/arch/x86/cpu.c b/hypervisor/arch/x86/cpu.c index 8f69c99bb..8cdef8a3e 100644 --- a/hypervisor/arch/x86/cpu.c +++ b/hypervisor/arch/x86/cpu.c @@ -144,8 +144,8 @@ void init_pcpu_pre(bool is_bsp) load_pcpu_state_data(); /* Initialize the hypervisor paging */ - init_e820(); init_paging(); + init_e820(); /* * Need update uart_base_address here for vaddr2paddr mapping may changed diff --git a/hypervisor/arch/x86/mmu.c b/hypervisor/arch/x86/mmu.c index 3f6096eee..b372bc9de 100644 --- a/hypervisor/arch/x86/mmu.c +++ b/hypervisor/arch/x86/mmu.c @@ -231,10 +231,12 @@ void init_paging(void) uint32_t i; uint64_t low32_max_ram = 0UL; uint64_t high64_max_ram = MEM_4G; + uint64_t top_addr_space = CONFIG_PLATFORM_RAM_SIZE + PLATFORM_LO_MMIO_SIZE; - const struct e820_entry *entry; - uint32_t entries_count = get_e820_entries_count(); - const struct e820_entry *p_e820 = get_e820_entry(); + struct acrn_boot_info *abi = get_acrn_boot_info(); + const struct abi_mmap *entry; + uint32_t entries_count = abi->mmap_entries; + const struct abi_mmap *p_mmap = abi->mmap_entry; pr_dbg("HV MMU Initialization"); @@ -245,8 +247,8 @@ void init_paging(void) /* Modify WB attribute for E820_TYPE_RAM */ for (i = 0U; i < entries_count; i++) { - entry = p_e820 + i; - if (entry->type == E820_TYPE_RAM) { + entry = p_mmap + i; + if (entry->type == MMAP_TYPE_RAM) { uint64_t end = entry->baseaddr + entry->length; if (end < MEM_4G) { low32_max_ram = max(end, low32_max_ram); @@ -257,6 +259,7 @@ void init_paging(void) } low32_max_ram = round_pde_up(low32_max_ram); + high64_max_ram = min(high64_max_ram, top_addr_space); high64_max_ram = round_pde_down(high64_max_ram); /* Map [0, low32_max_ram) and [4G, high64_max_ram) RAM regions as WB attribute */