mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-11-25 02:40:37 +00:00
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:
@@ -24,11 +24,10 @@ static struct lapic_regs depri_boot_lapic_regs;
|
||||
static void init_depri_boot(void)
|
||||
{
|
||||
static bool depri_initialized = false;
|
||||
struct multiboot_info *mbi = NULL;
|
||||
struct acrn_multiboot_info *mbi = get_multiboot_info();
|
||||
|
||||
if (!depri_initialized) {
|
||||
mbi = (struct multiboot_info *) hpa2hva(((uint64_t)(uint32_t)boot_regs[1]));
|
||||
if ((mbi == NULL) || ((mbi->mi_flags & MULTIBOOT_INFO_HAS_DRIVES) == 0U)) {
|
||||
if ((mbi->mi_flags & MULTIBOOT_INFO_HAS_DRIVES) == 0U) {
|
||||
pr_err("no multiboot drivers for depri_boot found");
|
||||
} else {
|
||||
(void)memcpy_s(&depri_boot_ctx, sizeof(struct depri_boot_context),
|
||||
|
||||
@@ -151,7 +151,7 @@ static int32_t init_vm_kernel_info(struct acrn_vm *vm, const struct multiboot_mo
|
||||
/**
|
||||
* @pre vm != NULL && mbi != NULL
|
||||
*/
|
||||
static void init_vm_bootargs_info(struct acrn_vm *vm, const struct multiboot_info *mbi)
|
||||
static void init_vm_bootargs_info(struct acrn_vm *vm, const struct acrn_multiboot_info *mbi)
|
||||
{
|
||||
struct acrn_vm_config *vm_config = get_vm_config(vm->vm_id);
|
||||
char *bootargs = vm_config->os_config.bootargs;
|
||||
@@ -162,12 +162,12 @@ static void init_vm_bootargs_info(struct acrn_vm *vm, const struct multiboot_inf
|
||||
} else {
|
||||
/* vm_config->load_order == SOS_VM */
|
||||
if (((mbi->mi_flags & MULTIBOOT_INFO_HAS_CMDLINE) != 0U)
|
||||
&& (*(char *)hpa2hva(mbi->mi_cmdline) != 0)) {
|
||||
&& (*(mbi->mi_cmdline) != '\0')) {
|
||||
/*
|
||||
* If there is cmdline from mbi->mi_cmdline, merge it with
|
||||
* vm_config->os_config.bootargs
|
||||
*/
|
||||
merge_cmdline(vm, hpa2hva((uint64_t)mbi->mi_cmdline), bootargs);
|
||||
merge_cmdline(vm, mbi->mi_cmdline, bootargs);
|
||||
|
||||
vm->sw.bootargs_info.src_addr = kernel_cmdline;
|
||||
vm->sw.bootargs_info.size = strnlen_s(kernel_cmdline, MAX_BOOTARGS_SIZE);
|
||||
@@ -210,10 +210,10 @@ static uint32_t get_mod_idx_by_tag(const struct multiboot_module *mods, uint32_t
|
||||
|
||||
/* @pre vm != NULL && mbi != NULL
|
||||
*/
|
||||
static int32_t init_vm_sw_load(struct acrn_vm *vm, const struct multiboot_info *mbi)
|
||||
static int32_t init_vm_sw_load(struct acrn_vm *vm, const struct acrn_multiboot_info *mbi)
|
||||
{
|
||||
struct acrn_vm_config *vm_config = get_vm_config(vm->vm_id);
|
||||
struct multiboot_module *mods = (struct multiboot_module *)hpa2hva((uint64_t)mbi->mi_mods_addr);
|
||||
struct multiboot_module *mods = (struct multiboot_module *)(&mbi->mi_mods[0]);
|
||||
uint32_t mod_idx;
|
||||
int32_t ret = -EINVAL;
|
||||
|
||||
@@ -245,25 +245,17 @@ static int32_t init_vm_sw_load(struct acrn_vm *vm, const struct multiboot_info *
|
||||
*/
|
||||
static int32_t init_general_vm_boot_info(struct acrn_vm *vm)
|
||||
{
|
||||
struct multiboot_info *mbi = NULL;
|
||||
struct acrn_multiboot_info *mbi = get_multiboot_info();
|
||||
int32_t ret = -EINVAL;
|
||||
|
||||
if (boot_regs[0] != MULTIBOOT_INFO_MAGIC) {
|
||||
panic("no multiboot info found");
|
||||
stac();
|
||||
if ((mbi->mi_flags & MULTIBOOT_INFO_HAS_MODS) == 0U) {
|
||||
panic("no multiboot module info found");
|
||||
} else {
|
||||
mbi = (struct multiboot_info *)hpa2hva((uint64_t)boot_regs[1]);
|
||||
|
||||
if (mbi != NULL) {
|
||||
stac();
|
||||
dev_dbg(DBG_LEVEL_BOOT, "Multiboot detected, flag=0x%x", mbi->mi_flags);
|
||||
if ((mbi->mi_flags & MULTIBOOT_INFO_HAS_MODS) == 0U) {
|
||||
panic("no multiboot module info found");
|
||||
} else {
|
||||
ret = init_vm_sw_load(vm, mbi);
|
||||
}
|
||||
clac();
|
||||
}
|
||||
ret = init_vm_sw_load(vm, mbi);
|
||||
}
|
||||
clac();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -31,8 +31,7 @@ static enum vboot_mode sos_boot_mode;
|
||||
*/
|
||||
void init_vboot(void)
|
||||
{
|
||||
|
||||
struct multiboot_info *mbi;
|
||||
struct acrn_multiboot_info *mbi = get_multiboot_info();
|
||||
uint32_t i;
|
||||
|
||||
const struct vboot_bootloader_map vboot_bootloader_maps[BOOTLOADER_NUM] = {
|
||||
@@ -43,23 +42,18 @@ void init_vboot(void)
|
||||
{"PXELINUX", DIRECT_BOOT_MODE},
|
||||
};
|
||||
|
||||
mbi = (struct multiboot_info *)hpa2hva((uint64_t)boot_regs[1]);
|
||||
if (mbi == NULL) {
|
||||
panic("No multiboot info");
|
||||
} else {
|
||||
for (i = 0U; i < BOOTLOADER_NUM; i++) {
|
||||
if (strncmp(hpa2hva(mbi->mi_loader_name), vboot_bootloader_maps[i].bootloader_name,
|
||||
strnlen_s(vboot_bootloader_maps[i].bootloader_name, BOOTLOADER_NAME_SIZE)) == 0) {
|
||||
/* Only support two vboot mode */
|
||||
if (vboot_bootloader_maps[i].mode == DEPRI_BOOT_MODE) {
|
||||
vboot_ops = get_deprivilege_boot_ops();
|
||||
sos_boot_mode = DEPRI_BOOT_MODE;
|
||||
} else {
|
||||
vboot_ops = get_direct_boot_ops();
|
||||
sos_boot_mode = DIRECT_BOOT_MODE;
|
||||
}
|
||||
break;
|
||||
for (i = 0U; i < BOOTLOADER_NUM; i++) {
|
||||
if (strncmp(mbi->mi_loader_name, vboot_bootloader_maps[i].bootloader_name,
|
||||
strnlen_s(vboot_bootloader_maps[i].bootloader_name, BOOTLOADER_NAME_SIZE)) == 0) {
|
||||
/* Only support two vboot mode */
|
||||
if (vboot_bootloader_maps[i].mode == DEPRI_BOOT_MODE) {
|
||||
vboot_ops = get_deprivilege_boot_ops();
|
||||
sos_boot_mode = DEPRI_BOOT_MODE;
|
||||
} else {
|
||||
vboot_ops = get_direct_boot_ops();
|
||||
sos_boot_mode = DIRECT_BOOT_MODE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user