cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-target-i386-Add-CPU-model-versions-supporting-xsaves.patch

a83cc2
From a7752067b45bc05f1127a62e39c38a3361bb1840 Mon Sep 17 00:00:00 2001
a83cc2
From: Vitaly Kuznetsov <vkuznets@redhat.com>
a83cc2
Date: Thu, 3 Jun 2021 14:04:18 -0400
a83cc2
Subject: [PATCH 07/21] target/i386: Add CPU model versions supporting 'xsaves'
a83cc2
MIME-Version: 1.0
a83cc2
Content-Type: text/plain; charset=UTF-8
a83cc2
Content-Transfer-Encoding: 8bit
a83cc2
a83cc2
RH-Author: Miroslav Rezanina <mrezanin@redhat.com>
a83cc2
RH-MergeRequest: 8: Synchronize with RHEL-AV 8.5 release 19 to RHEL 9
a83cc2
RH-Commit: [6/8] 814973113f19a21d10a90fcbbcd881eef354933d (mrezanin/centos-src-qemu-kvm)
a83cc2
RH-Bugzilla: 1957194
a83cc2
RH-Acked-by: Daniel P. Berrangé <berrange@redhat.com>
a83cc2
RH-Acked-by: Greg Kurz <gkurz@redhat.com>
a83cc2
RH-Acked-by: Laurent Vivier <lvivier@redhat.com>
a83cc2
RH-Acked-by: Vitaly Kuznetsov <vkuznets@redhat.com>
a83cc2
a83cc2
Hyper-V 2016 refuses to boot on Skylake+ CPU models because they lack
a83cc2
'xsaves'/'vmx-xsaves' features and this diverges from real hardware. The
a83cc2
same issue emerges with AMD "EPYC" CPU model prior to version 3 which got
a83cc2
'xsaves' added. EPYC-Rome/EPYC-Milan CPU models have 'xsaves' enabled from
a83cc2
the very beginning so the comment blaming KVM to explain why other CPUs
a83cc2
lack 'xsaves' is likely outdated.
a83cc2
a83cc2
Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
a83cc2
Message-Id: <20210412073952.860944-1-vkuznets@redhat.com>
a83cc2
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
a83cc2
(cherry picked from commit 7bde6b18575dd79c26ce1616e0c33151e83d9d7e)
a83cc2
a83cc2
Conflicts:
a83cc2
	target/i386/cpu.c (context, skipping c1826ea6a0520)
a83cc2
a83cc2
Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
a83cc2
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
a83cc2
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
a83cc2
---
a83cc2
 target/i386/cpu.c | 150 +++++++++++++++++++++++++++++-----------------
a83cc2
 1 file changed, 94 insertions(+), 56 deletions(-)
a83cc2
a83cc2
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
a83cc2
index c30bb2a6b0..da47c3e50e 100644
a83cc2
--- a/target/i386/cpu.c
a83cc2
+++ b/target/i386/cpu.c
a83cc2
@@ -2881,12 +2881,7 @@ static X86CPUDefinition builtin_x86_defs[] = {
a83cc2
             CPUID_7_0_EBX_BMI2 | CPUID_7_0_EBX_ERMS | CPUID_7_0_EBX_INVPCID |
a83cc2
             CPUID_7_0_EBX_RTM | CPUID_7_0_EBX_RDSEED | CPUID_7_0_EBX_ADX |
a83cc2
             CPUID_7_0_EBX_SMAP,
a83cc2
-        /* Missing: XSAVES (not supported by some Linux versions,
a83cc2
-         * including v4.1 to v4.12).
a83cc2
-         * KVM doesn't yet expose any XSAVES state save component,
a83cc2
-         * and the only one defined in Skylake (processor tracing)
a83cc2
-         * probably will block migration anyway.
a83cc2
-         */
a83cc2
+        /* XSAVES is added in version 4 */
a83cc2
         .features[FEAT_XSAVE] =
a83cc2
             CPUID_XSAVE_XSAVEOPT | CPUID_XSAVE_XSAVEC |
a83cc2
             CPUID_XSAVE_XGETBV1,
a83cc2
@@ -2962,6 +2957,15 @@ static X86CPUDefinition builtin_x86_defs[] = {
a83cc2
                     { /* end of list */ }
a83cc2
                 }
a83cc2
             },
