23 #include <linux/module.h>
24 #include <linux/kernel.h>
25 #include <linux/kvm_para.h>
31 #include <linux/reboot.h>
32 #include <linux/hash.h>
33 #include <linux/sched.h>
34 #include <linux/slab.h>
36 #include <asm/timer.h>
38 #include <asm/traps.h>
40 #include <asm/tlbflush.h>
44 #include <asm/hypervisor.h>
46 static int kvmapf = 1;
48 static int parse_no_kvmapf(
char *
arg)
56 static int steal_acc = 1;
57 static int parse_no_stealacc(
char *
arg)
67 static
int has_steal_clock = 0;
72 static
void kvm_io_delay(
void)
76 #define KVM_TASK_SLEEP_HASHBITS 8
77 #define KVM_TASK_SLEEP_HASHSIZE (1<<KVM_TASK_SLEEP_HASHBITS)
87 static struct kvm_task_sleep_head {
100 if (n->
token == token)
110 struct kvm_task_sleep_head *b = &async_pf_sleepers[
key];
120 e = _find_apf_task(b, token);
125 spin_unlock(&b->lock);
133 hlist_add_head(&n.
link, &b->list);
134 spin_unlock(&b->lock);
139 if (hlist_unhashed(&n.
link))
163 hlist_del_init(&n->
link);
166 else if (waitqueue_active(&n->
wq))
170 static void apf_task_wake_all(
void)
176 struct kvm_task_sleep_head *b = &async_pf_sleepers[
i];
182 apf_task_wake_one(n);
184 spin_unlock(&b->lock);
191 struct kvm_task_sleep_head *b = &async_pf_sleepers[
key];
201 n = _find_apf_task(b, token);
213 spin_unlock(&b->lock);
220 hlist_add_head(&n->
link, &b->list);
222 apf_task_wake_one(n);
223 spin_unlock(&b->lock);
264 static void __init paravirt_ops_setup(
void)
272 #ifdef CONFIG_X86_IO_APIC
277 static void kvm_register_steal_time(
void)
282 if (!has_steal_clock)
285 memset(st, 0,
sizeof(*st));
316 #ifdef CONFIG_PREEMPT
335 kvm_register_steal_time();
338 static void kvm_pv_disable_apf(
void)
350 static void kvm_pv_guest_cpu_reboot(
void *
unused)
359 kvm_pv_disable_apf();
364 unsigned long code,
void *unused)
372 .notifier_call = kvm_pv_reboot_notify,
375 static u64 kvm_steal_clock(
int cpu)
381 src = &
per_cpu(steal_time, cpu);
387 }
while ((version & 1) || (version != src->
version));
394 if (!has_steal_clock)
401 static void __init kvm_smp_prepare_boot_cpu(
void)
413 static void kvm_guest_cpu_offline(
void *
dummy)
418 kvm_pv_disable_apf();
423 unsigned long action,
void *hcpu)
425 int cpu = (
unsigned long)hcpu;
443 .notifier_call = kvm_cpu_notify,
447 static void __init kvm_apf_trap_init(
void)
459 paravirt_ops_setup();
464 x86_init.irqs.trap_init = kvm_apf_trap_init;
476 register_cpu_notifier(&kvm_cpu_notifier);
482 static bool __init kvm_detect(
void)
491 .detect = kvm_detect,
495 static __init int activate_jump_labels(
void)
497 if (has_steal_clock) {