From 4f19b3b87523accd39ba2e6b5e14a9623aad39b5 Mon Sep 17 00:00:00 2001 From: Yin Fengwei Date: Tue, 23 Oct 2018 15:43:33 +0800 Subject: [PATCH] hv: Prepare the gdt table for VM For VMs of partition mode, there is no guarantee 1:1 mapping between gpa and hpa, we need to copy the native gdt table to each VM's memory. Tracked-On: #1565 Signed-off-by: Yin Fengwei Acked-by: Anthony Xu --- hypervisor/common/vm_load.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/hypervisor/common/vm_load.c b/hypervisor/common/vm_load.c index a0970bd60..0ab77046d 100644 --- a/hypervisor/common/vm_load.c +++ b/hypervisor/common/vm_load.c @@ -38,6 +38,25 @@ static uint32_t create_e820_table(struct e820_entry *param_e820) } #endif +static void prepare_bsp_gdt(struct vm *vm) +{ + size_t gdt_len; + uint64_t gdt_base_hpa; + void *gdt_base_hva; + + gdt_base_hpa = gpa2hpa(vm, vm0_boot_context.gdt.base); + if (vm0_boot_context.gdt.base == gdt_base_hpa) { + return; + } else { + gdt_base_hva = hpa2hva(gdt_base_hpa); + gdt_len = ((size_t)vm0_boot_context.gdt.limit + 1U)/sizeof(uint8_t); + + (void )memcpy_s(gdt_base_hva, gdt_len, hpa2hva(vm0_boot_context.gdt.base), gdt_len); + } + + return; +} + static uint64_t create_zero_page(struct vm *vm) { struct zero_page *zeropage; @@ -96,6 +115,7 @@ int general_sw_loader(struct vm *vm) pr_dbg("Loading guest to run-time location"); + prepare_bsp_gdt(vm); set_vcpu_regs(vcpu, &vm0_boot_context); /* calculate the kernel entry point */