VirtualBox

Changeset 74618 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Oct 5, 2018 3:36:30 AM (6 years ago)
Author:
vboxsync
Message:

VMM/IEM: Nested VMX: bugref:9180 Adjust iemGetMaskedCr0 for both CR0 and CR4.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/VMMAll/IEMAllCImpl.cpp.h

    r74609 r74618  
    52105210
    52115211#ifdef VBOX_WITH_NESTED_HWVIRT_VMX
    5212     /* CRx bits are subject to masking when in VMX non-root mode. */
     5212    /* CR0/CR4 reads are subject to masking when in VMX non-root mode. */
    52135213    if (IEM_VMX_IS_NON_ROOT_MODE(pVCpu))
    52145214    {
    5215         if (iCrReg == 0)
    5216             crX = iemVmxGetMaskedCr0(pVCpu, crX);
     5215        if (   iCrReg == 0
     5216            || iCrReg == 4)
     5217            crX = iemVmxGetMaskedCrX(pVCpu, iCrReg, crX);
    52175218    }
    52185219#endif
     
    55025503            IEM_CTX_ASSERT(pVCpu, CPUMCTX_EXTRN_CR3);
    55035504
    5504             /* clear bit 63 from the source operand and indicate no invalidations are required. */
     5505            /* Bit 63 being clear in the source operand with PCIDE indicates no invalidations are required. */
    55055506            if (   (pVCpu->cpum.GstCtx.cr4 & X86_CR4_PCIDE)
    55065507                && (uNewCrX & RT_BIT_64(63)))
     
    55135514            }
    55145515
    5515             /* check / mask the value. */
     5516            /* Check / mask the value. */
    55165517            if (uNewCrX & UINT64_C(0xfff0000000000000))
    55175518            {
  • trunk/src/VBox/VMM/VMMAll/IEMAllCImplVmxInstr.cpp.h

    r74608 r74618  
    901901
    902902/**
    903  * Gets the nested-guest CR0 mask subjected to the CR0 guest/host mask and the CR0
     903 * Gets the nested-guest CR0/CR4 mask subjected to the corresponding guest/host mask
     904 * and the read-shadow.
     905 *
     906 * @returns The masked CR0/CR4.
     907 * @param   pVCpu       The cross context virtual CPU structure.
     908 * @param   iCrReg      The control register (either CR0 or CR4).
     909 * @param   uGuestCrX   The current guest CR0 or guest CR4.
     910 */
     911IEM_STATIC uint64_t iemVmxGetMaskedCrX(PVMCPU pVCpu, uint8_t iCrReg, uint64_t uGuestCrX)
     912{
     913    Assert(IEM_VMX_IS_NON_ROOT_MODE(pVCpu));
     914    Assert(iCrReg == 0 || iCrReg == 4);
     915
     916    PCVMXVVMCS pVmcs = pVCpu->cpum.GstCtx.hwvirt.vmx.CTX_SUFF(pVmcs);
     917    Assert(pVmcs);
     918
     919    /*
     920     * For each CR0 or CR4 bit owned by the host, the corresponding bit is loaded from the
     921     * CR0 read shadow or CR4 read shadow. For each CR0 or CR4 bit that is not owned by the
     922     * host, the corresponding bit from the guest CR0 or guest CR4 is loaded.
     923     *
     924     * See Intel Spec. 25.3 "Changes To Instruction Behavior In VMX Non-root Operation".
     925     */
     926    uint64_t fGstHostMask;
     927    uint64_t fReadShadow;
     928    if (iCrReg == 0)
     929    {
     930        fGstHostMask = pVmcs->u64Cr0Mask.u;
     931        fReadShadow  = pVmcs->u64Cr0ReadShadow.u;
     932    }
     933    else
     934    {
     935        fGstHostMask = pVmcs->u64Cr4Mask.u;
     936        fReadShadow  = pVmcs->u64Cr4ReadShadow.u;
     937    }
     938
     939    uint64_t const fMaskedCrX = (fReadShadow & fGstHostMask) | (uGuestCrX & ~fGstHostMask);
     940    return fMaskedCrX;
     941}
     942
     943
     944
     945/**
     946 * Gets the nested-guest CR4 mask subjected to the CR0 guest/host mask and the CR4
    904947 * read-shadow.
    905948 *
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