Blame SOURCES/kvm-target-i386-kvm-Block-migration-for-vCPUs-exposed-wi.patch

Pablo Greco e6a3ae
From 0d5048785d6edd2fee3b22aa6901e55539e07525 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:11 +0100
Pablo Greco e6a3ae
Subject: [PATCH 30/39] target/i386: kvm: Block migration for vCPUs exposed
Pablo Greco e6a3ae
 with nested virtualization
Pablo Greco e6a3ae
Pablo Greco e6a3ae
RH-Author: Paolo Bonzini <pbonzini@redhat.com>
Pablo Greco e6a3ae
Message-id: <20190722182220.19374-10-pbonzini@redhat.com>
Pablo Greco e6a3ae
Patchwork-id: 89633
Pablo Greco e6a3ae
O-Subject: [RHEL-8.1.0 PATCH qemu-kvm v3 09/18] target/i386: kvm: Block migration for vCPUs exposed with nested virtualization
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
From: Liran Alon <liran.alon@oracle.com>
Pablo Greco e6a3ae
Pablo Greco e6a3ae
Commit d98f26073beb ("target/i386: kvm: add VMX migration blocker")
Pablo Greco e6a3ae
added a migration blocker for vCPU exposed with Intel VMX.
Pablo Greco e6a3ae
However, migration should also be blocked for vCPU exposed with
Pablo Greco e6a3ae
AMD SVM.
Pablo Greco e6a3ae
Pablo Greco e6a3ae
Both cases should be blocked because QEMU should extract additional
Pablo Greco e6a3ae
vCPU state from KVM that should be migrated as part of vCPU VMState.
Pablo Greco e6a3ae
E.g. Whether vCPU is running in guest-mode or host-mode.
Pablo Greco e6a3ae
Pablo Greco e6a3ae
Fixes: d98f26073beb ("target/i386: kvm: add VMX migration blocker")
Pablo Greco e6a3ae
Reviewed-by: Maran Wilson <maran.wilson@oracle.com>
Pablo Greco e6a3ae
Signed-off-by: Liran Alon <liran.alon@oracle.com>
Pablo Greco e6a3ae
Message-Id: <20190619162140.133674-6-liran.alon@oracle.com>
Pablo Greco e6a3ae
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Pablo Greco e6a3ae
(cherry picked from commit 18ab37ba1cee290923240744288dbee8be9355fb)
Pablo Greco e6a3ae
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
Pablo Greco e6a3ae
---
Pablo Greco e6a3ae
 target/i386/cpu.c |  6 ------
Pablo Greco e6a3ae
 target/i386/cpu.h | 12 ++++++++++++
Pablo Greco e6a3ae
 target/i386/kvm.c | 14 +++++++-------
Pablo Greco e6a3ae
 3 files changed, 19 insertions(+), 13 deletions(-)
Pablo Greco e6a3ae
Pablo Greco e6a3ae
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
Pablo Greco e6a3ae
index af62281..bd0b784 100644
Pablo Greco e6a3ae
--- a/target/i386/cpu.c
Pablo Greco e6a3ae
+++ b/target/i386/cpu.c
Pablo Greco e6a3ae
@@ -5034,12 +5034,6 @@ static int x86_cpu_filter_features(X86CPU *cpu)
Pablo Greco e6a3ae
     return rv;
Pablo Greco e6a3ae
 }
Pablo Greco e6a3ae
 
Pablo Greco e6a3ae
-#define IS_INTEL_CPU(env) ((env)->cpuid_vendor1 == CPUID_VENDOR_INTEL_1 && \
Pablo Greco e6a3ae
-                           (env)->cpuid_vendor2 == CPUID_VENDOR_INTEL_2 && \
Pablo Greco e6a3ae
-                           (env)->cpuid_vendor3 == CPUID_VENDOR_INTEL_3)
Pablo Greco e6a3ae
-#define IS_AMD_CPU(env) ((env)->cpuid_vendor1 == CPUID_VENDOR_AMD_1 && \
Pablo Greco e6a3ae
-                         (env)->cpuid_vendor2 == CPUID_VENDOR_AMD_2 && \
Pablo Greco e6a3ae
-                         (env)->cpuid_vendor3 == CPUID_VENDOR_AMD_3)
Pablo Greco e6a3ae
 static void x86_cpu_realizefn(DeviceState *dev, Error **errp)
Pablo Greco e6a3ae
 {
Pablo Greco e6a3ae
     CPUState *cs = CPU(dev);
Pablo Greco e6a3ae
diff --git a/target/i386/cpu.h b/target/i386/cpu.h
Pablo Greco e6a3ae
index 923dfcd..f595fc3 100644
Pablo Greco e6a3ae
--- a/target/i386/cpu.h
Pablo Greco e6a3ae
+++ b/target/i386/cpu.h
Pablo Greco e6a3ae
@@ -722,6 +722,13 @@ typedef uint32_t FeatureWordArray[FEATURE_WORDS];
Pablo Greco e6a3ae
 
Pablo Greco e6a3ae
 #define CPUID_VENDOR_VIA   "CentaurHauls"
Pablo Greco e6a3ae
 
Pablo Greco e6a3ae
+#define IS_INTEL_CPU(env) ((env)->cpuid_vendor1 == CPUID_VENDOR_INTEL_1 && \
Pablo Greco e6a3ae
+                           (env)->cpuid_vendor2 == CPUID_VENDOR_INTEL_2 && \
Pablo Greco e6a3ae
+                           (env)->cpuid_vendor3 == CPUID_VENDOR_INTEL_3)
Pablo Greco e6a3ae
+#define IS_AMD_CPU(env) ((env)->cpuid_vendor1 == CPUID_VENDOR_AMD_1 && \
Pablo Greco e6a3ae
+                         (env)->cpuid_vendor2 == CPUID_VENDOR_AMD_2 && \
Pablo Greco e6a3ae
+                         (env)->cpuid_vendor3 == CPUID_VENDOR_AMD_3)
Pablo Greco e6a3ae
+
Pablo Greco e6a3ae
 #define CPUID_MWAIT_IBE     (1U << 1) /* Interrupts can exit capability */
