34b321
From eb87f1106d038247356ecd3071e6fa5654386ff5 Mon Sep 17 00:00:00 2001
34b321
From: Eduardo Habkost <ehabkost@redhat.com>
34b321
Date: Fri, 9 Sep 2016 19:08:33 +0200
34b321
Subject: [PATCH 1/2] target-i386: Add support for FEAT_7_0_ECX
34b321
34b321
RH-Author: Eduardo Habkost <ehabkost@redhat.com>
34b321
Message-id: <1473448114-1430-2-git-send-email-ehabkost@redhat.com>
34b321
Patchwork-id: 72276
34b321
O-Subject: [RHEL-7.3 qemu-kvm PATCH v2 1/2] target-i386: Add support for FEAT_7_0_ECX
34b321
Bugzilla: 1372459
34b321
RH-Acked-by: Bandan Das <bsd@redhat.com>
34b321
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
34b321
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
34b321
34b321
From: Paolo Bonzini <pbonzini@redhat.com>
34b321
34b321
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1372459
34b321
34b321
Done from scratch by copying what is done for FEAT_7_0_EBX.  Compare
34b321
to upstream commit f74eefe ("target-i386: Add PKU and and OSPKE support",
34b321
2016-01-21), but without actually adding PKU and OSPKE.  Because all
34b321
these features are "-cpu host"-only, they can be added without modifying
34b321
machine types.
34b321
34b321
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
34b321
[ehabkost: v2: removed the non-upstream cpuid_level < 7 check]
34b321
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
34b321
34b321
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
34b321
---
34b321
 target-i386/cpu.c | 29 ++++++++++++++++++++++++++++-
34b321
 target-i386/cpu.h |  1 +
34b321
 2 files changed, 29 insertions(+), 1 deletion(-)
34b321
34b321
diff --git a/target-i386/cpu.c b/target-i386/cpu.c
34b321
index 1001c47..d9c214c 100644
34b321
--- a/target-i386/cpu.c
34b321
+++ b/target-i386/cpu.c
34b321
@@ -150,6 +150,17 @@ static const char *cpuid_7_0_ebx_feature_name[] = {
34b321
     NULL, NULL, "avx512pf", "avx512er", "avx512cd", NULL, NULL, NULL,
34b321
 };
34b321
 
