VirtualBox

Changeset 64834 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Dec 12, 2016 4:35:07 PM (8 years ago)
Author:
vboxsync
Message:

Devices/Virtio: In an unlikely event that the guest requests features
we don't advertise, restrict requested features to supported ones,
don't use *all* supported host features. While here refactor the code
a bit to improve readability.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/VirtIO/Virtio.cpp

    r64825 r64834  
    492492    {
    493493        case VPCI_GUEST_FEATURES:
    494             /* Check if the guest negotiates properly, fall back to basics if it does not. */
    495             if (VPCI_F_BAD_FEATURE & u32)
     494        {
     495            const uint32_t uHostFeatures = vpciGetHostFeatures(pState, pCallbacks->pfnGetHostFeatures);
     496
     497            if (RT_LIKELY((u32 & ~uHostFeatures) == 0))
    496498            {
    497                 Log(("%s WARNING! Guest failed to negotiate properly (guest=%x)\n",
    498                      INSTANCE(pState), u32));
    499                 pState->uGuestFeatures = pCallbacks->pfnGetHostMinimalFeatures(pState);
    500             }
    501             /* The guest may potentially desire features we don't support! */
    502             else if (~vpciGetHostFeatures(pState, pCallbacks->pfnGetHostFeatures) & u32)
    503             {
    504                 Log(("%s Guest asked for features host does not support! (host=%x guest=%x)\n",
    505                      INSTANCE(pState),
    506                      vpciGetHostFeatures(pState, pCallbacks->pfnGetHostFeatures), u32));
    507                 pState->uGuestFeatures =
    508                     vpciGetHostFeatures(pState, pCallbacks->pfnGetHostFeatures);
     499                pState->uGuestFeatures = u32;
    509500            }
    510501            else
    511                 pState->uGuestFeatures = u32;
     502            {
     503                /*
     504                 * Guest requests features we don't advertise.  Stick
     505                 * to the minimum if negotiation looks completely
     506                 * botched, otherwise restrict to advertised features.
     507                 */
     508                if (u32 & VPCI_F_BAD_FEATURE)
     509                {
     510                    Log(("%s WARNING! Guest failed to negotiate properly (guest=%x)\n",
     511                         INSTANCE(pState), u32));
     512                    pState->uGuestFeatures = pCallbacks->pfnGetHostMinimalFeatures(pState);
     513                }
     514                else
     515                {
     516                    Log(("%s Guest asked for features host does not support! (host=%x guest=%x)\n",
     517                         INSTANCE(pState), uHostFeatures, u32));
     518                    pState->uGuestFeatures = u32 & uHostFeatures;
     519                }
     520            }
    512521            pCallbacks->pfnSetHostFeatures(pState, pState->uGuestFeatures);
    513522            break;
     523        }
    514524
    515525        case VPCI_QUEUE_PFN:
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