Blame SOURCES/kvm-i386-halt-poll-control-MSR-support.patch

8b1478
From ebfeb40743756dfa7087b43ce4e9afe3e85f9710 Mon Sep 17 00:00:00 2001
8b1478
From: Marcelo Tosatti <mtosatti@redhat.com>
8b1478
Date: Wed, 28 Aug 2019 01:00:55 +0200
8b1478
Subject: [PATCH 1/4] kvm: i386: halt poll control MSR support
8b1478
8b1478
RH-Author: Marcelo Tosatti <mtosatti@redhat.com>
8b1478
Message-id: <20190828010051.GA30252@amt.cnet>
8b1478
Patchwork-id: 90171
8b1478
O-Subject: [RHEL-7.8 qemu-kvm PATCH] kvm: i386: halt poll control MSR support
8b1478
Bugzilla: 1734502
8b1478
RH-Acked-by: Eduardo Habkost <ehabkost@redhat.com>
8b1478
RH-Acked-by: Igor Mammedov <imammedo@redhat.com>
8b1478
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
8b1478
8b1478
This is the qemu part of the haltpoll driver: allows migrating
8b1478
the MSR which the guest uses to disable host side polling.
8b1478
8b1478
Add support for halt poll control MSR: save/restore, migration
8b1478
and new feature name.
8b1478
8b1478
The purpose of this MSR is to allow the guest to disable
8b1478
host halt poll.
8b1478
8b1478
(cherry picked from commit d645e1328726b38b3c79525eb57842ce29c1df7c)
8b1478
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
8b1478
Message-Id: <20190603230408.GA7938@amt.cnet>
8b1478
[Do not enable by default, as pointed out by Mark Kanda. - Paolo]
8b1478
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
8b1478
8b1478
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
8b1478
---
8b1478
 linux-headers/asm-x86/kvm_para.h |  2 ++
8b1478
 target/i386/cpu.c                |  4 +++-
8b1478
 target/i386/cpu.h                |  1 +
8b1478
 target/i386/kvm.c                | 15 +++++++++++++++
8b1478
 target/i386/machine.c            | 20 ++++++++++++++++++++
8b1478
 5 files changed, 41 insertions(+), 1 deletion(-)
8b1478
8b1478
diff --git a/linux-headers/asm-x86/kvm_para.h b/linux-headers/asm-x86/kvm_para.h
8b1478
index 4c58184..38ab00d 100644
8b1478
--- a/linux-headers/asm-x86/kvm_para.h
8b1478
+++ b/linux-headers/asm-x86/kvm_para.h
8b1478
@@ -27,6 +27,7 @@
8b1478
 #define KVM_FEATURE_PV_UNHALT		7
8b1478
 #define KVM_FEATURE_PV_TLB_FLUSH	9
8b1478
 #define KVM_FEATURE_ASYNC_PF_VMEXIT	10
8b1478
+#define KVM_FEATURE_POLL_CONTROL	12
8b1478
 
