yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

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

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