Skip to content

Commit 52c020c

Browse files
zhenggenjren1
authored andcommitted
VMX: bug fix on operating vmx
Switch all the referenced virtual address to physical address include ept mapping, vmcs field, vmxon, vmclear, and vmptrld. Signed-off-by: Zheng, Gen <gen.zheng@intel.com> Reviewed-by: Chen, Jason Cl <jason.cj.chen@intel.com> Reviewed-by: Yakui, Zhao <yakui.zhao@intel.com> Signed-off-by: Zheng, Gen <gen.zheng@intel.com>
1 parent 7ed446e commit 52c020c

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

hypervisor/arch/x86/guest/vmsr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ void init_msr_emulation(struct vcpu *vcpu)
163163
}
164164

165165
/* Set up MSR bitmap - pg 2904 24.6.9 */
166-
value64 = (int64_t) vcpu->vm->arch_vm.msr_bitmap;
166+
value64 = HVA2HPA(vcpu->vm->arch_vm.msr_bitmap);
167167
exec_vmwrite64(VMX_MSR_BITMAP_FULL, value64);
168168
pr_dbg("VMX_MSR_BITMAP: 0x%016llx ", value64);
169169

hypervisor/arch/x86/vmx.c

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,18 @@ int exec_vmxon_instr(void)
9898
uint64_t tmp64;
9999
uint32_t tmp32;
100100
int ret_val = -EINVAL;
101-
void *vmxon_region;
101+
void *vmxon_region_va;
102+
uint64_t vmxon_region_pa;
102103

103104
/* Allocate page aligned memory for VMXON region */
104-
vmxon_region = alloc_page();
105+
vmxon_region_va = alloc_page();
105106

106-
if (vmxon_region != 0) {
107+
if (vmxon_region_va != 0) {
107108
/* Initialize vmxon page with revision id from IA32 VMX BASIC
108109
* MSR
109110
*/
110111
tmp32 = msr_read(MSR_IA32_VMX_BASIC);
111-
memcpy_s((uint32_t *) vmxon_region, 4, &tmp32, 4);
112+
memcpy_s((uint32_t *) vmxon_region_va, 4, &tmp32, 4);
112113

113114
/* Turn on CR0.NE and CR4.VMXE */
114115
CPU_CR_READ(cr0, &tmp64);
@@ -117,7 +118,8 @@ int exec_vmxon_instr(void)
117118
CPU_CR_WRITE(cr4, tmp64 | CR4_VMXE);
118119

119120
/* Turn ON VMX */
120-
ret_val = exec_vmxon(&vmxon_region);
121+
vmxon_region_pa = HVA2HPA(vmxon_region_va);
122+
ret_val = exec_vmxon(&vmxon_region_pa);
121123
}
122124

123125
return ret_val;
@@ -825,9 +827,9 @@ static void init_host_state(__unused struct vcpu *vcpu)
825827

826828
/* Set up host instruction pointer on VM Exit */
827829
field = VMX_HOST_RIP;
828-
value32 = (uint32_t) ((uint64_t) (&vm_exit) & 0xFFFFFFFF);
830+
value64 = (uint64_t)&vm_exit;
829831
pr_dbg("HOST RIP on VMExit %x ", value32);
830-
exec_vmwrite(field, value32);
832+
exec_vmwrite(field, value64);
831833
pr_dbg("vm exit return address = %x ", value32);
832834

833835
/* These fields manage host and guest system calls * pg 3069 31.10.4.2
@@ -1003,10 +1005,10 @@ static void init_exec_ctrl(struct vcpu *vcpu)
10031005
exec_vmwrite(VMX_CR3_TARGET_COUNT, 0);
10041006

10051007
/* Set up IO bitmap register A and B - pg 2902 24.6.4 */
1006-
value64 = (int64_t) vm->arch_vm.iobitmap[0];
1008+
value64 = HVA2HPA(vm->arch_vm.iobitmap[0]);
10071009
exec_vmwrite64(VMX_IO_BITMAP_A_FULL, value64);
10081010
pr_dbg("VMX_IO_BITMAP_A: 0x%016llx ", value64);
1009-
value64 = (int64_t) vm->arch_vm.iobitmap[1];
1011+
value64 = HVA2HPA(vm->arch_vm.iobitmap[1]);
10101012
exec_vmwrite64(VMX_IO_BITMAP_B_FULL, value64);
10111013
pr_dbg("VMX_IO_BITMAP_B: 0x%016llx ", value64);
10121014

@@ -1301,6 +1303,7 @@ int init_vmcs(struct vcpu *vcpu)
13011303
{
13021304
uint32_t vmx_rev_id;
13031305
int status = 0;
1306+
uint64_t vmcs_pa;
13041307

13051308
if (vcpu == NULL)
13061309
status = -EINVAL;
@@ -1314,11 +1317,12 @@ int init_vmcs(struct vcpu *vcpu)
13141317
memcpy_s((void *) vcpu->arch_vcpu.vmcs, 4, &vmx_rev_id, 4);
13151318

13161319
/* Execute VMCLEAR on current VMCS */
1317-
status = exec_vmclear((void *)&vcpu->arch_vcpu.vmcs);
1320+
vmcs_pa = HVA2HPA(vcpu->arch_vcpu.vmcs);
1321+
status = exec_vmclear((void *)&vmcs_pa);
13181322
ASSERT(status == 0, "Failed VMCLEAR during VMCS setup!");
13191323

13201324
/* Load VMCS pointer */
1321-
status = exec_vmptrld((void *)&vcpu->arch_vcpu.vmcs);
1325+
status = exec_vmptrld((void *)&vmcs_pa);
13221326
ASSERT(status == 0, "Failed VMCS pointer load!");
13231327

13241328
/* Initialize the Virtual Machine Control Structure (VMCS) */

0 commit comments

Comments
 (0)