VirtualBox

Changeset 102799 in vbox for trunk


Ignore:
Timestamp:
Jan 9, 2024 4:04:32 PM (13 months ago)
Author:
vboxsync
Message:

VMM/CPUM: bugref:10498 Check if the physical address fits before creating an MTRR mask (and region).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/VMMR3/CPUM.cpp

    r102689 r102799  
    33693369    if (pMtrrMap->idxMtrr < pMtrrMap->cMtrrs)
    33703370    {
    3371         pMtrrMap->aMtrrs[pMtrrMap->idxMtrr].MtrrPhysBase = GCPhysFirst | fType;
    3372         pMtrrMap->aMtrrs[pMtrrMap->idxMtrr].MtrrPhysMask = cpumR3GetVarMtrrMask(pVM, GCPhysFirst, GCPhysLast)
    3373                                                          | MSR_IA32_MTRR_PHYSMASK_VALID;
    3374         ++pMtrrMap->idxMtrr;
    3375 
    3376         uint64_t const cbRange = GCPhysLast - GCPhysFirst + 1;
    3377         if (fType != X86_MTRR_MT_UC)
    3378             pMtrrMap->cbMapped += cbRange;
    3379         else
     3371        RTGCPHYS const GCPhysLastMax = RT_BIT_64(pVM->cpum.s.GuestFeatures.cMaxPhysAddrWidth) - 1U;
     3372        if (GCPhysLast <= GCPhysLastMax)
    33803373        {
    3381             Assert(pMtrrMap->cbMapped >= cbRange);
    3382             pMtrrMap->cbMapped -= cbRange;
     3374            pMtrrMap->aMtrrs[pMtrrMap->idxMtrr].MtrrPhysBase = GCPhysFirst | fType;
     3375            pMtrrMap->aMtrrs[pMtrrMap->idxMtrr].MtrrPhysMask = cpumR3GetVarMtrrMask(pVM, GCPhysFirst, GCPhysLast)
     3376                                                             | MSR_IA32_MTRR_PHYSMASK_VALID;
     3377            ++pMtrrMap->idxMtrr;
     3378
     3379            uint64_t const cbRange = GCPhysLast - GCPhysFirst + 1;
     3380            if (fType != X86_MTRR_MT_UC)
     3381                pMtrrMap->cbMapped += cbRange;
     3382            else
     3383            {
     3384                Assert(pMtrrMap->cbMapped >= cbRange);
     3385                pMtrrMap->cbMapped -= cbRange;
     3386            }
     3387            return VINF_SUCCESS;
    33833388        }
    3384         return VINF_SUCCESS;
    33853389    }
    33863390    return VERR_OUT_OF_RESOURCES;
     
    37873791     */
    37883792    uint32_t const cbRamHole = MMR3PhysGet4GBRamHoleSize(pVM);
    3789     AssertMsg(cbRamHole <= 4032U * _1M, ("RAM hole size (%u bytes) is too large\n", cbRamHole));
    3790     AssertMsg(cbRamHole > 16 * _1M,     ("RAM hole size (%u byets) is too small\n", cbRamHole));
    3791     AssertMsg(!(cbRamHole & (_4M - 1)), ("RAM hole size (%u bytes) must be 4MB aligned\n", cbRamHole));
     3793    AssertMsg(cbRamHole <= 4032U * _1M, ("RAM hole size (%RU32 bytes) is too large\n", cbRamHole));
     3794    AssertMsg(cbRamHole > 16 * _1M,     ("RAM hole size (%RU32 byets) is too small\n", cbRamHole));
     3795    AssertMsg(!(cbRamHole & (_4M - 1)), ("RAM hole size (%RU32 bytes) must be 4MB aligned\n", cbRamHole));
     3796
     3797    /*
     3798     * Paranoia.
     3799     * Ensure the maximum physical-address width can accomodate the specified RAM size.
     3800     */
     3801    RTGCPHYS const GCPhysEndMax = RT_BIT_64(pVM->cpum.s.GuestFeatures.cMaxPhysAddrWidth);
     3802    RTGCPHYS const GCPhysEnd    = cbRam + cbRamHole;
     3803    if (GCPhysEnd <= GCPhysEndMax)
     3804    { /* likely */ }
     3805    else
     3806    {
     3807        LogRel(("CPUM: WARNING! Cannot fully map RAM of %' Rhcb (%RU64 bytes) as it exceeds maximum physical-address (%#RX64)\n",
     3808                cbRam, cbRam, cbRamHole, cbRamHole, GCPhysEndMax - 1));
     3809    }
    37923810
    37933811    /*
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