yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-x86-cpu-Add-support-for-UMONITOR-UMWAIT-TPAUSE.patch

016a62
From 7e7c5dab29ed99bda0fb5d810db6f12ae4aa2608 Mon Sep 17 00:00:00 2001
016a62
From: "plai@redhat.com" <plai@redhat.com>
016a62
Date: Tue, 26 Nov 2019 18:36:54 +0000
016a62
Subject: [PATCH 10/11] x86/cpu: Add support for UMONITOR/UMWAIT/TPAUSE
016a62
MIME-Version: 1.0
016a62
Content-Type: text/plain; charset=UTF-8
016a62
Content-Transfer-Encoding: 8bit
016a62
016a62
x86/cpu: Add support for UMONITOR/UMWAIT/TPAUSE
016a62
016a62
RH-Author: plai@redhat.com
016a62
Message-id: <1574797015-32564-7-git-send-email-plai@redhat.com>
016a62
Patchwork-id: 92695
016a62
O-Subject: [RHEL8.2 qemu-kvm PATCH 6/7] x86/cpu: Add support for UMONITOR/UMWAIT/TPAUSE
016a62
Bugzilla: 1634827
016a62
RH-Acked-by: Eduardo Habkost <ehabkost@redhat.com>
016a62
RH-Acked-by: Michael S. Tsirkin <mst@redhat.com>
016a62
RH-Acked-by: Igor Mammedov <imammedo@redhat.com>
016a62
016a62
From: Tao Xu <tao3.xu@intel.com>
016a62
016a62
UMONITOR, UMWAIT and TPAUSE are a set of user wait instructions.
016a62
This patch adds support for user wait instructions in KVM. Availability
016a62
of the user wait instructions is indicated by the presence of the CPUID
016a62
feature flag WAITPKG CPUID.0x07.0x0:ECX[5]. User wait instructions may
016a62
be executed at any privilege level, and use IA32_UMWAIT_CONTROL MSR to
016a62
set the maximum time.
016a62
016a62
The patch enable the umonitor, umwait and tpause features in KVM.
016a62
Because umwait and tpause can put a (psysical) CPU into a power saving
016a62
state, by default we dont't expose it to kvm and enable it only when
016a62
guest CPUID has it. And use QEMU command-line "-overcommit cpu-pm=on"
016a62
(enable_cpu_pm is enabled), a VM can use UMONITOR, UMWAIT and TPAUSE
016a62
instructions. If the instruction causes a delay, the amount of time
016a62
delayed is called here the physical delay. The physical delay is first
016a62
computed by determining the virtual delay (the time to delay relative to
016a62
the VM’s timestamp counter). Otherwise, UMONITOR, UMWAIT and TPAUSE cause
016a62
an invalid-opcode exception(#UD).
016a62
016a62
The release document ref below link:
016a62
https://software.intel.com/sites/default/files/\
016a62
managed/39/c5/325462-sdm-vol-1-2abcd-3abcd.pdf
016a62
016a62
Co-developed-by: Jingqi Liu <jingqi.liu@intel.com>
016a62
Signed-off-by: Jingqi Liu <jingqi.liu@intel.com>
016a62
Signed-off-by: Tao Xu <tao3.xu@intel.com>
016a62
Message-Id: <20191011074103.30393-2-tao3.xu@intel.com>
016a62
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
016a62
(cherry picked from commit 67192a298f5bf98f96e5516c3b6474c49e4853cd)
016a62
Signed-off-by: Paul Lai <plai@redhat.com>
016a62
016a62
Resolved Conflicts:
016a62
	target/i386/cpu.c
016a62
	target/i386/cpu.h
016a62
016a62
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
016a62
---
016a62
 target/i386/cpu.c | 2 +-
016a62
 target/i386/cpu.h | 2 ++
016a62
 target/i386/kvm.c | 6 ++++++
016a62
 3 files changed, 9 insertions(+), 1 deletion(-)
016a62
016a62
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
016a62
index 87b0502..7d2afc7 100644
016a62
--- a/target/i386/cpu.c
016a62
+++ b/target/i386/cpu.c
016a62
@@ -1016,7 +1016,7 @@ static FeatureWordInfo feature_word_info[FEATURE_WORDS] = {
016a62
         .type = CPUID_FEATURE_WORD,
016a62
         .feat_names = {
016a62
             NULL, "avx512vbmi", "umip", "pku",
016a62
-            "ospke", NULL, "avx512vbmi2", NULL,
016a62
+            "ospke", "waitpkg", "avx512vbmi2", NULL,
016a62
             "gfni", "vaes", "vpclmulqdq", "avx512vnni",
016a62
             "avx512bitalg", NULL, "avx512-vpopcntdq", NULL,
016a62
             "la57", NULL, NULL, NULL,
016a62
diff --git a/target/i386/cpu.h b/target/i386/cpu.h
016a62
index 7ab8ee9..fac98aa 100644
016a62
--- a/target/i386/cpu.h
016a62
+++ b/target/i386/cpu.h
016a62
@@ -708,6 +708,8 @@ typedef uint64_t FeatureWordArray[FEATURE_WORDS];
016a62
 #define CPUID_7_0_ECX_UMIP     (1U << 2)
016a62
 #define CPUID_7_0_ECX_PKU      (1U << 3)
016a62
 #define CPUID_7_0_ECX_OSPKE    (1U << 4)
016a62
+/* UMONITOR/UMWAIT/TPAUSE Instructions */
016a62
+#define CPUID_7_0_ECX_WAITPKG  (1U << 5)
016a62
 #define CPUID_7_0_ECX_VBMI2    (1U << 6) /* Additional VBMI Instrs */
016a62
 #define CPUID_7_0_ECX_GFNI     (1U << 8)
016a62
 #define CPUID_7_0_ECX_VAES     (1U << 9)
016a62
diff --git a/target/i386/kvm.c b/target/i386/kvm.c
016a62
index ffd01f0..0fd5650 100644
016a62
--- a/target/i386/kvm.c
016a62
+++ b/target/i386/kvm.c
016a62
@@ -392,6 +392,12 @@ uint32_t kvm_arch_get_supported_cpuid(KVMState *s, uint32_t function,
016a62
         if (host_tsx_blacklisted()) {
016a62
             ret &= ~(CPUID_7_0_EBX_RTM | CPUID_7_0_EBX_HLE);
016a62
         }
016a62
+    } else if (function == 7 && index == 0 && reg == R_ECX) {
016a62
+        if (enable_cpu_pm) {
016a62
+            ret |= CPUID_7_0_ECX_WAITPKG;
016a62
+        } else {
016a62
+            ret &= ~CPUID_7_0_ECX_WAITPKG;
016a62
+        }
016a62
     } else if (function == 7 && index == 0 && reg == R_EDX) {
016a62
         /*
016a62
          * Linux v4.17-v4.20 incorrectly return ARCH_CAPABILITIES on SVM hosts.
016a62
-- 
016a62
1.8.3.1
016a62