yeahuh / 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

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