VirtualBox

Changeset 48267 in vbox for trunk/src/VBox/VMM


Ignore:
Timestamp:
Sep 4, 2013 2:06:50 PM (12 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
88682
Message:

VMM: Allow VT-x to be used in SMX mode, more granular error checking.

Location:
trunk/src/VBox/VMM
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/VMMR0/HMR0.cpp

    r48230 r48267  
    799799
    800800/**
    801  * Worker function used by hmR0PowerCallback  and HMR0Init to initalize
    802  * VT-x on a CPU.
     801 * Worker function used by hmR0PowerCallback() and HMR0Init() to initalize VT-x
     802 * on a CPU.
    803803 *
    804804 * @param   idCpu       The identifier for the CPU the function is called on.
     
    812812    NOREF(pvUser2);
    813813
    814     /*
    815      * Both the LOCK and VMXON bit must be set; otherwise VMXON will generate a #GP.
    816      * Once the lock bit is set, this MSR can no longer be modified.
    817      */
    818814    uint64_t fFC = ASMRdMsr(MSR_IA32_FEATURE_CONTROL);
    819     if (   !(fFC    & (MSR_IA32_FEATURE_CONTROL_VMXON | MSR_IA32_FEATURE_CONTROL_LOCK))
    820         || (   (fFC & (MSR_IA32_FEATURE_CONTROL_VMXON | MSR_IA32_FEATURE_CONTROL_LOCK))
    821             == MSR_IA32_FEATURE_CONTROL_VMXON ) /* Some BIOSes forget to set the locked bit. */
    822        )
    823     {
    824         /* MSR is not yet locked; we can change it ourselves here. */
    825         ASMWrMsr(MSR_IA32_FEATURE_CONTROL,
    826                  g_HvmR0.vmx.Msrs.u64FeatureCtrl | MSR_IA32_FEATURE_CONTROL_VMXON | MSR_IA32_FEATURE_CONTROL_LOCK);
     815    bool const fInSmxMode       = !!(ASMGetCR4() & X86_CR4_SMXE);
     816    bool       fMsrLocked       = !!(fFC & MSR_IA32_FEATURE_CONTROL_LOCK);
     817    bool       fSmxVmxAllowed   = !!(fFC & MSR_IA32_FEATURE_CONTROL_SMX_VMXON);
     818    bool       fVmxAllowed      = !!(fFC & MSR_IA32_FEATURE_CONTROL_VMXON);
     819
     820    /* Check if the LOCK bit is set but excludes the required VMXON bit. */
     821    int rc = VERR_HM_IPE_1;
     822    if (fMsrLocked)
     823    {
     824        if (fInSmxMode && !fSmxVmxAllowed)
     825            rc = VERR_VMX_MSR_SMX_VMXON_DISABLED;
     826        else if (!fVmxAllowed)
     827            rc = VERR_VMX_MSR_VMXON_DISABLED;
     828        else
     829            rc = VINF_SUCCESS;
     830    }
     831    else
     832    {
     833        /*
     834         * MSR is not yet locked; we can change it ourselves here.
     835         * Once the lock bit is set, this MSR can no longer be modified.
     836         */
     837        fFC |= MSR_IA32_FEATURE_CONTROL_LOCK;
     838        if (fInSmxMode)
     839            fFC |= MSR_IA32_FEATURE_CONTROL_SMX_VMXON;
     840        else
     841            fFC |= MSR_IA32_FEATURE_CONTROL_VMXON;
     842
     843        ASMWrMsr(MSR_IA32_FEATURE_CONTROL, fFC);
     844
     845        /* Verify. */
    827846        fFC = ASMRdMsr(MSR_IA32_FEATURE_CONTROL);
    828     }
    829 
    830     int rc;
    831     if ((fFC & (MSR_IA32_FEATURE_CONTROL_VMXON | MSR_IA32_FEATURE_CONTROL_LOCK))
    832         ==     (MSR_IA32_FEATURE_CONTROL_VMXON | MSR_IA32_FEATURE_CONTROL_LOCK))
    833     {
    834         rc = VINF_SUCCESS;
    835     }
    836     else
    837         rc = VERR_VMX_MSR_LOCKED_OR_DISABLED;
     847        fMsrLocked     = !!(fFC & MSR_IA32_FEATURE_CONTROL_LOCK);
     848        fSmxVmxAllowed = fMsrLocked && !!(fFC & MSR_IA32_FEATURE_CONTROL_SMX_VMXON);
     849        fVmxAllowed    = fMsrLocked && !!(fFC & MSR_IA32_FEATURE_CONTROL_VMXON);
     850
     851        if (   (fInSmxMode && fSmxVmxAllowed)
     852            || fVmxAllowed)
     853        {
     854            rc = VINF_SUCCESS;
     855        }
     856        else
     857            rc = VERR_VMX_MSR_LOCKING_FAILED;
     858    }
    838859
    839860    hmR0FirstRcSetStatus(pFirstRc, rc);
     
    929950
    930951/**
    931  * Worker function passed to RTMpOnAll, RTMpOnOthers and RTMpOnSpecific that
    932  * is to be called on the target cpus.
     952 * Worker function passed to RTMpOnAll() that is to be called on all CPUs.
    933953 *
    934954 * @param   idCpu       The identifier for the CPU the function is called on.
  • trunk/src/VBox/VMM/VMMR3/HM.cpp

    r48262 r48267  
    504504                    break;
    505505
    506                 case VERR_VMX_MSR_LOCKED_OR_DISABLED:
    507                     pszMsg = "VT-x is disabled in the BIOS (or by the host OS).";
     506                case VERR_VMX_MSR_VMXON_DISABLED:
     507                    pszMsg = "VT-x is disabled in the BIOS.";
     508                    break;
     509
     510                case VERR_VMX_MSR_SMX_VMXON_DISABLED:
     511                    pszMsg = "VT-x is disabled in the BIOS for Safer-Mode/Trusted Extensions.";
     512                    break;
     513
     514                case VERR_VMX_MSR_LOCKING_FAILED:
     515                    pszMsg = "Failed to enable and lock VT-x features.";
    508516                    break;
    509517
     
    906914            case VERR_VMX_NO_VMX:
    907915                return VM_SET_ERROR(pVM, VERR_VMX_NO_VMX, "VT-x is not available.");
    908             case VERR_VMX_MSR_LOCKED_OR_DISABLED:
    909                 return VM_SET_ERROR(pVM, VERR_VMX_NO_VMX, "VT-x is disabled in the BIOS (or by the host OS).");
     916            case VERR_VMX_MSR_VMXON_DISABLED:
     917                return VM_SET_ERROR(pVM, VERR_VMX_NO_VMX, "VT-x is disabled in the BIOS.");
     918            case VERR_VMX_MSR_SMX_VMXON_DISABLED:
     919                return VM_SET_ERROR(pVM, VERR_VMX_NO_VMX, "VT-x is disabled in the BIOS for Safer-Mode/Trusted Extensions.");
     920            case VERR_VMX_MSR_LOCKING_FAILED:
     921                return VM_SET_ERROR(pVM, VERR_VMX_NO_VMX, "Failed to enable and lock VT-x features.");
    910922
    911923            case VERR_SVM_IN_USE:
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette