From bb55489e5c7a736a3c23cec0f98b07286dfd319c Mon Sep 17 00:00:00 2001 From: Victor Sun Date: Sun, 2 Jun 2019 22:36:00 +0800 Subject: [PATCH] HV: make vm kernel type configurable Different kernel has different load method, it should be configurable in vm configurations; Tracked-On: #3214 Signed-off-by: Victor Sun Reviewed-by: Jason Chen CJ --- hypervisor/boot/guest/vboot_info.c | 7 +++---- hypervisor/common/vm_load.c | 8 +++++--- hypervisor/include/arch/x86/guest/vm.h | 5 +---- hypervisor/include/arch/x86/vm_config.h | 5 +++++ hypervisor/scenarios/industry/vm_configurations.c | 1 + .../scenarios/logical_partition/vm_configurations.c | 2 ++ hypervisor/scenarios/sdc/vm_configurations.c | 1 + 7 files changed, 18 insertions(+), 11 deletions(-) diff --git a/hypervisor/boot/guest/vboot_info.c b/hypervisor/boot/guest/vboot_info.c index 7d9363d9f..ee0bf1e33 100644 --- a/hypervisor/boot/guest/vboot_info.c +++ b/hypervisor/boot/guest/vboot_info.c @@ -142,7 +142,7 @@ static void *get_kernel_load_addr(struct acrn_vm *vm) struct zero_page *zeropage; switch (sw_info->kernel_type) { - case VM_LINUX_GUEST: + case KERNEL_BZIMAGE: /* According to the explaination for pref_address * in Documentation/x86/boot.txt, a relocating * bootloader should attempt to load kernel at pref_address @@ -171,6 +171,7 @@ static int32_t init_general_vm_boot_info(struct acrn_vm *vm) { struct multiboot_module *mods = NULL; struct multiboot_info *mbi = NULL; + struct acrn_vm_config *vm_config = get_vm_config(vm->vm_id); int32_t ret = -EINVAL; if (boot_regs[0] != MULTIBOOT_INFO_MAGIC) { @@ -196,13 +197,11 @@ static int32_t init_general_vm_boot_info(struct acrn_vm *vm) dev_dbg(ACRN_DBG_BOOT, "cmd addr=0x%x, str=%s", mods[0].mm_string, (char *)(uint64_t)mods[0].mm_string); - vm->sw.kernel_type = VM_LINUX_GUEST; + vm->sw.kernel_type = vm_config->os_config.kernel_type; vm->sw.kernel_info.kernel_src_addr = hpa2hva((uint64_t)mods[0].mm_mod_start); vm->sw.kernel_info.kernel_size = mods[0].mm_mod_end - mods[0].mm_mod_start; vm->sw.kernel_info.kernel_load_addr = get_kernel_load_addr(vm); - struct acrn_vm_config *vm_config = get_vm_config(vm->vm_id); - if (vm_config->load_order == PRE_LAUNCHED_VM) { vm->sw.bootargs_info.src_addr = (void *)vm_config->os_config.bootargs; vm->sw.bootargs_info.size = diff --git a/hypervisor/common/vm_load.c b/hypervisor/common/vm_load.c index 065b16f9a..028212c95 100644 --- a/hypervisor/common/vm_load.c +++ b/hypervisor/common/vm_load.c @@ -180,12 +180,14 @@ int32_t direct_boot_sw_loader(struct acrn_vm *vm) ramdisk_info->size); } - /* See if guest is a Linux guest */ - if (vm->sw.kernel_type == VM_LINUX_GUEST) { + switch (vm->sw.kernel_type) { + case KERNEL_BZIMAGE: prepare_loading_bzimage(vm, vcpu); - } else { + break; + default: pr_err("%s, Loading VM SW failed", __func__); ret = -EINVAL; + break; } if (ret == 0) { diff --git a/hypervisor/include/arch/x86/guest/vm.h b/hypervisor/include/arch/x86/guest/vm.h index 33dc8a9f7..dbc8a31b4 100644 --- a/hypervisor/include/arch/x86/guest/vm.h +++ b/hypervisor/include/arch/x86/guest/vm.h @@ -50,7 +50,7 @@ struct sw_kernel_info { }; struct vm_sw_info { - int32_t kernel_type; /* Guest kernel type */ + enum os_kernel_type kernel_type; /* Guest kernel type */ /* Kernel information (common for all guest types) */ struct sw_kernel_info kernel_info; struct sw_module_info bootargs_info; @@ -69,9 +69,6 @@ struct vm_pm_info { struct pm_s_state_data *sx_state_data; /* data for S3/S5 implementation */ }; -/* VM guest types */ -#define VM_LINUX_GUEST 0x02 -#define VM_MONO_GUEST 0x01 /* Enumerated type for VM states */ enum vm_state { VM_POWERED_OFF = 0, diff --git a/hypervisor/include/arch/x86/vm_config.h b/hypervisor/include/arch/x86/vm_config.h index c4ae96237..9ee140b62 100644 --- a/hypervisor/include/arch/x86/vm_config.h +++ b/hypervisor/include/arch/x86/vm_config.h @@ -61,8 +61,13 @@ struct vuart_config { struct target_vuart t_vuart; /* target vuart */ } __aligned(8); +enum os_kernel_type { + KERNEL_BZIMAGE = 1, +}; + struct acrn_vm_os_config { char name[MAX_VM_OS_NAME_LEN]; /* OS name, useful for debug */ + enum os_kernel_type kernel_type; /* used for kernel specifc loading method */ char bootargs[MAX_BOOTARGS_SIZE]; /* boot args/cmdline */ } __aligned(8); diff --git a/hypervisor/scenarios/industry/vm_configurations.c b/hypervisor/scenarios/industry/vm_configurations.c index ad39c4097..4c6aafc0f 100644 --- a/hypervisor/scenarios/industry/vm_configurations.c +++ b/hypervisor/scenarios/industry/vm_configurations.c @@ -22,6 +22,7 @@ struct acrn_vm_config vm_configs[CONFIG_MAX_VM_NUM] = { }, .os_config = { .name = "ACRN Service OS", + .kernel_type = KERNEL_BZIMAGE, }, .vuart[0] = { .type = VUART_LEGACY_PIO, diff --git a/hypervisor/scenarios/logical_partition/vm_configurations.c b/hypervisor/scenarios/logical_partition/vm_configurations.c index 576e5af42..6d2b0eca1 100644 --- a/hypervisor/scenarios/logical_partition/vm_configurations.c +++ b/hypervisor/scenarios/logical_partition/vm_configurations.c @@ -26,6 +26,7 @@ struct acrn_vm_config vm_configs[CONFIG_MAX_VM_NUM] = { }, .os_config = { .name = "ClearLinux", + .kernel_type = KERNEL_BZIMAGE, .bootargs = VM0_CONFIG_OS_BOOTARG_CONSOLE \ VM0_CONFIG_OS_BOOTARG_MAXCPUS \ VM0_CONFIG_OS_BOOTARG_ROOT \ @@ -64,6 +65,7 @@ struct acrn_vm_config vm_configs[CONFIG_MAX_VM_NUM] = { }, .os_config = { .name = "ClearLinux", + .kernel_type = KERNEL_BZIMAGE, .bootargs = VM1_CONFIG_OS_BOOTARG_CONSOLE \ VM1_CONFIG_OS_BOOTARG_MAXCPUS \ VM1_CONFIG_OS_BOOTARG_ROOT \ diff --git a/hypervisor/scenarios/sdc/vm_configurations.c b/hypervisor/scenarios/sdc/vm_configurations.c index fd14f450d..b10213157 100644 --- a/hypervisor/scenarios/sdc/vm_configurations.c +++ b/hypervisor/scenarios/sdc/vm_configurations.c @@ -24,6 +24,7 @@ struct acrn_vm_config vm_configs[CONFIG_MAX_VM_NUM] = { }, .os_config = { .name = "ACRN Service OS", + .kernel_type = KERNEL_BZIMAGE, }, .vuart[0] = { .type = VUART_LEGACY_PIO,