VirtualBox

Changeset 66878 in vbox


Ignore:
Timestamp:
May 12, 2017 12:40:17 PM (8 years ago)
Author:
vboxsync
Message:

CPUM,HM: Added CPUMRZFpuStateActualizeAvxForRead and fixed missing MXCSR availability for the SSE variant. Should save MXCSR when VBOX_WITH_KERNEL_USING_XMM is define.

Location:
trunk
Files:
6 edited

Legend:

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

    r66581 r66878  
    16741674VMMRZ_INT_DECL(void)    CPUMRZFpuStateActualizeForChange(PVMCPU pVCpu);
    16751675VMMRZ_INT_DECL(void)    CPUMRZFpuStateActualizeSseForRead(PVMCPU pVCpu);
     1676VMMRZ_INT_DECL(void)    CPUMRZFpuStateActualizeAvxForRead(PVMCPU pVCpu);
    16761677/** @} */
    16771678
  • trunk/src/VBox/VMM/VMMR0/CPUMR0A.asm

    r61348 r66878  
    6666; @uses nothing (well, maybe cr0)
    6767;
     68 %ifndef RT_ASM_WITH_SEH64 ; workaround for yasm 1.3.0 bug (error: prologue -1 bytes, must be <256)
    6869ALIGNCODE(16)
     70 %endif
    6971BEGINPROC CPUMR0TouchHostFpu
    7072        push    xBP
     
    8890; @param    pCpumCpu  x86:[ebp+8] gcc:rdi msc:rcx     CPUMCPU pointer
    8991;
     92; @remarks  64-bit Windows drivers shouldn't use AVX registers without saving+loading:
     93;               https://msdn.microsoft.com/en-us/library/windows/hardware/ff545910%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396
     94;           However the compiler docs have different idea:
     95;               https://msdn.microsoft.com/en-us/library/9z1stfyw.aspx
     96;           We'll go with the former for now.
     97;
     98%ifndef RT_ASM_WITH_SEH64 ; workaround for yasm 1.3.0 bug (error: prologue -1 bytes, must be <256)
    9099ALIGNCODE(16)
     100%endif
    91101BEGINPROC cpumR0SaveHostRestoreGuestFPUState
    92102        push    xBP
     
    135145        ; If we didn't save the host state, we must save the non-volatile XMM registers.
    136146        mov     pXState, [pCpumCpu + CPUMCPU.Host.pXStateR0]
     147        stmxcsr [pXState + X86FXSTATE.MXCSR]
    137148        movdqa  [pXState + X86FXSTATE.xmm6 ], xmm6
    138149        movdqa  [pXState + X86FXSTATE.xmm7 ], xmm7
     
    166177        movdqa  xmm14, [pXState + X86FXSTATE.xmm14]
    167178        movdqa  xmm15, [pXState + X86FXSTATE.xmm15]
     179        ldmxcsr        [pXState + X86FXSTATE.MXCSR]
    168180%endif
    169181
     
    187199; @param    pCpumCpu  x86:[ebp+8] gcc:rdi msc:rcx     CPUMCPU pointer
    188200;
     201; @remarks  64-bit Windows drivers shouldn't use AVX registers without saving+loading:
     202;               https://msdn.microsoft.com/en-us/library/windows/hardware/ff545910%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396
     203;           However the compiler docs have different idea:
     204;               https://msdn.microsoft.com/en-us/library/9z1stfyw.aspx
     205;           We'll go with the former for now.
     206;
     207%ifndef RT_ASM_WITH_SEH64 ; workaround for yasm 1.3.0 bug (error: prologue -1 bytes, must be <256)
    189208ALIGNCODE(16)
     209%endif
    190210BEGINPROC cpumR0SaveGuestRestoreHostFPUState
    191211        push    xBP
     
    222242        ;
    223243        mov     pXState, [pCpumCpu + CPUMCPU.Host.pXStateR0]
     244        stmxcsr [pXState + X86FXSTATE.MXCSR]
    224245        movdqa  [pXState + X86FXSTATE.xmm6], xmm6
    225246        movdqa  [pXState + X86FXSTATE.xmm7], xmm7
     
    259280        movdqa  xmm14, [pXState + X86FXSTATE.xmm14]
    260281        movdqa  xmm15, [pXState + X86FXSTATE.xmm15]
     282        ldmxcsr        [pXState + X86FXSTATE.MXCSR]
    261283 %endif
    262284        CPUMR0_SAVE_GUEST
     
    293315; @param    pCpumCpu  x86:[ebp+8] gcc:rdi msc:rcx     CPUMCPU pointer
    294316;
     317  %ifndef RT_ASM_WITH_SEH64 ; workaround for yasm 1.3.0 bug (error: prologue -1 bytes, must be <256)
    295318ALIGNCODE(16)
     319  %endif
    296320BEGINPROC cpumR0RestoreHostFPUState
    297321        ;
  • trunk/src/VBox/VMM/VMMR0/HMR0A.asm

    r65932 r66878  
    808808; @remarks      This is essentially the same code as hmR0SVMRunWrapXMM, only the parameters differ a little bit.
    809809;
     810; @remarks      Drivers shouldn't use AVX registers without saving+loading:
     811;                   https://msdn.microsoft.com/en-us/library/windows/hardware/ff545910%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396
     812;               However the compiler docs have different idea:
     813;                   https://msdn.microsoft.com/en-us/library/9z1stfyw.aspx
     814;               We'll go with the former for now.
     815;
    810816; ASSUMING 64-bit and windows for now.
     817;
    811818ALIGNCODE(16)
    812819BEGINPROC hmR0VMXStartVMWrapXMM
    813820        push    xBP
    814821        mov     xBP, xSP
    815         sub     xSP, 0a0h + 040h        ; Don't bother optimizing the frame size.
     822        sub     xSP, 0b0h + 040h ; Don't bother optimizing the frame size.
    816823
    817824        ; spill input parameters.
     
    853860        movdqa  [rsp + 040h + 080h], xmm14
    854861        movdqa  [rsp + 040h + 090h], xmm15
     862        stmxcsr [rsp + 040h + 0a0h]
    855863
    856864        mov     r10, [xBP + 018h]       ; pCtx
     
    901909        movdqa  xmm14, [rsp + 040h + 080h]
    902910        movdqa  xmm15, [rsp + 040h + 090h]
     911        ldmxcsr        [rsp + 040h + 0a0h]
    903912        leave
    904913        ret
     
    926935        movdqa  xmm14, [r10 + XMM_OFF_IN_X86FXSTATE + 0e0h]
    927936        movdqa  xmm15, [r10 + XMM_OFF_IN_X86FXSTATE + 0f0h]
     937        ldmxcsr        [r10 + X86FXSTATE.MXCSR]
    928938
    929939        ; Make the call (same as in the other case ).
     
    940950        mov     r10, [xBP + 018h]       ; pCtx
    941951        mov     r10, [r10 + CPUMCTX.pXStateR0]
     952        stmxcsr [r10 + X86FXSTATE.MXCSR]
    942953        movdqa  [r10 + XMM_OFF_IN_X86FXSTATE + 000h], xmm0
    943954        movdqa  [r10 + XMM_OFF_IN_X86FXSTATE + 010h], xmm1
     
    976987; @remarks      This is essentially the same code as hmR0VMXStartVMWrapXMM, only the parameters differ a little bit.
    977988;
     989; @remarks      Drivers shouldn't use AVX registers without saving+loading:
     990;                   https://msdn.microsoft.com/en-us/library/windows/hardware/ff545910%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396
     991;               However the compiler docs have different idea:
     992;                   https://msdn.microsoft.com/en-us/library/9z1stfyw.aspx
     993;               We'll go with the former for now.
     994;
    978995; ASSUMING 64-bit and windows for now.
    979996ALIGNCODE(16)
     
    981998        push    xBP
    982999        mov     xBP, xSP
    983         sub     xSP, 0a0h + 040h        ; Don't bother optimizing the frame size.
     1000        sub     xSP, 0b0h + 040h        ; Don't bother optimizing the frame size.
    9841001
    9851002        ; spill input parameters.
     
    10211038        movdqa  [rsp + 040h + 080h], xmm14
    10221039        movdqa  [rsp + 040h + 090h], xmm15
     1040        stmxcsr [rsp + 040h + 0a0h]
    10231041
    10241042        mov     r10, [xBP + 020h]       ; pCtx
     
    10691087        movdqa  xmm14, [rsp + 040h + 080h]
    10701088        movdqa  xmm15, [rsp + 040h + 090h]
     1089        ldmxcsr [rsp + 040h + 0a0h]
    10711090        leave
    10721091        ret
     
    10941113        movdqa  xmm14, [r10 + XMM_OFF_IN_X86FXSTATE + 0e0h]
    10951114        movdqa  xmm15, [r10 + XMM_OFF_IN_X86FXSTATE + 0f0h]
     1115        ldmxcsr        [r10 + X86FXSTATE.MXCSR]
    10961116
    10971117        ; Make the call (same as in the other case ).
     
    11081128        mov     r10, [xBP + 020h]       ; pCtx
    11091129        mov     r10, [r10 + CPUMCTX.pXStateR0]
     1130        stmxcsr [r10 + X86FXSTATE.MXCSR]
    11101131        movdqa  [r10 + XMM_OFF_IN_X86FXSTATE + 000h], xmm0
    11111132        movdqa  [r10 + XMM_OFF_IN_X86FXSTATE + 010h], xmm1
  • trunk/src/VBox/VMM/VMMRZ/CPUMRZ.cpp

    r61392 r66878  
    134134
    135135/**
    136  * Makes sure the XMM0..XMM15 state in CPUMCPU::Guest is up to date.
     136 * Makes sure the XMM0..XMM15 and MXCSR state in CPUMCPU::Guest is up to date.
    137137 *
    138138 * This will not cause CPUM_USED_FPU_GUEST to change.
     
    162162}
    163163
     164
     165/**
     166 * Makes sure the YMM0..YMM15 and MXCSR state in CPUMCPU::Guest is up to date.
     167 *
     168 * This will not cause CPUM_USED_FPU_GUEST to change.
     169 *
     170 * @param   pVCpu       The cross context virtual CPU structure.
     171 */
     172VMMRZ_INT_DECL(void)    CPUMRZFpuStateActualizeAvxForRead(PVMCPU pVCpu)
     173{
     174    if (pVCpu->cpum.s.fUseFlags & CPUM_USED_FPU_GUEST)
     175    {
     176#if defined(IN_RING0) && ARCH_BITS == 32 && defined(VBOX_WITH_64_BITS_GUESTS)
     177        if (CPUMIsGuestInLongModeEx(&pVCpu->cpum.s.Guest))
     178        {
     179            Assert(!(pVCpu->cpum.s.fUseFlags & CPUM_SYNC_FPU_STATE));
     180            HMR0SaveFPUState(pVCpu->CTX_SUFF(pVM), pVCpu, &pVCpu->cpum.s.Guest);
     181            pVCpu->cpum.s.fUseFlags |= CPUM_USED_FPU_GUEST;
     182        }
     183        else
     184#endif
     185            cpumRZSaveGuestAvxRegisters(&pVCpu->cpum.s);
     186        Log7(("CPUMRZFpuStateActualizeAvxForRead\n"));
     187    }
     188}
     189
  • trunk/src/VBox/VMM/VMMRZ/CPUMRZA.asm

    r61368 r66878  
    105105; @param    fLeaveFpuAccessible  x86:[ebp+c] gcc:sil msc:dl      Whether to restore CR0 and XCR0 on
    106106;                                                                the way out. Only really applicable to RC.
     107;
     108; @remarks  64-bit Windows drivers shouldn't use AVX registers without saving+loading:
     109;               https://msdn.microsoft.com/en-us/library/windows/hardware/ff545910%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396
     110;           However the compiler docs have different idea:
     111;               https://msdn.microsoft.com/en-us/library/9z1stfyw.aspx
     112;           We'll go with the former for now.
    107113;
    108114align 16
     
    166172        movdqa  [pXState + X86FXSTATE.xmm14], xmm14
    167173        movdqa  [pXState + X86FXSTATE.xmm15], xmm15
     174        stmxcsr [pXState + X86FXSTATE.MXCSR]
    168175
    169176        ; Load the guest XMM register values we already saved in HMR0VMXStartVMWrapXMM.
     
    185192        movdqa  xmm14, [pXState + X86FXSTATE.xmm14]
    186193        movdqa  xmm15, [pXState + X86FXSTATE.xmm15]
     194        ldmxcsr        [pXState + X86FXSTATE.MXCSR]
    187195
    188196        CPUMR0_SAVE_GUEST
     
    200208        movdqa  xmm14, [pXState + X86FXSTATE.xmm14]
    201209        movdqa  xmm15, [pXState + X86FXSTATE.xmm15]
     210        ldmxcsr        [pXState + X86FXSTATE.MXCSR]
    202211
    203212 %endif
     
    223232
    224233;;
    225 ; Saves the guest XMM0..15 registers.
     234; Saves the guest XMM0..15 registers and MXCSR.
    226235;
    227236; The purpose is to actualize the register state for read-only use, so CR0 is
     
    270279        ; Do the job.
    271280        ;
     281        stmxcsr [xCX + X86FXSTATE.MXCSR]
    272282        movdqa  [xCX + X86FXSTATE.xmm0 ], xmm0
    273283        movdqa  [xCX + X86FXSTATE.xmm1 ], xmm1
     
    299309ENDPROC   cpumRZSaveGuestSseRegisters
    300310
     311;;
     312; Saves the guest YMM0..15 registers.
     313;
     314; The purpose is to actualize the register state for read-only use, so CR0 is
     315; restored in raw-mode context (so, the FPU/SSE/AVX CPU features can be
     316; inaccessible upon return).
     317;
     318; @param    pCpumCpu  x86:[ebp+8] gcc:rdi msc:rcx     CPUMCPU pointer
     319;
     320align 16
     321BEGINPROC cpumRZSaveGuestAvxRegisters
     322        push    xBP
     323        SEH64_PUSH_xBP
     324        mov     xBP, xSP
     325        SEH64_SET_FRAME_xBP 0
     326%ifdef IN_RC
     327        push    xBX
     328%endif
     329SEH64_END_PROLOGUE
     330
     331        ;
     332        ; Load xCX with the guest pXStateR0.
     333        ;
     334%ifdef ASM_CALL64_GCC
     335        mov     xCX, rdi
     336%elifdef RT_ARCH_X86
     337        mov     xCX, dword [ebp + 8]
     338%endif
     339%ifdef IN_RING0
     340        mov     xCX, [xCX + CPUMCPU.Guest.pXStateR0]
     341%elifdef IN_RC
     342        mov     xCX, [xCX + CPUMCPU.Guest.pXStateRC]
     343%else
     344 %error "Invalid context!"
     345%endif
     346
     347%ifdef IN_RC
     348        ; Temporarily grant access to the SSE state. xBX must be preserved until CR0 is restored!
     349        mov     ebx, cr0
     350        test    ebx, X86_CR0_TS | X86_CR0_EM
     351        jz      .skip_cr0_write
     352        mov     eax, ebx
     353        and     eax, ~(X86_CR0_TS | X86_CR0_EM)
     354        mov     cr0, eax
     355.skip_cr0_write:
     356%endif
     357
     358        ;
     359        ; Use XSAVE to do the job.
     360        ;
     361        ; Drivers shouldn't use AVX registers without saving+loading:
     362        ;     https://msdn.microsoft.com/en-us/library/windows/hardware/ff545910%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396
     363        ; However the compiler docs have different idea:
     364        ;     https://msdn.microsoft.com/en-us/library/9z1stfyw.aspx
     365        ; We'll go with the former for now.
     366        ;
     367%ifdef VBOX_WITH_KERNEL_USING_XMM
     368        mov     eax, XSAVE_C_YMM
     369%else
     370        mov     eax, XSAVE_C_YMM | XSAVE_C_SSE ; The SSE component includes MXCSR.
     371%endif
     372        xor     edx, edx
     373%if ARCH_BITS == 64
     374        o64 xsave [xCX]
     375%else
     376        xsave   [xCX]
     377%endif
     378
     379%ifdef IN_RC
     380        CPUMRZ_RESTORE_CR0_IF_TS_OR_EM_SET ebx  ; Restore CR0 if we changed it above.
     381        pop     xBX
     382%endif
     383        leave
     384        ret
     385ENDPROC   cpumRZSaveGuestAvxRegisters
     386
  • trunk/src/VBox/VMM/include/CPUMInternal.h

    r66403 r66878  
    559559DECLASM(void)       cpumRZSaveGuestFpuState(PCPUMCPU pCPUM, bool fLeaveFpuAccessible);
    560560DECLASM(void)       cpumRZSaveGuestSseRegisters(PCPUMCPU pCPUM);
     561DECLASM(void)       cpumRZSaveGuestAvxRegisters(PCPUMCPU pCPUM);
    561562# endif
    562563
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