thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone
Pablo Greco e6a3ae
From b6b9ed9623f87d1a2b574c8010685e68ac4cd669 Mon Sep 17 00:00:00 2001
Pablo Greco e6a3ae
From: "plai@redhat.com" <plai@redhat.com>
Pablo Greco e6a3ae
Date: Mon, 4 Nov 2019 17:35:19 +0000
Pablo Greco e6a3ae
Subject: [PATCH 2/2] x86: Intel AVX512_BF16 feature enabling
Pablo Greco e6a3ae
Pablo Greco e6a3ae
RH-Author: plai@redhat.com
Pablo Greco e6a3ae
Message-id: <1572888919-16839-1-git-send-email-plai@redhat.com>
Pablo Greco e6a3ae
Patchwork-id: 92026
Pablo Greco e6a3ae
O-Subject: [RHEL8.2 qemu-kvm PATCH] x86: Intel AVX512_BF16 feature enabling
Pablo Greco e6a3ae
Bugzilla: 1642541
Pablo Greco e6a3ae
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
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: Jing Liu <jing2.liu@linux.intel.com>
Pablo Greco e6a3ae
Pablo Greco e6a3ae
BZ: https://bugzilla.redhat.com/show_bug.cgi?id=1642541
Pablo Greco e6a3ae
Brew: http://brewweb.devel.redhat.com/brew/taskinfo?taskID=23221805
Pablo Greco e6a3ae
Branch: rhel-8.2.0
Pablo Greco e6a3ae
Pablo Greco e6a3ae
---
Pablo Greco e6a3ae
Pablo Greco e6a3ae
Intel CooperLake cpu adds AVX512_BF16 instruction, defining as
Pablo Greco e6a3ae
CPUID.(EAX=7,ECX=1):EAX[bit 05].
Pablo Greco e6a3ae
Pablo Greco e6a3ae
The patch adds a property for setting the subleaf of CPUID leaf 7 in
Pablo Greco e6a3ae
case that people would like to specify it.
Pablo Greco e6a3ae
Pablo Greco e6a3ae
The release spec link as follows,
Pablo Greco e6a3ae
https://software.intel.com/sites/default/files/managed/c5/15/\
Pablo Greco e6a3ae
architecture-instruction-set-extensions-programming-reference.pdf
Pablo Greco e6a3ae
Pablo Greco e6a3ae
Signed-off-by: Jing Liu <jing2.liu@linux.intel.com>
Pablo Greco e6a3ae
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Pablo Greco e6a3ae
(cherry picked from commit 80db491da4ce8b199e0e8d1e23943b20aab82f69)
Pablo Greco e6a3ae
Signed-off-by: Paul Lai <plai@redhat.com>
Pablo Greco e6a3ae
Pablo Greco e6a3ae
Resovled Conflicts:
Pablo Greco e6a3ae
	target/i386/cpu.h
Pablo Greco e6a3ae
Pablo Greco e6a3ae
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
Pablo Greco e6a3ae
---
Pablo Greco e6a3ae
 target/i386/cpu.c | 39 ++++++++++++++++++++++++++++++++++++++-
Pablo Greco e6a3ae
 target/i386/cpu.h |  6 ++++++
Pablo Greco e6a3ae
 target/i386/kvm.c |  3 ++-
Pablo Greco e6a3ae
 3 files changed, 46 insertions(+), 2 deletions(-)
Pablo Greco e6a3ae
Pablo Greco e6a3ae
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
Pablo Greco e6a3ae
index 7d2afc7..0717c66 100644
Pablo Greco e6a3ae
--- a/target/i386/cpu.c
Pablo Greco e6a3ae
+++ b/target/i386/cpu.c
Pablo Greco e6a3ae
@@ -767,6 +767,7 @@ static void x86_cpu_vendor_words2str(char *dst, uint32_t vendor1,
Pablo Greco e6a3ae
 #define TCG_7_0_ECX_FEATURES (CPUID_7_0_ECX_PKU | CPUID_7_0_ECX_OSPKE | \
Pablo Greco e6a3ae
           CPUID_7_0_ECX_LA57)
Pablo Greco e6a3ae
 #define TCG_7_0_EDX_FEATURES 0
Pablo Greco e6a3ae
+#define TCG_7_1_EAX_FEATURES 0
Pablo Greco e6a3ae
 #define TCG_APM_FEATURES 0
