From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: Roman Bolshakov <r.bolshakov@yadro.com>,
Cameron Esfahani <dirty@apple.com>
Subject: [PULL 17/53] i386: hvf: Don't duplicate register reset
Date: Mon, 6 Jul 2020 12:41:19 -0400 [thread overview]
Message-ID: <20200706164155.24696-18-pbonzini@redhat.com> (raw)
In-Reply-To: <20200706164155.24696-1-pbonzini@redhat.com>
From: Roman Bolshakov <r.bolshakov@yadro.com>
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>
---
include/sysemu/hvf.h | 1 -
target/i386/cpu.c | 3 --
target/i386/hvf/hvf.c | 89 -------------------------------------------
3 files changed, 93 deletions(-)
diff --git a/include/sysemu/hvf.h b/include/sysemu/hvf.h
index 1d40a8ec01..6d3ee4fdb7 100644
--- a/include/sysemu/hvf.h
+++ b/include/sysemu/hvf.h
@@ -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")
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index f1cbac2fb5..c44cc510e1 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -6099,9 +6099,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
}
diff --git a/target/i386/hvf/hvf.c b/target/i386/hvf/hvf.c
index 31980f9076..2a12867ef0 100644
--- a/target/i386/hvf/hvf.c
+++ b/target/i386/hvf/hvf.c
@@ -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);
--
2.26.2
next prev parent reply other threads:[~2020-07-06 16:49 UTC|newest]
Thread overview: 76+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-06 16:41 [PULL 00/53] Misc patches for QEMU 5.1 soft freeze Paolo Bonzini
2020-07-06 16:41 ` [PULL 01/53] tcg/svm: use host cr4 during NPT page table walk Paolo Bonzini
2020-07-06 16:41 ` [PULL 02/53] tests: Inject test name also when the test fails Paolo Bonzini
2020-07-06 16:41 ` [PULL 03/53] util/qemu-error: prepend guest name to error message to identify affected VM owner Paolo Bonzini
2020-07-06 16:41 ` [PULL 04/53] qom: Introduce object_property_try_add_child() Paolo Bonzini
2020-07-06 16:41 ` [PULL 05/53] tests/qmp-cmd-test: Add qmp/object-add-duplicate-id Paolo Bonzini
2020-07-06 16:41 ` [PULL 06/53] tests/qmp-cmd-test: Add qmp/object-add-failure-modes Paolo Bonzini
2020-07-06 16:41 ` [PULL 07/53] hw/core/null-machine: Do not initialize unused chardev backends Paolo Bonzini
2020-07-06 16:41 ` [PULL 08/53] target/i386: set SSE FTZ in correct floating-point state Paolo Bonzini
2020-07-06 16:41 ` [PULL 09/53] target/i386: fix IEEE SSE floating-point exception raising Paolo Bonzini
2020-07-06 16:41 ` [PULL 10/53] KVM: add support for AMD nested live migration Paolo Bonzini
2020-07-06 16:41 ` [PULL 11/53] coverity: provide Coverity-friendly MIN_CONST and MAX_CONST Paolo Bonzini
2020-07-06 16:41 ` [PULL 12/53] i386: hvf: Set env->eip in macvm_set_rip() Paolo Bonzini
2020-07-06 16:41 ` [PULL 13/53] i386: hvf: Move synchronize functions to sysemu Paolo Bonzini
2020-07-06 16:41 ` [PULL 14/53] i386: hvf: Add hvf_cpu_synchronize_pre_loadvm() Paolo Bonzini
2020-07-06 16:41 ` [PULL 15/53] i386: hvf: Make long mode enter and exit clearer Paolo Bonzini
2020-07-06 16:41 ` [PULL 16/53] i386: hvf: Move Guest LMA reset to macvm_set_cr0() Paolo Bonzini
2020-07-06 16:41 ` Paolo Bonzini [this message]
2020-07-06 16:41 ` [PULL 18/53] i386: hvf: Clean up synchronize functions Paolo Bonzini
2020-07-06 16:41 ` [PULL 19/53] MAINTAINERS: Add Cameron as HVF co-maintainer Paolo Bonzini
2020-07-06 16:41 ` [PULL 20/53] MAINTAINERS: Fix KVM path expansion glob Paolo Bonzini
2020-07-06 16:41 ` [PULL 21/53] MAINTAINERS: Add an 'overall' entry for accelerators Paolo Bonzini
2020-07-06 16:41 ` [PULL 22/53] MAINTAINERS: Cover the HAX accelerator stub Paolo Bonzini
2020-07-06 16:41 ` [PULL 23/53] Makefile: Remove dangerous EOL trailing backslash Paolo Bonzini
2020-07-06 16:41 ` [PULL 24/53] Makefile: Write MINIKCONF variables as one entry per line Paolo Bonzini
2020-07-06 16:41 ` [PULL 25/53] accel/Kconfig: Extract accel selectors into their own config Paolo Bonzini
2020-07-06 16:41 ` [PULL 26/53] accel/Kconfig: Add the TCG selector Paolo Bonzini
2020-07-06 16:41 ` [PULL 27/53] accel/tcg: Add stub for probe_access() Paolo Bonzini
2020-07-06 16:41 ` [PULL 28/53] Makefile: simplify MINIKCONF rules Paolo Bonzini
2020-07-17 11:02 ` Peter Maydell
2020-07-17 11:20 ` Paolo Bonzini
2020-07-17 13:01 ` Peter Maydell
2020-07-17 13:33 ` Paolo Bonzini
2020-07-06 16:41 ` [PULL 29/53] target/i386: remove gen_io_end Paolo Bonzini
2020-07-06 16:41 ` [PULL 30/53] target/i386: implement undocumented "smsw r32" behavior Paolo Bonzini
2020-07-06 16:41 ` [PULL 31/53] KVM: x86: believe what KVM says about WAITPKG Paolo Bonzini
2020-07-07 11:42 ` Maxim Levitsky
2020-07-07 11:58 ` Paolo Bonzini
2021-12-22 9:35 ` Chenyi Qiang
2020-07-06 16:41 ` [PULL 32/53] target/i386: sev: provide proper error reporting for query-sev-capabilities Paolo Bonzini
2020-07-06 16:41 ` [PULL 33/53] target/i386: sev: fail query-sev-capabilities if QEMU cannot use SEV Paolo Bonzini
2020-07-06 16:41 ` [PULL 34/53] iscsi: handle check condition status in retry loop Paolo Bonzini
2020-07-06 16:41 ` [PULL 35/53] iscsi: return -EIO when sense fields are meaningless Paolo Bonzini
2020-07-06 16:41 ` [PULL 36/53] chardev/tcp: fix error message double free error Paolo Bonzini
2020-07-06 16:41 ` [PULL 37/53] checkpatch: Change occurences of 'kernel' to 'qemu' in user messages Paolo Bonzini
2020-07-06 16:41 ` [PULL 38/53] target/i386: Correct the warning message of Intel PT Paolo Bonzini
2020-07-06 16:41 ` [PULL 39/53] cpus: Move CPU code from exec.c to cpus-common.c Paolo Bonzini
2020-07-06 16:41 ` [PULL 40/53] pc: fix leak in pc_system_flash_cleanup_unused Paolo Bonzini
2020-07-06 16:41 ` [PULL 41/53] softmmu: move softmmu only files from root Paolo Bonzini
2020-07-06 16:41 ` [PULL 42/53] cpu-throttle: new module, extracted from cpus.c Paolo Bonzini
2020-07-06 16:41 ` [PULL 43/53] cpu-timers, icount: new modules Paolo Bonzini
2020-07-06 16:41 ` [PULL 44/53] softmmu/vl: Remove the check for colons in -accel parameters Paolo Bonzini
2020-07-06 16:41 ` [PULL 45/53] accel/kvm: Let kvm_check_extension use global KVM state Paolo Bonzini
2020-07-06 16:41 ` [PULL 46/53] accel/kvm: Simplify kvm_check_extension() Paolo Bonzini
2020-07-06 16:41 ` [PULL 47/53] accel/kvm: Simplify kvm_check_extension_list() Paolo Bonzini
2020-07-06 16:41 ` [PULL 48/53] target/i386/kvm: Simplify get_para_features() Paolo Bonzini
2020-07-06 16:41 ` [PULL 49/53] target/i386/kvm: Simplify kvm_get_mce_cap_supported() Paolo Bonzini
2020-07-06 16:41 ` [PULL 50/53] target/i386/kvm: Simplify kvm_get_supported_[feature]_msrs() Paolo Bonzini
2020-07-06 16:41 ` [PULL 51/53] target/i386: Add SERIALIZE cpu feature Paolo Bonzini
2020-07-06 16:41 ` [PULL 52/53] target/i386: Enable TSX Suspend Load Address Tracking feature Paolo Bonzini
2020-07-06 16:41 ` [PULL 53/53] scripts: improve message when TAP based tests fail Paolo Bonzini
2020-07-06 17:19 ` [PULL 00/53] Misc patches for QEMU 5.1 soft freeze no-reply
2020-07-07 18:37 ` Peter Maydell
2020-07-07 18:42 ` Peter Maydell
2020-07-07 18:48 ` Paolo Bonzini
2020-07-08 8:25 ` Philippe Mathieu-Daudé
2020-07-08 16:13 ` Claudio Fontana
2020-07-08 16:16 ` Paolo Bonzini
2020-07-08 16:45 ` Claudio Fontana
2020-07-08 16:55 ` Paolo Bonzini
2020-07-08 17:03 ` Claudio Fontana
2020-07-08 18:25 ` Claudio Fontana
2020-07-08 18:34 ` Claudio Fontana
2020-07-08 18:41 ` Paolo Bonzini
2020-07-09 6:59 ` Claudio Fontana
2020-07-09 9:57 ` Paolo Bonzini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200706164155.24696-18-pbonzini@redhat.com \
--to=pbonzini@redhat.com \
--cc=dirty@apple.com \
--cc=qemu-devel@nongnu.org \
--cc=r.bolshakov@yadro.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).