a83cc2
+            {
a83cc2
+                .version = 4,
a83cc2
+                .note = "IBRS, XSAVES, no TSX",
a83cc2
+                .props = (PropValue[]) {
a83cc2
+                    { "xsaves", "on" },
a83cc2
+                    { "vmx-xsaves", "on" },
a83cc2
+                    { /* end of list */ }
a83cc2
+                }
a83cc2
+            },
a83cc2
             { /* end of list */ }
a83cc2
         }
a83cc2
     },
a83cc2
@@ -3001,12 +3005,7 @@ static X86CPUDefinition builtin_x86_defs[] = {
a83cc2
             CPUID_7_0_EBX_AVX512VL | CPUID_7_0_EBX_CLFLUSHOPT,
a83cc2
         .features[FEAT_7_0_ECX] =
a83cc2
             CPUID_7_0_ECX_PKU,
a83cc2
-        /* Missing: XSAVES (not supported by some Linux versions,
a83cc2
-         * including v4.1 to v4.12).
a83cc2
-         * KVM doesn't yet expose any XSAVES state save component,
a83cc2
-         * and the only one defined in Skylake (processor tracing)
a83cc2
-         * probably will block migration anyway.
a83cc2
-         */
a83cc2
+        /* XSAVES is added in version 5 */
a83cc2
         .features[FEAT_XSAVE] =
a83cc2
             CPUID_XSAVE_XSAVEOPT | CPUID_XSAVE_XSAVEC |
a83cc2
             CPUID_XSAVE_XGETBV1,
a83cc2
@@ -3094,6 +3093,15 @@ static X86CPUDefinition builtin_x86_defs[] = {
a83cc2
                     { /* end of list */ }
a83cc2
                 }
a83cc2
             },
a83cc2
+            {
a83cc2
+                .version = 5,
a83cc2
+                .note = "IBRS, XSAVES, EPT switching, no TSX",
a83cc2
+                .props = (PropValue[]) {
a83cc2
+                    { "xsaves", "on" },
a83cc2
+                    { "vmx-xsaves", "on" },
a83cc2
+                    { /* end of list */ }
a83cc2
+                }
a83cc2
+            },
a83cc2
             { /* end of list */ }
a83cc2
         }
a83cc2
     },
a83cc2
@@ -3136,12 +3144,7 @@ static X86CPUDefinition builtin_x86_defs[] = {
a83cc2
             CPUID_7_0_ECX_AVX512VNNI,
a83cc2
         .features[FEAT_7_0_EDX] =
a83cc2
             CPUID_7_0_EDX_SPEC_CTRL | CPUID_7_0_EDX_SPEC_CTRL_SSBD,
a83cc2
-        /* Missing: XSAVES (not supported by some Linux versions,
a83cc2
-                * including v4.1 to v4.12).
a83cc2
-                * KVM doesn't yet expose any XSAVES state save component,
a83cc2
-                * and the only one defined in Skylake (processor tracing)
a83cc2
-                * probably will block migration anyway.
a83cc2
-                */
a83cc2
+        /* XSAVES is added in version 5 */
a83cc2
         .features[FEAT_XSAVE] =
a83cc2
             CPUID_XSAVE_XSAVEOPT | CPUID_XSAVE_XSAVEC |
a83cc2
             CPUID_XSAVE_XGETBV1,
a83cc2
@@ -3225,6 +3228,14 @@ static X86CPUDefinition builtin_x86_defs[] = {
a83cc2
                   { /* end of list */ }
a83cc2
               },
a83cc2
             },
