]> git.proxmox.com Git - mirror_qemu.git/blame - accel/kvm/kvm-accel-ops.c
accel: Do not set CPUState::can_do_io in non-TCG accels
[mirror_qemu.git] / accel / kvm / kvm-accel-ops.c
CommitLineData
57038a92
CF
1/*
2 * QEMU KVM support
3 *
4 * Copyright IBM, Corp. 2008
5 * Red Hat, Inc. 2008
6 *
7 * Authors:
8 * Anthony Liguori <aliguori@us.ibm.com>
9 * Glauber Costa <gcosta@redhat.com>
10 *
11 * This work is licensed under the terms of the GNU GPL, version 2 or later.
12 * See the COPYING file in the top-level directory.
13 *
14 */
15
16#include "qemu/osdep.h"
17#include "qemu/error-report.h"
18#include "qemu/main-loop.h"
ae7467b1 19#include "sysemu/kvm.h"
57038a92
CF
20#include "sysemu/kvm_int.h"
21#include "sysemu/runstate.h"
22#include "sysemu/cpus.h"
23#include "qemu/guest-random.h"
d0a92b35 24#include "qapi/error.h"
57038a92 25
ae7467b1 26#include <linux/kvm.h>
57038a92
CF
27#include "kvm-cpus.h"
28
29static void *kvm_vcpu_thread_fn(void *arg)
30{
31 CPUState *cpu = arg;
32 int r;
33
34 rcu_register_thread();
35
195801d7 36 bql_lock();
57038a92
CF
37 qemu_thread_get_self(cpu->thread);
38 cpu->thread_id = qemu_get_thread_id();
57038a92
CF
39 current_cpu = cpu;
40
d0a92b35 41 r = kvm_init_vcpu(cpu, &error_fatal);
57038a92
CF
42 kvm_init_cpu_signals(cpu);
43
44 /* signal CPU creation */
45 cpu_thread_signal_created(cpu);
46 qemu_guest_random_seed_thread_part2(cpu->random_seed);
47
48 do {
49 if (cpu_can_run(cpu)) {
50 r = kvm_cpu_exec(cpu);
51 if (r == EXCP_DEBUG) {
52 cpu_handle_guest_debug(cpu);
53 }
54 }
55 qemu_wait_io_event(cpu);
56 } while (!cpu->unplug || cpu_can_run(cpu));
57
58 kvm_destroy_vcpu(cpu);
59 cpu_thread_signal_destroyed(cpu);
195801d7 60 bql_unlock();
57038a92
CF
61 rcu_unregister_thread();
62 return NULL;
63}
64
65static void kvm_start_vcpu_thread(CPUState *cpu)
66{
67 char thread_name[VCPU_THREAD_NAME_SIZE];
68
69 cpu->thread = g_malloc0(sizeof(QemuThread));
70 cpu->halt_cond = g_malloc0(sizeof(QemuCond));
71 qemu_cond_init(cpu->halt_cond);
72 snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/KVM",
73 cpu->cpu_index);
74 qemu_thread_create(cpu->thread, thread_name, kvm_vcpu_thread_fn,
75 cpu, QEMU_THREAD_JOINABLE);
76}
77
ad7d684d
PMD
78static bool kvm_vcpu_thread_is_idle(CPUState *cpu)
79{
80 return !kvm_halt_in_kernel();
81}
82
39196355
PMD
83static bool kvm_cpus_are_resettable(void)
84{
85 return !kvm_enabled() || kvm_cpu_check_are_resettable();
86}
87
412ae126
MY
88#ifdef KVM_CAP_SET_GUEST_DEBUG
89static int kvm_update_guest_debug_ops(CPUState *cpu)
90{
91 return kvm_update_guest_debug(cpu, 0);
92}
93#endif
94
b86f59c7
CF
95static void kvm_accel_ops_class_init(ObjectClass *oc, void *data)
96{
97 AccelOpsClass *ops = ACCEL_OPS_CLASS(oc);
98
99 ops->create_vcpu_thread = kvm_start_vcpu_thread;
ad7d684d 100 ops->cpu_thread_is_idle = kvm_vcpu_thread_is_idle;
39196355 101 ops->cpus_are_resettable = kvm_cpus_are_resettable;
b86f59c7
CF
102 ops->synchronize_post_reset = kvm_cpu_synchronize_post_reset;
103 ops->synchronize_post_init = kvm_cpu_synchronize_post_init;
104 ops->synchronize_state = kvm_cpu_synchronize_state;
105 ops->synchronize_pre_loadvm = kvm_cpu_synchronize_pre_loadvm;
ae7467b1
AB
106
107#ifdef KVM_CAP_SET_GUEST_DEBUG
412ae126 108 ops->update_guest_debug = kvm_update_guest_debug_ops;
a48e7d9e 109 ops->supports_guest_debug = kvm_supports_guest_debug;
ae7467b1
AB
110 ops->insert_breakpoint = kvm_insert_breakpoint;
111 ops->remove_breakpoint = kvm_remove_breakpoint;
112 ops->remove_all_breakpoints = kvm_remove_all_breakpoints;
113#endif
b86f59c7
CF
114}
115
116static const TypeInfo kvm_accel_ops_type = {
117 .name = ACCEL_OPS_NAME("kvm"),
57038a92 118
b86f59c7
CF
119 .parent = TYPE_ACCEL_OPS,
120 .class_init = kvm_accel_ops_class_init,
121 .abstract = true,
57038a92 122};
b86f59c7
CF
123
124static void kvm_accel_ops_register_types(void)
125{
126 type_register_static(&kvm_accel_ops_type);
127}
128type_init(kvm_accel_ops_register_types);