|
|
4ec855 |
From a8a32dd460a1d838cfe97ec53a2eb76c018c5dbf Mon Sep 17 00:00:00 2001
|
|
|
4ec855 |
From: Paolo Bonzini <pbonzini@redhat.com>
|
|
|
4ec855 |
Date: Mon, 22 Jul 2019 18:22:19 +0100
|
|
|
4ec855 |
Subject: [PATCH 38/39] target/i386: skip KVM_GET/SET_NESTED_STATE if VMX
|
|
|
4ec855 |
disabled, or for SVM
|
|
|
4ec855 |
|
|
|
4ec855 |
RH-Author: Paolo Bonzini <pbonzini@redhat.com>
|
|
|
4ec855 |
Message-id: <20190722182220.19374-18-pbonzini@redhat.com>
|
|
|
4ec855 |
Patchwork-id: 89636
|
|
|
4ec855 |
O-Subject: [RHEL-8.1.0 PATCH qemu-kvm v3 17/18] target/i386: skip KVM_GET/SET_NESTED_STATE if VMX disabled, or for SVM
|
|
|
4ec855 |
Bugzilla: 1689269
|
|
|
4ec855 |
RH-Acked-by: Peter Xu <zhexu@redhat.com>
|
|
|
4ec855 |
RH-Acked-by: Laurent Vivier <lvivier@redhat.com>
|
|
|
4ec855 |
RH-Acked-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
|
|
|
4ec855 |
|
|
|
4ec855 |
Do not allocate env->nested_state unless we later need to migrate the
|
|
|
4ec855 |
nested virtualization state.
|
|
|
4ec855 |
|
|
|
4ec855 |
With this change, nested_state_needed() will return false if the
|
|
|
4ec855 |
VMX flag is not included in the virtual machine. KVM_GET/SET_NESTED_STATE
|
|
|
4ec855 |
is also disabled for SVM which is safer (we know that at least the NPT
|
|
|
4ec855 |
root and paging mode have to be saved/loaded), and thus the corresponding
|
|
|
4ec855 |
subsection can go away as well.
|
|
|
4ec855 |
|
|
|
4ec855 |
Inspired by a patch from Liran Alon.
|
|
|
4ec855 |
|
|
|
4ec855 |
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
|
|
|
4ec855 |
(cherry picked from commit 1e44f3ab71fb4291d266a264f7c207ae5c6d59b2)
|
|
|
4ec855 |
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
|
|
|
4ec855 |
---
|
|
|
4ec855 |
target/i386/kvm.c | 16 ++++++++--------
|
|
|
4ec855 |
target/i386/machine.c | 21 +--------------------
|
|
|
4ec855 |
2 files changed, 9 insertions(+), 28 deletions(-)
|
|
|
4ec855 |
|
|
|
4ec855 |
diff --git a/target/i386/kvm.c b/target/i386/kvm.c
|
|
|
4ec855 |
index 0bd286e..8648f1f 100644
|
|
|
4ec855 |
--- a/target/i386/kvm.c
|
|
|
4ec855 |
+++ b/target/i386/kvm.c
|
|
|
4ec855 |
@@ -1220,15 +1220,15 @@ int kvm_arch_init_vcpu(CPUState *cs)
|
|
|
4ec855 |
max_nested_state_len = kvm_max_nested_state_length();
|
|
|
4ec855 |
if (max_nested_state_len > 0) {
|
|
|
4ec855 |
assert(max_nested_state_len >= offsetof(struct kvm_nested_state, data));
|
|
|
4ec855 |
- env->nested_state = g_malloc0(max_nested_state_len);
|
|
|
4ec855 |
|
|
|
4ec855 |
- env->nested_state->size = max_nested_state_len;
|
|
|
4ec855 |
-
|
|
|
4ec855 |
- if (IS_INTEL_CPU(env)) {
|
|
|
4ec855 |
- struct kvm_vmx_nested_state_hdr *vmx_hdr =
|
|
|
4ec855 |
- &env->nested_state->hdr.vmx;
|
|
|
4ec855 |
+ if (cpu_has_vmx(env)) {
|
|
|
4ec855 |
+ struct kvm_vmx_nested_state_hdr *vmx_hdr;
|
|
|
4ec855 |
|
|
|
4ec855 |
+ env->nested_state = g_malloc0(max_nested_state_len);
|
|
|
4ec855 |
+ env->nested_state->size = max_nested_state_len;
|
|
|
4ec855 |
env->nested_state->format = KVM_STATE_NESTED_FORMAT_VMX;
|
|
|
4ec855 |
+
|
|
|
4ec855 |
+ vmx_hdr = &env->nested_state->hdr.vmx;
|
|
|
4ec855 |
vmx_hdr->vmxon_pa = -1ull;
|
|
|
4ec855 |
vmx_hdr->vmcs12_pa = -1ull;
|
|
|
4ec855 |
}
|
|
|
4ec855 |
@@ -2966,7 +2966,7 @@ static int kvm_put_nested_state(X86CPU *cpu)
|
|
|
4ec855 |
CPUX86State *env = &cpu->env;
|
|
|
4ec855 |
int max_nested_state_len = kvm_max_nested_state_length();
|
|
|
4ec855 |
|
|
|
4ec855 |
- if (max_nested_state_len <= 0) {
|
|
|
4ec855 |
+ if (!env->nested_state) {
|
|
|
4ec855 |
return 0;
|
|
|
4ec855 |
}
|
|
|
4ec855 |
|
|
|
4ec855 |
@@ -2980,7 +2980,7 @@ static int kvm_get_nested_state(X86CPU *cpu)
|
|
|
4ec855 |
int max_nested_state_len = kvm_max_nested_state_length();
|
|
|
4ec855 |
int ret;
|
|
|
4ec855 |
|
|
|
4ec855 |
- if (max_nested_state_len <= 0) {
|
|
|
4ec855 |
+ if (!env->nested_state) {
|
|
|
4ec855 |
return 0;
|
|
|
4ec855 |
}
|
|
|
4ec855 |
|
|
|
4ec855 |
diff --git a/target/i386/machine.c b/target/i386/machine.c
|
|
|
4ec855 |
index 8d90d98..fa8d1cc 100644
|
|
|
4ec855 |
--- a/target/i386/machine.c
|
|
|
4ec855 |
+++ b/target/i386/machine.c
|
|
|
4ec855 |
@@ -1004,31 +1004,13 @@ static const VMStateDescription vmstate_vmx_nested_state = {
|
|
|
4ec855 |
}
|
|
|
4ec855 |
};
|
|
|
4ec855 |
|
|
|
4ec855 |
-static bool svm_nested_state_needed(void *opaque)
|
|
|
4ec855 |
-{
|
|
|
4ec855 |
- struct kvm_nested_state *nested_state = opaque;
|
|
|
4ec855 |
-
|
|
|
4ec855 |
- return (nested_state->format == KVM_STATE_NESTED_FORMAT_SVM);
|
|
|
4ec855 |
-}
|
|
|
4ec855 |
-
|
|
|
4ec855 |
-static const VMStateDescription vmstate_svm_nested_state = {
|
|
|
4ec855 |
- .name = "cpu/kvm_nested_state/svm",
|
|
|
4ec855 |
- .version_id = 1,
|
|
|
4ec855 |
- .minimum_version_id = 1,
|
|
|
4ec855 |
- .needed = svm_nested_state_needed,
|
|
|
4ec855 |
- .fields = (VMStateField[]) {
|
|
|
4ec855 |
- VMSTATE_END_OF_LIST()
|
|
|
4ec855 |
- }
|
|
|
4ec855 |
-};
|
|
|
4ec855 |
-
|
|
|
4ec855 |
static bool nested_state_needed(void *opaque)
|
|
|
4ec855 |
{
|
|
|
4ec855 |
X86CPU *cpu = opaque;
|
|
|
4ec855 |
CPUX86State *env = &cpu->env;
|
|
|
4ec855 |
|
|
|
4ec855 |
return (env->nested_state &&
|
|
|
4ec855 |
- (vmx_nested_state_needed(env->nested_state) ||
|
|
|
4ec855 |
- svm_nested_state_needed(env->nested_state)));
|
|
|
4ec855 |
+ vmx_nested_state_needed(env->nested_state));
|
|
|
4ec855 |
}
|
|
|
4ec855 |
|
|
|
4ec855 |
static int nested_state_post_load(void *opaque, int version_id)
|
|
|
4ec855 |
@@ -1090,7 +1072,6 @@ static const VMStateDescription vmstate_kvm_nested_state = {
|
|
|
4ec855 |
},
|
|
|
4ec855 |
.subsections = (const VMStateDescription*[]) {
|
|
|
4ec855 |
&vmstate_vmx_nested_state,
|
|
|
4ec855 |
- &vmstate_svm_nested_state,
|
|
|
4ec855 |
NULL
|
|
|
4ec855 |
}
|
|
|
4ec855 |
};
|
|
|
4ec855 |
--
|
|
|
4ec855 |
1.8.3.1
|
|
|
4ec855 |
|