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(__s390__)
160 int (*s390_handle_intercept
)(kvm_context_t context
, kvm_vcpu_context_t vcpu
,
161 struct kvm_run
*run
);
162 int (*s390_handle_reset
)(kvm_context_t context
, kvm_vcpu_context_t vcpu
,
163 struct kvm_run
*run
);
165 int (*unhandled
)(kvm_context_t context
, kvm_vcpu_context_t vcpu
,
170 * \brief Create new KVM context
172 * This creates a new kvm_context. A KVM context is a small area of data that
173 * holds information about the KVM instance that gets created by this call.\n
174 * This should always be your first call to KVM.
176 * \param callbacks Pointer to a valid kvm_callbacks structure
177 * \param opaque Not used
178 * \return NULL on failure
180 kvm_context_t
kvm_init(struct kvm_callbacks
*callbacks
,
184 * \brief Cleanup the KVM context
186 * Should always be called when closing down KVM.\n
187 * Exception: If kvm_init() fails, this function should not be called, as the
188 * context would be invalid
190 * \param kvm Pointer to the kvm_context that is to be freed
192 void kvm_finalize(kvm_context_t kvm
);
195 * \brief Disable the in-kernel IRQCHIP creation
197 * In-kernel irqchip is enabled by default. If userspace irqchip is to be used,
198 * this should be called prior to kvm_create().
200 * \param kvm Pointer to the kvm_context
202 void kvm_disable_irqchip_creation(kvm_context_t kvm
);
205 * \brief Disable the in-kernel PIT creation
207 * In-kernel pit is enabled by default. If userspace pit is to be used,
208 * this should be called prior to kvm_create().
210 * \param kvm Pointer to the kvm_context
212 void kvm_disable_pit_creation(kvm_context_t kvm
);
215 * \brief Create new virtual machine
217 * This creates a new virtual machine, maps physical RAM to it, and creates a
218 * virtual CPU for it.\n
220 * Memory gets mapped for addresses 0->0xA0000, 0xC0000->phys_mem_bytes
222 * \param kvm Pointer to the current kvm_context
223 * \param phys_mem_bytes The amount of physical ram you want the VM to have
224 * \param phys_mem This pointer will be set to point to the memory that
225 * kvm_create allocates for physical RAM
226 * \return 0 on success
228 int kvm_create(kvm_context_t kvm
,
229 unsigned long phys_mem_bytes
,
231 int kvm_create_vm(kvm_context_t kvm
);
232 int kvm_check_extension(kvm_context_t kvm
, int ext
);
233 void kvm_create_irqchip(kvm_context_t kvm
);
236 * \brief Create a new virtual cpu
238 * This creates a new virtual cpu (the first vcpu is created by kvm_create()).
239 * Should be called from a thread dedicated to the vcpu.
241 * \param kvm kvm context
242 * \param slot vcpu number (> 0)
243 * \return 0 on success, -errno on failure
245 kvm_vcpu_context_t
kvm_create_vcpu(kvm_context_t kvm
, int id
);
248 * \brief Start the VCPU
250 * This starts the VCPU and virtualization is started.\n
252 * This function will not return until any of these conditions are met:
253 * - An IO/MMIO handler does not return "0"
254 * - An exception that neither the guest OS, nor KVM can handle occurs
256 * \note This function will call the callbacks registered in kvm_init()
257 * to emulate those functions
258 * \note If you at any point want to interrupt the VCPU, kvm_run() will
259 * listen to the EINTR signal. This allows you to simulate external interrupts
260 * and asyncronous IO.
262 * \param kvm Pointer to the current kvm_context
263 * \param vcpu Which virtual CPU should be started
264 * \return 0 on success, but you really shouldn't expect this function to
265 * return except for when an error has occured, or when you have sent it
268 int kvm_run(kvm_vcpu_context_t vcpu
, void *env
);
271 * \brief Get interrupt flag from on last exit to userspace
273 * This gets the CPU interrupt flag as it was on the last exit to userspace.
275 * \param kvm Pointer to the current kvm_context
276 * \param vcpu Which virtual CPU should get dumped
277 * \return interrupt flag value (0 or 1)
279 int kvm_get_interrupt_flag(kvm_vcpu_context_t vcpu
);
282 * \brief Get the value of the APIC_BASE msr as of last exit to userspace
284 * This gets the APIC_BASE msr as it was on the last exit to userspace.
286 * \param kvm Pointer to the current kvm_context
287 * \param vcpu Which virtual CPU should get dumped
288 * \return APIC_BASE msr contents
290 uint64_t kvm_get_apic_base(kvm_vcpu_context_t vcpu
);
293 * \brief Check if a vcpu is ready for interrupt injection
295 * This checks if vcpu interrupts are not masked by mov ss or sti.
297 * \param kvm Pointer to the current kvm_context
298 * \param vcpu Which virtual CPU should get dumped
299 * \return boolean indicating interrupt injection readiness
301 int kvm_is_ready_for_interrupt_injection(kvm_vcpu_context_t vcpu
);
304 * \brief Read VCPU registers
306 * This gets the GP registers from the VCPU and outputs them
307 * into a kvm_regs structure
309 * \note This function returns a \b copy of the VCPUs registers.\n
310 * If you wish to modify the VCPUs GP registers, you should call kvm_set_regs()
312 * \param kvm Pointer to the current kvm_context
313 * \param vcpu Which virtual CPU should get dumped
314 * \param regs Pointer to a kvm_regs which will be populated with the VCPUs
316 * \return 0 on success
318 int kvm_get_regs(kvm_vcpu_context_t vcpu
, struct kvm_regs
*regs
);
321 * \brief Write VCPU registers
323 * This sets the GP registers on the VCPU from a kvm_regs structure
325 * \note When this function returns, the regs pointer and the data it points to
327 * \param kvm Pointer to the current kvm_context
328 * \param vcpu Which virtual CPU should get dumped
329 * \param regs Pointer to a kvm_regs which will be populated with the VCPUs
331 * \return 0 on success
333 int kvm_set_regs(kvm_vcpu_context_t vcpu
, struct kvm_regs
*regs
);
335 * \brief Read VCPU fpu registers
337 * This gets the FPU registers from the VCPU and outputs them
338 * into a kvm_fpu structure
340 * \note This function returns a \b copy of the VCPUs registers.\n
341 * If you wish to modify the VCPU FPU registers, you should call kvm_set_fpu()
343 * \param kvm Pointer to the current kvm_context
344 * \param vcpu Which virtual CPU should get dumped
345 * \param fpu Pointer to a kvm_fpu which will be populated with the VCPUs
346 * fpu registers values
347 * \return 0 on success
349 int kvm_get_fpu(kvm_vcpu_context_t vcpu
, struct kvm_fpu
*fpu
);
352 * \brief Write VCPU fpu registers
354 * This sets the FPU registers on the VCPU from a kvm_fpu structure
356 * \note When this function returns, the fpu pointer and the data it points to
358 * \param kvm Pointer to the current kvm_context
359 * \param vcpu Which virtual CPU should get dumped
360 * \param fpu Pointer to a kvm_fpu which holds the new vcpu fpu state
361 * \return 0 on success
363 int kvm_set_fpu(kvm_vcpu_context_t vcpu
, struct kvm_fpu
*fpu
);
366 * \brief Read VCPU system registers
368 * This gets the non-GP registers from the VCPU and outputs them
369 * into a kvm_sregs structure
371 * \note This function returns a \b copy of the VCPUs registers.\n
372 * If you wish to modify the VCPUs non-GP registers, you should call
375 * \param kvm Pointer to the current kvm_context
376 * \param vcpu Which virtual CPU should get dumped
377 * \param regs Pointer to a kvm_sregs which will be populated with the VCPUs
379 * \return 0 on success
381 int kvm_get_sregs(kvm_vcpu_context_t vcpu
, struct kvm_sregs
*regs
);
384 * \brief Write VCPU system registers
386 * This sets the non-GP registers on the VCPU from a kvm_sregs structure
388 * \note When this function returns, the regs pointer and the data it points to
390 * \param kvm Pointer to the current kvm_context
391 * \param vcpu Which virtual CPU should get dumped
392 * \param regs Pointer to a kvm_sregs which will be populated with the VCPUs
394 * \return 0 on success
396 int kvm_set_sregs(kvm_vcpu_context_t vcpu
, struct kvm_sregs
*regs
);
398 #ifdef KVM_CAP_MP_STATE
400 * * \brief Read VCPU MP state
403 int kvm_get_mpstate(kvm_vcpu_context_t vcpu
, struct kvm_mp_state
*mp_state
);
406 * * \brief Write VCPU MP state
409 int kvm_set_mpstate(kvm_vcpu_context_t vcpu
, struct kvm_mp_state
*mp_state
);
411 * * \brief Reset VCPU MP state
414 static inline int kvm_reset_mpstate(kvm_vcpu_context_t vcpu
)
416 struct kvm_mp_state mp_state
= {.mp_state
= KVM_MP_STATE_UNINITIALIZED
};
417 return kvm_set_mpstate(vcpu
, &mp_state
);
422 * \brief Simulate an external vectored interrupt
424 * This allows you to simulate an external vectored interrupt.
426 * \param kvm Pointer to the current kvm_context
427 * \param vcpu Which virtual CPU should get dumped
428 * \param irq Vector number
429 * \return 0 on success
431 int kvm_inject_irq(kvm_vcpu_context_t vcpu
, unsigned irq
);
433 #ifdef KVM_CAP_SET_GUEST_DEBUG
434 int kvm_set_guest_debug(kvm_vcpu_context_t
, struct kvm_guest_debug
*dbg
);
437 #if defined(__i386__) || defined(__x86_64__)
439 * \brief Setup a vcpu's cpuid instruction emulation
441 * Set up a table of cpuid function to cpuid outputs.\n
443 * \param kvm Pointer to the current kvm_context
444 * \param vcpu Which virtual CPU should be initialized
445 * \param nent number of entries to be installed
446 * \param entries cpuid function entries table
447 * \return 0 on success, or -errno on error
449 int kvm_setup_cpuid(kvm_vcpu_context_t vcpu
, int nent
,
450 struct kvm_cpuid_entry
*entries
);
453 * \brief Setup a vcpu's cpuid instruction emulation
455 * Set up a table of cpuid function to cpuid outputs.
456 * This call replaces the older kvm_setup_cpuid interface by adding a few
457 * parameters to support cpuid functions that have sub-leaf values.
459 * \param kvm Pointer to the current kvm_context
460 * \param vcpu Which virtual CPU should be initialized
461 * \param nent number of entries to be installed
462 * \param entries cpuid function entries table
463 * \return 0 on success, or -errno on error
465 int kvm_setup_cpuid2(kvm_vcpu_context_t vcpu
, int nent
,
466 struct kvm_cpuid_entry2
*entries
);
469 * \brief Setting the number of shadow pages to be allocated to the vm
471 * \param kvm pointer to kvm_context
472 * \param nrshadow_pages number of pages to be allocated
474 int kvm_set_shadow_pages(kvm_context_t kvm
, unsigned int nrshadow_pages
);
477 * \brief Getting the number of shadow pages that are allocated to the vm
479 * \param kvm pointer to kvm_context
480 * \param nrshadow_pages number of pages to be allocated
482 int kvm_get_shadow_pages(kvm_context_t kvm
, unsigned int *nrshadow_pages
);
485 * \brief Set up cr8 for next time the vcpu is executed
487 * This is a fast setter for cr8, which will be applied when the
488 * vcpu next enters guest mode.
490 * \param kvm Pointer to the current kvm_context
491 * \param vcpu Which virtual CPU should get dumped
492 * \param cr8 next cr8 value
494 void kvm_set_cr8(kvm_vcpu_context_t vcpu
, uint64_t cr8
);
497 * \brief Get cr8 for sync tpr in qemu apic emulation
499 * This is a getter for cr8, which used to sync with the tpr in qemu
502 * \param kvm Pointer to the current kvm_context
503 * \param vcpu Which virtual CPU should get dumped
505 __u64
kvm_get_cr8(kvm_vcpu_context_t vcpu
);
509 * \brief Set a vcpu's signal mask for guest mode
511 * A vcpu can have different signals blocked in guest mode and user mode.
512 * This allows guest execution to be interrupted on a signal, without requiring
513 * that the signal be delivered to a signal handler (the signal can be
514 * dequeued using sigwait(2).
516 * \param kvm Pointer to the current kvm_context
517 * \param vcpu Which virtual CPU should be initialized
518 * \param sigset signal mask for guest mode
519 * \return 0 on success, or -errno on error
521 int kvm_set_signal_mask(kvm_vcpu_context_t vcpu
, const sigset_t
*sigset
);
524 * \brief Dump VCPU registers
526 * This dumps some of the information that KVM has about a virtual CPU, namely:
529 * A much more verbose version of this is available as kvm_dump_vcpu()
531 * \param kvm Pointer to the current kvm_context
532 * \param vcpu Which virtual CPU should get dumped
533 * \return 0 on success
535 void kvm_show_regs(kvm_vcpu_context_t vcpu
);
538 void *kvm_create_phys_mem(kvm_context_t
, unsigned long phys_start
,
539 unsigned long len
, int log
, int writable
);
540 void kvm_destroy_phys_mem(kvm_context_t
, unsigned long phys_start
,
542 void kvm_unregister_memory_area(kvm_context_t
, uint64_t phys_start
,
545 int kvm_is_containing_region(kvm_context_t kvm
, unsigned long phys_start
, unsigned long size
);
546 int kvm_register_phys_mem(kvm_context_t kvm
,
547 unsigned long phys_start
, void *userspace_addr
,
548 unsigned long len
, int log
);
549 int kvm_get_dirty_pages(kvm_context_t
, unsigned long phys_addr
, void *buf
);
550 int kvm_get_dirty_pages_range(kvm_context_t kvm
, unsigned long phys_addr
,
551 unsigned long end_addr
, void*opaque
,
552 int (*cb
)(unsigned long start
, unsigned long len
,
553 void*bitmap
, void *opaque
));
554 int kvm_register_coalesced_mmio(kvm_context_t kvm
,
555 uint64_t addr
, uint32_t size
);
556 int kvm_unregister_coalesced_mmio(kvm_context_t kvm
,
557 uint64_t addr
, uint32_t size
);
560 * \brief Create a memory alias
562 * Aliases a portion of physical memory to another portion. If the guest
563 * accesses the alias region, it will behave exactly as if it accessed
566 int kvm_create_memory_alias(kvm_context_t
,
567 uint64_t phys_start
, uint64_t len
,
568 uint64_t target_phys
);
571 * \brief Destroy a memory alias
573 * Removes an alias created with kvm_create_memory_alias().
575 int kvm_destroy_memory_alias(kvm_context_t
, uint64_t phys_start
);
578 * \brief Get a bitmap of guest ram pages which are allocated to the guest.
580 * \param kvm Pointer to the current kvm_context
581 * \param phys_addr Memory slot phys addr
582 * \param bitmap Long aligned address of a big enough bitmap (one bit per page)
584 int kvm_get_mem_map(kvm_context_t kvm
, unsigned long phys_addr
, void *bitmap
);
585 int kvm_get_mem_map_range(kvm_context_t kvm
, unsigned long phys_addr
,
586 unsigned long len
, void *buf
, void *opaque
,
587 int (*cb
)(unsigned long start
,unsigned long len
,
588 void* bitmap
, void* opaque
));
589 int kvm_set_irq_level(kvm_context_t kvm
, int irq
, int level
, int *status
);
591 int kvm_dirty_pages_log_enable_slot(kvm_context_t kvm
,
594 int kvm_dirty_pages_log_disable_slot(kvm_context_t kvm
,
598 * \brief Enable dirty-pages-logging for all memory regions
600 * \param kvm Pointer to the current kvm_context
602 int kvm_dirty_pages_log_enable_all(kvm_context_t kvm
);
605 * \brief Disable dirty-page-logging for some memory regions
607 * Disable dirty-pages-logging for those memory regions that were
608 * created with dirty-page-logging disabled.
610 * \param kvm Pointer to the current kvm_context
612 int kvm_dirty_pages_log_reset(kvm_context_t kvm
);
615 * \brief Query whether in kernel irqchip is used
617 * \param kvm Pointer to the current kvm_context
619 int kvm_irqchip_in_kernel(kvm_context_t kvm
);
621 #ifdef KVM_CAP_IRQCHIP
623 * \brief Dump in kernel IRQCHIP contents
625 * Dump one of the in kernel irq chip devices, including PIC (master/slave)
626 * and IOAPIC into a kvm_irqchip structure
628 * \param kvm Pointer to the current kvm_context
629 * \param chip The irq chip device to be dumped
631 int kvm_get_irqchip(kvm_context_t kvm
, struct kvm_irqchip
*chip
);
634 * \brief Set in kernel IRQCHIP contents
636 * Write one of the in kernel irq chip devices, including PIC (master/slave)
640 * \param kvm Pointer to the current kvm_context
641 * \param chip THe irq chip device to be written
643 int kvm_set_irqchip(kvm_context_t kvm
, struct kvm_irqchip
*chip
);
645 #if defined(__i386__) || defined(__x86_64__)
647 * \brief Get in kernel local APIC for vcpu
649 * Save the local apic state including the timer of a virtual CPU
651 * \param kvm Pointer to the current kvm_context
652 * \param vcpu Which virtual CPU should be accessed
653 * \param s Local apic state of the specific virtual CPU
655 int kvm_get_lapic(kvm_vcpu_context_t vcpu
, struct kvm_lapic_state
*s
);
658 * \brief Set in kernel local APIC for vcpu
660 * Restore the local apic state including the timer of a virtual CPU
662 * \param kvm Pointer to the current kvm_context
663 * \param vcpu Which virtual CPU should be accessed
664 * \param s Local apic state of the specific virtual CPU
666 int kvm_set_lapic(kvm_vcpu_context_t vcpu
, struct kvm_lapic_state
*s
);
671 * \brief Simulate an NMI
673 * This allows you to simulate a non-maskable interrupt.
675 * \param kvm Pointer to the current kvm_context
676 * \param vcpu Which virtual CPU should get dumped
677 * \return 0 on success
679 int kvm_inject_nmi(kvm_vcpu_context_t vcpu
);
684 * \brief Query wheather in kernel pit is used
686 * \param kvm Pointer to the current kvm_context
688 int kvm_pit_in_kernel(kvm_context_t kvm
);
691 * \brief Initialize coalesced MMIO
693 * Check for coalesced MMIO capability and store in context
695 * \param kvm Pointer to the current kvm_context
697 int kvm_init_coalesced_mmio(kvm_context_t kvm
);
701 #if defined(__i386__) || defined(__x86_64__)
703 * \brief Get in kernel PIT of the virtual domain
705 * Save the PIT state.
707 * \param kvm Pointer to the current kvm_context
708 * \param s PIT state of the virtual domain
710 int kvm_get_pit(kvm_context_t kvm
, struct kvm_pit_state
*s
);
713 * \brief Set in kernel PIT of the virtual domain
715 * Restore the PIT state.
716 * Timer would be retriggerred after restored.
718 * \param kvm Pointer to the current kvm_context
719 * \param s PIT state of the virtual domain
721 int kvm_set_pit(kvm_context_t kvm
, struct kvm_pit_state
*s
);
724 int kvm_reinject_control(kvm_context_t kvm
, int pit_reinject
);
731 * \brief Enable kernel tpr access reporting
733 * When tpr access reporting is enabled, the kernel will call the
734 * ->tpr_access() callback every time the guest vcpu accesses the tpr.
736 * \param kvm Pointer to the current kvm_context
737 * \param vcpu vcpu to enable tpr access reporting on
739 int kvm_enable_tpr_access_reporting(kvm_vcpu_context_t vcpu
);
742 * \brief Disable kernel tpr access reporting
744 * Undoes the effect of kvm_enable_tpr_access_reporting().
746 * \param kvm Pointer to the current kvm_context
747 * \param vcpu vcpu to disable tpr access reporting on
749 int kvm_disable_tpr_access_reporting(kvm_vcpu_context_t vcpu
);
751 int kvm_enable_vapic(kvm_vcpu_context_t vcpu
, uint64_t vapic
);
755 #if defined(__s390__)
756 int kvm_s390_initial_reset(kvm_context_t kvm
, int slot
);
757 int kvm_s390_interrupt(kvm_context_t kvm
, int slot
,
758 struct kvm_s390_interrupt
*kvmint
);
759 int kvm_s390_set_initial_psw(kvm_context_t kvm
, int slot
, psw_t psw
);
760 int kvm_s390_store_status(kvm_context_t kvm
, int slot
, unsigned long addr
);
763 #ifdef KVM_CAP_DEVICE_ASSIGNMENT
765 * \brief Notifies host kernel about a PCI device to be assigned to a guest
767 * Used for PCI device assignment, this function notifies the host
768 * kernel about the assigning of the physical PCI device to a guest.
770 * \param kvm Pointer to the current kvm_context
771 * \param assigned_dev Parameters, like bus, devfn number, etc
773 int kvm_assign_pci_device(kvm_context_t kvm
,
774 struct kvm_assigned_pci_dev
*assigned_dev
);
777 * \brief Assign IRQ for an assigned device
779 * Used for PCI device assignment, this function assigns IRQ numbers for
780 * an physical device and guest IRQ handling.
782 * \param kvm Pointer to the current kvm_context
783 * \param assigned_irq Parameters, like dev id, host irq, guest irq, etc
785 int kvm_assign_irq(kvm_context_t kvm
,
786 struct kvm_assigned_irq
*assigned_irq
);
788 #ifdef KVM_CAP_ASSIGN_DEV_IRQ
790 * \brief Deassign IRQ for an assigned device
792 * Used for PCI device assignment, this function deassigns IRQ numbers
793 * for an assigned device.
795 * \param kvm Pointer to the current kvm_context
796 * \param assigned_irq Parameters, like dev id, host irq, guest irq, etc
798 int kvm_deassign_irq(kvm_context_t kvm
,
799 struct kvm_assigned_irq
*assigned_irq
);
804 * \brief Determines whether destroying memory regions is allowed
806 * KVM before 2.6.29 had a bug when destroying memory regions.
808 * \param kvm Pointer to the current kvm_context
810 int kvm_destroy_memory_region_works(kvm_context_t kvm
);
812 #ifdef KVM_CAP_DEVICE_DEASSIGNMENT
814 * \brief Notifies host kernel about a PCI device to be deassigned from a guest
816 * Used for hot remove PCI device, this function notifies the host
817 * kernel about the deassigning of the physical PCI device from a guest.
819 * \param kvm Pointer to the current kvm_context
820 * \param assigned_dev Parameters, like bus, devfn number, etc
822 int kvm_deassign_pci_device(kvm_context_t kvm
,
823 struct kvm_assigned_pci_dev
*assigned_dev
);
827 * \brief Checks whether the generic irq routing capability is present
829 * Checks whether kvm can reroute interrupts among the various interrupt
832 * \param kvm Pointer to the current kvm_context
834 int kvm_has_gsi_routing(kvm_context_t kvm
);
837 * \brief Determines the number of gsis that can be routed
839 * Returns the number of distinct gsis that can be routed by kvm. This is
840 * also the number of distinct routes (if a gsi has two routes, than another
841 * gsi cannot be used...)
843 * \param kvm Pointer to the current kvm_context
845 int kvm_get_gsi_count(kvm_context_t kvm
);
848 * \brief Clears the temporary irq routing table
850 * Clears the temporary irq routing table. Nothing is committed to the
853 * \param kvm Pointer to the current kvm_context
855 int kvm_clear_gsi_routes(kvm_context_t kvm
);
858 * \brief Adds an irq route to the temporary irq routing table
860 * Adds an irq route to the temporary irq routing table. Nothing is
861 * committed to the running VM.
863 * \param kvm Pointer to the current kvm_context
865 int kvm_add_irq_route(kvm_context_t kvm
, int gsi
, int irqchip
, int pin
);
868 * \brief Removes an irq route from the temporary irq routing table
870 * Adds an irq route to the temporary irq routing table. Nothing is
871 * committed to the running VM.
873 * \param kvm Pointer to the current kvm_context
875 int kvm_del_irq_route(kvm_context_t kvm
, int gsi
, int irqchip
, int pin
);
877 struct kvm_irq_routing_entry
;
879 * \brief Adds a routing entry to the temporary irq routing table
881 * Adds a filled routing entry to the temporary irq routing table. Nothing is
882 * committed to the running VM.
884 * \param kvm Pointer to the current kvm_context
886 int kvm_add_routing_entry(kvm_context_t kvm
,
887 struct kvm_irq_routing_entry
* entry
);
890 * \brief Removes a routing from the temporary irq routing table
892 * Remove a routing to the temporary irq routing table. Nothing is
893 * committed to the running VM.
895 * \param kvm Pointer to the current kvm_context
897 int kvm_del_routing_entry(kvm_context_t kvm
,
898 struct kvm_irq_routing_entry
* entry
);
901 * \brief Commit the temporary irq routing table
903 * Commit the temporary irq routing table to the running VM.
905 * \param kvm Pointer to the current kvm_context
907 int kvm_commit_irq_routes(kvm_context_t kvm
);
910 * \brief Get unused GSI number for irq routing table
912 * Get unused GSI number for irq routing table
914 * \param kvm Pointer to the current kvm_context
916 int kvm_get_irq_route_gsi(kvm_context_t kvm
);
919 * \brief Create a file descriptor for injecting interrupts
921 * Creates an eventfd based file-descriptor that maps to a specific GSI
922 * in the guest. eventfd compliant signaling (write() from userspace, or
923 * eventfd_signal() from kernelspace) will cause the GSI to inject
924 * itself into the guest at the next available window.
926 * \param kvm Pointer to the current kvm_context
927 * \param gsi GSI to assign to this fd
928 * \param flags reserved, must be zero
930 int kvm_irqfd(kvm_context_t kvm
, int gsi
, int flags
);
932 #ifdef KVM_CAP_DEVICE_MSIX
933 int kvm_assign_set_msix_nr(kvm_context_t kvm
,
934 struct kvm_assigned_msix_nr
*msix_nr
);
935 int kvm_assign_set_msix_entry(kvm_context_t kvm
,
936 struct kvm_assigned_msix_entry
*entry
);
939 uint32_t kvm_get_supported_cpuid(kvm_context_t kvm
, uint32_t function
, int reg
);