VirtualBox

Changeset 81305 in vbox for trunk/src/VBox/Main/src-server


Ignore:
Timestamp:
Oct 17, 2019 10:23:39 AM (5 years ago)
Author:
vboxsync
Message:

Main/HostImpl: Updated CPU features with nested VT-x conditions. Joined up the duplicate init and query-time into a helper function. (untested). bugref:9180

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-server/HostImpl.cpp

    r80797 r81305  
    374374    if (m->fVTSupported)
    375375    {
    376         int rc = SUPR3InitEx(false /*fUnrestricted*/, NULL);
    377         if (RT_SUCCESS(rc))
    378         {
    379             uint32_t fVTCaps;
    380             rc = SUPR3QueryVTCaps(&fVTCaps);
    381             if (RT_SUCCESS(rc))
    382             {
    383                 Assert(fVTCaps & (SUPVTCAPS_AMD_V | SUPVTCAPS_VT_X));
    384                 if (fVTCaps & SUPVTCAPS_NESTED_PAGING)
    385                     m->fNestedPagingSupported = true;
    386                 else
    387                     Assert(m->fNestedPagingSupported == false);
    388                 if (   (fVTCaps & SUPVTCAPS_AMD_V)
    389                     || (fVTCaps & SUPVTCAPS_VTX_UNRESTRICTED_GUEST))
    390                     m->fUnrestrictedGuestSupported = true;
    391                 else
    392                     Assert(m->fUnrestrictedGuestSupported == false);
    393                 /** @todo r=klaus put accurate condition here, it's still approximate. */
    394                 if (   (   (fVTCaps & SUPVTCAPS_AMD_V)
    395                         && m->fNestedPagingSupported)
    396                     || (fVTCaps & SUPVTCAPS_VTX_UNRESTRICTED_GUEST))
    397                     m->fNestedHWVirtSupported = true;
    398             }
    399             else
    400             {
    401                 LogRel(("SUPR0QueryVTCaps -> %Rrc\n", rc));
    402                 m->fVTSupported = m->fNestedPagingSupported = m->fUnrestrictedGuestSupported
    403                     = m->fNestedHWVirtSupported = false;
    404             }
    405             rc = SUPR3Term(false);
    406             AssertRC(rc);
    407         }
    408         else
    409             m->fRecheckVTSupported = true; /* Try again later when the driver is loaded. */
     376        m->fRecheckVTSupported = true; /* Try again later when the driver is loaded; cleared by i_updateProcessorFeatures on success. */
     377        i_updateProcessorFeatures();
    410378    }
    411379
     
    11691137
    11701138/**
     1139 * Updates fVTSupported, fNestedPagingSupported, fUnrestrictedGuestSupported and
     1140 * fNestedHWVirtSupported with info from SUPR3QueryVTCaps().
     1141 *
     1142 * This is repeated till we successfully open the support driver, in case it
     1143 * is loaded after VBoxSVC starts.
     1144 */
     1145void Host::i_updateProcessorFeatures()
     1146{
     1147    /* Perhaps the driver is available now... */
     1148    int rc = SUPR3InitEx(false /*fUnrestricted*/, NULL);
     1149    if (RT_SUCCESS(rc))
     1150    {
     1151        uint32_t fVTCaps;
     1152        rc = SUPR3QueryVTCaps(&fVTCaps);
     1153        AssertRC(rc);
     1154
     1155        SUPR3Term(false);
     1156
     1157        AutoWriteLock wlock(this COMMA_LOCKVAL_SRC_POS);
     1158        if (RT_FAILURE(rc))
     1159        {
     1160            LogRel(("SUPR0QueryVTCaps -> %Rrc\n", rc));
     1161            fVTCaps = 0;
     1162        }
     1163        m->fVTSupported                = (fVTCaps & (SUPVTCAPS_AMD_V | SUPVTCAPS_VT_X)) != 0;
     1164        m->fNestedPagingSupported      = (fVTCaps & SUPVTCAPS_NESTED_PAGING) != 0;
     1165        m->fUnrestrictedGuestSupported = (fVTCaps & (SUPVTCAPS_AMD_V | SUPVTCAPS_VTX_UNRESTRICTED_GUEST)) != 0;
     1166        m->fNestedHWVirtSupported      =     (fVTCaps & (SUPVTCAPS_AMD_V | SUPVTCAPS_NESTED_PAGING))
     1167                                          ==            (SUPVTCAPS_AMD_V | SUPVTCAPS_NESTED_PAGING)
     1168                                      ||     (fVTCaps & (  SUPVTCAPS_VT_X | SUPVTCAPS_NESTED_PAGING
     1169                                                         | SUPVTCAPS_VTX_UNRESTRICTED_GUEST | SUPVTCAPS_VTX_VMCS_SHADOWING))
     1170                                          ==            (  SUPVTCAPS_VT_X | SUPVTCAPS_NESTED_PAGING
     1171                                                         | SUPVTCAPS_VTX_UNRESTRICTED_GUEST | SUPVTCAPS_VTX_VMCS_SHADOWING);
     1172        m->fRecheckVTSupported = false; /* No need to try again, we cached everything. */
     1173    }
     1174}
     1175
     1176/**
    11711177 * Returns whether a host processor feature is supported or not
    11721178 *
     
    12061212        {
    12071213            alock.release();
    1208 
    1209             /* Perhaps the driver is available now... */
    1210             int rc = SUPR3InitEx(false /*fUnrestricted*/, NULL);
    1211             if (RT_SUCCESS(rc))
    1212             {
    1213                 uint32_t fVTCaps;
    1214                 rc = SUPR3QueryVTCaps(&fVTCaps);
    1215 
    1216                 AutoWriteLock wlock(this COMMA_LOCKVAL_SRC_POS);
    1217                 if (RT_SUCCESS(rc))
    1218                 {
    1219                     Assert(fVTCaps & (SUPVTCAPS_AMD_V | SUPVTCAPS_VT_X));
    1220                     if (fVTCaps & SUPVTCAPS_NESTED_PAGING)
    1221                         m->fNestedPagingSupported = true;
    1222                     else
    1223                         Assert(m->fNestedPagingSupported == false);
    1224                     if (   (fVTCaps & SUPVTCAPS_AMD_V)
    1225                         || (fVTCaps & SUPVTCAPS_VTX_UNRESTRICTED_GUEST))
    1226                         m->fUnrestrictedGuestSupported = true;
    1227                     else
    1228                         Assert(m->fUnrestrictedGuestSupported == false);
    1229                     /** @todo r=klaus put accurate condition here and update it as
    1230                      * the feature becomes available with VT-x. */
    1231                     if (   (fVTCaps & SUPVTCAPS_AMD_V)
    1232                         && m->fNestedPagingSupported)
    1233                         m->fNestedHWVirtSupported = true;
    1234                 }
    1235                 else
    1236                 {
    1237                     LogRel(("SUPR0QueryVTCaps -> %Rrc\n", rc));
    1238                     m->fVTSupported = m->fNestedPagingSupported = m->fUnrestrictedGuestSupported
    1239                         = m->fNestedHWVirtSupported = false;
    1240                 }
    1241                 rc = SUPR3Term(false);
    1242                 AssertRC(rc);
    1243                 m->fRecheckVTSupported = false; /* No need to try again, we cached everything. */
    1244             }
    1245 
     1214            i_updateProcessorFeatures();
    12461215            alock.acquire();
    12471216        }
Note: See TracChangeset for help on using the changeset viewer.

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