VirtualBox

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


Ignore:
Timestamp:
Jan 26, 2021 12:17:26 PM (4 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
142438
Message:

VMM/HMVMX: Only write VMX_VMCS_HOST_RIP and VMX_VMCS_HOST_RSP when they change.

File:
1 edited

Legend:

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

    r87429 r87431  
    824824 %endif
    825825
    826         ; Load CR2 if necessary (may be expensive as writing CR2 is a synchronizing instruction).
     826        ; Load CR2 if necessary (expensive as writing CR2 is a synchronizing instruction - (bird: still expensive on 10980xe)).
    827827        mov     rcx, qword [rdi + CPUMCTX.cr2]
    828828        mov     rdx, cr2
     
    830830        je      .skip_cr2_write
    831831        mov     cr2, rcx
    832 
    833832.skip_cr2_write:
    834         ; Set the vmlaunch/vmresume "return" host RIP and RSP values.
    835         lea     rcx, [NAME(hmR0VMXStartVMHostRIP) wrt rip] ;; @todo It is only strictly necessary to write VMX_VMCS_HOST_RIP when
    836         mov     eax, VMX_VMCS_HOST_RIP                     ;;       the VMXVMCSINFO::pfnStartVM function changes (eventually
    837         vmwrite rax, rcx                                   ;;       take the Windows/SSE stuff into account then)...
    838  %ifdef VBOX_STRICT
    839         jna     NAME(hmR0VMXStartVMHostRIP.vmwrite_failed)
    840  %endif
    841         mov     edx, VMX_VMCS_HOST_RSP                     ;; @todo The HOST_RSP value is unlikely to change much, so if vmwrite
    842         vmwrite rdx, rsp                                   ;;       can be noticably more expensive than a memory read, we could
    843  %ifdef VBOX_STRICT                                        ;;       easily optimize this one away almost completely by comparing
    844         jna     NAME(hmR0VMXStartVMHostRIP.vmwrite_failed) ;;       rsp with a shadow copy of VMX_VMCS_HOST_RSP.
    845  %endif
     833
     834        ; Set the vmlaunch/vmresume "return" host RIP and RSP values if they've changed (unlikly).
     835        ; The vmwrite isn't quite for free (on an 10980xe at least), thus we check if anything changed
     836        ; before writing here.
     837        lea     rcx, [NAME(hmR0VMXStartVMHostRIP) wrt rip]
     838        cmp     rcx, [rsi + VMCPU.hm + HMCPU.u + HMCPUVMX.uHostRIP]
     839        jne     .write_host_rip
     840.wrote_host_rip:
     841        cmp     rsp, [rsi + VMCPU.hm + HMCPU.u + HMCPUVMX.uHostRSP]
     842        jne     .write_host_rsp
     843.wrote_host_rsp:
    846844
    847845        ; Fight spectre and similar. Trashes rax, rcx, and rdx.
     
    880878        jz      NAME(hmR0VMXStartVMHostRIP.vmxstart64_start_failed)
    881879        jmp     NAME(hmR0VMXStartVMHostRIP) ; here if vmlaunch detected a failure
     880
     881
     882; Put these two outside the normal code path as they should rarely change.
     883ALIGNCODE(8)
     884.write_host_rip:
     885        mov     [rsi + VMCPU.hm + HMCPU.u + HMCPUVMX.uHostRIP], rcx
     886        mov     eax, VMX_VMCS_HOST_RIP                      ;; @todo It is only strictly necessary to write VMX_VMCS_HOST_RIP when
     887        vmwrite rax, rcx                                    ;;       the VMXVMCSINFO::pfnStartVM function changes (eventually
     888 %ifdef VBOX_STRICT                                         ;;       take the Windows/SSE stuff into account then)...
     889        jna     NAME(hmR0VMXStartVMHostRIP.vmwrite_failed)
     890 %endif
     891        jmp     .wrote_host_rip
     892
     893ALIGNCODE(8)
     894.write_host_rsp:
     895        mov     [rsi + VMCPU.hm + HMCPU.u + HMCPUVMX.uHostRSP], rsp
     896        mov     eax, VMX_VMCS_HOST_RSP
     897        vmwrite rax, rsp
     898 %ifdef VBOX_STRICT
     899        jna     NAME(hmR0VMXStartVMHostRIP.vmwrite_failed)
     900 %endif
     901        jmp     .wrote_host_rsp
    882902
    883903ALIGNCODE(64)
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