a83cc2
+            { .version = 5,
a83cc2
+              .note = "ARCH_CAPABILITIES, EPT switching, XSAVES, no TSX",
a83cc2
+              .props = (PropValue[]) {
a83cc2
+                  { "xsaves", "on" },
a83cc2
+                  { "vmx-xsaves", "on" },
a83cc2
+                  { /* end of list */ }
a83cc2
+              },
a83cc2
+            },
a83cc2
             { /* end of list */ }
a83cc2
         }
a83cc2
     },
a83cc2
@@ -3274,13 +3285,7 @@ static X86CPUDefinition builtin_x86_defs[] = {
a83cc2
             MSR_ARCH_CAP_PSCHANGE_MC_NO | MSR_ARCH_CAP_TAA_NO,
a83cc2
         .features[FEAT_7_1_EAX] =
a83cc2
             CPUID_7_1_EAX_AVX512_BF16,
a83cc2
-        /*
a83cc2
-         * Missing: XSAVES (not supported by some Linux versions,
a83cc2
-         * including v4.1 to v4.12).
a83cc2
-         * KVM doesn't yet expose any XSAVES state save component,
a83cc2
-         * and the only one defined in Skylake (processor tracing)
a83cc2
-         * probably will block migration anyway.
a83cc2
-         */
a83cc2
+        /* XSAVES is added in version 2 */
a83cc2
         .features[FEAT_XSAVE] =
a83cc2
             CPUID_XSAVE_XSAVEOPT | CPUID_XSAVE_XSAVEC |
a83cc2
             CPUID_XSAVE_XGETBV1,
a83cc2
@@ -3336,6 +3341,18 @@ static X86CPUDefinition builtin_x86_defs[] = {
a83cc2
         .features[FEAT_VMX_VMFUNC] = MSR_VMX_VMFUNC_EPT_SWITCHING,
a83cc2
         .xlevel = 0x80000008,
a83cc2
         .model_id = "Intel Xeon Processor (Cooperlake)",
a83cc2
+        .versions = (X86CPUVersionDefinition[]) {
a83cc2
+            { .version = 1 },
a83cc2
+            { .version = 2,
a83cc2
+              .note = "XSAVES",
a83cc2
+              .props = (PropValue[]) {
a83cc2
+                  { "xsaves", "on" },
a83cc2
+                  { "vmx-xsaves", "on" },
a83cc2
+                  { /* end of list */ }
a83cc2
+              },
a83cc2
+            },
a83cc2
+            { /* end of list */ }
a83cc2
+        }
a83cc2
     },
a83cc2
     {
a83cc2
         .name = "Icelake-Client",
a83cc2
@@ -3378,12 +3395,7 @@ static X86CPUDefinition builtin_x86_defs[] = {
a83cc2
             CPUID_7_0_ECX_AVX512_VPOPCNTDQ,
a83cc2
         .features[FEAT_7_0_EDX] =
a83cc2
             CPUID_7_0_EDX_SPEC_CTRL | CPUID_7_0_EDX_SPEC_CTRL_SSBD,
a83cc2
-        /* Missing: XSAVES (not supported by some Linux versions,
a83cc2
-                * including v4.1 to v4.12).
a83cc2
-                * KVM doesn't yet expose any XSAVES state save component,
a83cc2
-                * and the only one defined in Skylake (processor tracing)
a83cc2
-                * probably will block migration anyway.
a83cc2
-                */
a83cc2
+        /* XSAVES is added in version 3 */
a83cc2
         .features[FEAT_XSAVE] =
a83cc2
             CPUID_XSAVE_XSAVEOPT | CPUID_XSAVE_XSAVEC |
a83cc2
             CPUID_XSAVE_XGETBV1,
a83cc2
@@ -3451,6 +3463,15 @@ static X86CPUDefinition builtin_x86_defs[] = {
a83cc2
                     { /* end of list */ }
a83cc2
                 },
a83cc2
             },
a83cc2
+            {
a83cc2
+                .version = 3,
a83cc2
+                .note = "no TSX, XSAVES, deprecated",
a83cc2
+                .props = (PropValue[]) {
a83cc2
+                    { "xsaves", "on" },
a83cc2
+                    { "vmx-xsaves", "on" },
a83cc2
+                    { /* end of list */ }
a83cc2
+                },
a83cc2
+            },
a83cc2
             { /* end of list */ }
a83cc2
         },
a83cc2
         .deprecation_note = "use Icelake-Server instead"
a83cc2
@@ -3499,12 +3520,7 @@ static X86CPUDefinition builtin_x86_defs[] = {
a83cc2
             CPUID_7_0_ECX_AVX512_VPOPCNTDQ | CPUID_7_0_ECX_LA57,
a83cc2
         .features[FEAT_7_0_EDX] =
a83cc2
             CPUID_7_0_EDX_SPEC_CTRL | CPUID_7_0_EDX_SPEC_CTRL_SSBD,
a83cc2
-        /* Missing: XSAVES (not supported by some Linux versions,
a83cc2
-                * including v4.1 to v4.12).
a83cc2
-                * KVM doesn't yet expose any XSAVES state save component,
a83cc2
-                * and the only one defined in Skylake (processor tracing)
a83cc2
-                * probably will block migration anyway.
a83cc2
-                */
a83cc2
+        /* XSAVES is added in version 5 */
a83cc2
         .features[FEAT_XSAVE] =
a83cc2
             CPUID_XSAVE_XSAVEOPT | CPUID_XSAVE_XSAVEC |
a83cc2
             CPUID_XSAVE_XGETBV1,
a83cc2
@@ -3597,6 +3613,15 @@ static X86CPUDefinition builtin_x86_defs[] = {
a83cc2
                     { /* end of list */ }
a83cc2
                 },
a83cc2
             },
a83cc2
+            {
a83cc2
+                .version = 5,
a83cc2
+                .note = "XSAVES",
a83cc2
+                .props = (PropValue[]) {
a83cc2
+                    { "xsaves", "on" },
a83cc2
+                    { "vmx-xsaves", "on" },
a83cc2
+                    { /* end of list */ }
a83cc2
+                },
a83cc2
+            },
a83cc2
             { /* end of list */ }
a83cc2
         }
