VirtualBox

Changeset 61144 in vbox for trunk/src/VBox/VMM/VMMRZ


Ignore:
Timestamp:
May 23, 2016 10:16:26 PM (9 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
107425
Message:

CPUM,HM,GVMM,TRPM,VMM: Next part of the FPU state handling for IEM. This is a little bit risky change as we now leave CR0.TS+EM cleared after saving the host state, they only get restored when we restore the host state. On Windows, Darwin, and later on Linux (needs testing) we will rely on #NM handling of the host OS and not our own CR.TS/EM handy work. This means we won't be saving the host state but rather the ring-3 state of our own thread. This change also introduces a CPUM force flag that we're using for restoring CR0.TS/EM in raw-mode (it may be extended with other uses later if we need to).

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/VMMRZ/CPUMRZ.cpp

    r61068 r61144  
    5050        case 0:
    5151            cpumRZSaveHostFPUState(&pVCpu->cpum.s);
     52#ifdef IN_RC
     53            VMCPU_FF_SET(pVCpu, VMCPU_FF_CPUM); /* Must recalc CR0 before executing more code! */
     54#endif
    5255            break;
    5356
     
    5760            {
    5861                pVCpu->cpum.s.fUseFlags &= ~CPUM_SYNC_FPU_STATE;
    59 /** @todo tell HM! */
     62                HMR0NotifyCpumUnloadedGuestFpuState(pVCpu);
    6063            }
    6164#endif
     
    6366
    6467        case CPUM_USED_FPU_GUEST | CPUM_USED_FPU_HOST:
    65 /** @todo tell HM! */
    6668#if defined(IN_RING0) && ARCH_BITS == 32 && defined(VBOX_WITH_64_BITS_GUESTS)
    6769            Assert(!(pVCpu->cpum.s.fUseFlags & CPUM_SYNC_FPU_STATE));
     
    7072            else
    7173#endif
    72                 cpumRZSaveGuestFpuState(&pVCpu->cpum.s);
    73 
     74                cpumRZSaveGuestFpuState(&pVCpu->cpum.s, true /*fLeaveFpuAccessible*/);
     75#ifdef IN_RING0
     76            HMR0NotifyCpumUnloadedGuestFpuState(pVCpu);
     77#endif
    7478            break;
    7579
     
    112116        else
    113117#endif
    114             cpumRZSaveGuestFpuState(&pVCpu->cpum.s);
     118            cpumRZSaveGuestFpuState(&pVCpu->cpum.s, false /*fLeaveFpuAccessible*/);
    115119        pVCpu->cpum.s.fUseFlags |= CPUM_USED_FPU_GUEST;
    116120    }
     
    129133#if defined(VBOX_WITH_KERNEL_USING_XMM) && HC_ARCH_BITS == 64
    130134    NOREF(pVCpu);
     135#error "do NOT commit this"
    131136#else
    132137    if (pVCpu->cpum.s.fUseFlags & CPUM_USED_FPU_GUEST)
     
    141146        else
    142147# endif
     148        {
     149RTLogPrintf("calling cpumRZSaveGuestSseRegisters\n");
    143150            cpumRZSaveGuestSseRegisters(&pVCpu->cpum.s);
     151        }
    144152    }
    145153#endif
  • trunk/src/VBox/VMM/VMMRZ/CPUMRZA.asm

    r61112 r61144  
    3434; Saves the host FPU/SSE/AVX state.
    3535;
     36; Will return with CR0.EM and CR0.TS cleared!  This is the normal state in
     37; ring-0, whereas in raw-mode the caller will probably set VMCPU_FF_CPUM to
     38; re-evaluate the situation before executing more guest code.
     39;
    3640; @returns  VINF_SUCCESS (0) in EAX
    3741; @param    pCpumCpu  x86:[ebp+8] gcc:rdi msc:rcx     CPUMCPU pointer
     
    6670        pushf                           ; The darwin kernel can get upset or upset things if an
    6771        cli                             ; interrupt occurs while we're doing fxsave/fxrstor/cr0.
    68 %ifdef VBOX_WITH_KERNEL_USING_XMM
     72
     73%ifndef CPUM_CAN_USE_FPU_IN_R0
     74        ;
     75        ; In raw-mode context and on systems where the kernel doesn't necessarily
     76        ; allow us to use the FPU in ring-0 context, we have to disable FPU traps
     77        ; before doing fxsave/xsave here.  (xCX is 0 if no CR0 was necessary.)  We
     78        ; leave it like that so IEM can use the FPU/SSE/AVX host CPU features directly.
     79        ;
     80        SAVE_CR0_CLEAR_FPU_TRAPS xCX, xAX
     81        ;; @todo What about XCR0?
    6982 %ifdef IN_RING0
    70         movaps  xmm0, xmm0              ; Make 100% sure it's used before we save it or mess with CR0/XCR0.
    71  %endif
    72 %endif
    73         SAVE_CR0_CLEAR_FPU_TRAPS xCX, xAX ; xCX is now old CR0 value, don't use!
    74 
     83        mov     [pCpumCpu + CPUMCPU.Host.cr0Fpu], xCX
     84 %else
     85  %error "Huh?"
     86 %endif
     87%endif
     88        ;
     89        ; Save the host state (xsave/fxsave will cause thread FPU state to be
     90        ; loaded on systems where we are allowed to use it in ring-0.
     91        ;
    7592        CPUMR0_SAVE_HOST
    76         ;; @todo Save CR0 + XCR0 bits related to FPU, SSE and AVX*, leaving these register sets accessible to IEM.
    77 
    78         RESTORE_CR0 xCX
     93
    7994        or      dword [pCpumCpu + CPUMCPU.fUseFlags], (CPUM_USED_FPU_HOST | CPUM_USED_FPU_SINCE_REM) ; Latter is not necessarily true, but normally yes.
    8095        popf
     
    95110;
    96111; @param    pCpumCpu  x86:[ebp+8] gcc:rdi msc:rcx     CPUMCPU pointer
     112; @param    fLeaveFpuAccessible  x86:[ebp+c] gcc:sil msc:dl      Whether to restore CR0 and XCR0 on
     113;                                                                the way out. Only really applicable to RC.
    97114;
    98115align 16
     
    124141        pushf                           ; The darwin kernel can get upset or upset things if an
    125142        cli                             ; interrupt occurs while we're doing fxsave/fxrstor/cr0.
    126         SAVE_CR0_CLEAR_FPU_TRAPS xCX, xAX ; xCX is now old CR0 value, don't use!
    127 
     143
     144 %ifdef IN_RC
     145        SAVE_CR0_CLEAR_FPU_TRAPS xCX, xAX ; xCX must be preserved until CR0 is restored!
     146 %endif
    128147
    129148 %ifndef VBOX_WITH_KERNEL_USING_XMM
     
    185204 %endif
    186205
     206        and     dword [pCpumCpu + CPUMCPU.fUseFlags], ~CPUM_USED_FPU_GUEST
     207 %ifdef IN_RC
     208        test    byte [ebp + 0ch], 1     ; fLeaveFpuAccessible
     209        jz      .no_cr0_restore
    187210        RESTORE_CR0 xCX
    188         and     dword [pCpumCpu + CPUMCPU.fUseFlags], ~CPUM_USED_FPU_GUEST
    189 
     211.no_cr0_restore:
     212 %endif
    190213        popf
    191214%ifdef RT_ARCH_X86
     
    202225;;
    203226; Saves the guest XMM0..15 registers.
     227;
     228; The purpose is to actualize the register state for read-only use, so CR0 is
     229; restored in raw-mode context (so, the FPU/SSE/AVX CPU features can be
     230; inaccessible upon return).
    204231;
    205232; @param    pCpumCpu  x86:[ebp+8] gcc:rdi msc:rcx     CPUMCPU pointer
     
    228255 %else
    229256  %error "Invalid context!"
     257 %endif
     258
     259 %ifdef IN_RC
     260        ; Temporarily grant access to the SSE state. xDX must be preserved until CR0 is restored!
     261        SAVE_CR0_CLEAR_FPU_TRAPS xDX, xAX
    230262 %endif
    231263
     
    251283        movdqa  [xCX + X86FXSTATE.xmm15], xmm15
    252284 %endif
     285
     286 %ifdef IN_RC
     287        RESTORE_CR0 xDX                 ; Restore CR0 if we changed it above.
     288 %endif
     289
    253290%endif ; !VBOX_WITH_KERNEL_USING_XMM
    254291
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