8b1478
 /* The last 8 bits are used to indicate how to interpret the flags field
8b1478
  * in pvclock structure. If no bits are set, all flags are ignored.
8b1478
@@ -43,6 +44,7 @@
8b1478
 #define MSR_KVM_ASYNC_PF_EN 0x4b564d02
8b1478
 #define MSR_KVM_STEAL_TIME  0x4b564d03
8b1478
 #define MSR_KVM_PV_EOI_EN      0x4b564d04
8b1478
+#define MSR_KVM_POLL_CONTROL	0x4b564d05
8b1478
 
8b1478
 struct kvm_steal_time {
8b1478
 	__u64 steal;
8b1478
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
8b1478
index 1f2f286..928e53c 100644
8b1478
--- a/target/i386/cpu.c
8b1478
+++ b/target/i386/cpu.c
8b1478
@@ -903,7 +903,7 @@ static FeatureWordInfo feature_word_info[FEATURE_WORDS] = {
8b1478
             "kvmclock", "kvm-nopiodelay", "kvm-mmu", "kvmclock",
8b1478
             "kvm-asyncpf", "kvm-steal-time", "kvm-pv-eoi", "kvm-pv-unhalt",
8b1478
             NULL, "kvm-pv-tlb-flush", NULL, NULL,
8b1478
-            NULL, NULL, NULL, NULL,
8b1478
+            "kvm-poll-control", NULL, NULL, NULL,
8b1478
             NULL, NULL, NULL, NULL,
8b1478
             NULL, NULL, NULL, NULL,
8b1478
             "kvmclock-stable-bit", NULL, NULL, NULL,
8b1478
@@ -5342,6 +5342,8 @@ static void x86_cpu_initfn(Object *obj)
8b1478
     object_property_add_alias(obj, "kvm_steal_time", obj, "kvm-steal-time", &error_abort);
8b1478
     object_property_add_alias(obj, "kvm_pv_eoi", obj, "kvm-pv-eoi", &error_abort);
8b1478
     object_property_add_alias(obj, "kvm_pv_unhalt", obj, "kvm-pv-unhalt", &error_abort);
8b1478
+    object_property_add_alias(obj, "kvm_poll_control", obj, "kvm-poll-control",
8b1478
+                              &error_abort);
8b1478
     object_property_add_alias(obj, "svm_lock", obj, "svm-lock", &error_abort);
8b1478
     object_property_add_alias(obj, "nrip_save", obj, "nrip-save", &error_abort);
8b1478
     object_property_add_alias(obj, "tsc_scale", obj, "tsc-scale", &error_abort);
8b1478
diff --git a/target/i386/cpu.h b/target/i386/cpu.h
8b1478
index 8ab313e..095e695 100644
8b1478
--- a/target/i386/cpu.h
8b1478
+++ b/target/i386/cpu.h
8b1478
@@ -1233,6 +1233,7 @@ typedef struct CPUX86State {
8b1478
     uint64_t steal_time_msr;
8b1478
     uint64_t async_pf_en_msr;
8b1478
     uint64_t pv_eoi_en_msr;
8b1478
+    uint64_t poll_control_msr;
8b1478
 
8b1478
     /* Partition-wide HV MSRs, will be updated only on the first vcpu */
8b1478
     uint64_t msr_hv_hypercall;
8b1478
diff --git a/target/i386/kvm.c b/target/i386/kvm.c
8b1478
index 7afad93..72901e1 100644
8b1478
--- a/target/i386/kvm.c
8b1478
+++ b/target/i386/kvm.c
8b1478
@@ -1199,6 +1199,9 @@ void kvm_arch_reset_vcpu(X86CPU *cpu)
8b1478
             env->msr_hv_synic_sint[i] = HV_SINT_MASKED;
8b1478
         }
8b1478
     }
8b1478
+
8b1478
+    /* enabled by default */
8b1478
+    env->poll_control_msr = 1;
8b1478
 }
8b1478
 
8b1478
 void kvm_arch_do_init_vcpu(X86CPU *cpu)
8b1478
@@ -1869,6 +1872,11 @@ static int kvm_put_msrs(X86CPU *cpu, int level)
8b1478
         if (env->features[FEAT_KVM] & (1 << KVM_FEATURE_STEAL_TIME)) {
8b1478
             kvm_msr_entry_add(cpu, MSR_KVM_STEAL_TIME, env->steal_time_msr);
8b1478
         }