Pablo Greco e6a3ae
 #define TCG_6_EAX_FEATURES CPUID_6_EAX_ARAT
Pablo Greco e6a3ae
 #define TCG_XSAVE_FEATURES (CPUID_XSAVE_XSAVEOPT | CPUID_XSAVE_XGETBV1)
Pablo Greco e6a3ae
@@ -1050,6 +1051,25 @@ static FeatureWordInfo feature_word_info[FEATURE_WORDS] = {
Pablo Greco e6a3ae
         },
Pablo Greco e6a3ae
         .tcg_features = TCG_7_0_EDX_FEATURES,
Pablo Greco e6a3ae
     },
Pablo Greco e6a3ae
+    [FEAT_7_1_EAX] = {
Pablo Greco e6a3ae
+        .type = CPUID_FEATURE_WORD,
Pablo Greco e6a3ae
+        .feat_names = {
Pablo Greco e6a3ae
+            NULL, NULL, NULL, NULL,
Pablo Greco e6a3ae
+            NULL, "avx512-bf16", NULL, NULL,
Pablo Greco e6a3ae
+            NULL, NULL, NULL, NULL,
Pablo Greco e6a3ae
+            NULL, NULL, NULL, NULL,
Pablo Greco e6a3ae
+            NULL, NULL, NULL, NULL,
Pablo Greco e6a3ae
+            NULL, NULL, NULL, NULL,
Pablo Greco e6a3ae
+            NULL, NULL, NULL, NULL,
Pablo Greco e6a3ae
+            NULL, NULL, NULL, NULL,
Pablo Greco e6a3ae
+        },
Pablo Greco e6a3ae
+        .cpuid = {
Pablo Greco e6a3ae
+            .eax = 7,
Pablo Greco e6a3ae
+            .needs_ecx = true, .ecx = 1,
Pablo Greco e6a3ae
+            .reg = R_EAX,
Pablo Greco e6a3ae
+        },
Pablo Greco e6a3ae
+        .tcg_features = TCG_7_1_EAX_FEATURES,
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
@@ -5678,13 +5698,19 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count,
Pablo Greco e6a3ae
     case 7:
Pablo Greco e6a3ae
         /* Structured Extended Feature Flags Enumeration Leaf */
Pablo Greco e6a3ae
         if (count == 0) {
Pablo Greco e6a3ae
-            *eax = 0; /* Maximum ECX value for sub-leaves */
Pablo Greco e6a3ae
+            /* Maximum ECX value for sub-leaves */
Pablo Greco e6a3ae
+            *eax = env->cpuid_level_func7;
Pablo Greco e6a3ae
             *ebx = env->features[FEAT_7_0_EBX]; /* Feature flags */
Pablo Greco e6a3ae
             *ecx = env->features[FEAT_7_0_ECX]; /* Feature flags */
Pablo Greco e6a3ae
             if ((*ecx & CPUID_7_0_ECX_PKU) && env->cr[4] & CR4_PKE_MASK) {
Pablo Greco e6a3ae
                 *ecx |= CPUID_7_0_ECX_OSPKE;
Pablo Greco e6a3ae
             }
Pablo Greco e6a3ae
             *edx = env->features[FEAT_7_0_EDX]; /* Feature flags */
Pablo Greco e6a3ae
+        } else if (count == 1) {
Pablo Greco e6a3ae
+            *eax = env->features[FEAT_7_1_EAX];
Pablo Greco e6a3ae
+            *ebx = 0;
Pablo Greco e6a3ae
+            *ecx = 0;
Pablo Greco e6a3ae
+            *edx = 0;
Pablo Greco e6a3ae
         } else {
Pablo Greco e6a3ae
             *eax = 0;
Pablo Greco e6a3ae
             *ebx = 0;
Pablo Greco e6a3ae
@@ -6289,6 +6315,11 @@ static void x86_cpu_adjust_feat_level(X86CPU *cpu, FeatureWord w)
Pablo Greco e6a3ae
         x86_cpu_adjust_level(cpu, &env->cpuid_min_xlevel2, eax);
Pablo Greco e6a3ae
     break;
Pablo Greco e6a3ae
     }
Pablo Greco e6a3ae
+
Pablo Greco e6a3ae
+    if (eax == 7) {
Pablo Greco e6a3ae
+        x86_cpu_adjust_level(cpu, &env->cpuid_min_level_func7,
Pablo Greco e6a3ae
+                             fi->cpuid.ecx);
Pablo Greco e6a3ae
+    }
Pablo Greco e6a3ae
 }
