blob: cd6d9a5a42f60dcb93a528853fe65b8773b0832e [file] [log] [blame]
Marcelo Tosatti0cf1bfd2008-02-22 12:21:36 -05001/*
2 * KVM paravirt_ops implementation
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 *
18 * Copyright (C) 2007, Red Hat, Inc., Ingo Molnar <mingo@redhat.com>
19 * Copyright IBM Corporation, 2007
20 * Authors: Anthony Liguori <aliguori@us.ibm.com>
21 */
22
Frederic Weisbecker56dd9472013-02-24 00:23:25 +010023#include <linux/context_tracking.h>
Marcelo Tosatti0cf1bfd2008-02-22 12:21:36 -050024#include <linux/module.h>
25#include <linux/kernel.h>
26#include <linux/kvm_para.h>
27#include <linux/cpu.h>
28#include <linux/mm.h>
Marcelo Tosatti1da8a772008-02-22 12:21:37 -050029#include <linux/highmem.h>
Marcelo Tosatti096d14a2008-02-22 12:21:38 -050030#include <linux/hardirq.h>
Gleb Natapovfd10cde2010-10-14 11:22:51 +020031#include <linux/notifier.h>
32#include <linux/reboot.h>
Gleb Natapov631bc482010-10-14 11:22:52 +020033#include <linux/hash.h>
34#include <linux/sched.h>
35#include <linux/slab.h>
36#include <linux/kprobes.h>
Marcelo Tosattia90ede72009-02-11 22:45:42 -020037#include <asm/timer.h>
Gleb Natapovfd10cde2010-10-14 11:22:51 +020038#include <asm/cpu.h>
Gleb Natapov631bc482010-10-14 11:22:52 +020039#include <asm/traps.h>
40#include <asm/desc.h>
Gleb Natapov6c047cd2010-10-14 11:22:54 +020041#include <asm/tlbflush.h>
Gleb Natapove0875922012-04-04 15:30:33 +030042#include <asm/idle.h>
Michael S. Tsirkinab9cf492012-06-24 19:24:34 +030043#include <asm/apic.h>
44#include <asm/apicdef.h>
Prarit Bhargavafc733732012-07-06 13:47:39 -040045#include <asm/hypervisor.h>
Marcelo Tosatti3dc4f7c2012-11-27 23:28:56 -020046#include <asm/kvm_guest.h>
Marcelo Tosatti096d14a2008-02-22 12:21:38 -050047
Gleb Natapovfd10cde2010-10-14 11:22:51 +020048static int kvmapf = 1;
49
50static int parse_no_kvmapf(char *arg)
51{
52 kvmapf = 0;
53 return 0;
54}
55
56early_param("no-kvmapf", parse_no_kvmapf);
57
Glauber Costad910f5c2011-07-11 15:28:19 -040058static int steal_acc = 1;
59static int parse_no_stealacc(char *arg)
60{
61 steal_acc = 0;
62 return 0;
63}
64
65early_param("no-steal-acc", parse_no_stealacc);
66
Marcelo Tosatti3dc4f7c2012-11-27 23:28:56 -020067static int kvmclock_vsyscall = 1;
68static int parse_no_kvmclock_vsyscall(char *arg)
69{
70 kvmclock_vsyscall = 0;
71 return 0;
72}
73
74early_param("no-kvmclock-vsyscall", parse_no_kvmclock_vsyscall);
75
Gleb Natapovfd10cde2010-10-14 11:22:51 +020076static DEFINE_PER_CPU(struct kvm_vcpu_pv_apf_data, apf_reason) __aligned(64);
Glauber Costad910f5c2011-07-11 15:28:19 -040077static DEFINE_PER_CPU(struct kvm_steal_time, steal_time) __aligned(64);
78static int has_steal_clock = 0;
Marcelo Tosatti096d14a2008-02-22 12:21:38 -050079
Marcelo Tosatti0cf1bfd2008-02-22 12:21:36 -050080/*
81 * No need for any "IO delay" on KVM
82 */
83static void kvm_io_delay(void)
84{
85}
86
Gleb Natapov631bc482010-10-14 11:22:52 +020087#define KVM_TASK_SLEEP_HASHBITS 8
88#define KVM_TASK_SLEEP_HASHSIZE (1<<KVM_TASK_SLEEP_HASHBITS)
89
90struct kvm_task_sleep_node {
91 struct hlist_node link;
92 wait_queue_head_t wq;
93 u32 token;
94 int cpu;
Gleb Natapov6c047cd2010-10-14 11:22:54 +020095 bool halted;
Gleb Natapov631bc482010-10-14 11:22:52 +020096};
97
98static struct kvm_task_sleep_head {
99 spinlock_t lock;
100 struct hlist_head list;
101} async_pf_sleepers[KVM_TASK_SLEEP_HASHSIZE];
102
103static struct kvm_task_sleep_node *_find_apf_task(struct kvm_task_sleep_head *b,
104 u32 token)
105{
106 struct hlist_node *p;
107
108 hlist_for_each(p, &b->list) {
109 struct kvm_task_sleep_node *n =
110 hlist_entry(p, typeof(*n), link);
111 if (n->token == token)
112 return n;
113 }
114
115 return NULL;
116}
117
118void kvm_async_pf_task_wait(u32 token)
119{
120 u32 key = hash_32(token, KVM_TASK_SLEEP_HASHBITS);
121 struct kvm_task_sleep_head *b = &async_pf_sleepers[key];
122 struct kvm_task_sleep_node n, *e;
123 DEFINE_WAIT(wait);
124
Li Zhong9b132fb2012-12-04 10:35:13 +0800125 rcu_irq_enter();
126
Gleb Natapov631bc482010-10-14 11:22:52 +0200127 spin_lock(&b->lock);
128 e = _find_apf_task(b, token);
129 if (e) {
130 /* dummy entry exist -> wake up was delivered ahead of PF */
131 hlist_del(&e->link);
132 kfree(e);
133 spin_unlock(&b->lock);
Li Zhong9b132fb2012-12-04 10:35:13 +0800134
135 rcu_irq_exit();
Gleb Natapov631bc482010-10-14 11:22:52 +0200136 return;
137 }
138
139 n.token = token;
140 n.cpu = smp_processor_id();
Gleb Natapov859f8452012-11-28 15:19:08 +0200141 n.halted = is_idle_task(current) || preempt_count() > 1;
Gleb Natapov631bc482010-10-14 11:22:52 +0200142 init_waitqueue_head(&n.wq);
143 hlist_add_head(&n.link, &b->list);
144 spin_unlock(&b->lock);
145
146 for (;;) {
Gleb Natapov6c047cd2010-10-14 11:22:54 +0200147 if (!n.halted)
148 prepare_to_wait(&n.wq, &wait, TASK_UNINTERRUPTIBLE);
Gleb Natapov631bc482010-10-14 11:22:52 +0200149 if (hlist_unhashed(&n.link))
150 break;
Gleb Natapov6c047cd2010-10-14 11:22:54 +0200151
152 if (!n.halted) {
153 local_irq_enable();
154 schedule();
155 local_irq_disable();
156 } else {
157 /*
158 * We cannot reschedule. So halt.
159 */
Li Zhong9b132fb2012-12-04 10:35:13 +0800160 rcu_irq_exit();
Gleb Natapov6c047cd2010-10-14 11:22:54 +0200161 native_safe_halt();
Li Zhong9b132fb2012-12-04 10:35:13 +0800162 rcu_irq_enter();
Gleb Natapov6c047cd2010-10-14 11:22:54 +0200163 local_irq_disable();
164 }
Gleb Natapov631bc482010-10-14 11:22:52 +0200165 }
Gleb Natapov6c047cd2010-10-14 11:22:54 +0200166 if (!n.halted)
167 finish_wait(&n.wq, &wait);
Gleb Natapov631bc482010-10-14 11:22:52 +0200168
Li Zhong9b132fb2012-12-04 10:35:13 +0800169 rcu_irq_exit();
Gleb Natapov631bc482010-10-14 11:22:52 +0200170 return;
171}
172EXPORT_SYMBOL_GPL(kvm_async_pf_task_wait);
173
174static void apf_task_wake_one(struct kvm_task_sleep_node *n)
175{
176 hlist_del_init(&n->link);
Gleb Natapov6c047cd2010-10-14 11:22:54 +0200177 if (n->halted)
178 smp_send_reschedule(n->cpu);
179 else if (waitqueue_active(&n->wq))
Gleb Natapov631bc482010-10-14 11:22:52 +0200180 wake_up(&n->wq);
181}
182
183static void apf_task_wake_all(void)
184{
185 int i;
186
187 for (i = 0; i < KVM_TASK_SLEEP_HASHSIZE; i++) {
188 struct hlist_node *p, *next;
189 struct kvm_task_sleep_head *b = &async_pf_sleepers[i];
190 spin_lock(&b->lock);
191 hlist_for_each_safe(p, next, &b->list) {
192 struct kvm_task_sleep_node *n =
193 hlist_entry(p, typeof(*n), link);
194 if (n->cpu == smp_processor_id())
195 apf_task_wake_one(n);
196 }
197 spin_unlock(&b->lock);
198 }
199}
200
201void kvm_async_pf_task_wake(u32 token)
202{
203 u32 key = hash_32(token, KVM_TASK_SLEEP_HASHBITS);
204 struct kvm_task_sleep_head *b = &async_pf_sleepers[key];
205 struct kvm_task_sleep_node *n;
206
207 if (token == ~0) {
208 apf_task_wake_all();
209 return;
210 }
211
212again:
213 spin_lock(&b->lock);
214 n = _find_apf_task(b, token);
215 if (!n) {
216 /*
217 * async PF was not yet handled.
218 * Add dummy entry for the token.
219 */
Gleb Natapov62c49cc2012-05-02 15:04:02 +0300220 n = kzalloc(sizeof(*n), GFP_ATOMIC);
Gleb Natapov631bc482010-10-14 11:22:52 +0200221 if (!n) {
222 /*
223 * Allocation failed! Busy wait while other cpu
224 * handles async PF.
225 */
226 spin_unlock(&b->lock);
227 cpu_relax();
228 goto again;
229 }
230 n->token = token;
231 n->cpu = smp_processor_id();
232 init_waitqueue_head(&n->wq);
233 hlist_add_head(&n->link, &b->list);
234 } else
235 apf_task_wake_one(n);
236 spin_unlock(&b->lock);
237 return;
238}
239EXPORT_SYMBOL_GPL(kvm_async_pf_task_wake);
240
241u32 kvm_read_and_reset_pf_reason(void)
242{
243 u32 reason = 0;
244
245 if (__get_cpu_var(apf_reason).enabled) {
246 reason = __get_cpu_var(apf_reason).reason;
247 __get_cpu_var(apf_reason).reason = 0;
248 }
249
250 return reason;
251}
252EXPORT_SYMBOL_GPL(kvm_read_and_reset_pf_reason);
253
254dotraplinkage void __kprobes
255do_async_page_fault(struct pt_regs *regs, unsigned long error_code)
256{
Frederic Weisbecker6c1e0252013-02-24 01:19:14 +0100257 enum ctx_state prev_state;
258
Gleb Natapov631bc482010-10-14 11:22:52 +0200259 switch (kvm_read_and_reset_pf_reason()) {
260 default:
261 do_page_fault(regs, error_code);
262 break;
263 case KVM_PV_REASON_PAGE_NOT_PRESENT:
264 /* page is swapped out by the host. */
Frederic Weisbecker6c1e0252013-02-24 01:19:14 +0100265 prev_state = exception_enter();
Sasha Levinc5e015d2012-10-19 12:11:55 -0400266 exit_idle();
Gleb Natapov631bc482010-10-14 11:22:52 +0200267 kvm_async_pf_task_wait((u32)read_cr2());
Frederic Weisbecker6c1e0252013-02-24 01:19:14 +0100268 exception_exit(prev_state);
Gleb Natapov631bc482010-10-14 11:22:52 +0200269 break;
270 case KVM_PV_REASON_PAGE_READY:
Gleb Natapove0875922012-04-04 15:30:33 +0300271 rcu_irq_enter();
272 exit_idle();
Gleb Natapov631bc482010-10-14 11:22:52 +0200273 kvm_async_pf_task_wake((u32)read_cr2());
Gleb Natapove0875922012-04-04 15:30:33 +0300274 rcu_irq_exit();
Gleb Natapov631bc482010-10-14 11:22:52 +0200275 break;
276 }
277}
278
Rakib Mullickd3ac8812009-07-02 11:40:36 +0600279static void __init paravirt_ops_setup(void)
Marcelo Tosatti0cf1bfd2008-02-22 12:21:36 -0500280{
281 pv_info.name = "KVM";
282 pv_info.paravirt_enabled = 1;
283
284 if (kvm_para_has_feature(KVM_FEATURE_NOP_IO_DELAY))
285 pv_cpu_ops.io_delay = kvm_io_delay;
286
Marcelo Tosattia90ede72009-02-11 22:45:42 -0200287#ifdef CONFIG_X86_IO_APIC
288 no_timer_check = 1;
289#endif
Marcelo Tosatti0cf1bfd2008-02-22 12:21:36 -0500290}
291
Glauber Costad910f5c2011-07-11 15:28:19 -0400292static void kvm_register_steal_time(void)
293{
294 int cpu = smp_processor_id();
295 struct kvm_steal_time *st = &per_cpu(steal_time, cpu);
296
297 if (!has_steal_clock)
298 return;
299
300 memset(st, 0, sizeof(*st));
301
Dave Hansen5dfd4862013-01-22 13:24:35 -0800302 wrmsrl(MSR_KVM_STEAL_TIME, (slow_virt_to_phys(st) | KVM_MSR_ENABLED));
Shuah Khan136867f2013-02-05 19:57:22 -0700303 pr_info("kvm-stealtime: cpu %d, msr %llx\n",
304 cpu, (unsigned long long) slow_virt_to_phys(st));
Glauber Costad910f5c2011-07-11 15:28:19 -0400305}
306
Michael S. Tsirkinab9cf492012-06-24 19:24:34 +0300307static DEFINE_PER_CPU(unsigned long, kvm_apic_eoi) = KVM_PV_EOI_DISABLED;
308
309static void kvm_guest_apic_eoi_write(u32 reg, u32 val)
310{
311 /**
312 * This relies on __test_and_clear_bit to modify the memory
313 * in a way that is atomic with respect to the local CPU.
314 * The hypervisor only accesses this memory from the local CPU so
315 * there's no need for lock or memory barriers.
316 * An optimization barrier is implied in apic write.
317 */
318 if (__test_and_clear_bit(KVM_PV_EOI_BIT, &__get_cpu_var(kvm_apic_eoi)))
319 return;
Michael S. Tsirkin90536662012-07-15 15:56:52 +0300320 apic_write(APIC_EOI, APIC_EOI_ACK);
Michael S. Tsirkinab9cf492012-06-24 19:24:34 +0300321}
322
Gleb Natapovfd10cde2010-10-14 11:22:51 +0200323void __cpuinit kvm_guest_cpu_init(void)
324{
325 if (!kvm_para_available())
326 return;
327
328 if (kvm_para_has_feature(KVM_FEATURE_ASYNC_PF) && kvmapf) {
Dave Hansen5dfd4862013-01-22 13:24:35 -0800329 u64 pa = slow_virt_to_phys(&__get_cpu_var(apf_reason));
Gleb Natapovfd10cde2010-10-14 11:22:51 +0200330
Gleb Natapov6adba522010-10-14 11:22:55 +0200331#ifdef CONFIG_PREEMPT
332 pa |= KVM_ASYNC_PF_SEND_ALWAYS;
333#endif
Gleb Natapovfd10cde2010-10-14 11:22:51 +0200334 wrmsrl(MSR_KVM_ASYNC_PF_EN, pa | KVM_ASYNC_PF_ENABLED);
335 __get_cpu_var(apf_reason).enabled = 1;
336 printk(KERN_INFO"KVM setup async PF for cpu %d\n",
337 smp_processor_id());
338 }
Glauber Costad910f5c2011-07-11 15:28:19 -0400339
Michael S. Tsirkinab9cf492012-06-24 19:24:34 +0300340 if (kvm_para_has_feature(KVM_FEATURE_PV_EOI)) {
341 unsigned long pa;
342 /* Size alignment is implied but just to make it explicit. */
343 BUILD_BUG_ON(__alignof__(kvm_apic_eoi) < 4);
344 __get_cpu_var(kvm_apic_eoi) = 0;
Dave Hansen5dfd4862013-01-22 13:24:35 -0800345 pa = slow_virt_to_phys(&__get_cpu_var(kvm_apic_eoi))
346 | KVM_MSR_ENABLED;
Michael S. Tsirkinab9cf492012-06-24 19:24:34 +0300347 wrmsrl(MSR_KVM_PV_EOI_EN, pa);
348 }
349
Glauber Costad910f5c2011-07-11 15:28:19 -0400350 if (has_steal_clock)
351 kvm_register_steal_time();
Gleb Natapovfd10cde2010-10-14 11:22:51 +0200352}
353
Michael S. Tsirkinab9cf492012-06-24 19:24:34 +0300354static void kvm_pv_disable_apf(void)
Gleb Natapovfd10cde2010-10-14 11:22:51 +0200355{
356 if (!__get_cpu_var(apf_reason).enabled)
357 return;
358
359 wrmsrl(MSR_KVM_ASYNC_PF_EN, 0);
360 __get_cpu_var(apf_reason).enabled = 0;
361
362 printk(KERN_INFO"Unregister pv shared memory for cpu %d\n",
363 smp_processor_id());
364}
365
Michael S. Tsirkinab9cf492012-06-24 19:24:34 +0300366static void kvm_pv_guest_cpu_reboot(void *unused)
367{
368 /*
369 * We disable PV EOI before we load a new kernel by kexec,
370 * since MSR_KVM_PV_EOI_EN stores a pointer into old kernel's memory.
371 * New kernel can re-enable when it boots.
372 */
373 if (kvm_para_has_feature(KVM_FEATURE_PV_EOI))
374 wrmsrl(MSR_KVM_PV_EOI_EN, 0);
375 kvm_pv_disable_apf();
Florian Westphal8fbe6a52012-08-15 16:00:40 +0200376 kvm_disable_steal_time();
Michael S. Tsirkinab9cf492012-06-24 19:24:34 +0300377}
378
Gleb Natapovfd10cde2010-10-14 11:22:51 +0200379static int kvm_pv_reboot_notify(struct notifier_block *nb,
380 unsigned long code, void *unused)
381{
382 if (code == SYS_RESTART)
Michael S. Tsirkinab9cf492012-06-24 19:24:34 +0300383 on_each_cpu(kvm_pv_guest_cpu_reboot, NULL, 1);
Gleb Natapovfd10cde2010-10-14 11:22:51 +0200384 return NOTIFY_DONE;
385}
386
387static struct notifier_block kvm_pv_reboot_nb = {
388 .notifier_call = kvm_pv_reboot_notify,
389};
390
Glauber Costad910f5c2011-07-11 15:28:19 -0400391static u64 kvm_steal_clock(int cpu)
392{
393 u64 steal;
394 struct kvm_steal_time *src;
395 int version;
396
397 src = &per_cpu(steal_time, cpu);
398 do {
399 version = src->version;
400 rmb();
401 steal = src->steal;
402 rmb();
403 } while ((version & 1) || (version != src->version));
404
405 return steal;
406}
407
408void kvm_disable_steal_time(void)
409{
410 if (!has_steal_clock)
411 return;
412
413 wrmsr(MSR_KVM_STEAL_TIME, 0, 0);
414}
415
Gleb Natapovca3f1012010-10-14 11:22:49 +0200416#ifdef CONFIG_SMP
417static void __init kvm_smp_prepare_boot_cpu(void)
418{
419 WARN_ON(kvm_register_clock("primary cpu clock"));
Gleb Natapovfd10cde2010-10-14 11:22:51 +0200420 kvm_guest_cpu_init();
Gleb Natapovca3f1012010-10-14 11:22:49 +0200421 native_smp_prepare_boot_cpu();
422}
Gleb Natapovfd10cde2010-10-14 11:22:51 +0200423
Sedat Dilek775077a2011-01-03 00:01:29 +0100424static void __cpuinit kvm_guest_cpu_online(void *dummy)
Gleb Natapovfd10cde2010-10-14 11:22:51 +0200425{
426 kvm_guest_cpu_init();
427}
428
429static void kvm_guest_cpu_offline(void *dummy)
430{
Glauber Costad910f5c2011-07-11 15:28:19 -0400431 kvm_disable_steal_time();
Michael S. Tsirkinab9cf492012-06-24 19:24:34 +0300432 if (kvm_para_has_feature(KVM_FEATURE_PV_EOI))
433 wrmsrl(MSR_KVM_PV_EOI_EN, 0);
434 kvm_pv_disable_apf();
Gleb Natapov631bc482010-10-14 11:22:52 +0200435 apf_task_wake_all();
Gleb Natapovfd10cde2010-10-14 11:22:51 +0200436}
437
438static int __cpuinit kvm_cpu_notify(struct notifier_block *self,
439 unsigned long action, void *hcpu)
440{
441 int cpu = (unsigned long)hcpu;
442 switch (action) {
443 case CPU_ONLINE:
444 case CPU_DOWN_FAILED:
445 case CPU_ONLINE_FROZEN:
446 smp_call_function_single(cpu, kvm_guest_cpu_online, NULL, 0);
447 break;
448 case CPU_DOWN_PREPARE:
449 case CPU_DOWN_PREPARE_FROZEN:
450 smp_call_function_single(cpu, kvm_guest_cpu_offline, NULL, 1);
451 break;
452 default:
453 break;
454 }
455 return NOTIFY_OK;
456}
457
458static struct notifier_block __cpuinitdata kvm_cpu_notifier = {
459 .notifier_call = kvm_cpu_notify,
460};
Gleb Natapovca3f1012010-10-14 11:22:49 +0200461#endif
462
Gleb Natapov631bc482010-10-14 11:22:52 +0200463static void __init kvm_apf_trap_init(void)
464{
465 set_intr_gate(14, &async_page_fault);
466}
467
Marcelo Tosatti0cf1bfd2008-02-22 12:21:36 -0500468void __init kvm_guest_init(void)
469{
Gleb Natapov631bc482010-10-14 11:22:52 +0200470 int i;
471
Marcelo Tosatti0cf1bfd2008-02-22 12:21:36 -0500472 if (!kvm_para_available())
473 return;
474
475 paravirt_ops_setup();
Gleb Natapovfd10cde2010-10-14 11:22:51 +0200476 register_reboot_notifier(&kvm_pv_reboot_nb);
Gleb Natapov631bc482010-10-14 11:22:52 +0200477 for (i = 0; i < KVM_TASK_SLEEP_HASHSIZE; i++)
478 spin_lock_init(&async_pf_sleepers[i].lock);
479 if (kvm_para_has_feature(KVM_FEATURE_ASYNC_PF))
480 x86_init.irqs.trap_init = kvm_apf_trap_init;
481
Glauber Costad910f5c2011-07-11 15:28:19 -0400482 if (kvm_para_has_feature(KVM_FEATURE_STEAL_TIME)) {
483 has_steal_clock = 1;
484 pv_time_ops.steal_clock = kvm_steal_clock;
485 }
486
Michael S. Tsirkin90536662012-07-15 15:56:52 +0300487 if (kvm_para_has_feature(KVM_FEATURE_PV_EOI))
488 apic_set_eoi_write(kvm_guest_apic_eoi_write);
Michael S. Tsirkinab9cf492012-06-24 19:24:34 +0300489
Marcelo Tosatti3dc4f7c2012-11-27 23:28:56 -0200490 if (kvmclock_vsyscall)
491 kvm_setup_vsyscall_timeinfo();
492
Gleb Natapovca3f1012010-10-14 11:22:49 +0200493#ifdef CONFIG_SMP
494 smp_ops.smp_prepare_boot_cpu = kvm_smp_prepare_boot_cpu;
Gleb Natapovfd10cde2010-10-14 11:22:51 +0200495 register_cpu_notifier(&kvm_cpu_notifier);
496#else
497 kvm_guest_cpu_init();
Gleb Natapovca3f1012010-10-14 11:22:49 +0200498#endif
Marcelo Tosatti0cf1bfd2008-02-22 12:21:36 -0500499}
Glauber Costad910f5c2011-07-11 15:28:19 -0400500
Prarit Bhargavafc733732012-07-06 13:47:39 -0400501static bool __init kvm_detect(void)
502{
503 if (!kvm_para_available())
504 return false;
505 return true;
506}
507
508const struct hypervisor_x86 x86_hyper_kvm __refconst = {
509 .name = "KVM",
510 .detect = kvm_detect,
Alok N Kataria4cca6ea2013-01-17 15:44:42 -0800511 .x2apic_available = kvm_para_available,
Prarit Bhargavafc733732012-07-06 13:47:39 -0400512};
513EXPORT_SYMBOL_GPL(x86_hyper_kvm);
514
Glauber Costad910f5c2011-07-11 15:28:19 -0400515static __init int activate_jump_labels(void)
516{
517 if (has_steal_clock) {
Ingo Molnarc5905af2012-02-24 08:31:31 +0100518 static_key_slow_inc(&paravirt_steal_enabled);
Glauber Costad910f5c2011-07-11 15:28:19 -0400519 if (steal_acc)
Ingo Molnarc5905af2012-02-24 08:31:31 +0100520 static_key_slow_inc(&paravirt_steal_rq_enabled);
Glauber Costad910f5c2011-07-11 15:28:19 -0400521 }
522
523 return 0;
524}
525arch_initcall(activate_jump_labels);