Skip to content

Commit

Permalink
hv: Prepare the gdt table for VM
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
fyin1 authored and wenlingz committed Oct 25, 2018
1 parent ad1ef7b commit 4f19b3b
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions hypervisor/common/vm_load.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 */
Expand Down

0 comments on commit 4f19b3b

Please sign in to comment.