9 #include <asm/ptrace.h>
15 #define __user /* temporary, until installed via make headers_install */
18 #include <linux/kvm.h>
22 /* FIXME: share this number with kvm */
23 /* FIXME: or dynamically alloc/realloc regions */
25 #define KVM_MAX_NUM_MEM_REGIONS 1u
27 #define LIBKVM_S390_ORIGIN (0UL)
28 #elif defined(__ia64__)
29 #define KVM_MAX_NUM_MEM_REGIONS 32u
32 #define KVM_MAX_NUM_MEM_REGIONS 32u
36 /* kvm abi verison variable */
40 * \brief The KVM context
42 * The verbose KVM context
46 /// Filedescriptor to /dev/kvm
49 /// Callbacks that KVM uses to emulate various unvirtualizable functionality
50 struct kvm_callbacks
*callbacks
;
52 /// is dirty pages logging enabled for all regions or not
53 int dirty_pages_log_all
;
54 /// do not create in-kernel irqchip if set
55 int no_irqchip_creation
;
56 /// in-kernel irqchip status
57 int irqchip_in_kernel
;
58 /// ioctl to use to inject interrupts
59 int irqchip_inject_ioctl
;
60 /// do not create in-kernel pit if set
62 /// in-kernel pit status
64 /// in-kernel coalesced mmio
66 #ifdef KVM_CAP_IRQ_ROUTING
67 struct kvm_irq_routing
*irq_routes
;
68 int nr_allocated_irq_routes
;
70 void *used_gsi_bitmap
;
74 struct kvm_vcpu_context
78 struct kvm_context
*kvm
;
82 typedef struct kvm_context
*kvm_context_t
;
83 typedef struct kvm_vcpu_context
*kvm_vcpu_context_t
;
86 int kvm_alloc_kernel_memory(kvm_context_t kvm
, unsigned long memory
,
88 int kvm_alloc_userspace_memory(kvm_context_t kvm
, unsigned long memory
,
91 int kvm_arch_create(kvm_context_t kvm
, unsigned long phys_mem_bytes
,
93 int kvm_arch_run(kvm_vcpu_context_t vcpu
);
96 void kvm_show_code(kvm_vcpu_context_t vcpu
);
98 int handle_halt(kvm_vcpu_context_t vcpu
);
99 int handle_shutdown(kvm_context_t kvm
, void *env
);
100 void post_kvm_run(kvm_context_t kvm
, void *env
);
101 int pre_kvm_run(kvm_context_t kvm
, void *env
);
102 int handle_io_window(kvm_context_t kvm
);
103 int handle_debug(kvm_vcpu_context_t vcpu
, void *env
);
104 int try_push_interrupts(kvm_context_t kvm
);
107 #if defined(__x86_64__) || defined(__i386__)
108 struct kvm_msr_list
*kvm_get_msr_list(kvm_context_t
);
109 int kvm_get_msrs(kvm_vcpu_context_t
, struct kvm_msr_entry
*msrs
, int n
);
110 int kvm_set_msrs(kvm_vcpu_context_t
, struct kvm_msr_entry
*msrs
, int n
);
114 * \brief KVM callbacks structure
116 * This structure holds pointers to various functions that KVM will call
117 * when it encounters something that cannot be virtualized, such as
118 * accessing hardware devices via MMIO or regular IO.
120 struct kvm_callbacks
{
121 /// For 8bit IO reads from the guest (Usually when executing 'inb')
122 int (*inb
)(void *opaque
, uint16_t addr
, uint8_t *data
);
123 /// For 16bit IO reads from the guest (Usually when executing 'inw')
124 int (*inw
)(void *opaque
, uint16_t addr
, uint16_t *data
);
125 /// For 32bit IO reads from the guest (Usually when executing 'inl')
126 int (*inl
)(void *opaque
, uint16_t addr
, uint32_t *data
);
127 /// For 8bit IO writes from the guest (Usually when executing 'outb')
128 int (*outb
)(void *opaque
, uint16_t addr
, uint8_t data
);
129 /// For 16bit IO writes from the guest (Usually when executing 'outw')
130 int (*outw
)(void *opaque
, uint16_t addr
, uint16_t data
);
131 /// For 32bit IO writes from the guest (Usually when executing 'outl')
132 int (*outl
)(void *opaque
, uint16_t addr
, uint32_t data
);
133 /// generic memory reads to unmapped memory (For MMIO devices)
134 int (*mmio_read
)(void *opaque
, uint64_t addr
, uint8_t *data
,
136 /// generic memory writes to unmapped memory (For MMIO devices)
137 int (*mmio_write
)(void *opaque
, uint64_t addr
, uint8_t *data
,
139 #ifdef KVM_CAP_SET_GUEST_DEBUG
140 int (*debug
)(void *opaque
, void *env
,
141 struct kvm_debug_exit_arch
*arch_info
);
144 * \brief Called when the VCPU issues an 'hlt' instruction.
146 * Typically, you should yeild here to prevent 100% CPU utilization
149 int (*halt
)(void *opaque
, kvm_vcpu_context_t vcpu
);
150 int (*shutdown
)(void *opaque
, void *env
);
151 int (*io_window
)(void *opaque
);
152 int (*try_push_interrupts
)(void *opaque
);
153 #ifdef KVM_CAP_USER_NMI
154 void (*push_nmi
)(void *opaque
);
156 void (*post_kvm_run
)(void *opaque
, void *env
);
157 int (*pre_kvm_run
)(void *opaque
, void *env
);
158 int (*tpr_access
)(void *opaque
, kvm_vcpu_context_t vcpu
, uint64_t rip
, int is_write
);
159 #if defined(__powerpc__)
160 int (*powerpc_dcr_read
)(kvm_vcpu_context_t vcpu
, uint32_t dcrn
, uint32_t *data
);
161 int (*powerpc_dcr_write
)(kvm_vcpu_context_t vcpu
, uint32_t dcrn
, uint32_t data
);
163 #if defined(__s390__)
164 int (*s390_handle_intercept
)(kvm_context_t context
, kvm_vcpu_context_t vcpu
,
165 struct kvm_run
*run
);
166 int (*s390_handle_reset
)(kvm_context_t context
, kvm_vcpu_context_t vcpu
,
167 struct kvm_run
*run
);
169 int (*unhandled
)(kvm_context_t context
, kvm_vcpu_context_t vcpu
,
174 * \brief Create new KVM context
176 * This creates a new kvm_context. A KVM context is a small area of data that
177 * holds information about the KVM instance that gets created by this call.\n
178 * This should always be your first call to KVM.
180 * \param callbacks Pointer to a valid kvm_callbacks structure
181 * \param opaque Not used
182 * \return NULL on failure
184 kvm_context_t
kvm_init(struct kvm_callbacks
*callbacks
,
188 * \brief Cleanup the KVM context
190 * Should always be called when closing down KVM.\n
191 * Exception: If kvm_init() fails, this function should not be called, as the
192 * context would be invalid
194 * \param kvm Pointer to the kvm_context that is to be freed
196 void kvm_finalize(kvm_context_t kvm
);
199 * \brief Disable the in-kernel IRQCHIP creation
201 * In-kernel irqchip is enabled by default. If userspace irqchip is to be used,
202 * this should be called prior to kvm_create().
204 * \param kvm Pointer to the kvm_context
206 void kvm_disable_irqchip_creation(kvm_context_t kvm
);
209 * \brief Disable the in-kernel PIT creation
211 * In-kernel pit is enabled by default. If userspace pit is to be used,
212 * this should be called prior to kvm_create().
214 * \param kvm Pointer to the kvm_context
216 void kvm_disable_pit_creation(kvm_context_t kvm
);
219 * \brief Create new virtual machine
221 * This creates a new virtual machine, maps physical RAM to it, and creates a
222 * virtual CPU for it.\n
224 * Memory gets mapped for addresses 0->0xA0000, 0xC0000->phys_mem_bytes
226 * \param kvm Pointer to the current kvm_context
227 * \param phys_mem_bytes The amount of physical ram you want the VM to have
228 * \param phys_mem This pointer will be set to point to the memory that
229 * kvm_create allocates for physical RAM
230 * \return 0 on success
232 int kvm_create(kvm_context_t kvm
,
233 unsigned long phys_mem_bytes
,
235 int kvm_create_vm(kvm_context_t kvm
);
236 int kvm_check_extension(kvm_context_t kvm
, int ext
);
237 void kvm_create_irqchip(kvm_context_t kvm
);
240 * \brief Create a new virtual cpu
242 * This creates a new virtual cpu (the first vcpu is created by kvm_create()).
243 * Should be called from a thread dedicated to the vcpu.
245 * \param kvm kvm context
246 * \param slot vcpu number (> 0)
247 * \return 0 on success, -errno on failure
249 kvm_vcpu_context_t
kvm_create_vcpu(kvm_context_t kvm
, int id
);
252 * \brief Start the VCPU
254 * This starts the VCPU and virtualization is started.\n
256 * This function will not return until any of these conditions are met:
257 * - An IO/MMIO handler does not return "0"
258 * - An exception that neither the guest OS, nor KVM can handle occurs
260 * \note This function will call the callbacks registered in kvm_init()
261 * to emulate those functions
262 * \note If you at any point want to interrupt the VCPU, kvm_run() will
263 * listen to the EINTR signal. This allows you to simulate external interrupts
264 * and asyncronous IO.
266 * \param kvm Pointer to the current kvm_context
267 * \param vcpu Which virtual CPU should be started
268 * \return 0 on success, but you really shouldn't expect this function to
269 * return except for when an error has occured, or when you have sent it
272 int kvm_run(kvm_vcpu_context_t vcpu
, void *env
);
275 * \brief Get interrupt flag from on last exit to userspace
277 * This gets the CPU interrupt flag as it was on the last exit to userspace.
279 * \param kvm Pointer to the current kvm_context
280 * \param vcpu Which virtual CPU should get dumped
281 * \return interrupt flag value (0 or 1)
283 int kvm_get_interrupt_flag(kvm_vcpu_context_t vcpu
);
286 * \brief Get the value of the APIC_BASE msr as of last exit to userspace
288 * This gets the APIC_BASE msr as it was on the last exit to userspace.
290 * \param kvm Pointer to the current kvm_context
291 * \param vcpu Which virtual CPU should get dumped
292 * \return APIC_BASE msr contents
294 uint64_t kvm_get_apic_base(kvm_vcpu_context_t vcpu
);
297 * \brief Check if a vcpu is ready for interrupt injection
299 * This checks if vcpu interrupts are not masked by mov ss or sti.
301 * \param kvm Pointer to the current kvm_context
302 * \param vcpu Which virtual CPU should get dumped
303 * \return boolean indicating interrupt injection readiness
305 int kvm_is_ready_for_interrupt_injection(kvm_vcpu_context_t vcpu
);
308 * \brief Read VCPU registers
310 * This gets the GP registers from the VCPU and outputs them
311 * into a kvm_regs structure
313 * \note This function returns a \b copy of the VCPUs registers.\n
314 * If you wish to modify the VCPUs GP registers, you should call kvm_set_regs()
316 * \param kvm Pointer to the current kvm_context
317 * \param vcpu Which virtual CPU should get dumped
318 * \param regs Pointer to a kvm_regs which will be populated with the VCPUs
320 * \return 0 on success
322 int kvm_get_regs(kvm_vcpu_context_t vcpu
, struct kvm_regs
*regs
);
325 * \brief Write VCPU registers
327 * This sets the GP registers on the VCPU from a kvm_regs structure
329 * \note When this function returns, the regs pointer and the data it points to
331 * \param kvm Pointer to the current kvm_context
332 * \param vcpu Which virtual CPU should get dumped
333 * \param regs Pointer to a kvm_regs which will be populated with the VCPUs
335 * \return 0 on success
337 int kvm_set_regs(kvm_vcpu_context_t vcpu
, struct kvm_regs
*regs
);
339 * \brief Read VCPU fpu registers
341 * This gets the FPU registers from the VCPU and outputs them
342 * into a kvm_fpu structure
344 * \note This function returns a \b copy of the VCPUs registers.\n
345 * If you wish to modify the VCPU FPU registers, you should call kvm_set_fpu()
347 * \param kvm Pointer to the current kvm_context
348 * \param vcpu Which virtual CPU should get dumped
349 * \param fpu Pointer to a kvm_fpu which will be populated with the VCPUs
350 * fpu registers values
351 * \return 0 on success
353 int kvm_get_fpu(kvm_vcpu_context_t vcpu
, struct kvm_fpu
*fpu
);
356 * \brief Write VCPU fpu registers
358 * This sets the FPU registers on the VCPU from a kvm_fpu structure
360 * \note When this function returns, the fpu pointer and the data it points to
362 * \param kvm Pointer to the current kvm_context
363 * \param vcpu Which virtual CPU should get dumped
364 * \param fpu Pointer to a kvm_fpu which holds the new vcpu fpu state
365 * \return 0 on success
367 int kvm_set_fpu(kvm_vcpu_context_t vcpu
, struct kvm_fpu
*fpu
);
370 * \brief Read VCPU system registers
372 * This gets the non-GP registers from the VCPU and outputs them
373 * into a kvm_sregs structure
375 * \note This function returns a \b copy of the VCPUs registers.\n
376 * If you wish to modify the VCPUs non-GP registers, you should call
379 * \param kvm Pointer to the current kvm_context
380 * \param vcpu Which virtual CPU should get dumped
381 * \param regs Pointer to a kvm_sregs which will be populated with the VCPUs
383 * \return 0 on success
385 int kvm_get_sregs(kvm_vcpu_context_t vcpu
, struct kvm_sregs
*regs
);
388 * \brief Write VCPU system registers
390 * This sets the non-GP registers on the VCPU from a kvm_sregs structure
392 * \note When this function returns, the regs pointer and the data it points to
394 * \param kvm Pointer to the current kvm_context
395 * \param vcpu Which virtual CPU should get dumped
396 * \param regs Pointer to a kvm_sregs which will be populated with the VCPUs
398 * \return 0 on success
400 int kvm_set_sregs(kvm_vcpu_context_t vcpu
, struct kvm_sregs
*regs
);
402 #ifdef KVM_CAP_MP_STATE
404 * * \brief Read VCPU MP state
407 int kvm_get_mpstate(kvm_vcpu_context_t vcpu
, struct kvm_mp_state
*mp_state
);
410 * * \brief Write VCPU MP state
413 int kvm_set_mpstate(kvm_vcpu_context_t vcpu
, struct kvm_mp_state
*mp_state
);
415 * * \brief Reset VCPU MP state
418 static inline int kvm_reset_mpstate(kvm_vcpu_context_t vcpu
)
420 struct kvm_mp_state mp_state
= {.mp_state
= KVM_MP_STATE_UNINITIALIZED
};
421 return kvm_set_mpstate(vcpu
, &mp_state
);
426 * \brief Simulate an external vectored interrupt
428 * This allows you to simulate an external vectored interrupt.
430 * \param kvm Pointer to the current kvm_context
431 * \param vcpu Which virtual CPU should get dumped
432 * \param irq Vector number
433 * \return 0 on success
435 int kvm_inject_irq(kvm_vcpu_context_t vcpu
, unsigned irq
);
437 #ifdef KVM_CAP_SET_GUEST_DEBUG
438 int kvm_set_guest_debug(kvm_vcpu_context_t
, struct kvm_guest_debug
*dbg
);
441 #if defined(__i386__) || defined(__x86_64__)
443 * \brief Setup a vcpu's cpuid instruction emulation
445 * Set up a table of cpuid function to cpuid outputs.\n
447 * \param kvm Pointer to the current kvm_context
448 * \param vcpu Which virtual CPU should be initialized
449 * \param nent number of entries to be installed
450 * \param entries cpuid function entries table
451 * \return 0 on success, or -errno on error
453 int kvm_setup_cpuid(kvm_vcpu_context_t vcpu
, int nent
,
454 struct kvm_cpuid_entry
*entries
);
457 * \brief Setup a vcpu's cpuid instruction emulation
459 * Set up a table of cpuid function to cpuid outputs.
460 * This call replaces the older kvm_setup_cpuid interface by adding a few
461 * parameters to support cpuid functions that have sub-leaf values.
463 * \param kvm Pointer to the current kvm_context
464 * \param vcpu Which virtual CPU should be initialized
465 * \param nent number of entries to be installed
466 * \param entries cpuid function entries table
467 * \return 0 on success, or -errno on error
469 int kvm_setup_cpuid2(kvm_vcpu_context_t vcpu
, int nent
,
470 struct kvm_cpuid_entry2
*entries
);
473 * \brief Setting the number of shadow pages to be allocated to the vm
475 * \param kvm pointer to kvm_context
476 * \param nrshadow_pages number of pages to be allocated
478 int kvm_set_shadow_pages(kvm_context_t kvm
, unsigned int nrshadow_pages
);
481 * \brief Getting the number of shadow pages that are allocated to the vm
483 * \param kvm pointer to kvm_context
484 * \param nrshadow_pages number of pages to be allocated
486 int kvm_get_shadow_pages(kvm_context_t kvm
, unsigned int *nrshadow_pages
);
489 * \brief Set up cr8 for next time the vcpu is executed
491 * This is a fast setter for cr8, which will be applied when the
492 * vcpu next enters guest mode.
494 * \param kvm Pointer to the current kvm_context
495 * \param vcpu Which virtual CPU should get dumped
496 * \param cr8 next cr8 value
498 void kvm_set_cr8(kvm_vcpu_context_t vcpu
, uint64_t cr8
);
501 * \brief Get cr8 for sync tpr in qemu apic emulation
503 * This is a getter for cr8, which used to sync with the tpr in qemu
506 * \param kvm Pointer to the current kvm_context
507 * \param vcpu Which virtual CPU should get dumped
509 __u64
kvm_get_cr8(kvm_vcpu_context_t vcpu
);
513 * \brief Set a vcpu's signal mask for guest mode
515 * A vcpu can have different signals blocked in guest mode and user mode.
516 * This allows guest execution to be interrupted on a signal, without requiring
517 * that the signal be delivered to a signal handler (the signal can be
518 * dequeued using sigwait(2).
520 * \param kvm Pointer to the current kvm_context
521 * \param vcpu Which virtual CPU should be initialized
522 * \param sigset signal mask for guest mode
523 * \return 0 on success, or -errno on error
525 int kvm_set_signal_mask(kvm_vcpu_context_t vcpu
, const sigset_t
*sigset
);
528 * \brief Dump VCPU registers
530 * This dumps some of the information that KVM has about a virtual CPU, namely:
533 * A much more verbose version of this is available as kvm_dump_vcpu()
535 * \param kvm Pointer to the current kvm_context
536 * \param vcpu Which virtual CPU should get dumped
537 * \return 0 on success
539 void kvm_show_regs(kvm_vcpu_context_t vcpu
);
542 void *kvm_create_phys_mem(kvm_context_t
, unsigned long phys_start
,
543 unsigned long len
, int log
, int writable
);
544 void kvm_destroy_phys_mem(kvm_context_t
, unsigned long phys_start
,
546 void kvm_unregister_memory_area(kvm_context_t
, uint64_t phys_start
,
549 int kvm_is_containing_region(kvm_context_t kvm
, unsigned long phys_start
, unsigned long size
);
550 int kvm_register_phys_mem(kvm_context_t kvm
,
551 unsigned long phys_start
, void *userspace_addr
,
552 unsigned long len
, int log
);
553 int kvm_get_dirty_pages(kvm_context_t
, unsigned long phys_addr
, void *buf
);
554 int kvm_get_dirty_pages_range(kvm_context_t kvm
, unsigned long phys_addr
,
555 unsigned long end_addr
, void *buf
, void*opaque
,
556 int (*cb
)(unsigned long start
, unsigned long len
,
557 void*bitmap
, void *opaque
));
558 int kvm_register_coalesced_mmio(kvm_context_t kvm
,
559 uint64_t addr
, uint32_t size
);
560 int kvm_unregister_coalesced_mmio(kvm_context_t kvm
,
561 uint64_t addr
, uint32_t size
);
564 * \brief Create a memory alias
566 * Aliases a portion of physical memory to another portion. If the guest
567 * accesses the alias region, it will behave exactly as if it accessed
570 int kvm_create_memory_alias(kvm_context_t
,
571 uint64_t phys_start
, uint64_t len
,
572 uint64_t target_phys
);
575 * \brief Destroy a memory alias
577 * Removes an alias created with kvm_create_memory_alias().
579 int kvm_destroy_memory_alias(kvm_context_t
, uint64_t phys_start
);
582 * \brief Get a bitmap of guest ram pages which are allocated to the guest.
584 * \param kvm Pointer to the current kvm_context
585 * \param phys_addr Memory slot phys addr
586 * \param bitmap Long aligned address of a big enough bitmap (one bit per page)
588 int kvm_get_mem_map(kvm_context_t kvm
, unsigned long phys_addr
, void *bitmap
);
589 int kvm_get_mem_map_range(kvm_context_t kvm
, unsigned long phys_addr
,
590 unsigned long len
, void *buf
, void *opaque
,
591 int (*cb
)(unsigned long start
,unsigned long len
,
592 void* bitmap
, void* opaque
));
593 int kvm_set_irq_level(kvm_context_t kvm
, int irq
, int level
, int *status
);
595 int kvm_dirty_pages_log_enable_slot(kvm_context_t kvm
,
598 int kvm_dirty_pages_log_disable_slot(kvm_context_t kvm
,
602 * \brief Enable dirty-pages-logging for all memory regions
604 * \param kvm Pointer to the current kvm_context
606 int kvm_dirty_pages_log_enable_all(kvm_context_t kvm
);
609 * \brief Disable dirty-page-logging for some memory regions
611 * Disable dirty-pages-logging for those memory regions that were
612 * created with dirty-page-logging disabled.
614 * \param kvm Pointer to the current kvm_context
616 int kvm_dirty_pages_log_reset(kvm_context_t kvm
);
619 * \brief Query whether in kernel irqchip is used
621 * \param kvm Pointer to the current kvm_context
623 int kvm_irqchip_in_kernel(kvm_context_t kvm
);
625 int kvm_has_sync_mmu(kvm_context_t kvm
);
627 #ifdef KVM_CAP_IRQCHIP
629 * \brief Dump in kernel IRQCHIP contents
631 * Dump one of the in kernel irq chip devices, including PIC (master/slave)
632 * and IOAPIC into a kvm_irqchip structure
634 * \param kvm Pointer to the current kvm_context
635 * \param chip The irq chip device to be dumped
637 int kvm_get_irqchip(kvm_context_t kvm
, struct kvm_irqchip
*chip
);
640 * \brief Set in kernel IRQCHIP contents
642 * Write one of the in kernel irq chip devices, including PIC (master/slave)
646 * \param kvm Pointer to the current kvm_context
647 * \param chip THe irq chip device to be written
649 int kvm_set_irqchip(kvm_context_t kvm
, struct kvm_irqchip
*chip
);
651 #if defined(__i386__) || defined(__x86_64__)
653 * \brief Get in kernel local APIC for vcpu
655 * Save the local apic state including the timer of a virtual CPU
657 * \param kvm Pointer to the current kvm_context
658 * \param vcpu Which virtual CPU should be accessed
659 * \param s Local apic state of the specific virtual CPU
661 int kvm_get_lapic(kvm_vcpu_context_t vcpu
, struct kvm_lapic_state
*s
);
664 * \brief Set in kernel local APIC for vcpu
666 * Restore the local apic state including the timer of a virtual CPU
668 * \param kvm Pointer to the current kvm_context
669 * \param vcpu Which virtual CPU should be accessed
670 * \param s Local apic state of the specific virtual CPU
672 int kvm_set_lapic(kvm_vcpu_context_t vcpu
, struct kvm_lapic_state
*s
);
677 * \brief Simulate an NMI
679 * This allows you to simulate a non-maskable interrupt.
681 * \param kvm Pointer to the current kvm_context
682 * \param vcpu Which virtual CPU should get dumped
683 * \return 0 on success
685 int kvm_inject_nmi(kvm_vcpu_context_t vcpu
);
690 * \brief Query wheather in kernel pit is used
692 * \param kvm Pointer to the current kvm_context
694 int kvm_pit_in_kernel(kvm_context_t kvm
);
697 * \brief Initialize coalesced MMIO
699 * Check for coalesced MMIO capability and store in context
701 * \param kvm Pointer to the current kvm_context
703 int kvm_init_coalesced_mmio(kvm_context_t kvm
);
707 #if defined(__i386__) || defined(__x86_64__)
709 * \brief Get in kernel PIT of the virtual domain
711 * Save the PIT state.
713 * \param kvm Pointer to the current kvm_context
714 * \param s PIT state of the virtual domain
716 int kvm_get_pit(kvm_context_t kvm
, struct kvm_pit_state
*s
);
719 * \brief Set in kernel PIT of the virtual domain
721 * Restore the PIT state.
722 * Timer would be retriggerred after restored.
724 * \param kvm Pointer to the current kvm_context
725 * \param s PIT state of the virtual domain
727 int kvm_set_pit(kvm_context_t kvm
, struct kvm_pit_state
*s
);
730 int kvm_reinject_control(kvm_context_t kvm
, int pit_reinject
);
737 * \brief Enable kernel tpr access reporting
739 * When tpr access reporting is enabled, the kernel will call the
740 * ->tpr_access() callback every time the guest vcpu accesses the tpr.
742 * \param kvm Pointer to the current kvm_context
743 * \param vcpu vcpu to enable tpr access reporting on
745 int kvm_enable_tpr_access_reporting(kvm_vcpu_context_t vcpu
);
748 * \brief Disable kernel tpr access reporting
750 * Undoes the effect of kvm_enable_tpr_access_reporting().
752 * \param kvm Pointer to the current kvm_context
753 * \param vcpu vcpu to disable tpr access reporting on
755 int kvm_disable_tpr_access_reporting(kvm_vcpu_context_t vcpu
);
757 int kvm_enable_vapic(kvm_vcpu_context_t vcpu
, uint64_t vapic
);
761 #if defined(__s390__)
762 int kvm_s390_initial_reset(kvm_context_t kvm
, int slot
);
763 int kvm_s390_interrupt(kvm_context_t kvm
, int slot
,
764 struct kvm_s390_interrupt
*kvmint
);
765 int kvm_s390_set_initial_psw(kvm_context_t kvm
, int slot
, psw_t psw
);
766 int kvm_s390_store_status(kvm_context_t kvm
, int slot
, unsigned long addr
);
769 #ifdef KVM_CAP_DEVICE_ASSIGNMENT
771 * \brief Notifies host kernel about a PCI device to be assigned to a guest
773 * Used for PCI device assignment, this function notifies the host
774 * kernel about the assigning of the physical PCI device to a guest.
776 * \param kvm Pointer to the current kvm_context
777 * \param assigned_dev Parameters, like bus, devfn number, etc
779 int kvm_assign_pci_device(kvm_context_t kvm
,
780 struct kvm_assigned_pci_dev
*assigned_dev
);
783 * \brief Assign IRQ for an assigned device
785 * Used for PCI device assignment, this function assigns IRQ numbers for
786 * an physical device and guest IRQ handling.
788 * \param kvm Pointer to the current kvm_context
789 * \param assigned_irq Parameters, like dev id, host irq, guest irq, etc
791 int kvm_assign_irq(kvm_context_t kvm
,
792 struct kvm_assigned_irq
*assigned_irq
);
794 #ifdef KVM_CAP_ASSIGN_DEV_IRQ
796 * \brief Deassign IRQ for an assigned device
798 * Used for PCI device assignment, this function deassigns IRQ numbers
799 * for an assigned device.
801 * \param kvm Pointer to the current kvm_context
802 * \param assigned_irq Parameters, like dev id, host irq, guest irq, etc
804 int kvm_deassign_irq(kvm_context_t kvm
,
805 struct kvm_assigned_irq
*assigned_irq
);
810 * \brief Determines whether destroying memory regions is allowed
812 * KVM before 2.6.29 had a bug when destroying memory regions.
814 * \param kvm Pointer to the current kvm_context
816 int kvm_destroy_memory_region_works(kvm_context_t kvm
);
818 #ifdef KVM_CAP_DEVICE_DEASSIGNMENT
820 * \brief Notifies host kernel about a PCI device to be deassigned from a guest
822 * Used for hot remove PCI device, this function notifies the host
823 * kernel about the deassigning of the physical PCI device from a guest.
825 * \param kvm Pointer to the current kvm_context
826 * \param assigned_dev Parameters, like bus, devfn number, etc
828 int kvm_deassign_pci_device(kvm_context_t kvm
,
829 struct kvm_assigned_pci_dev
*assigned_dev
);
833 * \brief Checks whether the generic irq routing capability is present
835 * Checks whether kvm can reroute interrupts among the various interrupt
838 * \param kvm Pointer to the current kvm_context
840 int kvm_has_gsi_routing(kvm_context_t kvm
);
843 * \brief Determines the number of gsis that can be routed
845 * Returns the number of distinct gsis that can be routed by kvm. This is
846 * also the number of distinct routes (if a gsi has two routes, than another
847 * gsi cannot be used...)
849 * \param kvm Pointer to the current kvm_context
851 int kvm_get_gsi_count(kvm_context_t kvm
);
854 * \brief Clears the temporary irq routing table
856 * Clears the temporary irq routing table. Nothing is committed to the
859 * \param kvm Pointer to the current kvm_context
861 int kvm_clear_gsi_routes(kvm_context_t kvm
);
864 * \brief Adds an irq route to the temporary irq routing table
866 * Adds an irq route to the temporary irq routing table. Nothing is
867 * committed to the running VM.
869 * \param kvm Pointer to the current kvm_context
871 int kvm_add_irq_route(kvm_context_t kvm
, int gsi
, int irqchip
, int pin
);
874 * \brief Removes an irq route from the temporary irq routing table
876 * Adds an irq route to the temporary irq routing table. Nothing is
877 * committed to the running VM.
879 * \param kvm Pointer to the current kvm_context
881 int kvm_del_irq_route(kvm_context_t kvm
, int gsi
, int irqchip
, int pin
);
883 struct kvm_irq_routing_entry
;
885 * \brief Adds a routing entry to the temporary irq routing table
887 * Adds a filled routing entry to the temporary irq routing table. Nothing is
888 * committed to the running VM.
890 * \param kvm Pointer to the current kvm_context
892 int kvm_add_routing_entry(kvm_context_t kvm
,
893 struct kvm_irq_routing_entry
* entry
);
896 * \brief Removes a routing from the temporary irq routing table
898 * Remove a routing to the temporary irq routing table. Nothing is
899 * committed to the running VM.
901 * \param kvm Pointer to the current kvm_context
903 int kvm_del_routing_entry(kvm_context_t kvm
,
904 struct kvm_irq_routing_entry
* entry
);
907 * \brief Commit the temporary irq routing table
909 * Commit the temporary irq routing table to the running VM.
911 * \param kvm Pointer to the current kvm_context
913 int kvm_commit_irq_routes(kvm_context_t kvm
);
916 * \brief Get unused GSI number for irq routing table
918 * Get unused GSI number for irq routing table
920 * \param kvm Pointer to the current kvm_context
922 int kvm_get_irq_route_gsi(kvm_context_t kvm
);
925 * \brief Create a file descriptor for injecting interrupts
927 * Creates an eventfd based file-descriptor that maps to a specific GSI
928 * in the guest. eventfd compliant signaling (write() from userspace, or
929 * eventfd_signal() from kernelspace) will cause the GSI to inject
930 * itself into the guest at the next available window.
932 * \param kvm Pointer to the current kvm_context
933 * \param gsi GSI to assign to this fd
934 * \param flags reserved, must be zero
936 int kvm_irqfd(kvm_context_t kvm
, int gsi
, int flags
);
938 #ifdef KVM_CAP_DEVICE_MSIX
939 int kvm_assign_set_msix_nr(kvm_context_t kvm
,
940 struct kvm_assigned_msix_nr
*msix_nr
);
941 int kvm_assign_set_msix_entry(kvm_context_t kvm
,
942 struct kvm_assigned_msix_entry
*entry
);
945 uint32_t kvm_get_supported_cpuid(kvm_context_t kvm
, uint32_t function
, int reg
);