Blame SOURCES/kvm-x86-Add-AMX-XTILECFG-and-XTILEDATA-components.patch

1be5c7
From 3ba6092159b6e3b25505af2a49c0f6ac99043db9 Mon Sep 17 00:00:00 2001
1be5c7
From: Jing Liu <jing2.liu@intel.com>
1be5c7
Date: Wed, 16 Feb 2022 22:04:28 -0800
1be5c7
Subject: [PATCH 06/24] x86: Add AMX XTILECFG and XTILEDATA components
1be5c7
1be5c7
RH-Author: Paul Lai <plai@redhat.com>
1be5c7
RH-MergeRequest: 176: Enable KVM AMX support
1be5c7
RH-Commit: [6/13] 95229f87b4494631d57232f374a174f7bc95843a
1be5c7
RH-Bugzilla: 1916415
1be5c7
RH-Acked-by: Cornelia Huck <cohuck@redhat.com>
1be5c7
RH-Acked-by: Igor Mammedov <imammedo@redhat.com>
1be5c7
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
1be5c7
1be5c7
The AMX TILECFG register and the TMMx tile data registers are
1be5c7
saved/restored via XSAVE, respectively in state component 17
1be5c7
(64 bytes) and state component 18 (8192 bytes).
1be5c7
1be5c7
Add AMX feature bits to x86_ext_save_areas array to set
1be5c7
up AMX components. Add structs that define the layout of
1be5c7
AMX XSAVE areas and use QEMU_BUILD_BUG_ON to validate the
1be5c7
structs sizes.
1be5c7
1be5c7
Signed-off-by: Jing Liu <jing2.liu@intel.com>
1be5c7
Signed-off-by: Yang Zhong <yang.zhong@intel.com>
1be5c7
Message-Id: <20220217060434.52460-3-yang.zhong@intel.com>
1be5c7
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1be5c7
(cherry picked from commit 1f16764f7d4515bfd5e4ae0aae814fa280a7d0c8)
1be5c7
Signed-off-by: Paul Lai <plai@redhat.com>
1be5c7
---
1be5c7
 target/i386/cpu.c |  8 ++++++++
1be5c7
 target/i386/cpu.h | 18 +++++++++++++++++-
1be5c7
 2 files changed, 25 insertions(+), 1 deletion(-)
1be5c7
1be5c7
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
1be5c7
index f44fad3a2a..0453c27c9d 100644
1be5c7
--- a/target/i386/cpu.c
1be5c7
+++ b/target/i386/cpu.c
1be5c7
@@ -1401,6 +1401,14 @@ ExtSaveArea x86_ext_save_areas[XSAVE_STATE_AREA_COUNT] = {
1be5c7
     [XSTATE_PKRU_BIT] =
1be5c7
           { .feature = FEAT_7_0_ECX, .bits = CPUID_7_0_ECX_PKU,
1be5c7
             .size = sizeof(XSavePKRU) },
1be5c7
+    [XSTATE_XTILE_CFG_BIT] = {
1be5c7
+        .feature = FEAT_7_0_EDX, .bits = CPUID_7_0_EDX_AMX_TILE,
1be5c7
+        .size = sizeof(XSaveXTILECFG),
1be5c7
+    },
1be5c7
+    [XSTATE_XTILE_DATA_BIT] = {
1be5c7
+        .feature = FEAT_7_0_EDX, .bits = CPUID_7_0_EDX_AMX_TILE,
1be5c7
+        .size = sizeof(XSaveXTILEDATA)
1be5c7
+    },
1be5c7
 };
1be5c7
 
1be5c7
 static uint32_t xsave_area_size(uint64_t mask)