a83cc2
     },
a83cc2
@@ -3631,13 +3656,7 @@ static X86CPUDefinition builtin_x86_defs[] = {
a83cc2
         .features[FEAT_7_0_EDX] =
a83cc2
             CPUID_7_0_EDX_SPEC_CTRL | CPUID_7_0_EDX_ARCH_CAPABILITIES |
a83cc2
             CPUID_7_0_EDX_SPEC_CTRL_SSBD,
a83cc2
-        /*
a83cc2
-         * Missing: XSAVES (not supported by some Linux versions,
a83cc2
-         * including v4.1 to v4.12).
a83cc2
-         * KVM doesn't yet expose any XSAVES state save component,
a83cc2
-         * and the only one defined in Skylake (processor tracing)
a83cc2
-         * probably will block migration anyway.
a83cc2
-         */
a83cc2
+        /* XSAVES is added in version 3 */
a83cc2
         .features[FEAT_XSAVE] =
a83cc2
             CPUID_XSAVE_XSAVEOPT | CPUID_XSAVE_XSAVEC | CPUID_XSAVE_XGETBV1,
a83cc2
         .features[FEAT_6_EAX] =
a83cc2
@@ -3704,6 +3723,15 @@ static X86CPUDefinition builtin_x86_defs[] = {
a83cc2
                     { /* end of list */ },
a83cc2
                 },
a83cc2
             },
a83cc2
+            {
a83cc2
+                .version = 3,
a83cc2
+                .note = "XSAVES, no MPX, no MONITOR",
a83cc2
+                .props = (PropValue[]) {
a83cc2
+                    { "xsaves", "on" },
a83cc2
+                    { "vmx-xsaves", "on" },
a83cc2
+                    { /* end of list */ },
a83cc2
+                },
a83cc2
+            },
a83cc2
             { /* end of list */ },
