HV: init and sanitize acrn multiboot info

Initialize and sanitize a acrn specific multiboot info struct with current
supported multiboot1 in very early boot stage, which would bring below
benifits:

- don't need to do hpa2hva convention every time when refering boot_regs;

- panic early if failed to sanitize multiboot info, so that don't need to
  check multiboot info pointer/flags and panic in later boot process;

- keep most code unchanged when introduce multiboot2 support in future;

Tracked-On: #4419

Signed-off-by: Victor Sun <victor.sun@intel.com>
Acked-by: Eddie Dong <eddie.dong@intel.com>
This commit is contained in:
Victor Sun
2020-02-17 09:24:44 +08:00
committed by wenlingz
parent 520a0222d3
commit 19ffaa50dc
12 changed files with 162 additions and 92 deletions

View File

@@ -116,6 +116,10 @@ void init_pcpu_pre(bool is_bsp)
panic("hardware not support!");
}
if (sanitize_multiboot_info() != 0) {
panic("Multiboot info error!");
}
init_pcpu_model_name();
load_pcpu_state_data();

View File

@@ -114,54 +114,34 @@ void init_e820(void)
uint32_t i;
uint64_t top_addr_space = CONFIG_PLATFORM_RAM_SIZE + PLATFORM_LO_MMIO_SIZE;
if (boot_regs[0] == MULTIBOOT_INFO_MAGIC) {
/*
* Before installing new PML4 table in enable_paging(), HPA->HVA is always 1:1 mapping
* and hpa2hva() can't be used to do the conversion. Here we simply treat boot_reg[1] as HPA.
*/
uint64_t hpa = (uint64_t)boot_regs[1];
struct multiboot_info *mbi = (struct multiboot_info *)hpa;
struct acrn_multiboot_info *mbi = get_multiboot_info();
struct multiboot_mmap *mmap = mbi->mi_mmap_entry;
pr_info("Multiboot info detected\n");
if ((mbi->mi_flags & MULTIBOOT_INFO_HAS_MMAP) != 0U) {
/* HPA->HVA is always 1:1 mapping at this moment */
hpa = (uint64_t)mbi->mi_mmap_addr;
struct multiboot_mmap *mmap = (struct multiboot_mmap *)hpa;
hv_e820_entries_nr = mbi->mi_mmap_entries;
hv_e820_entries_nr = mbi->mi_mmap_length / sizeof(struct multiboot_mmap);
if (hv_e820_entries_nr > E820_MAX_ENTRIES) {
pr_err("Too many E820 entries %d\n", hv_e820_entries_nr);
hv_e820_entries_nr = E820_MAX_ENTRIES;
}
dev_dbg(DBG_LEVEL_E820, "mmap addr 0x%x entries %d\n",
mbi->mi_mmap_entry, hv_e820_entries_nr);
dev_dbg(DBG_LEVEL_E820, "mmap length 0x%x addr 0x%x entries %d\n",
mbi->mi_mmap_length, mbi->mi_mmap_addr, hv_e820_entries_nr);
for (i = 0U; i < hv_e820_entries_nr; i++) {
if (mmap[i].baseaddr >= top_addr_space) {
mmap[i].length = 0UL;
} else {
if ((mmap[i].baseaddr + mmap[i].length) > top_addr_space) {
mmap[i].length = top_addr_space - mmap[i].baseaddr;
}
}
hv_e820[i].baseaddr = mmap[i].baseaddr;
hv_e820[i].length = mmap[i].length;
hv_e820[i].type = mmap[i].type;
dev_dbg(DBG_LEVEL_E820, "mmap table: %d type: 0x%x\n", i, mmap[i].type);
dev_dbg(DBG_LEVEL_E820, "Base: 0x%016lx length: 0x%016lx",
mmap[i].baseaddr, mmap[i].length);
}
for (i = 0U; i < hv_e820_entries_nr; i++) {
if (mmap[i].baseaddr >= top_addr_space) {
mmap[i].length = 0UL;
} else {
panic("no memory map found from multiboot info");
if ((mmap[i].baseaddr + mmap[i].length) > top_addr_space) {
mmap[i].length = top_addr_space - mmap[i].baseaddr;
}
}
obtain_mem_range_info();
} else {
panic("no multiboot info found");
hv_e820[i].baseaddr = mmap[i].baseaddr;
hv_e820[i].length = mmap[i].length;
hv_e820[i].type = mmap[i].type;
dev_dbg(DBG_LEVEL_E820, "mmap table: %d type: 0x%x\n", i, mmap[i].type);
dev_dbg(DBG_LEVEL_E820, "Base: 0x%016lx length: 0x%016lx",
mmap[i].baseaddr, mmap[i].length);
}
obtain_mem_range_info();
}
uint32_t get_e820_entries_count(void)

View File

@@ -14,7 +14,7 @@
#include <logmsg.h>
#include <seed.h>
#include <ld_sym.h>
#include <vboot.h>
#include <boot.h>
/* Push sp magic to top of stack for call trace */
#define SWITCH_TO(rsp, to) \

View File

@@ -41,17 +41,12 @@ static uint32_t parse_seed_arg(void)
{
char *cmd_src = NULL;
char *arg, *arg_end;
struct multiboot_info *mbi = NULL;
struct acrn_multiboot_info *mbi = get_multiboot_info();
uint32_t i = SEED_ARG_NUM - 1U;
uint32_t len;
if (boot_regs[0U] == MULTIBOOT_INFO_MAGIC) {
mbi = (struct multiboot_info *)hpa2hva((uint64_t)boot_regs[1U]);
if (mbi != NULL) {
if ((mbi->mi_flags & MULTIBOOT_INFO_HAS_CMDLINE) != 0U) {
cmd_src = (char *)hpa2hva((uint64_t)mbi->mi_cmdline);
}
}
if ((mbi->mi_flags & MULTIBOOT_INFO_HAS_CMDLINE) != 0U) {
cmd_src = mbi->mi_cmdline;
}
if (cmd_src != NULL) {