Skip to content

Commit 4f19b3b

Browse files
fyin1wenlingz
authored andcommitted
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 <fengwei.yin@intel.com> Acked-by: Anthony Xu <anthony.xu@intel.com>
1 parent ad1ef7b commit 4f19b3b

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

hypervisor/common/vm_load.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,25 @@ static uint32_t create_e820_table(struct e820_entry *param_e820)
3838
}
3939
#endif
4040

41+
static void prepare_bsp_gdt(struct vm *vm)
42+
{
43+
size_t gdt_len;
44+
uint64_t gdt_base_hpa;
45+
void *gdt_base_hva;
46+
47+
gdt_base_hpa = gpa2hpa(vm, vm0_boot_context.gdt.base);
48+
if (vm0_boot_context.gdt.base == gdt_base_hpa) {
49+
return;
50+
} else {
51+
gdt_base_hva = hpa2hva(gdt_base_hpa);
52+
gdt_len = ((size_t)vm0_boot_context.gdt.limit + 1U)/sizeof(uint8_t);
53+
54+
(void )memcpy_s(gdt_base_hva, gdt_len, hpa2hva(vm0_boot_context.gdt.base), gdt_len);
55+
}
56+
57+
return;
58+
}
59+
4160
static uint64_t create_zero_page(struct vm *vm)
4261
{
4362
struct zero_page *zeropage;
@@ -96,6 +115,7 @@ int general_sw_loader(struct vm *vm)
96115

97116
pr_dbg("Loading guest to run-time location");
98117

118+
prepare_bsp_gdt(vm);
99119
set_vcpu_regs(vcpu, &vm0_boot_context);
100120

101121
/* calculate the kernel entry point */

0 commit comments

Comments
 (0)