cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-x86-add-AVX512_4VNNIW-and-AVX512_4FMAPS-features.patch

619821
From 7b43b5139f8e919203d3ed20fbba6cb143fde6d7 Mon Sep 17 00:00:00 2001
619821
From: Eduardo Habkost <ehabkost@redhat.com>
619821
Date: Thu, 23 Feb 2017 14:29:32 +0100
619821
Subject: [PATCH 02/17] x86: add AVX512_4VNNIW and AVX512_4FMAPS features
619821
619821
RH-Author: Eduardo Habkost <ehabkost@redhat.com>
619821
Message-id: <20170223142945.17790-2-ehabkost@redhat.com>
619821
Patchwork-id: 74033
619821
O-Subject: [RHEL-7.4 qemu-kvm PATCH v2 01/14] x86: add AVX512_4VNNIW and AVX512_4FMAPS features
619821
Bugzilla: 1382122
619821
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
619821
RH-Acked-by: Igor Mammedov <imammedo@redhat.com>
619821
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
619821
619821
From: Luwei Kang <luwei.kang@intel.com>
619821
619821
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1382122
619821
619821
The spec can be found in Intel Software Developer Manual or in
619821
Instruction Set Extensions Programming Reference.
619821
619821
Backport notes:
619821
619821
Changes v1 -> v2:
619821
* Fixed build error, moved feat_names to a separate static array
619821
  variable
619821
* Fixed backport mistakes (I had forgotten to add
619821
  features[FEAT_7_0_EDX] initialization and filtering code)
619821
619821
Signed-off-by: Piotr Luc <piotr.luc@intel.com>
619821
Signed-off-by: Luwei Kang <luwei.kang@intel.com>
619821
Message-Id: <1477902446-5932-1-git-send-email-he.chen@linux.intel.com>
619821
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
619821
(cherry picked from commit 95ea69fb46266aaa46d0c8b7f0ba8c4903dbe4e3)
619821
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
619821
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
619821
---
619821
 target-i386/cpu.c | 31 ++++++++++++++++++++++++++++++-
619821
 target-i386/cpu.h |  4 ++++
619821
 2 files changed, 34 insertions(+), 1 deletion(-)
619821
619821
diff --git a/target-i386/cpu.c b/target-i386/cpu.c
619821
index c3c8306..789e687 100644
619821
--- a/target-i386/cpu.c
619821
+++ b/target-i386/cpu.c
619821
@@ -165,6 +165,17 @@ static const char *cpuid_7_0_ecx_feature_name[] = {
619821
     NULL, NULL, NULL, NULL,
619821
 };
619821
 
