qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

i386: hvf: Make long mode enter and exit clearer

Intel SDM "9.8.5 Initializing IA-32e Mode" and "9.8.5.4 Switching Out of
IA-32e Mode Operation" define activation and deactivation of long mode
only upon a change of CR0.PG but current code invokes exit_long_mode()
unconditionally until LME is cleared.

Signed-off-by: Cameron Esfahani <dirty@apple.com>
Signed-off-by: Roman Bolshakov <r.bolshakov@yadro.com>
Message-Id: <20200630102824.77604-6-r.bolshakov@yadro.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

authored by

Cameron Esfahani and committed by
Paolo Bonzini
a4e26fa8 5536c98e

+7 -5
+7 -5
target/i386/hvf/vmx.h
··· 121 121 uint64_t pdpte[4] = {0, 0, 0, 0}; 122 122 uint64_t efer = rvmcs(vcpu, VMCS_GUEST_IA32_EFER); 123 123 uint64_t old_cr0 = rvmcs(vcpu, VMCS_GUEST_CR0); 124 + uint64_t changed_cr0 = old_cr0 ^ cr0; 124 125 uint64_t mask = CR0_PG | CR0_CD | CR0_NW | CR0_NE | CR0_ET; 125 126 126 127 if ((cr0 & CR0_PG) && (rvmcs(vcpu, VMCS_GUEST_CR4) & CR4_PAE) && ··· 138 139 wvmcs(vcpu, VMCS_CR0_SHADOW, cr0); 139 140 140 141 if (efer & MSR_EFER_LME) { 141 - if (!(old_cr0 & CR0_PG) && (cr0 & CR0_PG)) { 142 - enter_long_mode(vcpu, cr0, efer); 143 - } 144 - if (/*(old_cr0 & CR0_PG) &&*/ !(cr0 & CR0_PG)) { 145 - exit_long_mode(vcpu, cr0, efer); 142 + if (changed_cr0 & CR0_PG) { 143 + if (cr0 & CR0_PG) { 144 + enter_long_mode(vcpu, cr0, efer); 145 + } else { 146 + exit_long_mode(vcpu, cr0, efer); 147 + } 146 148 } 147 149 } 148 150