34b321
+static const char *cpuid_7_0_ecx_feature_name[] = {
34b321
+    NULL, NULL, NULL, NULL,
34b321
+    NULL, NULL, NULL, NULL,
34b321
+    NULL, NULL, NULL, NULL,
34b321
+    NULL, NULL, NULL, NULL,
34b321
+    NULL, NULL, NULL, NULL,
34b321
+    NULL, NULL, NULL, NULL,
34b321
+    NULL, NULL, NULL, NULL,
34b321
+    NULL, NULL, NULL, NULL,
34b321
+};
34b321
+
34b321
 static const char *cpuid_xsave_feature_name[] = {
34b321
     "xsaveopt", "xsavec", "xgetbv1", NULL,
34b321
     NULL, NULL, NULL, NULL,
34b321
@@ -204,6 +215,12 @@ static FeatureWordInfo feature_word_info[FEATURE_WORDS] = {
34b321
         .cpuid_needs_ecx = true, .cpuid_ecx = 0,
34b321
         .cpuid_reg = R_EBX,
34b321
     },
34b321
+    [FEAT_7_0_ECX] = {
34b321
+        .feat_names = cpuid_7_0_ecx_feature_name,
34b321
+        .cpuid_eax = 7,
34b321
+        .cpuid_needs_ecx = true, .cpuid_ecx = 0,
34b321
+        .cpuid_reg = R_ECX,
34b321
+    },
34b321
     [FEAT_XSAVE] = {
34b321
         .feat_names = cpuid_xsave_feature_name,
34b321
         .cpuid_eax = 0xd,
34b321
@@ -462,6 +479,7 @@ typedef struct x86_def_t {
34b321
           CPUID_7_0_EBX_FSGSBASE, CPUID_7_0_EBX_HLE, CPUID_7_0_EBX_AVX2,
34b321
           CPUID_7_0_EBX_ERMS, CPUID_7_0_EBX_INVPCID, CPUID_7_0_EBX_RTM,
34b321
           CPUID_7_0_EBX_RDSEED */
34b321
+#define TCG_7_0_ECX_FEATURES 0
34b321
 
34b321
 /* built-in CPU model definitions
34b321
  */
34b321
@@ -1198,8 +1216,11 @@ static void kvm_cpu_fill_host(x86_def_t *x86_cpu_def)
34b321
     if (x86_cpu_def->level >= 7) {
34b321
         x86_cpu_def->features[FEAT_7_0_EBX] =
34b321
                     kvm_arch_get_supported_cpuid(s, 0x7, 0, R_EBX);
34b321
+        x86_cpu_def->features[FEAT_7_0_ECX] =
34b321
+                    kvm_arch_get_supported_cpuid(s, 0x7, 0, R_ECX);
34b321
     } else {
34b321
         x86_cpu_def->features[FEAT_7_0_EBX] = 0;
34b321
+        x86_cpu_def->features[FEAT_7_0_ECX] = 0;
34b321
     }
34b321
     x86_cpu_def->features[FEAT_XSAVE] =
34b321
                 kvm_arch_get_supported_cpuid(s, 0xd, 1, R_EAX);
34b321
@@ -1283,6 +1304,9 @@ static int kvm_check_features_against_host(X86CPU *cpu)
34b321
         {&env->features[FEAT_7_0_EBX],
34b321
             &host_def.features[FEAT_7_0_EBX],
34b321
             FEAT_7_0_EBX },
34b321
+        {&env->features[FEAT_7_0_ECX],
34b321
+            &host_def.features[FEAT_7_0_ECX],
34b321
+            FEAT_7_0_ECX },
34b321
         {&env->features[FEAT_XSAVE],
34b321
             &host_def.features[FEAT_XSAVE],
34b321
             FEAT_XSAVE },
34b321
@@ -1824,6 +1848,7 @@ static void cpu_x86_parse_featurestr(X86CPU *cpu, char *features, Error **errp)
34b321
     env->features[FEAT_KVM] |= plus_features[FEAT_KVM];
34b321
     env->features[FEAT_SVM] |= plus_features[FEAT_SVM];
34b321
     env->features[FEAT_7_0_EBX] |= plus_features[FEAT_7_0_EBX];
34b321
+    env->features[FEAT_7_0_ECX] |= plus_features[FEAT_7_0_ECX];
34b321
     env->features[FEAT_XSAVE] |= plus_features[FEAT_XSAVE];
34b321
     env->features[FEAT_1_EDX] &= ~minus_features[FEAT_1_EDX];
34b321
     env->features[FEAT_1_ECX] &= ~minus_features[FEAT_1_ECX];
34b321
@@ -1833,6 +1858,7 @@ static void cpu_x86_parse_featurestr(X86CPU *cpu, char *features, Error **errp)
34b321
     env->features[FEAT_KVM] &= ~minus_features[FEAT_KVM];
34b321
     env->features[FEAT_SVM] &= ~minus_features[FEAT_SVM];
34b321
     env->features[FEAT_7_0_EBX] &= ~minus_features[FEAT_7_0_EBX];
34b321
+    env->features[FEAT_7_0_ECX] &= ~minus_features[FEAT_7_0_ECX];
34b321
     env->features[FEAT_XSAVE] &= ~minus_features[FEAT_XSAVE];
34b321
 
34b321
 out:
34b321
@@ -1969,6 +1995,7 @@ static void cpu_x86_register(X86CPU *cpu, const char *name, Error **errp)
34b321
     env->features[FEAT_SVM] = def->features[FEAT_SVM];
34b321
     env->features[FEAT_C000_0001_EDX] = def->features[FEAT_C000_0001_EDX];
34b321
     env->features[FEAT_7_0_EBX] = def->features[FEAT_7_0_EBX];
34b321
+    env->features[FEAT_7_0_ECX] = def->features[FEAT_7_0_ECX];
34b321
     env->features[FEAT_XSAVE] = def->features[FEAT_XSAVE];
34b321
     env->cpuid_xlevel2 = def->xlevel2;
34b321
 
34b321
@@ -2206,7 +2233,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count,
34b321
         if (count == 0) {
34b321
             *eax = 0; /* Maximum ECX value for sub-leaves */
34b321
             *ebx = env->features[FEAT_7_0_EBX]; /* Feature flags */
34b321
-            *ecx = 0; /* Reserved */
34b321
+            *ecx = env->features[FEAT_7_0_ECX]; /* Feature flags */
34b321
             *edx = 0; /* Reserved */
34b321
         } else {
34b321
             *eax = 0;
34b321
diff --git a/target-i386/cpu.h b/target-i386/cpu.h
34b321
index da7e060..5c62ee3 100644
34b321
--- a/target-i386/cpu.h
34b321
+++ b/target-i386/cpu.h
34b321
@@ -400,6 +400,7 @@ typedef enum FeatureWord {
34b321
     FEAT_1_EDX,         /* CPUID[1].EDX */
34b321
     FEAT_1_ECX,         /* CPUID[1].ECX */
34b321
     FEAT_7_0_EBX,       /* CPUID[EAX=7,ECX=0].EBX */
34b321
+    FEAT_7_0_ECX,       /* CPUID[EAX=7,ECX=0].ECX */
34b321
     FEAT_8000_0001_EDX, /* CPUID[8000_0001].EDX */
34b321
     FEAT_8000_0001_ECX, /* CPUID[8000_0001].ECX */
34b321
     FEAT_C000_0001_EDX, /* CPUID[C000_0001].EDX */
34b321
-- 
34b321
1.8.3.1
34b321