Blame SOURCES/kvm-x86-Data-structure-changes-to-support-MSR-based-feat.patch

Pablo Greco e6a3ae
From 1f97a7e017e09c60ca5b81062308cb951c5972a1 Mon Sep 17 00:00:00 2001
Pablo Greco e6a3ae
From: "plai@redhat.com" <plai@redhat.com>
Pablo Greco e6a3ae
Date: Wed, 3 Apr 2019 15:54:31 +0100
Pablo Greco e6a3ae
Subject: [PATCH 07/10] x86: Data structure changes to support MSR based
Pablo Greco e6a3ae
 features
Pablo Greco e6a3ae
Pablo Greco e6a3ae
RH-Author: plai@redhat.com
Pablo Greco e6a3ae
Message-id: <1554306874-28796-8-git-send-email-plai@redhat.com>
Pablo Greco e6a3ae
Patchwork-id: 85389
Pablo Greco e6a3ae
O-Subject: [RHEL8.1 qemu-kvm PATCH resend 07/10] x86: Data structure changes to support MSR based features
Pablo Greco e6a3ae
Bugzilla: 1561761
Pablo Greco e6a3ae
RH-Acked-by: Eduardo Habkost <ehabkost@redhat.com>
Pablo Greco e6a3ae
RH-Acked-by: Igor Mammedov <imammedo@redhat.com>
Pablo Greco e6a3ae
RH-Acked-by: Michael S. Tsirkin <mst@redhat.com>
Pablo Greco e6a3ae
Pablo Greco e6a3ae
From: Robert Hoo <robert.hu@linux.intel.com>
Pablo Greco e6a3ae
Pablo Greco e6a3ae
Add FeatureWordType indicator in struct FeatureWordInfo.
Pablo Greco e6a3ae
Change feature_word_info[] accordingly.
Pablo Greco e6a3ae
Change existing functions that refer to feature_word_info[] accordingly.
Pablo Greco e6a3ae
Pablo Greco e6a3ae
Signed-off-by: Robert Hoo <robert.hu@linux.intel.com>
Pablo Greco e6a3ae
Message-Id: <1539578845-37944-3-git-send-email-robert.hu@linux.intel.com>
Pablo Greco e6a3ae
[ehabkost: fixed hvf_enabled() case]
Pablo Greco e6a3ae
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Pablo Greco e6a3ae
Pablo Greco e6a3ae
(cherry picked from commit 07585923485952bf4cb7da563c9f91fecc85d09c)
Pablo Greco e6a3ae
Signed-off-by: Paul Lai <plai@redhat.com>
Pablo Greco e6a3ae
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
Pablo Greco e6a3ae
---
Pablo Greco e6a3ae
 target/i386/cpu.c | 197 +++++++++++++++++++++++++++++++++++++++---------------
Pablo Greco e6a3ae
 1 file changed, 142 insertions(+), 55 deletions(-)
