jonomango / hv

Lightweight Intel VT-x Hypervisor.
MIT License
363 stars 77 forks source link

Check for support of cr3 target count before write into #42

Open 1401199262 opened 6 months ago

1401199262 commented 6 months ago

If not doing this, on some cpu vm_launch would failed with VMCS_VM_INSTRUCTION_ERROR = 7, which is invalid vm execution control fileds.

https://github.com/jonomango/hv/blob/main/hv/vmcs.cpp#L99

// 3.24.6.7 // try to trigger the least amount of CR3 exits as possible if (cpu->cached.vmx_misc.cr3_target_count >= 1) { vmx_vmwrite(VMCS_CTRL_CR3_TARGET_COUNT, 1); vmx_vmwrite(VMCS_CTRL_CR3_TARGET_VALUE_0, ghv.system_cr3.flags); } else { vmx_vmwrite(VMCS_CTRL_CR3_TARGET_COUNT, 0); }