8b1478
+
8b1478
+        if (env->features[FEAT_KVM] & (1 << KVM_FEATURE_POLL_CONTROL)) {
8b1478
+            kvm_msr_entry_add(cpu, MSR_KVM_POLL_CONTROL, env->poll_control_msr);
8b1478
+        }
8b1478
+
8b1478
         if (has_architectural_pmu_version > 0) {
8b1478
             if (has_architectural_pmu_version > 1) {
8b1478
                 /* Stop the counter.  */
8b1478
@@ -2241,6 +2249,9 @@ static int kvm_get_msrs(X86CPU *cpu)
8b1478
     if (env->features[FEAT_KVM] & (1 << KVM_FEATURE_STEAL_TIME)) {
8b1478
         kvm_msr_entry_add(cpu, MSR_KVM_STEAL_TIME, 0);
8b1478
     }
8b1478
+    if (env->features[FEAT_KVM] & (1 << KVM_FEATURE_POLL_CONTROL)) {
8b1478
+        kvm_msr_entry_add(cpu, MSR_KVM_POLL_CONTROL, 1);
8b1478
+    }
8b1478
     if (has_architectural_pmu_version > 0) {
8b1478
         if (has_architectural_pmu_version > 1) {
8b1478
             kvm_msr_entry_add(cpu, MSR_CORE_PERF_FIXED_CTR_CTRL, 0);
8b1478
@@ -2470,6 +2481,10 @@ static int kvm_get_msrs(X86CPU *cpu)
8b1478
         case MSR_KVM_STEAL_TIME:
8b1478
             env->steal_time_msr = msrs[i].data;
8b1478
             break;
8b1478
+        case MSR_KVM_POLL_CONTROL: {
8b1478
+            env->poll_control_msr = msrs[i].data;
8b1478
+            break;
8b1478
+        }
8b1478
         case MSR_CORE_PERF_FIXED_CTR_CTRL:
8b1478
             env->msr_fixed_ctr_ctrl = msrs[i].data;
8b1478
             break;
8b1478
diff --git a/target/i386/machine.c b/target/i386/machine.c
8b1478
index 9e7256a..52b1eae 100644
8b1478
--- a/target/i386/machine.c
8b1478
+++ b/target/i386/machine.c
8b1478
@@ -325,6 +325,14 @@ static bool steal_time_msr_needed(void *opaque)
8b1478
     return cpu->env.steal_time_msr != 0;
8b1478
 }
8b1478
 
8b1478
+/* Poll control MSR enabled by default */
8b1478
+static bool poll_control_msr_needed(void *opaque)
8b1478
+{
8b1478
+    X86CPU *cpu = opaque;
8b1478
+
8b1478
+    return cpu->env.poll_control_msr != 1;
8b1478
+}
8b1478
+
8b1478
 static const VMStateDescription vmstate_steal_time_msr = {
8b1478
     .name = "cpu/steal_time_msr",
8b1478
     .version_id = 1,
8b1478
@@ -358,6 +366,17 @@ static const VMStateDescription vmstate_pv_eoi_msr = {
8b1478
     }
8b1478
 };
8b1478
 
8b1478
+static const VMStateDescription vmstate_poll_control_msr = {
8b1478
+    .name = "cpu/poll_control_msr",
8b1478
+    .version_id = 1,
8b1478
+    .minimum_version_id = 1,
8b1478
+    .needed = poll_control_msr_needed,
8b1478
+    .fields = (VMStateField[]) {
8b1478
+        VMSTATE_UINT64(env.poll_control_msr, X86CPU),
8b1478
+        VMSTATE_END_OF_LIST()
8b1478
+    }
8b1478
+};
8b1478
+
8b1478
 static bool fpop_ip_dp_needed(void *opaque)
8b1478
 {
8b1478
     X86CPU *cpu = opaque;
8b1478
@@ -1033,6 +1052,7 @@ VMStateDescription vmstate_x86_cpu = {
8b1478
         &vmstate_async_pf_msr,
8b1478
         &vmstate_pv_eoi_msr,
8b1478
         &vmstate_steal_time_msr,
8b1478
+        &vmstate_poll_control_msr,
8b1478
         &vmstate_fpop_ip_dp,
8b1478
         &vmstate_msr_tsc_adjust,
8b1478
         &vmstate_msr_tscdeadline,
8b1478
-- 
8b1478
1.8.3.1
8b1478