VirtualBox

Changeset 87361 in vbox


Ignore:
Timestamp:
Jan 21, 2021 9:13:55 PM (4 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
142342
Message:

VMM/CPUM,HMSVM: Mirror the state of fUseFlags[CPUM_USED_FPU_GUEST] in CPUMCTX::fUsedFpuGuest so the HM switcher code can get at it (only relevant for windows) and avoid a call to CPUMIsGuestFPUStateActive/Loaded.

Location:
trunk
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/vmm/cpum.mac

    r82968 r87361  
    255255    .aoffXState         resw    64
    256256    .fWorldSwitcher     resd    1
     257    .fUsedFpuGuest      resb    1
    257258    alignb 8
    258259    .fExtrn             resq    1
  • trunk/include/VBox/vmm/cpumctx.h

    r82968 r87361  
    473473    /** 0x2d4 - World switcher flags, CPUMCTX_WSF_XXX. */
    474474    uint32_t                    fWorldSwitcher;
    475     uint32_t                    fUnused;
     475    /** 0x2d8 - Mirror of CPUMCPU::fUseFlags[CPUM_USED_FPU_GUEST]. */
     476    bool                        fUsedFpuGuest;
     477    uint8_t                     afUnused[3];
    476478    /** 0x2d8 - Externalized state tracker, CPUMCTX_EXTRN_XXX.
    477479     * Currently only used internally in NEM/win.  */
  • trunk/src/VBox/VMM/VMMAll/CPUMAllRegs.cpp

    r87346 r87361  
    16161616VMMDECL(bool) CPUMIsGuestFPUStateActive(PVMCPU pVCpu)
    16171617{
    1618     return RT_BOOL(pVCpu->cpum.s.fUseFlags & CPUM_USED_FPU_GUEST);
     1618    bool fRet = RT_BOOL(pVCpu->cpum.s.fUseFlags & CPUM_USED_FPU_GUEST);
     1619    AssertMsg(fRet == pVCpu->cpum.s.Guest.fUsedFpuGuest, ("fRet=%d\n", fRet));
     1620    return fRet;
    16191621}
    16201622
     
    16281630VMMDECL(bool) CPUMIsGuestFPUStateLoaded(PVMCPU pVCpu)
    16291631{
    1630     return RT_BOOL(pVCpu->cpum.s.fUseFlags & CPUM_USED_FPU_GUEST);
     1632    bool fRet = RT_BOOL(pVCpu->cpum.s.fUseFlags & CPUM_USED_FPU_GUEST);
     1633    AssertMsg(fRet == pVCpu->cpum.s.Guest.fUsedFpuGuest, ("fRet=%d\n", fRet));
     1634    return fRet;
    16311635}
    16321636
  • trunk/src/VBox/VMM/VMMR0/CPUMR0.cpp

    r87346 r87361  
    466466    Assert(   (pVCpu->cpum.s.fUseFlags & (CPUM_USED_FPU_GUEST | CPUM_USED_FPU_HOST | CPUM_USED_FPU_SINCE_REM))
    467467           ==                            (CPUM_USED_FPU_GUEST | CPUM_USED_FPU_HOST | CPUM_USED_FPU_SINCE_REM));
     468    Assert(pVCpu->cpum.s.Guest.fUsedFpuGuest);
    468469    return rc;
    469470}
     
    485486    {
    486487        fSavedGuest = RT_BOOL(pVCpu->cpum.s.fUseFlags & CPUM_USED_FPU_GUEST);
     488        Assert(fSavedGuest == pVCpu->cpum.s.Guest.fUsedFpuGuest);
    487489        if (!(pVCpu->cpum.s.fUseFlags & CPUM_USED_MANUAL_XMM_RESTORE))
    488490            cpumR0SaveGuestRestoreHostFPUState(&pVCpu->cpum.s);
     
    509511    Assert(!(  pVCpu->cpum.s.fUseFlags
    510512             & (CPUM_USED_FPU_GUEST | CPUM_USED_FPU_HOST | CPUM_USED_MANUAL_XMM_RESTORE)));
     513    Assert(!pVCpu->cpum.s.Guest.fUsedFpuGuest);
    511514    return fSavedGuest;
    512515}
  • trunk/src/VBox/VMM/VMMR0/CPUMR0A.asm

    r82968 r87361  
    181181
    182182        or      dword [pCpumCpu + CPUMCPU.fUseFlags], (CPUM_USED_FPU_GUEST | CPUM_USED_FPU_SINCE_REM | CPUM_USED_FPU_HOST)
     183        mov     byte [pCpumCpu + CPUMCPU.Guest.fUsedFpuGuest], 1
    183184        popf
    184185
     
    295296        CPUMRZ_RESTORE_CR0_IF_TS_OR_EM_SET xCX
    296297        and     dword [pCpumCpu + CPUMCPU.fUseFlags], ~(CPUM_USED_FPU_GUEST | CPUM_USED_FPU_HOST)
     298        mov     byte [pCpumCpu + CPUMCPU.Guest.fUsedFpuGuest], 0
    297299
    298300        popf
  • trunk/src/VBox/VMM/VMMR0/HMR0A.asm

    r87359 r87361  
    10961096; @param    2   fLoadSaveGuestXcr0 value
    10971097; @param    3   The CPUMCTX_WSF_IBPB_ENTRY + CPUMCTX_WSF_IBPB_EXIT value.
    1098 %macro hmR0SvmVmRunTemplate 3
     1098; @param    4   The SSE saving/restoring: 0 to do nothing, 1 to do it manually, 2 to use xsave/xrstor.
     1099%macro hmR0SvmVmRunTemplate 4
    10991100
    11001101;;
     
    11091110              ; So the SEH64_XXX stuff is currently not operational.
    11101111BEGINPROC RT_CONCAT(hmR0SvmVmRun,%1)
     1112 %ifdef VBOX_WITH_KERNEL_USING_XMM
     1113  %if %4 == 0 && 0
     1114        ;
     1115        ; The non-saving variant will currently check the two SSE preconditions and pick
     1116        ; the right variant to continue with.  Later we can see if we can't manage to
     1117        ; move these decisions into hmR0SvmUpdateVmRunFunction().
     1118        ;
     1119        test    byte [rsi + VMCPU.cpum.GstCtx + CPUMCTX.fUsedFpuGuest], 1
     1120        jz      .save_xmm_no_need
     1121        cmp     dword [rdx + VMCPU.cpum.GstCtx + CPUMCTX.fXStateMask], 0
     1122        je      RT_CONCAT3(hmR0SvmVmRun,%1,_SseManual)
     1123        jmp     RT_CONCAT3(hmR0SvmVmRun,%1,_SseXSave)
     1124.save_xmm_no_need:
     1125  %endif
     1126 %endif
    11111127        push    rbp
    11121128        SEH64_PUSH_xBP
     
    11491165
    11501166 %ifdef VBOX_STRICT
     1167        ;
    11511168        ; Verify template preconditions / parameters to ensure HMSVM.cpp didn't miss some state change.
     1169        ;
    11521170        cmp     byte [rsi + VMCPU.hm + HMCPU.fLoadSaveGuestXcr0], %2
    11531171        mov     eax, VERR_SVM_VMRUN_PRECOND_0
     
    11591177        mov     eax, VERR_SVM_VMRUN_PRECOND_1
    11601178        jne     .failure_return
     1179
     1180  %ifdef VBOX_WITH_KERNEL_USING_XMM
     1181   %if   %4 == 0
     1182
     1183   %elif %4 == 1
     1184   %elif %4 == 2
     1185   %else
     1186    %error Invalid template parameter 4.
     1187   %endif
     1188  %endif
    11611189 %endif
    11621190
     
    11701198        mov     eax, [rsi + VMCPU.cpum.GstCtx + CPUMCTX.aXcr] ; load the guest XCR0
    11711199        mov     edx, [rsi + VMCPU.cpum.GstCtx + CPUMCTX.aXcr + 4]
    1172         xor     ecx, ecx                        ; paranoia; Also, indicates that we must restore XCR0 (moved into ecx, thus 0).
     1200        xor     ecx, ecx                        ; paranoia
    11731201        xsetbv
    11741202 %endif
     
    13181346; Instantiate the hmR0SvmVmRun various variations.
    13191347;
    1320 hmR0SvmVmRunTemplate _SansXcr0_SansIbpbEntry_SansIbpbExit, 0, 0
    1321 hmR0SvmVmRunTemplate _WithXcr0_SansIbpbEntry_SansIbpbExit, 1, 0
    1322 hmR0SvmVmRunTemplate _SansXcr0_WithIbpbEntry_SansIbpbExit, 0, CPUMCTX_WSF_IBPB_ENTRY
    1323 hmR0SvmVmRunTemplate _WithXcr0_WithIbpbEntry_SansIbpbExit, 1, CPUMCTX_WSF_IBPB_ENTRY
    1324 hmR0SvmVmRunTemplate _SansXcr0_SansIbpbEntry_WithIbpbExit, 0, CPUMCTX_WSF_IBPB_EXIT
    1325 hmR0SvmVmRunTemplate _WithXcr0_SansIbpbEntry_WithIbpbExit, 1, CPUMCTX_WSF_IBPB_EXIT
    1326 hmR0SvmVmRunTemplate _SansXcr0_WithIbpbEntry_WithIbpbExit, 0, CPUMCTX_WSF_IBPB_ENTRY | CPUMCTX_WSF_IBPB_EXIT
    1327 hmR0SvmVmRunTemplate _WithXcr0_WithIbpbEntry_WithIbpbExit, 1, CPUMCTX_WSF_IBPB_ENTRY | CPUMCTX_WSF_IBPB_EXIT
    1328 
     1348hmR0SvmVmRunTemplate _SansXcr0_SansIbpbEntry_SansIbpbExit,           0, 0,                                              0
     1349hmR0SvmVmRunTemplate _WithXcr0_SansIbpbEntry_SansIbpbExit,           1, 0,                                              0
     1350hmR0SvmVmRunTemplate _SansXcr0_WithIbpbEntry_SansIbpbExit,           0, CPUMCTX_WSF_IBPB_ENTRY,                         0
     1351hmR0SvmVmRunTemplate _WithXcr0_WithIbpbEntry_SansIbpbExit,           1, CPUMCTX_WSF_IBPB_ENTRY,                         0
     1352hmR0SvmVmRunTemplate _SansXcr0_SansIbpbEntry_WithIbpbExit,           0, CPUMCTX_WSF_IBPB_EXIT,                          0
     1353hmR0SvmVmRunTemplate _WithXcr0_SansIbpbEntry_WithIbpbExit,           1, CPUMCTX_WSF_IBPB_EXIT,                          0
     1354hmR0SvmVmRunTemplate _SansXcr0_WithIbpbEntry_WithIbpbExit,           0, CPUMCTX_WSF_IBPB_ENTRY | CPUMCTX_WSF_IBPB_EXIT, 0
     1355hmR0SvmVmRunTemplate _WithXcr0_WithIbpbEntry_WithIbpbExit,           1, CPUMCTX_WSF_IBPB_ENTRY | CPUMCTX_WSF_IBPB_EXIT, 0
     1356;%ifdef VBOX_WITH_KERNEL_USING_XMM
     1357;hmR0SvmVmRunTemplate _SansXcr0_SansIbpbEntry_SansIbpbExit_SseManual, 0, 0,                                              1
     1358;hmR0SvmVmRunTemplate _WithXcr0_SansIbpbEntry_SansIbpbExit_SseManual, 1, 0,                                              1
     1359;hmR0SvmVmRunTemplate _SansXcr0_WithIbpbEntry_SansIbpbExit_SseManual, 0, CPUMCTX_WSF_IBPB_ENTRY,                         1
     1360;hmR0SvmVmRunTemplate _WithXcr0_WithIbpbEntry_SansIbpbExit_SseManual, 1, CPUMCTX_WSF_IBPB_ENTRY,                         1
     1361;hmR0SvmVmRunTemplate _SansXcr0_SansIbpbEntry_WithIbpbExit_SseManual, 0, CPUMCTX_WSF_IBPB_EXIT,                          1
     1362;hmR0SvmVmRunTemplate _WithXcr0_SansIbpbEntry_WithIbpbExit_SseManual, 1, CPUMCTX_WSF_IBPB_EXIT,                          1
     1363;hmR0SvmVmRunTemplate _SansXcr0_WithIbpbEntry_WithIbpbExit_SseManual, 0, CPUMCTX_WSF_IBPB_ENTRY | CPUMCTX_WSF_IBPB_EXIT, 1
     1364;hmR0SvmVmRunTemplate _WithXcr0_WithIbpbEntry_WithIbpbExit_SseManual, 1, CPUMCTX_WSF_IBPB_ENTRY | CPUMCTX_WSF_IBPB_EXIT, 1
     1365;
     1366;hmR0SvmVmRunTemplate _SansXcr0_SansIbpbEntry_SansIbpbExit_SseXSave,  0, 0,                                              2
     1367;hmR0SvmVmRunTemplate _WithXcr0_SansIbpbEntry_SansIbpbExit_SseXSave,  1, 0,                                              2
     1368;hmR0SvmVmRunTemplate _SansXcr0_WithIbpbEntry_SansIbpbExit_SseXSave,  0, CPUMCTX_WSF_IBPB_ENTRY,                         2
     1369;hmR0SvmVmRunTemplate _WithXcr0_WithIbpbEntry_SansIbpbExit_SseXSave,  1, CPUMCTX_WSF_IBPB_ENTRY,                         2
     1370;hmR0SvmVmRunTemplate _SansXcr0_SansIbpbEntry_WithIbpbExit_SseXSave,  0, CPUMCTX_WSF_IBPB_EXIT,                          2
     1371;hmR0SvmVmRunTemplate _WithXcr0_SansIbpbEntry_WithIbpbExit_SseXSave,  1, CPUMCTX_WSF_IBPB_EXIT,                          2
     1372;hmR0SvmVmRunTemplate _SansXcr0_WithIbpbEntry_WithIbpbExit_SseXSave,  0, CPUMCTX_WSF_IBPB_ENTRY | CPUMCTX_WSF_IBPB_EXIT, 2
     1373;hmR0SvmVmRunTemplate _WithXcr0_WithIbpbEntry_WithIbpbExit_SseXSave,  1, CPUMCTX_WSF_IBPB_ENTRY | CPUMCTX_WSF_IBPB_EXIT, 2
     1374;%endif
     1375
  • trunk/src/VBox/VMM/VMMR0/HMSVMR0.cpp

    r87359 r87361  
    718718 * CPUMCTX_WSF_IBPB_EXIT cannot be changed at runtime.
    719719 */
    720 static void hmR0SvmUpdateRunFunction(PVMCPUCC pVCpu)
     720static void hmR0SvmUpdateVmRunFunction(PVMCPUCC pVCpu)
    721721{
    722722    static const PFNHMSVMVMRUN s_apfnHmR0SvmVmRunFunctions[] =
     
    745745static DECLCALLBACK(int) hmR0SvmVMRunSelector(PVMCC pVM, PVMCPUCC pVCpu, RTHCPHYS HCPhysVMCB)
    746746{
    747     hmR0SvmUpdateRunFunction(pVCpu);
     747    hmR0SvmUpdateVmRunFunction(pVCpu);
    748748    return pVCpu->hm.s.svm.pfnVMRun(pVM, pVCpu, HCPhysVMCB);
    749749}
     
    16721672    {
    16731673        pVCpu->hm.s.fLoadSaveGuestXcr0 = fLoadSaveGuestXcr0;
    1674         hmR0SvmUpdateRunFunction(pVCpu);
     1674        hmR0SvmUpdateVmRunFunction(pVCpu);
    16751675    }
    16761676
     
    65696569        {
    65706570            pVCpu->hm.s.fLoadSaveGuestXcr0 = fLoadSaveGuestXcr0;
    6571             hmR0SvmUpdateRunFunction(pVCpu);
     6571            hmR0SvmUpdateVmRunFunction(pVCpu);
    65726572        }
    65736573    }
  • trunk/src/VBox/VMM/VMMRZ/CPUMRZ.cpp

    r82968 r87361  
    9999    if (pVCpu->cpum.s.fUseFlags & CPUM_USED_FPU_GUEST)
    100100    {
     101        Assert(pVCpu->cpum.s.Guest.fUsedFpuGuest);
    101102        cpumRZSaveGuestFpuState(&pVCpu->cpum.s, false /*fLeaveFpuAccessible*/);
    102103        pVCpu->cpum.s.fUseFlags |= CPUM_USED_FPU_GUEST;
     104        pVCpu->cpum.s.Guest.fUsedFpuGuest = true;
    103105        Log7(("CPUMRZFpuStateActualizeForRead\n"));
    104106    }
     
    120122    if (pVCpu->cpum.s.fUseFlags & CPUM_USED_FPU_GUEST)
    121123    {
     124        Assert(pVCpu->cpum.s.Guest.fUsedFpuGuest);
    122125        cpumRZSaveGuestSseRegisters(&pVCpu->cpum.s);
    123126        Log7(("CPUMRZFpuStateActualizeSseForRead\n"));
     
    138141    if (pVCpu->cpum.s.fUseFlags & CPUM_USED_FPU_GUEST)
    139142    {
     143        Assert(pVCpu->cpum.s.Guest.fUsedFpuGuest);
    140144        cpumRZSaveGuestAvxRegisters(&pVCpu->cpum.s);
    141145        Log7(("CPUMRZFpuStateActualizeAvxForRead\n"));
  • trunk/src/VBox/VMM/VMMRZ/CPUMRZA.asm

    r82968 r87361  
    211211
    212212        and     dword [pCpumCpu + CPUMCPU.fUseFlags], ~CPUM_USED_FPU_GUEST
     213        mov     byte [pCpumCpu + CPUMCPU.Guest.fUsedFpuGuest], 0
    213214 %ifdef IN_RC
    214215        test    byte [ebp + 0ch], 1     ; fLeaveFpuAccessible
  • trunk/src/VBox/VMM/include/CPUMInternal.h

    r87351 r87361  
    6767/** Use flags (CPUM::fUseFlags).
    6868 * (Don't forget to sync this with CPUMInternal.mac !)
    69  * @note Part of saved state.
     69 * @note Was part of saved state (6.1 and earlier).
    7070 * @{ */
    7171/** Indicates that we've saved the host FPU, SSE, whatever state and that it
     
    7373#define CPUM_USED_FPU_HOST              RT_BIT(0)
    7474/** Indicates that we've loaded the guest FPU, SSE, whatever state and that it
    75  * needs to be saved. */
     75 * needs to be saved.
     76 * @note Mirrored in CPUMCTX::fUsedFpuGuest for the HM switcher code. */
    7677#define CPUM_USED_FPU_GUEST             RT_BIT(10)
    7778/** Used the guest FPU, SSE or such stuff since last we were in REM.
  • trunk/src/VBox/VMM/include/CPUMInternal.mac

    r87349 r87361  
    222222    .Guest.aoffXState         resw    64
    223223    .Guest.fWorldSwitcher     resd    1
     224    .Guest.fUsedFpuGuest      resb    1
    224225    alignb 8
    225226    .Guest.fExtrn             resq    1
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