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