VirtualBox

Changeset 80844 in vbox


Ignore:
Timestamp:
Sep 17, 2019 8:44:53 AM (5 years ago)
Author:
vboxsync
Message:

VMM/HMR0: Avoid clearing CR4.VMXE if the for some reason the host already has it set when we try to set-VMXON-clear probe for VMX availability.

File:
1 edited

Legend:

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

    r80587 r80844  
    405405                return rc;
    406406            }
    407             void      *pvScatchPage      = RTR0MemObjAddress(hScatchMemObj);
    408             RTHCPHYS   HCPhysScratchPage = RTR0MemObjGetPagePhysAddr(hScatchMemObj, 0);
     407            void          *pvScatchPage      = RTR0MemObjAddress(hScatchMemObj);
     408            RTHCPHYS const HCPhysScratchPage = RTR0MemObjGetPagePhysAddr(hScatchMemObj, 0);
    409409            ASMMemZeroPage(pvScatchPage);
    410410
     
    415415            RTCCUINTREG const fEFlags = ASMIntDisableFlags();
    416416
    417             /* Check CR4.VMXE. */
    418             g_HmR0.hwvirt.u.vmx.u64HostCr4 = ASMGetCR4();
    419             if (!(g_HmR0.hwvirt.u.vmx.u64HostCr4 & X86_CR4_VMXE))
    420             {
    421                 /* In theory this bit could be cleared behind our back. Which would cause #UD
    422                    faults when we try to execute the VMX instructions... */
    423                 ASMSetCR4(g_HmR0.hwvirt.u.vmx.u64HostCr4 | X86_CR4_VMXE);
    424             }
     417            /* Enable CR4.VMXE if it isn't already set. */
     418            RTCCUINTREG const uOldCr4 = SUPR0ChangeCR4(X86_CR4_VMXE, RTCCUINTREG_MAX);
    425419
    426420            /*
     
    452446            }
    453447
    454             /*
    455              * Restore CR4 again; don't leave the X86_CR4_VMXE flag set if it was not
    456              * set before (some software could incorrectly think it is in VMX mode).
    457              */
    458             ASMSetCR4(g_HmR0.hwvirt.u.vmx.u64HostCr4);
     448            /* Restore CR4.VMXE if it wasn't set prior to us setting it above. */
     449            if (!(uOldCr4 & X86_CR4_VMXE))
     450                SUPR0ChangeCR4(0 /* fOrMask */, ~X86_CR4_VMXE);
     451
     452            /* Restore interrupts. */
    459453            ASMSetFlags(fEFlags);
    460454
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