VirtualBox

Changeset 93728 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Feb 14, 2022 2:32:18 PM (3 years ago)
Author:
vboxsync
Message:

VMM/NEMR3Native-darwin: Apple requires to bind to all MSRs related to the LBR feature if it is enabled, this includes the INFO MSRs as well as the MSR_LER_{TO,FROM}_IP MSRs, bugref:9044

Location:
trunk/src/VBox/VMM
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/VMMR3/NEMR3Native-darwin.cpp

    r93723 r93728  
    11321132        READ_MSR(MSR_K8_SF_MASK, pVCpu->cpum.GstCtx.msrSFMASK);
    11331133    }
    1134     if (fWhat & CPUMCTX_EXTRN_OTHER_MSRS)
     1134    if (fWhat & CPUMCTX_EXTRN_TSC_AUX)
    11351135    {
    11361136        PCPUMCTXMSRS pCtxMsrs = CPUMQueryGuestCtxMsrsPtr(pVCpu);
    11371137        READ_MSR(MSR_K8_TSC_AUX, pCtxMsrs->msr.TscAux);
    1138 
     1138    }
     1139    if (fWhat & CPUMCTX_EXTRN_OTHER_MSRS)
     1140    {
    11391141        /* Last Branch Record. */
    11401142        if (pVM->nem.s.fLbr)
     
    11431145            uint32_t const idFromIpMsrStart = pVM->nem.s.idLbrFromIpMsrFirst;
    11441146            uint32_t const idToIpMsrStart   = pVM->nem.s.idLbrToIpMsrFirst;
     1147            uint32_t const idInfoMsrStart   = pVM->nem.s.idLbrInfoMsrFirst;
    11451148            uint32_t const cLbrStack        = pVM->nem.s.idLbrFromIpMsrLast - pVM->nem.s.idLbrFromIpMsrFirst + 1;
    11461149            Assert(cLbrStack <= 32);
     
    11521155                if (idToIpMsrStart != 0)
    11531156                    READ_MSR(idToIpMsrStart + i, pVmcsInfoShared->au64LbrToIpMsr[i]);
     1157                if (idInfoMsrStart != 0)
     1158                    READ_MSR(idInfoMsrStart + i, pVmcsInfoShared->au64LbrInfoMsr[i]);
    11541159            }
    11551160
    11561161            READ_MSR(pVM->nem.s.idLbrTosMsr, pVmcsInfoShared->u64LbrTosMsr);
     1162
     1163            if (pVM->nem.s.idLerFromIpMsr)
     1164                READ_MSR(pVM->nem.s.idLerFromIpMsr, pVmcsInfoShared->u64LerFromIpMsr);
     1165            if (pVM->nem.s.idLerToIpMsr)
     1166                READ_MSR(pVM->nem.s.idLerToIpMsr, pVmcsInfoShared->u64LerToIpMsr);
    11571167        }
    11581168    }
     
    17491759            uint32_t const idFromIpMsrStart = pVM->nem.s.idLbrFromIpMsrFirst;
    17501760            uint32_t const idToIpMsrStart   = pVM->nem.s.idLbrToIpMsrFirst;
     1761            uint32_t const idInfoMsrStart   = pVM->nem.s.idLbrInfoMsrFirst;
    17511762            uint32_t const cLbrStack        = pVM->nem.s.idLbrFromIpMsrLast - pVM->nem.s.idLbrFromIpMsrFirst + 1;
    17521763            Assert(cLbrStack <= 32);
     
    17581769                if (idToIpMsrStart != 0)
    17591770                    WRITE_MSR(idToIpMsrStart + i, pVmcsInfoShared->au64LbrToIpMsr[i]);
     1771                if (idInfoMsrStart != 0)
     1772                    WRITE_MSR(idInfoMsrStart + i, pVmcsInfoShared->au64LbrInfoMsr[i]);
    17601773            }
    17611774
    17621775            WRITE_MSR(pVM->nem.s.idLbrTosMsr, pVmcsInfoShared->u64LbrTosMsr);
     1776            if (pVM->nem.s.idLerFromIpMsr)
     1777                WRITE_MSR(pVM->nem.s.idLerFromIpMsr, pVmcsInfoShared->u64LerFromIpMsr);
     1778            if (pVM->nem.s.idLerToIpMsr)
     1779                WRITE_MSR(pVM->nem.s.idLerToIpMsr, pVmcsInfoShared->u64LerToIpMsr);
    17631780        }
    17641781
     
    19842001    uint32_t idLbrToIpMsrFirst;
    19852002    uint32_t idLbrToIpMsrLast;
     2003    uint32_t idLbrInfoMsrFirst;
     2004    uint32_t idLbrInfoMsrLast;
    19862005    uint32_t idLbrTosMsr;
     2006    uint32_t idLbrSelectMsr;
     2007    uint32_t idLerFromIpMsr;
     2008    uint32_t idLerToIpMsr;
    19872009
    19882010    /*
     
    20012023            idLbrToIpMsrFirst   = 0x0;
    20022024            idLbrToIpMsrLast    = 0x0;
     2025            idLbrInfoMsrFirst   = 0x0;
     2026            idLbrInfoMsrLast    = 0x0;
    20032027            idLbrTosMsr         = MSR_P4_LASTBRANCH_TOS;
     2028            idLbrSelectMsr      = 0x0;
     2029            idLerFromIpMsr      = 0x0;
     2030            idLerToIpMsr        = 0x0;
    20042031            break;
    20052032
     
    20112038            idLbrToIpMsrFirst   = MSR_LASTBRANCH_0_TO_IP;
    20122039            idLbrToIpMsrLast    = MSR_LASTBRANCH_31_TO_IP;
     2040            idLbrInfoMsrFirst   = MSR_LASTBRANCH_0_INFO;
     2041            idLbrInfoMsrLast    = MSR_LASTBRANCH_31_INFO;
    20132042            idLbrTosMsr         = MSR_LASTBRANCH_TOS;
     2043            idLbrSelectMsr      = MSR_LASTBRANCH_SELECT;
     2044            idLerFromIpMsr      = MSR_LER_FROM_IP;
     2045            idLerToIpMsr        = MSR_LER_TO_IP;
    20142046            break;
    20152047
     
    20222054            idLbrToIpMsrFirst   = MSR_LASTBRANCH_0_TO_IP;
    20232055            idLbrToIpMsrLast    = MSR_LASTBRANCH_15_TO_IP;
     2056            idLbrInfoMsrFirst   = MSR_LASTBRANCH_0_INFO;
     2057            idLbrInfoMsrLast    = MSR_LASTBRANCH_15_INFO;
    20242058            idLbrTosMsr         = MSR_LASTBRANCH_TOS;
     2059            idLbrSelectMsr      = MSR_LASTBRANCH_SELECT;
     2060            idLerFromIpMsr      = MSR_LER_FROM_IP;
     2061            idLerToIpMsr        = MSR_LER_TO_IP;
    20252062            break;
    20262063
     
    20302067            idLbrToIpMsrFirst   = MSR_CORE2_LASTBRANCH_0_TO_IP;
    20312068            idLbrToIpMsrLast    = MSR_CORE2_LASTBRANCH_3_TO_IP;
     2069            idLbrInfoMsrFirst   = 0x0;
     2070            idLbrInfoMsrLast    = 0x0;
    20322071            idLbrTosMsr         = MSR_CORE2_LASTBRANCH_TOS;
     2072            idLbrSelectMsr      = 0x0;
     2073            idLerFromIpMsr      = 0x0;
     2074            idLerToIpMsr        = 0x0;
    20332075            break;
    20342076
     
    20532095    AssertCompile(   RT_ELEMENTS(pVCpu0->nem.s.vmx.VmcsInfo.au64LbrFromIpMsr)
    20542096                  == RT_ELEMENTS(pVCpu0->nem.s.vmx.VmcsInfo.au64LbrToIpMsr));
     2097    AssertCompile(   RT_ELEMENTS(pVCpu0->nem.s.vmx.VmcsInfo.au64LbrFromIpMsr)
     2098                  == RT_ELEMENTS(pVCpu0->nem.s.vmx.VmcsInfo.au64LbrInfoMsr));
    20552099    if (cLbrStack > RT_ELEMENTS(pVCpu0->nem.s.vmx.VmcsInfo.au64LbrFromIpMsr))
    20562100    {
     
    20642108     * Update the LBR info. to the VM struct. for use later.
    20652109     */
    2066     pVM->nem.s.idLbrTosMsr = idLbrTosMsr;
     2110    pVM->nem.s.idLbrTosMsr         = idLbrTosMsr;
     2111    pVM->nem.s.idLbrSelectMsr      = idLbrSelectMsr;
    20672112
    20682113    pVM->nem.s.idLbrFromIpMsrFirst = idLbrFromIpMsrFirst;
     
    20712116    pVM->nem.s.idLbrToIpMsrFirst   = idLbrToIpMsrFirst;
    20722117    pVM->nem.s.idLbrToIpMsrLast    = idLbrToIpMsrLast;
     2118
     2119    pVM->nem.s.idLbrInfoMsrFirst   = idLbrInfoMsrFirst;
     2120    pVM->nem.s.idLbrInfoMsrLast    = idLbrInfoMsrLast;
     2121
     2122    pVM->nem.s.idLerFromIpMsr      = idLerFromIpMsr;
     2123    pVM->nem.s.idLerToIpMsr        = idLerToIpMsr;
    20732124    return VINF_SUCCESS;
    20742125}
     
    23172368        uint32_t const idFromIpMsrStart = pVM->nem.s.idLbrFromIpMsrFirst;
    23182369        uint32_t const idToIpMsrStart   = pVM->nem.s.idLbrToIpMsrFirst;
     2370        uint32_t const idInfoMsrStart   = pVM->nem.s.idLbrInfoMsrFirst;
    23192371        uint32_t const cLbrStack        = pVM->nem.s.idLbrFromIpMsrLast - pVM->nem.s.idLbrFromIpMsrFirst + 1;
    23202372        Assert(cLbrStack <= 32);
    23212373        for (uint32_t i = 0; i < cLbrStack; i++)
    23222374        {
    2323             rc = nemR3DarwinMsrSetManaged(pVCpu, idFromIpMsrStart + i, HV_MSR_READ); AssertRCReturn(rc, rc);
     2375            rc = nemR3DarwinMsrSetManaged(pVCpu, idFromIpMsrStart + i, HV_MSR_READ | HV_MSR_WRITE);
     2376            AssertRCReturn(rc, rc);
    23242377
    23252378            /* Some CPUs don't have a Branch-To-IP MSR (P4 and related Xeons). */
    23262379            if (idToIpMsrStart != 0)
    23272380            {
    2328                 rc = nemR3DarwinMsrSetManaged(pVCpu, idToIpMsrStart + i, HV_MSR_READ); AssertRCReturn(rc, rc);
     2381                rc = nemR3DarwinMsrSetManaged(pVCpu, idToIpMsrStart + i, HV_MSR_READ | HV_MSR_WRITE);
     2382                AssertRCReturn(rc, rc);
    23292383            }
    2330         }
    2331 
    2332         rc = nemR3DarwinMsrSetManaged(pVCpu, pVM->nem.s.idLbrTosMsr, HV_MSR_READ); AssertRCReturn(rc, rc);
     2384
     2385            if (idInfoMsrStart != 0)
     2386            {
     2387                rc = nemR3DarwinMsrSetManaged(pVCpu, idInfoMsrStart + i, HV_MSR_READ | HV_MSR_WRITE);
     2388                AssertRCReturn(rc, rc);
     2389            }
     2390        }
     2391
     2392        rc = nemR3DarwinMsrSetManaged(pVCpu, pVM->nem.s.idLbrTosMsr, HV_MSR_READ | HV_MSR_WRITE);
     2393        AssertRCReturn(rc, rc);
     2394
     2395        if (pVM->nem.s.idLerFromIpMsr)
     2396        {
     2397            rc = nemR3DarwinMsrSetManaged(pVCpu, pVM->nem.s.idLerFromIpMsr, HV_MSR_READ | HV_MSR_WRITE);
     2398            AssertRCReturn(rc, rc);
     2399        }
     2400
     2401        if (pVM->nem.s.idLerToIpMsr)
     2402        {
     2403            rc = nemR3DarwinMsrSetManaged(pVCpu, pVM->nem.s.idLerToIpMsr, HV_MSR_READ | HV_MSR_WRITE);
     2404            AssertRCReturn(rc, rc);
     2405        }
     2406
     2407        if (pVM->nem.s.idLbrSelectMsr)
     2408        {
     2409            rc = nemR3DarwinMsrSetManaged(pVCpu, pVM->nem.s.idLbrSelectMsr, HV_MSR_READ | HV_MSR_WRITE);
     2410            AssertRCReturn(rc, rc);
     2411        }
    23332412    }
    23342413
     
    26032682     */
    26042683    pHlp->pfnPrintf(pHlp, "CPU[%u]: LBRs (most-recent first)\n", pVCpu->idCpu);
     2684    if (pVM->nem.s.idLerFromIpMsr)
     2685        pHlp->pfnPrintf(pHlp, "LER: From IP=%#016RX64 - To IP=%#016RX64\n",
     2686                        pVmcsInfoShared->u64LerFromIpMsr, pVmcsInfoShared->u64LerToIpMsr);
    26052687    uint32_t idxCurrent = idxTopOfStack;
    26062688    Assert(idxTopOfStack < cLbrStack);
     
    26102692    {
    26112693        if (pVM->nem.s.idLbrToIpMsrFirst)
    2612             pHlp->pfnPrintf(pHlp, "  Branch (%2u): From IP=%#016RX64 - To IP=%#016RX64\n", idxCurrent,
    2613                             pVmcsInfoShared->au64LbrFromIpMsr[idxCurrent], pVmcsInfoShared->au64LbrToIpMsr[idxCurrent]);
     2694            pHlp->pfnPrintf(pHlp, "  Branch (%2u): From IP=%#016RX64 - To IP=%#016RX64 (Info: %#016RX64)\n", idxCurrent,
     2695                            pVmcsInfoShared->au64LbrFromIpMsr[idxCurrent],
     2696                            pVmcsInfoShared->au64LbrToIpMsr[idxCurrent],
     2697                            pVmcsInfoShared->au64LbrInfoMsr[idxCurrent]);
    26142698        else
    26152699            pHlp->pfnPrintf(pHlp, "  Branch (%2u): LBR=%#RX64\n", idxCurrent, pVmcsInfoShared->au64LbrFromIpMsr[idxCurrent]);
  • trunk/src/VBox/VMM/include/HMVMXCommon.h

    r93115 r93728  
    251251    /** List of LastBranch-To-IP MSRs. */
    252252    uint64_t                    au64LbrToIpMsr[32];
     253    /** List of LastBranch-Info MSRs. */
     254    uint64_t                    au64LbrInfoMsr[32];
    253255    /** The MSR containing the index to the most recent branch record.  */
    254256    uint64_t                    u64LbrTosMsr;
     257    /** The MSR containing the last event record from IP value. */
     258    uint64_t                    u64LerFromIpMsr;
     259    /** The MSR containing the last event record to IP value. */
     260    uint64_t                    u64LerToIpMsr;
    255261    /** @} */
    256262} VMXVMCSINFOSHARED;
  • trunk/src/VBox/VMM/include/NEMInternal.h

    r93722 r93728  
    279279    /** The host LBR TOS (top-of-stack) MSR id. */
    280280    uint32_t                    idLbrTosMsr;
     281    /** The host LBR select MSR id. */
     282    uint32_t                    idLbrSelectMsr;
     283    /** The host last event record from IP MSR id. */
     284    uint32_t                    idLerFromIpMsr;
     285    /** The host last event record to IP MSR id. */
     286    uint32_t                    idLerToIpMsr;
    281287
    282288    /** The first valid host LBR branch-from-IP stack range. */
     
    289295    /** The last valid host LBR branch-to-IP stack range. */
    290296    uint32_t                    idLbrToIpMsrLast;
     297
     298    /** The first valid host LBR info stack range. */
     299    uint32_t                    idLbrInfoMsrFirst;
     300    /** The last valid host LBR info stack range. */
     301    uint32_t                    idLbrInfoMsrLast;
    291302
    292303    STAMCOUNTER                 StatMapPage;
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