Pablo Greco e6a3ae
 
Pablo Greco e6a3ae
 /* Calculate XSAVE components based on the configured CPU feature flags */
Pablo Greco e6a3ae
@@ -6423,6 +6454,7 @@ static void x86_cpu_expand_features(X86CPU *cpu, Error **errp)
Pablo Greco e6a3ae
         x86_cpu_adjust_feat_level(cpu, FEAT_1_ECX);
Pablo Greco e6a3ae
         x86_cpu_adjust_feat_level(cpu, FEAT_6_EAX);
Pablo Greco e6a3ae
         x86_cpu_adjust_feat_level(cpu, FEAT_7_0_ECX);
Pablo Greco e6a3ae
+        x86_cpu_adjust_feat_level(cpu, FEAT_7_1_EAX);
Pablo Greco e6a3ae
         x86_cpu_adjust_feat_level(cpu, FEAT_8000_0001_EDX);
Pablo Greco e6a3ae
         x86_cpu_adjust_feat_level(cpu, FEAT_8000_0001_ECX);
Pablo Greco e6a3ae
         x86_cpu_adjust_feat_level(cpu, FEAT_8000_0007_EDX);
Pablo Greco e6a3ae
@@ -6442,6 +6474,9 @@ static void x86_cpu_expand_features(X86CPU *cpu, Error **errp)
Pablo Greco e6a3ae
     }
Pablo Greco e6a3ae
 
Pablo Greco e6a3ae
     /* Set cpuid_*level* based on cpuid_min_*level, if not explicitly set */
Pablo Greco e6a3ae
+    if (env->cpuid_level_func7 == UINT32_MAX) {
Pablo Greco e6a3ae
+        env->cpuid_level_func7 = env->cpuid_min_level_func7;
Pablo Greco e6a3ae
+    }
Pablo Greco e6a3ae
     if (env->cpuid_level == UINT32_MAX) {
Pablo Greco e6a3ae
         env->cpuid_level = env->cpuid_min_level;
Pablo Greco e6a3ae
     }
