VirtualBox

Changeset 57056 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Jul 22, 2015 2:12:42 PM (9 years ago)
Author:
vboxsync
Message:

cpumR3CpuIdSanitize: Log and clean up sub-leaves in the feature areas instead of freaking out with VERR_CPUM_IPE_2.

File:
1 edited

Legend:

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

    r56985 r57056  
    524524 * @param   cLeaves             The number of leaves in the array.
    525525 * @param   uLeaf               The leaf to locate.
    526  * @param   uSubLeaf            The subleaf to locate.  Pass 0 if no subleaves.
     526 * @param   uSubLeaf            The subleaf to locate.  Pass 0 if no sub-leaves.
    527527 */
    528528static PCPUMCPUIDLEAF cpumR3CpuIdGetLeaf(PCPUMCPUIDLEAF paLeaves, uint32_t cLeaves, uint32_t uLeaf, uint32_t uSubLeaf)
     
    545545 * @param   cLeaves             The number of leaves in the array.
    546546 * @param   uLeaf               The leaf to locate.
    547  * @param   uSubLeaf            The subleaf to locate.  Pass 0 if no subleaves.
     547 * @param   uSubLeaf            The subleaf to locate.  Pass 0 if no sub-leaves.
    548548 * @param   pLegacy             The legacy output leaf.
    549549 */
     
    715715 * Inserts a CPU ID leaf, replacing any existing ones.
    716716 *
    717  * When inserting a simple leaf where we already got a series of subleaves with
     717 * When inserting a simple leaf where we already got a series of sub-leaves with
    718718 * the same leaf number (eax), the simple leaf will replace the whole series.
    719719 *
     
    10381038 * @param   pLeaf       Where to store the found leaf.
    10391039 * @param   uLeaf       The leaf to locate.
    1040  * @param   uSubLeaf    The subleaf to locate.  Pass 0 if no subleaves.
     1040 * @param   uSubLeaf    The subleaf to locate.  Pass 0 if no sub-leaves.
    10411041 */
    10421042VMMR3DECL(int) CPUMR3CpuIdGetLeaf(PVM pVM, PCPUMCPUIDLEAF pLeaf, uint32_t uLeaf, uint32_t uSubLeaf)
     
    11741174                           relevant details in the release log. */
    11751175                        LogRel(("CPUM: VERR_CPUM_TOO_MANY_CPUID_SUBLEAVES! uLeaf=%#x cSubLeaves=%#x\n", uLeaf, cSubLeaves));
    1176                         LogRel(("------------------ dump of problematic subleaves ------------------\n"));
     1176                        LogRel(("------------------ dump of problematic sub-leaves -----------------\n"));
    11771177                        for (uint32_t uSubLeaf = 0; uSubLeaf < 128; uSubLeaf++)
    11781178                        {
     
    24022402
    24032403/**
     2404 * Used by cpumR3CpuIdSanitize to ensure that we don't have any sub-leaves for
     2405 * the given leaf.
     2406 *
     2407 * @returns pLeaf.
     2408 * @param   pCpum       The CPUM instance data.
     2409 * @param   pLeaf       The leaf to ensure is alone with it's EAX input value.
     2410 */
     2411static PCPUMCPUIDLEAF cpumR3CpuIdMakeSingleLeaf(PCPUM pCpum, PCPUMCPUIDLEAF pLeaf)
     2412{
     2413    Assert((uintptr_t)(pLeaf - pCpum->GuestInfo.paCpuIdLeavesR3) < pCpum->GuestInfo.cCpuIdLeaves);
     2414    if (pLeaf->fSubLeafMask != 0)
     2415    {
     2416        /*
     2417         * Figure out how many sub-leaves in need of removal (we'll keep the first).
     2418         * Log everything while we're at it.
     2419         */
     2420        LogRel(("CPUM:\n"
     2421                "CPUM: Unexpected CPUID sub-leaves for leaf %#x; fSubLeafMask=%#x\n", pLeaf->uLeaf, pLeaf->fSubLeafMask));
     2422        PCPUMCPUIDLEAF  pLast    = &pCpum->GuestInfo.paCpuIdLeavesR3[pCpum->GuestInfo.cCpuIdLeaves - 1];
     2423        PCPUMCPUIDLEAF  pSubLeaf = pLeaf;
     2424        for (;;)
     2425        {
     2426            LogRel(("CPUM: %08x/%08x: %08x %08x %08x %08x; flags=%#x mask=%#x\n",
     2427                    pSubLeaf->uLeaf, pSubLeaf->uSubLeaf,
     2428                    pSubLeaf->uEax, pSubLeaf->uEbx, pSubLeaf->uEcx, pSubLeaf->uEdx,
     2429                    pSubLeaf->fFlags, pSubLeaf->fSubLeafMask));
     2430            if (pSubLeaf == pLast || pSubLeaf[1].uLeaf != pLeaf->uLeaf)
     2431                break;
     2432            pSubLeaf++;
     2433        }
     2434        LogRel(("CPUM:\n"));
     2435
     2436        /*
     2437         * Remove the offending sub-leaves.
     2438         */
     2439        if (pSubLeaf != pLeaf)
     2440        {
     2441            if (pSubLeaf != pLast)
     2442                memmove(pLeaf + 1, pSubLeaf + 1, (uintptr_t)pLast - (uintptr_t)pSubLeaf);
     2443            pCpum->GuestInfo.cCpuIdLeaves -= (uint32_t)(pSubLeaf - pLeaf);
     2444        }
     2445
     2446        /*
     2447         * Convert the first sub-leaf into a single leaf.
     2448         */
     2449        pLeaf->uSubLeaf     = 0;
     2450        pLeaf->fSubLeafMask = 0;
     2451    }
     2452    return pLeaf;
     2453}
     2454
     2455
     2456/**
    24042457 * Sanitizes and adjust the CPUID leaves.
    24052458 *
     
    24512504    PCPUMCPUIDLEAF pStdFeatureLeaf = cpumR3CpuIdGetExactLeaf(pCpum, 1, 0); /* Note! Must refetch when used later. */
    24522505    AssertLogRelReturn(pStdFeatureLeaf, VERR_CPUM_IPE_2);
    2453     AssertLogRelReturn(pStdFeatureLeaf->fSubLeafMask == 0, VERR_CPUM_IPE_2);
     2506    pStdFeatureLeaf = cpumR3CpuIdMakeSingleLeaf(pCpum, pStdFeatureLeaf);
    24542507
    24552508    pStdFeatureLeaf->uEdx &= X86_CPUID_FEATURE_EDX_FPU
     
    26232676    if (pExtFeatureLeaf)
    26242677    {
    2625         AssertLogRelReturn(pExtFeatureLeaf->fSubLeafMask == 0, VERR_CPUM_IPE_2);
     2678        pExtFeatureLeaf = cpumR3CpuIdMakeSingleLeaf(pCpum, pExtFeatureLeaf);
    26262679
    26272680        pExtFeatureLeaf->uEdx &= X86_CPUID_AMD_FEATURE_EDX_FPU
     
    27592812     * AMD:   Reserved
    27602813     * VIA:   Reserved
    2761      * Safe to expose.  Restrict the number of calls to 1 since we don't
    2762      * implement this kind of subleaves (is there hardware that does??).
     2814     * Safe to expose.
    27632815     */
    27642816    uint32_t        uSubLeaf = 0;
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