619821
+static const char *cpuid_7_0_edx_feature_name[] = {
619821
+    NULL, NULL, "avx512-4vnniw", "avx512-4fmaps",
619821
+    NULL, NULL, NULL, NULL,
619821
+    NULL, NULL, NULL, NULL,
619821
+    NULL, NULL, NULL, NULL,
619821
+    NULL, NULL, NULL, NULL,
619821
+    NULL, NULL, NULL, NULL,
619821
+    NULL, NULL, NULL, NULL,
619821
+    NULL, NULL, NULL, NULL,
619821
+};
619821
+
619821
 static const char *cpuid_xsave_feature_name[] = {
619821
     "xsaveopt", "xsavec", "xgetbv1", NULL,
619821
     NULL, NULL, NULL, NULL,
619821
@@ -225,6 +236,12 @@ static FeatureWordInfo feature_word_info[FEATURE_WORDS] = {
619821
         .cpuid_needs_ecx = true, .cpuid_ecx = 0,
619821
         .cpuid_reg = R_ECX,
619821
     },
619821
+    [FEAT_7_0_EDX] = {
619821
+        .feat_names = cpuid_7_0_edx_feature_name,
619821
+        .cpuid_eax = 7,
619821
+        .cpuid_needs_ecx = true, .cpuid_ecx = 0,
619821
+        .cpuid_reg = R_EDX,
619821
+    },
619821
     [FEAT_XSAVE] = {
619821
         .feat_names = cpuid_xsave_feature_name,
619821
         .cpuid_eax = 0xd,
619821
@@ -484,6 +501,7 @@ typedef struct x86_def_t {
619821
           CPUID_7_0_EBX_ERMS, CPUID_7_0_EBX_INVPCID, CPUID_7_0_EBX_RTM,
619821
           CPUID_7_0_EBX_RDSEED */
619821
 #define TCG_7_0_ECX_FEATURES 0
619821
+#define TCG_7_0_EDX_FEATURES 0
619821
 
619821
 /* built-in CPU model definitions
619821
  */
619821
@@ -1254,9 +1272,12 @@ static void kvm_cpu_fill_host(x86_def_t *x86_cpu_def)
619821
                     kvm_arch_get_supported_cpuid(s, 0x7, 0, R_EBX);
619821
         x86_cpu_def->features[FEAT_7_0_ECX] =
619821
                     kvm_arch_get_supported_cpuid(s, 0x7, 0, R_ECX);
619821
+        x86_cpu_def->features[FEAT_7_0_EDX] =
619821
+                    kvm_arch_get_supported_cpuid(s, 0x7, 0, R_EDX);
619821
     } else {
619821
         x86_cpu_def->features[FEAT_7_0_EBX] = 0;
619821
         x86_cpu_def->features[FEAT_7_0_ECX] = 0;
619821
+        x86_cpu_def->features[FEAT_7_0_EDX] = 0;
619821
     }
619821
     x86_cpu_def->features[FEAT_XSAVE] =
619821
                 kvm_arch_get_supported_cpuid(s, 0xd, 1, R_EAX);
619821
@@ -1343,6 +1364,9 @@ static int kvm_check_features_against_host(X86CPU *cpu)
619821
         {&env->features[FEAT_7_0_ECX],
619821
             &host_def.features[FEAT_7_0_ECX],
619821
             FEAT_7_0_ECX },
619821
+        {&env->features[FEAT_7_0_EDX],
619821
+            &host_def.features[FEAT_7_0_EDX],
619821
+            FEAT_7_0_EDX },
619821
         {&env->features[FEAT_XSAVE],
619821
             &host_def.features[FEAT_XSAVE],
619821
             FEAT_XSAVE },
619821
@@ -1885,6 +1909,7 @@ static void cpu_x86_parse_featurestr(X86CPU *cpu, char *features, Error **errp)
619821
     env->features[FEAT_SVM] |= plus_features[FEAT_SVM];
619821
     env->features[FEAT_7_0_EBX] |= plus_features[FEAT_7_0_EBX];
619821
     env->features[FEAT_7_0_ECX] |= plus_features[FEAT_7_0_ECX];
619821
+    env->features[FEAT_7_0_EDX] |= plus_features[FEAT_7_0_EDX];
619821
     env->features[FEAT_XSAVE] |= plus_features[FEAT_XSAVE];
619821
     env->features[FEAT_1_EDX] &= ~minus_features[FEAT_1_EDX];
619821
     env->features[FEAT_1_ECX] &= ~minus_features[FEAT_1_ECX];
619821
@@ -1895,6 +1920,7 @@ static void cpu_x86_parse_featurestr(X86CPU *cpu, char *features, Error **errp)
619821
     env->features[FEAT_SVM] &= ~minus_features[FEAT_SVM];
619821
     env->features[FEAT_7_0_EBX] &= ~minus_features[FEAT_7_0_EBX];
619821
     env->features[FEAT_7_0_ECX] &= ~minus_features[FEAT_7_0_ECX];
619821
+    env->features[FEAT_7_0_EDX] &= ~minus_features[FEAT_7_0_EDX];
619821
     env->features[FEAT_XSAVE] &= ~minus_features[FEAT_XSAVE];
619821
 
619821
 out:
619821
@@ -2032,6 +2058,7 @@ static void cpu_x86_register(X86CPU *cpu, const char *name, Error **errp)
619821
     env->features[FEAT_C000_0001_EDX] = def->features[FEAT_C000_0001_EDX];
619821
     env->features[FEAT_7_0_EBX] = def->features[FEAT_7_0_EBX];
619821
     env->features[FEAT_7_0_ECX] = def->features[FEAT_7_0_ECX];
619821
+    env->features[FEAT_7_0_EDX] = def->features[FEAT_7_0_EDX];
619821
     env->features[FEAT_XSAVE] = def->features[FEAT_XSAVE];
619821
     env->cpuid_xlevel2 = def->xlevel2;
619821
 
619821
@@ -2270,7 +2297,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count,
619821
             *eax = 0; /* Maximum ECX value for sub-leaves */
619821
             *ebx = env->features[FEAT_7_0_EBX]; /* Feature flags */
619821
             *ecx = env->features[FEAT_7_0_ECX]; /* Feature flags */
619821
-            *edx = 0; /* Reserved */
619821
+            *edx = env->features[FEAT_7_0_EDX]; /* Feature flags */
619821
         } else {
619821
             *eax = 0;
619821
             *ebx = 0;
619821
@@ -2680,6 +2707,8 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)
619821
         env->features[FEAT_8000_0001_ECX] &= TCG_EXT3_FEATURES;
619821
         env->features[FEAT_SVM] &= TCG_SVM_FEATURES;
619821
         env->features[FEAT_XSAVE] = 0;
619821
+        env->features[FEAT_7_0_ECX] &= TCG_7_0_ECX_FEATURES;
619821
+        env->features[FEAT_7_0_EDX] &= TCG_7_0_EDX_FEATURES;
619821
     } else {
619821
         if ((cpu->check_cpuid || cpu->enforce_cpuid)
619821
             && kvm_check_features_against_host(cpu) && cpu->enforce_cpuid) {
619821
diff --git a/target-i386/cpu.h b/target-i386/cpu.h
619821
index d541809..eec5c49 100644
619821
--- a/target-i386/cpu.h
619821
+++ b/target-i386/cpu.h
619821
@@ -401,6 +401,7 @@ typedef enum FeatureWord {
619821
     FEAT_1_ECX,         /* CPUID[1].ECX */
619821
     FEAT_7_0_EBX,       /* CPUID[EAX=7,ECX=0].EBX */
619821
     FEAT_7_0_ECX,       /* CPUID[EAX=7,ECX=0].ECX */
619821
+    FEAT_7_0_EDX,       /* CPUID[EAX=7,ECX=0].EDX */
619821
     FEAT_8000_0001_EDX, /* CPUID[8000_0001].EDX */
619821
     FEAT_8000_0001_ECX, /* CPUID[8000_0001].ECX */
619821
     FEAT_C000_0001_EDX, /* CPUID[C000_0001].EDX */
619821
@@ -580,6 +581,9 @@ typedef uint32_t FeatureWordArray[FEATURE_WORDS];
619821
 #define CPUID_7_0_ECX_OSPKE    (1U << 4)
619821
 #define CPUID_7_0_ECX_RDPID    (1U << 22)
619821
 
619821
+#define CPUID_7_0_EDX_AVX512_4VNNIW (1U << 2) /* AVX512 Neural Network Instructions */
619821
+#define CPUID_7_0_EDX_AVX512_4FMAPS (1U << 3) /* AVX512 Multiply Accumulation Single Precision */
619821
+
619821
 #define CPUID_XSAVE_XSAVEOPT   (1U << 0)
619821
 #define CPUID_XSAVE_XSAVEC     (1U << 1)
619821
 #define CPUID_XSAVE_XGETBV1    (1U << 2)
619821
-- 
619821
1.8.3.1
619821