VirtualBox

Changeset 60718 in vbox


Ignore:
Timestamp:
Apr 27, 2016 2:14:57 PM (8 years ago)
Author:
vboxsync
Message:

VMM/APIC: Disallow enabling APIC if the VM was configured with a disabled APIC.

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

Legend:

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

    r60716 r60718  
    205205        const char *pszBefore;   /* The error message before printing the MSR index */
    206206        const char *pszAfter;    /* The error message after printing the MSR index */
    207         int         rcR0;        /* The ring-0 error code */
     207        int         rcRZ;        /* The RZ error code */
    208208    } const s_aAccess[] =
    209209    {
    210         { "read MSR",                      " while not in x2APIC mode", VINF_CPUM_R3_MSR_READ  },
    211         { "write MSR",                     " while not in x2APIC mode", VINF_CPUM_R3_MSR_WRITE },
    212         { "read reserved/unknown MSR",     "",                          VINF_CPUM_R3_MSR_READ  },
    213         { "write reserved/unknown MSR",    "",                          VINF_CPUM_R3_MSR_WRITE },
    214         { "read write-only MSR",           "",                          VINF_CPUM_R3_MSR_READ  },
    215         { "write read-only MSR",           "",                          VINF_CPUM_R3_MSR_WRITE },
    216         { "read reserved bits of MSR",     "",                          VINF_CPUM_R3_MSR_READ  },
    217         { "write reserved bits of MSR",    "",                          VINF_CPUM_R3_MSR_WRITE },
    218         { "write an invalid value to MSR", "",                          VINF_CPUM_R3_MSR_WRITE }
     210        { "read MSR",                      " while not in x2APIC mode",   VINF_CPUM_R3_MSR_READ  },
     211        { "write MSR",                     " while not in x2APIC mode",   VINF_CPUM_R3_MSR_WRITE },
     212        { "read reserved/unknown MSR",     "",                            VINF_CPUM_R3_MSR_READ  },
     213        { "write reserved/unknown MSR",    "",                            VINF_CPUM_R3_MSR_WRITE },
     214        { "read write-only MSR",           "",                            VINF_CPUM_R3_MSR_READ  },
     215        { "write read-only MSR",           "",                            VINF_CPUM_R3_MSR_WRITE },
     216        { "read reserved bits of MSR",     "",                            VINF_CPUM_R3_MSR_READ  },
     217        { "write reserved bits of MSR",    "",                            VINF_CPUM_R3_MSR_WRITE },
     218        { "write an invalid value to MSR", "",                            VINF_CPUM_R3_MSR_WRITE },
     219        { "write MSR",                     "disallowed by configuration", VINF_CPUM_R3_MSR_WRITE }
    219220    };
    220221    AssertCompile(RT_ELEMENTS(s_aAccess) == APICMSRACCESS_COUNT);
     
    227228    return VERR_CPUM_RAISE_GP_0;
    228229#else
    229     return s_aAccess[i].rcR0;
     230    return s_aAccess[i].rcRZ;
    230231#endif
    231232}
     
    20122013                }
    20132014
    2014                 uBaseMsr |= MSR_APICBASE_XAPIC_ENABLE_BIT;
    2015                 APICUpdateCpuIdForMode(pVCpu->CTX_SUFF(pVM), APICMODE_XAPIC);
    2016                 LogRel(("APIC%u: Switched mode to xAPIC\n", pVCpu->idCpu));
     2015                /* Don't allow enabling xAPIC if the VM is configured with a APIC disabled. */
     2016                if (pApic->enmOriginalMode != APICMODE_DISABLED)
     2017                {
     2018                    uBaseMsr |= MSR_APICBASE_XAPIC_ENABLE_BIT;
     2019                    APICUpdateCpuIdForMode(pVCpu->CTX_SUFF(pVM), APICMODE_XAPIC);
     2020                    LogRel(("APIC%u: Switched mode to xAPIC\n", pVCpu->idCpu));
     2021                }
     2022                else
     2023                    return apicMsrAccessError(pVCpu, MSR_IA32_APICBASE, APICMSRACCESS_WRITE_DISALLOWED_CONFIG);
    20172024                break;
    20182025            }
     
    20262033                }
    20272034
    2028                 uBaseMsr |= MSR_APICBASE_XAPIC_ENABLE_BIT | MSR_APICBASE_X2APIC_ENABLE_BIT;
    2029 
    2030                 /*
    2031                  * The APIC ID needs updating when entering x2APIC mode.
    2032                  * Software written APIC ID in xAPIC mode isn't preseved.
    2033                  * The APIC ID becomes read-only to software in x2APIC mode.
    2034                  *
    2035                  * See Intel spec. 10.12.5.1 "x2APIC States".
    2036                  */
    2037                 PX2APICPAGE pX2ApicPage = VMCPU_TO_X2APICPAGE(pVCpu);
    2038                 ASMMemZero32(&pX2ApicPage->id, sizeof(pX2ApicPage->id));
    2039                 pX2ApicPage->id.u32ApicId = pVCpu->idCpu;
    2040 
    2041                 /*
    2042                  * LDR initialization occurs when entering x2APIC mode.
    2043                  * See Intel spec. 10.12.10.2 "Deriving Logical x2APIC ID from the Local x2APIC ID".
    2044                  */
    2045                 pX2ApicPage->ldr.u32LogicalApicId = ((pX2ApicPage->id.u32ApicId & UINT32_C(0xffff0)) << 16)
    2046                                                   | (UINT32_C(1) << pX2ApicPage->id.u32ApicId & UINT32_C(0xf));
    2047 
    2048                 LogRel(("APIC%u: Switched mode to x2APIC\n", pVCpu->idCpu));
     2035                /* Don't allow enabling x2APIC if the VM is configured with a APIC disabled. */
     2036                if (pApic->enmOriginalMode != APICMODE_DISABLED)
     2037                {
     2038                    uBaseMsr |= MSR_APICBASE_XAPIC_ENABLE_BIT | MSR_APICBASE_X2APIC_ENABLE_BIT;
     2039
     2040                    /*
     2041                     * The APIC ID needs updating when entering x2APIC mode.
     2042                     * Software written APIC ID in xAPIC mode isn't preseved.
     2043                     * The APIC ID becomes read-only to software in x2APIC mode.
     2044                     *
     2045                     * See Intel spec. 10.12.5.1 "x2APIC States".
     2046                     */
     2047                    PX2APICPAGE pX2ApicPage = VMCPU_TO_X2APICPAGE(pVCpu);
     2048                    ASMMemZero32(&pX2ApicPage->id, sizeof(pX2ApicPage->id));
     2049                    pX2ApicPage->id.u32ApicId = pVCpu->idCpu;
     2050
     2051                    /*
     2052                     * LDR initialization occurs when entering x2APIC mode.
     2053                     * See Intel spec. 10.12.10.2 "Deriving Logical x2APIC ID from the Local x2APIC ID".
     2054                     */
     2055                    pX2ApicPage->ldr.u32LogicalApicId = ((pX2ApicPage->id.u32ApicId & UINT32_C(0xffff0)) << 16)
     2056                                                      | (UINT32_C(1) << pX2ApicPage->id.u32ApicId & UINT32_C(0xf));
     2057
     2058                    LogRel(("APIC%u: Switched mode to x2APIC\n", pVCpu->idCpu));
     2059                }
     2060                else
     2061                    return apicMsrAccessError(pVCpu, MSR_IA32_APICBASE, APICMSRACCESS_WRITE_DISALLOWED_CONFIG);
    20492062                break;
    20502063            }
  • trunk/src/VBox/VMM/include/APICInternal.h

    r60716 r60718  
    294294    /* MSR write with invalid value. */
    295295    APICMSRACCESS_WRITE_INVALID,
     296    /** MSR write disallowed due to incompatible config. */
     297    APICMSRACCESS_WRITE_DISALLOWED_CONFIG,
    296298    /* Count of enum members (don't use). */
    297299    APICMSRACCESS_COUNT
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