VirtualBox

Changeset 79142 in vbox for trunk/src/VBox/VMM


Ignore:
Timestamp:
Jun 14, 2019 4:54:41 AM (6 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
131309
Message:

VMM/HM: Nested VMX: bugref:9180 Reapply CR0/CR4 fixed bits while importing nested-guest CR0/CR4 after hardware-assisted VMX execution of the nested-guest.
Flag reloading all the HM state on the HM VM-exit notification callback.

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

Legend:

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

    r78650 r79142  
    12381238    NOREF(pCtx);
    12391239
    1240     /* There shouldn't be any externally kept state at this point. */
    1241     AssertMsg(!(pVCpu->cpum.GstCtx.fExtrn & CPUMCTX_EXTRN_ALL),
    1242               ("fExtrn=%#RX64 fExtrnMbz=%#RX64\n", pVCpu->cpum.GstCtx.fExtrn, CPUMCTX_EXTRN_ALL));
     1240    /*
     1241     * Transitions to ring-3 flag a full CPU-state change except if we transition to ring-3
     1242     * in response to a physical CPU interrupt as no changes to the guest-CPU state are
     1243     * expected (see VINF_EM_RAW_INTERRUPT handling in hmR0VmxExitToRing3).
     1244     *
     1245     * However, with nested-guests, the state -can- change on trips to ring-3 for we might
     1246     * try to inject a nested-guest physical interrupt and cause a VMX_EXIT_EXT_INT VM-exit
     1247     * for the nested-guest from ring-3.
     1248     *
     1249     * Flag reloading of just the guest-CPU state is -not- sufficient since HM also needs
     1250     * to reload related state with VM-entry/VM-exit controls and so on. Flag reloading
     1251     * the entire state.
     1252     */
     1253    CPUM_ASSERT_NOT_EXTRN(pVCpu, CPUMCTX_EXTRN_ALL);
     1254    ASMAtomicUoOrU64(&pVCpu->hm.s.fCtxChanged, HM_CHANGED_ALL_GUEST);
    12431255
    12441256    /*
  • trunk/src/VBox/VMM/VMMR0/HMVMXR0.cpp

    r79106 r79142  
    44644464             * For nested-guests, the "IA-32e mode guest" control we initialize with what is
    44654465             * required to get the nested-guest working with hardware-assisted VMX execution.
    4466              * It depends on the nested-guest's IA32_EFER.LMA bit. Remember, a nested-hypervisor
     4466             * It depends on the nested-guest's IA32_EFER.LMA bit. Remember, a guest hypervisor
    44674467             * can skip intercepting changes to the EFER MSR. This is why it it needs to be done
    44684468             * here rather than while merging the guest VMCS controls.
     
    49124912         * Figure out fixed CR0 bits in VMX operation.
    49134913         */
     4914        /** @todo Why do we need to OR and AND the fixed-0 and fixed-1 bits below? */
    49144915        uint64_t       fSetCr0 = pVM->hm.s.vmx.Msrs.u64Cr0Fixed0 & pVM->hm.s.vmx.Msrs.u64Cr0Fixed1;
    49154916        uint64_t const fZapCr0 = pVM->hm.s.vmx.Msrs.u64Cr0Fixed0 | pVM->hm.s.vmx.Msrs.u64Cr0Fixed1;
     
    50365037             * originally supplied. We must copy those bits from the nested-guest CR0 into
    50375038             * the nested-guest CR0 read-shadow.
     5039             *
     5040             * Note! We are zapping away any CR0 fixed bits of our VMX emulation and applying
     5041             *       the hardware's VMX CR0 fixed bits here.
    50385042             */
    50395043            HMVMX_CPUMCTX_ASSERT(pVCpu, CPUMCTX_EXTRN_CR0);
     
    51995203         * Figure out fixed CR4 bits in VMX operation.
    52005204         */
     5205        /** @todo Why do we need to OR and AND the fixed-0 and fixed-1 bits below? */
    52015206        uint64_t const fSetCr4 = pVM->hm.s.vmx.Msrs.u64Cr4Fixed0 & pVM->hm.s.vmx.Msrs.u64Cr4Fixed1;
    52025207        uint64_t const fZapCr4 = pVM->hm.s.vmx.Msrs.u64Cr4Fixed0 | pVM->hm.s.vmx.Msrs.u64Cr4Fixed1;
     
    77597764                    u64Val = (u64Val    & ~pVmcsInfo->u64Cr0Mask)
    77607765                           | (u64Shadow &  pVmcsInfo->u64Cr0Mask);
    7761 
     7766#ifdef VBOX_WITH_NESTED_HWVIRT_VMX
     7767                    /*
     7768                     * Reapply the nested-guest's CR0 fixed bits that might have been altered while
     7769                     * exporting the nested-guest CR0 for executing using hardware-assisted VMX.
     7770                     */
     7771                    if (CPUMIsGuestInVmxNonRootMode(pCtx))
     7772                    {
     7773                        u64Val |= pCtx->hwvirt.vmx.Msrs.u64Cr0Fixed0;
     7774                        u64Val &= pCtx->hwvirt.vmx.Msrs.u64Cr0Fixed1;
     7775                    }
     7776#endif
    77627777                    VMMRZCallRing3Disable(pVCpu);   /* May call into PGM which has Log statements. */
    77637778                    CPUMSetGuestCR0(pVCpu, u64Val);
     
    77827797                    u64Val = (u64Val    & ~pVmcsInfo->u64Cr4Mask)
    77837798                           | (u64Shadow &  pVmcsInfo->u64Cr4Mask);
     7799#ifdef VBOX_WITH_NESTED_HWVIRT_VMX
     7800                    /*
     7801                     * Reapply the nested-guest's CR4 fixed bits that might have been altered while
     7802                     * exporting the nested-guest CR4 for executing using hardware-assisted VMX.
     7803                     */
     7804                    if (CPUMIsGuestInVmxNonRootMode(pCtx))
     7805                    {
     7806                        u64Val |= pCtx->hwvirt.vmx.Msrs.u64Cr4Fixed0;
     7807                        u64Val &= pCtx->hwvirt.vmx.Msrs.u64Cr4Fixed1;
     7808                    }
     7809#endif
    77847810                    pCtx->cr4 = u64Val;
    77857811                }
     
    95119537 * and update error record fields accordingly.
    95129538 *
    9513  * @return VMX_IGS_* return codes.
     9539 * @returns VMX_IGS_* error codes.
    95149540 * @retval VMX_IGS_REASON_NOT_FOUND if this function could not find anything
    95159541 *         wrong with the guest state.
     
    95419567         * CR0.
    95429568         */
     9569        /** @todo Why do we need to OR and AND the fixed-0 and fixed-1 bits below? */
    95439570        uint32_t       fSetCr0 = (uint32_t)(pVM->hm.s.vmx.Msrs.u64Cr0Fixed0 & pVM->hm.s.vmx.Msrs.u64Cr0Fixed1);
    95449571        uint32_t const fZapCr0 = (uint32_t)(pVM->hm.s.vmx.Msrs.u64Cr0Fixed0 | pVM->hm.s.vmx.Msrs.u64Cr0Fixed1);
     
    95639590         * CR4.
    95649591         */
     9592        /** @todo Why do we need to OR and AND the fixed-0 and fixed-1 bits below? */
    95659593        uint64_t const fSetCr4 = (pVM->hm.s.vmx.Msrs.u64Cr4Fixed0 & pVM->hm.s.vmx.Msrs.u64Cr4Fixed1);
    95669594        uint64_t const fZapCr4 = (pVM->hm.s.vmx.Msrs.u64Cr4Fixed0 | pVM->hm.s.vmx.Msrs.u64Cr4Fixed1);
     
    1024610274     * These controls contains state that depends on the nested-guest state (primarily
    1024710275     * EFER MSR) and is thus not constant between VMLAUNCH/VMRESUME and the nested-guest
    10248      * VM-exit. Although the nested-hypervisor cannot change it, we need to in order to
     10276     * VM-exit. Although the guest hypervisor cannot change it, we need to in order to
    1024910277     * properly continue executing the nested-guest if the EFER MSR changes but does not
    1025010278     * cause a nested-guest VM-exits.
     
    1025210280     * VM-exit controls:
    1025310281     * These controls specify the host state on return. We cannot use the controls from
    10254      * the guest-hypervisor state as is as it would contain the guest state rather than
     10282     * the guest hypervisor state as is as it would contain the guest state rather than
    1025510283     * the host state. Since the host state is subject to change (e.g. preemption, trips
    1025610284     * to ring-3, longjmp and rescheduling to a different host CPU) they are not constant
     
    1026710295     * VM-exit MSR-load areas:
    1026810296     * This must contain the real host MSRs with hardware-assisted VMX execution. Hence,
    10269      * we can entirely ignore what the nested-hypervisor wants to load here.
     10297     * we can entirely ignore what the guest hypervisor wants to load here.
    1027010298     */
    1027110299
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette