render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
c480ed
From c465e315637d0b2cf01d2957de3d816186e0fd0f Mon Sep 17 00:00:00 2001
c480ed
Message-Id: <c465e315637d0b2cf01d2957de3d816186e0fd0f@dist-git>
c480ed
From: Jiri Denemark <jdenemar@redhat.com>
c480ed
Date: Fri, 21 Jun 2019 09:25:38 +0200
c480ed
Subject: [PATCH] cpu_x86: Store virCPUx86DataItem content in union
c480ed
MIME-Version: 1.0
c480ed
Content-Type: text/plain; charset=UTF-8
c480ed
Content-Transfer-Encoding: 8bit
c480ed
c480ed
The structure can only be used for CPUID data now. Adding a type
c480ed
indicator and moving the data into a union will let us store alternative
c480ed
data types.
c480ed
c480ed
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
c480ed
Reviewed-by: Ján Tomko <jtomko@redhat.com>
c480ed
(cherry picked from commit 370177e2f6784319b2fc86d8fe7a271248a5982e)
c480ed
c480ed
https://bugzilla.redhat.com/show_bug.cgi?id=1697627
c480ed
c480ed
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
c480ed
Message-Id: <00cf7daca0cde66e9a90f64435182ef430983b2e.1561068591.git.jdenemar@redhat.com>
c480ed
Reviewed-by: Ján Tomko <jtomko@redhat.com>
c480ed
---
c480ed
 src/cpu/cpu_x86.c              | 202 ++++++++++++++++++++++++---------
c480ed
 src/cpu/cpu_x86_data.h         |  10 +-
c480ed
 src/libxl/libxl_capabilities.c |   3 +-
c480ed
 src/qemu/qemu_monitor_json.c   |   3 +-
c480ed
 4 files changed, 160 insertions(+), 58 deletions(-)
c480ed
c480ed
diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c
c480ed
index 11c023ac31..e6da974b31 100644
c480ed
--- a/src/cpu/cpu_x86.c
c480ed
+++ b/src/cpu/cpu_x86.c
c480ed
@@ -59,7 +59,9 @@ struct _virCPUx86Feature {
c480ed
 };
c480ed
 
c480ed
 
c480ed
-#define CPUID(...) { .cpuid = {__VA_ARGS__} }
c480ed
+#define CPUID(...) \
c480ed
+    { .type = VIR_CPU_X86_DATA_CPUID, \
c480ed
+      .data = { .cpuid = {__VA_ARGS__} } }
c480ed
 
c480ed
 #define KVM_FEATURE_DEF(Name, Eax_in, Eax) \
c480ed
     static virCPUx86DataItem Name ## _data[] = { \
c480ed
@@ -193,10 +195,22 @@ static bool
c480ed
 virCPUx86DataItemMatch(const virCPUx86DataItem *item1,
c480ed
                        const virCPUx86DataItem *item2)
c480ed
 {
c480ed
-    return (item1->cpuid.eax == item2->cpuid.eax &&
c480ed
-            item1->cpuid.ebx == item2->cpuid.ebx &&
c480ed
-            item1->cpuid.ecx == item2->cpuid.ecx &&
c480ed
-            item1->cpuid.edx == item2->cpuid.edx);
c480ed
+    const virCPUx86CPUID *cpuid1;
c480ed
+    const virCPUx86CPUID *cpuid2;
c480ed
+
c480ed
+    switch (item1->type) {
c480ed
+    case VIR_CPU_X86_DATA_CPUID:
c480ed
+        cpuid1 = &item1->data.cpuid;
c480ed
+        cpuid2 = &item2->data.cpuid;
c480ed
+        return (cpuid1->eax == cpuid2->eax &&
c480ed
+                cpuid1->ebx == cpuid2->ebx &&
c480ed
+                cpuid1->ecx == cpuid2->ecx &&
c480ed
+                cpuid1->edx == cpuid2->edx);
c480ed
+
c480ed
+    case VIR_CPU_X86_DATA_NONE:
c480ed
+    default:
c480ed
+        return false;
c480ed
+    }
c480ed
 }
c480ed
 
c480ed
 
c480ed
@@ -204,10 +218,22 @@ static bool
c480ed
 virCPUx86DataItemMatchMasked(const virCPUx86DataItem *item,
c480ed
                              const virCPUx86DataItem *mask)
c480ed
 {
c480ed
-    return ((item->cpuid.eax & mask->cpuid.eax) == mask->cpuid.eax &&
c480ed
-            (item->cpuid.ebx & mask->cpuid.ebx) == mask->cpuid.ebx &&
c480ed
-            (item->cpuid.ecx & mask->cpuid.ecx) == mask->cpuid.ecx &&
c480ed
-            (item->cpuid.edx & mask->cpuid.edx) == mask->cpuid.edx);
c480ed
+    const virCPUx86CPUID *cpuid;
c480ed
+    const virCPUx86CPUID *cpuidMask;
c480ed
+
c480ed
+    switch (item->type) {
c480ed
+    case VIR_CPU_X86_DATA_CPUID:
c480ed
+        cpuid = &item->data.cpuid;
c480ed
+        cpuidMask = &mask->data.cpuid;
c480ed
+        return ((cpuid->eax & cpuidMask->eax) == cpuidMask->eax &&
c480ed
+                (cpuid->ebx & cpuidMask->ebx) == cpuidMask->ebx &&
c480ed
+                (cpuid->ecx & cpuidMask->ecx) == cpuidMask->ecx &&
c480ed
+                (cpuid->edx & cpuidMask->edx) == cpuidMask->edx);
c480ed
+
c480ed
+    case VIR_CPU_X86_DATA_NONE:
c480ed
+    default:
c480ed
+        return false;
c480ed
+    }
c480ed
 }
c480ed
 
c480ed
 
c480ed
@@ -215,13 +241,26 @@ static void
c480ed
 virCPUx86DataItemSetBits(virCPUx86DataItemPtr item,
c480ed
                          const virCPUx86DataItem *mask)
c480ed
 {
c480ed
+    virCPUx86CPUIDPtr cpuid;
c480ed
+    const virCPUx86CPUID *cpuidMask;
c480ed
+
c480ed
     if (!mask)
c480ed
         return;
c480ed
 
c480ed
-    item->cpuid.eax |= mask->cpuid.eax;
c480ed
-    item->cpuid.ebx |= mask->cpuid.ebx;
c480ed
-    item->cpuid.ecx |= mask->cpuid.ecx;
c480ed
-    item->cpuid.edx |= mask->cpuid.edx;
c480ed
+    switch (item->type) {
c480ed
+    case VIR_CPU_X86_DATA_CPUID:
c480ed
+        cpuid = &item->data.cpuid;
c480ed
+        cpuidMask = &mask->data.cpuid;
c480ed
+        cpuid->eax |= cpuidMask->eax;
c480ed
+        cpuid->ebx |= cpuidMask->ebx;
c480ed
+        cpuid->ecx |= cpuidMask->ecx;
c480ed
+        cpuid->edx |= cpuidMask->edx;
c480ed
+        break;
c480ed
+
c480ed
+    case VIR_CPU_X86_DATA_NONE:
c480ed
+    default:
c480ed
+        break;
c480ed
+    }
c480ed
 }
c480ed
 
c480ed
 
c480ed
@@ -229,13 +268,26 @@ static void
c480ed
 virCPUx86DataItemClearBits(virCPUx86DataItemPtr item,
c480ed
                            const virCPUx86DataItem *mask)
c480ed
 {
c480ed
+    virCPUx86CPUIDPtr cpuid;
c480ed
+    const virCPUx86CPUID *cpuidMask;
c480ed
+
c480ed
     if (!mask)
c480ed
         return;
c480ed
 
c480ed
-    item->cpuid.eax &= ~mask->cpuid.eax;
c480ed
-    item->cpuid.ebx &= ~mask->cpuid.ebx;
c480ed
-    item->cpuid.ecx &= ~mask->cpuid.ecx;
c480ed
-    item->cpuid.edx &= ~mask->cpuid.edx;
c480ed
+    switch (item->type) {
c480ed
+    case VIR_CPU_X86_DATA_CPUID:
c480ed
+        cpuid = &item->data.cpuid;
c480ed
+        cpuidMask = &mask->data.cpuid;
c480ed
+        cpuid->eax &= ~cpuidMask->eax;
c480ed
+        cpuid->ebx &= ~cpuidMask->ebx;
c480ed
+        cpuid->ecx &= ~cpuidMask->ecx;
c480ed
+        cpuid->edx &= ~cpuidMask->edx;
c480ed
+        break;
c480ed
+
c480ed
+    case VIR_CPU_X86_DATA_NONE:
c480ed
+    default:
c480ed
+        break;
c480ed
+    }
c480ed
 }
c480ed
 
c480ed
 
c480ed
@@ -243,13 +295,26 @@ static void
c480ed
 virCPUx86DataItemAndBits(virCPUx86DataItemPtr item,
c480ed
                          const virCPUx86DataItem *mask)
c480ed
 {
c480ed
+    virCPUx86CPUIDPtr cpuid;
c480ed
+    const virCPUx86CPUID *cpuidMask;
c480ed
+
c480ed
     if (!mask)
c480ed
         return;
c480ed
 
c480ed
-    item->cpuid.eax &= mask->cpuid.eax;
c480ed
-    item->cpuid.ebx &= mask->cpuid.ebx;
c480ed
-    item->cpuid.ecx &= mask->cpuid.ecx;
c480ed
-    item->cpuid.edx &= mask->cpuid.edx;
c480ed
+    switch (item->type) {
c480ed
+    case VIR_CPU_X86_DATA_CPUID:
c480ed
+        cpuid = &item->data.cpuid;
c480ed
+        cpuidMask = &mask->data.cpuid;
c480ed
+        cpuid->eax &= cpuidMask->eax;
c480ed
+        cpuid->ebx &= cpuidMask->ebx;
c480ed
+        cpuid->ecx &= cpuidMask->ecx;
c480ed
+        cpuid->edx &= cpuidMask->edx;
c480ed
+        break;
c480ed
+
c480ed
+    case VIR_CPU_X86_DATA_NONE:
c480ed
+    default:
c480ed
+        break;
c480ed
+    }
c480ed
 }
c480ed
 
c480ed
 
c480ed
@@ -289,15 +354,29 @@ virCPUx86DataSorter(const void *a, const void *b)
c480ed
     virCPUx86DataItemPtr da = (virCPUx86DataItemPtr) a;
c480ed
     virCPUx86DataItemPtr db = (virCPUx86DataItemPtr) b;
c480ed
 
c480ed
-    if (da->cpuid.eax_in > db->cpuid.eax_in)
c480ed
+    if (da->type > db->type)
c480ed
         return 1;
c480ed
-    else if (da->cpuid.eax_in < db->cpuid.eax_in)
c480ed
+    else if (da->type < db->type)
c480ed
         return -1;
c480ed
 
c480ed
-    if (da->cpuid.ecx_in > db->cpuid.ecx_in)
c480ed
-        return 1;
c480ed
-    else if (da->cpuid.ecx_in < db->cpuid.ecx_in)
c480ed
-        return -1;
c480ed
+    switch (da->type) {
c480ed
+    case VIR_CPU_X86_DATA_CPUID:
c480ed
+        if (da->data.cpuid.eax_in > db->data.cpuid.eax_in)
c480ed
+            return 1;
c480ed
+        else if (da->data.cpuid.eax_in < db->data.cpuid.eax_in)
c480ed
+            return -1;
c480ed
+
c480ed
+        if (da->data.cpuid.ecx_in > db->data.cpuid.ecx_in)
c480ed
+            return 1;
c480ed
+        else if (da->data.cpuid.ecx_in < db->data.cpuid.ecx_in)
c480ed
+            return -1;
c480ed
+
c480ed
+        break;
c480ed
+
c480ed
+    case VIR_CPU_X86_DATA_NONE:
c480ed
+    default:
c480ed
+        break;
c480ed
+    }
c480ed
 
c480ed
     return 0;
c480ed
 }
c480ed
@@ -526,9 +605,9 @@ x86DataToVendor(const virCPUx86Data *data,
c480ed
 
c480ed
 static int
c480ed
 virCPUx86VendorToData(const char *vendor,
c480ed
-                      virCPUx86DataItemPtr data)
c480ed
+                      virCPUx86DataItemPtr item)
c480ed
 {
c480ed
-    virCPUx86CPUIDPtr cpuid = &data->cpuid;
c480ed
+    virCPUx86CPUIDPtr cpuid;
c480ed
 
c480ed
     if (strlen(vendor) != VENDOR_STRING_LENGTH) {
c480ed
         virReportError(VIR_ERR_INTERNAL_ERROR,
c480ed
@@ -536,6 +615,8 @@ virCPUx86VendorToData(const char *vendor,
c480ed
         return -1;
c480ed
     }
c480ed
 
c480ed
+    item->type = VIR_CPU_X86_DATA_CPUID;
c480ed
+    cpuid = &item->data.cpuid;
c480ed
     cpuid->eax_in = 0;
c480ed
     cpuid->ecx_in = 0;
c480ed
     cpuid->ebx = virReadBufInt32LE(vendor);
c480ed
@@ -611,7 +692,7 @@ x86DataToSignatureFull(const virCPUx86Data *data,
c480ed
     if (!(item = virCPUx86DataGet(data, &leaf1)))
c480ed
         return;
c480ed
 
c480ed
-    cpuid = &item->cpuid;
c480ed
+    cpuid = &item->data.cpuid;
c480ed
     *family = ((cpuid->eax >> 20) & 0xff) + ((cpuid->eax >> 8) & 0xf);
c480ed
     *model = ((cpuid->eax >> 12) & 0xf0) + ((cpuid->eax >> 4) & 0xf);
c480ed
     *stepping = cpuid->eax & 0xf;
c480ed
@@ -630,7 +711,7 @@ x86DataToSignature(const virCPUx86Data *data)
c480ed
     if (!(item = virCPUx86DataGet(data, &leaf1)))
c480ed
         return 0;
c480ed
 
c480ed
-    return item->cpuid.eax & SIGNATURE_MASK;
c480ed
+    return item->data.cpuid.eax & SIGNATURE_MASK;
c480ed
 }
c480ed
 
c480ed
 
c480ed
@@ -885,7 +966,8 @@ x86ParseCPUID(xmlXPathContextPtr ctxt,
c480ed
         ret_eax == -2 || ret_ebx == -2 || ret_ecx == -2 || ret_edx == -2)
c480ed
         return -1;
c480ed
 
c480ed
-    cpuid = &item->cpuid;
c480ed
+    item->type = VIR_CPU_X86_DATA_CPUID;
c480ed
+    cpuid = &item->data.cpuid;
c480ed
     cpuid->eax_in = eax_in;
c480ed
     cpuid->ecx_in = ecx_in;
c480ed
     cpuid->eax = eax;
c480ed
@@ -1461,13 +1543,23 @@ virCPUx86DataFormat(const virCPUData *data)
c480ed
 
c480ed
     virBufferAddLit(&buf, "<cpudata arch='x86'>\n");
c480ed
     while ((item = virCPUx86DataNext(&iter))) {
c480ed
-        virCPUx86CPUIDPtr cpuid = &item->cpuid;
c480ed
-        virBufferAsprintf(&buf,
c480ed
-                          "  
c480ed
-                          " eax='0x%08x' ebx='0x%08x'"
c480ed
-                          " ecx='0x%08x' edx='0x%08x'/>\n",
c480ed
-                          cpuid->eax_in, cpuid->ecx_in,
c480ed
-                          cpuid->eax, cpuid->ebx, cpuid->ecx, cpuid->edx);
c480ed
+        virCPUx86CPUIDPtr cpuid;
c480ed
+
c480ed
+        switch (item->type) {
c480ed
+        case VIR_CPU_X86_DATA_CPUID:
c480ed
+            cpuid = &item->data.cpuid;
c480ed
+            virBufferAsprintf(&buf,
c480ed
+                              "  
c480ed
+                              " eax='0x%08x' ebx='0x%08x'"
c480ed
+                              " ecx='0x%08x' edx='0x%08x'/>\n",
c480ed
+                              cpuid->eax_in, cpuid->ecx_in,
c480ed
+                              cpuid->eax, cpuid->ebx, cpuid->ecx, cpuid->edx);
c480ed
+            break;
c480ed
+
c480ed
+        case VIR_CPU_X86_DATA_NONE:
c480ed
+        default:
c480ed
+            break;
c480ed
+        }
c480ed
     }
c480ed
     virBufferAddLit(&buf, "</cpudata>\n");
c480ed
 
c480ed
@@ -2226,7 +2318,7 @@ cpuidSetLeaf4(virCPUDataPtr data,
c480ed
               virCPUx86DataItemPtr subLeaf0)
c480ed
 {
c480ed
     virCPUx86DataItem item = *subLeaf0;
c480ed
-    virCPUx86CPUIDPtr cpuid = &item.cpuid;
c480ed
+    virCPUx86CPUIDPtr cpuid = &item.data.cpuid;
c480ed
 
c480ed
     if (virCPUx86DataAdd(data, subLeaf0) < 0)
c480ed
         return -1;
c480ed
@@ -2250,13 +2342,13 @@ cpuidSetLeaf7(virCPUDataPtr data,
c480ed
               virCPUx86DataItemPtr subLeaf0)
c480ed
 {
c480ed
     virCPUx86DataItem item = CPUID(.eax_in = 0x7);
c480ed
-    virCPUx86CPUIDPtr cpuid = &item.cpuid;
c480ed
+    virCPUx86CPUIDPtr cpuid = &item.data.cpuid;
c480ed
     uint32_t sub;
c480ed
 
c480ed
     if (virCPUx86DataAdd(data, subLeaf0) < 0)
c480ed
         return -1;
c480ed
 
c480ed
-    for (sub = 1; sub <= subLeaf0->cpuid.eax; sub++) {
c480ed
+    for (sub = 1; sub <= subLeaf0->data.cpuid.eax; sub++) {
c480ed
         cpuid->ecx_in = sub;
c480ed
         cpuidCall(cpuid);
c480ed
         if (virCPUx86DataAdd(data, &item) < 0)
c480ed
@@ -2278,7 +2370,7 @@ cpuidSetLeafB(virCPUDataPtr data,
c480ed
               virCPUx86DataItemPtr subLeaf0)
c480ed
 {
c480ed
     virCPUx86DataItem item = *subLeaf0;
c480ed
-    virCPUx86CPUIDPtr cpuid = &item.cpuid;
c480ed
+    virCPUx86CPUIDPtr cpuid = &item.data.cpuid;
c480ed
 
c480ed
     while (cpuid->ecx & 0xff00) {
c480ed
         if (virCPUx86DataAdd(data, &item) < 0)
c480ed
@@ -2303,7 +2395,7 @@ cpuidSetLeafD(virCPUDataPtr data,
c480ed
               virCPUx86DataItemPtr subLeaf0)
c480ed
 {
c480ed
     virCPUx86DataItem item = CPUID(.eax_in = 0xd);
c480ed
-    virCPUx86CPUIDPtr cpuid = &item.cpuid;
c480ed
+    virCPUx86CPUIDPtr cpuid = &item.data.cpuid;
c480ed
     virCPUx86CPUID sub0;
c480ed
     virCPUx86CPUID sub1;
c480ed
     uint32_t sub;
c480ed
@@ -2316,7 +2408,7 @@ cpuidSetLeafD(virCPUDataPtr data,
c480ed
     if (virCPUx86DataAdd(data, &item) < 0)
c480ed
         return -1;
c480ed
 
c480ed
-    sub0 = subLeaf0->cpuid;
c480ed
+    sub0 = subLeaf0->data.cpuid;
c480ed
     sub1 = *cpuid;
c480ed
     for (sub = 2; sub < 64; sub++) {
c480ed
         if (sub < 32 &&
c480ed
@@ -2351,8 +2443,8 @@ cpuidSetLeafResID(virCPUDataPtr data,
c480ed
                   virCPUx86DataItemPtr subLeaf0,
c480ed
                   uint32_t res)
c480ed
 {
c480ed
-    virCPUx86DataItem item = CPUID(.eax_in = subLeaf0->cpuid.eax_in);
c480ed
-    virCPUx86CPUIDPtr cpuid = &item.cpuid;
c480ed
+    virCPUx86DataItem item = CPUID(.eax_in = subLeaf0->data.cpuid.eax_in);
c480ed
+    virCPUx86CPUIDPtr cpuid = &item.data.cpuid;
c480ed
     uint32_t sub;
c480ed
 
c480ed
     if (virCPUx86DataAdd(data, subLeaf0) < 0)
c480ed
@@ -2380,11 +2472,11 @@ cpuidSetLeaf12(virCPUDataPtr data,
c480ed
                virCPUx86DataItemPtr subLeaf0)
c480ed
 {
c480ed
     virCPUx86DataItem item = CPUID(.eax_in = 0x7);
c480ed
-    virCPUx86CPUIDPtr cpuid = &item.cpuid;
c480ed
+    virCPUx86CPUIDPtr cpuid = &item.data.cpuid;
c480ed
     virCPUx86DataItemPtr leaf7;
c480ed
 
c480ed
     if (!(leaf7 = virCPUx86DataGet(&data->data.x86, &item)) ||
c480ed
-        !(leaf7->cpuid.ebx & (1 << 2)))
c480ed
+        !(leaf7->data.cpuid.ebx & (1 << 2)))
c480ed
         return 0;
c480ed
 
c480ed
     if (virCPUx86DataAdd(data, subLeaf0) < 0)
c480ed
@@ -2417,13 +2509,13 @@ cpuidSetLeaf14(virCPUDataPtr data,
c480ed
                virCPUx86DataItemPtr subLeaf0)
c480ed
 {
c480ed
     virCPUx86DataItem item = CPUID(.eax_in = 0x14);
c480ed
-    virCPUx86CPUIDPtr cpuid = &item.cpuid;
c480ed
+    virCPUx86CPUIDPtr cpuid = &item.data.cpuid;
c480ed
     uint32_t sub;
c480ed
 
c480ed
     if (virCPUx86DataAdd(data, subLeaf0) < 0)
c480ed
         return -1;
c480ed
 
c480ed
-    for (sub = 1; sub <= subLeaf0->cpuid.eax; sub++) {
c480ed
+    for (sub = 1; sub <= subLeaf0->data.cpuid.eax; sub++) {
c480ed
         cpuid->ecx_in = sub;
c480ed
         cpuidCall(cpuid);
c480ed
         if (virCPUx86DataAdd(data, &item) < 0)
c480ed
@@ -2443,16 +2535,16 @@ cpuidSetLeaf17(virCPUDataPtr data,
c480ed
                virCPUx86DataItemPtr subLeaf0)
c480ed
 {
c480ed
     virCPUx86DataItem item = CPUID(.eax_in = 0x17);
c480ed
-    virCPUx86CPUIDPtr cpuid = &item.cpuid;
c480ed
+    virCPUx86CPUIDPtr cpuid = &item.data.cpuid;
c480ed
     uint32_t sub;
c480ed
 
c480ed
-    if (subLeaf0->cpuid.eax < 3)
c480ed
+    if (subLeaf0->data.cpuid.eax < 3)
c480ed
         return 0;
c480ed
 
c480ed
     if (virCPUx86DataAdd(data, subLeaf0) < 0)
c480ed
         return -1;
c480ed
 
c480ed
-    for (sub = 1; sub <= subLeaf0->cpuid.eax; sub++) {
c480ed
+    for (sub = 1; sub <= subLeaf0->data.cpuid.eax; sub++) {
c480ed
         cpuid->ecx_in = sub;
c480ed
         cpuidCall(cpuid);
c480ed
         if (virCPUx86DataAdd(data, &item) < 0)
c480ed
@@ -2469,7 +2561,7 @@ cpuidSet(uint32_t base, virCPUDataPtr data)
c480ed
     uint32_t max;
c480ed
     uint32_t leaf;
c480ed
     virCPUx86DataItem item = CPUID(.eax_in = base);
c480ed
-    virCPUx86CPUIDPtr cpuid = &item.cpuid;
c480ed
+    virCPUx86CPUIDPtr cpuid = &item.data.cpuid;
c480ed
 
c480ed
     cpuidCall(cpuid);
c480ed
     max = cpuid->eax;
c480ed
diff --git a/src/cpu/cpu_x86_data.h b/src/cpu/cpu_x86_data.h
c480ed
index e93b355cf0..da8e91fe71 100644
c480ed
--- a/src/cpu/cpu_x86_data.h
c480ed
+++ b/src/cpu/cpu_x86_data.h
c480ed
@@ -71,10 +71,18 @@ struct _virCPUx86CPUID {
c480ed
 
c480ed
 # define VIR_CPU_X86_DATA_INIT { 0 }
c480ed
 
c480ed
+typedef enum {
c480ed
+    VIR_CPU_X86_DATA_NONE = 0,
c480ed
+    VIR_CPU_X86_DATA_CPUID,
c480ed
+} virCPUx86DataType;
c480ed
+
c480ed
 typedef struct _virCPUx86DataItem virCPUx86DataItem;
c480ed
 typedef virCPUx86DataItem *virCPUx86DataItemPtr;
c480ed
 struct _virCPUx86DataItem {
c480ed
-    virCPUx86CPUID cpuid;
c480ed
+    virCPUx86DataType type;
c480ed
+    union {
c480ed
+        virCPUx86CPUID cpuid;
c480ed
+    } data;
c480ed
 };
c480ed
 
c480ed
 typedef struct _virCPUx86Data virCPUx86Data;
c480ed
diff --git a/src/libxl/libxl_capabilities.c b/src/libxl/libxl_capabilities.c
c480ed
index 2b351fbdde..6630aa2c0b 100644
c480ed
--- a/src/libxl/libxl_capabilities.c
c480ed
+++ b/src/libxl/libxl_capabilities.c
c480ed
@@ -70,8 +70,9 @@ libxlCapsAddCPUID(virCPUDataPtr data, virCPUx86CPUID *cpuid, ssize_t ncaps)
c480ed
     virCPUx86DataItem item = { 0 };
c480ed
     size_t i;
c480ed
 
c480ed
+    item.type = VIR_CPU_X86_DATA_CPUID;
c480ed
     for (i = 0; i < ncaps; i++) {
c480ed
-        item.cpuid = cpuid[i];
c480ed
+        item.data.cpuid = cpuid[i];
c480ed
 
c480ed
         if (virCPUx86DataAdd(data, &item) < 0) {
c480ed
             VIR_DEBUG("Failed to add CPUID(%x,%x)",
c480ed
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
c480ed
index abfaa6e68a..e6ac82e96b 100644
c480ed
--- a/src/qemu/qemu_monitor_json.c
c480ed
+++ b/src/qemu/qemu_monitor_json.c
c480ed
@@ -7049,9 +7049,10 @@ qemuMonitorJSONParseCPUx86Features(virJSONValuePtr data)
c480ed
     if (!(cpudata = virCPUDataNew(VIR_ARCH_X86_64)))
c480ed
         goto error;
c480ed
 
c480ed
+    item.type = VIR_CPU_X86_DATA_CPUID;
c480ed
     for (i = 0; i < virJSONValueArraySize(data); i++) {
c480ed
         if (qemuMonitorJSONParseCPUx86FeatureWord(virJSONValueArrayGet(data, i),
c480ed
-                                                  &item.cpuid) < 0 ||
c480ed
+                                                  &item.data.cpuid) < 0 ||
c480ed
             virCPUx86DataAdd(cpudata, &item) < 0)
c480ed
             goto error;
c480ed
     }
c480ed
-- 
c480ed
2.22.0
c480ed