Pablo Greco e6a3ae
 #define CPUID_MWAIT_EMX     (1U << 0) /* enumeration supported */
Pablo Greco e6a3ae
 
Pablo Greco e6a3ae
@@ -1829,6 +1836,11 @@ static inline int32_t x86_get_a20_mask(CPUX86State *env)
Pablo Greco e6a3ae
     }
Pablo Greco e6a3ae
 }
Pablo Greco e6a3ae
 
Pablo Greco e6a3ae
+static inline bool cpu_has_vmx(CPUX86State *env)
Pablo Greco e6a3ae
+{
Pablo Greco e6a3ae
+    return env->features[FEAT_1_ECX] & CPUID_EXT_VMX;
Pablo Greco e6a3ae
+}
Pablo Greco e6a3ae
+
Pablo Greco e6a3ae
 /* fpu_helper.c */
Pablo Greco e6a3ae
 void update_fp_status(CPUX86State *env);
Pablo Greco e6a3ae
 void update_mxcsr_status(CPUX86State *env);
Pablo Greco e6a3ae
diff --git a/target/i386/kvm.c b/target/i386/kvm.c
Pablo Greco e6a3ae
index 1a4ff3c..f741e8b 100644
Pablo Greco e6a3ae
--- a/target/i386/kvm.c
Pablo Greco e6a3ae
+++ b/target/i386/kvm.c
Pablo Greco e6a3ae
@@ -772,7 +772,7 @@ static int hyperv_handle_properties(CPUState *cs)
Pablo Greco e6a3ae
 }
Pablo Greco e6a3ae
 
Pablo Greco e6a3ae
 static Error *invtsc_mig_blocker;
Pablo Greco e6a3ae
-static Error *vmx_mig_blocker;
Pablo Greco e6a3ae
+static Error *nested_virt_mig_blocker;
Pablo Greco e6a3ae
 
Pablo Greco e6a3ae
 #define KVM_MAX_CPUID_ENTRIES  100
Pablo Greco e6a3ae
 
Pablo Greco e6a3ae
@@ -1116,13 +1116,13 @@ int kvm_arch_init_vcpu(CPUState *cs)
Pablo Greco e6a3ae
                                   !!(c->ecx & CPUID_EXT_SMX);
Pablo Greco e6a3ae
     }
Pablo Greco e6a3ae
 
Pablo Greco e6a3ae
-    if ((env->features[FEAT_1_ECX] & CPUID_EXT_VMX) && !vmx_mig_blocker) {
Pablo Greco e6a3ae
-        error_setg(&vmx_mig_blocker,
Pablo Greco e6a3ae
-                   "Nested VMX virtualization does not support live migration yet");
Pablo Greco e6a3ae
-        r = migrate_add_blocker(vmx_mig_blocker, &local_err);
Pablo Greco e6a3ae
+    if (cpu_has_vmx(env) && !nested_virt_mig_blocker) {
Pablo Greco e6a3ae
+        error_setg(&nested_virt_mig_blocker,
Pablo Greco e6a3ae
+                   "Nested virtualization does not support live migration yet");
Pablo Greco e6a3ae
+        r = migrate_add_blocker(nested_virt_mig_blocker, &local_err);
Pablo Greco e6a3ae
         if (local_err) {
Pablo Greco e6a3ae
             error_report_err(local_err);
Pablo Greco e6a3ae
-            error_free(vmx_mig_blocker);
Pablo Greco e6a3ae
+            error_free(nested_virt_mig_blocker);
Pablo Greco e6a3ae
             return r;
Pablo Greco e6a3ae
         }
Pablo Greco e6a3ae
     }
Pablo Greco e6a3ae
@@ -1191,7 +1191,7 @@ int kvm_arch_init_vcpu(CPUState *cs)
Pablo Greco e6a3ae
  fail:
Pablo Greco e6a3ae
     migrate_del_blocker(invtsc_mig_blocker);
Pablo Greco e6a3ae
  fail2:
Pablo Greco e6a3ae
-    migrate_del_blocker(vmx_mig_blocker);
Pablo Greco e6a3ae
+    migrate_del_blocker(nested_virt_mig_blocker);
Pablo Greco e6a3ae
 
Pablo Greco e6a3ae
     return r;
Pablo Greco e6a3ae
 }
Pablo Greco e6a3ae
-- 
Pablo Greco e6a3ae
1.8.3.1
Pablo Greco e6a3ae