On 1/15/2022 5:37 AM, Xu, Anthony wrote:
Should we calculate ram size instead of top address? Now the top address about equal to 4G + RAM SIZE - Low Memory SIZE That's not true if high memory doesn't start from 4GB. Some logic have to get the top address of HPA and it can't replace by the RAM SIZE.
Which logic need the top address of HPA? Anthony
There might be a big hole in e820.
Anthony
-----Original Message----- From: Wei, Chenli <chenli.wei@...> Sent: Thursday, January 13, 2022 11:22 PM To: Wang, Yu1 <yu1.wang@...>; Xu, Anthony <anthony.xu@...>; acrn-dev@... Cc: Wei, Chenli <chenli.wei@...>; Chenli Wei <chenli.wei@...> Subject: [PATCH v2 1/4] hv:calculate hv_e820_top_addr_space dynamically
The e820 module could get the RAM info on run time, but the RAM size and MAX address was limited by CONFIG_PLATFORM_RAM_SIZE which was predefind by config tool.
Current solution can't support single binary for different boards or platforms and the CONFIG_PLATFORM_RAM_SIZE can't matching the RAM size if user have not update config tools setting after the device changed.
So this patch remove the CONFIG_PLATFORM_RAM_SIZE and calculate end address of each E820 entry on run time, then find the max address as the top address.
v1-->v2: 1.code format 2.change the logic of calculate top address.
Tracked-On: #6690 Signed-off-by: Chenli Wei <chenli.wei@...> --- hypervisor/arch/x86/e820.c | 36 ++++++++++++++++++++------ hypervisor/include/arch/x86/asm/e820.h | 1 + 2 files changed, 29 insertions(+), 8 deletions(-)
diff --git a/hypervisor/arch/x86/e820.c b/hypervisor/arch/x86/e820.c index 52b7e7012..f7eb8279b 100644 --- a/hypervisor/arch/x86/e820.c +++ b/hypervisor/arch/x86/e820.c @@ -13,6 +13,7 @@ #include <efi_mmap.h> #include <logmsg.h> #include <asm/guest/ept.h> +#include <util.h>
/* * e820.c contains the related e820 operations; like HV to get memory info for its MMU setup; @@ -20,6 +21,8 @@ */
static uint32_t hv_e820_entries_nr; +static uint64_t hv_e820_top_addr_space; + /* Describe the memory layout the hypervisor uses */ static struct e820_entry hv_e820[E820_MAX_ENTRIES];
@@ -105,7 +108,6 @@ uint64_t e820_alloc_memory(uint64_t size_arg, uint64_t max_addr) static void init_e820_from_efi_mmap(void) { uint32_t i, e820_idx = 0U; - uint64_t top_addr_space = CONFIG_PLATFORM_RAM_SIZE + PLATFORM_LO_MMIO_SIZE; const struct efi_memory_desc *efi_mmap_entry = get_efi_mmap_entry();
for (i = 0U; i < get_efi_mmap_entries_count(); i++) { @@ -116,13 +118,6 @@ static void init_e820_from_efi_mmap(void)
hv_e820[e820_idx].baseaddr = efi_mmap_entry[i].phys_addr; hv_e820[e820_idx].length = efi_mmap_entry[i].num_pages * PAGE_SIZE; - if (hv_e820[e820_idx].baseaddr >= top_addr_space) { - hv_e820[e820_idx].length = 0UL; - } else { - if ((hv_e820[e820_idx].baseaddr + hv_e820[e820_idx].length) > top_addr_space) { - hv_e820[e820_idx].length = top_addr_space - hv_e820[e820_idx].baseaddr; - } - }
/* The EFI BOOT Service releated regions need to be set to reserved and avoid being touched by * hypervisor, because at least below software modules rely on them: @@ -215,6 +210,24 @@ static void init_e820_from_mmap(struct acrn_boot_info *abi) } }
+static void calculate_e820_top_addr(void) +{ + uint32_t i; + + for(i = 0; i < hv_e820_entries_nr; i++){ + dev_dbg(DBG_LEVEL_E820, "hv_e820[%d]:type: 0x%x Base: 0x%016lx length: 0x%016lx", i, + hv_e820[i].type, hv_e820[i].baseaddr, hv_e820[i].length); + + if (hv_e820_top_addr_space < hv_e820[i].baseaddr + hv_e820[i].length) { + hv_e820_top_addr_space = hv_e820[i].baseaddr + hv_e820[i].length; + } + } + /* if top address less then 4G,we should set 4G as default to contain the Low MMIO */ + hv_e820_top_addr_space = (hv_e820_top_addr_space > MEM_4G) ? hv_e820_top_addr_space : MEM_4G; + + dev_dbg(DBG_LEVEL_E820, "Top Addr: 0x%016lx ",hv_e820_top_addr_space); +} + void init_e820(void) { struct acrn_boot_info *abi = get_acrn_boot_info(); @@ -225,6 +238,13 @@ void init_e820(void) } else { init_e820_from_mmap(abi); } + + calculate_e820_top_addr(); +} + +uint64_t get_e820_top_addr(void) +{ + return hv_e820_top_addr_space; }
uint32_t get_e820_entries_count(void) diff --git a/hypervisor/include/arch/x86/asm/e820.h b/hypervisor/include/arch/x86/asm/e820.h index 50459c675..23de176e7 100644 --- a/hypervisor/include/arch/x86/asm/e820.h +++ b/hypervisor/include/arch/x86/asm/e820.h @@ -40,6 +40,7 @@ void init_e820(void); uint64_t e820_alloc_memory(uint64_t size_arg, uint64_t max_addr); /* get total number of the e820 entries */ uint32_t get_e820_entries_count(void); +uint64_t get_e820_top_addr(void);
/* get the e802 entiries */ const struct e820_entry *get_e820_entry(void); -- 2.17.1
|