1be5c7
diff --git a/target/i386/cpu.h b/target/i386/cpu.h
1be5c7
index 5d9702a991..e1dd8b9555 100644
1be5c7
--- a/target/i386/cpu.h
1be5c7
+++ b/target/i386/cpu.h
1be5c7
@@ -537,6 +537,8 @@ typedef enum X86Seg {
1be5c7
 #define XSTATE_ZMM_Hi256_BIT            6
1be5c7
 #define XSTATE_Hi16_ZMM_BIT             7
1be5c7
 #define XSTATE_PKRU_BIT                 9
1be5c7
+#define XSTATE_XTILE_CFG_BIT            17
1be5c7
+#define XSTATE_XTILE_DATA_BIT           18
1be5c7
 
1be5c7
 #define XSTATE_FP_MASK                  (1ULL << XSTATE_FP_BIT)
1be5c7
 #define XSTATE_SSE_MASK                 (1ULL << XSTATE_SSE_BIT)
1be5c7
@@ -845,6 +847,8 @@ typedef uint64_t FeatureWordArray[FEATURE_WORDS];
1be5c7
 #define CPUID_7_0_EDX_TSX_LDTRK         (1U << 16)
1be5c7
 /* AVX512_FP16 instruction */
1be5c7
 #define CPUID_7_0_EDX_AVX512_FP16       (1U << 23)
1be5c7
+/* AMX tile (two-dimensional register) */
1be5c7
+#define CPUID_7_0_EDX_AMX_TILE          (1U << 24)
1be5c7
 /* Speculation Control */
1be5c7
 #define CPUID_7_0_EDX_SPEC_CTRL         (1U << 26)
1be5c7
 /* Single Thread Indirect Branch Predictors */
1be5c7
@@ -1348,6 +1352,16 @@ typedef struct XSavePKRU {
1be5c7
     uint32_t padding;
1be5c7
 } XSavePKRU;
1be5c7
 
1be5c7
+/* Ext. save area 17: AMX XTILECFG state */
1be5c7
+typedef struct XSaveXTILECFG {
1be5c7
+    uint8_t xtilecfg[64];
1be5c7
+} XSaveXTILECFG;
1be5c7
+
1be5c7
+/* Ext. save area 18: AMX XTILEDATA state */
1be5c7
+typedef struct XSaveXTILEDATA {
1be5c7
+    uint8_t xtiledata[8][1024];
1be5c7
+} XSaveXTILEDATA;
1be5c7
+
1be5c7
 QEMU_BUILD_BUG_ON(sizeof(XSaveAVX) != 0x100);
1be5c7
 QEMU_BUILD_BUG_ON(sizeof(XSaveBNDREG) != 0x40);
1be5c7
 QEMU_BUILD_BUG_ON(sizeof(XSaveBNDCSR) != 0x40);
1be5c7
@@ -1355,6 +1369,8 @@ QEMU_BUILD_BUG_ON(sizeof(XSaveOpmask) != 0x40);
1be5c7
 QEMU_BUILD_BUG_ON(sizeof(XSaveZMM_Hi256) != 0x200);
1be5c7
 QEMU_BUILD_BUG_ON(sizeof(XSaveHi16_ZMM) != 0x400);
1be5c7
 QEMU_BUILD_BUG_ON(sizeof(XSavePKRU) != 0x8);
1be5c7
+QEMU_BUILD_BUG_ON(sizeof(XSaveXTILECFG) != 0x40);
1be5c7
+QEMU_BUILD_BUG_ON(sizeof(XSaveXTILEDATA) != 0x2000);
1be5c7
 
1be5c7
 typedef struct ExtSaveArea {
1be5c7
     uint32_t feature, bits;
1be5c7
@@ -1362,7 +1378,7 @@ typedef struct ExtSaveArea {
1be5c7
     uint32_t ecx;
1be5c7
 } ExtSaveArea;
1be5c7
 
1be5c7
-#define XSAVE_STATE_AREA_COUNT (XSTATE_PKRU_BIT + 1)
1be5c7
+#define XSAVE_STATE_AREA_COUNT (XSTATE_XTILE_DATA_BIT + 1)
1be5c7
 
1be5c7
 extern ExtSaveArea x86_ext_save_areas[XSAVE_STATE_AREA_COUNT];
1be5c7
 
1be5c7
-- 
1be5c7
2.35.3
1be5c7