Skip to content

Commit b1bffee

Browse files
authored
Merge pull request #285 from djs55/vmx-inherit-defaults
vmx: inherit defaults from hypervisor
2 parents 8702deb + 2ed4867 commit b1bffee

File tree

2 files changed

+63
-58
lines changed

2 files changed

+63
-58
lines changed

src/lib/vmm/intel/vmx.c

Lines changed: 59 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -496,60 +496,6 @@ vmx_init(void)
496496
xhyve_abort("hv_vm_create unknown error %d\n", error);
497497
}
498498

499-
/* Check support for primary processor-based VM-execution controls */
500-
error = vmx_set_ctlreg(HV_VMX_CAP_PROCBASED,
501-
PROCBASED_CTLS_ONE_SETTING,
502-
PROCBASED_CTLS_ZERO_SETTING, &procbased_ctls);
503-
if (error) {
504-
printf("vmx_init: processor does not support desired primary "
505-
"processor-based controls\n");
506-
return (error);
507-
}
508-
509-
/* Clear the processor-based ctl bits that are set on demand */
510-
procbased_ctls &= ~PROCBASED_CTLS_WINDOW_SETTING;
511-
512-
/* Check support for secondary processor-based VM-execution controls */
513-
error = vmx_set_ctlreg(HV_VMX_CAP_PROCBASED2,
514-
PROCBASED_CTLS2_ONE_SETTING,
515-
PROCBASED_CTLS2_ZERO_SETTING, &procbased_ctls2);
516-
if (error) {
517-
printf("vmx_init: processor does not support desired secondary "
518-
"processor-based controls\n");
519-
return (error);
520-
}
521-
522-
/* Check support for pin-based VM-execution controls */
523-
error = vmx_set_ctlreg(HV_VMX_CAP_PINBASED,
524-
PINBASED_CTLS_ONE_SETTING,
525-
PINBASED_CTLS_ZERO_SETTING, &pinbased_ctls);
526-
if (error) {
527-
printf("vmx_init: processor does not support desired "
528-
"pin-based controls\n");
529-
return (error);
530-
}
531-
532-
/* Check support for VM-exit controls */
533-
error = vmx_set_ctlreg(HV_VMX_CAP_EXIT,
534-
VM_EXIT_CTLS_ONE_SETTING,
535-
VM_EXIT_CTLS_ZERO_SETTING,
536-
&exit_ctls);
537-
if (error) {
538-
printf("vmx_init: processor does not support desired "
539-
"exit controls\n");
540-
return (error);
541-
}
542-
543-
/* Check support for VM-entry controls */
544-
error = vmx_set_ctlreg(HV_VMX_CAP_ENTRY,
545-
VM_ENTRY_CTLS_ONE_SETTING, VM_ENTRY_CTLS_ZERO_SETTING,
546-
&entry_ctls);
547-
if (error) {
548-
printf("vmx_init: processor does not support desired "
549-
"entry controls\n");
550-
return (error);
551-
}
552-
553499
/*
554500
* Check support for optional features by testing them
555501
* as individual bits
@@ -649,6 +595,65 @@ vmx_vcpu_init(void *arg, int vcpuid) {
649595

650596
vmx_msr_guest_init(vmx, vcpuid);
651597

598+
/* Check support for primary processor-based VM-execution controls */
599+
procbased_ctls = (uint32_t) vmcs_read(vcpuid, HV_VMX_CAP_PROCBASED);
600+
error = vmx_set_ctlreg(HV_VMX_CAP_PROCBASED,
601+
PROCBASED_CTLS_ONE_SETTING,
602+
PROCBASED_CTLS_ZERO_SETTING, &procbased_ctls);
603+
if (error) {
604+
printf("vmx_init: processor does not support desired primary "
605+
"processor-based controls\n");
606+
return (error);
607+
}
608+
609+
/* Clear the processor-based ctl bits that are set on demand */
610+
procbased_ctls &= ~PROCBASED_CTLS_WINDOW_SETTING;
611+
612+
/* Check support for secondary processor-based VM-execution controls */
613+
procbased_ctls2 = (uint32_t) vmcs_read(vcpuid, HV_VMX_CAP_PROCBASED2);
614+
error = vmx_set_ctlreg(HV_VMX_CAP_PROCBASED2,
615+
PROCBASED_CTLS2_ONE_SETTING,
616+
PROCBASED_CTLS2_ZERO_SETTING, &procbased_ctls2);
617+
if (error) {
618+
printf("vmx_init: processor does not support desired secondary "
619+
"processor-based controls\n");
620+
return (error);
621+
}
622+
623+
/* Check support for pin-based VM-execution controls */
624+
pinbased_ctls = (uint32_t) vmcs_read(vcpuid, HV_VMX_CAP_PINBASED);
625+
error = vmx_set_ctlreg(HV_VMX_CAP_PINBASED,
626+
PINBASED_CTLS_ONE_SETTING,
627+
PINBASED_CTLS_ZERO_SETTING, &pinbased_ctls);
628+
if (error) {
629+
printf("vmx_init: processor does not support desired "
630+
"pin-based controls\n");
631+
return (error);
632+
}
633+
634+
/* Check support for VM-exit controls */
635+
exit_ctls = (uint32_t) vmcs_read(vcpuid, HV_VMX_CAP_EXIT);
636+
error = vmx_set_ctlreg(HV_VMX_CAP_EXIT,
637+
VM_EXIT_CTLS_ONE_SETTING,
638+
VM_EXIT_CTLS_ZERO_SETTING,
639+
&exit_ctls);
640+
if (error) {
641+
printf("vmx_init: processor does not support desired "
642+
"exit controls\n");
643+
return (error);
644+
}
645+
646+
/* Check support for VM-entry controls */
647+
entry_ctls = (uint32_t) vmcs_read(vcpuid, HV_VMX_CAP_ENTRY);
648+
error = vmx_set_ctlreg(HV_VMX_CAP_ENTRY,
649+
VM_ENTRY_CTLS_ONE_SETTING, VM_ENTRY_CTLS_ZERO_SETTING,
650+
&entry_ctls);
651+
if (error) {
652+
printf("vmx_init: processor does not support desired "
653+
"entry controls\n");
654+
return (error);
655+
}
656+
652657
vmcs_write(vcpuid, VMCS_PIN_BASED_CTLS, pinbased_ctls);
653658
vmcs_write(vcpuid, VMCS_PRI_PROC_BASED_CTLS, procbased_ctls);
654659
vmcs_write(vcpuid, VMCS_SEC_PROC_BASED_CTLS, procbased_ctls2);

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)