summaryrefslogtreecommitdiff
path: root/arch/x86/kernel/kvm.c
diff options
context:
space:
mode:
authorMarcelo Tosatti <mtosatti@redhat.com>2019-07-03 20:51:29 -0300
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2019-07-30 17:27:37 +0200
commita1c4423b02b2121108e3ea9580741e0f26309a48 (patch)
treec2b6c2842065c7ed359f997580078ca00ad02fe3 /arch/x86/kernel/kvm.c
parent2cffe9f6b96fece065ee8522673c90e92ef2085d (diff)
cpuidle-haltpoll: disable host side polling when kvm virtualized
When performing guest side polling, it is not necessary to also perform host side polling. So disable host side polling, via the new MSR interface, when loading cpuidle-haltpoll driver. Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Diffstat (limited to 'arch/x86/kernel/kvm.c')
-rw-r--r--arch/x86/kernel/kvm.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
index b7f34fe2171e..f48401be8ce0 100644
--- a/arch/x86/kernel/kvm.c
+++ b/arch/x86/kernel/kvm.c
@@ -875,3 +875,45 @@ void __init kvm_spinlock_init(void)
}
#endif /* CONFIG_PARAVIRT_SPINLOCKS */
+
+#ifdef CONFIG_ARCH_CPUIDLE_HALTPOLL
+
+static void kvm_disable_host_haltpoll(void *i)
+{
+ wrmsrl(MSR_KVM_POLL_CONTROL, 0);
+}
+
+static void kvm_enable_host_haltpoll(void *i)
+{
+ wrmsrl(MSR_KVM_POLL_CONTROL, 1);
+}
+
+void arch_haltpoll_enable(void)
+{
+ if (!kvm_para_has_feature(KVM_FEATURE_POLL_CONTROL)) {
+ printk(KERN_ERR "kvm: host does not support poll control\n");
+ printk(KERN_ERR "kvm: host upgrade recommended\n");
+ return;
+ }
+
+ preempt_disable();
+ /* Enable guest halt poll disables host halt poll */
+ kvm_disable_host_haltpoll(NULL);
+ smp_call_function(kvm_disable_host_haltpoll, NULL, 1);
+ preempt_enable();
+}
+EXPORT_SYMBOL_GPL(arch_haltpoll_enable);
+
+void arch_haltpoll_disable(void)
+{
+ if (!kvm_para_has_feature(KVM_FEATURE_POLL_CONTROL))
+ return;
+
+ preempt_disable();
+ /* Enable guest halt poll disables host halt poll */
+ kvm_enable_host_haltpoll(NULL);
+ smp_call_function(kvm_enable_host_haltpoll, NULL, 1);
+ preempt_enable();
+}
+EXPORT_SYMBOL_GPL(arch_haltpoll_disable);
+#endif