root / kvm-all.c @ 68f6dc7e
History | View | Annotate | Download (27.3 kB)
1 | 05330448 | aliguori | /*
|
---|---|---|---|
2 | 05330448 | aliguori | * QEMU KVM support
|
3 | 05330448 | aliguori | *
|
4 | 05330448 | aliguori | * Copyright IBM, Corp. 2008
|
5 | 5832d1f2 | aliguori | * Red Hat, Inc. 2008
|
6 | 05330448 | aliguori | *
|
7 | 05330448 | aliguori | * Authors:
|
8 | 05330448 | aliguori | * Anthony Liguori <aliguori@us.ibm.com>
|
9 | 5832d1f2 | aliguori | * Glauber Costa <gcosta@redhat.com>
|
10 | 05330448 | aliguori | *
|
11 | 05330448 | aliguori | * This work is licensed under the terms of the GNU GPL, version 2 or later.
|
12 | 05330448 | aliguori | * See the COPYING file in the top-level directory.
|
13 | 05330448 | aliguori | *
|
14 | 05330448 | aliguori | */
|
15 | 05330448 | aliguori | |
16 | 05330448 | aliguori | #include <sys/types.h> |
17 | 05330448 | aliguori | #include <sys/ioctl.h> |
18 | 05330448 | aliguori | #include <sys/mman.h> |
19 | 984b5181 | aliguori | #include <stdarg.h> |
20 | 05330448 | aliguori | |
21 | 05330448 | aliguori | #include <linux/kvm.h> |
22 | 05330448 | aliguori | |
23 | 05330448 | aliguori | #include "qemu-common.h" |
24 | 05330448 | aliguori | #include "sysemu.h" |
25 | d33a1810 | Jan Kiszka | #include "hw/hw.h" |
26 | e22a25c9 | aliguori | #include "gdbstub.h" |
27 | 05330448 | aliguori | #include "kvm.h" |
28 | 05330448 | aliguori | |
29 | f65ed4c1 | aliguori | /* KVM uses PAGE_SIZE in it's definition of COALESCED_MMIO_MAX */
|
30 | f65ed4c1 | aliguori | #define PAGE_SIZE TARGET_PAGE_SIZE
|
31 | f65ed4c1 | aliguori | |
32 | 05330448 | aliguori | //#define DEBUG_KVM
|
33 | 05330448 | aliguori | |
34 | 05330448 | aliguori | #ifdef DEBUG_KVM
|
35 | 05330448 | aliguori | #define dprintf(fmt, ...) \
|
36 | 05330448 | aliguori | do { fprintf(stderr, fmt, ## __VA_ARGS__); } while (0) |
37 | 05330448 | aliguori | #else
|
38 | 05330448 | aliguori | #define dprintf(fmt, ...) \
|
39 | 05330448 | aliguori | do { } while (0) |
40 | 05330448 | aliguori | #endif
|
41 | 05330448 | aliguori | |
42 | 34fc643f | aliguori | typedef struct KVMSlot |
43 | 34fc643f | aliguori | { |
44 | 34fc643f | aliguori | target_phys_addr_t start_addr; |
45 | 34fc643f | aliguori | ram_addr_t memory_size; |
46 | 34fc643f | aliguori | ram_addr_t phys_offset; |
47 | 34fc643f | aliguori | int slot;
|
48 | 34fc643f | aliguori | int flags;
|
49 | 34fc643f | aliguori | } KVMSlot; |
50 | 05330448 | aliguori | |
51 | 5832d1f2 | aliguori | typedef struct kvm_dirty_log KVMDirtyLog; |
52 | 5832d1f2 | aliguori | |
53 | 05330448 | aliguori | int kvm_allowed = 0; |
54 | 05330448 | aliguori | |
55 | 05330448 | aliguori | struct KVMState
|
56 | 05330448 | aliguori | { |
57 | 05330448 | aliguori | KVMSlot slots[32];
|
58 | 05330448 | aliguori | int fd;
|
59 | 05330448 | aliguori | int vmfd;
|
60 | 4c0960c0 | Avi Kivity | int regs_modified;
|
61 | f65ed4c1 | aliguori | int coalesced_mmio;
|
62 | e69917e2 | Jan Kiszka | int broken_set_mem_region;
|
63 | 4495d6a7 | Jan Kiszka | int migration_log;
|
64 | e22a25c9 | aliguori | #ifdef KVM_CAP_SET_GUEST_DEBUG
|
65 | e22a25c9 | aliguori | struct kvm_sw_breakpoint_head kvm_sw_breakpoints;
|
66 | e22a25c9 | aliguori | #endif
|
67 | 6f725c13 | Glauber Costa | int irqchip_in_kernel;
|
68 | 6f725c13 | Glauber Costa | int pit_in_kernel;
|
69 | 05330448 | aliguori | }; |
70 | 05330448 | aliguori | |
71 | 05330448 | aliguori | static KVMState *kvm_state;
|
72 | 05330448 | aliguori | |
73 | 05330448 | aliguori | static KVMSlot *kvm_alloc_slot(KVMState *s)
|
74 | 05330448 | aliguori | { |
75 | 05330448 | aliguori | int i;
|
76 | 05330448 | aliguori | |
77 | 05330448 | aliguori | for (i = 0; i < ARRAY_SIZE(s->slots); i++) { |
78 | 62d60e8c | aliguori | /* KVM private memory slots */
|
79 | 62d60e8c | aliguori | if (i >= 8 && i < 12) |
80 | 62d60e8c | aliguori | continue;
|
81 | 05330448 | aliguori | if (s->slots[i].memory_size == 0) |
82 | 05330448 | aliguori | return &s->slots[i];
|
83 | 05330448 | aliguori | } |
84 | 05330448 | aliguori | |
85 | d3f8d37f | aliguori | fprintf(stderr, "%s: no free slot available\n", __func__);
|
86 | d3f8d37f | aliguori | abort(); |
87 | d3f8d37f | aliguori | } |
88 | d3f8d37f | aliguori | |
89 | d3f8d37f | aliguori | static KVMSlot *kvm_lookup_matching_slot(KVMState *s,
|
90 | d3f8d37f | aliguori | target_phys_addr_t start_addr, |
91 | d3f8d37f | aliguori | target_phys_addr_t end_addr) |
92 | d3f8d37f | aliguori | { |
93 | d3f8d37f | aliguori | int i;
|
94 | d3f8d37f | aliguori | |
95 | d3f8d37f | aliguori | for (i = 0; i < ARRAY_SIZE(s->slots); i++) { |
96 | d3f8d37f | aliguori | KVMSlot *mem = &s->slots[i]; |
97 | d3f8d37f | aliguori | |
98 | d3f8d37f | aliguori | if (start_addr == mem->start_addr &&
|
99 | d3f8d37f | aliguori | end_addr == mem->start_addr + mem->memory_size) { |
100 | d3f8d37f | aliguori | return mem;
|
101 | d3f8d37f | aliguori | } |
102 | d3f8d37f | aliguori | } |
103 | d3f8d37f | aliguori | |
104 | 05330448 | aliguori | return NULL; |
105 | 05330448 | aliguori | } |
106 | 05330448 | aliguori | |
107 | 6152e2ae | aliguori | /*
|
108 | 6152e2ae | aliguori | * Find overlapping slot with lowest start address
|
109 | 6152e2ae | aliguori | */
|
110 | 6152e2ae | aliguori | static KVMSlot *kvm_lookup_overlapping_slot(KVMState *s,
|
111 | 6152e2ae | aliguori | target_phys_addr_t start_addr, |
112 | 6152e2ae | aliguori | target_phys_addr_t end_addr) |
113 | 05330448 | aliguori | { |
114 | 6152e2ae | aliguori | KVMSlot *found = NULL;
|
115 | 05330448 | aliguori | int i;
|
116 | 05330448 | aliguori | |
117 | 05330448 | aliguori | for (i = 0; i < ARRAY_SIZE(s->slots); i++) { |
118 | 05330448 | aliguori | KVMSlot *mem = &s->slots[i]; |
119 | 05330448 | aliguori | |
120 | 6152e2ae | aliguori | if (mem->memory_size == 0 || |
121 | 6152e2ae | aliguori | (found && found->start_addr < mem->start_addr)) { |
122 | 6152e2ae | aliguori | continue;
|
123 | 6152e2ae | aliguori | } |
124 | 6152e2ae | aliguori | |
125 | 6152e2ae | aliguori | if (end_addr > mem->start_addr &&
|
126 | 6152e2ae | aliguori | start_addr < mem->start_addr + mem->memory_size) { |
127 | 6152e2ae | aliguori | found = mem; |
128 | 6152e2ae | aliguori | } |
129 | 05330448 | aliguori | } |
130 | 05330448 | aliguori | |
131 | 6152e2ae | aliguori | return found;
|
132 | 05330448 | aliguori | } |
133 | 05330448 | aliguori | |
134 | 5832d1f2 | aliguori | static int kvm_set_user_memory_region(KVMState *s, KVMSlot *slot) |
135 | 5832d1f2 | aliguori | { |
136 | 5832d1f2 | aliguori | struct kvm_userspace_memory_region mem;
|
137 | 5832d1f2 | aliguori | |
138 | 5832d1f2 | aliguori | mem.slot = slot->slot; |
139 | 5832d1f2 | aliguori | mem.guest_phys_addr = slot->start_addr; |
140 | 5832d1f2 | aliguori | mem.memory_size = slot->memory_size; |
141 | 5579c7f3 | pbrook | mem.userspace_addr = (unsigned long)qemu_get_ram_ptr(slot->phys_offset); |
142 | 5832d1f2 | aliguori | mem.flags = slot->flags; |
143 | 4495d6a7 | Jan Kiszka | if (s->migration_log) {
|
144 | 4495d6a7 | Jan Kiszka | mem.flags |= KVM_MEM_LOG_DIRTY_PAGES; |
145 | 4495d6a7 | Jan Kiszka | } |
146 | 5832d1f2 | aliguori | return kvm_vm_ioctl(s, KVM_SET_USER_MEMORY_REGION, &mem);
|
147 | 5832d1f2 | aliguori | } |
148 | 5832d1f2 | aliguori | |
149 | 8d2ba1fb | Jan Kiszka | static void kvm_reset_vcpu(void *opaque) |
150 | 8d2ba1fb | Jan Kiszka | { |
151 | 8d2ba1fb | Jan Kiszka | CPUState *env = opaque; |
152 | 8d2ba1fb | Jan Kiszka | |
153 | 8d2ba1fb | Jan Kiszka | if (kvm_arch_put_registers(env)) {
|
154 | 8d2ba1fb | Jan Kiszka | fprintf(stderr, "Fatal: kvm vcpu reset failed\n");
|
155 | 8d2ba1fb | Jan Kiszka | abort(); |
156 | 8d2ba1fb | Jan Kiszka | } |
157 | 8d2ba1fb | Jan Kiszka | } |
158 | 5832d1f2 | aliguori | |
159 | 6f725c13 | Glauber Costa | int kvm_irqchip_in_kernel(void) |
160 | 6f725c13 | Glauber Costa | { |
161 | 6f725c13 | Glauber Costa | return kvm_state->irqchip_in_kernel;
|
162 | 6f725c13 | Glauber Costa | } |
163 | 6f725c13 | Glauber Costa | |
164 | 6f725c13 | Glauber Costa | int kvm_pit_in_kernel(void) |
165 | 6f725c13 | Glauber Costa | { |
166 | 6f725c13 | Glauber Costa | return kvm_state->pit_in_kernel;
|
167 | 6f725c13 | Glauber Costa | } |
168 | 6f725c13 | Glauber Costa | |
169 | 6f725c13 | Glauber Costa | |
170 | 05330448 | aliguori | int kvm_init_vcpu(CPUState *env)
|
171 | 05330448 | aliguori | { |
172 | 05330448 | aliguori | KVMState *s = kvm_state; |
173 | 05330448 | aliguori | long mmap_size;
|
174 | 05330448 | aliguori | int ret;
|
175 | 05330448 | aliguori | |
176 | 05330448 | aliguori | dprintf("kvm_init_vcpu\n");
|
177 | 05330448 | aliguori | |
178 | 984b5181 | aliguori | ret = kvm_vm_ioctl(s, KVM_CREATE_VCPU, env->cpu_index); |
179 | 05330448 | aliguori | if (ret < 0) { |
180 | 05330448 | aliguori | dprintf("kvm_create_vcpu failed\n");
|
181 | 05330448 | aliguori | goto err;
|
182 | 05330448 | aliguori | } |
183 | 05330448 | aliguori | |
184 | 05330448 | aliguori | env->kvm_fd = ret; |
185 | 05330448 | aliguori | env->kvm_state = s; |
186 | 05330448 | aliguori | |
187 | 05330448 | aliguori | mmap_size = kvm_ioctl(s, KVM_GET_VCPU_MMAP_SIZE, 0);
|
188 | 05330448 | aliguori | if (mmap_size < 0) { |
189 | 05330448 | aliguori | dprintf("KVM_GET_VCPU_MMAP_SIZE failed\n");
|
190 | 05330448 | aliguori | goto err;
|
191 | 05330448 | aliguori | } |
192 | 05330448 | aliguori | |
193 | 05330448 | aliguori | env->kvm_run = mmap(NULL, mmap_size, PROT_READ | PROT_WRITE, MAP_SHARED,
|
194 | 05330448 | aliguori | env->kvm_fd, 0);
|
195 | 05330448 | aliguori | if (env->kvm_run == MAP_FAILED) {
|
196 | 05330448 | aliguori | ret = -errno; |
197 | 05330448 | aliguori | dprintf("mmap'ing vcpu state failed\n");
|
198 | 05330448 | aliguori | goto err;
|
199 | 05330448 | aliguori | } |
200 | 05330448 | aliguori | |
201 | 05330448 | aliguori | ret = kvm_arch_init_vcpu(env); |
202 | 8d2ba1fb | Jan Kiszka | if (ret == 0) { |
203 | a08d4367 | Jan Kiszka | qemu_register_reset(kvm_reset_vcpu, env); |
204 | 8d2ba1fb | Jan Kiszka | ret = kvm_arch_put_registers(env); |
205 | 8d2ba1fb | Jan Kiszka | } |
206 | 05330448 | aliguori | err:
|
207 | 05330448 | aliguori | return ret;
|
208 | 05330448 | aliguori | } |
209 | 05330448 | aliguori | |
210 | f8d926e9 | Jan Kiszka | int kvm_put_mp_state(CPUState *env)
|
211 | f8d926e9 | Jan Kiszka | { |
212 | f8d926e9 | Jan Kiszka | struct kvm_mp_state mp_state = { .mp_state = env->mp_state };
|
213 | f8d926e9 | Jan Kiszka | |
214 | f8d926e9 | Jan Kiszka | return kvm_vcpu_ioctl(env, KVM_SET_MP_STATE, &mp_state);
|
215 | f8d926e9 | Jan Kiszka | } |
216 | f8d926e9 | Jan Kiszka | |
217 | f8d926e9 | Jan Kiszka | int kvm_get_mp_state(CPUState *env)
|
218 | f8d926e9 | Jan Kiszka | { |
219 | f8d926e9 | Jan Kiszka | struct kvm_mp_state mp_state;
|
220 | f8d926e9 | Jan Kiszka | int ret;
|
221 | f8d926e9 | Jan Kiszka | |
222 | f8d926e9 | Jan Kiszka | ret = kvm_vcpu_ioctl(env, KVM_GET_MP_STATE, &mp_state); |
223 | f8d926e9 | Jan Kiszka | if (ret < 0) { |
224 | f8d926e9 | Jan Kiszka | return ret;
|
225 | f8d926e9 | Jan Kiszka | } |
226 | f8d926e9 | Jan Kiszka | env->mp_state = mp_state.mp_state; |
227 | f8d926e9 | Jan Kiszka | return 0; |
228 | f8d926e9 | Jan Kiszka | } |
229 | f8d926e9 | Jan Kiszka | |
230 | 5832d1f2 | aliguori | /*
|
231 | 5832d1f2 | aliguori | * dirty pages logging control
|
232 | 5832d1f2 | aliguori | */
|
233 | d3f8d37f | aliguori | static int kvm_dirty_pages_log_change(target_phys_addr_t phys_addr, |
234 | 4495d6a7 | Jan Kiszka | ram_addr_t size, int flags, int mask) |
235 | 5832d1f2 | aliguori | { |
236 | 5832d1f2 | aliguori | KVMState *s = kvm_state; |
237 | d3f8d37f | aliguori | KVMSlot *mem = kvm_lookup_matching_slot(s, phys_addr, phys_addr + size); |
238 | 4495d6a7 | Jan Kiszka | int old_flags;
|
239 | 4495d6a7 | Jan Kiszka | |
240 | 5832d1f2 | aliguori | if (mem == NULL) { |
241 | d3f8d37f | aliguori | fprintf(stderr, "BUG: %s: invalid parameters " TARGET_FMT_plx "-" |
242 | d3f8d37f | aliguori | TARGET_FMT_plx "\n", __func__, phys_addr,
|
243 | b80a55e6 | Alexander Graf | (target_phys_addr_t)(phys_addr + size - 1));
|
244 | 5832d1f2 | aliguori | return -EINVAL;
|
245 | 5832d1f2 | aliguori | } |
246 | 5832d1f2 | aliguori | |
247 | 4495d6a7 | Jan Kiszka | old_flags = mem->flags; |
248 | 5832d1f2 | aliguori | |
249 | 4495d6a7 | Jan Kiszka | flags = (mem->flags & ~mask) | flags; |
250 | 5832d1f2 | aliguori | mem->flags = flags; |
251 | 5832d1f2 | aliguori | |
252 | 4495d6a7 | Jan Kiszka | /* If nothing changed effectively, no need to issue ioctl */
|
253 | 4495d6a7 | Jan Kiszka | if (s->migration_log) {
|
254 | 4495d6a7 | Jan Kiszka | flags |= KVM_MEM_LOG_DIRTY_PAGES; |
255 | 4495d6a7 | Jan Kiszka | } |
256 | 4495d6a7 | Jan Kiszka | if (flags == old_flags) {
|
257 | 4495d6a7 | Jan Kiszka | return 0; |
258 | 4495d6a7 | Jan Kiszka | } |
259 | 4495d6a7 | Jan Kiszka | |
260 | 5832d1f2 | aliguori | return kvm_set_user_memory_region(s, mem);
|
261 | 5832d1f2 | aliguori | } |
262 | 5832d1f2 | aliguori | |
263 | d3f8d37f | aliguori | int kvm_log_start(target_phys_addr_t phys_addr, ram_addr_t size)
|
264 | 5832d1f2 | aliguori | { |
265 | d3f8d37f | aliguori | return kvm_dirty_pages_log_change(phys_addr, size,
|
266 | 5832d1f2 | aliguori | KVM_MEM_LOG_DIRTY_PAGES, |
267 | 5832d1f2 | aliguori | KVM_MEM_LOG_DIRTY_PAGES); |
268 | 5832d1f2 | aliguori | } |
269 | 5832d1f2 | aliguori | |
270 | d3f8d37f | aliguori | int kvm_log_stop(target_phys_addr_t phys_addr, ram_addr_t size)
|
271 | 5832d1f2 | aliguori | { |
272 | d3f8d37f | aliguori | return kvm_dirty_pages_log_change(phys_addr, size,
|
273 | 5832d1f2 | aliguori | 0,
|
274 | 5832d1f2 | aliguori | KVM_MEM_LOG_DIRTY_PAGES); |
275 | 5832d1f2 | aliguori | } |
276 | 5832d1f2 | aliguori | |
277 | 4495d6a7 | Jan Kiszka | int kvm_set_migration_log(int enable) |
278 | 4495d6a7 | Jan Kiszka | { |
279 | 4495d6a7 | Jan Kiszka | KVMState *s = kvm_state; |
280 | 4495d6a7 | Jan Kiszka | KVMSlot *mem; |
281 | 4495d6a7 | Jan Kiszka | int i, err;
|
282 | 4495d6a7 | Jan Kiszka | |
283 | 4495d6a7 | Jan Kiszka | s->migration_log = enable; |
284 | 4495d6a7 | Jan Kiszka | |
285 | 4495d6a7 | Jan Kiszka | for (i = 0; i < ARRAY_SIZE(s->slots); i++) { |
286 | 4495d6a7 | Jan Kiszka | mem = &s->slots[i]; |
287 | 4495d6a7 | Jan Kiszka | |
288 | 4495d6a7 | Jan Kiszka | if (!!(mem->flags & KVM_MEM_LOG_DIRTY_PAGES) == enable) {
|
289 | 4495d6a7 | Jan Kiszka | continue;
|
290 | 4495d6a7 | Jan Kiszka | } |
291 | 4495d6a7 | Jan Kiszka | err = kvm_set_user_memory_region(s, mem); |
292 | 4495d6a7 | Jan Kiszka | if (err) {
|
293 | 4495d6a7 | Jan Kiszka | return err;
|
294 | 4495d6a7 | Jan Kiszka | } |
295 | 4495d6a7 | Jan Kiszka | } |
296 | 4495d6a7 | Jan Kiszka | return 0; |
297 | 4495d6a7 | Jan Kiszka | } |
298 | 4495d6a7 | Jan Kiszka | |
299 | 96c1606b | Alexander Graf | static int test_le_bit(unsigned long nr, unsigned char *addr) |
300 | 96c1606b | Alexander Graf | { |
301 | 96c1606b | Alexander Graf | return (addr[nr >> 3] >> (nr & 7)) & 1; |
302 | 96c1606b | Alexander Graf | } |
303 | 96c1606b | Alexander Graf | |
304 | 5832d1f2 | aliguori | /**
|
305 | 5832d1f2 | aliguori | * kvm_physical_sync_dirty_bitmap - Grab dirty bitmap from kernel space
|
306 | 5832d1f2 | aliguori | * This function updates qemu's dirty bitmap using cpu_physical_memory_set_dirty().
|
307 | 5832d1f2 | aliguori | * This means all bits are set to dirty.
|
308 | 5832d1f2 | aliguori | *
|
309 | d3f8d37f | aliguori | * @start_add: start of logged region.
|
310 | 5832d1f2 | aliguori | * @end_addr: end of logged region.
|
311 | 5832d1f2 | aliguori | */
|
312 | 151f7749 | Jan Kiszka | int kvm_physical_sync_dirty_bitmap(target_phys_addr_t start_addr,
|
313 | 151f7749 | Jan Kiszka | target_phys_addr_t end_addr) |
314 | 5832d1f2 | aliguori | { |
315 | 5832d1f2 | aliguori | KVMState *s = kvm_state; |
316 | 151f7749 | Jan Kiszka | unsigned long size, allocated_size = 0; |
317 | 151f7749 | Jan Kiszka | target_phys_addr_t phys_addr; |
318 | 5832d1f2 | aliguori | ram_addr_t addr; |
319 | 151f7749 | Jan Kiszka | KVMDirtyLog d; |
320 | 151f7749 | Jan Kiszka | KVMSlot *mem; |
321 | 151f7749 | Jan Kiszka | int ret = 0; |
322 | 5832d1f2 | aliguori | |
323 | 151f7749 | Jan Kiszka | d.dirty_bitmap = NULL;
|
324 | 151f7749 | Jan Kiszka | while (start_addr < end_addr) {
|
325 | 151f7749 | Jan Kiszka | mem = kvm_lookup_overlapping_slot(s, start_addr, end_addr); |
326 | 151f7749 | Jan Kiszka | if (mem == NULL) { |
327 | 151f7749 | Jan Kiszka | break;
|
328 | 151f7749 | Jan Kiszka | } |
329 | 5832d1f2 | aliguori | |
330 | 151f7749 | Jan Kiszka | size = ((mem->memory_size >> TARGET_PAGE_BITS) + 7) / 8; |
331 | 151f7749 | Jan Kiszka | if (!d.dirty_bitmap) {
|
332 | 151f7749 | Jan Kiszka | d.dirty_bitmap = qemu_malloc(size); |
333 | 151f7749 | Jan Kiszka | } else if (size > allocated_size) { |
334 | 151f7749 | Jan Kiszka | d.dirty_bitmap = qemu_realloc(d.dirty_bitmap, size); |
335 | 151f7749 | Jan Kiszka | } |
336 | 151f7749 | Jan Kiszka | allocated_size = size; |
337 | 151f7749 | Jan Kiszka | memset(d.dirty_bitmap, 0, allocated_size);
|
338 | 5832d1f2 | aliguori | |
339 | 151f7749 | Jan Kiszka | d.slot = mem->slot; |
340 | 5832d1f2 | aliguori | |
341 | 6e489f3f | Anthony Liguori | if (kvm_vm_ioctl(s, KVM_GET_DIRTY_LOG, &d) == -1) { |
342 | 151f7749 | Jan Kiszka | dprintf("ioctl failed %d\n", errno);
|
343 | 151f7749 | Jan Kiszka | ret = -1;
|
344 | 151f7749 | Jan Kiszka | break;
|
345 | 151f7749 | Jan Kiszka | } |
346 | 5832d1f2 | aliguori | |
347 | 151f7749 | Jan Kiszka | for (phys_addr = mem->start_addr, addr = mem->phys_offset;
|
348 | 151f7749 | Jan Kiszka | phys_addr < mem->start_addr + mem->memory_size; |
349 | 151f7749 | Jan Kiszka | phys_addr += TARGET_PAGE_SIZE, addr += TARGET_PAGE_SIZE) { |
350 | 96c1606b | Alexander Graf | unsigned char *bitmap = (unsigned char *)d.dirty_bitmap; |
351 | 151f7749 | Jan Kiszka | unsigned nr = (phys_addr - mem->start_addr) >> TARGET_PAGE_BITS;
|
352 | 151f7749 | Jan Kiszka | |
353 | 96c1606b | Alexander Graf | if (test_le_bit(nr, bitmap)) {
|
354 | 151f7749 | Jan Kiszka | cpu_physical_memory_set_dirty(addr); |
355 | 151f7749 | Jan Kiszka | } |
356 | 151f7749 | Jan Kiszka | } |
357 | 151f7749 | Jan Kiszka | start_addr = phys_addr; |
358 | 5832d1f2 | aliguori | } |
359 | 5832d1f2 | aliguori | qemu_free(d.dirty_bitmap); |
360 | 151f7749 | Jan Kiszka | |
361 | 151f7749 | Jan Kiszka | return ret;
|
362 | 5832d1f2 | aliguori | } |
363 | 5832d1f2 | aliguori | |
364 | f65ed4c1 | aliguori | int kvm_coalesce_mmio_region(target_phys_addr_t start, ram_addr_t size)
|
365 | f65ed4c1 | aliguori | { |
366 | f65ed4c1 | aliguori | int ret = -ENOSYS;
|
367 | f65ed4c1 | aliguori | #ifdef KVM_CAP_COALESCED_MMIO
|
368 | f65ed4c1 | aliguori | KVMState *s = kvm_state; |
369 | f65ed4c1 | aliguori | |
370 | f65ed4c1 | aliguori | if (s->coalesced_mmio) {
|
371 | f65ed4c1 | aliguori | struct kvm_coalesced_mmio_zone zone;
|
372 | f65ed4c1 | aliguori | |
373 | f65ed4c1 | aliguori | zone.addr = start; |
374 | f65ed4c1 | aliguori | zone.size = size; |
375 | f65ed4c1 | aliguori | |
376 | f65ed4c1 | aliguori | ret = kvm_vm_ioctl(s, KVM_REGISTER_COALESCED_MMIO, &zone); |
377 | f65ed4c1 | aliguori | } |
378 | f65ed4c1 | aliguori | #endif
|
379 | f65ed4c1 | aliguori | |
380 | f65ed4c1 | aliguori | return ret;
|
381 | f65ed4c1 | aliguori | } |
382 | f65ed4c1 | aliguori | |
383 | f65ed4c1 | aliguori | int kvm_uncoalesce_mmio_region(target_phys_addr_t start, ram_addr_t size)
|
384 | f65ed4c1 | aliguori | { |
385 | f65ed4c1 | aliguori | int ret = -ENOSYS;
|
386 | f65ed4c1 | aliguori | #ifdef KVM_CAP_COALESCED_MMIO
|
387 | f65ed4c1 | aliguori | KVMState *s = kvm_state; |
388 | f65ed4c1 | aliguori | |
389 | f65ed4c1 | aliguori | if (s->coalesced_mmio) {
|
390 | f65ed4c1 | aliguori | struct kvm_coalesced_mmio_zone zone;
|
391 | f65ed4c1 | aliguori | |
392 | f65ed4c1 | aliguori | zone.addr = start; |
393 | f65ed4c1 | aliguori | zone.size = size; |
394 | f65ed4c1 | aliguori | |
395 | f65ed4c1 | aliguori | ret = kvm_vm_ioctl(s, KVM_UNREGISTER_COALESCED_MMIO, &zone); |
396 | f65ed4c1 | aliguori | } |
397 | f65ed4c1 | aliguori | #endif
|
398 | f65ed4c1 | aliguori | |
399 | f65ed4c1 | aliguori | return ret;
|
400 | f65ed4c1 | aliguori | } |
401 | f65ed4c1 | aliguori | |
402 | ad7b8b33 | Anthony Liguori | int kvm_check_extension(KVMState *s, unsigned int extension) |
403 | ad7b8b33 | Anthony Liguori | { |
404 | ad7b8b33 | Anthony Liguori | int ret;
|
405 | ad7b8b33 | Anthony Liguori | |
406 | ad7b8b33 | Anthony Liguori | ret = kvm_ioctl(s, KVM_CHECK_EXTENSION, extension); |
407 | ad7b8b33 | Anthony Liguori | if (ret < 0) { |
408 | ad7b8b33 | Anthony Liguori | ret = 0;
|
409 | ad7b8b33 | Anthony Liguori | } |
410 | ad7b8b33 | Anthony Liguori | |
411 | ad7b8b33 | Anthony Liguori | return ret;
|
412 | ad7b8b33 | Anthony Liguori | } |
413 | ad7b8b33 | Anthony Liguori | |
414 | 05330448 | aliguori | int kvm_init(int smp_cpus) |
415 | 05330448 | aliguori | { |
416 | 168ccc11 | Jan Kiszka | static const char upgrade_note[] = |
417 | 168ccc11 | Jan Kiszka | "Please upgrade to at least kernel 2.6.29 or recent kvm-kmod\n"
|
418 | 168ccc11 | Jan Kiszka | "(see http://sourceforge.net/projects/kvm).\n";
|
419 | 05330448 | aliguori | KVMState *s; |
420 | 05330448 | aliguori | int ret;
|
421 | 05330448 | aliguori | int i;
|
422 | 05330448 | aliguori | |
423 | 9f8fd694 | Mark McLoughlin | if (smp_cpus > 1) { |
424 | 9f8fd694 | Mark McLoughlin | fprintf(stderr, "No SMP KVM support, use '-smp 1'\n");
|
425 | 05330448 | aliguori | return -EINVAL;
|
426 | 9f8fd694 | Mark McLoughlin | } |
427 | 05330448 | aliguori | |
428 | 05330448 | aliguori | s = qemu_mallocz(sizeof(KVMState));
|
429 | 05330448 | aliguori | |
430 | e22a25c9 | aliguori | #ifdef KVM_CAP_SET_GUEST_DEBUG
|
431 | 72cf2d4f | Blue Swirl | QTAILQ_INIT(&s->kvm_sw_breakpoints); |
432 | e22a25c9 | aliguori | #endif
|
433 | 05330448 | aliguori | for (i = 0; i < ARRAY_SIZE(s->slots); i++) |
434 | 05330448 | aliguori | s->slots[i].slot = i; |
435 | 05330448 | aliguori | |
436 | 05330448 | aliguori | s->vmfd = -1;
|
437 | 05330448 | aliguori | s->fd = open("/dev/kvm", O_RDWR);
|
438 | 05330448 | aliguori | if (s->fd == -1) { |
439 | 05330448 | aliguori | fprintf(stderr, "Could not access KVM kernel module: %m\n");
|
440 | 05330448 | aliguori | ret = -errno; |
441 | 05330448 | aliguori | goto err;
|
442 | 05330448 | aliguori | } |
443 | 05330448 | aliguori | |
444 | 05330448 | aliguori | ret = kvm_ioctl(s, KVM_GET_API_VERSION, 0);
|
445 | 05330448 | aliguori | if (ret < KVM_API_VERSION) {
|
446 | 05330448 | aliguori | if (ret > 0) |
447 | 05330448 | aliguori | ret = -EINVAL; |
448 | 05330448 | aliguori | fprintf(stderr, "kvm version too old\n");
|
449 | 05330448 | aliguori | goto err;
|
450 | 05330448 | aliguori | } |
451 | 05330448 | aliguori | |
452 | 05330448 | aliguori | if (ret > KVM_API_VERSION) {
|
453 | 05330448 | aliguori | ret = -EINVAL; |
454 | 05330448 | aliguori | fprintf(stderr, "kvm version not supported\n");
|
455 | 05330448 | aliguori | goto err;
|
456 | 05330448 | aliguori | } |
457 | 05330448 | aliguori | |
458 | 05330448 | aliguori | s->vmfd = kvm_ioctl(s, KVM_CREATE_VM, 0);
|
459 | 05330448 | aliguori | if (s->vmfd < 0) |
460 | 05330448 | aliguori | goto err;
|
461 | 05330448 | aliguori | |
462 | 05330448 | aliguori | /* initially, KVM allocated its own memory and we had to jump through
|
463 | 05330448 | aliguori | * hooks to make phys_ram_base point to this. Modern versions of KVM
|
464 | 5579c7f3 | pbrook | * just use a user allocated buffer so we can use regular pages
|
465 | 05330448 | aliguori | * unmodified. Make sure we have a sufficiently modern version of KVM.
|
466 | 05330448 | aliguori | */
|
467 | ad7b8b33 | Anthony Liguori | if (!kvm_check_extension(s, KVM_CAP_USER_MEMORY)) {
|
468 | ad7b8b33 | Anthony Liguori | ret = -EINVAL; |
469 | 168ccc11 | Jan Kiszka | fprintf(stderr, "kvm does not support KVM_CAP_USER_MEMORY\n%s",
|
470 | 168ccc11 | Jan Kiszka | upgrade_note); |
471 | 05330448 | aliguori | goto err;
|
472 | 05330448 | aliguori | } |
473 | 05330448 | aliguori | |
474 | d85dc283 | aliguori | /* There was a nasty bug in < kvm-80 that prevents memory slots from being
|
475 | d85dc283 | aliguori | * destroyed properly. Since we rely on this capability, refuse to work
|
476 | d85dc283 | aliguori | * with any kernel without this capability. */
|
477 | ad7b8b33 | Anthony Liguori | if (!kvm_check_extension(s, KVM_CAP_DESTROY_MEMORY_REGION_WORKS)) {
|
478 | ad7b8b33 | Anthony Liguori | ret = -EINVAL; |
479 | d85dc283 | aliguori | |
480 | d85dc283 | aliguori | fprintf(stderr, |
481 | 168ccc11 | Jan Kiszka | "KVM kernel module broken (DESTROY_MEMORY_REGION).\n%s",
|
482 | 168ccc11 | Jan Kiszka | upgrade_note); |
483 | d85dc283 | aliguori | goto err;
|
484 | d85dc283 | aliguori | } |
485 | d85dc283 | aliguori | |
486 | f65ed4c1 | aliguori | #ifdef KVM_CAP_COALESCED_MMIO
|
487 | ad7b8b33 | Anthony Liguori | s->coalesced_mmio = kvm_check_extension(s, KVM_CAP_COALESCED_MMIO); |
488 | ad7b8b33 | Anthony Liguori | #else
|
489 | ad7b8b33 | Anthony Liguori | s->coalesced_mmio = 0;
|
490 | f65ed4c1 | aliguori | #endif
|
491 | f65ed4c1 | aliguori | |
492 | e69917e2 | Jan Kiszka | s->broken_set_mem_region = 1;
|
493 | e69917e2 | Jan Kiszka | #ifdef KVM_CAP_JOIN_MEMORY_REGIONS_WORKS
|
494 | e69917e2 | Jan Kiszka | ret = kvm_ioctl(s, KVM_CHECK_EXTENSION, KVM_CAP_JOIN_MEMORY_REGIONS_WORKS); |
495 | e69917e2 | Jan Kiszka | if (ret > 0) { |
496 | e69917e2 | Jan Kiszka | s->broken_set_mem_region = 0;
|
497 | e69917e2 | Jan Kiszka | } |
498 | e69917e2 | Jan Kiszka | #endif
|
499 | e69917e2 | Jan Kiszka | |
500 | 05330448 | aliguori | ret = kvm_arch_init(s, smp_cpus); |
501 | 05330448 | aliguori | if (ret < 0) |
502 | 05330448 | aliguori | goto err;
|
503 | 05330448 | aliguori | |
504 | 05330448 | aliguori | kvm_state = s; |
505 | 05330448 | aliguori | |
506 | 05330448 | aliguori | return 0; |
507 | 05330448 | aliguori | |
508 | 05330448 | aliguori | err:
|
509 | 05330448 | aliguori | if (s) {
|
510 | 05330448 | aliguori | if (s->vmfd != -1) |
511 | 05330448 | aliguori | close(s->vmfd); |
512 | 05330448 | aliguori | if (s->fd != -1) |
513 | 05330448 | aliguori | close(s->fd); |
514 | 05330448 | aliguori | } |
515 | 05330448 | aliguori | qemu_free(s); |
516 | 05330448 | aliguori | |
517 | 05330448 | aliguori | return ret;
|
518 | 05330448 | aliguori | } |
519 | 05330448 | aliguori | |
520 | 05330448 | aliguori | static int kvm_handle_io(CPUState *env, uint16_t port, void *data, |
521 | 05330448 | aliguori | int direction, int size, uint32_t count) |
522 | 05330448 | aliguori | { |
523 | 05330448 | aliguori | int i;
|
524 | 05330448 | aliguori | uint8_t *ptr = data; |
525 | 05330448 | aliguori | |
526 | 05330448 | aliguori | for (i = 0; i < count; i++) { |
527 | 05330448 | aliguori | if (direction == KVM_EXIT_IO_IN) {
|
528 | 05330448 | aliguori | switch (size) {
|
529 | 05330448 | aliguori | case 1: |
530 | 05330448 | aliguori | stb_p(ptr, cpu_inb(env, port)); |
531 | 05330448 | aliguori | break;
|
532 | 05330448 | aliguori | case 2: |
533 | 05330448 | aliguori | stw_p(ptr, cpu_inw(env, port)); |
534 | 05330448 | aliguori | break;
|
535 | 05330448 | aliguori | case 4: |
536 | 05330448 | aliguori | stl_p(ptr, cpu_inl(env, port)); |
537 | 05330448 | aliguori | break;
|
538 | 05330448 | aliguori | } |
539 | 05330448 | aliguori | } else {
|
540 | 05330448 | aliguori | switch (size) {
|
541 | 05330448 | aliguori | case 1: |
542 | 05330448 | aliguori | cpu_outb(env, port, ldub_p(ptr)); |
543 | 05330448 | aliguori | break;
|
544 | 05330448 | aliguori | case 2: |
545 | 05330448 | aliguori | cpu_outw(env, port, lduw_p(ptr)); |
546 | 05330448 | aliguori | break;
|
547 | 05330448 | aliguori | case 4: |
548 | 05330448 | aliguori | cpu_outl(env, port, ldl_p(ptr)); |
549 | 05330448 | aliguori | break;
|
550 | 05330448 | aliguori | } |
551 | 05330448 | aliguori | } |
552 | 05330448 | aliguori | |
553 | 05330448 | aliguori | ptr += size; |
554 | 05330448 | aliguori | } |
555 | 05330448 | aliguori | |
556 | 05330448 | aliguori | return 1; |
557 | 05330448 | aliguori | } |
558 | 05330448 | aliguori | |
559 | f65ed4c1 | aliguori | static void kvm_run_coalesced_mmio(CPUState *env, struct kvm_run *run) |
560 | f65ed4c1 | aliguori | { |
561 | f65ed4c1 | aliguori | #ifdef KVM_CAP_COALESCED_MMIO
|
562 | f65ed4c1 | aliguori | KVMState *s = kvm_state; |
563 | f65ed4c1 | aliguori | if (s->coalesced_mmio) {
|
564 | f65ed4c1 | aliguori | struct kvm_coalesced_mmio_ring *ring;
|
565 | f65ed4c1 | aliguori | |
566 | f65ed4c1 | aliguori | ring = (void *)run + (s->coalesced_mmio * TARGET_PAGE_SIZE);
|
567 | f65ed4c1 | aliguori | while (ring->first != ring->last) {
|
568 | f65ed4c1 | aliguori | struct kvm_coalesced_mmio *ent;
|
569 | f65ed4c1 | aliguori | |
570 | f65ed4c1 | aliguori | ent = &ring->coalesced_mmio[ring->first]; |
571 | f65ed4c1 | aliguori | |
572 | f65ed4c1 | aliguori | cpu_physical_memory_write(ent->phys_addr, ent->data, ent->len); |
573 | f65ed4c1 | aliguori | /* FIXME smp_wmb() */
|
574 | f65ed4c1 | aliguori | ring->first = (ring->first + 1) % KVM_COALESCED_MMIO_MAX;
|
575 | f65ed4c1 | aliguori | } |
576 | f65ed4c1 | aliguori | } |
577 | f65ed4c1 | aliguori | #endif
|
578 | f65ed4c1 | aliguori | } |
579 | f65ed4c1 | aliguori | |
580 | 4c0960c0 | Avi Kivity | void kvm_cpu_synchronize_state(CPUState *env)
|
581 | 4c0960c0 | Avi Kivity | { |
582 | 4c0960c0 | Avi Kivity | if (!env->kvm_state->regs_modified) {
|
583 | 4c0960c0 | Avi Kivity | kvm_arch_get_registers(env); |
584 | 4c0960c0 | Avi Kivity | env->kvm_state->regs_modified = 1;
|
585 | 4c0960c0 | Avi Kivity | } |
586 | 4c0960c0 | Avi Kivity | } |
587 | 4c0960c0 | Avi Kivity | |
588 | 05330448 | aliguori | int kvm_cpu_exec(CPUState *env)
|
589 | 05330448 | aliguori | { |
590 | 05330448 | aliguori | struct kvm_run *run = env->kvm_run;
|
591 | 05330448 | aliguori | int ret;
|
592 | 05330448 | aliguori | |
593 | 05330448 | aliguori | dprintf("kvm_cpu_exec()\n");
|
594 | 05330448 | aliguori | |
595 | 05330448 | aliguori | do {
|
596 | be214e6c | aurel32 | if (env->exit_request) {
|
597 | 05330448 | aliguori | dprintf("interrupt exit requested\n");
|
598 | 05330448 | aliguori | ret = 0;
|
599 | 05330448 | aliguori | break;
|
600 | 05330448 | aliguori | } |
601 | 05330448 | aliguori | |
602 | 4c0960c0 | Avi Kivity | if (env->kvm_state->regs_modified) {
|
603 | 4c0960c0 | Avi Kivity | kvm_arch_put_registers(env); |
604 | 4c0960c0 | Avi Kivity | env->kvm_state->regs_modified = 0;
|
605 | 4c0960c0 | Avi Kivity | } |
606 | 4c0960c0 | Avi Kivity | |
607 | 8c14c173 | Jan Kiszka | kvm_arch_pre_run(env, run); |
608 | 05330448 | aliguori | ret = kvm_vcpu_ioctl(env, KVM_RUN, 0);
|
609 | 05330448 | aliguori | kvm_arch_post_run(env, run); |
610 | 05330448 | aliguori | |
611 | 05330448 | aliguori | if (ret == -EINTR || ret == -EAGAIN) {
|
612 | 05330448 | aliguori | dprintf("io window exit\n");
|
613 | 05330448 | aliguori | ret = 0;
|
614 | 05330448 | aliguori | break;
|
615 | 05330448 | aliguori | } |
616 | 05330448 | aliguori | |
617 | 05330448 | aliguori | if (ret < 0) { |
618 | 05330448 | aliguori | dprintf("kvm run failed %s\n", strerror(-ret));
|
619 | 05330448 | aliguori | abort(); |
620 | 05330448 | aliguori | } |
621 | 05330448 | aliguori | |
622 | f65ed4c1 | aliguori | kvm_run_coalesced_mmio(env, run); |
623 | f65ed4c1 | aliguori | |
624 | 05330448 | aliguori | ret = 0; /* exit loop */ |
625 | 05330448 | aliguori | switch (run->exit_reason) {
|
626 | 05330448 | aliguori | case KVM_EXIT_IO:
|
627 | 05330448 | aliguori | dprintf("handle_io\n");
|
628 | 05330448 | aliguori | ret = kvm_handle_io(env, run->io.port, |
629 | 05330448 | aliguori | (uint8_t *)run + run->io.data_offset, |
630 | 05330448 | aliguori | run->io.direction, |
631 | 05330448 | aliguori | run->io.size, |
632 | 05330448 | aliguori | run->io.count); |
633 | 05330448 | aliguori | break;
|
634 | 05330448 | aliguori | case KVM_EXIT_MMIO:
|
635 | 05330448 | aliguori | dprintf("handle_mmio\n");
|
636 | 05330448 | aliguori | cpu_physical_memory_rw(run->mmio.phys_addr, |
637 | 05330448 | aliguori | run->mmio.data, |
638 | 05330448 | aliguori | run->mmio.len, |
639 | 05330448 | aliguori | run->mmio.is_write); |
640 | 05330448 | aliguori | ret = 1;
|
641 | 05330448 | aliguori | break;
|
642 | 05330448 | aliguori | case KVM_EXIT_IRQ_WINDOW_OPEN:
|
643 | 05330448 | aliguori | dprintf("irq_window_open\n");
|
644 | 05330448 | aliguori | break;
|
645 | 05330448 | aliguori | case KVM_EXIT_SHUTDOWN:
|
646 | 05330448 | aliguori | dprintf("shutdown\n");
|
647 | 05330448 | aliguori | qemu_system_reset_request(); |
648 | 05330448 | aliguori | ret = 1;
|
649 | 05330448 | aliguori | break;
|
650 | 05330448 | aliguori | case KVM_EXIT_UNKNOWN:
|
651 | 05330448 | aliguori | dprintf("kvm_exit_unknown\n");
|
652 | 05330448 | aliguori | break;
|
653 | 05330448 | aliguori | case KVM_EXIT_FAIL_ENTRY:
|
654 | 05330448 | aliguori | dprintf("kvm_exit_fail_entry\n");
|
655 | 05330448 | aliguori | break;
|
656 | 05330448 | aliguori | case KVM_EXIT_EXCEPTION:
|
657 | 05330448 | aliguori | dprintf("kvm_exit_exception\n");
|
658 | 05330448 | aliguori | break;
|
659 | 05330448 | aliguori | case KVM_EXIT_DEBUG:
|
660 | 05330448 | aliguori | dprintf("kvm_exit_debug\n");
|
661 | e22a25c9 | aliguori | #ifdef KVM_CAP_SET_GUEST_DEBUG
|
662 | e22a25c9 | aliguori | if (kvm_arch_debug(&run->debug.arch)) {
|
663 | e22a25c9 | aliguori | gdb_set_stop_cpu(env); |
664 | e22a25c9 | aliguori | vm_stop(EXCP_DEBUG); |
665 | e22a25c9 | aliguori | env->exception_index = EXCP_DEBUG; |
666 | e22a25c9 | aliguori | return 0; |
667 | e22a25c9 | aliguori | } |
668 | e22a25c9 | aliguori | /* re-enter, this exception was guest-internal */
|
669 | e22a25c9 | aliguori | ret = 1;
|
670 | e22a25c9 | aliguori | #endif /* KVM_CAP_SET_GUEST_DEBUG */ |
671 | 05330448 | aliguori | break;
|
672 | 05330448 | aliguori | default:
|
673 | 05330448 | aliguori | dprintf("kvm_arch_handle_exit\n");
|
674 | 05330448 | aliguori | ret = kvm_arch_handle_exit(env, run); |
675 | 05330448 | aliguori | break;
|
676 | 05330448 | aliguori | } |
677 | 05330448 | aliguori | } while (ret > 0); |
678 | 05330448 | aliguori | |
679 | be214e6c | aurel32 | if (env->exit_request) {
|
680 | be214e6c | aurel32 | env->exit_request = 0;
|
681 | becfc390 | aliguori | env->exception_index = EXCP_INTERRUPT; |
682 | becfc390 | aliguori | } |
683 | becfc390 | aliguori | |
684 | 05330448 | aliguori | return ret;
|
685 | 05330448 | aliguori | } |
686 | 05330448 | aliguori | |
687 | 05330448 | aliguori | void kvm_set_phys_mem(target_phys_addr_t start_addr,
|
688 | 05330448 | aliguori | ram_addr_t size, |
689 | 05330448 | aliguori | ram_addr_t phys_offset) |
690 | 05330448 | aliguori | { |
691 | 05330448 | aliguori | KVMState *s = kvm_state; |
692 | 05330448 | aliguori | ram_addr_t flags = phys_offset & ~TARGET_PAGE_MASK; |
693 | 6152e2ae | aliguori | KVMSlot *mem, old; |
694 | 6152e2ae | aliguori | int err;
|
695 | 05330448 | aliguori | |
696 | d3f8d37f | aliguori | if (start_addr & ~TARGET_PAGE_MASK) {
|
697 | e6f4afe0 | Jan Kiszka | if (flags >= IO_MEM_UNASSIGNED) {
|
698 | e6f4afe0 | Jan Kiszka | if (!kvm_lookup_overlapping_slot(s, start_addr,
|
699 | e6f4afe0 | Jan Kiszka | start_addr + size)) { |
700 | e6f4afe0 | Jan Kiszka | return;
|
701 | e6f4afe0 | Jan Kiszka | } |
702 | e6f4afe0 | Jan Kiszka | fprintf(stderr, "Unaligned split of a KVM memory slot\n");
|
703 | e6f4afe0 | Jan Kiszka | } else {
|
704 | e6f4afe0 | Jan Kiszka | fprintf(stderr, "Only page-aligned memory slots supported\n");
|
705 | e6f4afe0 | Jan Kiszka | } |
706 | d3f8d37f | aliguori | abort(); |
707 | d3f8d37f | aliguori | } |
708 | d3f8d37f | aliguori | |
709 | 05330448 | aliguori | /* KVM does not support read-only slots */
|
710 | 05330448 | aliguori | phys_offset &= ~IO_MEM_ROM; |
711 | 05330448 | aliguori | |
712 | 6152e2ae | aliguori | while (1) { |
713 | 6152e2ae | aliguori | mem = kvm_lookup_overlapping_slot(s, start_addr, start_addr + size); |
714 | 6152e2ae | aliguori | if (!mem) {
|
715 | 6152e2ae | aliguori | break;
|
716 | 6152e2ae | aliguori | } |
717 | 62d60e8c | aliguori | |
718 | 6152e2ae | aliguori | if (flags < IO_MEM_UNASSIGNED && start_addr >= mem->start_addr &&
|
719 | 6152e2ae | aliguori | (start_addr + size <= mem->start_addr + mem->memory_size) && |
720 | 6152e2ae | aliguori | (phys_offset - start_addr == mem->phys_offset - mem->start_addr)) { |
721 | 6152e2ae | aliguori | /* The new slot fits into the existing one and comes with
|
722 | 6152e2ae | aliguori | * identical parameters - nothing to be done. */
|
723 | 05330448 | aliguori | return;
|
724 | 6152e2ae | aliguori | } |
725 | 6152e2ae | aliguori | |
726 | 6152e2ae | aliguori | old = *mem; |
727 | 6152e2ae | aliguori | |
728 | 6152e2ae | aliguori | /* unregister the overlapping slot */
|
729 | 6152e2ae | aliguori | mem->memory_size = 0;
|
730 | 6152e2ae | aliguori | err = kvm_set_user_memory_region(s, mem); |
731 | 6152e2ae | aliguori | if (err) {
|
732 | 6152e2ae | aliguori | fprintf(stderr, "%s: error unregistering overlapping slot: %s\n",
|
733 | 6152e2ae | aliguori | __func__, strerror(-err)); |
734 | 62d60e8c | aliguori | abort(); |
735 | 62d60e8c | aliguori | } |
736 | 6152e2ae | aliguori | |
737 | 6152e2ae | aliguori | /* Workaround for older KVM versions: we can't join slots, even not by
|
738 | 6152e2ae | aliguori | * unregistering the previous ones and then registering the larger
|
739 | 6152e2ae | aliguori | * slot. We have to maintain the existing fragmentation. Sigh.
|
740 | 6152e2ae | aliguori | *
|
741 | 6152e2ae | aliguori | * This workaround assumes that the new slot starts at the same
|
742 | 6152e2ae | aliguori | * address as the first existing one. If not or if some overlapping
|
743 | 6152e2ae | aliguori | * slot comes around later, we will fail (not seen in practice so far)
|
744 | 6152e2ae | aliguori | * - and actually require a recent KVM version. */
|
745 | e69917e2 | Jan Kiszka | if (s->broken_set_mem_region &&
|
746 | e69917e2 | Jan Kiszka | old.start_addr == start_addr && old.memory_size < size && |
747 | 6152e2ae | aliguori | flags < IO_MEM_UNASSIGNED) { |
748 | 6152e2ae | aliguori | mem = kvm_alloc_slot(s); |
749 | 6152e2ae | aliguori | mem->memory_size = old.memory_size; |
750 | 6152e2ae | aliguori | mem->start_addr = old.start_addr; |
751 | 6152e2ae | aliguori | mem->phys_offset = old.phys_offset; |
752 | 6152e2ae | aliguori | mem->flags = 0;
|
753 | 6152e2ae | aliguori | |
754 | 6152e2ae | aliguori | err = kvm_set_user_memory_region(s, mem); |
755 | 6152e2ae | aliguori | if (err) {
|
756 | 6152e2ae | aliguori | fprintf(stderr, "%s: error updating slot: %s\n", __func__,
|
757 | 6152e2ae | aliguori | strerror(-err)); |
758 | 6152e2ae | aliguori | abort(); |
759 | 6152e2ae | aliguori | } |
760 | 6152e2ae | aliguori | |
761 | 6152e2ae | aliguori | start_addr += old.memory_size; |
762 | 6152e2ae | aliguori | phys_offset += old.memory_size; |
763 | 6152e2ae | aliguori | size -= old.memory_size; |
764 | 6152e2ae | aliguori | continue;
|
765 | 6152e2ae | aliguori | } |
766 | 6152e2ae | aliguori | |
767 | 6152e2ae | aliguori | /* register prefix slot */
|
768 | 6152e2ae | aliguori | if (old.start_addr < start_addr) {
|
769 | 6152e2ae | aliguori | mem = kvm_alloc_slot(s); |
770 | 6152e2ae | aliguori | mem->memory_size = start_addr - old.start_addr; |
771 | 6152e2ae | aliguori | mem->start_addr = old.start_addr; |
772 | 6152e2ae | aliguori | mem->phys_offset = old.phys_offset; |
773 | 6152e2ae | aliguori | mem->flags = 0;
|
774 | 6152e2ae | aliguori | |
775 | 6152e2ae | aliguori | err = kvm_set_user_memory_region(s, mem); |
776 | 6152e2ae | aliguori | if (err) {
|
777 | 6152e2ae | aliguori | fprintf(stderr, "%s: error registering prefix slot: %s\n",
|
778 | 6152e2ae | aliguori | __func__, strerror(-err)); |
779 | 6152e2ae | aliguori | abort(); |
780 | 6152e2ae | aliguori | } |
781 | 6152e2ae | aliguori | } |
782 | 6152e2ae | aliguori | |
783 | 6152e2ae | aliguori | /* register suffix slot */
|
784 | 6152e2ae | aliguori | if (old.start_addr + old.memory_size > start_addr + size) {
|
785 | 6152e2ae | aliguori | ram_addr_t size_delta; |
786 | 6152e2ae | aliguori | |
787 | 6152e2ae | aliguori | mem = kvm_alloc_slot(s); |
788 | 6152e2ae | aliguori | mem->start_addr = start_addr + size; |
789 | 6152e2ae | aliguori | size_delta = mem->start_addr - old.start_addr; |
790 | 6152e2ae | aliguori | mem->memory_size = old.memory_size - size_delta; |
791 | 6152e2ae | aliguori | mem->phys_offset = old.phys_offset + size_delta; |
792 | 6152e2ae | aliguori | mem->flags = 0;
|
793 | 6152e2ae | aliguori | |
794 | 6152e2ae | aliguori | err = kvm_set_user_memory_region(s, mem); |
795 | 6152e2ae | aliguori | if (err) {
|
796 | 6152e2ae | aliguori | fprintf(stderr, "%s: error registering suffix slot: %s\n",
|
797 | 6152e2ae | aliguori | __func__, strerror(-err)); |
798 | 6152e2ae | aliguori | abort(); |
799 | 6152e2ae | aliguori | } |
800 | 6152e2ae | aliguori | } |
801 | 05330448 | aliguori | } |
802 | 6152e2ae | aliguori | |
803 | 6152e2ae | aliguori | /* in case the KVM bug workaround already "consumed" the new slot */
|
804 | 6152e2ae | aliguori | if (!size)
|
805 | 6152e2ae | aliguori | return;
|
806 | 6152e2ae | aliguori | |
807 | 05330448 | aliguori | /* KVM does not need to know about this memory */
|
808 | 05330448 | aliguori | if (flags >= IO_MEM_UNASSIGNED)
|
809 | 05330448 | aliguori | return;
|
810 | 05330448 | aliguori | |
811 | 05330448 | aliguori | mem = kvm_alloc_slot(s); |
812 | 05330448 | aliguori | mem->memory_size = size; |
813 | 34fc643f | aliguori | mem->start_addr = start_addr; |
814 | 34fc643f | aliguori | mem->phys_offset = phys_offset; |
815 | 05330448 | aliguori | mem->flags = 0;
|
816 | 05330448 | aliguori | |
817 | 6152e2ae | aliguori | err = kvm_set_user_memory_region(s, mem); |
818 | 6152e2ae | aliguori | if (err) {
|
819 | 6152e2ae | aliguori | fprintf(stderr, "%s: error registering slot: %s\n", __func__,
|
820 | 6152e2ae | aliguori | strerror(-err)); |
821 | 6152e2ae | aliguori | abort(); |
822 | 6152e2ae | aliguori | } |
823 | 05330448 | aliguori | } |
824 | 05330448 | aliguori | |
825 | 984b5181 | aliguori | int kvm_ioctl(KVMState *s, int type, ...) |
826 | 05330448 | aliguori | { |
827 | 05330448 | aliguori | int ret;
|
828 | 984b5181 | aliguori | void *arg;
|
829 | 984b5181 | aliguori | va_list ap; |
830 | 05330448 | aliguori | |
831 | 984b5181 | aliguori | va_start(ap, type); |
832 | 984b5181 | aliguori | arg = va_arg(ap, void *);
|
833 | 984b5181 | aliguori | va_end(ap); |
834 | 984b5181 | aliguori | |
835 | 984b5181 | aliguori | ret = ioctl(s->fd, type, arg); |
836 | 05330448 | aliguori | if (ret == -1) |
837 | 05330448 | aliguori | ret = -errno; |
838 | 05330448 | aliguori | |
839 | 05330448 | aliguori | return ret;
|
840 | 05330448 | aliguori | } |
841 | 05330448 | aliguori | |
842 | 984b5181 | aliguori | int kvm_vm_ioctl(KVMState *s, int type, ...) |
843 | 05330448 | aliguori | { |
844 | 05330448 | aliguori | int ret;
|
845 | 984b5181 | aliguori | void *arg;
|
846 | 984b5181 | aliguori | va_list ap; |
847 | 984b5181 | aliguori | |
848 | 984b5181 | aliguori | va_start(ap, type); |
849 | 984b5181 | aliguori | arg = va_arg(ap, void *);
|
850 | 984b5181 | aliguori | va_end(ap); |
851 | 05330448 | aliguori | |
852 | 984b5181 | aliguori | ret = ioctl(s->vmfd, type, arg); |
853 | 05330448 | aliguori | if (ret == -1) |
854 | 05330448 | aliguori | ret = -errno; |
855 | 05330448 | aliguori | |
856 | 05330448 | aliguori | return ret;
|
857 | 05330448 | aliguori | } |
858 | 05330448 | aliguori | |
859 | 984b5181 | aliguori | int kvm_vcpu_ioctl(CPUState *env, int type, ...) |
860 | 05330448 | aliguori | { |
861 | 05330448 | aliguori | int ret;
|
862 | 984b5181 | aliguori | void *arg;
|
863 | 984b5181 | aliguori | va_list ap; |
864 | 984b5181 | aliguori | |
865 | 984b5181 | aliguori | va_start(ap, type); |
866 | 984b5181 | aliguori | arg = va_arg(ap, void *);
|
867 | 984b5181 | aliguori | va_end(ap); |
868 | 05330448 | aliguori | |
869 | 984b5181 | aliguori | ret = ioctl(env->kvm_fd, type, arg); |
870 | 05330448 | aliguori | if (ret == -1) |
871 | 05330448 | aliguori | ret = -errno; |
872 | 05330448 | aliguori | |
873 | 05330448 | aliguori | return ret;
|
874 | 05330448 | aliguori | } |
875 | bd322087 | aliguori | |
876 | bd322087 | aliguori | int kvm_has_sync_mmu(void) |
877 | bd322087 | aliguori | { |
878 | a9c11522 | aurel32 | #ifdef KVM_CAP_SYNC_MMU
|
879 | bd322087 | aliguori | KVMState *s = kvm_state; |
880 | bd322087 | aliguori | |
881 | ad7b8b33 | Anthony Liguori | return kvm_check_extension(s, KVM_CAP_SYNC_MMU);
|
882 | ad7b8b33 | Anthony Liguori | #else
|
883 | bd322087 | aliguori | return 0; |
884 | ad7b8b33 | Anthony Liguori | #endif
|
885 | bd322087 | aliguori | } |
886 | e22a25c9 | aliguori | |
887 | 6f0437e8 | Jan Kiszka | void kvm_setup_guest_memory(void *start, size_t size) |
888 | 6f0437e8 | Jan Kiszka | { |
889 | 6f0437e8 | Jan Kiszka | if (!kvm_has_sync_mmu()) {
|
890 | 6f0437e8 | Jan Kiszka | #ifdef MADV_DONTFORK
|
891 | 6f0437e8 | Jan Kiszka | int ret = madvise(start, size, MADV_DONTFORK);
|
892 | 6f0437e8 | Jan Kiszka | |
893 | 6f0437e8 | Jan Kiszka | if (ret) {
|
894 | 6f0437e8 | Jan Kiszka | perror("madvice");
|
895 | 6f0437e8 | Jan Kiszka | exit(1);
|
896 | 6f0437e8 | Jan Kiszka | } |
897 | 6f0437e8 | Jan Kiszka | #else
|
898 | 6f0437e8 | Jan Kiszka | fprintf(stderr, |
899 | 6f0437e8 | Jan Kiszka | "Need MADV_DONTFORK in absence of synchronous KVM MMU\n");
|
900 | 6f0437e8 | Jan Kiszka | exit(1);
|
901 | 6f0437e8 | Jan Kiszka | #endif
|
902 | 6f0437e8 | Jan Kiszka | } |
903 | 6f0437e8 | Jan Kiszka | } |
904 | 6f0437e8 | Jan Kiszka | |
905 | e22a25c9 | aliguori | #ifdef KVM_CAP_SET_GUEST_DEBUG
|
906 | fc5d642f | Luiz Capitulino | static void on_vcpu(CPUState *env, void (*func)(void *data), void *data) |
907 | fc5d642f | Luiz Capitulino | { |
908 | fc5d642f | Luiz Capitulino | if (env == cpu_single_env) {
|
909 | fc5d642f | Luiz Capitulino | func(data); |
910 | fc5d642f | Luiz Capitulino | return;
|
911 | fc5d642f | Luiz Capitulino | } |
912 | fc5d642f | Luiz Capitulino | abort(); |
913 | fc5d642f | Luiz Capitulino | } |
914 | fc5d642f | Luiz Capitulino | |
915 | e22a25c9 | aliguori | struct kvm_sw_breakpoint *kvm_find_sw_breakpoint(CPUState *env,
|
916 | e22a25c9 | aliguori | target_ulong pc) |
917 | e22a25c9 | aliguori | { |
918 | e22a25c9 | aliguori | struct kvm_sw_breakpoint *bp;
|
919 | e22a25c9 | aliguori | |
920 | 72cf2d4f | Blue Swirl | QTAILQ_FOREACH(bp, &env->kvm_state->kvm_sw_breakpoints, entry) { |
921 | e22a25c9 | aliguori | if (bp->pc == pc)
|
922 | e22a25c9 | aliguori | return bp;
|
923 | e22a25c9 | aliguori | } |
924 | e22a25c9 | aliguori | return NULL; |
925 | e22a25c9 | aliguori | } |
926 | e22a25c9 | aliguori | |
927 | e22a25c9 | aliguori | int kvm_sw_breakpoints_active(CPUState *env)
|
928 | e22a25c9 | aliguori | { |
929 | 72cf2d4f | Blue Swirl | return !QTAILQ_EMPTY(&env->kvm_state->kvm_sw_breakpoints);
|
930 | e22a25c9 | aliguori | } |
931 | e22a25c9 | aliguori | |
932 | 452e4751 | Glauber Costa | struct kvm_set_guest_debug_data {
|
933 | 452e4751 | Glauber Costa | struct kvm_guest_debug dbg;
|
934 | 452e4751 | Glauber Costa | CPUState *env; |
935 | 452e4751 | Glauber Costa | int err;
|
936 | 452e4751 | Glauber Costa | }; |
937 | 452e4751 | Glauber Costa | |
938 | 452e4751 | Glauber Costa | static void kvm_invoke_set_guest_debug(void *data) |
939 | 452e4751 | Glauber Costa | { |
940 | 452e4751 | Glauber Costa | struct kvm_set_guest_debug_data *dbg_data = data;
|
941 | 452e4751 | Glauber Costa | dbg_data->err = kvm_vcpu_ioctl(dbg_data->env, KVM_SET_GUEST_DEBUG, &dbg_data->dbg); |
942 | 452e4751 | Glauber Costa | } |
943 | 452e4751 | Glauber Costa | |
944 | e22a25c9 | aliguori | int kvm_update_guest_debug(CPUState *env, unsigned long reinject_trap) |
945 | e22a25c9 | aliguori | { |
946 | 452e4751 | Glauber Costa | struct kvm_set_guest_debug_data data;
|
947 | e22a25c9 | aliguori | |
948 | 452e4751 | Glauber Costa | data.dbg.control = 0;
|
949 | e22a25c9 | aliguori | if (env->singlestep_enabled)
|
950 | 452e4751 | Glauber Costa | data.dbg.control = KVM_GUESTDBG_ENABLE | KVM_GUESTDBG_SINGLESTEP; |
951 | e22a25c9 | aliguori | |
952 | 452e4751 | Glauber Costa | kvm_arch_update_guest_debug(env, &data.dbg); |
953 | 452e4751 | Glauber Costa | data.dbg.control |= reinject_trap; |
954 | 452e4751 | Glauber Costa | data.env = env; |
955 | e22a25c9 | aliguori | |
956 | 452e4751 | Glauber Costa | on_vcpu(env, kvm_invoke_set_guest_debug, &data); |
957 | 452e4751 | Glauber Costa | return data.err;
|
958 | e22a25c9 | aliguori | } |
959 | e22a25c9 | aliguori | |
960 | e22a25c9 | aliguori | int kvm_insert_breakpoint(CPUState *current_env, target_ulong addr,
|
961 | e22a25c9 | aliguori | target_ulong len, int type)
|
962 | e22a25c9 | aliguori | { |
963 | e22a25c9 | aliguori | struct kvm_sw_breakpoint *bp;
|
964 | e22a25c9 | aliguori | CPUState *env; |
965 | e22a25c9 | aliguori | int err;
|
966 | e22a25c9 | aliguori | |
967 | e22a25c9 | aliguori | if (type == GDB_BREAKPOINT_SW) {
|
968 | e22a25c9 | aliguori | bp = kvm_find_sw_breakpoint(current_env, addr); |
969 | e22a25c9 | aliguori | if (bp) {
|
970 | e22a25c9 | aliguori | bp->use_count++; |
971 | e22a25c9 | aliguori | return 0; |
972 | e22a25c9 | aliguori | } |
973 | e22a25c9 | aliguori | |
974 | e22a25c9 | aliguori | bp = qemu_malloc(sizeof(struct kvm_sw_breakpoint)); |
975 | e22a25c9 | aliguori | if (!bp)
|
976 | e22a25c9 | aliguori | return -ENOMEM;
|
977 | e22a25c9 | aliguori | |
978 | e22a25c9 | aliguori | bp->pc = addr; |
979 | e22a25c9 | aliguori | bp->use_count = 1;
|
980 | e22a25c9 | aliguori | err = kvm_arch_insert_sw_breakpoint(current_env, bp); |
981 | e22a25c9 | aliguori | if (err) {
|
982 | e22a25c9 | aliguori | free(bp); |
983 | e22a25c9 | aliguori | return err;
|
984 | e22a25c9 | aliguori | } |
985 | e22a25c9 | aliguori | |
986 | 72cf2d4f | Blue Swirl | QTAILQ_INSERT_HEAD(¤t_env->kvm_state->kvm_sw_breakpoints, |
987 | e22a25c9 | aliguori | bp, entry); |
988 | e22a25c9 | aliguori | } else {
|
989 | e22a25c9 | aliguori | err = kvm_arch_insert_hw_breakpoint(addr, len, type); |
990 | e22a25c9 | aliguori | if (err)
|
991 | e22a25c9 | aliguori | return err;
|
992 | e22a25c9 | aliguori | } |
993 | e22a25c9 | aliguori | |
994 | e22a25c9 | aliguori | for (env = first_cpu; env != NULL; env = env->next_cpu) { |
995 | e22a25c9 | aliguori | err = kvm_update_guest_debug(env, 0);
|
996 | e22a25c9 | aliguori | if (err)
|
997 | e22a25c9 | aliguori | return err;
|
998 | e22a25c9 | aliguori | } |
999 | e22a25c9 | aliguori | return 0; |
1000 | e22a25c9 | aliguori | } |
1001 | e22a25c9 | aliguori | |
1002 | e22a25c9 | aliguori | int kvm_remove_breakpoint(CPUState *current_env, target_ulong addr,
|
1003 | e22a25c9 | aliguori | target_ulong len, int type)
|
1004 | e22a25c9 | aliguori | { |
1005 | e22a25c9 | aliguori | struct kvm_sw_breakpoint *bp;
|
1006 | e22a25c9 | aliguori | CPUState *env; |
1007 | e22a25c9 | aliguori | int err;
|
1008 | e22a25c9 | aliguori | |
1009 | e22a25c9 | aliguori | if (type == GDB_BREAKPOINT_SW) {
|
1010 | e22a25c9 | aliguori | bp = kvm_find_sw_breakpoint(current_env, addr); |
1011 | e22a25c9 | aliguori | if (!bp)
|
1012 | e22a25c9 | aliguori | return -ENOENT;
|
1013 | e22a25c9 | aliguori | |
1014 | e22a25c9 | aliguori | if (bp->use_count > 1) { |
1015 | e22a25c9 | aliguori | bp->use_count--; |
1016 | e22a25c9 | aliguori | return 0; |
1017 | e22a25c9 | aliguori | } |
1018 | e22a25c9 | aliguori | |
1019 | e22a25c9 | aliguori | err = kvm_arch_remove_sw_breakpoint(current_env, bp); |
1020 | e22a25c9 | aliguori | if (err)
|
1021 | e22a25c9 | aliguori | return err;
|
1022 | e22a25c9 | aliguori | |
1023 | 72cf2d4f | Blue Swirl | QTAILQ_REMOVE(¤t_env->kvm_state->kvm_sw_breakpoints, bp, entry); |
1024 | e22a25c9 | aliguori | qemu_free(bp); |
1025 | e22a25c9 | aliguori | } else {
|
1026 | e22a25c9 | aliguori | err = kvm_arch_remove_hw_breakpoint(addr, len, type); |
1027 | e22a25c9 | aliguori | if (err)
|
1028 | e22a25c9 | aliguori | return err;
|
1029 | e22a25c9 | aliguori | } |
1030 | e22a25c9 | aliguori | |
1031 | e22a25c9 | aliguori | for (env = first_cpu; env != NULL; env = env->next_cpu) { |
1032 | e22a25c9 | aliguori | err = kvm_update_guest_debug(env, 0);
|
1033 | e22a25c9 | aliguori | if (err)
|
1034 | e22a25c9 | aliguori | return err;
|
1035 | e22a25c9 | aliguori | } |
1036 | e22a25c9 | aliguori | return 0; |
1037 | e22a25c9 | aliguori | } |
1038 | e22a25c9 | aliguori | |
1039 | e22a25c9 | aliguori | void kvm_remove_all_breakpoints(CPUState *current_env)
|
1040 | e22a25c9 | aliguori | { |
1041 | e22a25c9 | aliguori | struct kvm_sw_breakpoint *bp, *next;
|
1042 | e22a25c9 | aliguori | KVMState *s = current_env->kvm_state; |
1043 | e22a25c9 | aliguori | CPUState *env; |
1044 | e22a25c9 | aliguori | |
1045 | 72cf2d4f | Blue Swirl | QTAILQ_FOREACH_SAFE(bp, &s->kvm_sw_breakpoints, entry, next) { |
1046 | e22a25c9 | aliguori | if (kvm_arch_remove_sw_breakpoint(current_env, bp) != 0) { |
1047 | e22a25c9 | aliguori | /* Try harder to find a CPU that currently sees the breakpoint. */
|
1048 | e22a25c9 | aliguori | for (env = first_cpu; env != NULL; env = env->next_cpu) { |
1049 | e22a25c9 | aliguori | if (kvm_arch_remove_sw_breakpoint(env, bp) == 0) |
1050 | e22a25c9 | aliguori | break;
|
1051 | e22a25c9 | aliguori | } |
1052 | e22a25c9 | aliguori | } |
1053 | e22a25c9 | aliguori | } |
1054 | e22a25c9 | aliguori | kvm_arch_remove_all_hw_breakpoints(); |
1055 | e22a25c9 | aliguori | |
1056 | e22a25c9 | aliguori | for (env = first_cpu; env != NULL; env = env->next_cpu) |
1057 | e22a25c9 | aliguori | kvm_update_guest_debug(env, 0);
|
1058 | e22a25c9 | aliguori | } |
1059 | e22a25c9 | aliguori | |
1060 | e22a25c9 | aliguori | #else /* !KVM_CAP_SET_GUEST_DEBUG */ |
1061 | e22a25c9 | aliguori | |
1062 | e22a25c9 | aliguori | int kvm_update_guest_debug(CPUState *env, unsigned long reinject_trap) |
1063 | e22a25c9 | aliguori | { |
1064 | e22a25c9 | aliguori | return -EINVAL;
|
1065 | e22a25c9 | aliguori | } |
1066 | e22a25c9 | aliguori | |
1067 | e22a25c9 | aliguori | int kvm_insert_breakpoint(CPUState *current_env, target_ulong addr,
|
1068 | e22a25c9 | aliguori | target_ulong len, int type)
|
1069 | e22a25c9 | aliguori | { |
1070 | e22a25c9 | aliguori | return -EINVAL;
|
1071 | e22a25c9 | aliguori | } |
1072 | e22a25c9 | aliguori | |
1073 | e22a25c9 | aliguori | int kvm_remove_breakpoint(CPUState *current_env, target_ulong addr,
|
1074 | e22a25c9 | aliguori | target_ulong len, int type)
|
1075 | e22a25c9 | aliguori | { |
1076 | e22a25c9 | aliguori | return -EINVAL;
|
1077 | e22a25c9 | aliguori | } |
1078 | e22a25c9 | aliguori | |
1079 | e22a25c9 | aliguori | void kvm_remove_all_breakpoints(CPUState *current_env)
|
1080 | e22a25c9 | aliguori | { |
1081 | e22a25c9 | aliguori | } |
1082 | e22a25c9 | aliguori | #endif /* !KVM_CAP_SET_GUEST_DEBUG */ |