Skip to content

Commit 13dc961

Browse files
binbinwu1lijinxia
authored andcommitted
hv: use vmx_write_cr<#> to init control register of uefi platform
In current code, on uefi platform, vmcs will be overwritten according to uefi context, using the exec_vmwrite directly. This patch use vmx_write_cr<#> interface to init control registers. Signed-off-by: Binbin Wu <binbin.wu@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
1 parent 66c74c6 commit 13dc961

File tree

1 file changed

+7
-17
lines changed

1 file changed

+7
-17
lines changed

hypervisor/arch/x86/vmx.c

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1358,23 +1358,13 @@ static void override_uefi_vmcs(struct vcpu *vcpu)
13581358
&vcpu->arch_vcpu.contexts[vcpu->arch_vcpu.cur_context];
13591359

13601360
if (get_vcpu_mode(vcpu) == CPU_MODE_64BIT) {
1361-
/* Set up guest CR0 field */
1362-
field = VMX_GUEST_CR0;
1363-
cur_context->cr0 = efi_ctx->cr0 | CR0_PG | CR0_PE | CR0_NE;
1364-
exec_vmwrite(field, cur_context->cr0 & 0xFFFFFFFF);
1365-
pr_dbg("VMX_GUEST_CR0: 0x%016llx ", cur_context->cr0);
1366-
1367-
/* Set up guest CR3 field */
1368-
field = VMX_GUEST_CR3;
1369-
cur_context->cr3 = efi_ctx->cr3;
1370-
exec_vmwrite(field, cur_context->cr3 & 0xFFFFFFFF);
1371-
pr_dbg("VMX_GUEST_CR3: 0x%016llx ", cur_context->cr3);
1372-
1373-
/* Set up guest CR4 field */
1374-
field = VMX_GUEST_CR4;
1375-
cur_context->cr4 = efi_ctx->cr4 | CR4_VMXE;
1376-
exec_vmwrite(field, cur_context->cr4 & 0xFFFFFFFF);
1377-
pr_dbg("VMX_GUEST_CR4: 0x%016llx ", cur_context->cr4);
1361+
/* CR4 should be set before CR0, because when set CR0, CR4 value
1362+
* will be checked. */
1363+
/* VMXE is always on bit when set CR4, and not allowed to be set
1364+
* from input cr4 value */
1365+
vmx_write_cr4(vcpu, efi_ctx->cr4 & ~CR4_VMXE);
1366+
vmx_write_cr3(vcpu, efi_ctx->cr3);
1367+
vmx_write_cr0(vcpu, efi_ctx->cr0 | CR0_PG | CR0_PE | CR0_NE);
13781368

13791369
/* Selector */
13801370
field = VMX_GUEST_CS_SEL;

0 commit comments

Comments
 (0)