i386: hvf: Don't duplicate register reset
hvf_reset_vcpu() duplicates actions performed by x86_cpu_reset(). The difference is that hvf_reset_vcpu() stores initial values directly to VMCS while x86_cpu_reset() stores it in CPUX86State and then cpu_synchronize_all_post_init() or cpu_synchronize_all_post_reset() flushes CPUX86State into VMCS. That makes hvf_reset_vcpu() a kind of no-op. Here's the trace of CPU state modifications during VM start: hvf_reset_vcpu (resets VMCS) cpu_synchronize_all_post_init (overwrites VMCS fields written by hvf_reset_vcpu()) cpu_synchronize_all_states hvf_reset_vcpu (resets VMCS) cpu_synchronize_all_post_reset (overwrites VMCS fields written by hvf_reset_vcpu()) General purpose registers, system registers, segment descriptors, flags and IP are set by hvf_put_segments() in post-init and post-reset, therefore it's safe to remove them from hvf_reset_vcpu(). PDPTE initialization can be dropped because Intel SDM (26.3.1.6 Checks on Guest Page-Directory-Pointer-Table Entries) doesn't require PDPTE to be clear unless PAE is used: "A VM entry to a guest that does not use PAE paging does not check the validity of any PDPTEs." And if PAE is used, PDPTE's are initialized from CR3 in macvm_set_cr0(). Cc: Cameron Esfahani <dirty@apple.com> Signed-off-by: Roman Bolshakov <r.bolshakov@yadro.com> Message-Id: <20200630102824.77604-8-r.bolshakov@yadro.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
82695a1b9c
commit
5009ef22c6
@ -30,7 +30,6 @@ void hvf_cpu_synchronize_post_reset(CPUState *);
|
||||
void hvf_cpu_synchronize_post_init(CPUState *);
|
||||
void hvf_cpu_synchronize_pre_loadvm(CPUState *);
|
||||
void hvf_vcpu_destroy(CPUState *);
|
||||
void hvf_reset_vcpu(CPUState *);
|
||||
|
||||
#define TYPE_HVF_ACCEL ACCEL_CLASS_NAME("hvf")
|
||||
|
||||
|
@ -6080,9 +6080,6 @@ static void x86_cpu_reset(DeviceState *dev)
|
||||
if (kvm_enabled()) {
|
||||
kvm_arch_reset_vcpu(cpu);
|
||||
}
|
||||
else if (hvf_enabled()) {
|
||||
hvf_reset_vcpu(s);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -452,95 +452,6 @@ static MemoryListener hvf_memory_listener = {
|
||||
.log_sync = hvf_log_sync,
|
||||
};
|
||||
|
||||
void hvf_reset_vcpu(CPUState *cpu) {
|
||||
uint64_t pdpte[4] = {0, 0, 0, 0};
|
||||
int i;
|
||||
|
||||
/* TODO: this shouldn't be needed; there is already a call to
|
||||
* cpu_synchronize_all_post_reset in vl.c
|
||||
*/
|
||||
wvmcs(cpu->hvf_fd, VMCS_GUEST_IA32_EFER, 0);
|
||||
|
||||
/* Initialize PDPTE */
|
||||
for (i = 0; i < 4; i++) {
|
||||
wvmcs(cpu->hvf_fd, VMCS_GUEST_PDPTE0 + i * 2, pdpte[i]);
|
||||
}
|
||||
|
||||
macvm_set_cr0(cpu->hvf_fd, 0x60000010);
|
||||
|
||||
wvmcs(cpu->hvf_fd, VMCS_CR4_MASK, CR4_VMXE_MASK);
|
||||
wvmcs(cpu->hvf_fd, VMCS_CR4_SHADOW, 0x0);
|
||||
wvmcs(cpu->hvf_fd, VMCS_GUEST_CR4, CR4_VMXE_MASK);
|
||||
|
||||
/* set VMCS guest state fields */
|
||||
wvmcs(cpu->hvf_fd, VMCS_GUEST_CS_SELECTOR, 0xf000);
|
||||
wvmcs(cpu->hvf_fd, VMCS_GUEST_CS_LIMIT, 0xffff);
|
||||
wvmcs(cpu->hvf_fd, VMCS_GUEST_CS_ACCESS_RIGHTS, 0x9b);
|
||||
wvmcs(cpu->hvf_fd, VMCS_GUEST_CS_BASE, 0xffff0000);
|
||||
|
||||
wvmcs(cpu->hvf_fd, VMCS_GUEST_DS_SELECTOR, 0);
|
||||
wvmcs(cpu->hvf_fd, VMCS_GUEST_DS_LIMIT, 0xffff);
|
||||
wvmcs(cpu->hvf_fd, VMCS_GUEST_DS_ACCESS_RIGHTS, 0x93);
|
||||
wvmcs(cpu->hvf_fd, VMCS_GUEST_DS_BASE, 0);
|
||||
|
||||
wvmcs(cpu->hvf_fd, VMCS_GUEST_ES_SELECTOR, 0);
|
||||
wvmcs(cpu->hvf_fd, VMCS_GUEST_ES_LIMIT, 0xffff);
|
||||
wvmcs(cpu->hvf_fd, VMCS_GUEST_ES_ACCESS_RIGHTS, 0x93);
|
||||
wvmcs(cpu->hvf_fd, VMCS_GUEST_ES_BASE, 0);
|
||||
|
||||
wvmcs(cpu->hvf_fd, VMCS_GUEST_FS_SELECTOR, 0);
|
||||
wvmcs(cpu->hvf_fd, VMCS_GUEST_FS_LIMIT, 0xffff);
|
||||
wvmcs(cpu->hvf_fd, VMCS_GUEST_FS_ACCESS_RIGHTS, 0x93);
|
||||
wvmcs(cpu->hvf_fd, VMCS_GUEST_FS_BASE, 0);
|
||||
|
||||
wvmcs(cpu->hvf_fd, VMCS_GUEST_GS_SELECTOR, 0);
|
||||
wvmcs(cpu->hvf_fd, VMCS_GUEST_GS_LIMIT, 0xffff);
|
||||
wvmcs(cpu->hvf_fd, VMCS_GUEST_GS_ACCESS_RIGHTS, 0x93);
|
||||
wvmcs(cpu->hvf_fd, VMCS_GUEST_GS_BASE, 0);
|
||||
|
||||
wvmcs(cpu->hvf_fd, VMCS_GUEST_SS_SELECTOR, 0);
|
||||
wvmcs(cpu->hvf_fd, VMCS_GUEST_SS_LIMIT, 0xffff);
|
||||
wvmcs(cpu->hvf_fd, VMCS_GUEST_SS_ACCESS_RIGHTS, 0x93);
|
||||
wvmcs(cpu->hvf_fd, VMCS_GUEST_SS_BASE, 0);
|
||||
|
||||
wvmcs(cpu->hvf_fd, VMCS_GUEST_LDTR_SELECTOR, 0);
|
||||
wvmcs(cpu->hvf_fd, VMCS_GUEST_LDTR_LIMIT, 0);
|
||||
wvmcs(cpu->hvf_fd, VMCS_GUEST_LDTR_ACCESS_RIGHTS, 0x10000);
|
||||
wvmcs(cpu->hvf_fd, VMCS_GUEST_LDTR_BASE, 0);
|
||||
|
||||
wvmcs(cpu->hvf_fd, VMCS_GUEST_TR_SELECTOR, 0);
|
||||
wvmcs(cpu->hvf_fd, VMCS_GUEST_TR_LIMIT, 0);
|
||||
wvmcs(cpu->hvf_fd, VMCS_GUEST_TR_ACCESS_RIGHTS, 0x83);
|
||||
wvmcs(cpu->hvf_fd, VMCS_GUEST_TR_BASE, 0);
|
||||
|
||||
wvmcs(cpu->hvf_fd, VMCS_GUEST_GDTR_LIMIT, 0);
|
||||
wvmcs(cpu->hvf_fd, VMCS_GUEST_GDTR_BASE, 0);
|
||||
|
||||
wvmcs(cpu->hvf_fd, VMCS_GUEST_IDTR_LIMIT, 0);
|
||||
wvmcs(cpu->hvf_fd, VMCS_GUEST_IDTR_BASE, 0);
|
||||
|
||||
/*wvmcs(cpu->hvf_fd, VMCS_GUEST_CR2, 0x0);*/
|
||||
wvmcs(cpu->hvf_fd, VMCS_GUEST_CR3, 0x0);
|
||||
|
||||
wreg(cpu->hvf_fd, HV_X86_RIP, 0xfff0);
|
||||
wreg(cpu->hvf_fd, HV_X86_RDX, 0x623);
|
||||
wreg(cpu->hvf_fd, HV_X86_RFLAGS, 0x2);
|
||||
wreg(cpu->hvf_fd, HV_X86_RSP, 0x0);
|
||||
wreg(cpu->hvf_fd, HV_X86_RAX, 0x0);
|
||||
wreg(cpu->hvf_fd, HV_X86_RBX, 0x0);
|
||||
wreg(cpu->hvf_fd, HV_X86_RCX, 0x0);
|
||||
wreg(cpu->hvf_fd, HV_X86_RSI, 0x0);
|
||||
wreg(cpu->hvf_fd, HV_X86_RDI, 0x0);
|
||||
wreg(cpu->hvf_fd, HV_X86_RBP, 0x0);
|
||||
|
||||
for (int i = 0; i < 8; i++) {
|
||||
wreg(cpu->hvf_fd, HV_X86_R8 + i, 0x0);
|
||||
}
|
||||
|
||||
hv_vcpu_invalidate_tlb(cpu->hvf_fd);
|
||||
hv_vcpu_flush(cpu->hvf_fd);
|
||||
}
|
||||
|
||||
void hvf_vcpu_destroy(CPUState *cpu)
|
||||
{
|
||||
X86CPU *x86_cpu = X86_CPU(cpu);
|
||||
|
Loading…
Reference in New Issue
Block a user