VirtualBox

Changeset 87754 in vbox for trunk/src/VBox/VMM/VMMR0


Ignore:
Timestamp:
Feb 13, 2021 5:44:31 PM (4 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
142806
Message:

VMM/HMVMX: Moved the RDTSC in hmR0VmxPostRunGuest to the RESTORE_STATE_VMX assembly macro to get a more accurate value. bugref:9941

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/VMMR0/HMR0A.asm

    r87741 r87754  
    521521 %endif
    522522
    523         ; Save the guest state and restore the non-volatile registers.  We use rax=pGstCtx here.
    524         mov     [rsp + cbFrame + frm_guest_rax], rax
    525         mov     rax, [rsp + cbFrame + frm_pGstCtx]
    526 
    527         mov     qword [rax + CPUMCTX.ebp], rbp
     523        ; Save the guest state and restore the non-volatile registers.  We use rcx=pGstCtx (&pVCpu->cpum.GstCtx) here.
     524        mov     [rsp + cbFrame + frm_guest_rcx], rcx
     525        mov     rcx, [rsp + cbFrame + frm_pGstCtx]
     526
     527        mov     qword [rcx + CPUMCTX.eax], rax
     528        mov     qword [rcx + CPUMCTX.edx], rdx
     529        rdtsc
     530        mov     qword [rcx + CPUMCTX.ebp], rbp
    528531        lea     rbp, [rsp + cbFrame]    ; re-establish the frame pointer as early as possible.
    529         mov     qword [rax + CPUMCTX.ecx], rcx
    530         mov     rcx, SPECTRE_FILLER
    531         mov     qword [rax + CPUMCTX.edx], rdx
    532         mov     rdx, [rbp + frm_guest_rax]
    533         mov     qword [rax + CPUMCTX.eax], rdx
    534         mov     rdx, rcx
    535         mov     qword [rax + CPUMCTX.r8],  r8
    536         mov     r8, rcx
    537         mov     qword [rax + CPUMCTX.r9],  r9
    538         mov     r9, rcx
    539         mov     qword [rax + CPUMCTX.r10], r10
    540         mov     r10, rcx
    541         mov     qword [rax + CPUMCTX.r11], r11
    542         mov     r11, rcx
    543         mov     qword [rax + CPUMCTX.esi], rsi
     532        shl     rdx, 20h
     533        or      rax, rdx                ; TSC value in RAX
     534        mov     rdx, [rbp + frm_guest_rcx]
     535        mov     qword [rcx + CPUMCTX.ecx], rdx
     536        mov     rdx, SPECTRE_FILLER     ; FILLER in RDX
     537        mov     qword [rcx + GVMCPU.hmr0 + HMR0PERVCPU.uTscExit - VMCPU.cpum.GstCtx], rax
     538        mov     qword [rcx + CPUMCTX.r8],  r8
     539        mov     r8, rdx
     540        mov     qword [rcx + CPUMCTX.r9],  r9
     541        mov     r9, rdx
     542        mov     qword [rcx + CPUMCTX.r10], r10
     543        mov     r10, rdx
     544        mov     qword [rcx + CPUMCTX.r11], r11
     545        mov     r11, rdx
     546        mov     qword [rcx + CPUMCTX.esi], rsi
    544547 %ifdef ASM_CALL64_MSC
    545548        mov     rsi, [rbp + frm_saved_rsi]
    546549 %else
    547         mov     rsi, rcx
    548  %endif
    549         mov     qword [rax + CPUMCTX.edi], rdi
     550        mov     rsi, rdx
     551 %endif
     552        mov     qword [rcx + CPUMCTX.edi], rdi
    550553 %ifdef ASM_CALL64_MSC
    551554        mov     rdi, [rbp + frm_saved_rdi]
    552555 %else
    553         mov     rdi, rcx
    554  %endif
    555         mov     qword [rax + CPUMCTX.ebx], rbx
     556        mov     rdi, rdx
     557 %endif
     558        mov     qword [rcx + CPUMCTX.ebx], rbx
    556559        mov     rbx, [rbp + frm_saved_rbx]
    557         mov     qword [rax + CPUMCTX.r12], r12
     560        mov     qword [rcx + CPUMCTX.r12], r12
    558561        mov     r12,  [rbp + frm_saved_r12]
    559         mov     qword [rax + CPUMCTX.r13], r13
     562        mov     qword [rcx + CPUMCTX.r13], r13
    560563        mov     r13,  [rbp + frm_saved_r13]
    561         mov     qword [rax + CPUMCTX.r14], r14
     564        mov     qword [rcx + CPUMCTX.r14], r14
    562565        mov     r14,  [rbp + frm_saved_r14]
    563         mov     qword [rax + CPUMCTX.r15], r15
     566        mov     qword [rcx + CPUMCTX.r15], r15
    564567        mov     r15,  [rbp + frm_saved_r15]
    565568
    566         mov     rdx, cr2
    567         mov     qword [rax + CPUMCTX.cr2], rdx
    568         mov     rdx, rcx
     569        mov     rax, cr2
     570        mov     qword [rcx + CPUMCTX.cr2], rax
     571        mov     rax, rdx
    569572
    570573 %if %4 != 0
    571574        ; Save the context pointer in r8 for the SSE save/restore.
    572         mov     r8, rax
     575        mov     r8, rcx
    573576 %endif
    574577
     
    682685 %define frm_saved_ldtr      -03ch              ; 16-bit: always saved.
    683686 %define frm_rcError         -040h              ; 32-bit: Error status code (not used in the success path)
    684  %define frm_guest_rax       -048h              ; Temporary storage slot for guest RAX.
     687 %define frm_guest_rcx       -048h              ; Temporary storage slot for guest RCX.
    685688 %if %4 = 0
    686689  %assign cbFrame             048h
  • trunk/src/VBox/VMM/VMMR0/HMVMXR0.cpp

    r87752 r87754  
    1115311153static void hmR0VmxPostRunGuest(PVMCPUCC pVCpu, PVMXTRANSIENT pVmxTransient, int rcVMRun)
    1115411154{
    11155     uint64_t const uHostTsc = ASMReadTSC();                     /** @todo We can do a lot better here, see @bugref{9180#c38}. */
    11156 
    1115711155    ASMAtomicUoWriteBool(&pVCpu->hm.s.fCheckedTLBFlush, false); /* See HMInvalidatePageOnAllVCpus(): used for TLB flushing. */
    1115811156    ASMAtomicIncU32(&pVCpu->hmr0.s.cWorldSwitchExits);          /* Initialized in vmR3CreateUVM(): used for EMT poking. */
     
    1116711165        uint64_t uGstTsc;
    1116811166        if (!pVmxTransient->fIsNestedGuest)
    11169             uGstTsc = uHostTsc + pVmcsInfo->u64TscOffset;
     11167            uGstTsc = pVCpu->hmr0.s.uTscExit + pVmcsInfo->u64TscOffset;
    1117011168        else
    1117111169        {
    11172             uint64_t const uNstGstTsc = uHostTsc + pVmcsInfo->u64TscOffset;
     11170            uint64_t const uNstGstTsc = pVCpu->hmr0.s.uTscExit + pVmcsInfo->u64TscOffset;
    1117311171            uGstTsc = CPUMRemoveNestedGuestTscOffset(pVCpu, uNstGstTsc);
    1117411172        }
     
    1117711175
    1117811176    STAM_PROFILE_ADV_STOP_START(&pVCpu->hm.s.StatInGC, &pVCpu->hm.s.StatPreExit, x);
    11179     TMNotifyEndOfExecution(pVCpu->CTX_SUFF(pVM), pVCpu, uHostTsc);      /* Notify TM that the guest is no longer running. */
     11177    TMNotifyEndOfExecution(pVCpu->CTX_SUFF(pVM), pVCpu, pVCpu->hmr0.s.uTscExit); /* Notify TM that the guest is no longer running. */
    1118011178    VMCPU_SET_STATE(pVCpu, VMCPUSTATE_STARTED_HM);
    1118111179
     
    1125811256         */
    1125911257        EMHistoryAddExit(pVCpu, EMEXIT_MAKE_FT(EMEXIT_F_KIND_VMX, pVmxTransient->uExitReason & EMEXIT_F_TYPE_MASK),
    11260                          UINT64_MAX, uHostTsc);
     11258                         UINT64_MAX, pVCpu->hmr0.s.uTscExit);
    1126111259
    1126211260        if (RT_LIKELY(!pVmxTransient->fVMEntryFailed))
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