kvm_int.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /*
  2. * Internal definitions for a target's KVM support
  3. *
  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.
  6. *
  7. */
  8. #ifndef QEMU_KVM_INT_H
  9. #define QEMU_KVM_INT_H
  10. #include "exec/memory.h"
  11. #include "qapi/qapi-types-common.h"
  12. #include "qemu/accel.h"
  13. #include "qemu/queue.h"
  14. #include "system/kvm.h"
  15. #include "hw/boards.h"
  16. #include "hw/i386/topology.h"
  17. #include "io/channel-socket.h"
  18. typedef struct KVMSlot
  19. {
  20. hwaddr start_addr;
  21. ram_addr_t memory_size;
  22. void *ram;
  23. int slot;
  24. int flags;
  25. int old_flags;
  26. /* Dirty bitmap cache for the slot */
  27. unsigned long *dirty_bmap;
  28. unsigned long dirty_bmap_size;
  29. /* Cache of the address space ID */
  30. int as_id;
  31. /* Cache of the offset in ram address space */
  32. ram_addr_t ram_start_offset;
  33. int guest_memfd;
  34. hwaddr guest_memfd_offset;
  35. } KVMSlot;
  36. typedef struct KVMMemoryUpdate {
  37. QSIMPLEQ_ENTRY(KVMMemoryUpdate) next;
  38. MemoryRegionSection section;
  39. } KVMMemoryUpdate;
  40. typedef struct KVMMemoryListener {
  41. MemoryListener listener;
  42. KVMSlot *slots;
  43. unsigned int nr_slots_used;
  44. unsigned int nr_slots_allocated;
  45. int as_id;
  46. QSIMPLEQ_HEAD(, KVMMemoryUpdate) transaction_add;
  47. QSIMPLEQ_HEAD(, KVMMemoryUpdate) transaction_del;
  48. } KVMMemoryListener;
  49. #define KVM_MSI_HASHTAB_SIZE 256
  50. typedef struct KVMHostTopoInfo {
  51. /* Number of package on the Host */
  52. unsigned int maxpkgs;
  53. /* Number of cpus on the Host */
  54. unsigned int maxcpus;
  55. /* Number of cpus on each different package */
  56. unsigned int *pkg_cpu_count;
  57. /* Each package can have different maxticks */
  58. unsigned int *maxticks;
  59. } KVMHostTopoInfo;
  60. struct KVMMsrEnergy {
  61. pid_t pid;
  62. bool enable;
  63. char *socket_path;
  64. QIOChannelSocket *sioc;
  65. QemuThread msr_thr;
  66. unsigned int guest_vcpus;
  67. unsigned int guest_vsockets;
  68. X86CPUTopoInfo guest_topo_info;
  69. KVMHostTopoInfo host_topo;
  70. const CPUArchIdList *guest_cpu_list;
  71. uint64_t *msr_value;
  72. uint64_t msr_unit;
  73. uint64_t msr_limit;
  74. uint64_t msr_info;
  75. };
  76. enum KVMDirtyRingReaperState {
  77. KVM_DIRTY_RING_REAPER_NONE = 0,
  78. /* The reaper is sleeping */
  79. KVM_DIRTY_RING_REAPER_WAIT,
  80. /* The reaper is reaping for dirty pages */
  81. KVM_DIRTY_RING_REAPER_REAPING,
  82. };
  83. /*
  84. * KVM reaper instance, responsible for collecting the KVM dirty bits
  85. * via the dirty ring.
  86. */
  87. struct KVMDirtyRingReaper {
  88. /* The reaper thread */
  89. QemuThread reaper_thr;
  90. volatile uint64_t reaper_iteration; /* iteration number of reaper thr */
  91. volatile enum KVMDirtyRingReaperState reaper_state; /* reap thr state */
  92. };
  93. struct KVMState
  94. {
  95. AccelState parent_obj;
  96. /* Max number of KVM slots supported */
  97. int nr_slots_max;
  98. int fd;
  99. int vmfd;
  100. int coalesced_mmio;
  101. int coalesced_pio;
  102. struct kvm_coalesced_mmio_ring *coalesced_mmio_ring;
  103. bool coalesced_flush_in_progress;
  104. int vcpu_events;
  105. #ifdef TARGET_KVM_HAVE_GUEST_DEBUG
  106. QTAILQ_HEAD(, kvm_sw_breakpoint) kvm_sw_breakpoints;
  107. #endif
  108. int max_nested_state_len;
  109. int kvm_shadow_mem;
  110. bool kernel_irqchip_allowed;
  111. bool kernel_irqchip_required;
  112. OnOffAuto kernel_irqchip_split;
  113. bool sync_mmu;
  114. bool guest_state_protected;
  115. uint64_t manual_dirty_log_protect;
  116. /*
  117. * Older POSIX says that ioctl numbers are signed int, but in
  118. * practice they are not. (Newer POSIX doesn't specify ioctl
  119. * at all.) Linux, glibc and *BSD all treat ioctl numbers as
  120. * unsigned, and real-world ioctl values like KVM_GET_XSAVE have
  121. * bit 31 set, which means that passing them via an 'int' will
  122. * result in sign-extension when they get converted back to the
  123. * 'unsigned long' which the ioctl() prototype uses. Luckily Linux
  124. * always treats the argument as an unsigned 32-bit int, so any
  125. * possible sign-extension is deliberately ignored, but for
  126. * consistency we keep to the same type that glibc is using.
  127. */
  128. unsigned long irq_set_ioctl;
  129. unsigned int sigmask_len;
  130. GHashTable *gsimap;
  131. #ifdef KVM_CAP_IRQ_ROUTING
  132. struct kvm_irq_routing *irq_routes;
  133. int nr_allocated_irq_routes;
  134. unsigned long *used_gsi_bitmap;
  135. unsigned int gsi_count;
  136. #endif
  137. KVMMemoryListener memory_listener;
  138. QLIST_HEAD(, KVMParkedVcpu) kvm_parked_vcpus;
  139. /* For "info mtree -f" to tell if an MR is registered in KVM */
  140. int nr_as;
  141. struct KVMAs {
  142. KVMMemoryListener *ml;
  143. AddressSpace *as;
  144. } *as;
  145. uint64_t kvm_dirty_ring_bytes; /* Size of the per-vcpu dirty ring */
  146. uint32_t kvm_dirty_ring_size; /* Number of dirty GFNs per ring */
  147. bool kvm_dirty_ring_with_bitmap;
  148. uint64_t kvm_eager_split_size; /* Eager Page Splitting chunk size */
  149. struct KVMDirtyRingReaper reaper;
  150. struct KVMMsrEnergy msr_energy;
  151. NotifyVmexitOption notify_vmexit;
  152. uint32_t notify_window;
  153. uint32_t xen_version;
  154. uint32_t xen_caps;
  155. uint16_t xen_gnttab_max_frames;
  156. uint16_t xen_evtchn_max_pirq;
  157. char *device;
  158. };
  159. void kvm_memory_listener_register(KVMState *s, KVMMemoryListener *kml,
  160. AddressSpace *as, int as_id, const char *name);
  161. void kvm_set_max_memslot_size(hwaddr max_slot_size);
  162. /**
  163. * kvm_hwpoison_page_add:
  164. *
  165. * Parameters:
  166. * @ram_addr: the address in the RAM for the poisoned page
  167. *
  168. * Add a poisoned page to the list
  169. *
  170. * Return: None.
  171. */
  172. void kvm_hwpoison_page_add(ram_addr_t ram_addr);
  173. #endif