Thomas Gleixner | f6ce7f2 | 2019-05-19 15:51:49 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Marcelo Tosatti | 0cf1bfd | 2008-02-22 12:21:36 -0500 | [diff] [blame] | 2 | /* |
| 3 | * KVM paravirt_ops implementation |
| 4 | * |
Marcelo Tosatti | 0cf1bfd | 2008-02-22 12:21:36 -0500 | [diff] [blame] | 5 | * Copyright (C) 2007, Red Hat, Inc., Ingo Molnar <mingo@redhat.com> |
| 6 | * Copyright IBM Corporation, 2007 |
| 7 | * Authors: Anthony Liguori <aliguori@us.ibm.com> |
| 8 | */ |
| 9 | |
Frederic Weisbecker | 56dd947 | 2013-02-24 00:23:25 +0100 | [diff] [blame] | 10 | #include <linux/context_tracking.h> |
Paul Gortmaker | 186f436 | 2016-07-13 20:18:56 -0400 | [diff] [blame] | 11 | #include <linux/init.h> |
Marcelo Tosatti | 0cf1bfd | 2008-02-22 12:21:36 -0500 | [diff] [blame] | 12 | #include <linux/kernel.h> |
| 13 | #include <linux/kvm_para.h> |
| 14 | #include <linux/cpu.h> |
| 15 | #include <linux/mm.h> |
Marcelo Tosatti | 1da8a77 | 2008-02-22 12:21:37 -0500 | [diff] [blame] | 16 | #include <linux/highmem.h> |
Marcelo Tosatti | 096d14a | 2008-02-22 12:21:38 -0500 | [diff] [blame] | 17 | #include <linux/hardirq.h> |
Gleb Natapov | fd10cde | 2010-10-14 11:22:51 +0200 | [diff] [blame] | 18 | #include <linux/notifier.h> |
| 19 | #include <linux/reboot.h> |
Gleb Natapov | 631bc48 | 2010-10-14 11:22:52 +0200 | [diff] [blame] | 20 | #include <linux/hash.h> |
| 21 | #include <linux/sched.h> |
| 22 | #include <linux/slab.h> |
| 23 | #include <linux/kprobes.h> |
Srivatsa Vaddagiri | 92b7520 | 2013-08-06 14:55:41 +0530 | [diff] [blame] | 24 | #include <linux/debugfs.h> |
Ulrich Obergfell | 9919e39 | 2014-10-13 15:55:37 -0700 | [diff] [blame] | 25 | #include <linux/nmi.h> |
Rik van Riel | 9db284f | 2016-03-21 15:13:27 +0100 | [diff] [blame] | 26 | #include <linux/swait.h> |
Marcelo Tosatti | a90ede7 | 2009-02-11 22:45:42 -0200 | [diff] [blame] | 27 | #include <asm/timer.h> |
Gleb Natapov | fd10cde | 2010-10-14 11:22:51 +0200 | [diff] [blame] | 28 | #include <asm/cpu.h> |
Gleb Natapov | 631bc48 | 2010-10-14 11:22:52 +0200 | [diff] [blame] | 29 | #include <asm/traps.h> |
| 30 | #include <asm/desc.h> |
Gleb Natapov | 6c047cd | 2010-10-14 11:22:54 +0200 | [diff] [blame] | 31 | #include <asm/tlbflush.h> |
Michael S. Tsirkin | ab9cf49 | 2012-06-24 19:24:34 +0300 | [diff] [blame] | 32 | #include <asm/apic.h> |
| 33 | #include <asm/apicdef.h> |
Prarit Bhargava | fc73373 | 2012-07-06 13:47:39 -0400 | [diff] [blame] | 34 | #include <asm/hypervisor.h> |
Peter Zijlstra | 48a8b97 | 2018-08-22 17:30:16 +0200 | [diff] [blame] | 35 | #include <asm/tlb.h> |
Yi Wang | 19308a4 | 2019-10-10 14:37:25 +0800 | [diff] [blame] | 36 | #include <asm/cpuidle_haltpoll.h> |
Marcelo Tosatti | 096d14a | 2008-02-22 12:21:38 -0500 | [diff] [blame] | 37 | |
Gleb Natapov | fd10cde | 2010-10-14 11:22:51 +0200 | [diff] [blame] | 38 | static int kvmapf = 1; |
| 39 | |
Dou Liyang | afdc3f58 | 2018-01-17 11:46:54 +0800 | [diff] [blame] | 40 | static int __init parse_no_kvmapf(char *arg) |
Gleb Natapov | fd10cde | 2010-10-14 11:22:51 +0200 | [diff] [blame] | 41 | { |
| 42 | kvmapf = 0; |
| 43 | return 0; |
| 44 | } |
| 45 | |
| 46 | early_param("no-kvmapf", parse_no_kvmapf); |
| 47 | |
Glauber Costa | d910f5c | 2011-07-11 15:28:19 -0400 | [diff] [blame] | 48 | static int steal_acc = 1; |
Dou Liyang | afdc3f58 | 2018-01-17 11:46:54 +0800 | [diff] [blame] | 49 | static int __init parse_no_stealacc(char *arg) |
Glauber Costa | d910f5c | 2011-07-11 15:28:19 -0400 | [diff] [blame] | 50 | { |
| 51 | steal_acc = 0; |
| 52 | return 0; |
| 53 | } |
| 54 | |
| 55 | early_param("no-steal-acc", parse_no_stealacc); |
| 56 | |
Brijesh Singh | 4716276 | 2017-10-20 09:30:58 -0500 | [diff] [blame] | 57 | static DEFINE_PER_CPU_DECRYPTED(struct kvm_vcpu_pv_apf_data, apf_reason) __aligned(64); |
Andi Kleen | 14e581c | 2019-03-29 17:47:42 -0700 | [diff] [blame] | 58 | DEFINE_PER_CPU_DECRYPTED(struct kvm_steal_time, steal_time) __aligned(64) __visible; |
Glauber Costa | d910f5c | 2011-07-11 15:28:19 -0400 | [diff] [blame] | 59 | static int has_steal_clock = 0; |
Marcelo Tosatti | 096d14a | 2008-02-22 12:21:38 -0500 | [diff] [blame] | 60 | |
Marcelo Tosatti | 0cf1bfd | 2008-02-22 12:21:36 -0500 | [diff] [blame] | 61 | /* |
| 62 | * No need for any "IO delay" on KVM |
| 63 | */ |
| 64 | static void kvm_io_delay(void) |
| 65 | { |
| 66 | } |
| 67 | |
Gleb Natapov | 631bc48 | 2010-10-14 11:22:52 +0200 | [diff] [blame] | 68 | #define KVM_TASK_SLEEP_HASHBITS 8 |
| 69 | #define KVM_TASK_SLEEP_HASHSIZE (1<<KVM_TASK_SLEEP_HASHBITS) |
| 70 | |
| 71 | struct kvm_task_sleep_node { |
| 72 | struct hlist_node link; |
Rik van Riel | 9db284f | 2016-03-21 15:13:27 +0100 | [diff] [blame] | 73 | struct swait_queue_head wq; |
Gleb Natapov | 631bc48 | 2010-10-14 11:22:52 +0200 | [diff] [blame] | 74 | u32 token; |
| 75 | int cpu; |
Gleb Natapov | 6c047cd | 2010-10-14 11:22:54 +0200 | [diff] [blame] | 76 | bool halted; |
Gleb Natapov | 631bc48 | 2010-10-14 11:22:52 +0200 | [diff] [blame] | 77 | }; |
| 78 | |
| 79 | static struct kvm_task_sleep_head { |
Rik van Riel | 9db284f | 2016-03-21 15:13:27 +0100 | [diff] [blame] | 80 | raw_spinlock_t lock; |
Gleb Natapov | 631bc48 | 2010-10-14 11:22:52 +0200 | [diff] [blame] | 81 | struct hlist_head list; |
| 82 | } async_pf_sleepers[KVM_TASK_SLEEP_HASHSIZE]; |
| 83 | |
| 84 | static struct kvm_task_sleep_node *_find_apf_task(struct kvm_task_sleep_head *b, |
| 85 | u32 token) |
| 86 | { |
| 87 | struct hlist_node *p; |
| 88 | |
| 89 | hlist_for_each(p, &b->list) { |
| 90 | struct kvm_task_sleep_node *n = |
| 91 | hlist_entry(p, typeof(*n), link); |
| 92 | if (n->token == token) |
| 93 | return n; |
| 94 | } |
| 95 | |
| 96 | return NULL; |
| 97 | } |
| 98 | |
Boqun Feng | a2b7861 | 2017-10-03 21:36:51 +0800 | [diff] [blame] | 99 | /* |
| 100 | * @interrupt_kernel: Is this called from a routine which interrupts the kernel |
| 101 | * (other than user space)? |
| 102 | */ |
| 103 | void kvm_async_pf_task_wait(u32 token, int interrupt_kernel) |
Gleb Natapov | 631bc48 | 2010-10-14 11:22:52 +0200 | [diff] [blame] | 104 | { |
| 105 | u32 key = hash_32(token, KVM_TASK_SLEEP_HASHBITS); |
| 106 | struct kvm_task_sleep_head *b = &async_pf_sleepers[key]; |
| 107 | struct kvm_task_sleep_node n, *e; |
Rik van Riel | 9db284f | 2016-03-21 15:13:27 +0100 | [diff] [blame] | 108 | DECLARE_SWAITQUEUE(wait); |
Gleb Natapov | 631bc48 | 2010-10-14 11:22:52 +0200 | [diff] [blame] | 109 | |
Li Zhong | 9b132fb | 2012-12-04 10:35:13 +0800 | [diff] [blame] | 110 | rcu_irq_enter(); |
| 111 | |
Rik van Riel | 9db284f | 2016-03-21 15:13:27 +0100 | [diff] [blame] | 112 | raw_spin_lock(&b->lock); |
Gleb Natapov | 631bc48 | 2010-10-14 11:22:52 +0200 | [diff] [blame] | 113 | e = _find_apf_task(b, token); |
| 114 | if (e) { |
| 115 | /* dummy entry exist -> wake up was delivered ahead of PF */ |
| 116 | hlist_del(&e->link); |
| 117 | kfree(e); |
Rik van Riel | 9db284f | 2016-03-21 15:13:27 +0100 | [diff] [blame] | 118 | raw_spin_unlock(&b->lock); |
Li Zhong | 9b132fb | 2012-12-04 10:35:13 +0800 | [diff] [blame] | 119 | |
| 120 | rcu_irq_exit(); |
Gleb Natapov | 631bc48 | 2010-10-14 11:22:52 +0200 | [diff] [blame] | 121 | return; |
| 122 | } |
| 123 | |
| 124 | n.token = token; |
| 125 | n.cpu = smp_processor_id(); |
Boqun Feng | a2b7861 | 2017-10-03 21:36:51 +0800 | [diff] [blame] | 126 | n.halted = is_idle_task(current) || |
| 127 | (IS_ENABLED(CONFIG_PREEMPT_COUNT) |
| 128 | ? preempt_count() > 1 || rcu_preempt_depth() |
| 129 | : interrupt_kernel); |
Rik van Riel | 9db284f | 2016-03-21 15:13:27 +0100 | [diff] [blame] | 130 | init_swait_queue_head(&n.wq); |
Gleb Natapov | 631bc48 | 2010-10-14 11:22:52 +0200 | [diff] [blame] | 131 | hlist_add_head(&n.link, &b->list); |
Rik van Riel | 9db284f | 2016-03-21 15:13:27 +0100 | [diff] [blame] | 132 | raw_spin_unlock(&b->lock); |
Gleb Natapov | 631bc48 | 2010-10-14 11:22:52 +0200 | [diff] [blame] | 133 | |
| 134 | for (;;) { |
Gleb Natapov | 6c047cd | 2010-10-14 11:22:54 +0200 | [diff] [blame] | 135 | if (!n.halted) |
Peter Zijlstra | b3dae10 | 2018-06-12 10:34:52 +0200 | [diff] [blame] | 136 | prepare_to_swait_exclusive(&n.wq, &wait, TASK_UNINTERRUPTIBLE); |
Gleb Natapov | 631bc48 | 2010-10-14 11:22:52 +0200 | [diff] [blame] | 137 | if (hlist_unhashed(&n.link)) |
| 138 | break; |
Gleb Natapov | 6c047cd | 2010-10-14 11:22:54 +0200 | [diff] [blame] | 139 | |
Wanpeng Li | 337c017 | 2017-08-01 05:20:03 -0700 | [diff] [blame] | 140 | rcu_irq_exit(); |
| 141 | |
Gleb Natapov | 6c047cd | 2010-10-14 11:22:54 +0200 | [diff] [blame] | 142 | if (!n.halted) { |
| 143 | local_irq_enable(); |
| 144 | schedule(); |
| 145 | local_irq_disable(); |
| 146 | } else { |
| 147 | /* |
| 148 | * We cannot reschedule. So halt. |
| 149 | */ |
| 150 | native_safe_halt(); |
| 151 | local_irq_disable(); |
| 152 | } |
Wanpeng Li | 337c017 | 2017-08-01 05:20:03 -0700 | [diff] [blame] | 153 | |
| 154 | rcu_irq_enter(); |
Gleb Natapov | 631bc48 | 2010-10-14 11:22:52 +0200 | [diff] [blame] | 155 | } |
Gleb Natapov | 6c047cd | 2010-10-14 11:22:54 +0200 | [diff] [blame] | 156 | if (!n.halted) |
Rik van Riel | 9db284f | 2016-03-21 15:13:27 +0100 | [diff] [blame] | 157 | finish_swait(&n.wq, &wait); |
Gleb Natapov | 631bc48 | 2010-10-14 11:22:52 +0200 | [diff] [blame] | 158 | |
Li Zhong | 9b132fb | 2012-12-04 10:35:13 +0800 | [diff] [blame] | 159 | rcu_irq_exit(); |
Gleb Natapov | 631bc48 | 2010-10-14 11:22:52 +0200 | [diff] [blame] | 160 | return; |
| 161 | } |
| 162 | EXPORT_SYMBOL_GPL(kvm_async_pf_task_wait); |
| 163 | |
| 164 | static void apf_task_wake_one(struct kvm_task_sleep_node *n) |
| 165 | { |
| 166 | hlist_del_init(&n->link); |
Gleb Natapov | 6c047cd | 2010-10-14 11:22:54 +0200 | [diff] [blame] | 167 | if (n->halted) |
| 168 | smp_send_reschedule(n->cpu); |
Davidlohr Bueso | a0cff57 | 2017-09-13 13:08:21 -0700 | [diff] [blame] | 169 | else if (swq_has_sleeper(&n->wq)) |
Peter Zijlstra | b3dae10 | 2018-06-12 10:34:52 +0200 | [diff] [blame] | 170 | swake_up_one(&n->wq); |
Gleb Natapov | 631bc48 | 2010-10-14 11:22:52 +0200 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | static void apf_task_wake_all(void) |
| 174 | { |
| 175 | int i; |
| 176 | |
| 177 | for (i = 0; i < KVM_TASK_SLEEP_HASHSIZE; i++) { |
| 178 | struct hlist_node *p, *next; |
| 179 | struct kvm_task_sleep_head *b = &async_pf_sleepers[i]; |
Rik van Riel | 9db284f | 2016-03-21 15:13:27 +0100 | [diff] [blame] | 180 | raw_spin_lock(&b->lock); |
Gleb Natapov | 631bc48 | 2010-10-14 11:22:52 +0200 | [diff] [blame] | 181 | hlist_for_each_safe(p, next, &b->list) { |
| 182 | struct kvm_task_sleep_node *n = |
| 183 | hlist_entry(p, typeof(*n), link); |
| 184 | if (n->cpu == smp_processor_id()) |
| 185 | apf_task_wake_one(n); |
| 186 | } |
Rik van Riel | 9db284f | 2016-03-21 15:13:27 +0100 | [diff] [blame] | 187 | raw_spin_unlock(&b->lock); |
Gleb Natapov | 631bc48 | 2010-10-14 11:22:52 +0200 | [diff] [blame] | 188 | } |
| 189 | } |
| 190 | |
| 191 | void kvm_async_pf_task_wake(u32 token) |
| 192 | { |
| 193 | u32 key = hash_32(token, KVM_TASK_SLEEP_HASHBITS); |
| 194 | struct kvm_task_sleep_head *b = &async_pf_sleepers[key]; |
| 195 | struct kvm_task_sleep_node *n; |
| 196 | |
| 197 | if (token == ~0) { |
| 198 | apf_task_wake_all(); |
| 199 | return; |
| 200 | } |
| 201 | |
| 202 | again: |
Rik van Riel | 9db284f | 2016-03-21 15:13:27 +0100 | [diff] [blame] | 203 | raw_spin_lock(&b->lock); |
Gleb Natapov | 631bc48 | 2010-10-14 11:22:52 +0200 | [diff] [blame] | 204 | n = _find_apf_task(b, token); |
| 205 | if (!n) { |
| 206 | /* |
| 207 | * async PF was not yet handled. |
| 208 | * Add dummy entry for the token. |
| 209 | */ |
Gleb Natapov | 62c49cc | 2012-05-02 15:04:02 +0300 | [diff] [blame] | 210 | n = kzalloc(sizeof(*n), GFP_ATOMIC); |
Gleb Natapov | 631bc48 | 2010-10-14 11:22:52 +0200 | [diff] [blame] | 211 | if (!n) { |
| 212 | /* |
| 213 | * Allocation failed! Busy wait while other cpu |
| 214 | * handles async PF. |
| 215 | */ |
Rik van Riel | 9db284f | 2016-03-21 15:13:27 +0100 | [diff] [blame] | 216 | raw_spin_unlock(&b->lock); |
Gleb Natapov | 631bc48 | 2010-10-14 11:22:52 +0200 | [diff] [blame] | 217 | cpu_relax(); |
| 218 | goto again; |
| 219 | } |
| 220 | n->token = token; |
| 221 | n->cpu = smp_processor_id(); |
Rik van Riel | 9db284f | 2016-03-21 15:13:27 +0100 | [diff] [blame] | 222 | init_swait_queue_head(&n->wq); |
Gleb Natapov | 631bc48 | 2010-10-14 11:22:52 +0200 | [diff] [blame] | 223 | hlist_add_head(&n->link, &b->list); |
| 224 | } else |
| 225 | apf_task_wake_one(n); |
Rik van Riel | 9db284f | 2016-03-21 15:13:27 +0100 | [diff] [blame] | 226 | raw_spin_unlock(&b->lock); |
Gleb Natapov | 631bc48 | 2010-10-14 11:22:52 +0200 | [diff] [blame] | 227 | return; |
| 228 | } |
| 229 | EXPORT_SYMBOL_GPL(kvm_async_pf_task_wake); |
| 230 | |
| 231 | u32 kvm_read_and_reset_pf_reason(void) |
| 232 | { |
| 233 | u32 reason = 0; |
| 234 | |
Christoph Lameter | 89cbc76 | 2014-08-17 12:30:40 -0500 | [diff] [blame] | 235 | if (__this_cpu_read(apf_reason.enabled)) { |
| 236 | reason = __this_cpu_read(apf_reason.reason); |
| 237 | __this_cpu_write(apf_reason.reason, 0); |
Gleb Natapov | 631bc48 | 2010-10-14 11:22:52 +0200 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | return reason; |
| 241 | } |
| 242 | EXPORT_SYMBOL_GPL(kvm_read_and_reset_pf_reason); |
Masami Hiramatsu | 9326638 | 2014-04-17 17:18:14 +0900 | [diff] [blame] | 243 | NOKPROBE_SYMBOL(kvm_read_and_reset_pf_reason); |
Gleb Natapov | 631bc48 | 2010-10-14 11:22:52 +0200 | [diff] [blame] | 244 | |
Masami Hiramatsu | 9326638 | 2014-04-17 17:18:14 +0900 | [diff] [blame] | 245 | dotraplinkage void |
Peter Zijlstra | a0d14b8 | 2019-07-11 13:40:59 +0200 | [diff] [blame] | 246 | do_async_page_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address) |
Gleb Natapov | 631bc48 | 2010-10-14 11:22:52 +0200 | [diff] [blame] | 247 | { |
| 248 | switch (kvm_read_and_reset_pf_reason()) { |
| 249 | default: |
Peter Zijlstra | a0d14b8 | 2019-07-11 13:40:59 +0200 | [diff] [blame] | 250 | do_page_fault(regs, error_code, address); |
Gleb Natapov | 631bc48 | 2010-10-14 11:22:52 +0200 | [diff] [blame] | 251 | break; |
| 252 | case KVM_PV_REASON_PAGE_NOT_PRESENT: |
| 253 | /* page is swapped out by the host. */ |
Peter Zijlstra | a0d14b8 | 2019-07-11 13:40:59 +0200 | [diff] [blame] | 254 | kvm_async_pf_task_wait((u32)address, !user_mode(regs)); |
Gleb Natapov | 631bc48 | 2010-10-14 11:22:52 +0200 | [diff] [blame] | 255 | break; |
| 256 | case KVM_PV_REASON_PAGE_READY: |
Gleb Natapov | e087592 | 2012-04-04 15:30:33 +0300 | [diff] [blame] | 257 | rcu_irq_enter(); |
Peter Zijlstra | a0d14b8 | 2019-07-11 13:40:59 +0200 | [diff] [blame] | 258 | kvm_async_pf_task_wake((u32)address); |
Gleb Natapov | e087592 | 2012-04-04 15:30:33 +0300 | [diff] [blame] | 259 | rcu_irq_exit(); |
Gleb Natapov | 631bc48 | 2010-10-14 11:22:52 +0200 | [diff] [blame] | 260 | break; |
| 261 | } |
| 262 | } |
Masami Hiramatsu | 9326638 | 2014-04-17 17:18:14 +0900 | [diff] [blame] | 263 | NOKPROBE_SYMBOL(do_async_page_fault); |
Gleb Natapov | 631bc48 | 2010-10-14 11:22:52 +0200 | [diff] [blame] | 264 | |
Rakib Mullick | d3ac881 | 2009-07-02 11:40:36 +0600 | [diff] [blame] | 265 | static void __init paravirt_ops_setup(void) |
Marcelo Tosatti | 0cf1bfd | 2008-02-22 12:21:36 -0500 | [diff] [blame] | 266 | { |
| 267 | pv_info.name = "KVM"; |
Andy Lutomirski | 29fa682 | 2014-12-05 19:03:28 -0800 | [diff] [blame] | 268 | |
Marcelo Tosatti | 0cf1bfd | 2008-02-22 12:21:36 -0500 | [diff] [blame] | 269 | if (kvm_para_has_feature(KVM_FEATURE_NOP_IO_DELAY)) |
Juergen Gross | 5c83511 | 2018-08-28 09:40:19 +0200 | [diff] [blame] | 270 | pv_ops.cpu.io_delay = kvm_io_delay; |
Marcelo Tosatti | 0cf1bfd | 2008-02-22 12:21:36 -0500 | [diff] [blame] | 271 | |
Marcelo Tosatti | a90ede7 | 2009-02-11 22:45:42 -0200 | [diff] [blame] | 272 | #ifdef CONFIG_X86_IO_APIC |
| 273 | no_timer_check = 1; |
| 274 | #endif |
Marcelo Tosatti | 0cf1bfd | 2008-02-22 12:21:36 -0500 | [diff] [blame] | 275 | } |
| 276 | |
Glauber Costa | d910f5c | 2011-07-11 15:28:19 -0400 | [diff] [blame] | 277 | static void kvm_register_steal_time(void) |
| 278 | { |
| 279 | int cpu = smp_processor_id(); |
| 280 | struct kvm_steal_time *st = &per_cpu(steal_time, cpu); |
| 281 | |
| 282 | if (!has_steal_clock) |
| 283 | return; |
| 284 | |
Dave Hansen | 5dfd486 | 2013-01-22 13:24:35 -0800 | [diff] [blame] | 285 | wrmsrl(MSR_KVM_STEAL_TIME, (slow_virt_to_phys(st) | KVM_MSR_ENABLED)); |
Shuah Khan | 136867f | 2013-02-05 19:57:22 -0700 | [diff] [blame] | 286 | pr_info("kvm-stealtime: cpu %d, msr %llx\n", |
| 287 | cpu, (unsigned long long) slow_virt_to_phys(st)); |
Glauber Costa | d910f5c | 2011-07-11 15:28:19 -0400 | [diff] [blame] | 288 | } |
| 289 | |
Brijesh Singh | 4716276 | 2017-10-20 09:30:58 -0500 | [diff] [blame] | 290 | static DEFINE_PER_CPU_DECRYPTED(unsigned long, kvm_apic_eoi) = KVM_PV_EOI_DISABLED; |
Michael S. Tsirkin | ab9cf49 | 2012-06-24 19:24:34 +0300 | [diff] [blame] | 291 | |
Wanpeng Li | 8ca2255 | 2016-11-07 11:13:40 +0800 | [diff] [blame] | 292 | static notrace void kvm_guest_apic_eoi_write(u32 reg, u32 val) |
Michael S. Tsirkin | ab9cf49 | 2012-06-24 19:24:34 +0300 | [diff] [blame] | 293 | { |
| 294 | /** |
| 295 | * This relies on __test_and_clear_bit to modify the memory |
| 296 | * in a way that is atomic with respect to the local CPU. |
| 297 | * The hypervisor only accesses this memory from the local CPU so |
| 298 | * there's no need for lock or memory barriers. |
| 299 | * An optimization barrier is implied in apic write. |
| 300 | */ |
Christoph Lameter | 89cbc76 | 2014-08-17 12:30:40 -0500 | [diff] [blame] | 301 | if (__test_and_clear_bit(KVM_PV_EOI_BIT, this_cpu_ptr(&kvm_apic_eoi))) |
Michael S. Tsirkin | ab9cf49 | 2012-06-24 19:24:34 +0300 | [diff] [blame] | 302 | return; |
Wanpeng Li | 8ca2255 | 2016-11-07 11:13:40 +0800 | [diff] [blame] | 303 | apic->native_eoi_write(APIC_EOI, APIC_EOI_ACK); |
Michael S. Tsirkin | ab9cf49 | 2012-06-24 19:24:34 +0300 | [diff] [blame] | 304 | } |
| 305 | |
Nicholas Krause | ed3cf15 | 2015-05-20 00:24:10 -0400 | [diff] [blame] | 306 | static void kvm_guest_cpu_init(void) |
Gleb Natapov | fd10cde | 2010-10-14 11:22:51 +0200 | [diff] [blame] | 307 | { |
Gleb Natapov | fd10cde | 2010-10-14 11:22:51 +0200 | [diff] [blame] | 308 | if (kvm_para_has_feature(KVM_FEATURE_ASYNC_PF) && kvmapf) { |
Christoph Lameter | 89cbc76 | 2014-08-17 12:30:40 -0500 | [diff] [blame] | 309 | u64 pa = slow_virt_to_phys(this_cpu_ptr(&apf_reason)); |
Gleb Natapov | fd10cde | 2010-10-14 11:22:51 +0200 | [diff] [blame] | 310 | |
Thomas Gleixner | 09c7e8b | 2019-07-26 23:19:44 +0200 | [diff] [blame] | 311 | #ifdef CONFIG_PREEMPTION |
Gleb Natapov | 6adba52 | 2010-10-14 11:22:55 +0200 | [diff] [blame] | 312 | pa |= KVM_ASYNC_PF_SEND_ALWAYS; |
| 313 | #endif |
Wanpeng Li | 52a5c15 | 2017-07-13 18:30:42 -0700 | [diff] [blame] | 314 | pa |= KVM_ASYNC_PF_ENABLED; |
| 315 | |
Radim Krčmář | fe2a302 | 2018-02-01 22:16:21 +0100 | [diff] [blame] | 316 | if (kvm_para_has_feature(KVM_FEATURE_ASYNC_PF_VMEXIT)) |
| 317 | pa |= KVM_ASYNC_PF_DELIVERY_AS_PF_VMEXIT; |
| 318 | |
| 319 | wrmsrl(MSR_KVM_ASYNC_PF_EN, pa); |
Christoph Lameter | 89cbc76 | 2014-08-17 12:30:40 -0500 | [diff] [blame] | 320 | __this_cpu_write(apf_reason.enabled, 1); |
Gleb Natapov | fd10cde | 2010-10-14 11:22:51 +0200 | [diff] [blame] | 321 | printk(KERN_INFO"KVM setup async PF for cpu %d\n", |
| 322 | smp_processor_id()); |
| 323 | } |
Glauber Costa | d910f5c | 2011-07-11 15:28:19 -0400 | [diff] [blame] | 324 | |
Michael S. Tsirkin | ab9cf49 | 2012-06-24 19:24:34 +0300 | [diff] [blame] | 325 | if (kvm_para_has_feature(KVM_FEATURE_PV_EOI)) { |
| 326 | unsigned long pa; |
| 327 | /* Size alignment is implied but just to make it explicit. */ |
| 328 | BUILD_BUG_ON(__alignof__(kvm_apic_eoi) < 4); |
Christoph Lameter | 89cbc76 | 2014-08-17 12:30:40 -0500 | [diff] [blame] | 329 | __this_cpu_write(kvm_apic_eoi, 0); |
| 330 | pa = slow_virt_to_phys(this_cpu_ptr(&kvm_apic_eoi)) |
Dave Hansen | 5dfd486 | 2013-01-22 13:24:35 -0800 | [diff] [blame] | 331 | | KVM_MSR_ENABLED; |
Michael S. Tsirkin | ab9cf49 | 2012-06-24 19:24:34 +0300 | [diff] [blame] | 332 | wrmsrl(MSR_KVM_PV_EOI_EN, pa); |
| 333 | } |
| 334 | |
Glauber Costa | d910f5c | 2011-07-11 15:28:19 -0400 | [diff] [blame] | 335 | if (has_steal_clock) |
| 336 | kvm_register_steal_time(); |
Gleb Natapov | fd10cde | 2010-10-14 11:22:51 +0200 | [diff] [blame] | 337 | } |
| 338 | |
Michael S. Tsirkin | ab9cf49 | 2012-06-24 19:24:34 +0300 | [diff] [blame] | 339 | static void kvm_pv_disable_apf(void) |
Gleb Natapov | fd10cde | 2010-10-14 11:22:51 +0200 | [diff] [blame] | 340 | { |
Christoph Lameter | 89cbc76 | 2014-08-17 12:30:40 -0500 | [diff] [blame] | 341 | if (!__this_cpu_read(apf_reason.enabled)) |
Gleb Natapov | fd10cde | 2010-10-14 11:22:51 +0200 | [diff] [blame] | 342 | return; |
| 343 | |
| 344 | wrmsrl(MSR_KVM_ASYNC_PF_EN, 0); |
Christoph Lameter | 89cbc76 | 2014-08-17 12:30:40 -0500 | [diff] [blame] | 345 | __this_cpu_write(apf_reason.enabled, 0); |
Gleb Natapov | fd10cde | 2010-10-14 11:22:51 +0200 | [diff] [blame] | 346 | |
| 347 | printk(KERN_INFO"Unregister pv shared memory for cpu %d\n", |
| 348 | smp_processor_id()); |
| 349 | } |
| 350 | |
Michael S. Tsirkin | ab9cf49 | 2012-06-24 19:24:34 +0300 | [diff] [blame] | 351 | static void kvm_pv_guest_cpu_reboot(void *unused) |
| 352 | { |
| 353 | /* |
| 354 | * We disable PV EOI before we load a new kernel by kexec, |
| 355 | * since MSR_KVM_PV_EOI_EN stores a pointer into old kernel's memory. |
| 356 | * New kernel can re-enable when it boots. |
| 357 | */ |
| 358 | if (kvm_para_has_feature(KVM_FEATURE_PV_EOI)) |
| 359 | wrmsrl(MSR_KVM_PV_EOI_EN, 0); |
| 360 | kvm_pv_disable_apf(); |
Florian Westphal | 8fbe6a5 | 2012-08-15 16:00:40 +0200 | [diff] [blame] | 361 | kvm_disable_steal_time(); |
Michael S. Tsirkin | ab9cf49 | 2012-06-24 19:24:34 +0300 | [diff] [blame] | 362 | } |
| 363 | |
Gleb Natapov | fd10cde | 2010-10-14 11:22:51 +0200 | [diff] [blame] | 364 | static int kvm_pv_reboot_notify(struct notifier_block *nb, |
| 365 | unsigned long code, void *unused) |
| 366 | { |
| 367 | if (code == SYS_RESTART) |
Michael S. Tsirkin | ab9cf49 | 2012-06-24 19:24:34 +0300 | [diff] [blame] | 368 | on_each_cpu(kvm_pv_guest_cpu_reboot, NULL, 1); |
Gleb Natapov | fd10cde | 2010-10-14 11:22:51 +0200 | [diff] [blame] | 369 | return NOTIFY_DONE; |
| 370 | } |
| 371 | |
| 372 | static struct notifier_block kvm_pv_reboot_nb = { |
| 373 | .notifier_call = kvm_pv_reboot_notify, |
| 374 | }; |
| 375 | |
Glauber Costa | d910f5c | 2011-07-11 15:28:19 -0400 | [diff] [blame] | 376 | static u64 kvm_steal_clock(int cpu) |
| 377 | { |
| 378 | u64 steal; |
| 379 | struct kvm_steal_time *src; |
| 380 | int version; |
| 381 | |
| 382 | src = &per_cpu(steal_time, cpu); |
| 383 | do { |
| 384 | version = src->version; |
Wanpeng Li | 5a48a62 | 2017-04-11 02:49:21 -0700 | [diff] [blame] | 385 | virt_rmb(); |
Glauber Costa | d910f5c | 2011-07-11 15:28:19 -0400 | [diff] [blame] | 386 | steal = src->steal; |
Wanpeng Li | 5a48a62 | 2017-04-11 02:49:21 -0700 | [diff] [blame] | 387 | virt_rmb(); |
Glauber Costa | d910f5c | 2011-07-11 15:28:19 -0400 | [diff] [blame] | 388 | } while ((version & 1) || (version != src->version)); |
| 389 | |
| 390 | return steal; |
| 391 | } |
| 392 | |
| 393 | void kvm_disable_steal_time(void) |
| 394 | { |
| 395 | if (!has_steal_clock) |
| 396 | return; |
| 397 | |
| 398 | wrmsr(MSR_KVM_STEAL_TIME, 0, 0); |
| 399 | } |
| 400 | |
Brijesh Singh | 4716276 | 2017-10-20 09:30:58 -0500 | [diff] [blame] | 401 | static inline void __set_percpu_decrypted(void *ptr, unsigned long size) |
| 402 | { |
| 403 | early_set_memory_decrypted((unsigned long) ptr, size); |
| 404 | } |
| 405 | |
| 406 | /* |
| 407 | * Iterate through all possible CPUs and map the memory region pointed |
| 408 | * by apf_reason, steal_time and kvm_apic_eoi as decrypted at once. |
| 409 | * |
| 410 | * Note: we iterate through all possible CPUs to ensure that CPUs |
| 411 | * hotplugged will have their per-cpu variable already mapped as |
| 412 | * decrypted. |
| 413 | */ |
| 414 | static void __init sev_map_percpu_data(void) |
| 415 | { |
| 416 | int cpu; |
| 417 | |
| 418 | if (!sev_active()) |
| 419 | return; |
| 420 | |
| 421 | for_each_possible_cpu(cpu) { |
| 422 | __set_percpu_decrypted(&per_cpu(apf_reason, cpu), sizeof(apf_reason)); |
| 423 | __set_percpu_decrypted(&per_cpu(steal_time, cpu), sizeof(steal_time)); |
| 424 | __set_percpu_decrypted(&per_cpu(kvm_apic_eoi, cpu), sizeof(kvm_apic_eoi)); |
| 425 | } |
| 426 | } |
| 427 | |
Wanpeng Li | a262bca | 2020-02-18 09:08:23 +0800 | [diff] [blame] | 428 | static bool pv_tlb_flush_supported(void) |
| 429 | { |
| 430 | return (kvm_para_has_feature(KVM_FEATURE_PV_TLB_FLUSH) && |
| 431 | !kvm_para_has_hint(KVM_HINTS_REALTIME) && |
| 432 | kvm_para_has_feature(KVM_FEATURE_STEAL_TIME)); |
| 433 | } |
| 434 | |
Wanpeng Li | 8a9442f | 2020-02-18 09:08:24 +0800 | [diff] [blame^] | 435 | static DEFINE_PER_CPU(cpumask_var_t, __pv_cpu_mask); |
| 436 | |
Gleb Natapov | ca3f101 | 2010-10-14 11:22:49 +0200 | [diff] [blame] | 437 | #ifdef CONFIG_SMP |
Wanpeng Li | a262bca | 2020-02-18 09:08:23 +0800 | [diff] [blame] | 438 | |
| 439 | static bool pv_ipi_supported(void) |
| 440 | { |
| 441 | return kvm_para_has_feature(KVM_FEATURE_PV_SEND_IPI); |
| 442 | } |
| 443 | |
| 444 | static bool pv_sched_yield_supported(void) |
| 445 | { |
| 446 | return (kvm_para_has_feature(KVM_FEATURE_PV_SCHED_YIELD) && |
| 447 | !kvm_para_has_hint(KVM_HINTS_REALTIME) && |
| 448 | kvm_para_has_feature(KVM_FEATURE_STEAL_TIME)); |
| 449 | } |
| 450 | |
Wanpeng Li | aaffcfd | 2018-07-23 14:39:52 +0800 | [diff] [blame] | 451 | #define KVM_IPI_CLUSTER_SIZE (2 * BITS_PER_LONG) |
| 452 | |
| 453 | static void __send_ipi_mask(const struct cpumask *mask, int vector) |
| 454 | { |
| 455 | unsigned long flags; |
| 456 | int cpu, apic_id, icr; |
| 457 | int min = 0, max = 0; |
| 458 | #ifdef CONFIG_X86_64 |
| 459 | __uint128_t ipi_bitmap = 0; |
| 460 | #else |
| 461 | u64 ipi_bitmap = 0; |
| 462 | #endif |
Sean Christopherson | de81c2f | 2019-01-23 09:22:40 -0800 | [diff] [blame] | 463 | long ret; |
Wanpeng Li | aaffcfd | 2018-07-23 14:39:52 +0800 | [diff] [blame] | 464 | |
| 465 | if (cpumask_empty(mask)) |
| 466 | return; |
| 467 | |
| 468 | local_irq_save(flags); |
| 469 | |
| 470 | switch (vector) { |
| 471 | default: |
| 472 | icr = APIC_DM_FIXED | vector; |
| 473 | break; |
| 474 | case NMI_VECTOR: |
| 475 | icr = APIC_DM_NMI; |
| 476 | break; |
| 477 | } |
| 478 | |
| 479 | for_each_cpu(cpu, mask) { |
| 480 | apic_id = per_cpu(x86_cpu_to_apicid, cpu); |
| 481 | if (!ipi_bitmap) { |
| 482 | min = max = apic_id; |
| 483 | } else if (apic_id < min && max - apic_id < KVM_IPI_CLUSTER_SIZE) { |
| 484 | ipi_bitmap <<= min - apic_id; |
| 485 | min = apic_id; |
| 486 | } else if (apic_id < min + KVM_IPI_CLUSTER_SIZE) { |
| 487 | max = apic_id < max ? max : apic_id; |
| 488 | } else { |
Sean Christopherson | de81c2f | 2019-01-23 09:22:40 -0800 | [diff] [blame] | 489 | ret = kvm_hypercall4(KVM_HC_SEND_IPI, (unsigned long)ipi_bitmap, |
Wanpeng Li | aaffcfd | 2018-07-23 14:39:52 +0800 | [diff] [blame] | 490 | (unsigned long)(ipi_bitmap >> BITS_PER_LONG), min, icr); |
Sean Christopherson | de81c2f | 2019-01-23 09:22:40 -0800 | [diff] [blame] | 491 | WARN_ONCE(ret < 0, "KVM: failed to send PV IPI: %ld", ret); |
Wanpeng Li | aaffcfd | 2018-07-23 14:39:52 +0800 | [diff] [blame] | 492 | min = max = apic_id; |
| 493 | ipi_bitmap = 0; |
| 494 | } |
| 495 | __set_bit(apic_id - min, (unsigned long *)&ipi_bitmap); |
| 496 | } |
| 497 | |
| 498 | if (ipi_bitmap) { |
Sean Christopherson | de81c2f | 2019-01-23 09:22:40 -0800 | [diff] [blame] | 499 | ret = kvm_hypercall4(KVM_HC_SEND_IPI, (unsigned long)ipi_bitmap, |
Wanpeng Li | aaffcfd | 2018-07-23 14:39:52 +0800 | [diff] [blame] | 500 | (unsigned long)(ipi_bitmap >> BITS_PER_LONG), min, icr); |
Sean Christopherson | de81c2f | 2019-01-23 09:22:40 -0800 | [diff] [blame] | 501 | WARN_ONCE(ret < 0, "KVM: failed to send PV IPI: %ld", ret); |
Wanpeng Li | aaffcfd | 2018-07-23 14:39:52 +0800 | [diff] [blame] | 502 | } |
| 503 | |
| 504 | local_irq_restore(flags); |
| 505 | } |
| 506 | |
| 507 | static void kvm_send_ipi_mask(const struct cpumask *mask, int vector) |
| 508 | { |
| 509 | __send_ipi_mask(mask, vector); |
| 510 | } |
| 511 | |
| 512 | static void kvm_send_ipi_mask_allbutself(const struct cpumask *mask, int vector) |
| 513 | { |
| 514 | unsigned int this_cpu = smp_processor_id(); |
Wanpeng Li | 8a9442f | 2020-02-18 09:08:24 +0800 | [diff] [blame^] | 515 | struct cpumask *new_mask = this_cpu_cpumask_var_ptr(__pv_cpu_mask); |
Wanpeng Li | aaffcfd | 2018-07-23 14:39:52 +0800 | [diff] [blame] | 516 | const struct cpumask *local_mask; |
| 517 | |
Wanpeng Li | 8a9442f | 2020-02-18 09:08:24 +0800 | [diff] [blame^] | 518 | cpumask_copy(new_mask, mask); |
| 519 | cpumask_clear_cpu(this_cpu, new_mask); |
| 520 | local_mask = new_mask; |
Wanpeng Li | aaffcfd | 2018-07-23 14:39:52 +0800 | [diff] [blame] | 521 | __send_ipi_mask(local_mask, vector); |
| 522 | } |
| 523 | |
Wanpeng Li | aaffcfd | 2018-07-23 14:39:52 +0800 | [diff] [blame] | 524 | /* |
| 525 | * Set the IPI entry points |
| 526 | */ |
| 527 | static void kvm_setup_pv_ipi(void) |
| 528 | { |
| 529 | apic->send_IPI_mask = kvm_send_ipi_mask; |
| 530 | apic->send_IPI_mask_allbutself = kvm_send_ipi_mask_allbutself; |
Wanpeng Li | aaffcfd | 2018-07-23 14:39:52 +0800 | [diff] [blame] | 531 | pr_info("KVM setup pv IPIs\n"); |
| 532 | } |
| 533 | |
Wanpeng Li | f85f6e7 | 2019-06-11 20:23:48 +0800 | [diff] [blame] | 534 | static void kvm_smp_send_call_func_ipi(const struct cpumask *mask) |
| 535 | { |
| 536 | int cpu; |
| 537 | |
| 538 | native_send_call_func_ipi(mask); |
| 539 | |
| 540 | /* Make sure other vCPUs get a chance to run if they need to. */ |
| 541 | for_each_cpu(cpu, mask) { |
| 542 | if (vcpu_is_preempted(cpu)) { |
| 543 | kvm_hypercall1(KVM_HC_SCHED_YIELD, per_cpu(x86_cpu_to_apicid, cpu)); |
| 544 | break; |
| 545 | } |
| 546 | } |
| 547 | } |
| 548 | |
Wanpeng Li | 34226b6 | 2018-03-24 21:17:24 -0700 | [diff] [blame] | 549 | static void __init kvm_smp_prepare_cpus(unsigned int max_cpus) |
| 550 | { |
| 551 | native_smp_prepare_cpus(max_cpus); |
Michael S. Tsirkin | 633711e | 2018-05-17 17:54:24 +0300 | [diff] [blame] | 552 | if (kvm_para_has_hint(KVM_HINTS_REALTIME)) |
Wanpeng Li | 34226b6 | 2018-03-24 21:17:24 -0700 | [diff] [blame] | 553 | static_branch_disable(&virt_spin_lock_key); |
| 554 | } |
| 555 | |
Gleb Natapov | ca3f101 | 2010-10-14 11:22:49 +0200 | [diff] [blame] | 556 | static void __init kvm_smp_prepare_boot_cpu(void) |
| 557 | { |
Brijesh Singh | 4716276 | 2017-10-20 09:30:58 -0500 | [diff] [blame] | 558 | /* |
| 559 | * Map the per-cpu variables as decrypted before kvm_guest_cpu_init() |
| 560 | * shares the guest physical address with the hypervisor. |
| 561 | */ |
| 562 | sev_map_percpu_data(); |
| 563 | |
Gleb Natapov | fd10cde | 2010-10-14 11:22:51 +0200 | [diff] [blame] | 564 | kvm_guest_cpu_init(); |
Gleb Natapov | ca3f101 | 2010-10-14 11:22:49 +0200 | [diff] [blame] | 565 | native_smp_prepare_boot_cpu(); |
Srivatsa Vaddagiri | 92b7520 | 2013-08-06 14:55:41 +0530 | [diff] [blame] | 566 | kvm_spinlock_init(); |
Gleb Natapov | ca3f101 | 2010-10-14 11:22:49 +0200 | [diff] [blame] | 567 | } |
Gleb Natapov | fd10cde | 2010-10-14 11:22:51 +0200 | [diff] [blame] | 568 | |
Sebastian Andrzej Siewior | 9a20ea4 | 2016-08-18 14:57:29 +0200 | [diff] [blame] | 569 | static void kvm_guest_cpu_offline(void) |
Gleb Natapov | fd10cde | 2010-10-14 11:22:51 +0200 | [diff] [blame] | 570 | { |
Glauber Costa | d910f5c | 2011-07-11 15:28:19 -0400 | [diff] [blame] | 571 | kvm_disable_steal_time(); |
Michael S. Tsirkin | ab9cf49 | 2012-06-24 19:24:34 +0300 | [diff] [blame] | 572 | if (kvm_para_has_feature(KVM_FEATURE_PV_EOI)) |
| 573 | wrmsrl(MSR_KVM_PV_EOI_EN, 0); |
| 574 | kvm_pv_disable_apf(); |
Gleb Natapov | 631bc48 | 2010-10-14 11:22:52 +0200 | [diff] [blame] | 575 | apf_task_wake_all(); |
Gleb Natapov | fd10cde | 2010-10-14 11:22:51 +0200 | [diff] [blame] | 576 | } |
| 577 | |
Sebastian Andrzej Siewior | 9a20ea4 | 2016-08-18 14:57:29 +0200 | [diff] [blame] | 578 | static int kvm_cpu_online(unsigned int cpu) |
Gleb Natapov | fd10cde | 2010-10-14 11:22:51 +0200 | [diff] [blame] | 579 | { |
Sebastian Andrzej Siewior | 9a20ea4 | 2016-08-18 14:57:29 +0200 | [diff] [blame] | 580 | local_irq_disable(); |
| 581 | kvm_guest_cpu_init(); |
| 582 | local_irq_enable(); |
| 583 | return 0; |
Gleb Natapov | fd10cde | 2010-10-14 11:22:51 +0200 | [diff] [blame] | 584 | } |
| 585 | |
Sebastian Andrzej Siewior | 9a20ea4 | 2016-08-18 14:57:29 +0200 | [diff] [blame] | 586 | static int kvm_cpu_down_prepare(unsigned int cpu) |
| 587 | { |
| 588 | local_irq_disable(); |
| 589 | kvm_guest_cpu_offline(); |
| 590 | local_irq_enable(); |
| 591 | return 0; |
| 592 | } |
Gleb Natapov | ca3f101 | 2010-10-14 11:22:49 +0200 | [diff] [blame] | 593 | #endif |
| 594 | |
Gleb Natapov | 631bc48 | 2010-10-14 11:22:52 +0200 | [diff] [blame] | 595 | static void __init kvm_apf_trap_init(void) |
| 596 | { |
Thomas Gleixner | facaa3e | 2017-08-28 08:47:59 +0200 | [diff] [blame] | 597 | update_intr_gate(X86_TRAP_PF, async_page_fault); |
Gleb Natapov | 631bc48 | 2010-10-14 11:22:52 +0200 | [diff] [blame] | 598 | } |
| 599 | |
Wanpeng Li | 858a43a | 2017-12-12 17:33:02 -0800 | [diff] [blame] | 600 | |
| 601 | static void kvm_flush_tlb_others(const struct cpumask *cpumask, |
| 602 | const struct flush_tlb_info *info) |
| 603 | { |
| 604 | u8 state; |
| 605 | int cpu; |
| 606 | struct kvm_steal_time *src; |
Wanpeng Li | 8a9442f | 2020-02-18 09:08:24 +0800 | [diff] [blame^] | 607 | struct cpumask *flushmask = this_cpu_cpumask_var_ptr(__pv_cpu_mask); |
Wanpeng Li | 858a43a | 2017-12-12 17:33:02 -0800 | [diff] [blame] | 608 | |
| 609 | cpumask_copy(flushmask, cpumask); |
| 610 | /* |
| 611 | * We have to call flush only on online vCPUs. And |
| 612 | * queue flush_on_enter for pre-empted vCPUs |
| 613 | */ |
| 614 | for_each_cpu(cpu, flushmask) { |
| 615 | src = &per_cpu(steal_time, cpu); |
| 616 | state = READ_ONCE(src->preempted); |
| 617 | if ((state & KVM_VCPU_PREEMPTED)) { |
| 618 | if (try_cmpxchg(&src->preempted, &state, |
| 619 | state | KVM_VCPU_FLUSH_TLB)) |
| 620 | __cpumask_clear_cpu(cpu, flushmask); |
| 621 | } |
| 622 | } |
| 623 | |
| 624 | native_flush_tlb_others(flushmask, info); |
| 625 | } |
| 626 | |
Juergen Gross | f361464 | 2017-11-09 14:27:38 +0100 | [diff] [blame] | 627 | static void __init kvm_guest_init(void) |
Marcelo Tosatti | 0cf1bfd | 2008-02-22 12:21:36 -0500 | [diff] [blame] | 628 | { |
Gleb Natapov | 631bc48 | 2010-10-14 11:22:52 +0200 | [diff] [blame] | 629 | int i; |
| 630 | |
Marcelo Tosatti | 0cf1bfd | 2008-02-22 12:21:36 -0500 | [diff] [blame] | 631 | paravirt_ops_setup(); |
Gleb Natapov | fd10cde | 2010-10-14 11:22:51 +0200 | [diff] [blame] | 632 | register_reboot_notifier(&kvm_pv_reboot_nb); |
Gleb Natapov | 631bc48 | 2010-10-14 11:22:52 +0200 | [diff] [blame] | 633 | for (i = 0; i < KVM_TASK_SLEEP_HASHSIZE; i++) |
Rik van Riel | 9db284f | 2016-03-21 15:13:27 +0100 | [diff] [blame] | 634 | raw_spin_lock_init(&async_pf_sleepers[i].lock); |
Gleb Natapov | 631bc48 | 2010-10-14 11:22:52 +0200 | [diff] [blame] | 635 | if (kvm_para_has_feature(KVM_FEATURE_ASYNC_PF)) |
| 636 | x86_init.irqs.trap_init = kvm_apf_trap_init; |
| 637 | |
Glauber Costa | d910f5c | 2011-07-11 15:28:19 -0400 | [diff] [blame] | 638 | if (kvm_para_has_feature(KVM_FEATURE_STEAL_TIME)) { |
| 639 | has_steal_clock = 1; |
Juergen Gross | 5c83511 | 2018-08-28 09:40:19 +0200 | [diff] [blame] | 640 | pv_ops.time.steal_clock = kvm_steal_clock; |
Glauber Costa | d910f5c | 2011-07-11 15:28:19 -0400 | [diff] [blame] | 641 | } |
| 642 | |
Wanpeng Li | a262bca | 2020-02-18 09:08:23 +0800 | [diff] [blame] | 643 | if (pv_tlb_flush_supported()) { |
Juergen Gross | 5c83511 | 2018-08-28 09:40:19 +0200 | [diff] [blame] | 644 | pv_ops.mmu.flush_tlb_others = kvm_flush_tlb_others; |
| 645 | pv_ops.mmu.tlb_remove_table = tlb_remove_table; |
Wanpeng Li | 8a9442f | 2020-02-18 09:08:24 +0800 | [diff] [blame^] | 646 | pr_info("KVM setup pv remote TLB flush\n"); |
Peter Zijlstra | 48a8b97 | 2018-08-22 17:30:16 +0200 | [diff] [blame] | 647 | } |
Wanpeng Li | 858a43a | 2017-12-12 17:33:02 -0800 | [diff] [blame] | 648 | |
Michael S. Tsirkin | 9053666 | 2012-07-15 15:56:52 +0300 | [diff] [blame] | 649 | if (kvm_para_has_feature(KVM_FEATURE_PV_EOI)) |
| 650 | apic_set_eoi_write(kvm_guest_apic_eoi_write); |
Michael S. Tsirkin | ab9cf49 | 2012-06-24 19:24:34 +0300 | [diff] [blame] | 651 | |
Gleb Natapov | ca3f101 | 2010-10-14 11:22:49 +0200 | [diff] [blame] | 652 | #ifdef CONFIG_SMP |
Wanpeng Li | 34226b6 | 2018-03-24 21:17:24 -0700 | [diff] [blame] | 653 | smp_ops.smp_prepare_cpus = kvm_smp_prepare_cpus; |
Gleb Natapov | ca3f101 | 2010-10-14 11:22:49 +0200 | [diff] [blame] | 654 | smp_ops.smp_prepare_boot_cpu = kvm_smp_prepare_boot_cpu; |
Wanpeng Li | a262bca | 2020-02-18 09:08:23 +0800 | [diff] [blame] | 655 | if (pv_sched_yield_supported()) { |
Wanpeng Li | f85f6e7 | 2019-06-11 20:23:48 +0800 | [diff] [blame] | 656 | smp_ops.send_call_func_ipi = kvm_smp_send_call_func_ipi; |
| 657 | pr_info("KVM setup pv sched yield\n"); |
| 658 | } |
Sebastian Andrzej Siewior | 9a20ea4 | 2016-08-18 14:57:29 +0200 | [diff] [blame] | 659 | if (cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN, "x86/kvm:online", |
| 660 | kvm_cpu_online, kvm_cpu_down_prepare) < 0) |
| 661 | pr_err("kvm_guest: Failed to install cpu hotplug callbacks\n"); |
Gleb Natapov | fd10cde | 2010-10-14 11:22:51 +0200 | [diff] [blame] | 662 | #else |
Brijesh Singh | 4716276 | 2017-10-20 09:30:58 -0500 | [diff] [blame] | 663 | sev_map_percpu_data(); |
Gleb Natapov | fd10cde | 2010-10-14 11:22:51 +0200 | [diff] [blame] | 664 | kvm_guest_cpu_init(); |
Gleb Natapov | ca3f101 | 2010-10-14 11:22:49 +0200 | [diff] [blame] | 665 | #endif |
Ulrich Obergfell | 9919e39 | 2014-10-13 15:55:37 -0700 | [diff] [blame] | 666 | |
| 667 | /* |
| 668 | * Hard lockup detection is enabled by default. Disable it, as guests |
| 669 | * can get false positives too easily, for example if the host is |
| 670 | * overcommitted. |
| 671 | */ |
Ulrich Obergfell | 692297d | 2015-04-14 15:44:19 -0700 | [diff] [blame] | 672 | hardlockup_detector_disable(); |
Marcelo Tosatti | 0cf1bfd | 2008-02-22 12:21:36 -0500 | [diff] [blame] | 673 | } |
Glauber Costa | d910f5c | 2011-07-11 15:28:19 -0400 | [diff] [blame] | 674 | |
Paolo Bonzini | 1c300a4 | 2014-01-27 14:49:40 +0100 | [diff] [blame] | 675 | static noinline uint32_t __kvm_cpuid_base(void) |
| 676 | { |
| 677 | if (boot_cpu_data.cpuid_level < 0) |
| 678 | return 0; /* So we don't blow up on old processors */ |
| 679 | |
Borislav Petkov | 0c9f3536 | 2016-03-29 17:41:55 +0200 | [diff] [blame] | 680 | if (boot_cpu_has(X86_FEATURE_HYPERVISOR)) |
Paolo Bonzini | 1c300a4 | 2014-01-27 14:49:40 +0100 | [diff] [blame] | 681 | return hypervisor_cpuid_base("KVMKVMKVM\0\0\0", 0); |
| 682 | |
| 683 | return 0; |
| 684 | } |
| 685 | |
| 686 | static inline uint32_t kvm_cpuid_base(void) |
| 687 | { |
| 688 | static int kvm_cpuid_base = -1; |
| 689 | |
| 690 | if (kvm_cpuid_base == -1) |
| 691 | kvm_cpuid_base = __kvm_cpuid_base(); |
| 692 | |
| 693 | return kvm_cpuid_base; |
| 694 | } |
| 695 | |
| 696 | bool kvm_para_available(void) |
| 697 | { |
| 698 | return kvm_cpuid_base() != 0; |
| 699 | } |
| 700 | EXPORT_SYMBOL_GPL(kvm_para_available); |
| 701 | |
Paolo Bonzini | 77f01bd | 2014-01-27 14:51:44 +0100 | [diff] [blame] | 702 | unsigned int kvm_arch_para_features(void) |
| 703 | { |
| 704 | return cpuid_eax(kvm_cpuid_base() | KVM_CPUID_FEATURES); |
| 705 | } |
| 706 | |
Wanpeng Li | a4429e5 | 2018-02-13 09:05:40 +0800 | [diff] [blame] | 707 | unsigned int kvm_arch_para_hints(void) |
| 708 | { |
| 709 | return cpuid_edx(kvm_cpuid_base() | KVM_CPUID_FEATURES); |
| 710 | } |
Wanpeng Li | 1328edc | 2019-08-29 16:49:57 +0800 | [diff] [blame] | 711 | EXPORT_SYMBOL_GPL(kvm_arch_para_hints); |
Wanpeng Li | a4429e5 | 2018-02-13 09:05:40 +0800 | [diff] [blame] | 712 | |
Jason Wang | 9df56f1 | 2013-07-25 16:54:35 +0800 | [diff] [blame] | 713 | static uint32_t __init kvm_detect(void) |
Prarit Bhargava | fc73373 | 2012-07-06 13:47:39 -0400 | [diff] [blame] | 714 | { |
Jason Wang | 9df56f1 | 2013-07-25 16:54:35 +0800 | [diff] [blame] | 715 | return kvm_cpuid_base(); |
Prarit Bhargava | fc73373 | 2012-07-06 13:47:39 -0400 | [diff] [blame] | 716 | } |
| 717 | |
Wanpeng Li | d63bae0 | 2018-07-23 14:39:51 +0800 | [diff] [blame] | 718 | static void __init kvm_apic_init(void) |
| 719 | { |
Wanpeng Li | aaffcfd | 2018-07-23 14:39:52 +0800 | [diff] [blame] | 720 | #if defined(CONFIG_SMP) |
Wanpeng Li | a262bca | 2020-02-18 09:08:23 +0800 | [diff] [blame] | 721 | if (pv_ipi_supported()) |
Wanpeng Li | aaffcfd | 2018-07-23 14:39:52 +0800 | [diff] [blame] | 722 | kvm_setup_pv_ipi(); |
| 723 | #endif |
Wanpeng Li | d63bae0 | 2018-07-23 14:39:51 +0800 | [diff] [blame] | 724 | } |
| 725 | |
| 726 | static void __init kvm_init_platform(void) |
| 727 | { |
Linus Torvalds | e61cf2e | 2018-08-19 10:38:36 -0700 | [diff] [blame] | 728 | kvmclock_init(); |
Wanpeng Li | d63bae0 | 2018-07-23 14:39:51 +0800 | [diff] [blame] | 729 | x86_platform.apic_post_init = kvm_apic_init; |
| 730 | } |
| 731 | |
Juergen Gross | 03b2a32 | 2017-11-09 14:27:36 +0100 | [diff] [blame] | 732 | const __initconst struct hypervisor_x86 x86_hyper_kvm = { |
Prarit Bhargava | fc73373 | 2012-07-06 13:47:39 -0400 | [diff] [blame] | 733 | .name = "KVM", |
| 734 | .detect = kvm_detect, |
Juergen Gross | 03b2a32 | 2017-11-09 14:27:36 +0100 | [diff] [blame] | 735 | .type = X86_HYPER_KVM, |
Juergen Gross | f361464 | 2017-11-09 14:27:38 +0100 | [diff] [blame] | 736 | .init.guest_late_init = kvm_guest_init, |
Juergen Gross | f72e38e | 2017-11-09 14:27:35 +0100 | [diff] [blame] | 737 | .init.x2apic_available = kvm_para_available, |
Wanpeng Li | d63bae0 | 2018-07-23 14:39:51 +0800 | [diff] [blame] | 738 | .init.init_platform = kvm_init_platform, |
Prarit Bhargava | fc73373 | 2012-07-06 13:47:39 -0400 | [diff] [blame] | 739 | }; |
Prarit Bhargava | fc73373 | 2012-07-06 13:47:39 -0400 | [diff] [blame] | 740 | |
Glauber Costa | d910f5c | 2011-07-11 15:28:19 -0400 | [diff] [blame] | 741 | static __init int activate_jump_labels(void) |
| 742 | { |
| 743 | if (has_steal_clock) { |
Ingo Molnar | c5905af | 2012-02-24 08:31:31 +0100 | [diff] [blame] | 744 | static_key_slow_inc(¶virt_steal_enabled); |
Glauber Costa | d910f5c | 2011-07-11 15:28:19 -0400 | [diff] [blame] | 745 | if (steal_acc) |
Ingo Molnar | c5905af | 2012-02-24 08:31:31 +0100 | [diff] [blame] | 746 | static_key_slow_inc(¶virt_steal_rq_enabled); |
Glauber Costa | d910f5c | 2011-07-11 15:28:19 -0400 | [diff] [blame] | 747 | } |
| 748 | |
| 749 | return 0; |
| 750 | } |
| 751 | arch_initcall(activate_jump_labels); |
Srivatsa Vaddagiri | 92b7520 | 2013-08-06 14:55:41 +0530 | [diff] [blame] | 752 | |
Wanpeng Li | 8a9442f | 2020-02-18 09:08:24 +0800 | [diff] [blame^] | 753 | static __init int kvm_alloc_cpumask(void) |
Wanpeng Li | 858a43a | 2017-12-12 17:33:02 -0800 | [diff] [blame] | 754 | { |
| 755 | int cpu; |
Wanpeng Li | 8a9442f | 2020-02-18 09:08:24 +0800 | [diff] [blame^] | 756 | bool alloc = false; |
Wanpeng Li | 858a43a | 2017-12-12 17:33:02 -0800 | [diff] [blame] | 757 | |
Thadeu Lima de Souza Cascardo | 64b38bd | 2020-01-31 12:56:55 -0300 | [diff] [blame] | 758 | if (!kvm_para_available() || nopv) |
| 759 | return 0; |
| 760 | |
Wanpeng Li | 8a9442f | 2020-02-18 09:08:24 +0800 | [diff] [blame^] | 761 | if (pv_tlb_flush_supported()) |
| 762 | alloc = true; |
| 763 | |
| 764 | #if defined(CONFIG_SMP) |
| 765 | if (pv_ipi_supported()) |
| 766 | alloc = true; |
| 767 | #endif |
| 768 | |
| 769 | if (alloc) |
Wanpeng Li | 858a43a | 2017-12-12 17:33:02 -0800 | [diff] [blame] | 770 | for_each_possible_cpu(cpu) { |
Wanpeng Li | 8a9442f | 2020-02-18 09:08:24 +0800 | [diff] [blame^] | 771 | zalloc_cpumask_var_node(per_cpu_ptr(&__pv_cpu_mask, cpu), |
Wanpeng Li | 858a43a | 2017-12-12 17:33:02 -0800 | [diff] [blame] | 772 | GFP_KERNEL, cpu_to_node(cpu)); |
| 773 | } |
Wanpeng Li | 858a43a | 2017-12-12 17:33:02 -0800 | [diff] [blame] | 774 | |
| 775 | return 0; |
| 776 | } |
Wanpeng Li | 8a9442f | 2020-02-18 09:08:24 +0800 | [diff] [blame^] | 777 | arch_initcall(kvm_alloc_cpumask); |
Wanpeng Li | 858a43a | 2017-12-12 17:33:02 -0800 | [diff] [blame] | 778 | |
Srivatsa Vaddagiri | 92b7520 | 2013-08-06 14:55:41 +0530 | [diff] [blame] | 779 | #ifdef CONFIG_PARAVIRT_SPINLOCKS |
| 780 | |
| 781 | /* Kick a cpu by its apicid. Used to wake up a halted vcpu */ |
Raghavendra K T | 36bd621 | 2013-08-16 15:08:41 +0530 | [diff] [blame] | 782 | static void kvm_kick_cpu(int cpu) |
Srivatsa Vaddagiri | 92b7520 | 2013-08-06 14:55:41 +0530 | [diff] [blame] | 783 | { |
| 784 | int apicid; |
| 785 | unsigned long flags = 0; |
| 786 | |
| 787 | apicid = per_cpu(x86_cpu_to_apicid, cpu); |
| 788 | kvm_hypercall2(KVM_HC_KICK_CPU, flags, apicid); |
| 789 | } |
| 790 | |
Waiman Long | bf0c7c3 | 2015-04-24 14:56:39 -0400 | [diff] [blame] | 791 | #include <asm/qspinlock.h> |
| 792 | |
| 793 | static void kvm_wait(u8 *ptr, u8 val) |
| 794 | { |
| 795 | unsigned long flags; |
| 796 | |
| 797 | if (in_nmi()) |
| 798 | return; |
| 799 | |
| 800 | local_irq_save(flags); |
| 801 | |
| 802 | if (READ_ONCE(*ptr) != val) |
| 803 | goto out; |
| 804 | |
| 805 | /* |
| 806 | * halt until it's our turn and kicked. Note that we do safe halt |
| 807 | * for irq enabled case to avoid hang when lock info is overwritten |
| 808 | * in irq spinlock slowpath and no spurious interrupt occur to save us. |
| 809 | */ |
| 810 | if (arch_irqs_disabled_flags(flags)) |
| 811 | halt(); |
| 812 | else |
| 813 | safe_halt(); |
| 814 | |
| 815 | out: |
| 816 | local_irq_restore(flags); |
| 817 | } |
| 818 | |
Waiman Long | dd0fd8b | 2017-02-20 13:36:04 -0500 | [diff] [blame] | 819 | #ifdef CONFIG_X86_32 |
Waiman Long | 6c62985 | 2017-02-20 13:36:03 -0500 | [diff] [blame] | 820 | __visible bool __kvm_vcpu_is_preempted(long cpu) |
Peter Zijlstra | 3cded41 | 2016-11-15 16:47:06 +0100 | [diff] [blame] | 821 | { |
| 822 | struct kvm_steal_time *src = &per_cpu(steal_time, cpu); |
| 823 | |
Wanpeng Li | fa55eed | 2017-12-12 17:33:01 -0800 | [diff] [blame] | 824 | return !!(src->preempted & KVM_VCPU_PREEMPTED); |
Peter Zijlstra | 3cded41 | 2016-11-15 16:47:06 +0100 | [diff] [blame] | 825 | } |
| 826 | PV_CALLEE_SAVE_REGS_THUNK(__kvm_vcpu_is_preempted); |
| 827 | |
Waiman Long | dd0fd8b | 2017-02-20 13:36:04 -0500 | [diff] [blame] | 828 | #else |
| 829 | |
| 830 | #include <asm/asm-offsets.h> |
| 831 | |
| 832 | extern bool __raw_callee_save___kvm_vcpu_is_preempted(long); |
| 833 | |
| 834 | /* |
| 835 | * Hand-optimize version for x86-64 to avoid 8 64-bit register saving and |
| 836 | * restoring to/from the stack. |
| 837 | */ |
| 838 | asm( |
| 839 | ".pushsection .text;" |
| 840 | ".global __raw_callee_save___kvm_vcpu_is_preempted;" |
| 841 | ".type __raw_callee_save___kvm_vcpu_is_preempted, @function;" |
| 842 | "__raw_callee_save___kvm_vcpu_is_preempted:" |
| 843 | "movq __per_cpu_offset(,%rdi,8), %rax;" |
| 844 | "cmpb $0, " __stringify(KVM_STEAL_TIME_preempted) "+steal_time(%rax);" |
| 845 | "setne %al;" |
| 846 | "ret;" |
Josh Poimboeuf | 083db67 | 2019-07-17 20:36:36 -0500 | [diff] [blame] | 847 | ".size __raw_callee_save___kvm_vcpu_is_preempted, .-__raw_callee_save___kvm_vcpu_is_preempted;" |
Waiman Long | dd0fd8b | 2017-02-20 13:36:04 -0500 | [diff] [blame] | 848 | ".popsection"); |
| 849 | |
| 850 | #endif |
| 851 | |
Srivatsa Vaddagiri | 92b7520 | 2013-08-06 14:55:41 +0530 | [diff] [blame] | 852 | /* |
| 853 | * Setup pv_lock_ops to exploit KVM_FEATURE_PV_UNHALT if present. |
| 854 | */ |
| 855 | void __init kvm_spinlock_init(void) |
| 856 | { |
Srivatsa Vaddagiri | 92b7520 | 2013-08-06 14:55:41 +0530 | [diff] [blame] | 857 | /* Does host kernel support KVM_FEATURE_PV_UNHALT? */ |
| 858 | if (!kvm_para_has_feature(KVM_FEATURE_PV_UNHALT)) |
| 859 | return; |
| 860 | |
Michael S. Tsirkin | 633711e | 2018-05-17 17:54:24 +0300 | [diff] [blame] | 861 | if (kvm_para_has_hint(KVM_HINTS_REALTIME)) |
Wanpeng Li | b2798ba | 2018-02-13 09:05:41 +0800 | [diff] [blame] | 862 | return; |
Wanpeng Li | b2798ba | 2018-02-13 09:05:41 +0800 | [diff] [blame] | 863 | |
Waiman Long | 3553ae5 | 2018-07-17 17:59:27 -0400 | [diff] [blame] | 864 | /* Don't use the pvqspinlock code if there is only 1 vCPU. */ |
| 865 | if (num_possible_cpus() == 1) |
| 866 | return; |
| 867 | |
Waiman Long | bf0c7c3 | 2015-04-24 14:56:39 -0400 | [diff] [blame] | 868 | __pv_init_lock_hash(); |
Juergen Gross | 5c83511 | 2018-08-28 09:40:19 +0200 | [diff] [blame] | 869 | pv_ops.lock.queued_spin_lock_slowpath = __pv_queued_spin_lock_slowpath; |
| 870 | pv_ops.lock.queued_spin_unlock = |
| 871 | PV_CALLEE_SAVE(__pv_queued_spin_unlock); |
| 872 | pv_ops.lock.wait = kvm_wait; |
| 873 | pv_ops.lock.kick = kvm_kick_cpu; |
Peter Zijlstra | 3cded41 | 2016-11-15 16:47:06 +0100 | [diff] [blame] | 874 | |
| 875 | if (kvm_para_has_feature(KVM_FEATURE_STEAL_TIME)) { |
Juergen Gross | 5c83511 | 2018-08-28 09:40:19 +0200 | [diff] [blame] | 876 | pv_ops.lock.vcpu_is_preempted = |
Peter Zijlstra | 3cded41 | 2016-11-15 16:47:06 +0100 | [diff] [blame] | 877 | PV_CALLEE_SAVE(__kvm_vcpu_is_preempted); |
| 878 | } |
Srivatsa Vaddagiri | 92b7520 | 2013-08-06 14:55:41 +0530 | [diff] [blame] | 879 | } |
Raghavendra K T | 3dbef3e | 2013-10-09 14:33:21 +0530 | [diff] [blame] | 880 | |
Srivatsa Vaddagiri | 92b7520 | 2013-08-06 14:55:41 +0530 | [diff] [blame] | 881 | #endif /* CONFIG_PARAVIRT_SPINLOCKS */ |
Marcelo Tosatti | a1c4423 | 2019-07-03 20:51:29 -0300 | [diff] [blame] | 882 | |
| 883 | #ifdef CONFIG_ARCH_CPUIDLE_HALTPOLL |
| 884 | |
| 885 | static void kvm_disable_host_haltpoll(void *i) |
| 886 | { |
| 887 | wrmsrl(MSR_KVM_POLL_CONTROL, 0); |
| 888 | } |
| 889 | |
| 890 | static void kvm_enable_host_haltpoll(void *i) |
| 891 | { |
| 892 | wrmsrl(MSR_KVM_POLL_CONTROL, 1); |
| 893 | } |
| 894 | |
Joao Martins | 97d3eb9 | 2019-09-02 11:40:31 +0100 | [diff] [blame] | 895 | void arch_haltpoll_enable(unsigned int cpu) |
Marcelo Tosatti | a1c4423 | 2019-07-03 20:51:29 -0300 | [diff] [blame] | 896 | { |
| 897 | if (!kvm_para_has_feature(KVM_FEATURE_POLL_CONTROL)) { |
Joao Martins | 97d3eb9 | 2019-09-02 11:40:31 +0100 | [diff] [blame] | 898 | pr_err_once("kvm: host does not support poll control\n"); |
| 899 | pr_err_once("kvm: host upgrade recommended\n"); |
Marcelo Tosatti | a1c4423 | 2019-07-03 20:51:29 -0300 | [diff] [blame] | 900 | return; |
| 901 | } |
| 902 | |
Marcelo Tosatti | a1c4423 | 2019-07-03 20:51:29 -0300 | [diff] [blame] | 903 | /* Enable guest halt poll disables host halt poll */ |
Joao Martins | 97d3eb9 | 2019-09-02 11:40:31 +0100 | [diff] [blame] | 904 | smp_call_function_single(cpu, kvm_disable_host_haltpoll, NULL, 1); |
Marcelo Tosatti | a1c4423 | 2019-07-03 20:51:29 -0300 | [diff] [blame] | 905 | } |
| 906 | EXPORT_SYMBOL_GPL(arch_haltpoll_enable); |
| 907 | |
Joao Martins | 97d3eb9 | 2019-09-02 11:40:31 +0100 | [diff] [blame] | 908 | void arch_haltpoll_disable(unsigned int cpu) |
Marcelo Tosatti | a1c4423 | 2019-07-03 20:51:29 -0300 | [diff] [blame] | 909 | { |
| 910 | if (!kvm_para_has_feature(KVM_FEATURE_POLL_CONTROL)) |
| 911 | return; |
| 912 | |
Marcelo Tosatti | a1c4423 | 2019-07-03 20:51:29 -0300 | [diff] [blame] | 913 | /* Enable guest halt poll disables host halt poll */ |
Joao Martins | 97d3eb9 | 2019-09-02 11:40:31 +0100 | [diff] [blame] | 914 | smp_call_function_single(cpu, kvm_enable_host_haltpoll, NULL, 1); |
Marcelo Tosatti | a1c4423 | 2019-07-03 20:51:29 -0300 | [diff] [blame] | 915 | } |
| 916 | EXPORT_SYMBOL_GPL(arch_haltpoll_disable); |
| 917 | #endif |