Blame SOURCES/libvirt-cpu-x86-Add-internal-CPUID-features-support-and-KVM-feature-bits.patch

43fe83
From 45c1fda7075b723a1bf292b9bbcb0b27cab9e72c Mon Sep 17 00:00:00 2001
43fe83
Message-Id: <45c1fda7075b723a1bf292b9bbcb0b27cab9e72c.1383922566.git.jdenemar@redhat.com>
43fe83
From: Peter Krempa <pkrempa@redhat.com>
43fe83
Date: Fri, 8 Nov 2013 12:33:32 +0100
43fe83
Subject: [PATCH] cpu: x86: Add internal CPUID features support and KVM feature
43fe83
 bits
43fe83
43fe83
https://bugzilla.redhat.com/show_bug.cgi?id=1008989
43fe83
43fe83
Some of the emulator features are presented in the <features> element in
43fe83
the domain XML although they are virtual CPUID feature bits when
43fe83
presented to the guest. To avoid confusing the users with these
43fe83
features, as they are not configurable via the <cpu> element, this patch
43fe83
adds an internal array where those can be stored privately instead of
43fe83
exposing them in the XML.
43fe83
43fe83
Additionaly KVM feature bits are added as example usage of this code.
43fe83
43fe83
(cherry picked from commit 2e8f90802ddc5405121ba1b92f47b885867a325a)
43fe83
43fe83
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
43fe83
---
43fe83
 src/cpu/cpu_x86.c      | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++
43fe83
 src/cpu/cpu_x86_data.h | 12 ++++++++++
43fe83
 2 files changed, 76 insertions(+)
43fe83
43fe83
diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c
43fe83
index 3bdb3c3..7bd8acb 100644
43fe83
--- a/src/cpu/cpu_x86.c
43fe83
+++ b/src/cpu/cpu_x86.c
43fe83
@@ -56,6 +56,25 @@ struct x86_feature {
43fe83
     struct x86_feature *next;
43fe83
 };
43fe83
 
