From b454a067bec26adfd4a9cb52b5987cfab6629fc3 Mon Sep 17 00:00:00 2001 From: Yin Fengwei Date: Wed, 3 Oct 2018 20:07:39 +0800 Subject: [PATCH] hv: remove the vm loader for UOS in hv. Now, we make UOS to set BSP init state by using hypercall. We could drop the old UOS loader in HV and make vm loader in HV only for SOS. Tracked-On: #1231 Signed-off-by: Yin Fengwei Acked-by: Eddie Dong --- hypervisor/arch/x86/guest/vcpu.c | 2 +- hypervisor/arch/x86/guest/vm.c | 8 ++-- hypervisor/bsp/uefi/uefi.c | 6 +-- hypervisor/common/vm_load.c | 45 +---------------------- hypervisor/include/arch/x86/guest/guest.h | 5 +-- 5 files changed, 11 insertions(+), 55 deletions(-) diff --git a/hypervisor/arch/x86/guest/vcpu.c b/hypervisor/arch/x86/guest/vcpu.c index 8e3475a97..14bc9588e 100644 --- a/hypervisor/arch/x86/guest/vcpu.c +++ b/hypervisor/arch/x86/guest/vcpu.c @@ -661,6 +661,7 @@ int prepare_vcpu(struct vm *vm, uint16_t pcpu_id) } else { return -EINVAL; } + vm_sw_loader(vm); } else { #ifdef CONFIG_EFI_STUB /* currently non-vm0 will boot kernel directly */ @@ -670,7 +671,6 @@ int prepare_vcpu(struct vm *vm, uint16_t pcpu_id) #endif } #endif //CONFIG_PARTITION_MODE - vm_sw_loader(vm, vcpu); } else { vcpu->arch_vcpu.cpu_mode = CPU_MODE_REAL; } diff --git a/hypervisor/arch/x86/guest/vm.c b/hypervisor/arch/x86/guest/vm.c index f978650c7..eb9adcb92 100644 --- a/hypervisor/arch/x86/guest/vm.c +++ b/hypervisor/arch/x86/guest/vm.c @@ -304,11 +304,11 @@ int reset_vm(struct vm *vm) foreach_vcpu(i, vm, vcpu) { reset_vcpu(vcpu); - vcpu->arch_vcpu.cpu_mode = CPU_MODE_REAL; - if (is_vcpu_bsp(vcpu)) { - vm_sw_loader(vm, vcpu); - } + } + + if (is_vm0(vm)) { + vm_sw_loader(vm); } vioapic_reset(vm_ioapic(vm)); diff --git a/hypervisor/bsp/uefi/uefi.c b/hypervisor/bsp/uefi/uefi.c index 50af6e95a..be605f24b 100644 --- a/hypervisor/bsp/uefi/uefi.c +++ b/hypervisor/bsp/uefi/uefi.c @@ -36,18 +36,16 @@ void efi_spurious_handler(int vector) return; } -int uefi_sw_loader(struct vm *vm, struct vcpu *vcpu) +int uefi_sw_loader(struct vm *vm) { int ret = 0; + struct vcpu *vcpu = get_primary_vcpu(vm); struct acrn_vcpu_regs *vcpu_regs = &vm0_boot_context; ASSERT(vm != NULL, "Incorrect argument"); pr_dbg("Loading guest to run-time location"); - if (!is_vm0(vm)) - return load_guest(vm, vcpu); - vlapic_restore(vcpu_vlapic(vcpu), &uefi_lapic_regs); /* For UEFI platform, the bsp init regs come from two places: diff --git a/hypervisor/common/vm_load.c b/hypervisor/common/vm_load.c index 681d08c8a..a9cdb7948 100644 --- a/hypervisor/common/vm_load.c +++ b/hypervisor/common/vm_load.c @@ -85,41 +85,7 @@ static uint64_t create_zero_page(struct vm *vm) return gpa; } -int load_guest(struct vm *vm, struct vcpu *vcpu) -{ - int32_t ret = 0; - void *hva; - uint64_t lowmem_gpa_top; - - hva = gpa2hva(vm, GUEST_CFG_OFFSET); - lowmem_gpa_top = *(uint64_t *)hva; - - hva = gpa2hva(vm, lowmem_gpa_top - - MEM_4K - MEM_2K); - vcpu->entry_addr = (void *)(*((uint64_t *)hva)); - - if (get_vcpu_mode(vcpu) == CPU_MODE_REAL) { - set_bsp_real_mode_entry(vcpu); - } else { - set_bsp_protect_mode_regs(vcpu); - } - - vcpu_set_gpreg(vcpu, CPU_REG_RSI, lowmem_gpa_top - MEM_4K); - - pr_info("%s, Set config according to predefined offset:", - __func__); - pr_info("VCPU%hu Entry: 0x%llx, RSI: 0x%016llx, cr3: 0x%016llx", - vcpu->vcpu_id, vcpu->entry_addr, - vcpu_get_gpreg(vcpu, CPU_REG_RSI), - vm->arch_vm.guest_init_pml4); - - return ret; -} - -/* - * @pre vm != NULL - */ -int general_sw_loader(struct vm *vm, struct vcpu *vcpu) +int general_sw_loader(struct vm *vm) { int32_t ret = 0; void *hva; @@ -128,17 +94,10 @@ int general_sw_loader(struct vm *vm, struct vcpu *vcpu) struct zero_page *zeropage; struct sw_linux *sw_linux = &(vm->sw.linux_info); struct sw_kernel_info *sw_kernel = &(vm->sw.kernel_info); + struct vcpu *vcpu = get_primary_vcpu(vm); pr_dbg("Loading guest to run-time location"); -/* ACRN in partiton mode boots all VMs without devicemodel */ -#ifndef CONFIG_PARTITION_MODE - /* FIXME: set config according to predefined offset */ - if (!is_vm0(vm)) { - return load_guest(vm, vcpu); - } -#endif - set_vcpu_regs(vcpu, &vm0_boot_context); /* calculate the kernel entry point */ diff --git a/hypervisor/include/arch/x86/guest/guest.h b/hypervisor/include/arch/x86/guest/guest.h index de89d83e8..2917f4ce9 100644 --- a/hypervisor/include/arch/x86/guest/guest.h +++ b/hypervisor/include/arch/x86/guest/guest.h @@ -135,10 +135,9 @@ void init_msr_emulation(struct vcpu *vcpu); struct run_context; int vmx_vmrun(struct run_context *context, int ops, int ibrs); -int load_guest(struct vm *vm, struct vcpu *vcpu); -int general_sw_loader(struct vm *vm, struct vcpu *vcpu); +int general_sw_loader(struct vm *vm); -typedef int (*vm_sw_loader_t)(struct vm *vm, struct vcpu *vcpu); +typedef int (*vm_sw_loader_t)(struct vm *vm); extern vm_sw_loader_t vm_sw_loader; /* @pre Caller(Guest) should make sure gpa is continuous.