Skip to content

Commit 2ed4867

Browse files
committed
vmx: inherit default capability bits from the hypervisor
There have been some observed initialisation failures on new hypervisors / hardware, caused by us not recognising a new hypervisor feature. Previously the code would print an error and exit if it encountered an unknown feature. However the hypervisor is able to provide a safe default, so we should use that instead. Setting the features we want is a VMCS write and querying the default fields is a VMCS read. Therefore this patch - moves the capability probing into the vCPU setup where a VMCS read is possible - initialises the feature bits with a VMCS read (previously these were all 0) - removes the failure case when we encounter an unknown feature bit (since the default will be safe) Signed-off-by: David Scott <dave@recoil.org>
1 parent 67ca664 commit 2ed4867

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/lib/vmm/intel/vmx.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,7 @@ vmx_vcpu_init(void *arg, int vcpuid) {
596596
vmx_msr_guest_init(vmx, vcpuid);
597597

598598
/* Check support for primary processor-based VM-execution controls */
599+
procbased_ctls = (uint32_t) vmcs_read(vcpuid, HV_VMX_CAP_PROCBASED);
599600
error = vmx_set_ctlreg(HV_VMX_CAP_PROCBASED,
600601
PROCBASED_CTLS_ONE_SETTING,
601602
PROCBASED_CTLS_ZERO_SETTING, &procbased_ctls);
@@ -609,6 +610,7 @@ vmx_vcpu_init(void *arg, int vcpuid) {
609610
procbased_ctls &= ~PROCBASED_CTLS_WINDOW_SETTING;
610611

611612
/* Check support for secondary processor-based VM-execution controls */
613+
procbased_ctls2 = (uint32_t) vmcs_read(vcpuid, HV_VMX_CAP_PROCBASED2);
612614
error = vmx_set_ctlreg(HV_VMX_CAP_PROCBASED2,
613615
PROCBASED_CTLS2_ONE_SETTING,
614616
PROCBASED_CTLS2_ZERO_SETTING, &procbased_ctls2);
@@ -619,6 +621,7 @@ vmx_vcpu_init(void *arg, int vcpuid) {
619621
}
620622

621623
/* Check support for pin-based VM-execution controls */
624+
pinbased_ctls = (uint32_t) vmcs_read(vcpuid, HV_VMX_CAP_PINBASED);
622625
error = vmx_set_ctlreg(HV_VMX_CAP_PINBASED,
623626
PINBASED_CTLS_ONE_SETTING,
624627
PINBASED_CTLS_ZERO_SETTING, &pinbased_ctls);
@@ -629,6 +632,7 @@ vmx_vcpu_init(void *arg, int vcpuid) {
629632
}
630633

631634
/* Check support for VM-exit controls */
635+
exit_ctls = (uint32_t) vmcs_read(vcpuid, HV_VMX_CAP_EXIT);
632636
error = vmx_set_ctlreg(HV_VMX_CAP_EXIT,
633637
VM_EXIT_CTLS_ONE_SETTING,
634638
VM_EXIT_CTLS_ZERO_SETTING,
@@ -640,6 +644,7 @@ vmx_vcpu_init(void *arg, int vcpuid) {
640644
}
641645

642646
/* Check support for VM-entry controls */
647+
entry_ctls = (uint32_t) vmcs_read(vcpuid, HV_VMX_CAP_ENTRY);
643648
error = vmx_set_ctlreg(HV_VMX_CAP_ENTRY,
644649
VM_ENTRY_CTLS_ONE_SETTING, VM_ENTRY_CTLS_ZERO_SETTING,
645650
&entry_ctls);

src/lib/vmm/intel/vmx_msr.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,17 +96,17 @@ int vmx_set_ctlreg(hv_vmx_capability_t cap_field, uint32_t ones_mask,
9696
}
9797
*retval |= 1 << i;
9898
} else {
99-
/* don't care */
99+
/* Hypervisor doesn't care */
100100
if (zeros_mask & (1 << i)){
101101
*retval &= ~(1 << i);
102102
} else if (ones_mask & (1 << i)) {
103103
*retval |= 1 << i;
104104
} else {
105-
/* XXX: don't allow unspecified don't cares */
105+
/* We don't care either: inherit the system default */
106106
fprintf(stderr,
107107
"vmx_set_ctlreg: cap_field: %d bit: %d unspecified "
108-
"don't care\n", cap_field, i);
109-
return (EINVAL);
108+
"don't care: bit is %d\n", cap_field, i,
109+
(*retval & (1 << i))?1:0);
110110
}
111111
}
112112
}

0 commit comments

Comments
 (0)