ae23c9
From 766a7ab6a7ebb9e819f6ec9a9b109ec4659388d4 Mon Sep 17 00:00:00 2001
ae23c9
From: Eduardo Habkost <ehabkost@redhat.com>
ae23c9
Date: Thu, 9 May 2019 23:21:08 +0100
ae23c9
Subject: [PATCH 2/2] i386: Disable OSPKE on CPU model definitions
ae23c9
ae23c9
RH-Author: Eduardo Habkost <ehabkost@redhat.com>
ae23c9
Message-id: <20190509232108.25675-3-ehabkost@redhat.com>
ae23c9
Patchwork-id: 87254
ae23c9
O-Subject: [RHEL-8.1.0 qemu-kvm PATCH 2/2] i386: Disable OSPKE on CPU model definitions
ae23c9
Bugzilla: 1561761
ae23c9
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
ae23c9
RH-Acked-by: Igor Mammedov <imammedo@redhat.com>
ae23c9
RH-Acked-by: Danilo de Paula <ddepaula@redhat.com>
ae23c9
ae23c9
Currently, the Cascadelake-Server, Icelake-Client, and
ae23c9
Icelake-Server are always generating the following warning:
ae23c9
ae23c9
  qemu-system-x86_64: warning: \
ae23c9
    host doesn't support requested feature: CPUID.07H:ECX [bit 4]
ae23c9
ae23c9
This happens because OSPKE was never returned by
ae23c9
GET_SUPPORTED_CPUID or x86_cpu_get_supported_feature_word().
ae23c9
OSPKE is a runtime flag automatically set by the KVM module or by
ae23c9
TCG code, was always cleared by x86_cpu_filter_features(), and
ae23c9
was not supposed to appear on the CPU model table.
ae23c9
ae23c9
Remove the OSPKE flag from the CPU model table entries, to avoid
ae23c9
the bogus warning and avoid returning invalid feature data on
ae23c9
query-cpu-* QMP commands.  As OSPKE was always cleared by
ae23c9
x86_cpu_filter_features(), this won't have any guest-visible
ae23c9
impact.
ae23c9
ae23c9
Include a test case that should detect the problem if we introduce
ae23c9
a similar bug again.
ae23c9
ae23c9
Fixes: c7a88b52f62b ("i386: Add new model of Cascadelake-Server")
ae23c9
Fixes: 8a11c62da914 ("i386: Add new CPU model Icelake-{Server,Client}")
ae23c9
Cc: Tao Xu <tao3.xu@intel.com>
ae23c9
Cc: Robert Hoo <robert.hu@linux.intel.com>
ae23c9
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
ae23c9
Message-Id: <20190319200515.14999-1-ehabkost@redhat.com>
ae23c9
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
ae23c9
(cherry picked from commit bb4928c7cafe50ab2137a0034e350ef1bfa044d9)
ae23c9
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
ae23c9
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
ae23c9
---
ae23c9
 target/i386/cpu.c               |  4 ++--
ae23c9
 tests/acceptance/cpu_queries.py | 33 +++++++++++++++++++++++++++++++++
ae23c9
 2 files changed, 35 insertions(+), 2 deletions(-)
ae23c9
 create mode 100644 tests/acceptance/cpu_queries.py
ae23c9
ae23c9
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
ae23c9
index c56d7e7..8ff6c38 100644
ae23c9
--- a/target/i386/cpu.c
ae23c9
+++ b/target/i386/cpu.c
ae23c9
@@ -2518,7 +2518,7 @@ static X86CPUDefinition builtin_x86_defs[] = {
ae23c9
             CPUID_7_0_EBX_SMAP | CPUID_7_0_EBX_MPX,
ae23c9
         .features[FEAT_7_0_ECX] =
ae23c9
             CPUID_7_0_ECX_VBMI | CPUID_7_0_ECX_UMIP | CPUID_7_0_ECX_PKU |
ae23c9
-            CPUID_7_0_ECX_OSPKE | CPUID_7_0_ECX_VBMI2 | CPUID_7_0_ECX_GFNI |
ae23c9
+            CPUID_7_0_ECX_VBMI2 | CPUID_7_0_ECX_GFNI |
ae23c9
             CPUID_7_0_ECX_VAES | CPUID_7_0_ECX_VPCLMULQDQ |
ae23c9
             CPUID_7_0_ECX_AVX512VNNI | CPUID_7_0_ECX_AVX512BITALG |
ae23c9
             CPUID_7_0_ECX_AVX512_VPOPCNTDQ,
ae23c9
@@ -2576,7 +2576,7 @@ static X86CPUDefinition builtin_x86_defs[] = {
ae23c9
             CPUID_7_0_EBX_AVX512VL | CPUID_7_0_EBX_CLFLUSHOPT,
ae23c9
         .features[FEAT_7_0_ECX] =
ae23c9
             CPUID_7_0_ECX_VBMI | CPUID_7_0_ECX_UMIP | CPUID_7_0_ECX_PKU |
ae23c9
-            CPUID_7_0_ECX_OSPKE | CPUID_7_0_ECX_VBMI2 | CPUID_7_0_ECX_GFNI |
ae23c9
+            CPUID_7_0_ECX_VBMI2 | CPUID_7_0_ECX_GFNI |
ae23c9
             CPUID_7_0_ECX_VAES | CPUID_7_0_ECX_VPCLMULQDQ |
ae23c9
             CPUID_7_0_ECX_AVX512VNNI | CPUID_7_0_ECX_AVX512BITALG |
ae23c9
             CPUID_7_0_ECX_AVX512_VPOPCNTDQ | CPUID_7_0_ECX_LA57,
ae23c9
diff --git a/tests/acceptance/cpu_queries.py b/tests/acceptance/cpu_queries.py
ae23c9
new file mode 100644
ae23c9
index 0000000..e71edec
ae23c9
--- /dev/null
ae23c9
+++ b/tests/acceptance/cpu_queries.py
ae23c9
@@ -0,0 +1,33 @@
ae23c9
+# Sanity check of query-cpu-* results
ae23c9
+#
ae23c9
+# Copyright (c) 2019 Red Hat, Inc.
ae23c9
+#
ae23c9
+# Author:
ae23c9
+#  Eduardo Habkost <ehabkost@redhat.com>
ae23c9
+#
ae23c9
+# This work is licensed under the terms of the GNU GPL, version 2 or
ae23c9
+# later.  See the COPYING file in the top-level directory.
ae23c9
+
ae23c9
+import logging
ae23c9
+
ae23c9
+from avocado_qemu import Test
ae23c9
+
ae23c9
+class QueryCPUModelExpansion(Test):
ae23c9
+    """
ae23c9
+    Run query-cpu-model-expansion for each CPU model, and validate results
ae23c9
+    """
ae23c9
+
ae23c9
+    def test(self):
ae23c9
+        self.vm.set_machine('none')
ae23c9
+        self.vm.add_args('-S')
ae23c9
+        self.vm.launch()
ae23c9
+
ae23c9
+        cpus = self.vm.command('query-cpu-definitions')
ae23c9
+        for c in cpus:
ae23c9
+            print(repr(c))
ae23c9
+            self.assertNotIn('', c['unavailable-features'], c['name'])
ae23c9
+
ae23c9
+        for c in cpus:
ae23c9
+            model = {'name': c['name']}
ae23c9
+            e = self.vm.command('query-cpu-model-expansion', model=model, type='full')
ae23c9
+            self.assertEquals(e['model']['name'], c['name'])
ae23c9
-- 
ae23c9
1.8.3.1
ae23c9