yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

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

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