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.
Acked-by: Anthony Xu
@@ -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 */