43fe83
+struct x86_kvm_feature {
43fe83
+    const char *name;
43fe83
+    const virCPUx86CPUID cpuid;
43fe83
+};
43fe83
+
43fe83
+static const struct x86_kvm_feature x86_kvm_features[] =
43fe83
+{
43fe83
+    {VIR_CPU_x86_KVM_CLOCKSOURCE,  { .function = 0x40000001, .eax = 0x00000001 }},
43fe83
+    {VIR_CPU_x86_KVM_NOP_IO_DELAY, { .function = 0x40000001, .eax = 0x00000002 }},
43fe83
+    {VIR_CPU_x86_KVM_MMU_OP,       { .function = 0x40000001, .eax = 0x00000004 }},
43fe83
+    {VIR_CPU_x86_KVM_CLOCKSOURCE2, { .function = 0x40000001, .eax = 0x00000008 }},
43fe83
+    {VIR_CPU_x86_KVM_ASYNC_PF,     { .function = 0x40000001, .eax = 0x00000010 }},
43fe83
+    {VIR_CPU_x86_KVM_STEAL_TIME,   { .function = 0x40000001, .eax = 0x00000020 }},
43fe83
+    {VIR_CPU_x86_KVM_PV_EOI,       { .function = 0x40000001, .eax = 0x00000040 }},
43fe83
+    {VIR_CPU_x86_KVM_PV_UNHALT,    { .function = 0x40000001, .eax = 0x00000080 }},
43fe83
+    {VIR_CPU_x86_KVM_CLOCKSOURCE_STABLE_BIT,
43fe83
+                                   { .function = 0x40000001, .eax = 0x01000000 }},
43fe83
+};
43fe83
+
43fe83
 struct x86_model {
43fe83
     char *name;
43fe83
     const struct x86_vendor *vendor;
43fe83
@@ -1068,6 +1087,48 @@ x86MapLoadCallback(enum cpuMapElement element,
43fe83
 }
43fe83
 
43fe83
 
43fe83
+static int
43fe83
+x86MapLoadInternalFeatures(struct x86_map *map)
43fe83
+{
43fe83
+    size_t i;
43fe83
+    struct x86_feature *feature = NULL;
43fe83
+
43fe83
+    for (i = 0; i < ARRAY_CARDINALITY(x86_kvm_features); i++) {
43fe83
+        const char *name = x86_kvm_features[i].name;
43fe83
+
43fe83
+        if (x86FeatureFind(map, name)) {
43fe83
+            virReportError(VIR_ERR_INTERNAL_ERROR,
43fe83
+                           _("CPU feature %s already defined"), name);
43fe83
+            return -1;
43fe83
+        }
43fe83
+
43fe83
+        if (!(feature = x86FeatureNew()))
43fe83
+            goto error;
43fe83
+
43fe83
+        if (VIR_STRDUP(feature->name, name) < 0)
43fe83
+            goto error;
43fe83
+
43fe83
+        if (virCPUx86DataAddCPUID(feature->data, &x86_kvm_features[i].cpuid))
43fe83
+            goto error;
43fe83
+
43fe83
+        if (map->features == NULL) {
43fe83
+            map->features = feature;
43fe83
+        } else {
43fe83
+            feature->next = map->features;
43fe83
+            map->features = feature;
43fe83
+        }
43fe83
+
43fe83
+        feature = NULL;
43fe83
+    }
43fe83
+
43fe83
+    return 0;
43fe83
+
43fe83
+error:
43fe83
+    x86FeatureFree(feature);
43fe83
+    return -1;
43fe83
+}
43fe83
+
43fe83
+
43fe83
 static struct x86_map *
43fe83
 virCPUx86LoadMap(void)
43fe83
 {
43fe83
@@ -1079,6 +1140,9 @@ virCPUx86LoadMap(void)
43fe83
     if (cpuMapLoad("x86", x86MapLoadCallback, map) < 0)
43fe83
         goto error;
43fe83
 
43fe83
+    if (x86MapLoadInternalFeatures(map) < 0)
43fe83
+        goto error;
43fe83
+
43fe83
     return map;
43fe83
 
43fe83
 error:
43fe83
diff --git a/src/cpu/cpu_x86_data.h b/src/cpu/cpu_x86_data.h
43fe83
index 69066f1..88dccf6 100644
43fe83
--- a/src/cpu/cpu_x86_data.h
43fe83
+++ b/src/cpu/cpu_x86_data.h
43fe83
@@ -36,8 +36,20 @@ struct _virCPUx86CPUID {
43fe83
 };
43fe83
 
43fe83
 # define CPUX86_BASIC    0x0
43fe83
+# define CPUX86_KVM      0x40000000
43fe83
 # define CPUX86_EXTENDED 0x80000000
43fe83
 
43fe83
+# define VIR_CPU_x86_KVM_CLOCKSOURCE  "__kvm_clocksource"
43fe83
+# define VIR_CPU_x86_KVM_NOP_IO_DELAY "__kvm_no_io_delay"
43fe83
+# define VIR_CPU_x86_KVM_MMU_OP       "__kvm_mmu_op"
43fe83
+# define VIR_CPU_x86_KVM_CLOCKSOURCE2 "__kvm_clocksource2"
43fe83
+# define VIR_CPU_x86_KVM_ASYNC_PF     "__kvm_async_pf"
43fe83
+# define VIR_CPU_x86_KVM_STEAL_TIME   "__kvm_steal_time"
43fe83
+# define VIR_CPU_x86_KVM_PV_EOI       "__kvm_pv_eoi"
43fe83
+# define VIR_CPU_x86_KVM_PV_UNHALT    "__kvm_pv_unhalt"
43fe83
+# define VIR_CPU_x86_KVM_CLOCKSOURCE_STABLE_BIT "__kvm_clocksource_stable"
43fe83
+
43fe83
+
43fe83
 typedef struct _virCPUx86Data virCPUx86Data;
43fe83
 struct _virCPUx86Data {
43fe83
     size_t len;
43fe83
-- 
43fe83
1.8.4.2
43fe83