4 * Copyright IBM, Corp. 2008
8 * Anthony Liguori <aliguori@us.ibm.com>
9 * Glauber Costa <gcosta@redhat.com>
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.
16 #include <sys/types.h>
17 #include <sys/ioctl.h>
21 #include <linux/kvm.h>
23 #include "qemu-common.h"
24 #include "qemu-barrier.h"
32 #include "exec-memory.h"
34 /* This check must be after config-host.h is included */
36 #include <sys/eventfd.h>
39 /* KVM uses PAGE_SIZE in its definition of COALESCED_MMIO_MAX */
40 #define PAGE_SIZE TARGET_PAGE_SIZE
45 #define DPRINTF(fmt, ...) \
46 do { fprintf(stderr, fmt, ## __VA_ARGS__); } while (0)
48 #define DPRINTF(fmt, ...) \
52 #define KVM_MSI_HASHTAB_SIZE 256
54 typedef struct KVMSlot
56 target_phys_addr_t start_addr
;
57 ram_addr_t memory_size
;
63 typedef struct kvm_dirty_log KVMDirtyLog
;
65 typedef struct KVMMSIRoute
{
66 struct kvm_irq_routing_entry kroute
;
67 QTAILQ_ENTRY(KVMMSIRoute
) entry
;
76 struct kvm_coalesced_mmio_ring
*coalesced_mmio_ring
;
77 bool coalesced_flush_in_progress
;
78 int broken_set_mem_region
;
81 int robust_singlestep
;
83 #ifdef KVM_CAP_SET_GUEST_DEBUG
84 struct kvm_sw_breakpoint_head kvm_sw_breakpoints
;
89 /* The man page (and posix) say ioctl numbers are signed int, but
90 * they're not. Linux, glibc and *BSD all treat ioctl numbers as
91 * unsigned, and treating them as signed here can break things */
92 unsigned irqchip_inject_ioctl
;
93 #ifdef KVM_CAP_IRQ_ROUTING
94 struct kvm_irq_routing
*irq_routes
;
95 int nr_allocated_irq_routes
;
96 uint32_t *used_gsi_bitmap
;
97 unsigned int gsi_count
;
98 QTAILQ_HEAD(msi_hashtab
, KVMMSIRoute
) msi_hashtab
[KVM_MSI_HASHTAB_SIZE
];
104 bool kvm_kernel_irqchip
;
106 static const KVMCapabilityInfo kvm_required_capabilites
[] = {
107 KVM_CAP_INFO(USER_MEMORY
),
108 KVM_CAP_INFO(DESTROY_MEMORY_REGION_WORKS
),
112 static KVMSlot
*kvm_alloc_slot(KVMState
*s
)
116 for (i
= 0; i
< ARRAY_SIZE(s
->slots
); i
++) {
117 if (s
->slots
[i
].memory_size
== 0) {
122 fprintf(stderr
, "%s: no free slot available\n", __func__
);
126 static KVMSlot
*kvm_lookup_matching_slot(KVMState
*s
,
127 target_phys_addr_t start_addr
,
128 target_phys_addr_t end_addr
)
132 for (i
= 0; i
< ARRAY_SIZE(s
->slots
); i
++) {
133 KVMSlot
*mem
= &s
->slots
[i
];
135 if (start_addr
== mem
->start_addr
&&
136 end_addr
== mem
->start_addr
+ mem
->memory_size
) {
145 * Find overlapping slot with lowest start address
147 static KVMSlot
*kvm_lookup_overlapping_slot(KVMState
*s
,
148 target_phys_addr_t start_addr
,
149 target_phys_addr_t end_addr
)
151 KVMSlot
*found
= NULL
;
154 for (i
= 0; i
< ARRAY_SIZE(s
->slots
); i
++) {
155 KVMSlot
*mem
= &s
->slots
[i
];
157 if (mem
->memory_size
== 0 ||
158 (found
&& found
->start_addr
< mem
->start_addr
)) {
162 if (end_addr
> mem
->start_addr
&&
163 start_addr
< mem
->start_addr
+ mem
->memory_size
) {
171 int kvm_physical_memory_addr_from_host(KVMState
*s
, void *ram
,
172 target_phys_addr_t
*phys_addr
)
176 for (i
= 0; i
< ARRAY_SIZE(s
->slots
); i
++) {
177 KVMSlot
*mem
= &s
->slots
[i
];
179 if (ram
>= mem
->ram
&& ram
< mem
->ram
+ mem
->memory_size
) {
180 *phys_addr
= mem
->start_addr
+ (ram
- mem
->ram
);
188 static int kvm_set_user_memory_region(KVMState
*s
, KVMSlot
*slot
)
190 struct kvm_userspace_memory_region mem
;
192 mem
.slot
= slot
->slot
;
193 mem
.guest_phys_addr
= slot
->start_addr
;
194 mem
.memory_size
= slot
->memory_size
;
195 mem
.userspace_addr
= (unsigned long)slot
->ram
;
196 mem
.flags
= slot
->flags
;
197 if (s
->migration_log
) {
198 mem
.flags
|= KVM_MEM_LOG_DIRTY_PAGES
;
200 return kvm_vm_ioctl(s
, KVM_SET_USER_MEMORY_REGION
, &mem
);
203 static void kvm_reset_vcpu(void *opaque
)
205 CPUArchState
*env
= opaque
;
207 kvm_arch_reset_vcpu(env
);
210 int kvm_init_vcpu(CPUArchState
*env
)
212 KVMState
*s
= kvm_state
;
216 DPRINTF("kvm_init_vcpu\n");
218 ret
= kvm_vm_ioctl(s
, KVM_CREATE_VCPU
, env
->cpu_index
);
220 DPRINTF("kvm_create_vcpu failed\n");
226 env
->kvm_vcpu_dirty
= 1;
228 mmap_size
= kvm_ioctl(s
, KVM_GET_VCPU_MMAP_SIZE
, 0);
231 DPRINTF("KVM_GET_VCPU_MMAP_SIZE failed\n");
235 env
->kvm_run
= mmap(NULL
, mmap_size
, PROT_READ
| PROT_WRITE
, MAP_SHARED
,
237 if (env
->kvm_run
== MAP_FAILED
) {
239 DPRINTF("mmap'ing vcpu state failed\n");
243 if (s
->coalesced_mmio
&& !s
->coalesced_mmio_ring
) {
244 s
->coalesced_mmio_ring
=
245 (void *)env
->kvm_run
+ s
->coalesced_mmio
* PAGE_SIZE
;
248 ret
= kvm_arch_init_vcpu(env
);
250 qemu_register_reset(kvm_reset_vcpu
, env
);
251 kvm_arch_reset_vcpu(env
);
258 * dirty pages logging control
261 static int kvm_mem_flags(KVMState
*s
, bool log_dirty
)
263 return log_dirty
? KVM_MEM_LOG_DIRTY_PAGES
: 0;
266 static int kvm_slot_dirty_pages_log_change(KVMSlot
*mem
, bool log_dirty
)
268 KVMState
*s
= kvm_state
;
269 int flags
, mask
= KVM_MEM_LOG_DIRTY_PAGES
;
272 old_flags
= mem
->flags
;
274 flags
= (mem
->flags
& ~mask
) | kvm_mem_flags(s
, log_dirty
);
277 /* If nothing changed effectively, no need to issue ioctl */
278 if (s
->migration_log
) {
279 flags
|= KVM_MEM_LOG_DIRTY_PAGES
;
282 if (flags
== old_flags
) {
286 return kvm_set_user_memory_region(s
, mem
);
289 static int kvm_dirty_pages_log_change(target_phys_addr_t phys_addr
,
290 ram_addr_t size
, bool log_dirty
)
292 KVMState
*s
= kvm_state
;
293 KVMSlot
*mem
= kvm_lookup_matching_slot(s
, phys_addr
, phys_addr
+ size
);
296 fprintf(stderr
, "BUG: %s: invalid parameters " TARGET_FMT_plx
"-"
297 TARGET_FMT_plx
"\n", __func__
, phys_addr
,
298 (target_phys_addr_t
)(phys_addr
+ size
- 1));
301 return kvm_slot_dirty_pages_log_change(mem
, log_dirty
);
304 static void kvm_log_start(MemoryListener
*listener
,
305 MemoryRegionSection
*section
)
309 r
= kvm_dirty_pages_log_change(section
->offset_within_address_space
,
310 section
->size
, true);
316 static void kvm_log_stop(MemoryListener
*listener
,
317 MemoryRegionSection
*section
)
321 r
= kvm_dirty_pages_log_change(section
->offset_within_address_space
,
322 section
->size
, false);
328 static int kvm_set_migration_log(int enable
)
330 KVMState
*s
= kvm_state
;
334 s
->migration_log
= enable
;
336 for (i
= 0; i
< ARRAY_SIZE(s
->slots
); i
++) {
339 if (!mem
->memory_size
) {
342 if (!!(mem
->flags
& KVM_MEM_LOG_DIRTY_PAGES
) == enable
) {
345 err
= kvm_set_user_memory_region(s
, mem
);
353 /* get kvm's dirty pages bitmap and update qemu's */
354 static int kvm_get_dirty_pages_log_range(MemoryRegionSection
*section
,
355 unsigned long *bitmap
)
358 unsigned long page_number
, c
;
359 target_phys_addr_t addr
, addr1
;
360 unsigned int len
= ((section
->size
/ TARGET_PAGE_SIZE
) + HOST_LONG_BITS
- 1) / HOST_LONG_BITS
;
361 unsigned long hpratio
= getpagesize() / TARGET_PAGE_SIZE
;
364 * bitmap-traveling is faster than memory-traveling (for addr...)
365 * especially when most of the memory is not dirty.
367 for (i
= 0; i
< len
; i
++) {
368 if (bitmap
[i
] != 0) {
369 c
= leul_to_cpu(bitmap
[i
]);
373 page_number
= (i
* HOST_LONG_BITS
+ j
) * hpratio
;
374 addr1
= page_number
* TARGET_PAGE_SIZE
;
375 addr
= section
->offset_within_region
+ addr1
;
376 memory_region_set_dirty(section
->mr
, addr
,
377 TARGET_PAGE_SIZE
* hpratio
);
384 #define ALIGN(x, y) (((x)+(y)-1) & ~((y)-1))
387 * kvm_physical_sync_dirty_bitmap - Grab dirty bitmap from kernel space
388 * This function updates qemu's dirty bitmap using
389 * memory_region_set_dirty(). This means all bits are set
392 * @start_add: start of logged region.
393 * @end_addr: end of logged region.
395 static int kvm_physical_sync_dirty_bitmap(MemoryRegionSection
*section
)
397 KVMState
*s
= kvm_state
;
398 unsigned long size
, allocated_size
= 0;
402 target_phys_addr_t start_addr
= section
->offset_within_address_space
;
403 target_phys_addr_t end_addr
= start_addr
+ section
->size
;
405 d
.dirty_bitmap
= NULL
;
406 while (start_addr
< end_addr
) {
407 mem
= kvm_lookup_overlapping_slot(s
, start_addr
, end_addr
);
412 /* XXX bad kernel interface alert
413 * For dirty bitmap, kernel allocates array of size aligned to
414 * bits-per-long. But for case when the kernel is 64bits and
415 * the userspace is 32bits, userspace can't align to the same
416 * bits-per-long, since sizeof(long) is different between kernel
417 * and user space. This way, userspace will provide buffer which
418 * may be 4 bytes less than the kernel will use, resulting in
419 * userspace memory corruption (which is not detectable by valgrind
420 * too, in most cases).
421 * So for now, let's align to 64 instead of HOST_LONG_BITS here, in
422 * a hope that sizeof(long) wont become >8 any time soon.
424 size
= ALIGN(((mem
->memory_size
) >> TARGET_PAGE_BITS
),
425 /*HOST_LONG_BITS*/ 64) / 8;
426 if (!d
.dirty_bitmap
) {
427 d
.dirty_bitmap
= g_malloc(size
);
428 } else if (size
> allocated_size
) {
429 d
.dirty_bitmap
= g_realloc(d
.dirty_bitmap
, size
);
431 allocated_size
= size
;
432 memset(d
.dirty_bitmap
, 0, allocated_size
);
436 if (kvm_vm_ioctl(s
, KVM_GET_DIRTY_LOG
, &d
) == -1) {
437 DPRINTF("ioctl failed %d\n", errno
);
442 kvm_get_dirty_pages_log_range(section
, d
.dirty_bitmap
);
443 start_addr
= mem
->start_addr
+ mem
->memory_size
;
445 g_free(d
.dirty_bitmap
);
450 int kvm_coalesce_mmio_region(target_phys_addr_t start
, ram_addr_t size
)
453 KVMState
*s
= kvm_state
;
455 if (s
->coalesced_mmio
) {
456 struct kvm_coalesced_mmio_zone zone
;
462 ret
= kvm_vm_ioctl(s
, KVM_REGISTER_COALESCED_MMIO
, &zone
);
468 int kvm_uncoalesce_mmio_region(target_phys_addr_t start
, ram_addr_t size
)
471 KVMState
*s
= kvm_state
;
473 if (s
->coalesced_mmio
) {
474 struct kvm_coalesced_mmio_zone zone
;
480 ret
= kvm_vm_ioctl(s
, KVM_UNREGISTER_COALESCED_MMIO
, &zone
);
486 int kvm_check_extension(KVMState
*s
, unsigned int extension
)
490 ret
= kvm_ioctl(s
, KVM_CHECK_EXTENSION
, extension
);
498 static int kvm_check_many_ioeventfds(void)
500 /* Userspace can use ioeventfd for io notification. This requires a host
501 * that supports eventfd(2) and an I/O thread; since eventfd does not
502 * support SIGIO it cannot interrupt the vcpu.
504 * Older kernels have a 6 device limit on the KVM io bus. Find out so we
505 * can avoid creating too many ioeventfds.
507 #if defined(CONFIG_EVENTFD)
510 for (i
= 0; i
< ARRAY_SIZE(ioeventfds
); i
++) {
511 ioeventfds
[i
] = eventfd(0, EFD_CLOEXEC
);
512 if (ioeventfds
[i
] < 0) {
515 ret
= kvm_set_ioeventfd_pio_word(ioeventfds
[i
], 0, i
, true);
517 close(ioeventfds
[i
]);
522 /* Decide whether many devices are supported or not */
523 ret
= i
== ARRAY_SIZE(ioeventfds
);
526 kvm_set_ioeventfd_pio_word(ioeventfds
[i
], 0, i
, false);
527 close(ioeventfds
[i
]);
535 static const KVMCapabilityInfo
*
536 kvm_check_extension_list(KVMState
*s
, const KVMCapabilityInfo
*list
)
539 if (!kvm_check_extension(s
, list
->value
)) {
547 static void kvm_set_phys_mem(MemoryRegionSection
*section
, bool add
)
549 KVMState
*s
= kvm_state
;
552 MemoryRegion
*mr
= section
->mr
;
553 bool log_dirty
= memory_region_is_logging(mr
);
554 target_phys_addr_t start_addr
= section
->offset_within_address_space
;
555 ram_addr_t size
= section
->size
;
559 /* kvm works in page size chunks, but the function may be called
560 with sub-page size and unaligned start address. */
561 delta
= TARGET_PAGE_ALIGN(size
) - size
;
567 size
&= TARGET_PAGE_MASK
;
568 if (!size
|| (start_addr
& ~TARGET_PAGE_MASK
)) {
572 if (!memory_region_is_ram(mr
)) {
576 ram
= memory_region_get_ram_ptr(mr
) + section
->offset_within_region
+ delta
;
579 mem
= kvm_lookup_overlapping_slot(s
, start_addr
, start_addr
+ size
);
584 if (add
&& start_addr
>= mem
->start_addr
&&
585 (start_addr
+ size
<= mem
->start_addr
+ mem
->memory_size
) &&
586 (ram
- start_addr
== mem
->ram
- mem
->start_addr
)) {
587 /* The new slot fits into the existing one and comes with
588 * identical parameters - update flags and done. */
589 kvm_slot_dirty_pages_log_change(mem
, log_dirty
);
595 if (mem
->flags
& KVM_MEM_LOG_DIRTY_PAGES
) {
596 kvm_physical_sync_dirty_bitmap(section
);
599 /* unregister the overlapping slot */
600 mem
->memory_size
= 0;
601 err
= kvm_set_user_memory_region(s
, mem
);
603 fprintf(stderr
, "%s: error unregistering overlapping slot: %s\n",
604 __func__
, strerror(-err
));
608 /* Workaround for older KVM versions: we can't join slots, even not by
609 * unregistering the previous ones and then registering the larger
610 * slot. We have to maintain the existing fragmentation. Sigh.
612 * This workaround assumes that the new slot starts at the same
613 * address as the first existing one. If not or if some overlapping
614 * slot comes around later, we will fail (not seen in practice so far)
615 * - and actually require a recent KVM version. */
616 if (s
->broken_set_mem_region
&&
617 old
.start_addr
== start_addr
&& old
.memory_size
< size
&& add
) {
618 mem
= kvm_alloc_slot(s
);
619 mem
->memory_size
= old
.memory_size
;
620 mem
->start_addr
= old
.start_addr
;
622 mem
->flags
= kvm_mem_flags(s
, log_dirty
);
624 err
= kvm_set_user_memory_region(s
, mem
);
626 fprintf(stderr
, "%s: error updating slot: %s\n", __func__
,
631 start_addr
+= old
.memory_size
;
632 ram
+= old
.memory_size
;
633 size
-= old
.memory_size
;
637 /* register prefix slot */
638 if (old
.start_addr
< start_addr
) {
639 mem
= kvm_alloc_slot(s
);
640 mem
->memory_size
= start_addr
- old
.start_addr
;
641 mem
->start_addr
= old
.start_addr
;
643 mem
->flags
= kvm_mem_flags(s
, log_dirty
);
645 err
= kvm_set_user_memory_region(s
, mem
);
647 fprintf(stderr
, "%s: error registering prefix slot: %s\n",
648 __func__
, strerror(-err
));
650 fprintf(stderr
, "%s: This is probably because your kernel's " \
651 "PAGE_SIZE is too big. Please try to use 4k " \
652 "PAGE_SIZE!\n", __func__
);
658 /* register suffix slot */
659 if (old
.start_addr
+ old
.memory_size
> start_addr
+ size
) {
660 ram_addr_t size_delta
;
662 mem
= kvm_alloc_slot(s
);
663 mem
->start_addr
= start_addr
+ size
;
664 size_delta
= mem
->start_addr
- old
.start_addr
;
665 mem
->memory_size
= old
.memory_size
- size_delta
;
666 mem
->ram
= old
.ram
+ size_delta
;
667 mem
->flags
= kvm_mem_flags(s
, log_dirty
);
669 err
= kvm_set_user_memory_region(s
, mem
);
671 fprintf(stderr
, "%s: error registering suffix slot: %s\n",
672 __func__
, strerror(-err
));
678 /* in case the KVM bug workaround already "consumed" the new slot */
685 mem
= kvm_alloc_slot(s
);
686 mem
->memory_size
= size
;
687 mem
->start_addr
= start_addr
;
689 mem
->flags
= kvm_mem_flags(s
, log_dirty
);
691 err
= kvm_set_user_memory_region(s
, mem
);
693 fprintf(stderr
, "%s: error registering slot: %s\n", __func__
,
699 static void kvm_begin(MemoryListener
*listener
)
703 static void kvm_commit(MemoryListener
*listener
)
707 static void kvm_region_add(MemoryListener
*listener
,
708 MemoryRegionSection
*section
)
710 kvm_set_phys_mem(section
, true);
713 static void kvm_region_del(MemoryListener
*listener
,
714 MemoryRegionSection
*section
)
716 kvm_set_phys_mem(section
, false);
719 static void kvm_region_nop(MemoryListener
*listener
,
720 MemoryRegionSection
*section
)
724 static void kvm_log_sync(MemoryListener
*listener
,
725 MemoryRegionSection
*section
)
729 r
= kvm_physical_sync_dirty_bitmap(section
);
735 static void kvm_log_global_start(struct MemoryListener
*listener
)
739 r
= kvm_set_migration_log(1);
743 static void kvm_log_global_stop(struct MemoryListener
*listener
)
747 r
= kvm_set_migration_log(0);
751 static void kvm_mem_ioeventfd_add(MemoryRegionSection
*section
,
752 bool match_data
, uint64_t data
, int fd
)
756 assert(match_data
&& section
->size
<= 8);
758 r
= kvm_set_ioeventfd_mmio(fd
, section
->offset_within_address_space
,
759 data
, true, section
->size
);
765 static void kvm_mem_ioeventfd_del(MemoryRegionSection
*section
,
766 bool match_data
, uint64_t data
, int fd
)
770 r
= kvm_set_ioeventfd_mmio(fd
, section
->offset_within_address_space
,
771 data
, false, section
->size
);
777 static void kvm_io_ioeventfd_add(MemoryRegionSection
*section
,
778 bool match_data
, uint64_t data
, int fd
)
782 assert(match_data
&& section
->size
== 2);
784 r
= kvm_set_ioeventfd_pio_word(fd
, section
->offset_within_address_space
,
791 static void kvm_io_ioeventfd_del(MemoryRegionSection
*section
,
792 bool match_data
, uint64_t data
, int fd
)
797 r
= kvm_set_ioeventfd_pio_word(fd
, section
->offset_within_address_space
,
804 static void kvm_eventfd_add(MemoryListener
*listener
,
805 MemoryRegionSection
*section
,
806 bool match_data
, uint64_t data
, int fd
)
808 if (section
->address_space
== get_system_memory()) {
809 kvm_mem_ioeventfd_add(section
, match_data
, data
, fd
);
811 kvm_io_ioeventfd_add(section
, match_data
, data
, fd
);
815 static void kvm_eventfd_del(MemoryListener
*listener
,
816 MemoryRegionSection
*section
,
817 bool match_data
, uint64_t data
, int fd
)
819 if (section
->address_space
== get_system_memory()) {
820 kvm_mem_ioeventfd_del(section
, match_data
, data
, fd
);
822 kvm_io_ioeventfd_del(section
, match_data
, data
, fd
);
826 static MemoryListener kvm_memory_listener
= {
828 .commit
= kvm_commit
,
829 .region_add
= kvm_region_add
,
830 .region_del
= kvm_region_del
,
831 .region_nop
= kvm_region_nop
,
832 .log_start
= kvm_log_start
,
833 .log_stop
= kvm_log_stop
,
834 .log_sync
= kvm_log_sync
,
835 .log_global_start
= kvm_log_global_start
,
836 .log_global_stop
= kvm_log_global_stop
,
837 .eventfd_add
= kvm_eventfd_add
,
838 .eventfd_del
= kvm_eventfd_del
,
842 static void kvm_handle_interrupt(CPUArchState
*env
, int mask
)
844 env
->interrupt_request
|= mask
;
846 if (!qemu_cpu_is_self(env
)) {
851 int kvm_irqchip_set_irq(KVMState
*s
, int irq
, int level
)
853 struct kvm_irq_level event
;
856 assert(kvm_irqchip_in_kernel());
860 ret
= kvm_vm_ioctl(s
, s
->irqchip_inject_ioctl
, &event
);
862 perror("kvm_set_irqchip_line");
866 return (s
->irqchip_inject_ioctl
== KVM_IRQ_LINE
) ? 1 : event
.status
;
869 #ifdef KVM_CAP_IRQ_ROUTING
870 static void set_gsi(KVMState
*s
, unsigned int gsi
)
872 s
->used_gsi_bitmap
[gsi
/ 32] |= 1U << (gsi
% 32);
875 static void clear_gsi(KVMState
*s
, unsigned int gsi
)
877 s
->used_gsi_bitmap
[gsi
/ 32] &= ~(1U << (gsi
% 32));
880 static void kvm_init_irq_routing(KVMState
*s
)
884 gsi_count
= kvm_check_extension(s
, KVM_CAP_IRQ_ROUTING
);
886 unsigned int gsi_bits
, i
;
888 /* Round up so we can search ints using ffs */
889 gsi_bits
= ALIGN(gsi_count
, 32);
890 s
->used_gsi_bitmap
= g_malloc0(gsi_bits
/ 8);
891 s
->gsi_count
= gsi_count
;
893 /* Mark any over-allocated bits as already in use */
894 for (i
= gsi_count
; i
< gsi_bits
; i
++) {
899 s
->irq_routes
= g_malloc0(sizeof(*s
->irq_routes
));
900 s
->nr_allocated_irq_routes
= 0;
902 if (!s
->direct_msi
) {
903 for (i
= 0; i
< KVM_MSI_HASHTAB_SIZE
; i
++) {
904 QTAILQ_INIT(&s
->msi_hashtab
[i
]);
908 kvm_arch_init_irq_routing(s
);
911 static void kvm_add_routing_entry(KVMState
*s
,
912 struct kvm_irq_routing_entry
*entry
)
914 struct kvm_irq_routing_entry
*new;
917 if (s
->irq_routes
->nr
== s
->nr_allocated_irq_routes
) {
918 n
= s
->nr_allocated_irq_routes
* 2;
922 size
= sizeof(struct kvm_irq_routing
);
923 size
+= n
* sizeof(*new);
924 s
->irq_routes
= g_realloc(s
->irq_routes
, size
);
925 s
->nr_allocated_irq_routes
= n
;
927 n
= s
->irq_routes
->nr
++;
928 new = &s
->irq_routes
->entries
[n
];
929 memset(new, 0, sizeof(*new));
930 new->gsi
= entry
->gsi
;
931 new->type
= entry
->type
;
932 new->flags
= entry
->flags
;
935 set_gsi(s
, entry
->gsi
);
938 void kvm_irqchip_add_route(KVMState
*s
, int irq
, int irqchip
, int pin
)
940 struct kvm_irq_routing_entry e
;
942 assert(pin
< s
->gsi_count
);
945 e
.type
= KVM_IRQ_ROUTING_IRQCHIP
;
947 e
.u
.irqchip
.irqchip
= irqchip
;
948 e
.u
.irqchip
.pin
= pin
;
949 kvm_add_routing_entry(s
, &e
);
952 int kvm_irqchip_commit_routes(KVMState
*s
)
954 s
->irq_routes
->flags
= 0;
955 return kvm_vm_ioctl(s
, KVM_SET_GSI_ROUTING
, s
->irq_routes
);
958 static void kvm_irqchip_release_virq(KVMState
*s
, int virq
)
960 struct kvm_irq_routing_entry
*e
;
963 for (i
= 0; i
< s
->irq_routes
->nr
; i
++) {
964 e
= &s
->irq_routes
->entries
[i
];
965 if (e
->gsi
== virq
) {
967 *e
= s
->irq_routes
->entries
[s
->irq_routes
->nr
];
973 static unsigned int kvm_hash_msi(uint32_t data
)
975 /* This is optimized for IA32 MSI layout. However, no other arch shall
976 * repeat the mistake of not providing a direct MSI injection API. */
980 static void kvm_flush_dynamic_msi_routes(KVMState
*s
)
982 KVMMSIRoute
*route
, *next
;
985 for (hash
= 0; hash
< KVM_MSI_HASHTAB_SIZE
; hash
++) {
986 QTAILQ_FOREACH_SAFE(route
, &s
->msi_hashtab
[hash
], entry
, next
) {
987 kvm_irqchip_release_virq(s
, route
->kroute
.gsi
);
988 QTAILQ_REMOVE(&s
->msi_hashtab
[hash
], route
, entry
);
994 static int kvm_irqchip_get_virq(KVMState
*s
)
996 uint32_t *word
= s
->used_gsi_bitmap
;
997 int max_words
= ALIGN(s
->gsi_count
, 32) / 32;
1002 /* Return the lowest unused GSI in the bitmap */
1003 for (i
= 0; i
< max_words
; i
++) {
1004 bit
= ffs(~word
[i
]);
1009 return bit
- 1 + i
* 32;
1011 if (!s
->direct_msi
&& retry
) {
1013 kvm_flush_dynamic_msi_routes(s
);
1020 static KVMMSIRoute
*kvm_lookup_msi_route(KVMState
*s
, MSIMessage msg
)
1022 unsigned int hash
= kvm_hash_msi(msg
.data
);
1025 QTAILQ_FOREACH(route
, &s
->msi_hashtab
[hash
], entry
) {
1026 if (route
->kroute
.u
.msi
.address_lo
== (uint32_t)msg
.address
&&
1027 route
->kroute
.u
.msi
.address_hi
== (msg
.address
>> 32) &&
1028 route
->kroute
.u
.msi
.data
== msg
.data
) {
1035 int kvm_irqchip_send_msi(KVMState
*s
, MSIMessage msg
)
1040 if (s
->direct_msi
) {
1041 msi
.address_lo
= (uint32_t)msg
.address
;
1042 msi
.address_hi
= msg
.address
>> 32;
1043 msi
.data
= msg
.data
;
1045 memset(msi
.pad
, 0, sizeof(msi
.pad
));
1047 return kvm_vm_ioctl(s
, KVM_SIGNAL_MSI
, &msi
);
1050 route
= kvm_lookup_msi_route(s
, msg
);
1054 virq
= kvm_irqchip_get_virq(s
);
1059 route
= g_malloc(sizeof(KVMMSIRoute
));
1060 route
->kroute
.gsi
= virq
;
1061 route
->kroute
.type
= KVM_IRQ_ROUTING_MSI
;
1062 route
->kroute
.flags
= 0;
1063 route
->kroute
.u
.msi
.address_lo
= (uint32_t)msg
.address
;
1064 route
->kroute
.u
.msi
.address_hi
= msg
.address
>> 32;
1065 route
->kroute
.u
.msi
.data
= msg
.data
;
1067 kvm_add_routing_entry(s
, &route
->kroute
);
1069 QTAILQ_INSERT_TAIL(&s
->msi_hashtab
[kvm_hash_msi(msg
.data
)], route
,
1072 ret
= kvm_irqchip_commit_routes(s
);
1078 assert(route
->kroute
.type
== KVM_IRQ_ROUTING_MSI
);
1080 return kvm_irqchip_set_irq(s
, route
->kroute
.gsi
, 1);
1083 #else /* !KVM_CAP_IRQ_ROUTING */
1085 static void kvm_init_irq_routing(KVMState
*s
)
1089 int kvm_irqchip_send_msi(KVMState
*s
, MSIMessage msg
)
1093 #endif /* !KVM_CAP_IRQ_ROUTING */
1095 static int kvm_irqchip_create(KVMState
*s
)
1097 QemuOptsList
*list
= qemu_find_opts("machine");
1100 if (QTAILQ_EMPTY(&list
->head
) ||
1101 !qemu_opt_get_bool(QTAILQ_FIRST(&list
->head
),
1102 "kernel_irqchip", false) ||
1103 !kvm_check_extension(s
, KVM_CAP_IRQCHIP
)) {
1107 ret
= kvm_vm_ioctl(s
, KVM_CREATE_IRQCHIP
);
1109 fprintf(stderr
, "Create kernel irqchip failed\n");
1113 s
->irqchip_inject_ioctl
= KVM_IRQ_LINE
;
1114 if (kvm_check_extension(s
, KVM_CAP_IRQ_INJECT_STATUS
)) {
1115 s
->irqchip_inject_ioctl
= KVM_IRQ_LINE_STATUS
;
1117 kvm_kernel_irqchip
= true;
1119 kvm_init_irq_routing(s
);
1126 static const char upgrade_note
[] =
1127 "Please upgrade to at least kernel 2.6.29 or recent kvm-kmod\n"
1128 "(see http://sourceforge.net/projects/kvm).\n";
1130 const KVMCapabilityInfo
*missing_cap
;
1134 s
= g_malloc0(sizeof(KVMState
));
1137 * On systems where the kernel can support different base page
1138 * sizes, host page size may be different from TARGET_PAGE_SIZE,
1139 * even with KVM. TARGET_PAGE_SIZE is assumed to be the minimum
1140 * page size for the system though.
1142 assert(TARGET_PAGE_SIZE
<= getpagesize());
1144 #ifdef KVM_CAP_SET_GUEST_DEBUG
1145 QTAILQ_INIT(&s
->kvm_sw_breakpoints
);
1147 for (i
= 0; i
< ARRAY_SIZE(s
->slots
); i
++) {
1148 s
->slots
[i
].slot
= i
;
1151 s
->fd
= qemu_open("/dev/kvm", O_RDWR
);
1153 fprintf(stderr
, "Could not access KVM kernel module: %m\n");
1158 ret
= kvm_ioctl(s
, KVM_GET_API_VERSION
, 0);
1159 if (ret
< KVM_API_VERSION
) {
1163 fprintf(stderr
, "kvm version too old\n");
1167 if (ret
> KVM_API_VERSION
) {
1169 fprintf(stderr
, "kvm version not supported\n");
1173 s
->vmfd
= kvm_ioctl(s
, KVM_CREATE_VM
, 0);
1176 fprintf(stderr
, "Please add the 'switch_amode' kernel parameter to "
1177 "your host kernel command line\n");
1183 missing_cap
= kvm_check_extension_list(s
, kvm_required_capabilites
);
1186 kvm_check_extension_list(s
, kvm_arch_required_capabilities
);
1190 fprintf(stderr
, "kvm does not support %s\n%s",
1191 missing_cap
->name
, upgrade_note
);
1195 s
->coalesced_mmio
= kvm_check_extension(s
, KVM_CAP_COALESCED_MMIO
);
1197 s
->broken_set_mem_region
= 1;
1198 ret
= kvm_check_extension(s
, KVM_CAP_JOIN_MEMORY_REGIONS_WORKS
);
1200 s
->broken_set_mem_region
= 0;
1203 #ifdef KVM_CAP_VCPU_EVENTS
1204 s
->vcpu_events
= kvm_check_extension(s
, KVM_CAP_VCPU_EVENTS
);
1207 s
->robust_singlestep
=
1208 kvm_check_extension(s
, KVM_CAP_X86_ROBUST_SINGLESTEP
);
1210 #ifdef KVM_CAP_DEBUGREGS
1211 s
->debugregs
= kvm_check_extension(s
, KVM_CAP_DEBUGREGS
);
1214 #ifdef KVM_CAP_XSAVE
1215 s
->xsave
= kvm_check_extension(s
, KVM_CAP_XSAVE
);
1219 s
->xcrs
= kvm_check_extension(s
, KVM_CAP_XCRS
);
1222 #ifdef KVM_CAP_PIT_STATE2
1223 s
->pit_state2
= kvm_check_extension(s
, KVM_CAP_PIT_STATE2
);
1226 s
->direct_msi
= (kvm_check_extension(s
, KVM_CAP_SIGNAL_MSI
) > 0);
1228 ret
= kvm_arch_init(s
);
1233 ret
= kvm_irqchip_create(s
);
1239 memory_listener_register(&kvm_memory_listener
, NULL
);
1241 s
->many_ioeventfds
= kvm_check_many_ioeventfds();
1243 cpu_interrupt_handler
= kvm_handle_interrupt
;
1261 static void kvm_handle_io(uint16_t port
, void *data
, int direction
, int size
,
1265 uint8_t *ptr
= data
;
1267 for (i
= 0; i
< count
; i
++) {
1268 if (direction
== KVM_EXIT_IO_IN
) {
1271 stb_p(ptr
, cpu_inb(port
));
1274 stw_p(ptr
, cpu_inw(port
));
1277 stl_p(ptr
, cpu_inl(port
));
1283 cpu_outb(port
, ldub_p(ptr
));
1286 cpu_outw(port
, lduw_p(ptr
));
1289 cpu_outl(port
, ldl_p(ptr
));
1298 static int kvm_handle_internal_error(CPUArchState
*env
, struct kvm_run
*run
)
1300 fprintf(stderr
, "KVM internal error.");
1301 if (kvm_check_extension(kvm_state
, KVM_CAP_INTERNAL_ERROR_DATA
)) {
1304 fprintf(stderr
, " Suberror: %d\n", run
->internal
.suberror
);
1305 for (i
= 0; i
< run
->internal
.ndata
; ++i
) {
1306 fprintf(stderr
, "extra data[%d]: %"PRIx64
"\n",
1307 i
, (uint64_t)run
->internal
.data
[i
]);
1310 fprintf(stderr
, "\n");
1312 if (run
->internal
.suberror
== KVM_INTERNAL_ERROR_EMULATION
) {
1313 fprintf(stderr
, "emulation failure\n");
1314 if (!kvm_arch_stop_on_emulation_error(env
)) {
1315 cpu_dump_state(env
, stderr
, fprintf
, CPU_DUMP_CODE
);
1316 return EXCP_INTERRUPT
;
1319 /* FIXME: Should trigger a qmp message to let management know
1320 * something went wrong.
1325 void kvm_flush_coalesced_mmio_buffer(void)
1327 KVMState
*s
= kvm_state
;
1329 if (s
->coalesced_flush_in_progress
) {
1333 s
->coalesced_flush_in_progress
= true;
1335 if (s
->coalesced_mmio_ring
) {
1336 struct kvm_coalesced_mmio_ring
*ring
= s
->coalesced_mmio_ring
;
1337 while (ring
->first
!= ring
->last
) {
1338 struct kvm_coalesced_mmio
*ent
;
1340 ent
= &ring
->coalesced_mmio
[ring
->first
];
1342 cpu_physical_memory_write(ent
->phys_addr
, ent
->data
, ent
->len
);
1344 ring
->first
= (ring
->first
+ 1) % KVM_COALESCED_MMIO_MAX
;
1348 s
->coalesced_flush_in_progress
= false;
1351 static void do_kvm_cpu_synchronize_state(void *_env
)
1353 CPUArchState
*env
= _env
;
1355 if (!env
->kvm_vcpu_dirty
) {
1356 kvm_arch_get_registers(env
);
1357 env
->kvm_vcpu_dirty
= 1;
1361 void kvm_cpu_synchronize_state(CPUArchState
*env
)
1363 if (!env
->kvm_vcpu_dirty
) {
1364 run_on_cpu(env
, do_kvm_cpu_synchronize_state
, env
);
1368 void kvm_cpu_synchronize_post_reset(CPUArchState
*env
)
1370 kvm_arch_put_registers(env
, KVM_PUT_RESET_STATE
);
1371 env
->kvm_vcpu_dirty
= 0;
1374 void kvm_cpu_synchronize_post_init(CPUArchState
*env
)
1376 kvm_arch_put_registers(env
, KVM_PUT_FULL_STATE
);
1377 env
->kvm_vcpu_dirty
= 0;
1380 int kvm_cpu_exec(CPUArchState
*env
)
1382 struct kvm_run
*run
= env
->kvm_run
;
1385 DPRINTF("kvm_cpu_exec()\n");
1387 if (kvm_arch_process_async_events(env
)) {
1388 env
->exit_request
= 0;
1393 if (env
->kvm_vcpu_dirty
) {
1394 kvm_arch_put_registers(env
, KVM_PUT_RUNTIME_STATE
);
1395 env
->kvm_vcpu_dirty
= 0;
1398 kvm_arch_pre_run(env
, run
);
1399 if (env
->exit_request
) {
1400 DPRINTF("interrupt exit requested\n");
1402 * KVM requires us to reenter the kernel after IO exits to complete
1403 * instruction emulation. This self-signal will ensure that we
1406 qemu_cpu_kick_self();
1408 qemu_mutex_unlock_iothread();
1410 run_ret
= kvm_vcpu_ioctl(env
, KVM_RUN
, 0);
1412 qemu_mutex_lock_iothread();
1413 kvm_arch_post_run(env
, run
);
1415 kvm_flush_coalesced_mmio_buffer();
1418 if (run_ret
== -EINTR
|| run_ret
== -EAGAIN
) {
1419 DPRINTF("io window exit\n");
1420 ret
= EXCP_INTERRUPT
;
1423 fprintf(stderr
, "error: kvm run failed %s\n",
1424 strerror(-run_ret
));
1428 switch (run
->exit_reason
) {
1430 DPRINTF("handle_io\n");
1431 kvm_handle_io(run
->io
.port
,
1432 (uint8_t *)run
+ run
->io
.data_offset
,
1439 DPRINTF("handle_mmio\n");
1440 cpu_physical_memory_rw(run
->mmio
.phys_addr
,
1443 run
->mmio
.is_write
);
1446 case KVM_EXIT_IRQ_WINDOW_OPEN
:
1447 DPRINTF("irq_window_open\n");
1448 ret
= EXCP_INTERRUPT
;
1450 case KVM_EXIT_SHUTDOWN
:
1451 DPRINTF("shutdown\n");
1452 qemu_system_reset_request();
1453 ret
= EXCP_INTERRUPT
;
1455 case KVM_EXIT_UNKNOWN
:
1456 fprintf(stderr
, "KVM: unknown exit, hardware reason %" PRIx64
"\n",
1457 (uint64_t)run
->hw
.hardware_exit_reason
);
1460 case KVM_EXIT_INTERNAL_ERROR
:
1461 ret
= kvm_handle_internal_error(env
, run
);
1464 DPRINTF("kvm_arch_handle_exit\n");
1465 ret
= kvm_arch_handle_exit(env
, run
);
1471 cpu_dump_state(env
, stderr
, fprintf
, CPU_DUMP_CODE
);
1472 vm_stop(RUN_STATE_INTERNAL_ERROR
);
1475 env
->exit_request
= 0;
1479 int kvm_ioctl(KVMState
*s
, int type
, ...)
1486 arg
= va_arg(ap
, void *);
1489 ret
= ioctl(s
->fd
, type
, arg
);
1496 int kvm_vm_ioctl(KVMState
*s
, int type
, ...)
1503 arg
= va_arg(ap
, void *);
1506 ret
= ioctl(s
->vmfd
, type
, arg
);
1513 int kvm_vcpu_ioctl(CPUArchState
*env
, int type
, ...)
1520 arg
= va_arg(ap
, void *);
1523 ret
= ioctl(env
->kvm_fd
, type
, arg
);
1530 int kvm_has_sync_mmu(void)
1532 return kvm_check_extension(kvm_state
, KVM_CAP_SYNC_MMU
);
1535 int kvm_has_vcpu_events(void)
1537 return kvm_state
->vcpu_events
;
1540 int kvm_has_robust_singlestep(void)
1542 return kvm_state
->robust_singlestep
;
1545 int kvm_has_debugregs(void)
1547 return kvm_state
->debugregs
;
1550 int kvm_has_xsave(void)
1552 return kvm_state
->xsave
;
1555 int kvm_has_xcrs(void)
1557 return kvm_state
->xcrs
;
1560 int kvm_has_pit_state2(void)
1562 return kvm_state
->pit_state2
;
1565 int kvm_has_many_ioeventfds(void)
1567 if (!kvm_enabled()) {
1570 return kvm_state
->many_ioeventfds
;
1573 int kvm_has_gsi_routing(void)
1575 #ifdef KVM_CAP_IRQ_ROUTING
1576 return kvm_check_extension(kvm_state
, KVM_CAP_IRQ_ROUTING
);
1582 int kvm_allows_irq0_override(void)
1584 return !kvm_irqchip_in_kernel() || kvm_has_gsi_routing();
1587 void kvm_setup_guest_memory(void *start
, size_t size
)
1589 if (!kvm_has_sync_mmu()) {
1590 int ret
= qemu_madvise(start
, size
, QEMU_MADV_DONTFORK
);
1593 perror("qemu_madvise");
1595 "Need MADV_DONTFORK in absence of synchronous KVM MMU\n");
1601 #ifdef KVM_CAP_SET_GUEST_DEBUG
1602 struct kvm_sw_breakpoint
*kvm_find_sw_breakpoint(CPUArchState
*env
,
1605 struct kvm_sw_breakpoint
*bp
;
1607 QTAILQ_FOREACH(bp
, &env
->kvm_state
->kvm_sw_breakpoints
, entry
) {
1615 int kvm_sw_breakpoints_active(CPUArchState
*env
)
1617 return !QTAILQ_EMPTY(&env
->kvm_state
->kvm_sw_breakpoints
);
1620 struct kvm_set_guest_debug_data
{
1621 struct kvm_guest_debug dbg
;
1626 static void kvm_invoke_set_guest_debug(void *data
)
1628 struct kvm_set_guest_debug_data
*dbg_data
= data
;
1629 CPUArchState
*env
= dbg_data
->env
;
1631 dbg_data
->err
= kvm_vcpu_ioctl(env
, KVM_SET_GUEST_DEBUG
, &dbg_data
->dbg
);
1634 int kvm_update_guest_debug(CPUArchState
*env
, unsigned long reinject_trap
)
1636 struct kvm_set_guest_debug_data data
;
1638 data
.dbg
.control
= reinject_trap
;
1640 if (env
->singlestep_enabled
) {
1641 data
.dbg
.control
|= KVM_GUESTDBG_ENABLE
| KVM_GUESTDBG_SINGLESTEP
;
1643 kvm_arch_update_guest_debug(env
, &data
.dbg
);
1646 run_on_cpu(env
, kvm_invoke_set_guest_debug
, &data
);
1650 int kvm_insert_breakpoint(CPUArchState
*current_env
, target_ulong addr
,
1651 target_ulong len
, int type
)
1653 struct kvm_sw_breakpoint
*bp
;
1657 if (type
== GDB_BREAKPOINT_SW
) {
1658 bp
= kvm_find_sw_breakpoint(current_env
, addr
);
1664 bp
= g_malloc(sizeof(struct kvm_sw_breakpoint
));
1671 err
= kvm_arch_insert_sw_breakpoint(current_env
, bp
);
1677 QTAILQ_INSERT_HEAD(¤t_env
->kvm_state
->kvm_sw_breakpoints
,
1680 err
= kvm_arch_insert_hw_breakpoint(addr
, len
, type
);
1686 for (env
= first_cpu
; env
!= NULL
; env
= env
->next_cpu
) {
1687 err
= kvm_update_guest_debug(env
, 0);
1695 int kvm_remove_breakpoint(CPUArchState
*current_env
, target_ulong addr
,
1696 target_ulong len
, int type
)
1698 struct kvm_sw_breakpoint
*bp
;
1702 if (type
== GDB_BREAKPOINT_SW
) {
1703 bp
= kvm_find_sw_breakpoint(current_env
, addr
);
1708 if (bp
->use_count
> 1) {
1713 err
= kvm_arch_remove_sw_breakpoint(current_env
, bp
);
1718 QTAILQ_REMOVE(¤t_env
->kvm_state
->kvm_sw_breakpoints
, bp
, entry
);
1721 err
= kvm_arch_remove_hw_breakpoint(addr
, len
, type
);
1727 for (env
= first_cpu
; env
!= NULL
; env
= env
->next_cpu
) {
1728 err
= kvm_update_guest_debug(env
, 0);
1736 void kvm_remove_all_breakpoints(CPUArchState
*current_env
)
1738 struct kvm_sw_breakpoint
*bp
, *next
;
1739 KVMState
*s
= current_env
->kvm_state
;
1742 QTAILQ_FOREACH_SAFE(bp
, &s
->kvm_sw_breakpoints
, entry
, next
) {
1743 if (kvm_arch_remove_sw_breakpoint(current_env
, bp
) != 0) {
1744 /* Try harder to find a CPU that currently sees the breakpoint. */
1745 for (env
= first_cpu
; env
!= NULL
; env
= env
->next_cpu
) {
1746 if (kvm_arch_remove_sw_breakpoint(env
, bp
) == 0) {
1752 kvm_arch_remove_all_hw_breakpoints();
1754 for (env
= first_cpu
; env
!= NULL
; env
= env
->next_cpu
) {
1755 kvm_update_guest_debug(env
, 0);
1759 #else /* !KVM_CAP_SET_GUEST_DEBUG */
1761 int kvm_update_guest_debug(CPUArchState
*env
, unsigned long reinject_trap
)
1766 int kvm_insert_breakpoint(CPUArchState
*current_env
, target_ulong addr
,
1767 target_ulong len
, int type
)
1772 int kvm_remove_breakpoint(CPUArchState
*current_env
, target_ulong addr
,
1773 target_ulong len
, int type
)
1778 void kvm_remove_all_breakpoints(CPUArchState
*current_env
)
1781 #endif /* !KVM_CAP_SET_GUEST_DEBUG */
1783 int kvm_set_signal_mask(CPUArchState
*env
, const sigset_t
*sigset
)
1785 struct kvm_signal_mask
*sigmask
;
1789 return kvm_vcpu_ioctl(env
, KVM_SET_SIGNAL_MASK
, NULL
);
1792 sigmask
= g_malloc(sizeof(*sigmask
) + sizeof(*sigset
));
1795 memcpy(sigmask
->sigset
, sigset
, sizeof(*sigset
));
1796 r
= kvm_vcpu_ioctl(env
, KVM_SET_SIGNAL_MASK
, sigmask
);
1802 int kvm_set_ioeventfd_mmio(int fd
, uint32_t addr
, uint32_t val
, bool assign
,
1806 struct kvm_ioeventfd iofd
;
1808 iofd
.datamatch
= val
;
1811 iofd
.flags
= KVM_IOEVENTFD_FLAG_DATAMATCH
;
1814 if (!kvm_enabled()) {
1819 iofd
.flags
|= KVM_IOEVENTFD_FLAG_DEASSIGN
;
1822 ret
= kvm_vm_ioctl(kvm_state
, KVM_IOEVENTFD
, &iofd
);
1831 int kvm_set_ioeventfd_pio_word(int fd
, uint16_t addr
, uint16_t val
, bool assign
)
1833 struct kvm_ioeventfd kick
= {
1837 .flags
= KVM_IOEVENTFD_FLAG_DATAMATCH
| KVM_IOEVENTFD_FLAG_PIO
,
1841 if (!kvm_enabled()) {
1845 kick
.flags
|= KVM_IOEVENTFD_FLAG_DEASSIGN
;
1847 r
= kvm_vm_ioctl(kvm_state
, KVM_IOEVENTFD
, &kick
);
1854 int kvm_on_sigbus_vcpu(CPUArchState
*env
, int code
, void *addr
)
1856 return kvm_arch_on_sigbus_vcpu(env
, code
, addr
);
1859 int kvm_on_sigbus(int code
, void *addr
)
1861 return kvm_arch_on_sigbus(code
, addr
);