Skip to content

Commit bed6f0b

Browse files
binbinwu1lijinxia
authored andcommitted
hv: set start mode of vcpu
In current code, sos/uos bsp can only start from 64bit mode. For sbl platform: This patch start sos bsp from protected mode by default. CONFIG_START_VM0_BSP_64BIT is defined to allow start sos bsp from 64bit mode. If a config CONFIG_START_VM0_BSP_64BIT defined in config file, then sos bsp will start from 64bit mode. This patch start uos bsp from real mode, which needs the integration of virtual bootloader (vsbl). For uefi platform: This patch sets sos bsp vcpu mode according to the uefi context. This patch starts uos bsp from protected mode, because vsbl is not ready to publish for uefi platform yet. After vsbl is ready, can change to start uos bsp from real mode. Signed-off-by: Binbin Wu <binbin.wu@intel.com> Reviewed-by: Eddie Dong <eddie.dong@intel.com> Reviewed-by: Kevin Tian <kevin.tian@intel.com> Acked-by: Xu, Anthony <anthony.xu@intel.com>
1 parent 0d309e2 commit bed6f0b

File tree

4 files changed

+33
-5
lines changed

4 files changed

+33
-5
lines changed

hypervisor/arch/x86/guest/guest.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,7 @@ int prepare_vm0_memmap_and_e820(struct vm *vm)
552552
return 0;
553553
}
554554

555+
#ifdef CONFIG_START_VM0_BSP_64BIT
555556
/*******************************************************************
556557
* GUEST initial page table
557558
*
@@ -680,6 +681,7 @@ uint64_t create_guest_initial_paging(struct vm *vm)
680681

681682
return GUEST_INIT_PAGE_TABLE_START;
682683
}
684+
#endif
683685

684686
/*******************************************************************
685687
* GUEST initial GDT table

hypervisor/arch/x86/guest/vcpu.c

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
#include <hypervisor.h>
88
#include <schedule.h>
99

10+
#ifdef CONFIG_EFI_STUB
11+
#include <acrn_efi.h>
12+
extern struct efi_ctx* efi_ctx;
13+
#endif
14+
1015
vm_sw_loader_t vm_sw_loader;
1116

1217
/***********************************************************************
@@ -67,14 +72,16 @@ int create_vcpu(int cpu_id, struct vm *vm, struct vcpu **rtn_vcpu_handle)
6772
vcpu->pcpu_id, vcpu->vm->attr.id, vcpu->vcpu_id,
6873
is_vcpu_bsp(vcpu) ? "PRIMARY" : "SECONDARY");
6974

70-
/* Is this VCPU a VM BSP, create page hierarchy for this VM */
71-
if (is_vcpu_bsp(vcpu)) {
75+
#ifdef CONFIG_START_VM0_BSP_64BIT
76+
/* Is this VCPU a VM0 BSP, create page hierarchy for this VM */
77+
if (is_vcpu_bsp(vcpu) && is_vm0(vcpu->vm)) {
7278
/* Set up temporary guest page tables */
7379
vm->arch_vm.guest_init_pml4 = create_guest_initial_paging(vm);
7480
pr_info("VM *d VCPU %d CR3: 0x%016llx ",
7581
vm->attr.id, vcpu->vcpu_id,
7682
vm->arch_vm.guest_init_pml4);
7783
}
84+
#endif
7885

7986
/* Allocate VMCS region for this VCPU */
8087
vcpu->arch_vcpu.vmcs = alloc_page();
@@ -319,8 +326,24 @@ int prepare_vcpu(struct vm *vm, int pcpu_id)
319326
/* Load VM SW */
320327
if (!vm_sw_loader)
321328
vm_sw_loader = general_sw_loader;
329+
if (is_vm0(vcpu->vm)) {
330+
vcpu->arch_vcpu.cpu_mode = CPU_MODE_PROTECTED;
331+
#ifdef CONFIG_EFI_STUB
332+
if ((efi_ctx->efer & MSR_IA32_EFER_LMA_BIT) &&
333+
(efi_ctx->cs_ar & 0x2000))
334+
vcpu->arch_vcpu.cpu_mode = CPU_MODE_64BIT;
335+
#elif CONFIG_START_VM0_BSP_64BIT
336+
vcpu->arch_vcpu.cpu_mode = CPU_MODE_64BIT;
337+
#endif
338+
} else {
339+
#ifdef CONFIG_EFI_STUB
340+
/* currently non-vm0 will boot kernel directly */
341+
vcpu->arch_vcpu.cpu_mode = CPU_MODE_PROTECTED;
342+
#else
343+
vcpu->arch_vcpu.cpu_mode = CPU_MODE_REAL;
344+
#endif
345+
}
322346
vm_sw_loader(vm, vcpu);
323-
vcpu->arch_vcpu.cpu_mode = CPU_MODE_64BIT;
324347
} else {
325348
vcpu->arch_vcpu.cpu_mode = CPU_MODE_REAL;
326349
}

hypervisor/arch/x86/vmx.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,7 @@ static void init_guest_state(struct vcpu *vcpu)
657657
limit = 0xffff;
658658

659659
} else if (vcpu_mode == CPU_MODE_PROTECTED) {
660+
/* Linear data segment in guest init gdt */
660661
es = ss = ds = fs = gs = 0x18;
661662
limit = 0xffffffff;
662663
} else if (vcpu_mode == CPU_MODE_64BIT) {

hypervisor/common/vm_load.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,10 @@ int general_sw_loader(struct vm *vm, struct vcpu *vcpu)
122122
zeropage = (struct zero_page *)
123123
vm->sw.kernel_info.kernel_src_addr;
124124
kernel_entry_offset = (zeropage->hdr.setup_sects + 1) * 512;
125-
/* 64bit entry is the 512bytes after the start */
126-
kernel_entry_offset += 512;
125+
if (vcpu->arch_vcpu.cpu_mode == CPU_MODE_64BIT)
126+
/* 64bit entry is the 512bytes after the start */
127+
kernel_entry_offset += 512;
128+
127129
vm->sw.kernel_info.kernel_entry_addr =
128130
(void *)((unsigned long)vm->sw.kernel_info.kernel_load_addr
129131
+ kernel_entry_offset);

0 commit comments

Comments
 (0)