cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-target-i386-skip-KVM_GET-SET_NESTED_STATE-if-VMX-dis.patch

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