thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone
9ae3a8
From 592237e21bc3527ebc66b8f4c76652cf5cde9438 Mon Sep 17 00:00:00 2001
9ae3a8
From: "plai@redhat.com" <plai@redhat.com>
9ae3a8
Date: Mon, 23 Sep 2019 20:40:19 +0200
9ae3a8
Subject: [PATCH 03/12] target-i386: Isolate KVM-specific code on CPU feature
9ae3a8
 filtering logic
9ae3a8
MIME-Version: 1.0
9ae3a8
Content-Type: text/plain; charset=UTF-8
9ae3a8
Content-Transfer-Encoding: 8bit
9ae3a8
9ae3a8
RH-Author: plai@redhat.com
9ae3a8
Message-id: <1569271227-28026-3-git-send-email-plai@redhat.com>
9ae3a8
Patchwork-id: 90855
9ae3a8
O-Subject: [RHEL7.8 qemu-kvm PATCH v6 02/10] target-i386: Isolate KVM-specific code on CPU feature filtering logic
9ae3a8
Bugzilla: 1709971
9ae3a8
RH-Acked-by: Eduardo Habkost <ehabkost@redhat.com>
9ae3a8
RH-Acked-by: Bandan Das <bsd@redhat.com>
9ae3a8
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
9ae3a8
From: Eduardo Habkost <ehabkost@redhat.com>
9ae3a8
9ae3a8
This will allow us to re-use the feature filtering logic (and the
9ae3a8
check/enforce flag logic) for TCG.
9ae3a8
9ae3a8
Reviewed-by: Richard Henderson <rth@twiddle.net>
9ae3a8
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
9ae3a8
Signed-off-by: Andreas Färber <afaerber@suse.de>
9ae3a8
(cherry picked from commit 27418adf32b9cd164d464fffc4fc0505d6b2b15d)
9ae3a8
Signed-off-by: Paul Lai <plai@redhat.com>
9ae3a8
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
---
9ae3a8
 target-i386/cpu.c | 21 +++++++++++++--------
9ae3a8
 1 file changed, 13 insertions(+), 8 deletions(-)
9ae3a8
9ae3a8
diff --git a/target-i386/cpu.c b/target-i386/cpu.c
9ae3a8
index 6fb805b..ff0921f 100644
9ae3a8
--- a/target-i386/cpu.c
9ae3a8
+++ b/target-i386/cpu.c
9ae3a8
@@ -2387,6 +2387,16 @@ CpuDefinitionInfoList *arch_query_cpu_definitions(Error **errp)
9ae3a8
     return cpu_list;
9ae3a8
 }
9ae3a8
 
9ae3a8
+static uint32_t x86_cpu_get_supported_feature_word(FeatureWord w)
9ae3a8
+{
9ae3a8
+    FeatureWordInfo *wi = &feature_word_info[w];
9ae3a8
+
9ae3a8
+    assert(kvm_enabled());
9ae3a8
+    return kvm_arch_get_supported_cpuid(kvm_state, wi->cpuid_eax,
9ae3a8
+                                                   wi->cpuid_ecx,
9ae3a8
+                                                   wi->cpuid_reg);
9ae3a8
+}
9ae3a8
+
9ae3a8
 /*
9ae3a8
  * Filters CPU feature words based on host availability of each feature.
9ae3a8
  *
9ae3a8
@@ -2394,20 +2404,15 @@ CpuDefinitionInfoList *arch_query_cpu_definitions(Error **errp)
9ae3a8
  *
9ae3a8
  * Returns: 0 if all flags are supported by the host, non-zero otherwise.
9ae3a8
  */
9ae3a8
-static int filter_features_for_kvm(X86CPU *cpu)
9ae3a8
+static int x86_cpu_filter_features(X86CPU *cpu)
9ae3a8
 {
9ae3a8
     CPUX86State *env = &cpu->env;
9ae3a8
-    KVMState *s = kvm_state;
9ae3a8
     FeatureWord w;
9ae3a8
     int rv = 0;
9ae3a8
 
9ae3a8
-    assert(kvm_enabled());
9ae3a8
-
9ae3a8
     for (w = 0; w < FEATURE_WORDS; w++) {
9ae3a8
         FeatureWordInfo *wi = &feature_word_info[w];
9ae3a8
-        uint32_t host_feat = kvm_arch_get_supported_cpuid(s, wi->cpuid_eax,
9ae3a8
-                                                             wi->cpuid_ecx,
9ae3a8
-                                                             wi->cpuid_reg);
9ae3a8
+        uint32_t host_feat = x86_cpu_get_supported_feature_word(w);
9ae3a8
         uint32_t requested_features = env->features[w];
9ae3a8
         env->features[w] &= host_feat;
9ae3a8
         cpu->filtered_features[w] = requested_features & ~env->features[w];
9ae3a8
@@ -3102,7 +3107,7 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)
9ae3a8
             env->features[w] &= feature_word_info[w].tcg_features;
9ae3a8
         }
9ae3a8
     } else {
9ae3a8
-        if (filter_features_for_kvm(cpu) && cpu->enforce_cpuid) {
9ae3a8
+        if (x86_cpu_filter_features(cpu) && cpu->enforce_cpuid) {
9ae3a8
             error_setg(&local_err,
9ae3a8
                        "Host's CPU doesn't support requested features");
9ae3a8
             goto out;
9ae3a8
-- 
9ae3a8
1.8.3.1
9ae3a8