2 * Internal definitions for a target's KVM support
4 * This work is licensed under the terms of the GNU GPL, version 2 or later.
5 * See the COPYING file in the top-level directory.
10 #define QEMU_KVM_INT_H
12 #include "exec/memory.h"
13 #include "qapi/qapi-types-common.h"
14 #include "qemu/accel.h"
15 #include "qemu/queue.h"
16 #include "sysemu/kvm.h"
17 #include "hw/boards.h"
18 #include "hw/i386/topology.h"
19 #include "io/channel-socket.h"
21 typedef struct KVMSlot
24 ram_addr_t memory_size
;
29 /* Dirty bitmap cache for the slot */
30 unsigned long *dirty_bmap
;
31 unsigned long dirty_bmap_size
;
32 /* Cache of the address space ID */
34 /* Cache of the offset in ram address space */
35 ram_addr_t ram_start_offset
;
37 hwaddr guest_memfd_offset
;
40 typedef struct KVMMemoryUpdate
{
41 QSIMPLEQ_ENTRY(KVMMemoryUpdate
) next
;
42 MemoryRegionSection section
;
45 typedef struct KVMMemoryListener
{
46 MemoryListener listener
;
48 unsigned int nr_used_slots
;
50 QSIMPLEQ_HEAD(, KVMMemoryUpdate
) transaction_add
;
51 QSIMPLEQ_HEAD(, KVMMemoryUpdate
) transaction_del
;
54 #define KVM_MSI_HASHTAB_SIZE 256
56 typedef struct KVMHostTopoInfo
{
57 /* Number of package on the Host */
59 /* Number of cpus on the Host */
61 /* Number of cpus on each different package */
62 unsigned int *pkg_cpu_count
;
63 /* Each package can have different maxticks */
64 unsigned int *maxticks
;
71 QIOChannelSocket
*sioc
;
73 unsigned int guest_vcpus
;
74 unsigned int guest_vsockets
;
75 X86CPUTopoInfo guest_topo_info
;
76 KVMHostTopoInfo host_topo
;
77 const CPUArchIdList
*guest_cpu_list
;
84 enum KVMDirtyRingReaperState
{
85 KVM_DIRTY_RING_REAPER_NONE
= 0,
86 /* The reaper is sleeping */
87 KVM_DIRTY_RING_REAPER_WAIT
,
88 /* The reaper is reaping for dirty pages */
89 KVM_DIRTY_RING_REAPER_REAPING
,
93 * KVM reaper instance, responsible for collecting the KVM dirty bits
96 struct KVMDirtyRingReaper
{
97 /* The reaper thread */
98 QemuThread reaper_thr
;
99 volatile uint64_t reaper_iteration
; /* iteration number of reaper thr */
100 volatile enum KVMDirtyRingReaperState reaper_state
; /* reap thr state */
104 AccelState parent_obj
;
111 struct kvm_coalesced_mmio_ring
*coalesced_mmio_ring
;
112 bool coalesced_flush_in_progress
;
114 #ifdef TARGET_KVM_HAVE_GUEST_DEBUG
115 QTAILQ_HEAD(, kvm_sw_breakpoint
) kvm_sw_breakpoints
;
117 int max_nested_state_len
;
119 bool kernel_irqchip_allowed
;
120 bool kernel_irqchip_required
;
121 OnOffAuto kernel_irqchip_split
;
123 bool guest_state_protected
;
124 uint64_t manual_dirty_log_protect
;
126 * Older POSIX says that ioctl numbers are signed int, but in
127 * practice they are not. (Newer POSIX doesn't specify ioctl
128 * at all.) Linux, glibc and *BSD all treat ioctl numbers as
129 * unsigned, and real-world ioctl values like KVM_GET_XSAVE have
130 * bit 31 set, which means that passing them via an 'int' will
131 * result in sign-extension when they get converted back to the
132 * 'unsigned long' which the ioctl() prototype uses. Luckily Linux
133 * always treats the argument as an unsigned 32-bit int, so any
134 * possible sign-extension is deliberately ignored, but for
135 * consistency we keep to the same type that glibc is using.
137 unsigned long irq_set_ioctl
;
138 unsigned int sigmask_len
;
140 #ifdef KVM_CAP_IRQ_ROUTING
141 struct kvm_irq_routing
*irq_routes
;
142 int nr_allocated_irq_routes
;
143 unsigned long *used_gsi_bitmap
;
144 unsigned int gsi_count
;
146 KVMMemoryListener memory_listener
;
147 QLIST_HEAD(, KVMParkedVcpu
) kvm_parked_vcpus
;
149 /* For "info mtree -f" to tell if an MR is registered in KVM */
152 KVMMemoryListener
*ml
;
155 uint64_t kvm_dirty_ring_bytes
; /* Size of the per-vcpu dirty ring */
156 uint32_t kvm_dirty_ring_size
; /* Number of dirty GFNs per ring */
157 bool kvm_dirty_ring_with_bitmap
;
158 uint64_t kvm_eager_split_size
; /* Eager Page Splitting chunk size */
159 struct KVMDirtyRingReaper reaper
;
160 struct KVMMsrEnergy msr_energy
;
161 NotifyVmexitOption notify_vmexit
;
162 uint32_t notify_window
;
163 uint32_t xen_version
;
165 uint16_t xen_gnttab_max_frames
;
166 uint16_t xen_evtchn_max_pirq
;
170 void kvm_memory_listener_register(KVMState
*s
, KVMMemoryListener
*kml
,
171 AddressSpace
*as
, int as_id
, const char *name
);
173 void kvm_set_max_memslot_size(hwaddr max_slot_size
);
176 * kvm_hwpoison_page_add:
179 * @ram_addr: the address in the RAM for the poisoned page
181 * Add a poisoned page to the list
185 void kvm_hwpoison_page_add(ram_addr_t ram_addr
);