MCPcopy Create free account
hub / github.com/F-Stack/f-stack / vmx_modinit

Function vmx_modinit

freebsd/amd64/vmm/intel/vmx.c:662–960  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

660}
661
662static int
663vmx_modinit(int ipinum)
664{
665 int error;
666 uint64_t basic, fixed0, fixed1, feature_control;
667 uint32_t tmp, procbased2_vid_bits;
668
669 /* CPUID.1:ECX[bit 5] must be 1 for processor to support VMX */
670 if (!(cpu_feature2 & CPUID2_VMX)) {
671 printf("vmx_modinit: processor does not support VMX "
672 "operation\n");
673 return (ENXIO);
674 }
675
676 /*
677 * Verify that MSR_IA32_FEATURE_CONTROL lock and VMXON enable bits
678 * are set (bits 0 and 2 respectively).
679 */
680 feature_control = rdmsr(MSR_IA32_FEATURE_CONTROL);
681 if ((feature_control & IA32_FEATURE_CONTROL_LOCK) == 1 &&
682 (feature_control & IA32_FEATURE_CONTROL_VMX_EN) == 0) {
683 printf("vmx_modinit: VMX operation disabled by BIOS\n");
684 return (ENXIO);
685 }
686
687 /*
688 * Verify capabilities MSR_VMX_BASIC:
689 * - bit 54 indicates support for INS/OUTS decoding
690 */
691 basic = rdmsr(MSR_VMX_BASIC);
692 if ((basic & (1UL << 54)) == 0) {
693 printf("vmx_modinit: processor does not support desired basic "
694 "capabilities\n");
695 return (EINVAL);
696 }
697
698 /* Check support for primary processor-based VM-execution controls */
699 error = vmx_set_ctlreg(MSR_VMX_PROCBASED_CTLS,
700 MSR_VMX_TRUE_PROCBASED_CTLS,
701 PROCBASED_CTLS_ONE_SETTING,
702 PROCBASED_CTLS_ZERO_SETTING, &procbased_ctls);
703 if (error) {
704 printf("vmx_modinit: processor does not support desired "
705 "primary processor-based controls\n");
706 return (error);
707 }
708
709 /* Clear the processor-based ctl bits that are set on demand */
710 procbased_ctls &= ~PROCBASED_CTLS_WINDOW_SETTING;
711
712 /* Check support for secondary processor-based VM-execution controls */
713 error = vmx_set_ctlreg(MSR_VMX_PROCBASED_CTLS2,
714 MSR_VMX_PROCBASED_CTLS2,
715 PROCBASED_CTLS2_ONE_SETTING,
716 PROCBASED_CTLS2_ZERO_SETTING, &procbased_ctls2);
717 if (error) {
718 printf("vmx_modinit: processor does not support desired "
719 "secondary processor-based controls\n");

Callers

nothing calls this directly

Calls 10

vmx_set_ctlregFunction · 0.85
host_has_rdpidFunction · 0.85
host_has_rdtscpFunction · 0.85
lapic_ipi_allocFunction · 0.85
ept_initFunction · 0.85
vpid_initFunction · 0.85
vmx_msr_initFunction · 0.85
smp_rendezvousFunction · 0.85
printfFunction · 0.50
rdmsrFunction · 0.50

Tested by

no test coverage detected