a83cc2
         },
a83cc2
     },
a83cc2
@@ -3762,13 +3790,7 @@ static X86CPUDefinition builtin_x86_defs[] = {
a83cc2
             CPUID_7_0_EDX_CORE_CAPABILITY,
a83cc2
         .features[FEAT_CORE_CAPABILITY] =
a83cc2
             MSR_CORE_CAP_SPLIT_LOCK_DETECT,
a83cc2
-        /*
a83cc2
-         * Missing: XSAVES (not supported by some Linux versions,
a83cc2
-         * including v4.1 to v4.12).
a83cc2
-         * KVM doesn't yet expose any XSAVES state save component,
a83cc2
-         * and the only one defined in Skylake (processor tracing)
a83cc2
-         * probably will block migration anyway.
a83cc2
-         */
a83cc2
+        /* XSAVES is is added in version 3 */
a83cc2
         .features[FEAT_XSAVE] =
a83cc2
             CPUID_XSAVE_XSAVEOPT | CPUID_XSAVE_XSAVEC |
a83cc2
             CPUID_XSAVE_XGETBV1,
a83cc2
@@ -3833,6 +3855,15 @@ static X86CPUDefinition builtin_x86_defs[] = {
a83cc2
                     { /* end of list */ },
a83cc2
                 },
a83cc2
             },
a83cc2
+            {
a83cc2
+                .version = 3,
a83cc2
+                .note = "XSAVES, no MPX",
a83cc2
+                .props = (PropValue[]) {
a83cc2
+                    { "xsaves", "on" },
a83cc2
+                    { "vmx-xsaves", "on" },
a83cc2
+                    { /* end of list */ },
a83cc2
+                },
a83cc2
+            },
a83cc2
             { /* end of list */ },
a83cc2
         },
a83cc2
     },
a83cc2
@@ -4114,11 +4145,7 @@ static X86CPUDefinition builtin_x86_defs[] = {
a83cc2
             CPUID_7_0_EBX_FSGSBASE | CPUID_7_0_EBX_BMI1 | CPUID_7_0_EBX_AVX2 |
a83cc2
             CPUID_7_0_EBX_SMEP | CPUID_7_0_EBX_BMI2 | CPUID_7_0_EBX_RDSEED |
a83cc2
             CPUID_7_0_EBX_ADX | CPUID_7_0_EBX_SMAP | CPUID_7_0_EBX_CLFLUSHOPT,
a83cc2
-        /*
a83cc2
-         * Missing: XSAVES (not supported by some Linux versions,
a83cc2
-         * including v4.1 to v4.12).
a83cc2
-         * KVM doesn't yet expose any XSAVES state save component.
a83cc2
-         */
a83cc2
+        /* XSAVES is added in version 2 */
a83cc2
         .features[FEAT_XSAVE] =
a83cc2
             CPUID_XSAVE_XSAVEOPT | CPUID_XSAVE_XSAVEC |
a83cc2
             CPUID_XSAVE_XGETBV1,
a83cc2
@@ -4129,6 +4156,17 @@ static X86CPUDefinition builtin_x86_defs[] = {
a83cc2
         .xlevel = 0x8000001E,
a83cc2
         .model_id = "Hygon Dhyana Processor",
a83cc2
         .cache_info = &epyc_cache_info,
a83cc2
+        .versions = (X86CPUVersionDefinition[]) {
a83cc2
+            { .version = 1 },
a83cc2
+            { .version = 2,
a83cc2
+              .note = "XSAVES",
a83cc2
+              .props = (PropValue[]) {
a83cc2
+                  { "xsaves", "on" },
a83cc2
+                  { /* end of list */ }
a83cc2
+              },
a83cc2
+            },
a83cc2
+            { /* end of list */ }
a83cc2
+        }
a83cc2
     },
a83cc2
     {
a83cc2
         .name = "EPYC-Rome",
a83cc2
-- 
a83cc2
2.27.0
a83cc2