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

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