Pablo Greco e6a3ae
@@ -7150,6 +7185,8 @@ static Property x86_cpu_properties[] = {
Pablo Greco e6a3ae
     DEFINE_PROP_BOOL("host-phys-bits", X86CPU, host_phys_bits, false),
Pablo Greco e6a3ae
     DEFINE_PROP_UINT8("host-phys-bits-limit", X86CPU, host_phys_bits_limit, 0),
Pablo Greco e6a3ae
     DEFINE_PROP_BOOL("fill-mtrr-mask", X86CPU, fill_mtrr_mask, true),
Pablo Greco e6a3ae
+    DEFINE_PROP_UINT32("level-func7", X86CPU, env.cpuid_level_func7,
Pablo Greco e6a3ae
+                       UINT32_MAX),
Pablo Greco e6a3ae
     DEFINE_PROP_UINT32("level", X86CPU, env.cpuid_level, UINT32_MAX),
Pablo Greco e6a3ae
     DEFINE_PROP_UINT32("xlevel", X86CPU, env.cpuid_xlevel, UINT32_MAX),
Pablo Greco e6a3ae
     DEFINE_PROP_UINT32("xlevel2", X86CPU, env.cpuid_xlevel2, UINT32_MAX),
Pablo Greco e6a3ae
diff --git a/target/i386/cpu.h b/target/i386/cpu.h
Pablo Greco e6a3ae
index ecbe4f0..43a5ae0 100644
Pablo Greco e6a3ae
--- a/target/i386/cpu.h
Pablo Greco e6a3ae
+++ b/target/i386/cpu.h
Pablo Greco e6a3ae
@@ -509,6 +509,7 @@ typedef enum FeatureWord {
Pablo Greco e6a3ae
     FEAT_7_0_EBX,       /* CPUID[EAX=7,ECX=0].EBX */
Pablo Greco e6a3ae
     FEAT_7_0_ECX,       /* CPUID[EAX=7,ECX=0].ECX */
Pablo Greco e6a3ae
     FEAT_7_0_EDX,       /* CPUID[EAX=7,ECX=0].EDX */
Pablo Greco e6a3ae
+    FEAT_7_1_EAX,       /* CPUID[EAX=7,ECX=1].EAX */
Pablo Greco e6a3ae
     FEAT_8000_0001_EDX, /* CPUID[8000_0001].EDX */
Pablo Greco e6a3ae
     FEAT_8000_0001_ECX, /* CPUID[8000_0001].ECX */
Pablo Greco e6a3ae
     FEAT_8000_0007_EDX, /* CPUID[8000_0007].EDX */
Pablo Greco e6a3ae
@@ -732,6 +733,7 @@ typedef uint64_t FeatureWordArray[FEATURE_WORDS];
Pablo Greco e6a3ae
 #define CPUID_7_0_EDX_SPEC_CTRL_SSBD  (1U << 31) /* Speculative Store Bypass Disable */
Pablo Greco e6a3ae
 
Pablo Greco e6a3ae
 #define KVM_HINTS_DEDICATED (1U << 0)
Pablo Greco e6a3ae
+#define CPUID_7_1_EAX_AVX512_BF16 (1U << 5) /* AVX512 BFloat16 Instruction */
Pablo Greco e6a3ae
 
Pablo Greco e6a3ae
 #define CPUID_8000_0008_EBX_WBNOINVD  (1U << 9)  /* Write back and
Pablo Greco e6a3ae
                                                                              do not invalidate cache */
Pablo Greco e6a3ae
@@ -1451,6 +1453,10 @@ typedef struct CPUX86State {
Pablo Greco e6a3ae
     /* Fields after CPU_COMMON are preserved across CPU reset. */
Pablo Greco e6a3ae
 
Pablo Greco e6a3ae
     /* processor features (e.g. for CPUID insn) */
Pablo Greco e6a3ae
+    /* Minimum cpuid leaf 7 value */
Pablo Greco e6a3ae
+    uint32_t cpuid_level_func7;
Pablo Greco e6a3ae
+    /* Actual cpuid leaf 7 value */
Pablo Greco e6a3ae
+    uint32_t cpuid_min_level_func7;
Pablo Greco e6a3ae
     /* Minimum level/xlevel/xlevel2, based on CPU model + features */
Pablo Greco e6a3ae
     uint32_t cpuid_min_level, cpuid_min_xlevel, cpuid_min_xlevel2;
Pablo Greco e6a3ae
     /* Maximum level/xlevel/xlevel2 value for auto-assignment: */
Pablo Greco e6a3ae
diff --git a/target/i386/kvm.c b/target/i386/kvm.c
Pablo Greco e6a3ae
index ad58bfb..92eda8d 100644
Pablo Greco e6a3ae
--- a/target/i386/kvm.c
Pablo Greco e6a3ae
+++ b/target/i386/kvm.c
Pablo Greco e6a3ae
@@ -1058,6 +1058,7 @@ int kvm_arch_init_vcpu(CPUState *cs)
Pablo Greco e6a3ae
                 c = &cpuid_data.entries[cpuid_i++];
Pablo Greco e6a3ae
             }
Pablo Greco e6a3ae
             break;
Pablo Greco e6a3ae
+        case 0x7:
Pablo Greco e6a3ae
         case 0x14: {
Pablo Greco e6a3ae
             uint32_t times;
Pablo Greco e6a3ae
 
Pablo Greco e6a3ae
@@ -1070,7 +1071,7 @@ int kvm_arch_init_vcpu(CPUState *cs)
Pablo Greco e6a3ae
             for (j = 1; j <= times; ++j) {
Pablo Greco e6a3ae
                 if (cpuid_i == KVM_MAX_CPUID_ENTRIES) {
Pablo Greco e6a3ae
                     fprintf(stderr, "cpuid_data is full, no space for "
Pablo Greco e6a3ae
-                                "cpuid(eax:0x14,ecx:0x%x)\n", j);
Pablo Greco e6a3ae
+                                "cpuid(eax:0x%x,ecx:0x%x)\n", i, j);
Pablo Greco e6a3ae
                     abort();
Pablo Greco e6a3ae
                 }
Pablo Greco e6a3ae
                 c = &cpuid_data.entries[cpuid_i++];
Pablo Greco e6a3ae
-- 
Pablo Greco e6a3ae
1.8.3.1
Pablo Greco e6a3ae