Pablo Greco e6a3ae
Pablo Greco e6a3ae
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
Pablo Greco e6a3ae
index d86b744..a0fdd3a 100644
Pablo Greco e6a3ae
--- a/target/i386/cpu.c
Pablo Greco e6a3ae
+++ b/target/i386/cpu.c
Pablo Greco e6a3ae
@@ -773,17 +773,36 @@ static void x86_cpu_vendor_words2str(char *dst, uint32_t vendor1,
Pablo Greco e6a3ae
           /* missing:
Pablo Greco e6a3ae
           CPUID_XSAVE_XSAVEC, CPUID_XSAVE_XSAVES */
Pablo Greco e6a3ae
 
Pablo Greco e6a3ae
+typedef enum FeatureWordType {
Pablo Greco e6a3ae
+   CPUID_FEATURE_WORD,
Pablo Greco e6a3ae
+   MSR_FEATURE_WORD,
Pablo Greco e6a3ae
+} FeatureWordType;
Pablo Greco e6a3ae
+
Pablo Greco e6a3ae
 typedef struct FeatureWordInfo {
Pablo Greco e6a3ae
+    FeatureWordType type;
Pablo Greco e6a3ae
     /* feature flags names are taken from "Intel Processor Identification and
Pablo Greco e6a3ae
      * the CPUID Instruction" and AMD's "CPUID Specification".
Pablo Greco e6a3ae
      * In cases of disagreement between feature naming conventions,
Pablo Greco e6a3ae
      * aliases may be added.
Pablo Greco e6a3ae
      */
Pablo Greco e6a3ae
     const char *feat_names[32];
Pablo Greco e6a3ae
-    uint32_t cpuid_eax;   /* Input EAX for CPUID */
Pablo Greco e6a3ae
-    bool cpuid_needs_ecx; /* CPUID instruction uses ECX as input */
Pablo Greco e6a3ae
-    uint32_t cpuid_ecx;   /* Input ECX value for CPUID */
Pablo Greco e6a3ae
-    int cpuid_reg;        /* output register (R_* constant) */
Pablo Greco e6a3ae
+    union {
Pablo Greco e6a3ae
+        /* If type==CPUID_FEATURE_WORD */
Pablo Greco e6a3ae
+        struct {
Pablo Greco e6a3ae
+            uint32_t eax;   /* Input EAX for CPUID */
Pablo Greco e6a3ae
+            bool needs_ecx; /* CPUID instruction uses ECX as input */
Pablo Greco e6a3ae
+            uint32_t ecx;   /* Input ECX value for CPUID */
Pablo Greco e6a3ae
+            int reg;        /* output register (R_* constant) */
Pablo Greco e6a3ae
+        } cpuid;
Pablo Greco e6a3ae
+        /* If type==MSR_FEATURE_WORD */
Pablo Greco e6a3ae
+        struct {
Pablo Greco e6a3ae
+            uint32_t index;
Pablo Greco e6a3ae
+            struct {   /*CPUID that enumerate this MSR*/
Pablo Greco e6a3ae
+                FeatureWord cpuid_class;
Pablo Greco e6a3ae
+                uint32_t    cpuid_flag;
Pablo Greco e6a3ae
+            } cpuid_dep;
Pablo Greco e6a3ae
+        } msr;
Pablo Greco e6a3ae
+    };
Pablo Greco e6a3ae
     uint32_t tcg_features; /* Feature flags supported by TCG */
Pablo Greco e6a3ae
     uint32_t unmigratable_flags; /* Feature flags known to be unmigratable */
Pablo Greco e6a3ae
     uint32_t migratable_flags; /* Feature flags known to be migratable */
Pablo Greco e6a3ae
@@ -793,6 +812,7 @@ typedef struct FeatureWordInfo {
Pablo Greco e6a3ae
 
Pablo Greco e6a3ae
 static FeatureWordInfo feature_word_info[FEATURE_WORDS] = {
Pablo Greco e6a3ae
     [FEAT_1_EDX] = {
Pablo Greco e6a3ae
+        .type = CPUID_FEATURE_WORD,
Pablo Greco e6a3ae
         .feat_names = {
Pablo Greco e6a3ae
             "fpu", "vme", "de", "pse",
Pablo Greco e6a3ae
             "tsc", "msr", "pae", "mce",
Pablo Greco e6a3ae
@@ -803,10 +823,11 @@ static FeatureWordInfo feature_word_info[FEATURE_WORDS] = {
Pablo Greco e6a3ae
             "fxsr", "sse", "sse2", "ss",
Pablo Greco e6a3ae
             "ht" /* Intel htt */, "tm", "ia64", "pbe",
Pablo Greco e6a3ae
         },
Pablo Greco e6a3ae
-        .cpuid_eax = 1, .cpuid_reg = R_EDX,
Pablo Greco e6a3ae
+        .cpuid = {.eax = 1, .reg = R_EDX, },
Pablo Greco e6a3ae
         .tcg_features = TCG_FEATURES,
Pablo Greco e6a3ae
     },
Pablo Greco e6a3ae
     [FEAT_1_ECX] = {
Pablo Greco e6a3ae
+        .type = CPUID_FEATURE_WORD,
Pablo Greco e6a3ae
         .feat_names = {
Pablo Greco e6a3ae
             "pni" /* Intel,AMD sse3 */, "pclmulqdq", "dtes64", "monitor",
Pablo Greco e6a3ae
             "ds-cpl", "vmx", "smx", "est",
Pablo Greco e6a3ae
@@ -817,7 +838,7 @@ static FeatureWordInfo feature_word_info[FEATURE_WORDS] = {
Pablo Greco e6a3ae
             "tsc-deadline", "aes", "xsave", "osxsave",
Pablo Greco e6a3ae
             "avx", "f16c", "rdrand", "hypervisor",
Pablo Greco e6a3ae
         },
Pablo Greco e6a3ae
-        .cpuid_eax = 1, .cpuid_reg = R_ECX,
Pablo Greco e6a3ae
+        .cpuid = { .eax = 1, .reg = R_ECX, },
Pablo Greco e6a3ae
         .tcg_features = TCG_EXT_FEATURES,
Pablo Greco e6a3ae
     },
Pablo Greco e6a3ae
     /* Feature names that are already defined on feature_name[] but
Pablo Greco e6a3ae
@@ -826,6 +847,7 @@ static FeatureWordInfo feature_word_info[FEATURE_WORDS] = {
Pablo Greco e6a3ae
      * to features[FEAT_8000_0001_EDX] if and only if CPU vendor is AMD.
Pablo Greco e6a3ae
      */
Pablo Greco e6a3ae
     [FEAT_8000_0001_EDX] = {
Pablo Greco e6a3ae
+        .type = CPUID_FEATURE_WORD,
Pablo Greco e6a3ae
         .feat_names = {
Pablo Greco e6a3ae
             NULL /* fpu */, NULL /* vme */, NULL /* de */, NULL /* pse */,
Pablo Greco e6a3ae
             NULL /* tsc */, NULL /* msr */, NULL /* pae */, NULL /* mce */,
Pablo Greco e6a3ae
@@ -836,10 +858,11 @@ static FeatureWordInfo feature_word_info[FEATURE_WORDS] = {
Pablo Greco e6a3ae
             NULL /* fxsr */, "fxsr-opt", "pdpe1gb", "rdtscp",
Pablo Greco e6a3ae
             NULL, "lm", "3dnowext", "3dnow",
Pablo Greco e6a3ae
         },
Pablo Greco e6a3ae
-        .cpuid_eax = 0x80000001, .cpuid_reg = R_EDX,
Pablo Greco e6a3ae
+        .cpuid = { .eax = 0x80000001, .reg = R_EDX, },
Pablo Greco e6a3ae
         .tcg_features = TCG_EXT2_FEATURES,
Pablo Greco e6a3ae
     },
Pablo Greco e6a3ae
     [FEAT_8000_0001_ECX] = {
Pablo Greco e6a3ae
+        .type = CPUID_FEATURE_WORD,
Pablo Greco e6a3ae
         .feat_names = {
Pablo Greco e6a3ae
             "lahf-lm", "cmp-legacy", "svm", "extapic",
Pablo Greco e6a3ae
             "cr8legacy", "abm", "sse4a", "misalignsse",
Pablo Greco e6a3ae
@@ -850,7 +873,7 @@ static FeatureWordInfo feature_word_info[FEATURE_WORDS] = {
Pablo Greco e6a3ae
             "perfctr-nb", NULL, NULL, NULL,
Pablo Greco e6a3ae
             NULL, NULL, NULL, NULL,
Pablo Greco e6a3ae
         },
Pablo Greco e6a3ae
-        .cpuid_eax = 0x80000001, .cpuid_reg = R_ECX,
Pablo Greco e6a3ae
+        .cpuid = { .eax = 0x80000001, .reg = R_ECX, },
Pablo Greco e6a3ae
         .tcg_features = TCG_EXT3_FEATURES,
Pablo Greco e6a3ae
         /*
Pablo Greco e6a3ae
          * TOPOEXT is always allowed but can't be enabled blindly by
Pablo Greco e6a3ae
@@ -860,6 +883,7 @@ static FeatureWordInfo feature_word_info[FEATURE_WORDS] = {
Pablo Greco e6a3ae
         .no_autoenable_flags = CPUID_EXT3_TOPOEXT,
Pablo Greco e6a3ae
     },
Pablo Greco e6a3ae
     [FEAT_C000_0001_EDX] = {
Pablo Greco e6a3ae
+        .type = CPUID_FEATURE_WORD,
Pablo Greco e6a3ae
         .feat_names = {
Pablo Greco e6a3ae
             NULL, NULL, "xstore", "xstore-en",
Pablo Greco e6a3ae
             NULL, NULL, "xcrypt", "xcrypt-en",
Pablo Greco e6a3ae
@@ -870,10 +894,11 @@ static FeatureWordInfo feature_word_info[FEATURE_WORDS] = {
Pablo Greco e6a3ae
             NULL, NULL, NULL, NULL,
Pablo Greco e6a3ae
             NULL, NULL, NULL, NULL,
Pablo Greco e6a3ae
         },
Pablo Greco e6a3ae
-        .cpuid_eax = 0xC0000001, .cpuid_reg = R_EDX,
Pablo Greco e6a3ae
+        .cpuid = { .eax = 0xC0000001, .reg = R_EDX, },
Pablo Greco e6a3ae
         .tcg_features = TCG_EXT4_FEATURES,
Pablo Greco e6a3ae
     },
Pablo Greco e6a3ae
     [FEAT_KVM] = {
Pablo Greco e6a3ae
+        .type = CPUID_FEATURE_WORD,
Pablo Greco e6a3ae
         .feat_names = {
Pablo Greco e6a3ae
             "kvmclock", "kvm-nopiodelay", "kvm-mmu", "kvmclock",
Pablo Greco e6a3ae
             "kvm-asyncpf", "kvm-steal-time", "kvm-pv-eoi", "kvm-pv-unhalt",
Pablo Greco e6a3ae
@@ -884,10 +909,11 @@ static FeatureWordInfo feature_word_info[FEATURE_WORDS] = {
Pablo Greco e6a3ae
             "kvmclock-stable-bit", NULL, NULL, NULL,
Pablo Greco e6a3ae
             NULL, NULL, NULL, NULL,
Pablo Greco e6a3ae
         },
Pablo Greco e6a3ae
-        .cpuid_eax = KVM_CPUID_FEATURES, .cpuid_reg = R_EAX,
Pablo Greco e6a3ae
+        .cpuid = { .eax = KVM_CPUID_FEATURES, .reg = R_EAX, },
Pablo Greco e6a3ae
         .tcg_features = TCG_KVM_FEATURES,
Pablo Greco e6a3ae
     },
Pablo Greco e6a3ae
     [FEAT_KVM_HINTS] = {
Pablo Greco e6a3ae
+        .type = CPUID_FEATURE_WORD,
Pablo Greco e6a3ae
         .feat_names = {
Pablo Greco e6a3ae
             "kvm-hint-dedicated", NULL, NULL, NULL,
Pablo Greco e6a3ae
             NULL, NULL, NULL, NULL,
Pablo Greco e6a3ae
@@ -898,7 +924,7 @@ static FeatureWordInfo feature_word_info[FEATURE_WORDS] = {
Pablo Greco e6a3ae
             NULL, NULL, NULL, NULL,
Pablo Greco e6a3ae
             NULL, NULL, NULL, NULL,
Pablo Greco e6a3ae
         },
Pablo Greco e6a3ae
-        .cpuid_eax = KVM_CPUID_FEATURES, .cpuid_reg = R_EDX,
Pablo Greco e6a3ae
+        .cpuid = { .eax = KVM_CPUID_FEATURES, .reg = R_EDX, },
Pablo Greco e6a3ae
         .tcg_features = TCG_KVM_FEATURES,
Pablo Greco e6a3ae
         /*
Pablo Greco e6a3ae
          * KVM hints aren't auto-enabled by -cpu host, they need to be
Pablo Greco e6a3ae
@@ -907,6 +933,7 @@ static FeatureWordInfo feature_word_info[FEATURE_WORDS] = {
Pablo Greco e6a3ae
         .no_autoenable_flags = ~0U,
Pablo Greco e6a3ae
     },
Pablo Greco e6a3ae
     [FEAT_HYPERV_EAX] = {
Pablo Greco e6a3ae
+        .type = CPUID_FEATURE_WORD,
Pablo Greco e6a3ae
         .feat_names = {
Pablo Greco e6a3ae
             NULL /* hv_msr_vp_runtime_access */, NULL /* hv_msr_time_refcount_access */,
Pablo Greco e6a3ae
             NULL /* hv_msr_synic_access */, NULL /* hv_msr_stimer_access */,
Pablo Greco e6a3ae
@@ -920,9 +947,10 @@ static FeatureWordInfo feature_word_info[FEATURE_WORDS] = {
Pablo Greco e6a3ae
             NULL, NULL, NULL, NULL,
Pablo Greco e6a3ae
             NULL, NULL, NULL, NULL,
Pablo Greco e6a3ae
         },
Pablo Greco e6a3ae
-        .cpuid_eax = 0x40000003, .cpuid_reg = R_EAX,
Pablo Greco e6a3ae
+        .cpuid = { .eax = 0x40000003, .reg = R_EAX, },
Pablo Greco e6a3ae
     },
Pablo Greco e6a3ae
     [FEAT_HYPERV_EBX] = {
Pablo Greco e6a3ae
+        .type = CPUID_FEATURE_WORD,
Pablo Greco e6a3ae
         .feat_names = {
Pablo Greco e6a3ae
             NULL /* hv_create_partitions */, NULL /* hv_access_partition_id */,
Pablo Greco e6a3ae
             NULL /* hv_access_memory_pool */, NULL /* hv_adjust_message_buffers */,
Pablo Greco e6a3ae
@@ -936,9 +964,10 @@ static FeatureWordInfo feature_word_info[FEATURE_WORDS] = {
Pablo Greco e6a3ae
             NULL, NULL, NULL, NULL,
Pablo Greco e6a3ae
             NULL, NULL, NULL, NULL,
Pablo Greco e6a3ae
         },
Pablo Greco e6a3ae
-        .cpuid_eax = 0x40000003, .cpuid_reg = R_EBX,
Pablo Greco e6a3ae
+        .cpuid = { .eax = 0x40000003, .reg = R_EBX, },
Pablo Greco e6a3ae
     },
Pablo Greco e6a3ae
     [FEAT_HYPERV_EDX] = {
Pablo Greco e6a3ae
+        .type = CPUID_FEATURE_WORD,
Pablo Greco e6a3ae
         .feat_names = {
Pablo Greco e6a3ae
             NULL /* hv_mwait */, NULL /* hv_guest_debugging */,
Pablo Greco e6a3ae
             NULL /* hv_perf_monitor */, NULL /* hv_cpu_dynamic_part */,
Pablo Greco e6a3ae
@@ -951,9 +980,10 @@ static FeatureWordInfo feature_word_info[FEATURE_WORDS] = {
Pablo Greco e6a3ae
             NULL, NULL, NULL, NULL,
Pablo Greco e6a3ae
             NULL, NULL, NULL, NULL,
Pablo Greco e6a3ae
         },
Pablo Greco e6a3ae
-        .cpuid_eax = 0x40000003, .cpuid_reg = R_EDX,
Pablo Greco e6a3ae
+        .cpuid = { .eax = 0x40000003, .reg = R_EDX, },
Pablo Greco e6a3ae
     },
Pablo Greco e6a3ae
     [FEAT_SVM] = {
Pablo Greco e6a3ae
+        .type = CPUID_FEATURE_WORD,
Pablo Greco e6a3ae
         .feat_names = {
Pablo Greco e6a3ae
             "npt", "lbrv", "svm-lock", "nrip-save",
Pablo Greco e6a3ae
             "tsc-scale", "vmcb-clean",  "flushbyasid", "decodeassists",
Pablo Greco e6a3ae
@@ -964,10 +994,11 @@ static FeatureWordInfo feature_word_info[FEATURE_WORDS] = {
Pablo Greco e6a3ae
             NULL, NULL, NULL, NULL,
Pablo Greco e6a3ae
             NULL, NULL, NULL, NULL,
Pablo Greco e6a3ae
         },
Pablo Greco e6a3ae
-        .cpuid_eax = 0x8000000A, .cpuid_reg = R_EDX,
Pablo Greco e6a3ae
+        .cpuid = { .eax = 0x8000000A, .reg = R_EDX, },
Pablo Greco e6a3ae
         .tcg_features = TCG_SVM_FEATURES,
Pablo Greco e6a3ae
     },
Pablo Greco e6a3ae
     [FEAT_7_0_EBX] = {
Pablo Greco e6a3ae
+        .type = CPUID_FEATURE_WORD,
Pablo Greco e6a3ae
         .feat_names = {
Pablo Greco e6a3ae
             "fsgsbase", "tsc-adjust", NULL, "bmi1",
Pablo Greco e6a3ae
             "hle", "avx2", NULL, "smep",
Pablo Greco e6a3ae
@@ -978,12 +1009,15 @@ static FeatureWordInfo feature_word_info[FEATURE_WORDS] = {
Pablo Greco e6a3ae
             "clwb", "intel-pt", "avx512pf", "avx512er",
Pablo Greco e6a3ae
             "avx512cd", "sha-ni", "avx512bw", "avx512vl",
Pablo Greco e6a3ae
         },
Pablo Greco e6a3ae
-        .cpuid_eax = 7,
Pablo Greco e6a3ae
-        .cpuid_needs_ecx = true, .cpuid_ecx = 0,
Pablo Greco e6a3ae
-        .cpuid_reg = R_EBX,
Pablo Greco e6a3ae
+        .cpuid = {
Pablo Greco e6a3ae
+            .eax = 7,
Pablo Greco e6a3ae
+            .needs_ecx = true, .ecx = 0,
Pablo Greco e6a3ae
+            .reg = R_EBX,
Pablo Greco e6a3ae
+        },
Pablo Greco e6a3ae
         .tcg_features = TCG_7_0_EBX_FEATURES,
Pablo Greco e6a3ae
     },
Pablo Greco e6a3ae
     [FEAT_7_0_ECX] = {
Pablo Greco e6a3ae
+        .type = CPUID_FEATURE_WORD,
Pablo Greco e6a3ae
         .feat_names = {
Pablo Greco e6a3ae
             NULL, "avx512vbmi", "umip", "pku",
Pablo Greco e6a3ae
             "ospke", NULL, "avx512vbmi2", NULL,
Pablo Greco e6a3ae
@@ -994,12 +1028,15 @@ static FeatureWordInfo feature_word_info[FEATURE_WORDS] = {
Pablo Greco e6a3ae
             NULL, NULL, NULL, NULL,
Pablo Greco e6a3ae
             NULL, NULL, NULL, NULL,
Pablo Greco e6a3ae
         },
Pablo Greco e6a3ae
-        .cpuid_eax = 7,
Pablo Greco e6a3ae
-        .cpuid_needs_ecx = true, .cpuid_ecx = 0,
Pablo Greco e6a3ae
-        .cpuid_reg = R_ECX,
Pablo Greco e6a3ae
+        .cpuid = {
Pablo Greco e6a3ae
+            .eax = 7,
Pablo Greco e6a3ae
+            .needs_ecx = true, .ecx = 0,
Pablo Greco e6a3ae
+            .reg = R_ECX,
Pablo Greco e6a3ae
+        },
Pablo Greco e6a3ae
         .tcg_features = TCG_7_0_ECX_FEATURES,
Pablo Greco e6a3ae
     },
Pablo Greco e6a3ae
     [FEAT_7_0_EDX] = {
Pablo Greco e6a3ae
+        .type = CPUID_FEATURE_WORD,
Pablo Greco e6a3ae
         .feat_names = {
Pablo Greco e6a3ae
             NULL, NULL, "avx512-4vnniw", "avx512-4fmaps",
Pablo Greco e6a3ae
             NULL, NULL, NULL, NULL,
Pablo Greco e6a3ae
@@ -1010,13 +1047,16 @@ static FeatureWordInfo feature_word_info[FEATURE_WORDS] = {
Pablo Greco e6a3ae
             NULL, NULL, "spec-ctrl", "stibp",
Pablo Greco e6a3ae
             NULL, "arch-capabilities", NULL, "ssbd",
Pablo Greco e6a3ae
         },
Pablo Greco e6a3ae
-        .cpuid_eax = 7,
Pablo Greco e6a3ae
-        .cpuid_needs_ecx = true, .cpuid_ecx = 0,
Pablo Greco e6a3ae
-        .cpuid_reg = R_EDX,
Pablo Greco e6a3ae
+        .cpuid = {
Pablo Greco e6a3ae
+            .eax = 7,
Pablo Greco e6a3ae
+            .needs_ecx = true, .ecx = 0,
Pablo Greco e6a3ae
+            .reg = R_EDX,
Pablo Greco e6a3ae
+        },
Pablo Greco e6a3ae
         .tcg_features = TCG_7_0_EDX_FEATURES,
Pablo Greco e6a3ae
         .unmigratable_flags = CPUID_7_0_EDX_ARCH_CAPABILITIES,
Pablo Greco e6a3ae
     },
Pablo Greco e6a3ae
     [FEAT_8000_0007_EDX] = {
Pablo Greco e6a3ae
+        .type = CPUID_FEATURE_WORD,
Pablo Greco e6a3ae
         .feat_names = {
Pablo Greco e6a3ae
             NULL, NULL, NULL, NULL,
Pablo Greco e6a3ae
             NULL, NULL, NULL, NULL,
Pablo Greco e6a3ae
@@ -1027,12 +1067,12 @@ static FeatureWordInfo feature_word_info[FEATURE_WORDS] = {
Pablo Greco e6a3ae
             NULL, NULL, NULL, NULL,
Pablo Greco e6a3ae
             NULL, NULL, NULL, NULL,
Pablo Greco e6a3ae
         },
Pablo Greco e6a3ae
-        .cpuid_eax = 0x80000007,
Pablo Greco e6a3ae
-        .cpuid_reg = R_EDX,
Pablo Greco e6a3ae
+        .cpuid = { .eax = 0x80000007, .reg = R_EDX, },
Pablo Greco e6a3ae
         .tcg_features = TCG_APM_FEATURES,
Pablo Greco e6a3ae
         .unmigratable_flags = CPUID_APM_INVTSC,
Pablo Greco e6a3ae
     },
Pablo Greco e6a3ae
     [FEAT_8000_0008_EBX] = {
Pablo Greco e6a3ae
+        .type = CPUID_FEATURE_WORD,
Pablo Greco e6a3ae
         .feat_names = {
Pablo Greco e6a3ae
             NULL, NULL, NULL, NULL,
Pablo Greco e6a3ae
             NULL, NULL, NULL, NULL,
Pablo Greco e6a3ae
@@ -1043,12 +1083,12 @@ static FeatureWordInfo feature_word_info[FEATURE_WORDS] = {
Pablo Greco e6a3ae
             NULL, "virt-ssbd", NULL, NULL,
Pablo Greco e6a3ae
             NULL, NULL, NULL, NULL,
Pablo Greco e6a3ae
         },
Pablo Greco e6a3ae
-        .cpuid_eax = 0x80000008,
Pablo Greco e6a3ae
-        .cpuid_reg = R_EBX,
Pablo Greco e6a3ae
+        .cpuid = { .eax = 0x80000008, .reg = R_EBX, },
Pablo Greco e6a3ae
         .tcg_features = 0,
Pablo Greco e6a3ae
         .unmigratable_flags = 0,
Pablo Greco e6a3ae
     },
Pablo Greco e6a3ae
     [FEAT_XSAVE] = {
Pablo Greco e6a3ae
+        .type = CPUID_FEATURE_WORD,
Pablo Greco e6a3ae
         .feat_names = {
Pablo Greco e6a3ae
             "xsaveopt", "xsavec", "xgetbv1", "xsaves",
Pablo Greco e6a3ae
             NULL, NULL, NULL, NULL,
Pablo Greco e6a3ae
@@ -1059,12 +1099,15 @@ static FeatureWordInfo feature_word_info[FEATURE_WORDS] = {
Pablo Greco e6a3ae
             NULL, NULL, NULL, NULL,
Pablo Greco e6a3ae
             NULL, NULL, NULL, NULL,
Pablo Greco e6a3ae
         },
Pablo Greco e6a3ae
-        .cpuid_eax = 0xd,
Pablo Greco e6a3ae
-        .cpuid_needs_ecx = true, .cpuid_ecx = 1,
Pablo Greco e6a3ae
-        .cpuid_reg = R_EAX,
Pablo Greco e6a3ae
+        .cpuid = {
Pablo Greco e6a3ae
+            .eax = 0xd,
Pablo Greco e6a3ae
+            .needs_ecx = true, .ecx = 1,
Pablo Greco e6a3ae
+            .reg = R_EAX,
Pablo Greco e6a3ae
+        },
Pablo Greco e6a3ae
         .tcg_features = TCG_XSAVE_FEATURES,
Pablo Greco e6a3ae
     },
Pablo Greco e6a3ae
     [FEAT_6_EAX] = {
Pablo Greco e6a3ae
+        .type = CPUID_FEATURE_WORD,
Pablo Greco e6a3ae
         .feat_names = {
Pablo Greco e6a3ae
             NULL, NULL, "arat", NULL,
Pablo Greco e6a3ae
             NULL, NULL, NULL, NULL,
Pablo Greco e6a3ae
@@ -1075,13 +1118,16 @@ static FeatureWordInfo feature_word_info[FEATURE_WORDS] = {
Pablo Greco e6a3ae
             NULL, NULL, NULL, NULL,
Pablo Greco e6a3ae
             NULL, NULL, NULL, NULL,
Pablo Greco e6a3ae
         },
Pablo Greco e6a3ae
-        .cpuid_eax = 6, .cpuid_reg = R_EAX,
Pablo Greco e6a3ae
+        .cpuid = { .eax = 6, .reg = R_EAX, },
Pablo Greco e6a3ae
         .tcg_features = TCG_6_EAX_FEATURES,
Pablo Greco e6a3ae
     },
Pablo Greco e6a3ae
     [FEAT_XSAVE_COMP_LO] = {
Pablo Greco e6a3ae
-        .cpuid_eax = 0xD,
Pablo Greco e6a3ae
-        .cpuid_needs_ecx = true, .cpuid_ecx = 0,
Pablo Greco e6a3ae
-        .cpuid_reg = R_EAX,
Pablo Greco e6a3ae
+        .type = CPUID_FEATURE_WORD,
Pablo Greco e6a3ae
+        .cpuid = {
Pablo Greco e6a3ae
+            .eax = 0xD,
Pablo Greco e6a3ae
+            .needs_ecx = true, .ecx = 0,
Pablo Greco e6a3ae
+            .reg = R_EAX,
Pablo Greco e6a3ae
+        },
Pablo Greco e6a3ae
         .tcg_features = ~0U,
Pablo Greco e6a3ae
         .migratable_flags = XSTATE_FP_MASK | XSTATE_SSE_MASK |
Pablo Greco e6a3ae
             XSTATE_YMM_MASK | XSTATE_BNDREGS_MASK | XSTATE_BNDCSR_MASK |
Pablo Greco e6a3ae
@@ -1089,9 +1135,12 @@ static FeatureWordInfo feature_word_info[FEATURE_WORDS] = {
Pablo Greco e6a3ae
             XSTATE_PKRU_MASK,
Pablo Greco e6a3ae
     },
Pablo Greco e6a3ae
     [FEAT_XSAVE_COMP_HI] = {
Pablo Greco e6a3ae
-        .cpuid_eax = 0xD,
Pablo Greco e6a3ae
-        .cpuid_needs_ecx = true, .cpuid_ecx = 0,
Pablo Greco e6a3ae
-        .cpuid_reg = R_EDX,
Pablo Greco e6a3ae
+        .type = CPUID_FEATURE_WORD,
Pablo Greco e6a3ae
+        .cpuid = {
Pablo Greco e6a3ae
+            .eax = 0xD,
Pablo Greco e6a3ae
+            .needs_ecx = true, .ecx = 0,
Pablo Greco e6a3ae
+            .reg = R_EDX,
Pablo Greco e6a3ae
+        },
Pablo Greco e6a3ae
         .tcg_features = ~0U,
Pablo Greco e6a3ae
     },
Pablo Greco e6a3ae
 };
Pablo Greco e6a3ae
@@ -2961,21 +3010,41 @@ static const TypeInfo host_x86_cpu_type_info = {
Pablo Greco e6a3ae
 
Pablo Greco e6a3ae
 #endif
Pablo Greco e6a3ae
 
Pablo Greco e6a3ae
+static char *feature_word_description(FeatureWordInfo *f, uint32_t bit)
Pablo Greco e6a3ae
+{
Pablo Greco e6a3ae
+    assert(f->type == CPUID_FEATURE_WORD || f->type == MSR_FEATURE_WORD);
Pablo Greco e6a3ae
+
Pablo Greco e6a3ae
+    switch (f->type) {
Pablo Greco e6a3ae
+    case CPUID_FEATURE_WORD:
Pablo Greco e6a3ae
+        {
Pablo Greco e6a3ae
+            const char *reg = get_register_name_32(f->cpuid.reg);
Pablo Greco e6a3ae
+            assert(reg);
Pablo Greco e6a3ae
+            return g_strdup_printf("CPUID.%02XH:%s",
Pablo Greco e6a3ae
+                                   f->cpuid.eax, reg);
Pablo Greco e6a3ae
+        }
Pablo Greco e6a3ae
+    case MSR_FEATURE_WORD:
Pablo Greco e6a3ae
+        return g_strdup_printf("MSR(%02XH)",
Pablo Greco e6a3ae
+                               f->msr.index);
Pablo Greco e6a3ae
+    }
Pablo Greco e6a3ae
+
Pablo Greco e6a3ae
+    return NULL;
Pablo Greco e6a3ae
+}
Pablo Greco e6a3ae
+
Pablo Greco e6a3ae
 static void report_unavailable_features(FeatureWord w, uint32_t mask)
Pablo Greco e6a3ae
 {
Pablo Greco e6a3ae
     FeatureWordInfo *f = &feature_word_info[w];
Pablo Greco e6a3ae
     int i;
Pablo Greco e6a3ae
+    char *feat_word_str;
Pablo Greco e6a3ae
 
Pablo Greco e6a3ae
     for (i = 0; i < 32; ++i) {
Pablo Greco e6a3ae
         if ((1UL << i) & mask) {
Pablo Greco e6a3ae
-            const char *reg = get_register_name_32(f->cpuid_reg);
Pablo Greco e6a3ae
-            assert(reg);
Pablo Greco e6a3ae
-            warn_report("%s doesn't support requested feature: "
Pablo Greco e6a3ae
-                        "CPUID.%02XH:%s%s%s [bit %d]",
Pablo Greco e6a3ae
+            feat_word_str = feature_word_description(f, i);
Pablo Greco e6a3ae
+            warn_report("%s doesn't support requested feature: %s%s%s [bit %d]",
Pablo Greco e6a3ae
                         accel_uses_host_cpuid() ? "host" : "TCG",
Pablo Greco e6a3ae
-                        f->cpuid_eax, reg,
Pablo Greco e6a3ae
+                        feat_word_str,
Pablo Greco e6a3ae
                         f->feat_names[i] ? "." : "",
Pablo Greco e6a3ae
                         f->feat_names[i] ? f->feat_names[i] : "", i);
Pablo Greco e6a3ae
+            g_free(feat_word_str);
Pablo Greco e6a3ae
         }
Pablo Greco e6a3ae
     }
Pablo Greco e6a3ae
 }
Pablo Greco e6a3ae
@@ -3219,11 +3288,18 @@ static void x86_cpu_get_feature_words(Object *obj, Visitor *v,
Pablo Greco e6a3ae
 
Pablo Greco e6a3ae
     for (w = 0; w < FEATURE_WORDS; w++) {
Pablo Greco e6a3ae
         FeatureWordInfo *wi = &feature_word_info[w];
Pablo Greco e6a3ae
+        /*
Pablo Greco e6a3ae
+                * We didn't have MSR features when "feature-words" was
Pablo Greco e6a3ae
+                *  introduced. Therefore skipped other type entries.
Pablo Greco e6a3ae
+                */
Pablo Greco e6a3ae
+        if (wi->type != CPUID_FEATURE_WORD) {
Pablo Greco e6a3ae
+            continue;
Pablo Greco e6a3ae
+        }
Pablo Greco e6a3ae
         X86CPUFeatureWordInfo *qwi = &word_infos[w];
Pablo Greco e6a3ae
-        qwi->cpuid_input_eax = wi->cpuid_eax;
Pablo Greco e6a3ae
-        qwi->has_cpuid_input_ecx = wi->cpuid_needs_ecx;
Pablo Greco e6a3ae
-        qwi->cpuid_input_ecx = wi->cpuid_ecx;
Pablo Greco e6a3ae
-        qwi->cpuid_register = x86_reg_info_32[wi->cpuid_reg].qapi_enum;
Pablo Greco e6a3ae
+        qwi->cpuid_input_eax = wi->cpuid.eax;
Pablo Greco e6a3ae
+        qwi->has_cpuid_input_ecx = wi->cpuid.needs_ecx;
Pablo Greco e6a3ae
+        qwi->cpuid_input_ecx = wi->cpuid.ecx;
Pablo Greco e6a3ae
+        qwi->cpuid_register = x86_reg_info_32[wi->cpuid.reg].qapi_enum;
Pablo Greco e6a3ae
         qwi->features = array[w];
Pablo Greco e6a3ae
 
Pablo Greco e6a3ae
         /* List will be in reverse order, but order shouldn't matter */
Pablo Greco e6a3ae
@@ -3579,16 +3655,26 @@ static uint32_t x86_cpu_get_supported_feature_word(FeatureWord w,
Pablo Greco e6a3ae
                                                    bool migratable_only)
Pablo Greco e6a3ae
 {
Pablo Greco e6a3ae
     FeatureWordInfo *wi = &feature_word_info[w];
Pablo Greco e6a3ae
-    uint32_t r;
Pablo Greco e6a3ae
+    uint32_t r = 0;
Pablo Greco e6a3ae
 
Pablo Greco e6a3ae
     if (kvm_enabled()) {
Pablo Greco e6a3ae
-        r = kvm_arch_get_supported_cpuid(kvm_state, wi->cpuid_eax,
Pablo Greco e6a3ae
-                                                    wi->cpuid_ecx,
Pablo Greco e6a3ae
-                                                    wi->cpuid_reg);
Pablo Greco e6a3ae
+        switch (wi->type) {
Pablo Greco e6a3ae
+        case CPUID_FEATURE_WORD:
Pablo Greco e6a3ae
+            r = kvm_arch_get_supported_cpuid(kvm_state, wi->cpuid.eax,
Pablo Greco e6a3ae
+                                                        wi->cpuid.ecx,
Pablo Greco e6a3ae
+                                                        wi->cpuid.reg);
Pablo Greco e6a3ae
+            break;
Pablo Greco e6a3ae
+        case MSR_FEATURE_WORD:
Pablo Greco e6a3ae
+            r = kvm_arch_get_supported_msr_feature(kvm_state, wi->msr.index);
Pablo Greco e6a3ae
+            break;
Pablo Greco e6a3ae
+        }
Pablo Greco e6a3ae
     } else if (hvf_enabled()) {
Pablo Greco e6a3ae
-        r = hvf_get_supported_cpuid(wi->cpuid_eax,
Pablo Greco e6a3ae
-                                    wi->cpuid_ecx,
Pablo Greco e6a3ae
-                                    wi->cpuid_reg);
Pablo Greco e6a3ae
+        if (wi->type != CPUID_FEATURE_WORD) {
Pablo Greco e6a3ae
+            return 0;
Pablo Greco e6a3ae
+        }
Pablo Greco e6a3ae
+        r = hvf_get_supported_cpuid(wi->cpuid.eax,
Pablo Greco e6a3ae
+                                    wi->cpuid.ecx,
Pablo Greco e6a3ae
+                                    wi->cpuid.reg);
Pablo Greco e6a3ae
     } else if (tcg_enabled()) {
Pablo Greco e6a3ae
         r = wi->tcg_features;
Pablo Greco e6a3ae
     } else {
Pablo Greco e6a3ae
@@ -4649,9 +4735,10 @@ static void x86_cpu_adjust_feat_level(X86CPU *cpu, FeatureWord w)
Pablo Greco e6a3ae
 {
Pablo Greco e6a3ae
     CPUX86State *env = &cpu->env;
Pablo Greco e6a3ae
     FeatureWordInfo *fi = &feature_word_info[w];
Pablo Greco e6a3ae
-    uint32_t eax = fi->cpuid_eax;
Pablo Greco e6a3ae
+    uint32_t eax = fi->cpuid.eax;
Pablo Greco e6a3ae
     uint32_t region = eax & 0xF0000000;
Pablo Greco e6a3ae
 
Pablo Greco e6a3ae
+    assert(feature_word_info[w].type == CPUID_FEATURE_WORD);
Pablo Greco e6a3ae
     if (!env->features[w]) {
Pablo Greco e6a3ae
         return;
Pablo Greco e6a3ae
     }
Pablo Greco e6a3ae
-- 
Pablo Greco e6a3ae
1.8.3.1
Pablo Greco e6a3ae