Avi Kivity | 9c1b96e | 2009-06-09 12:37:58 +0300 | [diff] [blame] | 1 | The Definitive KVM (Kernel-based Virtual Machine) API Documentation |
| 2 | =================================================================== |
| 3 | |
| 4 | 1. General description |
| 5 | |
| 6 | The kvm API is a set of ioctls that are issued to control various aspects |
| 7 | of a virtual machine. The ioctls belong to three classes |
| 8 | |
| 9 | - System ioctls: These query and set global attributes which affect the |
| 10 | whole kvm subsystem. In addition a system ioctl is used to create |
| 11 | virtual machines |
| 12 | |
| 13 | - VM ioctls: These query and set attributes that affect an entire virtual |
| 14 | machine, for example memory layout. In addition a VM ioctl is used to |
| 15 | create virtual cpus (vcpus). |
| 16 | |
| 17 | Only run VM ioctls from the same process (address space) that was used |
| 18 | to create the VM. |
| 19 | |
| 20 | - vcpu ioctls: These query and set attributes that control the operation |
| 21 | of a single virtual cpu. |
| 22 | |
| 23 | Only run vcpu ioctls from the same thread that was used to create the |
| 24 | vcpu. |
| 25 | |
Wu Fengguang | 2044892d | 2009-12-24 09:04:16 +0800 | [diff] [blame] | 26 | 2. File descriptors |
Avi Kivity | 9c1b96e | 2009-06-09 12:37:58 +0300 | [diff] [blame] | 27 | |
| 28 | The kvm API is centered around file descriptors. An initial |
| 29 | open("/dev/kvm") obtains a handle to the kvm subsystem; this handle |
| 30 | can be used to issue system ioctls. A KVM_CREATE_VM ioctl on this |
Wu Fengguang | 2044892d | 2009-12-24 09:04:16 +0800 | [diff] [blame] | 31 | handle will create a VM file descriptor which can be used to issue VM |
Avi Kivity | 9c1b96e | 2009-06-09 12:37:58 +0300 | [diff] [blame] | 32 | ioctls. A KVM_CREATE_VCPU ioctl on a VM fd will create a virtual cpu |
| 33 | and return a file descriptor pointing to it. Finally, ioctls on a vcpu |
| 34 | fd can be used to control the vcpu, including the important task of |
| 35 | actually running guest code. |
| 36 | |
| 37 | In general file descriptors can be migrated among processes by means |
| 38 | of fork() and the SCM_RIGHTS facility of unix domain socket. These |
| 39 | kinds of tricks are explicitly not supported by kvm. While they will |
| 40 | not cause harm to the host, their actual behavior is not guaranteed by |
| 41 | the API. The only supported use is one virtual machine per process, |
| 42 | and one vcpu per thread. |
| 43 | |
| 44 | 3. Extensions |
| 45 | |
| 46 | As of Linux 2.6.22, the KVM ABI has been stabilized: no backward |
| 47 | incompatible change are allowed. However, there is an extension |
| 48 | facility that allows backward-compatible extensions to the API to be |
| 49 | queried and used. |
| 50 | |
| 51 | The extension mechanism is not based on on the Linux version number. |
| 52 | Instead, kvm defines extension identifiers and a facility to query |
| 53 | whether a particular extension identifier is available. If it is, a |
| 54 | set of ioctls is available for application use. |
| 55 | |
| 56 | 4. API description |
| 57 | |
| 58 | This section describes ioctls that can be used to control kvm guests. |
| 59 | For each ioctl, the following information is provided along with a |
| 60 | description: |
| 61 | |
| 62 | Capability: which KVM extension provides this ioctl. Can be 'basic', |
| 63 | which means that is will be provided by any kernel that supports |
| 64 | API version 12 (see section 4.1), or a KVM_CAP_xyz constant, which |
| 65 | means availability needs to be checked with KVM_CHECK_EXTENSION |
| 66 | (see section 4.4). |
| 67 | |
| 68 | Architectures: which instruction set architectures provide this ioctl. |
| 69 | x86 includes both i386 and x86_64. |
| 70 | |
| 71 | Type: system, vm, or vcpu. |
| 72 | |
| 73 | Parameters: what parameters are accepted by the ioctl. |
| 74 | |
| 75 | Returns: the return value. General error numbers (EBADF, ENOMEM, EINVAL) |
| 76 | are not detailed, but errors with specific meanings are. |
| 77 | |
| 78 | 4.1 KVM_GET_API_VERSION |
| 79 | |
| 80 | Capability: basic |
| 81 | Architectures: all |
| 82 | Type: system ioctl |
| 83 | Parameters: none |
| 84 | Returns: the constant KVM_API_VERSION (=12) |
| 85 | |
| 86 | This identifies the API version as the stable kvm API. It is not |
| 87 | expected that this number will change. However, Linux 2.6.20 and |
| 88 | 2.6.21 report earlier versions; these are not documented and not |
| 89 | supported. Applications should refuse to run if KVM_GET_API_VERSION |
| 90 | returns a value other than 12. If this check passes, all ioctls |
| 91 | described as 'basic' will be available. |
| 92 | |
| 93 | 4.2 KVM_CREATE_VM |
| 94 | |
| 95 | Capability: basic |
| 96 | Architectures: all |
| 97 | Type: system ioctl |
| 98 | Parameters: none |
| 99 | Returns: a VM fd that can be used to control the new virtual machine. |
| 100 | |
| 101 | The new VM has no virtual cpus and no memory. An mmap() of a VM fd |
| 102 | will access the virtual machine's physical address space; offset zero |
| 103 | corresponds to guest physical address zero. Use of mmap() on a VM fd |
| 104 | is discouraged if userspace memory allocation (KVM_CAP_USER_MEMORY) is |
| 105 | available. |
| 106 | |
| 107 | 4.3 KVM_GET_MSR_INDEX_LIST |
| 108 | |
| 109 | Capability: basic |
| 110 | Architectures: x86 |
| 111 | Type: system |
| 112 | Parameters: struct kvm_msr_list (in/out) |
| 113 | Returns: 0 on success; -1 on error |
| 114 | Errors: |
| 115 | E2BIG: the msr index list is to be to fit in the array specified by |
| 116 | the user. |
| 117 | |
| 118 | struct kvm_msr_list { |
| 119 | __u32 nmsrs; /* number of msrs in entries */ |
| 120 | __u32 indices[0]; |
| 121 | }; |
| 122 | |
| 123 | This ioctl returns the guest msrs that are supported. The list varies |
| 124 | by kvm version and host processor, but does not change otherwise. The |
| 125 | user fills in the size of the indices array in nmsrs, and in return |
| 126 | kvm adjusts nmsrs to reflect the actual number of msrs and fills in |
| 127 | the indices array with their numbers. |
| 128 | |
Avi Kivity | 2e2602c | 2010-07-07 14:09:39 +0300 | [diff] [blame] | 129 | Note: if kvm indicates supports MCE (KVM_CAP_MCE), then the MCE bank MSRs are |
| 130 | not returned in the MSR list, as different vcpus can have a different number |
| 131 | of banks, as set via the KVM_X86_SETUP_MCE ioctl. |
| 132 | |
Avi Kivity | 9c1b96e | 2009-06-09 12:37:58 +0300 | [diff] [blame] | 133 | 4.4 KVM_CHECK_EXTENSION |
| 134 | |
| 135 | Capability: basic |
| 136 | Architectures: all |
| 137 | Type: system ioctl |
| 138 | Parameters: extension identifier (KVM_CAP_*) |
| 139 | Returns: 0 if unsupported; 1 (or some other positive integer) if supported |
| 140 | |
| 141 | The API allows the application to query about extensions to the core |
| 142 | kvm API. Userspace passes an extension identifier (an integer) and |
| 143 | receives an integer that describes the extension availability. |
| 144 | Generally 0 means no and 1 means yes, but some extensions may report |
| 145 | additional information in the integer return value. |
| 146 | |
| 147 | 4.5 KVM_GET_VCPU_MMAP_SIZE |
| 148 | |
| 149 | Capability: basic |
| 150 | Architectures: all |
| 151 | Type: system ioctl |
| 152 | Parameters: none |
| 153 | Returns: size of vcpu mmap area, in bytes |
| 154 | |
| 155 | The KVM_RUN ioctl (cf.) communicates with userspace via a shared |
| 156 | memory region. This ioctl returns the size of that region. See the |
| 157 | KVM_RUN documentation for details. |
| 158 | |
| 159 | 4.6 KVM_SET_MEMORY_REGION |
| 160 | |
| 161 | Capability: basic |
| 162 | Architectures: all |
| 163 | Type: vm ioctl |
| 164 | Parameters: struct kvm_memory_region (in) |
| 165 | Returns: 0 on success, -1 on error |
| 166 | |
Avi Kivity | b74a07b | 2010-06-21 11:48:05 +0300 | [diff] [blame] | 167 | This ioctl is obsolete and has been removed. |
Avi Kivity | 9c1b96e | 2009-06-09 12:37:58 +0300 | [diff] [blame] | 168 | |
Paul Bolle | 68ba697 | 2011-02-15 00:05:59 +0100 | [diff] [blame] | 169 | 4.7 KVM_CREATE_VCPU |
Avi Kivity | 9c1b96e | 2009-06-09 12:37:58 +0300 | [diff] [blame] | 170 | |
| 171 | Capability: basic |
| 172 | Architectures: all |
| 173 | Type: vm ioctl |
| 174 | Parameters: vcpu id (apic id on x86) |
| 175 | Returns: vcpu fd on success, -1 on error |
| 176 | |
| 177 | This API adds a vcpu to a virtual machine. The vcpu id is a small integer |
Pekka Enberg | 76d2540 | 2011-05-09 22:48:54 +0300 | [diff] [blame] | 178 | in the range [0, max_vcpus). You can use KVM_CAP_NR_VCPUS of the |
| 179 | KVM_CHECK_EXTENSION ioctl() to determine the value for max_vcpus at run-time. |
| 180 | If the KVM_CAP_NR_VCPUS does not exist, you should assume that max_vcpus is 4 |
| 181 | cpus max. |
Avi Kivity | 9c1b96e | 2009-06-09 12:37:58 +0300 | [diff] [blame] | 182 | |
Paul Bolle | 68ba697 | 2011-02-15 00:05:59 +0100 | [diff] [blame] | 183 | 4.8 KVM_GET_DIRTY_LOG (vm ioctl) |
Avi Kivity | 9c1b96e | 2009-06-09 12:37:58 +0300 | [diff] [blame] | 184 | |
| 185 | Capability: basic |
| 186 | Architectures: x86 |
| 187 | Type: vm ioctl |
| 188 | Parameters: struct kvm_dirty_log (in/out) |
| 189 | Returns: 0 on success, -1 on error |
| 190 | |
| 191 | /* for KVM_GET_DIRTY_LOG */ |
| 192 | struct kvm_dirty_log { |
| 193 | __u32 slot; |
| 194 | __u32 padding; |
| 195 | union { |
| 196 | void __user *dirty_bitmap; /* one bit per page */ |
| 197 | __u64 padding; |
| 198 | }; |
| 199 | }; |
| 200 | |
| 201 | Given a memory slot, return a bitmap containing any pages dirtied |
| 202 | since the last call to this ioctl. Bit 0 is the first page in the |
| 203 | memory slot. Ensure the entire structure is cleared to avoid padding |
| 204 | issues. |
| 205 | |
Paul Bolle | 68ba697 | 2011-02-15 00:05:59 +0100 | [diff] [blame] | 206 | 4.9 KVM_SET_MEMORY_ALIAS |
Avi Kivity | 9c1b96e | 2009-06-09 12:37:58 +0300 | [diff] [blame] | 207 | |
| 208 | Capability: basic |
| 209 | Architectures: x86 |
| 210 | Type: vm ioctl |
| 211 | Parameters: struct kvm_memory_alias (in) |
| 212 | Returns: 0 (success), -1 (error) |
| 213 | |
Avi Kivity | a1f4d395 | 2010-06-21 11:44:20 +0300 | [diff] [blame] | 214 | This ioctl is obsolete and has been removed. |
Avi Kivity | 9c1b96e | 2009-06-09 12:37:58 +0300 | [diff] [blame] | 215 | |
Paul Bolle | 68ba697 | 2011-02-15 00:05:59 +0100 | [diff] [blame] | 216 | 4.10 KVM_RUN |
Avi Kivity | 9c1b96e | 2009-06-09 12:37:58 +0300 | [diff] [blame] | 217 | |
| 218 | Capability: basic |
| 219 | Architectures: all |
| 220 | Type: vcpu ioctl |
| 221 | Parameters: none |
| 222 | Returns: 0 on success, -1 on error |
| 223 | Errors: |
| 224 | EINTR: an unmasked signal is pending |
| 225 | |
| 226 | This ioctl is used to run a guest virtual cpu. While there are no |
| 227 | explicit parameters, there is an implicit parameter block that can be |
| 228 | obtained by mmap()ing the vcpu fd at offset 0, with the size given by |
| 229 | KVM_GET_VCPU_MMAP_SIZE. The parameter block is formatted as a 'struct |
| 230 | kvm_run' (see below). |
| 231 | |
Paul Bolle | 68ba697 | 2011-02-15 00:05:59 +0100 | [diff] [blame] | 232 | 4.11 KVM_GET_REGS |
Avi Kivity | 9c1b96e | 2009-06-09 12:37:58 +0300 | [diff] [blame] | 233 | |
| 234 | Capability: basic |
| 235 | Architectures: all |
| 236 | Type: vcpu ioctl |
| 237 | Parameters: struct kvm_regs (out) |
| 238 | Returns: 0 on success, -1 on error |
| 239 | |
| 240 | Reads the general purpose registers from the vcpu. |
| 241 | |
| 242 | /* x86 */ |
| 243 | struct kvm_regs { |
| 244 | /* out (KVM_GET_REGS) / in (KVM_SET_REGS) */ |
| 245 | __u64 rax, rbx, rcx, rdx; |
| 246 | __u64 rsi, rdi, rsp, rbp; |
| 247 | __u64 r8, r9, r10, r11; |
| 248 | __u64 r12, r13, r14, r15; |
| 249 | __u64 rip, rflags; |
| 250 | }; |
| 251 | |
Paul Bolle | 68ba697 | 2011-02-15 00:05:59 +0100 | [diff] [blame] | 252 | 4.12 KVM_SET_REGS |
Avi Kivity | 9c1b96e | 2009-06-09 12:37:58 +0300 | [diff] [blame] | 253 | |
| 254 | Capability: basic |
| 255 | Architectures: all |
| 256 | Type: vcpu ioctl |
| 257 | Parameters: struct kvm_regs (in) |
| 258 | Returns: 0 on success, -1 on error |
| 259 | |
| 260 | Writes the general purpose registers into the vcpu. |
| 261 | |
| 262 | See KVM_GET_REGS for the data structure. |
| 263 | |
Paul Bolle | 68ba697 | 2011-02-15 00:05:59 +0100 | [diff] [blame] | 264 | 4.13 KVM_GET_SREGS |
Avi Kivity | 9c1b96e | 2009-06-09 12:37:58 +0300 | [diff] [blame] | 265 | |
| 266 | Capability: basic |
Scott Wood | 5ce941e | 2011-04-27 17:24:21 -0500 | [diff] [blame] | 267 | Architectures: x86, ppc |
Avi Kivity | 9c1b96e | 2009-06-09 12:37:58 +0300 | [diff] [blame] | 268 | Type: vcpu ioctl |
| 269 | Parameters: struct kvm_sregs (out) |
| 270 | Returns: 0 on success, -1 on error |
| 271 | |
| 272 | Reads special registers from the vcpu. |
| 273 | |
| 274 | /* x86 */ |
| 275 | struct kvm_sregs { |
| 276 | struct kvm_segment cs, ds, es, fs, gs, ss; |
| 277 | struct kvm_segment tr, ldt; |
| 278 | struct kvm_dtable gdt, idt; |
| 279 | __u64 cr0, cr2, cr3, cr4, cr8; |
| 280 | __u64 efer; |
| 281 | __u64 apic_base; |
| 282 | __u64 interrupt_bitmap[(KVM_NR_INTERRUPTS + 63) / 64]; |
| 283 | }; |
| 284 | |
Scott Wood | 5ce941e | 2011-04-27 17:24:21 -0500 | [diff] [blame] | 285 | /* ppc -- see arch/powerpc/include/asm/kvm.h */ |
| 286 | |
Avi Kivity | 9c1b96e | 2009-06-09 12:37:58 +0300 | [diff] [blame] | 287 | interrupt_bitmap is a bitmap of pending external interrupts. At most |
| 288 | one bit may be set. This interrupt has been acknowledged by the APIC |
| 289 | but not yet injected into the cpu core. |
| 290 | |
Paul Bolle | 68ba697 | 2011-02-15 00:05:59 +0100 | [diff] [blame] | 291 | 4.14 KVM_SET_SREGS |
Avi Kivity | 9c1b96e | 2009-06-09 12:37:58 +0300 | [diff] [blame] | 292 | |
| 293 | Capability: basic |
Scott Wood | 5ce941e | 2011-04-27 17:24:21 -0500 | [diff] [blame] | 294 | Architectures: x86, ppc |
Avi Kivity | 9c1b96e | 2009-06-09 12:37:58 +0300 | [diff] [blame] | 295 | Type: vcpu ioctl |
| 296 | Parameters: struct kvm_sregs (in) |
| 297 | Returns: 0 on success, -1 on error |
| 298 | |
| 299 | Writes special registers into the vcpu. See KVM_GET_SREGS for the |
| 300 | data structures. |
| 301 | |
Paul Bolle | 68ba697 | 2011-02-15 00:05:59 +0100 | [diff] [blame] | 302 | 4.15 KVM_TRANSLATE |
Avi Kivity | 9c1b96e | 2009-06-09 12:37:58 +0300 | [diff] [blame] | 303 | |
| 304 | Capability: basic |
| 305 | Architectures: x86 |
| 306 | Type: vcpu ioctl |
| 307 | Parameters: struct kvm_translation (in/out) |
| 308 | Returns: 0 on success, -1 on error |
| 309 | |
| 310 | Translates a virtual address according to the vcpu's current address |
| 311 | translation mode. |
| 312 | |
| 313 | struct kvm_translation { |
| 314 | /* in */ |
| 315 | __u64 linear_address; |
| 316 | |
| 317 | /* out */ |
| 318 | __u64 physical_address; |
| 319 | __u8 valid; |
| 320 | __u8 writeable; |
| 321 | __u8 usermode; |
| 322 | __u8 pad[5]; |
| 323 | }; |
| 324 | |
Paul Bolle | 68ba697 | 2011-02-15 00:05:59 +0100 | [diff] [blame] | 325 | 4.16 KVM_INTERRUPT |
Avi Kivity | 9c1b96e | 2009-06-09 12:37:58 +0300 | [diff] [blame] | 326 | |
| 327 | Capability: basic |
Alexander Graf | 6f7a2bd | 2010-08-31 02:03:32 +0200 | [diff] [blame] | 328 | Architectures: x86, ppc |
Avi Kivity | 9c1b96e | 2009-06-09 12:37:58 +0300 | [diff] [blame] | 329 | Type: vcpu ioctl |
| 330 | Parameters: struct kvm_interrupt (in) |
| 331 | Returns: 0 on success, -1 on error |
| 332 | |
| 333 | Queues a hardware interrupt vector to be injected. This is only |
Alexander Graf | 6f7a2bd | 2010-08-31 02:03:32 +0200 | [diff] [blame] | 334 | useful if in-kernel local APIC or equivalent is not used. |
Avi Kivity | 9c1b96e | 2009-06-09 12:37:58 +0300 | [diff] [blame] | 335 | |
| 336 | /* for KVM_INTERRUPT */ |
| 337 | struct kvm_interrupt { |
| 338 | /* in */ |
| 339 | __u32 irq; |
| 340 | }; |
| 341 | |
Alexander Graf | 6f7a2bd | 2010-08-31 02:03:32 +0200 | [diff] [blame] | 342 | X86: |
| 343 | |
Avi Kivity | 9c1b96e | 2009-06-09 12:37:58 +0300 | [diff] [blame] | 344 | Note 'irq' is an interrupt vector, not an interrupt pin or line. |
| 345 | |
Alexander Graf | 6f7a2bd | 2010-08-31 02:03:32 +0200 | [diff] [blame] | 346 | PPC: |
| 347 | |
| 348 | Queues an external interrupt to be injected. This ioctl is overleaded |
| 349 | with 3 different irq values: |
| 350 | |
| 351 | a) KVM_INTERRUPT_SET |
| 352 | |
| 353 | This injects an edge type external interrupt into the guest once it's ready |
| 354 | to receive interrupts. When injected, the interrupt is done. |
| 355 | |
| 356 | b) KVM_INTERRUPT_UNSET |
| 357 | |
| 358 | This unsets any pending interrupt. |
| 359 | |
| 360 | Only available with KVM_CAP_PPC_UNSET_IRQ. |
| 361 | |
| 362 | c) KVM_INTERRUPT_SET_LEVEL |
| 363 | |
| 364 | This injects a level type external interrupt into the guest context. The |
| 365 | interrupt stays pending until a specific ioctl with KVM_INTERRUPT_UNSET |
| 366 | is triggered. |
| 367 | |
| 368 | Only available with KVM_CAP_PPC_IRQ_LEVEL. |
| 369 | |
| 370 | Note that any value for 'irq' other than the ones stated above is invalid |
| 371 | and incurs unexpected behavior. |
| 372 | |
Paul Bolle | 68ba697 | 2011-02-15 00:05:59 +0100 | [diff] [blame] | 373 | 4.17 KVM_DEBUG_GUEST |
Avi Kivity | 9c1b96e | 2009-06-09 12:37:58 +0300 | [diff] [blame] | 374 | |
| 375 | Capability: basic |
| 376 | Architectures: none |
| 377 | Type: vcpu ioctl |
| 378 | Parameters: none) |
| 379 | Returns: -1 on error |
| 380 | |
| 381 | Support for this has been removed. Use KVM_SET_GUEST_DEBUG instead. |
| 382 | |
Paul Bolle | 68ba697 | 2011-02-15 00:05:59 +0100 | [diff] [blame] | 383 | 4.18 KVM_GET_MSRS |
Avi Kivity | 9c1b96e | 2009-06-09 12:37:58 +0300 | [diff] [blame] | 384 | |
| 385 | Capability: basic |
| 386 | Architectures: x86 |
| 387 | Type: vcpu ioctl |
| 388 | Parameters: struct kvm_msrs (in/out) |
| 389 | Returns: 0 on success, -1 on error |
| 390 | |
| 391 | Reads model-specific registers from the vcpu. Supported msr indices can |
| 392 | be obtained using KVM_GET_MSR_INDEX_LIST. |
| 393 | |
| 394 | struct kvm_msrs { |
| 395 | __u32 nmsrs; /* number of msrs in entries */ |
| 396 | __u32 pad; |
| 397 | |
| 398 | struct kvm_msr_entry entries[0]; |
| 399 | }; |
| 400 | |
| 401 | struct kvm_msr_entry { |
| 402 | __u32 index; |
| 403 | __u32 reserved; |
| 404 | __u64 data; |
| 405 | }; |
| 406 | |
| 407 | Application code should set the 'nmsrs' member (which indicates the |
| 408 | size of the entries array) and the 'index' member of each array entry. |
| 409 | kvm will fill in the 'data' member. |
| 410 | |
Paul Bolle | 68ba697 | 2011-02-15 00:05:59 +0100 | [diff] [blame] | 411 | 4.19 KVM_SET_MSRS |
Avi Kivity | 9c1b96e | 2009-06-09 12:37:58 +0300 | [diff] [blame] | 412 | |
| 413 | Capability: basic |
| 414 | Architectures: x86 |
| 415 | Type: vcpu ioctl |
| 416 | Parameters: struct kvm_msrs (in) |
| 417 | Returns: 0 on success, -1 on error |
| 418 | |
| 419 | Writes model-specific registers to the vcpu. See KVM_GET_MSRS for the |
| 420 | data structures. |
| 421 | |
| 422 | Application code should set the 'nmsrs' member (which indicates the |
| 423 | size of the entries array), and the 'index' and 'data' members of each |
| 424 | array entry. |
| 425 | |
Paul Bolle | 68ba697 | 2011-02-15 00:05:59 +0100 | [diff] [blame] | 426 | 4.20 KVM_SET_CPUID |
Avi Kivity | 9c1b96e | 2009-06-09 12:37:58 +0300 | [diff] [blame] | 427 | |
| 428 | Capability: basic |
| 429 | Architectures: x86 |
| 430 | Type: vcpu ioctl |
| 431 | Parameters: struct kvm_cpuid (in) |
| 432 | Returns: 0 on success, -1 on error |
| 433 | |
| 434 | Defines the vcpu responses to the cpuid instruction. Applications |
| 435 | should use the KVM_SET_CPUID2 ioctl if available. |
| 436 | |
| 437 | |
| 438 | struct kvm_cpuid_entry { |
| 439 | __u32 function; |
| 440 | __u32 eax; |
| 441 | __u32 ebx; |
| 442 | __u32 ecx; |
| 443 | __u32 edx; |
| 444 | __u32 padding; |
| 445 | }; |
| 446 | |
| 447 | /* for KVM_SET_CPUID */ |
| 448 | struct kvm_cpuid { |
| 449 | __u32 nent; |
| 450 | __u32 padding; |
| 451 | struct kvm_cpuid_entry entries[0]; |
| 452 | }; |
| 453 | |
Paul Bolle | 68ba697 | 2011-02-15 00:05:59 +0100 | [diff] [blame] | 454 | 4.21 KVM_SET_SIGNAL_MASK |
Avi Kivity | 9c1b96e | 2009-06-09 12:37:58 +0300 | [diff] [blame] | 455 | |
| 456 | Capability: basic |
| 457 | Architectures: x86 |
| 458 | Type: vcpu ioctl |
| 459 | Parameters: struct kvm_signal_mask (in) |
| 460 | Returns: 0 on success, -1 on error |
| 461 | |
| 462 | Defines which signals are blocked during execution of KVM_RUN. This |
| 463 | signal mask temporarily overrides the threads signal mask. Any |
| 464 | unblocked signal received (except SIGKILL and SIGSTOP, which retain |
| 465 | their traditional behaviour) will cause KVM_RUN to return with -EINTR. |
| 466 | |
| 467 | Note the signal will only be delivered if not blocked by the original |
| 468 | signal mask. |
| 469 | |
| 470 | /* for KVM_SET_SIGNAL_MASK */ |
| 471 | struct kvm_signal_mask { |
| 472 | __u32 len; |
| 473 | __u8 sigset[0]; |
| 474 | }; |
| 475 | |
Paul Bolle | 68ba697 | 2011-02-15 00:05:59 +0100 | [diff] [blame] | 476 | 4.22 KVM_GET_FPU |
Avi Kivity | 9c1b96e | 2009-06-09 12:37:58 +0300 | [diff] [blame] | 477 | |
| 478 | Capability: basic |
| 479 | Architectures: x86 |
| 480 | Type: vcpu ioctl |
| 481 | Parameters: struct kvm_fpu (out) |
| 482 | Returns: 0 on success, -1 on error |
| 483 | |
| 484 | Reads the floating point state from the vcpu. |
| 485 | |
| 486 | /* for KVM_GET_FPU and KVM_SET_FPU */ |
| 487 | struct kvm_fpu { |
| 488 | __u8 fpr[8][16]; |
| 489 | __u16 fcw; |
| 490 | __u16 fsw; |
| 491 | __u8 ftwx; /* in fxsave format */ |
| 492 | __u8 pad1; |
| 493 | __u16 last_opcode; |
| 494 | __u64 last_ip; |
| 495 | __u64 last_dp; |
| 496 | __u8 xmm[16][16]; |
| 497 | __u32 mxcsr; |
| 498 | __u32 pad2; |
| 499 | }; |
| 500 | |
Paul Bolle | 68ba697 | 2011-02-15 00:05:59 +0100 | [diff] [blame] | 501 | 4.23 KVM_SET_FPU |
Avi Kivity | 9c1b96e | 2009-06-09 12:37:58 +0300 | [diff] [blame] | 502 | |
| 503 | Capability: basic |
| 504 | Architectures: x86 |
| 505 | Type: vcpu ioctl |
| 506 | Parameters: struct kvm_fpu (in) |
| 507 | Returns: 0 on success, -1 on error |
| 508 | |
| 509 | Writes the floating point state to the vcpu. |
| 510 | |
| 511 | /* for KVM_GET_FPU and KVM_SET_FPU */ |
| 512 | struct kvm_fpu { |
| 513 | __u8 fpr[8][16]; |
| 514 | __u16 fcw; |
| 515 | __u16 fsw; |
| 516 | __u8 ftwx; /* in fxsave format */ |
| 517 | __u8 pad1; |
| 518 | __u16 last_opcode; |
| 519 | __u64 last_ip; |
| 520 | __u64 last_dp; |
| 521 | __u8 xmm[16][16]; |
| 522 | __u32 mxcsr; |
| 523 | __u32 pad2; |
| 524 | }; |
| 525 | |
Paul Bolle | 68ba697 | 2011-02-15 00:05:59 +0100 | [diff] [blame] | 526 | 4.24 KVM_CREATE_IRQCHIP |
Avi Kivity | 5dadbfd | 2009-08-23 17:08:04 +0300 | [diff] [blame] | 527 | |
| 528 | Capability: KVM_CAP_IRQCHIP |
| 529 | Architectures: x86, ia64 |
| 530 | Type: vm ioctl |
| 531 | Parameters: none |
| 532 | Returns: 0 on success, -1 on error |
| 533 | |
| 534 | Creates an interrupt controller model in the kernel. On x86, creates a virtual |
| 535 | ioapic, a virtual PIC (two PICs, nested), and sets up future vcpus to have a |
| 536 | local APIC. IRQ routing for GSIs 0-15 is set to both PIC and IOAPIC; GSI 16-23 |
| 537 | only go to the IOAPIC. On ia64, a IOSAPIC is created. |
| 538 | |
Paul Bolle | 68ba697 | 2011-02-15 00:05:59 +0100 | [diff] [blame] | 539 | 4.25 KVM_IRQ_LINE |
Avi Kivity | 5dadbfd | 2009-08-23 17:08:04 +0300 | [diff] [blame] | 540 | |
| 541 | Capability: KVM_CAP_IRQCHIP |
| 542 | Architectures: x86, ia64 |
| 543 | Type: vm ioctl |
| 544 | Parameters: struct kvm_irq_level |
| 545 | Returns: 0 on success, -1 on error |
| 546 | |
| 547 | Sets the level of a GSI input to the interrupt controller model in the kernel. |
| 548 | Requires that an interrupt controller model has been previously created with |
| 549 | KVM_CREATE_IRQCHIP. Note that edge-triggered interrupts require the level |
| 550 | to be set to 1 and then back to 0. |
| 551 | |
| 552 | struct kvm_irq_level { |
| 553 | union { |
| 554 | __u32 irq; /* GSI */ |
| 555 | __s32 status; /* not used for KVM_IRQ_LEVEL */ |
| 556 | }; |
| 557 | __u32 level; /* 0 or 1 */ |
| 558 | }; |
| 559 | |
Paul Bolle | 68ba697 | 2011-02-15 00:05:59 +0100 | [diff] [blame] | 560 | 4.26 KVM_GET_IRQCHIP |
Avi Kivity | 5dadbfd | 2009-08-23 17:08:04 +0300 | [diff] [blame] | 561 | |
| 562 | Capability: KVM_CAP_IRQCHIP |
| 563 | Architectures: x86, ia64 |
| 564 | Type: vm ioctl |
| 565 | Parameters: struct kvm_irqchip (in/out) |
| 566 | Returns: 0 on success, -1 on error |
| 567 | |
| 568 | Reads the state of a kernel interrupt controller created with |
| 569 | KVM_CREATE_IRQCHIP into a buffer provided by the caller. |
| 570 | |
| 571 | struct kvm_irqchip { |
| 572 | __u32 chip_id; /* 0 = PIC1, 1 = PIC2, 2 = IOAPIC */ |
| 573 | __u32 pad; |
| 574 | union { |
| 575 | char dummy[512]; /* reserving space */ |
| 576 | struct kvm_pic_state pic; |
| 577 | struct kvm_ioapic_state ioapic; |
| 578 | } chip; |
| 579 | }; |
| 580 | |
Paul Bolle | 68ba697 | 2011-02-15 00:05:59 +0100 | [diff] [blame] | 581 | 4.27 KVM_SET_IRQCHIP |
Avi Kivity | 5dadbfd | 2009-08-23 17:08:04 +0300 | [diff] [blame] | 582 | |
| 583 | Capability: KVM_CAP_IRQCHIP |
| 584 | Architectures: x86, ia64 |
| 585 | Type: vm ioctl |
| 586 | Parameters: struct kvm_irqchip (in) |
| 587 | Returns: 0 on success, -1 on error |
| 588 | |
| 589 | Sets the state of a kernel interrupt controller created with |
| 590 | KVM_CREATE_IRQCHIP from a buffer provided by the caller. |
| 591 | |
| 592 | struct kvm_irqchip { |
| 593 | __u32 chip_id; /* 0 = PIC1, 1 = PIC2, 2 = IOAPIC */ |
| 594 | __u32 pad; |
| 595 | union { |
| 596 | char dummy[512]; /* reserving space */ |
| 597 | struct kvm_pic_state pic; |
| 598 | struct kvm_ioapic_state ioapic; |
| 599 | } chip; |
| 600 | }; |
| 601 | |
Paul Bolle | 68ba697 | 2011-02-15 00:05:59 +0100 | [diff] [blame] | 602 | 4.28 KVM_XEN_HVM_CONFIG |
Ed Swierk | ffde22a | 2009-10-15 15:21:43 -0700 | [diff] [blame] | 603 | |
| 604 | Capability: KVM_CAP_XEN_HVM |
| 605 | Architectures: x86 |
| 606 | Type: vm ioctl |
| 607 | Parameters: struct kvm_xen_hvm_config (in) |
| 608 | Returns: 0 on success, -1 on error |
| 609 | |
| 610 | Sets the MSR that the Xen HVM guest uses to initialize its hypercall |
| 611 | page, and provides the starting address and size of the hypercall |
| 612 | blobs in userspace. When the guest writes the MSR, kvm copies one |
| 613 | page of a blob (32- or 64-bit, depending on the vcpu mode) to guest |
| 614 | memory. |
| 615 | |
| 616 | struct kvm_xen_hvm_config { |
| 617 | __u32 flags; |
| 618 | __u32 msr; |
| 619 | __u64 blob_addr_32; |
| 620 | __u64 blob_addr_64; |
| 621 | __u8 blob_size_32; |
| 622 | __u8 blob_size_64; |
| 623 | __u8 pad2[30]; |
| 624 | }; |
| 625 | |
Paul Bolle | 68ba697 | 2011-02-15 00:05:59 +0100 | [diff] [blame] | 626 | 4.29 KVM_GET_CLOCK |
Glauber Costa | afbcf7a | 2009-10-16 15:28:36 -0400 | [diff] [blame] | 627 | |
| 628 | Capability: KVM_CAP_ADJUST_CLOCK |
| 629 | Architectures: x86 |
| 630 | Type: vm ioctl |
| 631 | Parameters: struct kvm_clock_data (out) |
| 632 | Returns: 0 on success, -1 on error |
| 633 | |
| 634 | Gets the current timestamp of kvmclock as seen by the current guest. In |
| 635 | conjunction with KVM_SET_CLOCK, it is used to ensure monotonicity on scenarios |
| 636 | such as migration. |
| 637 | |
| 638 | struct kvm_clock_data { |
| 639 | __u64 clock; /* kvmclock current value */ |
| 640 | __u32 flags; |
| 641 | __u32 pad[9]; |
| 642 | }; |
| 643 | |
Paul Bolle | 68ba697 | 2011-02-15 00:05:59 +0100 | [diff] [blame] | 644 | 4.30 KVM_SET_CLOCK |
Glauber Costa | afbcf7a | 2009-10-16 15:28:36 -0400 | [diff] [blame] | 645 | |
| 646 | Capability: KVM_CAP_ADJUST_CLOCK |
| 647 | Architectures: x86 |
| 648 | Type: vm ioctl |
| 649 | Parameters: struct kvm_clock_data (in) |
| 650 | Returns: 0 on success, -1 on error |
| 651 | |
Wu Fengguang | 2044892d | 2009-12-24 09:04:16 +0800 | [diff] [blame] | 652 | Sets the current timestamp of kvmclock to the value specified in its parameter. |
Glauber Costa | afbcf7a | 2009-10-16 15:28:36 -0400 | [diff] [blame] | 653 | In conjunction with KVM_GET_CLOCK, it is used to ensure monotonicity on scenarios |
| 654 | such as migration. |
| 655 | |
| 656 | struct kvm_clock_data { |
| 657 | __u64 clock; /* kvmclock current value */ |
| 658 | __u32 flags; |
| 659 | __u32 pad[9]; |
| 660 | }; |
| 661 | |
Paul Bolle | 68ba697 | 2011-02-15 00:05:59 +0100 | [diff] [blame] | 662 | 4.31 KVM_GET_VCPU_EVENTS |
Jan Kiszka | 3cfc309 | 2009-11-12 01:04:25 +0100 | [diff] [blame] | 663 | |
| 664 | Capability: KVM_CAP_VCPU_EVENTS |
Jan Kiszka | 48005f6 | 2010-02-19 19:38:07 +0100 | [diff] [blame] | 665 | Extended by: KVM_CAP_INTR_SHADOW |
Jan Kiszka | 3cfc309 | 2009-11-12 01:04:25 +0100 | [diff] [blame] | 666 | Architectures: x86 |
| 667 | Type: vm ioctl |
| 668 | Parameters: struct kvm_vcpu_event (out) |
| 669 | Returns: 0 on success, -1 on error |
| 670 | |
| 671 | Gets currently pending exceptions, interrupts, and NMIs as well as related |
| 672 | states of the vcpu. |
| 673 | |
| 674 | struct kvm_vcpu_events { |
| 675 | struct { |
| 676 | __u8 injected; |
| 677 | __u8 nr; |
| 678 | __u8 has_error_code; |
| 679 | __u8 pad; |
| 680 | __u32 error_code; |
| 681 | } exception; |
| 682 | struct { |
| 683 | __u8 injected; |
| 684 | __u8 nr; |
| 685 | __u8 soft; |
Jan Kiszka | 48005f6 | 2010-02-19 19:38:07 +0100 | [diff] [blame] | 686 | __u8 shadow; |
Jan Kiszka | 3cfc309 | 2009-11-12 01:04:25 +0100 | [diff] [blame] | 687 | } interrupt; |
| 688 | struct { |
| 689 | __u8 injected; |
| 690 | __u8 pending; |
| 691 | __u8 masked; |
| 692 | __u8 pad; |
| 693 | } nmi; |
| 694 | __u32 sipi_vector; |
Jan Kiszka | dab4b91 | 2009-12-06 18:24:15 +0100 | [diff] [blame] | 695 | __u32 flags; |
Jan Kiszka | 3cfc309 | 2009-11-12 01:04:25 +0100 | [diff] [blame] | 696 | }; |
| 697 | |
Jan Kiszka | 48005f6 | 2010-02-19 19:38:07 +0100 | [diff] [blame] | 698 | KVM_VCPUEVENT_VALID_SHADOW may be set in the flags field to signal that |
| 699 | interrupt.shadow contains a valid state. Otherwise, this field is undefined. |
| 700 | |
Paul Bolle | 68ba697 | 2011-02-15 00:05:59 +0100 | [diff] [blame] | 701 | 4.32 KVM_SET_VCPU_EVENTS |
Jan Kiszka | 3cfc309 | 2009-11-12 01:04:25 +0100 | [diff] [blame] | 702 | |
| 703 | Capability: KVM_CAP_VCPU_EVENTS |
Jan Kiszka | 48005f6 | 2010-02-19 19:38:07 +0100 | [diff] [blame] | 704 | Extended by: KVM_CAP_INTR_SHADOW |
Jan Kiszka | 3cfc309 | 2009-11-12 01:04:25 +0100 | [diff] [blame] | 705 | Architectures: x86 |
| 706 | Type: vm ioctl |
| 707 | Parameters: struct kvm_vcpu_event (in) |
| 708 | Returns: 0 on success, -1 on error |
| 709 | |
| 710 | Set pending exceptions, interrupts, and NMIs as well as related states of the |
| 711 | vcpu. |
| 712 | |
| 713 | See KVM_GET_VCPU_EVENTS for the data structure. |
| 714 | |
Jan Kiszka | dab4b91 | 2009-12-06 18:24:15 +0100 | [diff] [blame] | 715 | Fields that may be modified asynchronously by running VCPUs can be excluded |
| 716 | from the update. These fields are nmi.pending and sipi_vector. Keep the |
| 717 | corresponding bits in the flags field cleared to suppress overwriting the |
| 718 | current in-kernel state. The bits are: |
| 719 | |
| 720 | KVM_VCPUEVENT_VALID_NMI_PENDING - transfer nmi.pending to the kernel |
| 721 | KVM_VCPUEVENT_VALID_SIPI_VECTOR - transfer sipi_vector |
| 722 | |
Jan Kiszka | 48005f6 | 2010-02-19 19:38:07 +0100 | [diff] [blame] | 723 | If KVM_CAP_INTR_SHADOW is available, KVM_VCPUEVENT_VALID_SHADOW can be set in |
| 724 | the flags field to signal that interrupt.shadow contains a valid state and |
| 725 | shall be written into the VCPU. |
| 726 | |
Paul Bolle | 68ba697 | 2011-02-15 00:05:59 +0100 | [diff] [blame] | 727 | 4.33 KVM_GET_DEBUGREGS |
Jan Kiszka | a1efbe7 | 2010-02-15 10:45:43 +0100 | [diff] [blame] | 728 | |
| 729 | Capability: KVM_CAP_DEBUGREGS |
| 730 | Architectures: x86 |
| 731 | Type: vm ioctl |
| 732 | Parameters: struct kvm_debugregs (out) |
| 733 | Returns: 0 on success, -1 on error |
| 734 | |
| 735 | Reads debug registers from the vcpu. |
| 736 | |
| 737 | struct kvm_debugregs { |
| 738 | __u64 db[4]; |
| 739 | __u64 dr6; |
| 740 | __u64 dr7; |
| 741 | __u64 flags; |
| 742 | __u64 reserved[9]; |
| 743 | }; |
| 744 | |
Paul Bolle | 68ba697 | 2011-02-15 00:05:59 +0100 | [diff] [blame] | 745 | 4.34 KVM_SET_DEBUGREGS |
Jan Kiszka | a1efbe7 | 2010-02-15 10:45:43 +0100 | [diff] [blame] | 746 | |
| 747 | Capability: KVM_CAP_DEBUGREGS |
| 748 | Architectures: x86 |
| 749 | Type: vm ioctl |
| 750 | Parameters: struct kvm_debugregs (in) |
| 751 | Returns: 0 on success, -1 on error |
| 752 | |
| 753 | Writes debug registers into the vcpu. |
| 754 | |
| 755 | See KVM_GET_DEBUGREGS for the data structure. The flags field is unused |
| 756 | yet and must be cleared on entry. |
| 757 | |
Paul Bolle | 68ba697 | 2011-02-15 00:05:59 +0100 | [diff] [blame] | 758 | 4.35 KVM_SET_USER_MEMORY_REGION |
Avi Kivity | 0f2d8f4 | 2010-03-25 12:16:48 +0200 | [diff] [blame] | 759 | |
| 760 | Capability: KVM_CAP_USER_MEM |
| 761 | Architectures: all |
| 762 | Type: vm ioctl |
| 763 | Parameters: struct kvm_userspace_memory_region (in) |
| 764 | Returns: 0 on success, -1 on error |
| 765 | |
| 766 | struct kvm_userspace_memory_region { |
| 767 | __u32 slot; |
| 768 | __u32 flags; |
| 769 | __u64 guest_phys_addr; |
| 770 | __u64 memory_size; /* bytes */ |
| 771 | __u64 userspace_addr; /* start of the userspace allocated memory */ |
| 772 | }; |
| 773 | |
| 774 | /* for kvm_memory_region::flags */ |
| 775 | #define KVM_MEM_LOG_DIRTY_PAGES 1UL |
| 776 | |
| 777 | This ioctl allows the user to create or modify a guest physical memory |
| 778 | slot. When changing an existing slot, it may be moved in the guest |
| 779 | physical memory space, or its flags may be modified. It may not be |
| 780 | resized. Slots may not overlap in guest physical address space. |
| 781 | |
| 782 | Memory for the region is taken starting at the address denoted by the |
| 783 | field userspace_addr, which must point at user addressable memory for |
| 784 | the entire memory slot size. Any object may back this memory, including |
| 785 | anonymous memory, ordinary files, and hugetlbfs. |
| 786 | |
| 787 | It is recommended that the lower 21 bits of guest_phys_addr and userspace_addr |
| 788 | be identical. This allows large pages in the guest to be backed by large |
| 789 | pages in the host. |
| 790 | |
| 791 | The flags field supports just one flag, KVM_MEM_LOG_DIRTY_PAGES, which |
| 792 | instructs kvm to keep track of writes to memory within the slot. See |
| 793 | the KVM_GET_DIRTY_LOG ioctl. |
| 794 | |
| 795 | When the KVM_CAP_SYNC_MMU capability, changes in the backing of the memory |
| 796 | region are automatically reflected into the guest. For example, an mmap() |
| 797 | that affects the region will be made visible immediately. Another example |
| 798 | is madvise(MADV_DROP). |
| 799 | |
| 800 | It is recommended to use this API instead of the KVM_SET_MEMORY_REGION ioctl. |
| 801 | The KVM_SET_MEMORY_REGION does not allow fine grained control over memory |
| 802 | allocation and is deprecated. |
Jan Kiszka | 3cfc309 | 2009-11-12 01:04:25 +0100 | [diff] [blame] | 803 | |
Paul Bolle | 68ba697 | 2011-02-15 00:05:59 +0100 | [diff] [blame] | 804 | 4.36 KVM_SET_TSS_ADDR |
Avi Kivity | 8a5416d | 2010-03-25 12:27:30 +0200 | [diff] [blame] | 805 | |
| 806 | Capability: KVM_CAP_SET_TSS_ADDR |
| 807 | Architectures: x86 |
| 808 | Type: vm ioctl |
| 809 | Parameters: unsigned long tss_address (in) |
| 810 | Returns: 0 on success, -1 on error |
| 811 | |
| 812 | This ioctl defines the physical address of a three-page region in the guest |
| 813 | physical address space. The region must be within the first 4GB of the |
| 814 | guest physical address space and must not conflict with any memory slot |
| 815 | or any mmio address. The guest may malfunction if it accesses this memory |
| 816 | region. |
| 817 | |
| 818 | This ioctl is required on Intel-based hosts. This is needed on Intel hardware |
| 819 | because of a quirk in the virtualization implementation (see the internals |
| 820 | documentation when it pops into existence). |
| 821 | |
Paul Bolle | 68ba697 | 2011-02-15 00:05:59 +0100 | [diff] [blame] | 822 | 4.37 KVM_ENABLE_CAP |
Alexander Graf | 71fbfd5 | 2010-03-24 21:48:29 +0100 | [diff] [blame] | 823 | |
| 824 | Capability: KVM_CAP_ENABLE_CAP |
| 825 | Architectures: ppc |
| 826 | Type: vcpu ioctl |
| 827 | Parameters: struct kvm_enable_cap (in) |
| 828 | Returns: 0 on success; -1 on error |
| 829 | |
| 830 | +Not all extensions are enabled by default. Using this ioctl the application |
| 831 | can enable an extension, making it available to the guest. |
| 832 | |
| 833 | On systems that do not support this ioctl, it always fails. On systems that |
| 834 | do support it, it only works for extensions that are supported for enablement. |
| 835 | |
| 836 | To check if a capability can be enabled, the KVM_CHECK_EXTENSION ioctl should |
| 837 | be used. |
| 838 | |
| 839 | struct kvm_enable_cap { |
| 840 | /* in */ |
| 841 | __u32 cap; |
| 842 | |
| 843 | The capability that is supposed to get enabled. |
| 844 | |
| 845 | __u32 flags; |
| 846 | |
| 847 | A bitfield indicating future enhancements. Has to be 0 for now. |
| 848 | |
| 849 | __u64 args[4]; |
| 850 | |
| 851 | Arguments for enabling a feature. If a feature needs initial values to |
| 852 | function properly, this is the place to put them. |
| 853 | |
| 854 | __u8 pad[64]; |
| 855 | }; |
| 856 | |
Paul Bolle | 68ba697 | 2011-02-15 00:05:59 +0100 | [diff] [blame] | 857 | 4.38 KVM_GET_MP_STATE |
Avi Kivity | b843f06 | 2010-04-25 15:51:46 +0300 | [diff] [blame] | 858 | |
| 859 | Capability: KVM_CAP_MP_STATE |
| 860 | Architectures: x86, ia64 |
| 861 | Type: vcpu ioctl |
| 862 | Parameters: struct kvm_mp_state (out) |
| 863 | Returns: 0 on success; -1 on error |
| 864 | |
| 865 | struct kvm_mp_state { |
| 866 | __u32 mp_state; |
| 867 | }; |
| 868 | |
| 869 | Returns the vcpu's current "multiprocessing state" (though also valid on |
| 870 | uniprocessor guests). |
| 871 | |
| 872 | Possible values are: |
| 873 | |
| 874 | - KVM_MP_STATE_RUNNABLE: the vcpu is currently running |
| 875 | - KVM_MP_STATE_UNINITIALIZED: the vcpu is an application processor (AP) |
| 876 | which has not yet received an INIT signal |
| 877 | - KVM_MP_STATE_INIT_RECEIVED: the vcpu has received an INIT signal, and is |
| 878 | now ready for a SIPI |
| 879 | - KVM_MP_STATE_HALTED: the vcpu has executed a HLT instruction and |
| 880 | is waiting for an interrupt |
| 881 | - KVM_MP_STATE_SIPI_RECEIVED: the vcpu has just received a SIPI (vector |
Uwe Kleine-König | b595076 | 2010-11-01 15:38:34 -0400 | [diff] [blame] | 882 | accessible via KVM_GET_VCPU_EVENTS) |
Avi Kivity | b843f06 | 2010-04-25 15:51:46 +0300 | [diff] [blame] | 883 | |
| 884 | This ioctl is only useful after KVM_CREATE_IRQCHIP. Without an in-kernel |
| 885 | irqchip, the multiprocessing state must be maintained by userspace. |
| 886 | |
Paul Bolle | 68ba697 | 2011-02-15 00:05:59 +0100 | [diff] [blame] | 887 | 4.39 KVM_SET_MP_STATE |
Avi Kivity | b843f06 | 2010-04-25 15:51:46 +0300 | [diff] [blame] | 888 | |
| 889 | Capability: KVM_CAP_MP_STATE |
| 890 | Architectures: x86, ia64 |
| 891 | Type: vcpu ioctl |
| 892 | Parameters: struct kvm_mp_state (in) |
| 893 | Returns: 0 on success; -1 on error |
| 894 | |
| 895 | Sets the vcpu's current "multiprocessing state"; see KVM_GET_MP_STATE for |
| 896 | arguments. |
| 897 | |
| 898 | This ioctl is only useful after KVM_CREATE_IRQCHIP. Without an in-kernel |
| 899 | irqchip, the multiprocessing state must be maintained by userspace. |
| 900 | |
Paul Bolle | 68ba697 | 2011-02-15 00:05:59 +0100 | [diff] [blame] | 901 | 4.40 KVM_SET_IDENTITY_MAP_ADDR |
Avi Kivity | 47dbb84 | 2010-04-29 12:08:56 +0300 | [diff] [blame] | 902 | |
| 903 | Capability: KVM_CAP_SET_IDENTITY_MAP_ADDR |
| 904 | Architectures: x86 |
| 905 | Type: vm ioctl |
| 906 | Parameters: unsigned long identity (in) |
| 907 | Returns: 0 on success, -1 on error |
| 908 | |
| 909 | This ioctl defines the physical address of a one-page region in the guest |
| 910 | physical address space. The region must be within the first 4GB of the |
| 911 | guest physical address space and must not conflict with any memory slot |
| 912 | or any mmio address. The guest may malfunction if it accesses this memory |
| 913 | region. |
| 914 | |
| 915 | This ioctl is required on Intel-based hosts. This is needed on Intel hardware |
| 916 | because of a quirk in the virtualization implementation (see the internals |
| 917 | documentation when it pops into existence). |
| 918 | |
Paul Bolle | 68ba697 | 2011-02-15 00:05:59 +0100 | [diff] [blame] | 919 | 4.41 KVM_SET_BOOT_CPU_ID |
Avi Kivity | 57bc24c | 2010-04-29 12:12:57 +0300 | [diff] [blame] | 920 | |
| 921 | Capability: KVM_CAP_SET_BOOT_CPU_ID |
| 922 | Architectures: x86, ia64 |
| 923 | Type: vm ioctl |
| 924 | Parameters: unsigned long vcpu_id |
| 925 | Returns: 0 on success, -1 on error |
| 926 | |
| 927 | Define which vcpu is the Bootstrap Processor (BSP). Values are the same |
| 928 | as the vcpu id in KVM_CREATE_VCPU. If this ioctl is not called, the default |
| 929 | is vcpu 0. |
| 930 | |
Paul Bolle | 68ba697 | 2011-02-15 00:05:59 +0100 | [diff] [blame] | 931 | 4.42 KVM_GET_XSAVE |
Sheng Yang | 2d5b5a6 | 2010-06-13 17:29:39 +0800 | [diff] [blame] | 932 | |
| 933 | Capability: KVM_CAP_XSAVE |
| 934 | Architectures: x86 |
| 935 | Type: vcpu ioctl |
| 936 | Parameters: struct kvm_xsave (out) |
| 937 | Returns: 0 on success, -1 on error |
| 938 | |
| 939 | struct kvm_xsave { |
| 940 | __u32 region[1024]; |
| 941 | }; |
| 942 | |
| 943 | This ioctl would copy current vcpu's xsave struct to the userspace. |
| 944 | |
Paul Bolle | 68ba697 | 2011-02-15 00:05:59 +0100 | [diff] [blame] | 945 | 4.43 KVM_SET_XSAVE |
Sheng Yang | 2d5b5a6 | 2010-06-13 17:29:39 +0800 | [diff] [blame] | 946 | |
| 947 | Capability: KVM_CAP_XSAVE |
| 948 | Architectures: x86 |
| 949 | Type: vcpu ioctl |
| 950 | Parameters: struct kvm_xsave (in) |
| 951 | Returns: 0 on success, -1 on error |
| 952 | |
| 953 | struct kvm_xsave { |
| 954 | __u32 region[1024]; |
| 955 | }; |
| 956 | |
| 957 | This ioctl would copy userspace's xsave struct to the kernel. |
| 958 | |
Paul Bolle | 68ba697 | 2011-02-15 00:05:59 +0100 | [diff] [blame] | 959 | 4.44 KVM_GET_XCRS |
Sheng Yang | 2d5b5a6 | 2010-06-13 17:29:39 +0800 | [diff] [blame] | 960 | |
| 961 | Capability: KVM_CAP_XCRS |
| 962 | Architectures: x86 |
| 963 | Type: vcpu ioctl |
| 964 | Parameters: struct kvm_xcrs (out) |
| 965 | Returns: 0 on success, -1 on error |
| 966 | |
| 967 | struct kvm_xcr { |
| 968 | __u32 xcr; |
| 969 | __u32 reserved; |
| 970 | __u64 value; |
| 971 | }; |
| 972 | |
| 973 | struct kvm_xcrs { |
| 974 | __u32 nr_xcrs; |
| 975 | __u32 flags; |
| 976 | struct kvm_xcr xcrs[KVM_MAX_XCRS]; |
| 977 | __u64 padding[16]; |
| 978 | }; |
| 979 | |
| 980 | This ioctl would copy current vcpu's xcrs to the userspace. |
| 981 | |
Paul Bolle | 68ba697 | 2011-02-15 00:05:59 +0100 | [diff] [blame] | 982 | 4.45 KVM_SET_XCRS |
Sheng Yang | 2d5b5a6 | 2010-06-13 17:29:39 +0800 | [diff] [blame] | 983 | |
| 984 | Capability: KVM_CAP_XCRS |
| 985 | Architectures: x86 |
| 986 | Type: vcpu ioctl |
| 987 | Parameters: struct kvm_xcrs (in) |
| 988 | Returns: 0 on success, -1 on error |
| 989 | |
| 990 | struct kvm_xcr { |
| 991 | __u32 xcr; |
| 992 | __u32 reserved; |
| 993 | __u64 value; |
| 994 | }; |
| 995 | |
| 996 | struct kvm_xcrs { |
| 997 | __u32 nr_xcrs; |
| 998 | __u32 flags; |
| 999 | struct kvm_xcr xcrs[KVM_MAX_XCRS]; |
| 1000 | __u64 padding[16]; |
| 1001 | }; |
| 1002 | |
| 1003 | This ioctl would set vcpu's xcr to the value userspace specified. |
| 1004 | |
Paul Bolle | 68ba697 | 2011-02-15 00:05:59 +0100 | [diff] [blame] | 1005 | 4.46 KVM_GET_SUPPORTED_CPUID |
Avi Kivity | d153513 | 2010-07-14 09:45:21 +0300 | [diff] [blame] | 1006 | |
| 1007 | Capability: KVM_CAP_EXT_CPUID |
| 1008 | Architectures: x86 |
| 1009 | Type: system ioctl |
| 1010 | Parameters: struct kvm_cpuid2 (in/out) |
| 1011 | Returns: 0 on success, -1 on error |
| 1012 | |
| 1013 | struct kvm_cpuid2 { |
| 1014 | __u32 nent; |
| 1015 | __u32 padding; |
| 1016 | struct kvm_cpuid_entry2 entries[0]; |
| 1017 | }; |
| 1018 | |
| 1019 | #define KVM_CPUID_FLAG_SIGNIFCANT_INDEX 1 |
| 1020 | #define KVM_CPUID_FLAG_STATEFUL_FUNC 2 |
| 1021 | #define KVM_CPUID_FLAG_STATE_READ_NEXT 4 |
| 1022 | |
| 1023 | struct kvm_cpuid_entry2 { |
| 1024 | __u32 function; |
| 1025 | __u32 index; |
| 1026 | __u32 flags; |
| 1027 | __u32 eax; |
| 1028 | __u32 ebx; |
| 1029 | __u32 ecx; |
| 1030 | __u32 edx; |
| 1031 | __u32 padding[3]; |
| 1032 | }; |
| 1033 | |
| 1034 | This ioctl returns x86 cpuid features which are supported by both the hardware |
| 1035 | and kvm. Userspace can use the information returned by this ioctl to |
| 1036 | construct cpuid information (for KVM_SET_CPUID2) that is consistent with |
| 1037 | hardware, kernel, and userspace capabilities, and with user requirements (for |
| 1038 | example, the user may wish to constrain cpuid to emulate older hardware, |
| 1039 | or for feature consistency across a cluster). |
| 1040 | |
| 1041 | Userspace invokes KVM_GET_SUPPORTED_CPUID by passing a kvm_cpuid2 structure |
| 1042 | with the 'nent' field indicating the number of entries in the variable-size |
| 1043 | array 'entries'. If the number of entries is too low to describe the cpu |
| 1044 | capabilities, an error (E2BIG) is returned. If the number is too high, |
| 1045 | the 'nent' field is adjusted and an error (ENOMEM) is returned. If the |
| 1046 | number is just right, the 'nent' field is adjusted to the number of valid |
| 1047 | entries in the 'entries' array, which is then filled. |
| 1048 | |
| 1049 | The entries returned are the host cpuid as returned by the cpuid instruction, |
Avi Kivity | c39cbd2 | 2010-09-12 16:39:11 +0200 | [diff] [blame] | 1050 | with unknown or unsupported features masked out. Some features (for example, |
| 1051 | x2apic), may not be present in the host cpu, but are exposed by kvm if it can |
| 1052 | emulate them efficiently. The fields in each entry are defined as follows: |
Avi Kivity | d153513 | 2010-07-14 09:45:21 +0300 | [diff] [blame] | 1053 | |
| 1054 | function: the eax value used to obtain the entry |
| 1055 | index: the ecx value used to obtain the entry (for entries that are |
| 1056 | affected by ecx) |
| 1057 | flags: an OR of zero or more of the following: |
| 1058 | KVM_CPUID_FLAG_SIGNIFCANT_INDEX: |
| 1059 | if the index field is valid |
| 1060 | KVM_CPUID_FLAG_STATEFUL_FUNC: |
| 1061 | if cpuid for this function returns different values for successive |
| 1062 | invocations; there will be several entries with the same function, |
| 1063 | all with this flag set |
| 1064 | KVM_CPUID_FLAG_STATE_READ_NEXT: |
| 1065 | for KVM_CPUID_FLAG_STATEFUL_FUNC entries, set if this entry is |
| 1066 | the first entry to be read by a cpu |
| 1067 | eax, ebx, ecx, edx: the values returned by the cpuid instruction for |
| 1068 | this function/index combination |
| 1069 | |
Paul Bolle | 68ba697 | 2011-02-15 00:05:59 +0100 | [diff] [blame] | 1070 | 4.47 KVM_PPC_GET_PVINFO |
Alexander Graf | 15711e9 | 2010-07-29 14:48:08 +0200 | [diff] [blame] | 1071 | |
| 1072 | Capability: KVM_CAP_PPC_GET_PVINFO |
| 1073 | Architectures: ppc |
| 1074 | Type: vm ioctl |
| 1075 | Parameters: struct kvm_ppc_pvinfo (out) |
| 1076 | Returns: 0 on success, !0 on error |
| 1077 | |
| 1078 | struct kvm_ppc_pvinfo { |
| 1079 | __u32 flags; |
| 1080 | __u32 hcall[4]; |
| 1081 | __u8 pad[108]; |
| 1082 | }; |
| 1083 | |
| 1084 | This ioctl fetches PV specific information that need to be passed to the guest |
| 1085 | using the device tree or other means from vm context. |
| 1086 | |
| 1087 | For now the only implemented piece of information distributed here is an array |
| 1088 | of 4 instructions that make up a hypercall. |
| 1089 | |
| 1090 | If any additional field gets added to this structure later on, a bit for that |
| 1091 | additional piece of information will be set in the flags bitmap. |
| 1092 | |
Paul Bolle | 68ba697 | 2011-02-15 00:05:59 +0100 | [diff] [blame] | 1093 | 4.48 KVM_ASSIGN_PCI_DEVICE |
Jan Kiszka | 49f4817 | 2010-11-16 22:30:07 +0100 | [diff] [blame] | 1094 | |
| 1095 | Capability: KVM_CAP_DEVICE_ASSIGNMENT |
| 1096 | Architectures: x86 ia64 |
| 1097 | Type: vm ioctl |
| 1098 | Parameters: struct kvm_assigned_pci_dev (in) |
| 1099 | Returns: 0 on success, -1 on error |
| 1100 | |
| 1101 | Assigns a host PCI device to the VM. |
| 1102 | |
| 1103 | struct kvm_assigned_pci_dev { |
| 1104 | __u32 assigned_dev_id; |
| 1105 | __u32 busnr; |
| 1106 | __u32 devfn; |
| 1107 | __u32 flags; |
| 1108 | __u32 segnr; |
| 1109 | union { |
| 1110 | __u32 reserved[11]; |
| 1111 | }; |
| 1112 | }; |
| 1113 | |
| 1114 | The PCI device is specified by the triple segnr, busnr, and devfn. |
| 1115 | Identification in succeeding service requests is done via assigned_dev_id. The |
| 1116 | following flags are specified: |
| 1117 | |
| 1118 | /* Depends on KVM_CAP_IOMMU */ |
| 1119 | #define KVM_DEV_ASSIGN_ENABLE_IOMMU (1 << 0) |
| 1120 | |
Paul Bolle | 68ba697 | 2011-02-15 00:05:59 +0100 | [diff] [blame] | 1121 | 4.49 KVM_DEASSIGN_PCI_DEVICE |
Jan Kiszka | 49f4817 | 2010-11-16 22:30:07 +0100 | [diff] [blame] | 1122 | |
| 1123 | Capability: KVM_CAP_DEVICE_DEASSIGNMENT |
| 1124 | Architectures: x86 ia64 |
| 1125 | Type: vm ioctl |
| 1126 | Parameters: struct kvm_assigned_pci_dev (in) |
| 1127 | Returns: 0 on success, -1 on error |
| 1128 | |
| 1129 | Ends PCI device assignment, releasing all associated resources. |
| 1130 | |
| 1131 | See KVM_CAP_DEVICE_ASSIGNMENT for the data structure. Only assigned_dev_id is |
| 1132 | used in kvm_assigned_pci_dev to identify the device. |
| 1133 | |
Paul Bolle | 68ba697 | 2011-02-15 00:05:59 +0100 | [diff] [blame] | 1134 | 4.50 KVM_ASSIGN_DEV_IRQ |
Jan Kiszka | 49f4817 | 2010-11-16 22:30:07 +0100 | [diff] [blame] | 1135 | |
| 1136 | Capability: KVM_CAP_ASSIGN_DEV_IRQ |
| 1137 | Architectures: x86 ia64 |
| 1138 | Type: vm ioctl |
| 1139 | Parameters: struct kvm_assigned_irq (in) |
| 1140 | Returns: 0 on success, -1 on error |
| 1141 | |
| 1142 | Assigns an IRQ to a passed-through device. |
| 1143 | |
| 1144 | struct kvm_assigned_irq { |
| 1145 | __u32 assigned_dev_id; |
| 1146 | __u32 host_irq; |
| 1147 | __u32 guest_irq; |
| 1148 | __u32 flags; |
| 1149 | union { |
| 1150 | struct { |
| 1151 | __u32 addr_lo; |
| 1152 | __u32 addr_hi; |
| 1153 | __u32 data; |
| 1154 | } guest_msi; |
| 1155 | __u32 reserved[12]; |
| 1156 | }; |
| 1157 | }; |
| 1158 | |
| 1159 | The following flags are defined: |
| 1160 | |
| 1161 | #define KVM_DEV_IRQ_HOST_INTX (1 << 0) |
| 1162 | #define KVM_DEV_IRQ_HOST_MSI (1 << 1) |
| 1163 | #define KVM_DEV_IRQ_HOST_MSIX (1 << 2) |
| 1164 | |
| 1165 | #define KVM_DEV_IRQ_GUEST_INTX (1 << 8) |
| 1166 | #define KVM_DEV_IRQ_GUEST_MSI (1 << 9) |
| 1167 | #define KVM_DEV_IRQ_GUEST_MSIX (1 << 10) |
| 1168 | |
| 1169 | It is not valid to specify multiple types per host or guest IRQ. However, the |
| 1170 | IRQ type of host and guest can differ or can even be null. |
| 1171 | |
Paul Bolle | 68ba697 | 2011-02-15 00:05:59 +0100 | [diff] [blame] | 1172 | 4.51 KVM_DEASSIGN_DEV_IRQ |
Jan Kiszka | 49f4817 | 2010-11-16 22:30:07 +0100 | [diff] [blame] | 1173 | |
| 1174 | Capability: KVM_CAP_ASSIGN_DEV_IRQ |
| 1175 | Architectures: x86 ia64 |
| 1176 | Type: vm ioctl |
| 1177 | Parameters: struct kvm_assigned_irq (in) |
| 1178 | Returns: 0 on success, -1 on error |
| 1179 | |
| 1180 | Ends an IRQ assignment to a passed-through device. |
| 1181 | |
| 1182 | See KVM_ASSIGN_DEV_IRQ for the data structure. The target device is specified |
| 1183 | by assigned_dev_id, flags must correspond to the IRQ type specified on |
| 1184 | KVM_ASSIGN_DEV_IRQ. Partial deassignment of host or guest IRQ is allowed. |
| 1185 | |
Paul Bolle | 68ba697 | 2011-02-15 00:05:59 +0100 | [diff] [blame] | 1186 | 4.52 KVM_SET_GSI_ROUTING |
Jan Kiszka | 49f4817 | 2010-11-16 22:30:07 +0100 | [diff] [blame] | 1187 | |
| 1188 | Capability: KVM_CAP_IRQ_ROUTING |
| 1189 | Architectures: x86 ia64 |
| 1190 | Type: vm ioctl |
| 1191 | Parameters: struct kvm_irq_routing (in) |
| 1192 | Returns: 0 on success, -1 on error |
| 1193 | |
| 1194 | Sets the GSI routing table entries, overwriting any previously set entries. |
| 1195 | |
| 1196 | struct kvm_irq_routing { |
| 1197 | __u32 nr; |
| 1198 | __u32 flags; |
| 1199 | struct kvm_irq_routing_entry entries[0]; |
| 1200 | }; |
| 1201 | |
| 1202 | No flags are specified so far, the corresponding field must be set to zero. |
| 1203 | |
| 1204 | struct kvm_irq_routing_entry { |
| 1205 | __u32 gsi; |
| 1206 | __u32 type; |
| 1207 | __u32 flags; |
| 1208 | __u32 pad; |
| 1209 | union { |
| 1210 | struct kvm_irq_routing_irqchip irqchip; |
| 1211 | struct kvm_irq_routing_msi msi; |
| 1212 | __u32 pad[8]; |
| 1213 | } u; |
| 1214 | }; |
| 1215 | |
| 1216 | /* gsi routing entry types */ |
| 1217 | #define KVM_IRQ_ROUTING_IRQCHIP 1 |
| 1218 | #define KVM_IRQ_ROUTING_MSI 2 |
| 1219 | |
| 1220 | No flags are specified so far, the corresponding field must be set to zero. |
| 1221 | |
| 1222 | struct kvm_irq_routing_irqchip { |
| 1223 | __u32 irqchip; |
| 1224 | __u32 pin; |
| 1225 | }; |
| 1226 | |
| 1227 | struct kvm_irq_routing_msi { |
| 1228 | __u32 address_lo; |
| 1229 | __u32 address_hi; |
| 1230 | __u32 data; |
| 1231 | __u32 pad; |
| 1232 | }; |
| 1233 | |
Paul Bolle | 68ba697 | 2011-02-15 00:05:59 +0100 | [diff] [blame] | 1234 | 4.53 KVM_ASSIGN_SET_MSIX_NR |
Jan Kiszka | 49f4817 | 2010-11-16 22:30:07 +0100 | [diff] [blame] | 1235 | |
| 1236 | Capability: KVM_CAP_DEVICE_MSIX |
| 1237 | Architectures: x86 ia64 |
| 1238 | Type: vm ioctl |
| 1239 | Parameters: struct kvm_assigned_msix_nr (in) |
| 1240 | Returns: 0 on success, -1 on error |
| 1241 | |
| 1242 | Set the number of MSI-X interrupts for an assigned device. This service can |
| 1243 | only be called once in the lifetime of an assigned device. |
| 1244 | |
| 1245 | struct kvm_assigned_msix_nr { |
| 1246 | __u32 assigned_dev_id; |
| 1247 | __u16 entry_nr; |
| 1248 | __u16 padding; |
| 1249 | }; |
| 1250 | |
| 1251 | #define KVM_MAX_MSIX_PER_DEV 256 |
| 1252 | |
Paul Bolle | 68ba697 | 2011-02-15 00:05:59 +0100 | [diff] [blame] | 1253 | 4.54 KVM_ASSIGN_SET_MSIX_ENTRY |
Jan Kiszka | 49f4817 | 2010-11-16 22:30:07 +0100 | [diff] [blame] | 1254 | |
| 1255 | Capability: KVM_CAP_DEVICE_MSIX |
| 1256 | Architectures: x86 ia64 |
| 1257 | Type: vm ioctl |
| 1258 | Parameters: struct kvm_assigned_msix_entry (in) |
| 1259 | Returns: 0 on success, -1 on error |
| 1260 | |
| 1261 | Specifies the routing of an MSI-X assigned device interrupt to a GSI. Setting |
| 1262 | the GSI vector to zero means disabling the interrupt. |
| 1263 | |
| 1264 | struct kvm_assigned_msix_entry { |
| 1265 | __u32 assigned_dev_id; |
| 1266 | __u32 gsi; |
| 1267 | __u16 entry; /* The index of entry in the MSI-X table */ |
| 1268 | __u16 padding[3]; |
| 1269 | }; |
| 1270 | |
Joerg Roedel | 92a1f12 | 2011-03-25 09:44:51 +0100 | [diff] [blame] | 1271 | 4.54 KVM_SET_TSC_KHZ |
| 1272 | |
| 1273 | Capability: KVM_CAP_TSC_CONTROL |
| 1274 | Architectures: x86 |
| 1275 | Type: vcpu ioctl |
| 1276 | Parameters: virtual tsc_khz |
| 1277 | Returns: 0 on success, -1 on error |
| 1278 | |
| 1279 | Specifies the tsc frequency for the virtual machine. The unit of the |
| 1280 | frequency is KHz. |
| 1281 | |
| 1282 | 4.55 KVM_GET_TSC_KHZ |
| 1283 | |
| 1284 | Capability: KVM_CAP_GET_TSC_KHZ |
| 1285 | Architectures: x86 |
| 1286 | Type: vcpu ioctl |
| 1287 | Parameters: none |
| 1288 | Returns: virtual tsc-khz on success, negative value on error |
| 1289 | |
| 1290 | Returns the tsc frequency of the guest. The unit of the return value is |
| 1291 | KHz. If the host has unstable tsc this ioctl returns -EIO instead as an |
| 1292 | error. |
| 1293 | |
Avi Kivity | e767793 | 2011-05-11 08:30:51 -0400 | [diff] [blame^] | 1294 | 4.56 KVM_GET_LAPIC |
| 1295 | |
| 1296 | Capability: KVM_CAP_IRQCHIP |
| 1297 | Architectures: x86 |
| 1298 | Type: vcpu ioctl |
| 1299 | Parameters: struct kvm_lapic_state (out) |
| 1300 | Returns: 0 on success, -1 on error |
| 1301 | |
| 1302 | #define KVM_APIC_REG_SIZE 0x400 |
| 1303 | struct kvm_lapic_state { |
| 1304 | char regs[KVM_APIC_REG_SIZE]; |
| 1305 | }; |
| 1306 | |
| 1307 | Reads the Local APIC registers and copies them into the input argument. The |
| 1308 | data format and layout are the same as documented in the architecture manual. |
| 1309 | |
| 1310 | 4.57 KVM_SET_LAPIC |
| 1311 | |
| 1312 | Capability: KVM_CAP_IRQCHIP |
| 1313 | Architectures: x86 |
| 1314 | Type: vcpu ioctl |
| 1315 | Parameters: struct kvm_lapic_state (in) |
| 1316 | Returns: 0 on success, -1 on error |
| 1317 | |
| 1318 | #define KVM_APIC_REG_SIZE 0x400 |
| 1319 | struct kvm_lapic_state { |
| 1320 | char regs[KVM_APIC_REG_SIZE]; |
| 1321 | }; |
| 1322 | |
| 1323 | Copies the input argument into the the Local APIC registers. The data format |
| 1324 | and layout are the same as documented in the architecture manual. |
| 1325 | |
Avi Kivity | 9c1b96e | 2009-06-09 12:37:58 +0300 | [diff] [blame] | 1326 | 5. The kvm_run structure |
| 1327 | |
| 1328 | Application code obtains a pointer to the kvm_run structure by |
| 1329 | mmap()ing a vcpu fd. From that point, application code can control |
| 1330 | execution by changing fields in kvm_run prior to calling the KVM_RUN |
| 1331 | ioctl, and obtain information about the reason KVM_RUN returned by |
| 1332 | looking up structure members. |
| 1333 | |
| 1334 | struct kvm_run { |
| 1335 | /* in */ |
| 1336 | __u8 request_interrupt_window; |
| 1337 | |
| 1338 | Request that KVM_RUN return when it becomes possible to inject external |
| 1339 | interrupts into the guest. Useful in conjunction with KVM_INTERRUPT. |
| 1340 | |
| 1341 | __u8 padding1[7]; |
| 1342 | |
| 1343 | /* out */ |
| 1344 | __u32 exit_reason; |
| 1345 | |
| 1346 | When KVM_RUN has returned successfully (return value 0), this informs |
| 1347 | application code why KVM_RUN has returned. Allowable values for this |
| 1348 | field are detailed below. |
| 1349 | |
| 1350 | __u8 ready_for_interrupt_injection; |
| 1351 | |
| 1352 | If request_interrupt_window has been specified, this field indicates |
| 1353 | an interrupt can be injected now with KVM_INTERRUPT. |
| 1354 | |
| 1355 | __u8 if_flag; |
| 1356 | |
| 1357 | The value of the current interrupt flag. Only valid if in-kernel |
| 1358 | local APIC is not used. |
| 1359 | |
| 1360 | __u8 padding2[2]; |
| 1361 | |
| 1362 | /* in (pre_kvm_run), out (post_kvm_run) */ |
| 1363 | __u64 cr8; |
| 1364 | |
| 1365 | The value of the cr8 register. Only valid if in-kernel local APIC is |
| 1366 | not used. Both input and output. |
| 1367 | |
| 1368 | __u64 apic_base; |
| 1369 | |
| 1370 | The value of the APIC BASE msr. Only valid if in-kernel local |
| 1371 | APIC is not used. Both input and output. |
| 1372 | |
| 1373 | union { |
| 1374 | /* KVM_EXIT_UNKNOWN */ |
| 1375 | struct { |
| 1376 | __u64 hardware_exit_reason; |
| 1377 | } hw; |
| 1378 | |
| 1379 | If exit_reason is KVM_EXIT_UNKNOWN, the vcpu has exited due to unknown |
| 1380 | reasons. Further architecture-specific information is available in |
| 1381 | hardware_exit_reason. |
| 1382 | |
| 1383 | /* KVM_EXIT_FAIL_ENTRY */ |
| 1384 | struct { |
| 1385 | __u64 hardware_entry_failure_reason; |
| 1386 | } fail_entry; |
| 1387 | |
| 1388 | If exit_reason is KVM_EXIT_FAIL_ENTRY, the vcpu could not be run due |
| 1389 | to unknown reasons. Further architecture-specific information is |
| 1390 | available in hardware_entry_failure_reason. |
| 1391 | |
| 1392 | /* KVM_EXIT_EXCEPTION */ |
| 1393 | struct { |
| 1394 | __u32 exception; |
| 1395 | __u32 error_code; |
| 1396 | } ex; |
| 1397 | |
| 1398 | Unused. |
| 1399 | |
| 1400 | /* KVM_EXIT_IO */ |
| 1401 | struct { |
| 1402 | #define KVM_EXIT_IO_IN 0 |
| 1403 | #define KVM_EXIT_IO_OUT 1 |
| 1404 | __u8 direction; |
| 1405 | __u8 size; /* bytes */ |
| 1406 | __u16 port; |
| 1407 | __u32 count; |
| 1408 | __u64 data_offset; /* relative to kvm_run start */ |
| 1409 | } io; |
| 1410 | |
Wu Fengguang | 2044892d | 2009-12-24 09:04:16 +0800 | [diff] [blame] | 1411 | If exit_reason is KVM_EXIT_IO, then the vcpu has |
Avi Kivity | 9c1b96e | 2009-06-09 12:37:58 +0300 | [diff] [blame] | 1412 | executed a port I/O instruction which could not be satisfied by kvm. |
| 1413 | data_offset describes where the data is located (KVM_EXIT_IO_OUT) or |
| 1414 | where kvm expects application code to place the data for the next |
Wu Fengguang | 2044892d | 2009-12-24 09:04:16 +0800 | [diff] [blame] | 1415 | KVM_RUN invocation (KVM_EXIT_IO_IN). Data format is a packed array. |
Avi Kivity | 9c1b96e | 2009-06-09 12:37:58 +0300 | [diff] [blame] | 1416 | |
| 1417 | struct { |
| 1418 | struct kvm_debug_exit_arch arch; |
| 1419 | } debug; |
| 1420 | |
| 1421 | Unused. |
| 1422 | |
| 1423 | /* KVM_EXIT_MMIO */ |
| 1424 | struct { |
| 1425 | __u64 phys_addr; |
| 1426 | __u8 data[8]; |
| 1427 | __u32 len; |
| 1428 | __u8 is_write; |
| 1429 | } mmio; |
| 1430 | |
Wu Fengguang | 2044892d | 2009-12-24 09:04:16 +0800 | [diff] [blame] | 1431 | If exit_reason is KVM_EXIT_MMIO, then the vcpu has |
Avi Kivity | 9c1b96e | 2009-06-09 12:37:58 +0300 | [diff] [blame] | 1432 | executed a memory-mapped I/O instruction which could not be satisfied |
| 1433 | by kvm. The 'data' member contains the written data if 'is_write' is |
| 1434 | true, and should be filled by application code otherwise. |
| 1435 | |
Alexander Graf | ad0a048 | 2010-03-24 21:48:30 +0100 | [diff] [blame] | 1436 | NOTE: For KVM_EXIT_IO, KVM_EXIT_MMIO and KVM_EXIT_OSI, the corresponding |
| 1437 | operations are complete (and guest state is consistent) only after userspace |
| 1438 | has re-entered the kernel with KVM_RUN. The kernel side will first finish |
Marcelo Tosatti | 6796134 | 2010-02-13 16:10:26 -0200 | [diff] [blame] | 1439 | incomplete operations and then check for pending signals. Userspace |
| 1440 | can re-enter the guest with an unmasked signal pending to complete |
| 1441 | pending operations. |
| 1442 | |
Avi Kivity | 9c1b96e | 2009-06-09 12:37:58 +0300 | [diff] [blame] | 1443 | /* KVM_EXIT_HYPERCALL */ |
| 1444 | struct { |
| 1445 | __u64 nr; |
| 1446 | __u64 args[6]; |
| 1447 | __u64 ret; |
| 1448 | __u32 longmode; |
| 1449 | __u32 pad; |
| 1450 | } hypercall; |
| 1451 | |
Avi Kivity | 647dc49 | 2010-04-01 14:39:21 +0300 | [diff] [blame] | 1452 | Unused. This was once used for 'hypercall to userspace'. To implement |
| 1453 | such functionality, use KVM_EXIT_IO (x86) or KVM_EXIT_MMIO (all except s390). |
| 1454 | Note KVM_EXIT_IO is significantly faster than KVM_EXIT_MMIO. |
Avi Kivity | 9c1b96e | 2009-06-09 12:37:58 +0300 | [diff] [blame] | 1455 | |
| 1456 | /* KVM_EXIT_TPR_ACCESS */ |
| 1457 | struct { |
| 1458 | __u64 rip; |
| 1459 | __u32 is_write; |
| 1460 | __u32 pad; |
| 1461 | } tpr_access; |
| 1462 | |
| 1463 | To be documented (KVM_TPR_ACCESS_REPORTING). |
| 1464 | |
| 1465 | /* KVM_EXIT_S390_SIEIC */ |
| 1466 | struct { |
| 1467 | __u8 icptcode; |
| 1468 | __u64 mask; /* psw upper half */ |
| 1469 | __u64 addr; /* psw lower half */ |
| 1470 | __u16 ipa; |
| 1471 | __u32 ipb; |
| 1472 | } s390_sieic; |
| 1473 | |
| 1474 | s390 specific. |
| 1475 | |
| 1476 | /* KVM_EXIT_S390_RESET */ |
| 1477 | #define KVM_S390_RESET_POR 1 |
| 1478 | #define KVM_S390_RESET_CLEAR 2 |
| 1479 | #define KVM_S390_RESET_SUBSYSTEM 4 |
| 1480 | #define KVM_S390_RESET_CPU_INIT 8 |
| 1481 | #define KVM_S390_RESET_IPL 16 |
| 1482 | __u64 s390_reset_flags; |
| 1483 | |
| 1484 | s390 specific. |
| 1485 | |
| 1486 | /* KVM_EXIT_DCR */ |
| 1487 | struct { |
| 1488 | __u32 dcrn; |
| 1489 | __u32 data; |
| 1490 | __u8 is_write; |
| 1491 | } dcr; |
| 1492 | |
| 1493 | powerpc specific. |
| 1494 | |
Alexander Graf | ad0a048 | 2010-03-24 21:48:30 +0100 | [diff] [blame] | 1495 | /* KVM_EXIT_OSI */ |
| 1496 | struct { |
| 1497 | __u64 gprs[32]; |
| 1498 | } osi; |
| 1499 | |
| 1500 | MOL uses a special hypercall interface it calls 'OSI'. To enable it, we catch |
| 1501 | hypercalls and exit with this exit struct that contains all the guest gprs. |
| 1502 | |
| 1503 | If exit_reason is KVM_EXIT_OSI, then the vcpu has triggered such a hypercall. |
| 1504 | Userspace can now handle the hypercall and when it's done modify the gprs as |
| 1505 | necessary. Upon guest entry all guest GPRs will then be replaced by the values |
| 1506 | in this struct. |
| 1507 | |
Avi Kivity | 9c1b96e | 2009-06-09 12:37:58 +0300 | [diff] [blame] | 1508 | /* Fix the size of the union. */ |
| 1509 | char padding[256]; |
| 1510 | }; |
| 1511 | }; |