1.. SPDX-License-Identifier: GPL-2.0 2 3=================================================================== 4The Definitive KVM (Kernel-based Virtual Machine) API Documentation 5=================================================================== 6 71. General description 8====================== 9 10The kvm API is a set of ioctls that are issued to control various aspects 11of a virtual machine. The ioctls belong to the following classes: 12 13 - System ioctls: These query and set global attributes which affect the 14 whole kvm subsystem. In addition a system ioctl is used to create 15 virtual machines. 16 17 - VM ioctls: These query and set attributes that affect an entire virtual 18 machine, for example memory layout. In addition a VM ioctl is used to 19 create virtual cpus (vcpus) and devices. 20 21 VM ioctls must be issued from the same process (address space) that was 22 used to create the VM. 23 24 - vcpu ioctls: These query and set attributes that control the operation 25 of a single virtual cpu. 26 27 vcpu ioctls should be issued from the same thread that was used to create 28 the vcpu, except for asynchronous vcpu ioctl that are marked as such in 29 the documentation. Otherwise, the first ioctl after switching threads 30 could see a performance impact. 31 32 - device ioctls: These query and set attributes that control the operation 33 of a single device. 34 35 device ioctls must be issued from the same process (address space) that 36 was used to create the VM. 37 382. File descriptors 39=================== 40 41The kvm API is centered around file descriptors. An initial 42open("/dev/kvm") obtains a handle to the kvm subsystem; this handle 43can be used to issue system ioctls. A KVM_CREATE_VM ioctl on this 44handle will create a VM file descriptor which can be used to issue VM 45ioctls. A KVM_CREATE_VCPU or KVM_CREATE_DEVICE ioctl on a VM fd will 46create a virtual cpu or device and return a file descriptor pointing to 47the new resource. Finally, ioctls on a vcpu or device fd can be used 48to control the vcpu or device. For vcpus, this includes the important 49task of actually running guest code. 50 51In general file descriptors can be migrated among processes by means 52of fork() and the SCM_RIGHTS facility of unix domain socket. These 53kinds of tricks are explicitly not supported by kvm. While they will 54not cause harm to the host, their actual behavior is not guaranteed by 55the API. See "General description" for details on the ioctl usage 56model that is supported by KVM. 57 58It is important to note that although VM ioctls may only be issued from 59the process that created the VM, a VM's lifecycle is associated with its 60file descriptor, not its creator (process). In other words, the VM and 61its resources, *including the associated address space*, are not freed 62until the last reference to the VM's file descriptor has been released. 63For example, if fork() is issued after ioctl(KVM_CREATE_VM), the VM will 64not be freed until both the parent (original) process and its child have 65put their references to the VM's file descriptor. 66 67Because a VM's resources are not freed until the last reference to its 68file descriptor is released, creating additional references to a VM 69via fork(), dup(), etc... without careful consideration is strongly 70discouraged and may have unwanted side effects, e.g. memory allocated 71by and on behalf of the VM's process may not be freed/unaccounted when 72the VM is shut down. 73 74 753. Extensions 76============= 77 78As of Linux 2.6.22, the KVM ABI has been stabilized: no backward 79incompatible change are allowed. However, there is an extension 80facility that allows backward-compatible extensions to the API to be 81queried and used. 82 83The extension mechanism is not based on the Linux version number. 84Instead, kvm defines extension identifiers and a facility to query 85whether a particular extension identifier is available. If it is, a 86set of ioctls is available for application use. 87 88 894. API description 90================== 91 92This section describes ioctls that can be used to control kvm guests. 93For each ioctl, the following information is provided along with a 94description: 95 96 Capability: 97 which KVM extension provides this ioctl. Can be 'basic', 98 which means that is will be provided by any kernel that supports 99 API version 12 (see section 4.1), a KVM_CAP_xyz constant, which 100 means availability needs to be checked with KVM_CHECK_EXTENSION 101 (see section 4.4), or 'none' which means that while not all kernels 102 support this ioctl, there's no capability bit to check its 103 availability: for kernels that don't support the ioctl, 104 the ioctl returns -ENOTTY. 105 106 Architectures: 107 which instruction set architectures provide this ioctl. 108 x86 includes both i386 and x86_64. 109 110 Type: 111 system, vm, or vcpu. 112 113 Parameters: 114 what parameters are accepted by the ioctl. 115 116 Returns: 117 the return value. General error numbers (EBADF, ENOMEM, EINVAL) 118 are not detailed, but errors with specific meanings are. 119 120 1214.1 KVM_GET_API_VERSION 122----------------------- 123 124:Capability: basic 125:Architectures: all 126:Type: system ioctl 127:Parameters: none 128:Returns: the constant KVM_API_VERSION (=12) 129 130This identifies the API version as the stable kvm API. It is not 131expected that this number will change. However, Linux 2.6.20 and 1322.6.21 report earlier versions; these are not documented and not 133supported. Applications should refuse to run if KVM_GET_API_VERSION 134returns a value other than 12. If this check passes, all ioctls 135described as 'basic' will be available. 136 137 1384.2 KVM_CREATE_VM 139----------------- 140 141:Capability: basic 142:Architectures: all 143:Type: system ioctl 144:Parameters: machine type identifier (KVM_VM_*) 145:Returns: a VM fd that can be used to control the new virtual machine. 146 147The new VM has no virtual cpus and no memory. 148You probably want to use 0 as machine type. 149 150In order to create user controlled virtual machines on S390, check 151KVM_CAP_S390_UCONTROL and use the flag KVM_VM_S390_UCONTROL as 152privileged user (CAP_SYS_ADMIN). 153 154On arm64, the physical address size for a VM (IPA Size limit) is limited 155to 40bits by default. The limit can be configured if the host supports the 156extension KVM_CAP_ARM_VM_IPA_SIZE. When supported, use 157KVM_VM_TYPE_ARM_IPA_SIZE(IPA_Bits) to set the size in the machine type 158identifier, where IPA_Bits is the maximum width of any physical 159address used by the VM. The IPA_Bits is encoded in bits[7-0] of the 160machine type identifier. 161 162e.g, to configure a guest to use 48bit physical address size:: 163 164 vm_fd = ioctl(dev_fd, KVM_CREATE_VM, KVM_VM_TYPE_ARM_IPA_SIZE(48)); 165 166The requested size (IPA_Bits) must be: 167 168 == ========================================================= 169 0 Implies default size, 40bits (for backward compatibility) 170 N Implies N bits, where N is a positive integer such that, 171 32 <= N <= Host_IPA_Limit 172 == ========================================================= 173 174Host_IPA_Limit is the maximum possible value for IPA_Bits on the host and 175is dependent on the CPU capability and the kernel configuration. The limit can 176be retrieved using KVM_CAP_ARM_VM_IPA_SIZE of the KVM_CHECK_EXTENSION 177ioctl() at run-time. 178 179Creation of the VM will fail if the requested IPA size (whether it is 180implicit or explicit) is unsupported on the host. 181 182Please note that configuring the IPA size does not affect the capability 183exposed by the guest CPUs in ID_AA64MMFR0_EL1[PARange]. It only affects 184size of the address translated by the stage2 level (guest physical to 185host physical address translations). 186 187 1884.3 KVM_GET_MSR_INDEX_LIST, KVM_GET_MSR_FEATURE_INDEX_LIST 189---------------------------------------------------------- 190 191:Capability: basic, KVM_CAP_GET_MSR_FEATURES for KVM_GET_MSR_FEATURE_INDEX_LIST 192:Architectures: x86 193:Type: system ioctl 194:Parameters: struct kvm_msr_list (in/out) 195:Returns: 0 on success; -1 on error 196 197Errors: 198 199 ====== ============================================================ 200 EFAULT the msr index list cannot be read from or written to 201 E2BIG the msr index list is too big to fit in the array specified by 202 the user. 203 ====== ============================================================ 204 205:: 206 207 struct kvm_msr_list { 208 __u32 nmsrs; /* number of msrs in entries */ 209 __u32 indices[0]; 210 }; 211 212The user fills in the size of the indices array in nmsrs, and in return 213kvm adjusts nmsrs to reflect the actual number of msrs and fills in the 214indices array with their numbers. 215 216KVM_GET_MSR_INDEX_LIST returns the guest msrs that are supported. The list 217varies by kvm version and host processor, but does not change otherwise. 218 219Note: if kvm indicates supports MCE (KVM_CAP_MCE), then the MCE bank MSRs are 220not returned in the MSR list, as different vcpus can have a different number 221of banks, as set via the KVM_X86_SETUP_MCE ioctl. 222 223KVM_GET_MSR_FEATURE_INDEX_LIST returns the list of MSRs that can be passed 224to the KVM_GET_MSRS system ioctl. This lets userspace probe host capabilities 225and processor features that are exposed via MSRs (e.g., VMX capabilities). 226This list also varies by kvm version and host processor, but does not change 227otherwise. 228 229 2304.4 KVM_CHECK_EXTENSION 231----------------------- 232 233:Capability: basic, KVM_CAP_CHECK_EXTENSION_VM for vm ioctl 234:Architectures: all 235:Type: system ioctl, vm ioctl 236:Parameters: extension identifier (KVM_CAP_*) 237:Returns: 0 if unsupported; 1 (or some other positive integer) if supported 238 239The API allows the application to query about extensions to the core 240kvm API. Userspace passes an extension identifier (an integer) and 241receives an integer that describes the extension availability. 242Generally 0 means no and 1 means yes, but some extensions may report 243additional information in the integer return value. 244 245Based on their initialization different VMs may have different capabilities. 246It is thus encouraged to use the vm ioctl to query for capabilities (available 247with KVM_CAP_CHECK_EXTENSION_VM on the vm fd) 248 2494.5 KVM_GET_VCPU_MMAP_SIZE 250-------------------------- 251 252:Capability: basic 253:Architectures: all 254:Type: system ioctl 255:Parameters: none 256:Returns: size of vcpu mmap area, in bytes 257 258The KVM_RUN ioctl (cf.) communicates with userspace via a shared 259memory region. This ioctl returns the size of that region. See the 260KVM_RUN documentation for details. 261 262Besides the size of the KVM_RUN communication region, other areas of 263the VCPU file descriptor can be mmap-ed, including: 264 265- if KVM_CAP_COALESCED_MMIO is available, a page at 266 KVM_COALESCED_MMIO_PAGE_OFFSET * PAGE_SIZE; for historical reasons, 267 this page is included in the result of KVM_GET_VCPU_MMAP_SIZE. 268 KVM_CAP_COALESCED_MMIO is not documented yet. 269 270- if KVM_CAP_DIRTY_LOG_RING is available, a number of pages at 271 KVM_DIRTY_LOG_PAGE_OFFSET * PAGE_SIZE. For more information on 272 KVM_CAP_DIRTY_LOG_RING, see section 8.3. 273 274 2754.7 KVM_CREATE_VCPU 276------------------- 277 278:Capability: basic 279:Architectures: all 280:Type: vm ioctl 281:Parameters: vcpu id (apic id on x86) 282:Returns: vcpu fd on success, -1 on error 283 284This API adds a vcpu to a virtual machine. No more than max_vcpus may be added. 285The vcpu id is an integer in the range [0, max_vcpu_id). 286 287The recommended max_vcpus value can be retrieved using the KVM_CAP_NR_VCPUS of 288the KVM_CHECK_EXTENSION ioctl() at run-time. 289The maximum possible value for max_vcpus can be retrieved using the 290KVM_CAP_MAX_VCPUS of the KVM_CHECK_EXTENSION ioctl() at run-time. 291 292If the KVM_CAP_NR_VCPUS does not exist, you should assume that max_vcpus is 4 293cpus max. 294If the KVM_CAP_MAX_VCPUS does not exist, you should assume that max_vcpus is 295same as the value returned from KVM_CAP_NR_VCPUS. 296 297The maximum possible value for max_vcpu_id can be retrieved using the 298KVM_CAP_MAX_VCPU_ID of the KVM_CHECK_EXTENSION ioctl() at run-time. 299 300If the KVM_CAP_MAX_VCPU_ID does not exist, you should assume that max_vcpu_id 301is the same as the value returned from KVM_CAP_MAX_VCPUS. 302 303On powerpc using book3s_hv mode, the vcpus are mapped onto virtual 304threads in one or more virtual CPU cores. (This is because the 305hardware requires all the hardware threads in a CPU core to be in the 306same partition.) The KVM_CAP_PPC_SMT capability indicates the number 307of vcpus per virtual core (vcore). The vcore id is obtained by 308dividing the vcpu id by the number of vcpus per vcore. The vcpus in a 309given vcore will always be in the same physical core as each other 310(though that might be a different physical core from time to time). 311Userspace can control the threading (SMT) mode of the guest by its 312allocation of vcpu ids. For example, if userspace wants 313single-threaded guest vcpus, it should make all vcpu ids be a multiple 314of the number of vcpus per vcore. 315 316For virtual cpus that have been created with S390 user controlled virtual 317machines, the resulting vcpu fd can be memory mapped at page offset 318KVM_S390_SIE_PAGE_OFFSET in order to obtain a memory map of the virtual 319cpu's hardware control block. 320 321 3224.8 KVM_GET_DIRTY_LOG (vm ioctl) 323-------------------------------- 324 325:Capability: basic 326:Architectures: all 327:Type: vm ioctl 328:Parameters: struct kvm_dirty_log (in/out) 329:Returns: 0 on success, -1 on error 330 331:: 332 333 /* for KVM_GET_DIRTY_LOG */ 334 struct kvm_dirty_log { 335 __u32 slot; 336 __u32 padding; 337 union { 338 void __user *dirty_bitmap; /* one bit per page */ 339 __u64 padding; 340 }; 341 }; 342 343Given a memory slot, return a bitmap containing any pages dirtied 344since the last call to this ioctl. Bit 0 is the first page in the 345memory slot. Ensure the entire structure is cleared to avoid padding 346issues. 347 348If KVM_CAP_MULTI_ADDRESS_SPACE is available, bits 16-31 of slot field specifies 349the address space for which you want to return the dirty bitmap. See 350KVM_SET_USER_MEMORY_REGION for details on the usage of slot field. 351 352The bits in the dirty bitmap are cleared before the ioctl returns, unless 353KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2 is enabled. For more information, 354see the description of the capability. 355 356Note that the Xen shared info page, if configured, shall always be assumed 357to be dirty. KVM will not explicitly mark it such. 358 359 3604.10 KVM_RUN 361------------ 362 363:Capability: basic 364:Architectures: all 365:Type: vcpu ioctl 366:Parameters: none 367:Returns: 0 on success, -1 on error 368 369Errors: 370 371 ======= ============================================================== 372 EINTR an unmasked signal is pending 373 ENOEXEC the vcpu hasn't been initialized or the guest tried to execute 374 instructions from device memory (arm64) 375 ENOSYS data abort outside memslots with no syndrome info and 376 KVM_CAP_ARM_NISV_TO_USER not enabled (arm64) 377 EPERM SVE feature set but not finalized (arm64) 378 ======= ============================================================== 379 380This ioctl is used to run a guest virtual cpu. While there are no 381explicit parameters, there is an implicit parameter block that can be 382obtained by mmap()ing the vcpu fd at offset 0, with the size given by 383KVM_GET_VCPU_MMAP_SIZE. The parameter block is formatted as a 'struct 384kvm_run' (see below). 385 386 3874.11 KVM_GET_REGS 388----------------- 389 390:Capability: basic 391:Architectures: all except arm64 392:Type: vcpu ioctl 393:Parameters: struct kvm_regs (out) 394:Returns: 0 on success, -1 on error 395 396Reads the general purpose registers from the vcpu. 397 398:: 399 400 /* x86 */ 401 struct kvm_regs { 402 /* out (KVM_GET_REGS) / in (KVM_SET_REGS) */ 403 __u64 rax, rbx, rcx, rdx; 404 __u64 rsi, rdi, rsp, rbp; 405 __u64 r8, r9, r10, r11; 406 __u64 r12, r13, r14, r15; 407 __u64 rip, rflags; 408 }; 409 410 /* mips */ 411 struct kvm_regs { 412 /* out (KVM_GET_REGS) / in (KVM_SET_REGS) */ 413 __u64 gpr[32]; 414 __u64 hi; 415 __u64 lo; 416 __u64 pc; 417 }; 418 419 /* LoongArch */ 420 struct kvm_regs { 421 /* out (KVM_GET_REGS) / in (KVM_SET_REGS) */ 422 unsigned long gpr[32]; 423 unsigned long pc; 424 }; 425 426 4274.12 KVM_SET_REGS 428----------------- 429 430:Capability: basic 431:Architectures: all except arm64 432:Type: vcpu ioctl 433:Parameters: struct kvm_regs (in) 434:Returns: 0 on success, -1 on error 435 436Writes the general purpose registers into the vcpu. 437 438See KVM_GET_REGS for the data structure. 439 440 4414.13 KVM_GET_SREGS 442------------------ 443 444:Capability: basic 445:Architectures: x86, ppc 446:Type: vcpu ioctl 447:Parameters: struct kvm_sregs (out) 448:Returns: 0 on success, -1 on error 449 450Reads special registers from the vcpu. 451 452:: 453 454 /* x86 */ 455 struct kvm_sregs { 456 struct kvm_segment cs, ds, es, fs, gs, ss; 457 struct kvm_segment tr, ldt; 458 struct kvm_dtable gdt, idt; 459 __u64 cr0, cr2, cr3, cr4, cr8; 460 __u64 efer; 461 __u64 apic_base; 462 __u64 interrupt_bitmap[(KVM_NR_INTERRUPTS + 63) / 64]; 463 }; 464 465 /* ppc -- see arch/powerpc/include/uapi/asm/kvm.h */ 466 467interrupt_bitmap is a bitmap of pending external interrupts. At most 468one bit may be set. This interrupt has been acknowledged by the APIC 469but not yet injected into the cpu core. 470 471 4724.14 KVM_SET_SREGS 473------------------ 474 475:Capability: basic 476:Architectures: x86, ppc 477:Type: vcpu ioctl 478:Parameters: struct kvm_sregs (in) 479:Returns: 0 on success, -1 on error 480 481Writes special registers into the vcpu. See KVM_GET_SREGS for the 482data structures. 483 484 4854.15 KVM_TRANSLATE 486------------------ 487 488:Capability: basic 489:Architectures: x86 490:Type: vcpu ioctl 491:Parameters: struct kvm_translation (in/out) 492:Returns: 0 on success, -1 on error 493 494Translates a virtual address according to the vcpu's current address 495translation mode. 496 497:: 498 499 struct kvm_translation { 500 /* in */ 501 __u64 linear_address; 502 503 /* out */ 504 __u64 physical_address; 505 __u8 valid; 506 __u8 writeable; 507 __u8 usermode; 508 __u8 pad[5]; 509 }; 510 511 5124.16 KVM_INTERRUPT 513------------------ 514 515:Capability: basic 516:Architectures: x86, ppc, mips, riscv, loongarch 517:Type: vcpu ioctl 518:Parameters: struct kvm_interrupt (in) 519:Returns: 0 on success, negative on failure. 520 521Queues a hardware interrupt vector to be injected. 522 523:: 524 525 /* for KVM_INTERRUPT */ 526 struct kvm_interrupt { 527 /* in */ 528 __u32 irq; 529 }; 530 531X86: 532^^^^ 533 534:Returns: 535 536 ========= =================================== 537 0 on success, 538 -EEXIST if an interrupt is already enqueued 539 -EINVAL the irq number is invalid 540 -ENXIO if the PIC is in the kernel 541 -EFAULT if the pointer is invalid 542 ========= =================================== 543 544Note 'irq' is an interrupt vector, not an interrupt pin or line. This 545ioctl is useful if the in-kernel PIC is not used. 546 547PPC: 548^^^^ 549 550Queues an external interrupt to be injected. This ioctl is overloaded 551with 3 different irq values: 552 553a) KVM_INTERRUPT_SET 554 555 This injects an edge type external interrupt into the guest once it's ready 556 to receive interrupts. When injected, the interrupt is done. 557 558b) KVM_INTERRUPT_UNSET 559 560 This unsets any pending interrupt. 561 562 Only available with KVM_CAP_PPC_UNSET_IRQ. 563 564c) KVM_INTERRUPT_SET_LEVEL 565 566 This injects a level type external interrupt into the guest context. The 567 interrupt stays pending until a specific ioctl with KVM_INTERRUPT_UNSET 568 is triggered. 569 570 Only available with KVM_CAP_PPC_IRQ_LEVEL. 571 572Note that any value for 'irq' other than the ones stated above is invalid 573and incurs unexpected behavior. 574 575This is an asynchronous vcpu ioctl and can be invoked from any thread. 576 577MIPS: 578^^^^^ 579 580Queues an external interrupt to be injected into the virtual CPU. A negative 581interrupt number dequeues the interrupt. 582 583This is an asynchronous vcpu ioctl and can be invoked from any thread. 584 585RISC-V: 586^^^^^^^ 587 588Queues an external interrupt to be injected into the virtual CPU. This ioctl 589is overloaded with 2 different irq values: 590 591a) KVM_INTERRUPT_SET 592 593 This sets external interrupt for a virtual CPU and it will receive 594 once it is ready. 595 596b) KVM_INTERRUPT_UNSET 597 598 This clears pending external interrupt for a virtual CPU. 599 600This is an asynchronous vcpu ioctl and can be invoked from any thread. 601 602LOONGARCH: 603^^^^^^^^^^ 604 605Queues an external interrupt to be injected into the virtual CPU. A negative 606interrupt number dequeues the interrupt. 607 608This is an asynchronous vcpu ioctl and can be invoked from any thread. 609 610 6114.17 KVM_DEBUG_GUEST 612-------------------- 613 614:Capability: basic 615:Architectures: none 616:Type: vcpu ioctl 617:Parameters: none) 618:Returns: -1 on error 619 620Support for this has been removed. Use KVM_SET_GUEST_DEBUG instead. 621 622 6234.18 KVM_GET_MSRS 624----------------- 625 626:Capability: basic (vcpu), KVM_CAP_GET_MSR_FEATURES (system) 627:Architectures: x86 628:Type: system ioctl, vcpu ioctl 629:Parameters: struct kvm_msrs (in/out) 630:Returns: number of msrs successfully returned; 631 -1 on error 632 633When used as a system ioctl: 634Reads the values of MSR-based features that are available for the VM. This 635is similar to KVM_GET_SUPPORTED_CPUID, but it returns MSR indices and values. 636The list of msr-based features can be obtained using KVM_GET_MSR_FEATURE_INDEX_LIST 637in a system ioctl. 638 639When used as a vcpu ioctl: 640Reads model-specific registers from the vcpu. Supported msr indices can 641be obtained using KVM_GET_MSR_INDEX_LIST in a system ioctl. 642 643:: 644 645 struct kvm_msrs { 646 __u32 nmsrs; /* number of msrs in entries */ 647 __u32 pad; 648 649 struct kvm_msr_entry entries[0]; 650 }; 651 652 struct kvm_msr_entry { 653 __u32 index; 654 __u32 reserved; 655 __u64 data; 656 }; 657 658Application code should set the 'nmsrs' member (which indicates the 659size of the entries array) and the 'index' member of each array entry. 660kvm will fill in the 'data' member. 661 662 6634.19 KVM_SET_MSRS 664----------------- 665 666:Capability: basic 667:Architectures: x86 668:Type: vcpu ioctl 669:Parameters: struct kvm_msrs (in) 670:Returns: number of msrs successfully set (see below), -1 on error 671 672Writes model-specific registers to the vcpu. See KVM_GET_MSRS for the 673data structures. 674 675Application code should set the 'nmsrs' member (which indicates the 676size of the entries array), and the 'index' and 'data' members of each 677array entry. 678 679It tries to set the MSRs in array entries[] one by one. If setting an MSR 680fails, e.g., due to setting reserved bits, the MSR isn't supported/emulated 681by KVM, etc..., it stops processing the MSR list and returns the number of 682MSRs that have been set successfully. 683 684 6854.20 KVM_SET_CPUID 686------------------ 687 688:Capability: basic 689:Architectures: x86 690:Type: vcpu ioctl 691:Parameters: struct kvm_cpuid (in) 692:Returns: 0 on success, -1 on error 693 694Defines the vcpu responses to the cpuid instruction. Applications 695should use the KVM_SET_CPUID2 ioctl if available. 696 697Caveat emptor: 698 - If this IOCTL fails, KVM gives no guarantees that previous valid CPUID 699 configuration (if there is) is not corrupted. Userspace can get a copy 700 of the resulting CPUID configuration through KVM_GET_CPUID2 in case. 701 - Using KVM_SET_CPUID{,2} after KVM_RUN, i.e. changing the guest vCPU model 702 after running the guest, may cause guest instability. 703 - Using heterogeneous CPUID configurations, modulo APIC IDs, topology, etc... 704 may cause guest instability. 705 706:: 707 708 struct kvm_cpuid_entry { 709 __u32 function; 710 __u32 eax; 711 __u32 ebx; 712 __u32 ecx; 713 __u32 edx; 714 __u32 padding; 715 }; 716 717 /* for KVM_SET_CPUID */ 718 struct kvm_cpuid { 719 __u32 nent; 720 __u32 padding; 721 struct kvm_cpuid_entry entries[0]; 722 }; 723 724 7254.21 KVM_SET_SIGNAL_MASK 726------------------------ 727 728:Capability: basic 729:Architectures: all 730:Type: vcpu ioctl 731:Parameters: struct kvm_signal_mask (in) 732:Returns: 0 on success, -1 on error 733 734Defines which signals are blocked during execution of KVM_RUN. This 735signal mask temporarily overrides the threads signal mask. Any 736unblocked signal received (except SIGKILL and SIGSTOP, which retain 737their traditional behaviour) will cause KVM_RUN to return with -EINTR. 738 739Note the signal will only be delivered if not blocked by the original 740signal mask. 741 742:: 743 744 /* for KVM_SET_SIGNAL_MASK */ 745 struct kvm_signal_mask { 746 __u32 len; 747 __u8 sigset[0]; 748 }; 749 750 7514.22 KVM_GET_FPU 752---------------- 753 754:Capability: basic 755:Architectures: x86, loongarch 756:Type: vcpu ioctl 757:Parameters: struct kvm_fpu (out) 758:Returns: 0 on success, -1 on error 759 760Reads the floating point state from the vcpu. 761 762:: 763 764 /* x86: for KVM_GET_FPU and KVM_SET_FPU */ 765 struct kvm_fpu { 766 __u8 fpr[8][16]; 767 __u16 fcw; 768 __u16 fsw; 769 __u8 ftwx; /* in fxsave format */ 770 __u8 pad1; 771 __u16 last_opcode; 772 __u64 last_ip; 773 __u64 last_dp; 774 __u8 xmm[16][16]; 775 __u32 mxcsr; 776 __u32 pad2; 777 }; 778 779 /* LoongArch: for KVM_GET_FPU and KVM_SET_FPU */ 780 struct kvm_fpu { 781 __u32 fcsr; 782 __u64 fcc; 783 struct kvm_fpureg { 784 __u64 val64[4]; 785 }fpr[32]; 786 }; 787 788 7894.23 KVM_SET_FPU 790---------------- 791 792:Capability: basic 793:Architectures: x86, loongarch 794:Type: vcpu ioctl 795:Parameters: struct kvm_fpu (in) 796:Returns: 0 on success, -1 on error 797 798Writes the floating point state to the vcpu. 799 800:: 801 802 /* x86: for KVM_GET_FPU and KVM_SET_FPU */ 803 struct kvm_fpu { 804 __u8 fpr[8][16]; 805 __u16 fcw; 806 __u16 fsw; 807 __u8 ftwx; /* in fxsave format */ 808 __u8 pad1; 809 __u16 last_opcode; 810 __u64 last_ip; 811 __u64 last_dp; 812 __u8 xmm[16][16]; 813 __u32 mxcsr; 814 __u32 pad2; 815 }; 816 817 /* LoongArch: for KVM_GET_FPU and KVM_SET_FPU */ 818 struct kvm_fpu { 819 __u32 fcsr; 820 __u64 fcc; 821 struct kvm_fpureg { 822 __u64 val64[4]; 823 }fpr[32]; 824 }; 825 826 8274.24 KVM_CREATE_IRQCHIP 828----------------------- 829 830:Capability: KVM_CAP_IRQCHIP, KVM_CAP_S390_IRQCHIP (s390) 831:Architectures: x86, arm64, s390 832:Type: vm ioctl 833:Parameters: none 834:Returns: 0 on success, -1 on error 835 836Creates an interrupt controller model in the kernel. 837On x86, creates a virtual ioapic, a virtual PIC (two PICs, nested), and sets up 838future vcpus to have a local APIC. IRQ routing for GSIs 0-15 is set to both 839PIC and IOAPIC; GSI 16-23 only go to the IOAPIC. 840On arm64, a GICv2 is created. Any other GIC versions require the usage of 841KVM_CREATE_DEVICE, which also supports creating a GICv2. Using 842KVM_CREATE_DEVICE is preferred over KVM_CREATE_IRQCHIP for GICv2. 843On s390, a dummy irq routing table is created. 844 845Note that on s390 the KVM_CAP_S390_IRQCHIP vm capability needs to be enabled 846before KVM_CREATE_IRQCHIP can be used. 847 848 8494.25 KVM_IRQ_LINE 850----------------- 851 852:Capability: KVM_CAP_IRQCHIP 853:Architectures: x86, arm64 854:Type: vm ioctl 855:Parameters: struct kvm_irq_level 856:Returns: 0 on success, -1 on error 857 858Sets the level of a GSI input to the interrupt controller model in the kernel. 859On some architectures it is required that an interrupt controller model has 860been previously created with KVM_CREATE_IRQCHIP. Note that edge-triggered 861interrupts require the level to be set to 1 and then back to 0. 862 863On real hardware, interrupt pins can be active-low or active-high. This 864does not matter for the level field of struct kvm_irq_level: 1 always 865means active (asserted), 0 means inactive (deasserted). 866 867x86 allows the operating system to program the interrupt polarity 868(active-low/active-high) for level-triggered interrupts, and KVM used 869to consider the polarity. However, due to bitrot in the handling of 870active-low interrupts, the above convention is now valid on x86 too. 871This is signaled by KVM_CAP_X86_IOAPIC_POLARITY_IGNORED. Userspace 872should not present interrupts to the guest as active-low unless this 873capability is present (or unless it is not using the in-kernel irqchip, 874of course). 875 876 877arm64 can signal an interrupt either at the CPU level, or at the 878in-kernel irqchip (GIC), and for in-kernel irqchip can tell the GIC to 879use PPIs designated for specific cpus. The irq field is interpreted 880like this:: 881 882 bits: | 31 ... 28 | 27 ... 24 | 23 ... 16 | 15 ... 0 | 883 field: | vcpu2_index | irq_type | vcpu_index | irq_id | 884 885The irq_type field has the following values: 886 887- irq_type[0]: 888 out-of-kernel GIC: irq_id 0 is IRQ, irq_id 1 is FIQ 889- irq_type[1]: 890 in-kernel GIC: SPI, irq_id between 32 and 1019 (incl.) 891 (the vcpu_index field is ignored) 892- irq_type[2]: 893 in-kernel GIC: PPI, irq_id between 16 and 31 (incl.) 894 895(The irq_id field thus corresponds nicely to the IRQ ID in the ARM GIC specs) 896 897In both cases, level is used to assert/deassert the line. 898 899When KVM_CAP_ARM_IRQ_LINE_LAYOUT_2 is supported, the target vcpu is 900identified as (256 * vcpu2_index + vcpu_index). Otherwise, vcpu2_index 901must be zero. 902 903Note that on arm64, the KVM_CAP_IRQCHIP capability only conditions 904injection of interrupts for the in-kernel irqchip. KVM_IRQ_LINE can always 905be used for a userspace interrupt controller. 906 907:: 908 909 struct kvm_irq_level { 910 union { 911 __u32 irq; /* GSI */ 912 __s32 status; /* not used for KVM_IRQ_LEVEL */ 913 }; 914 __u32 level; /* 0 or 1 */ 915 }; 916 917 9184.26 KVM_GET_IRQCHIP 919-------------------- 920 921:Capability: KVM_CAP_IRQCHIP 922:Architectures: x86 923:Type: vm ioctl 924:Parameters: struct kvm_irqchip (in/out) 925:Returns: 0 on success, -1 on error 926 927Reads the state of a kernel interrupt controller created with 928KVM_CREATE_IRQCHIP into a buffer provided by the caller. 929 930:: 931 932 struct kvm_irqchip { 933 __u32 chip_id; /* 0 = PIC1, 1 = PIC2, 2 = IOAPIC */ 934 __u32 pad; 935 union { 936 char dummy[512]; /* reserving space */ 937 struct kvm_pic_state pic; 938 struct kvm_ioapic_state ioapic; 939 } chip; 940 }; 941 942 9434.27 KVM_SET_IRQCHIP 944-------------------- 945 946:Capability: KVM_CAP_IRQCHIP 947:Architectures: x86 948:Type: vm ioctl 949:Parameters: struct kvm_irqchip (in) 950:Returns: 0 on success, -1 on error 951 952Sets the state of a kernel interrupt controller created with 953KVM_CREATE_IRQCHIP from a buffer provided by the caller. 954 955:: 956 957 struct kvm_irqchip { 958 __u32 chip_id; /* 0 = PIC1, 1 = PIC2, 2 = IOAPIC */ 959 __u32 pad; 960 union { 961 char dummy[512]; /* reserving space */ 962 struct kvm_pic_state pic; 963 struct kvm_ioapic_state ioapic; 964 } chip; 965 }; 966 967 9684.28 KVM_XEN_HVM_CONFIG 969----------------------- 970 971:Capability: KVM_CAP_XEN_HVM 972:Architectures: x86 973:Type: vm ioctl 974:Parameters: struct kvm_xen_hvm_config (in) 975:Returns: 0 on success, -1 on error 976 977Sets the MSR that the Xen HVM guest uses to initialize its hypercall 978page, and provides the starting address and size of the hypercall 979blobs in userspace. When the guest writes the MSR, kvm copies one 980page of a blob (32- or 64-bit, depending on the vcpu mode) to guest 981memory. 982 983:: 984 985 struct kvm_xen_hvm_config { 986 __u32 flags; 987 __u32 msr; 988 __u64 blob_addr_32; 989 __u64 blob_addr_64; 990 __u8 blob_size_32; 991 __u8 blob_size_64; 992 __u8 pad2[30]; 993 }; 994 995If certain flags are returned from the KVM_CAP_XEN_HVM check, they may 996be set in the flags field of this ioctl: 997 998The KVM_XEN_HVM_CONFIG_INTERCEPT_HCALL flag requests KVM to generate 999the contents of the hypercall page automatically; hypercalls will be 1000intercepted and passed to userspace through KVM_EXIT_XEN. In this 1001case, all of the blob size and address fields must be zero. 1002 1003The KVM_XEN_HVM_CONFIG_EVTCHN_SEND flag indicates to KVM that userspace 1004will always use the KVM_XEN_HVM_EVTCHN_SEND ioctl to deliver event 1005channel interrupts rather than manipulating the guest's shared_info 1006structures directly. This, in turn, may allow KVM to enable features 1007such as intercepting the SCHEDOP_poll hypercall to accelerate PV 1008spinlock operation for the guest. Userspace may still use the ioctl 1009to deliver events if it was advertised, even if userspace does not 1010send this indication that it will always do so 1011 1012No other flags are currently valid in the struct kvm_xen_hvm_config. 1013 10144.29 KVM_GET_CLOCK 1015------------------ 1016 1017:Capability: KVM_CAP_ADJUST_CLOCK 1018:Architectures: x86 1019:Type: vm ioctl 1020:Parameters: struct kvm_clock_data (out) 1021:Returns: 0 on success, -1 on error 1022 1023Gets the current timestamp of kvmclock as seen by the current guest. In 1024conjunction with KVM_SET_CLOCK, it is used to ensure monotonicity on scenarios 1025such as migration. 1026 1027When KVM_CAP_ADJUST_CLOCK is passed to KVM_CHECK_EXTENSION, it returns the 1028set of bits that KVM can return in struct kvm_clock_data's flag member. 1029 1030The following flags are defined: 1031 1032KVM_CLOCK_TSC_STABLE 1033 If set, the returned value is the exact kvmclock 1034 value seen by all VCPUs at the instant when KVM_GET_CLOCK was called. 1035 If clear, the returned value is simply CLOCK_MONOTONIC plus a constant 1036 offset; the offset can be modified with KVM_SET_CLOCK. KVM will try 1037 to make all VCPUs follow this clock, but the exact value read by each 1038 VCPU could differ, because the host TSC is not stable. 1039 1040KVM_CLOCK_REALTIME 1041 If set, the `realtime` field in the kvm_clock_data 1042 structure is populated with the value of the host's real time 1043 clocksource at the instant when KVM_GET_CLOCK was called. If clear, 1044 the `realtime` field does not contain a value. 1045 1046KVM_CLOCK_HOST_TSC 1047 If set, the `host_tsc` field in the kvm_clock_data 1048 structure is populated with the value of the host's timestamp counter (TSC) 1049 at the instant when KVM_GET_CLOCK was called. If clear, the `host_tsc` field 1050 does not contain a value. 1051 1052:: 1053 1054 struct kvm_clock_data { 1055 __u64 clock; /* kvmclock current value */ 1056 __u32 flags; 1057 __u32 pad0; 1058 __u64 realtime; 1059 __u64 host_tsc; 1060 __u32 pad[4]; 1061 }; 1062 1063 10644.30 KVM_SET_CLOCK 1065------------------ 1066 1067:Capability: KVM_CAP_ADJUST_CLOCK 1068:Architectures: x86 1069:Type: vm ioctl 1070:Parameters: struct kvm_clock_data (in) 1071:Returns: 0 on success, -1 on error 1072 1073Sets the current timestamp of kvmclock to the value specified in its parameter. 1074In conjunction with KVM_GET_CLOCK, it is used to ensure monotonicity on scenarios 1075such as migration. 1076 1077The following flags can be passed: 1078 1079KVM_CLOCK_REALTIME 1080 If set, KVM will compare the value of the `realtime` field 1081 with the value of the host's real time clocksource at the instant when 1082 KVM_SET_CLOCK was called. The difference in elapsed time is added to the final 1083 kvmclock value that will be provided to guests. 1084 1085Other flags returned by ``KVM_GET_CLOCK`` are accepted but ignored. 1086 1087:: 1088 1089 struct kvm_clock_data { 1090 __u64 clock; /* kvmclock current value */ 1091 __u32 flags; 1092 __u32 pad0; 1093 __u64 realtime; 1094 __u64 host_tsc; 1095 __u32 pad[4]; 1096 }; 1097 1098 10994.31 KVM_GET_VCPU_EVENTS 1100------------------------ 1101 1102:Capability: KVM_CAP_VCPU_EVENTS 1103:Extended by: KVM_CAP_INTR_SHADOW 1104:Architectures: x86, arm64 1105:Type: vcpu ioctl 1106:Parameters: struct kvm_vcpu_events (out) 1107:Returns: 0 on success, -1 on error 1108 1109X86: 1110^^^^ 1111 1112Gets currently pending exceptions, interrupts, and NMIs as well as related 1113states of the vcpu. 1114 1115:: 1116 1117 struct kvm_vcpu_events { 1118 struct { 1119 __u8 injected; 1120 __u8 nr; 1121 __u8 has_error_code; 1122 __u8 pending; 1123 __u32 error_code; 1124 } exception; 1125 struct { 1126 __u8 injected; 1127 __u8 nr; 1128 __u8 soft; 1129 __u8 shadow; 1130 } interrupt; 1131 struct { 1132 __u8 injected; 1133 __u8 pending; 1134 __u8 masked; 1135 __u8 pad; 1136 } nmi; 1137 __u32 sipi_vector; 1138 __u32 flags; 1139 struct { 1140 __u8 smm; 1141 __u8 pending; 1142 __u8 smm_inside_nmi; 1143 __u8 latched_init; 1144 } smi; 1145 __u8 reserved[27]; 1146 __u8 exception_has_payload; 1147 __u64 exception_payload; 1148 }; 1149 1150The following bits are defined in the flags field: 1151 1152- KVM_VCPUEVENT_VALID_SHADOW may be set to signal that 1153 interrupt.shadow contains a valid state. 1154 1155- KVM_VCPUEVENT_VALID_SMM may be set to signal that smi contains a 1156 valid state. 1157 1158- KVM_VCPUEVENT_VALID_PAYLOAD may be set to signal that the 1159 exception_has_payload, exception_payload, and exception.pending 1160 fields contain a valid state. This bit will be set whenever 1161 KVM_CAP_EXCEPTION_PAYLOAD is enabled. 1162 1163- KVM_VCPUEVENT_VALID_TRIPLE_FAULT may be set to signal that the 1164 triple_fault_pending field contains a valid state. This bit will 1165 be set whenever KVM_CAP_X86_TRIPLE_FAULT_EVENT is enabled. 1166 1167ARM64: 1168^^^^^^ 1169 1170If the guest accesses a device that is being emulated by the host kernel in 1171such a way that a real device would generate a physical SError, KVM may make 1172a virtual SError pending for that VCPU. This system error interrupt remains 1173pending until the guest takes the exception by unmasking PSTATE.A. 1174 1175Running the VCPU may cause it to take a pending SError, or make an access that 1176causes an SError to become pending. The event's description is only valid while 1177the VPCU is not running. 1178 1179This API provides a way to read and write the pending 'event' state that is not 1180visible to the guest. To save, restore or migrate a VCPU the struct representing 1181the state can be read then written using this GET/SET API, along with the other 1182guest-visible registers. It is not possible to 'cancel' an SError that has been 1183made pending. 1184 1185A device being emulated in user-space may also wish to generate an SError. To do 1186this the events structure can be populated by user-space. The current state 1187should be read first, to ensure no existing SError is pending. If an existing 1188SError is pending, the architecture's 'Multiple SError interrupts' rules should 1189be followed. (2.5.3 of DDI0587.a "ARM Reliability, Availability, and 1190Serviceability (RAS) Specification"). 1191 1192SError exceptions always have an ESR value. Some CPUs have the ability to 1193specify what the virtual SError's ESR value should be. These systems will 1194advertise KVM_CAP_ARM_INJECT_SERROR_ESR. In this case exception.has_esr will 1195always have a non-zero value when read, and the agent making an SError pending 1196should specify the ISS field in the lower 24 bits of exception.serror_esr. If 1197the system supports KVM_CAP_ARM_INJECT_SERROR_ESR, but user-space sets the events 1198with exception.has_esr as zero, KVM will choose an ESR. 1199 1200Specifying exception.has_esr on a system that does not support it will return 1201-EINVAL. Setting anything other than the lower 24bits of exception.serror_esr 1202will return -EINVAL. 1203 1204It is not possible to read back a pending external abort (injected via 1205KVM_SET_VCPU_EVENTS or otherwise) because such an exception is always delivered 1206directly to the virtual CPU). 1207 1208:: 1209 1210 struct kvm_vcpu_events { 1211 struct { 1212 __u8 serror_pending; 1213 __u8 serror_has_esr; 1214 __u8 ext_dabt_pending; 1215 /* Align it to 8 bytes */ 1216 __u8 pad[5]; 1217 __u64 serror_esr; 1218 } exception; 1219 __u32 reserved[12]; 1220 }; 1221 12224.32 KVM_SET_VCPU_EVENTS 1223------------------------ 1224 1225:Capability: KVM_CAP_VCPU_EVENTS 1226:Extended by: KVM_CAP_INTR_SHADOW 1227:Architectures: x86, arm64 1228:Type: vcpu ioctl 1229:Parameters: struct kvm_vcpu_events (in) 1230:Returns: 0 on success, -1 on error 1231 1232X86: 1233^^^^ 1234 1235Set pending exceptions, interrupts, and NMIs as well as related states of the 1236vcpu. 1237 1238See KVM_GET_VCPU_EVENTS for the data structure. 1239 1240Fields that may be modified asynchronously by running VCPUs can be excluded 1241from the update. These fields are nmi.pending, sipi_vector, smi.smm, 1242smi.pending. Keep the corresponding bits in the flags field cleared to 1243suppress overwriting the current in-kernel state. The bits are: 1244 1245=============================== ================================== 1246KVM_VCPUEVENT_VALID_NMI_PENDING transfer nmi.pending to the kernel 1247KVM_VCPUEVENT_VALID_SIPI_VECTOR transfer sipi_vector 1248KVM_VCPUEVENT_VALID_SMM transfer the smi sub-struct. 1249=============================== ================================== 1250 1251If KVM_CAP_INTR_SHADOW is available, KVM_VCPUEVENT_VALID_SHADOW can be set in 1252the flags field to signal that interrupt.shadow contains a valid state and 1253shall be written into the VCPU. 1254 1255KVM_VCPUEVENT_VALID_SMM can only be set if KVM_CAP_X86_SMM is available. 1256 1257If KVM_CAP_EXCEPTION_PAYLOAD is enabled, KVM_VCPUEVENT_VALID_PAYLOAD 1258can be set in the flags field to signal that the 1259exception_has_payload, exception_payload, and exception.pending fields 1260contain a valid state and shall be written into the VCPU. 1261 1262If KVM_CAP_X86_TRIPLE_FAULT_EVENT is enabled, KVM_VCPUEVENT_VALID_TRIPLE_FAULT 1263can be set in flags field to signal that the triple_fault field contains 1264a valid state and shall be written into the VCPU. 1265 1266ARM64: 1267^^^^^^ 1268 1269User space may need to inject several types of events to the guest. 1270 1271Set the pending SError exception state for this VCPU. It is not possible to 1272'cancel' an Serror that has been made pending. 1273 1274If the guest performed an access to I/O memory which could not be handled by 1275userspace, for example because of missing instruction syndrome decode 1276information or because there is no device mapped at the accessed IPA, then 1277userspace can ask the kernel to inject an external abort using the address 1278from the exiting fault on the VCPU. It is a programming error to set 1279ext_dabt_pending after an exit which was not either KVM_EXIT_MMIO or 1280KVM_EXIT_ARM_NISV. This feature is only available if the system supports 1281KVM_CAP_ARM_INJECT_EXT_DABT. This is a helper which provides commonality in 1282how userspace reports accesses for the above cases to guests, across different 1283userspace implementations. Nevertheless, userspace can still emulate all Arm 1284exceptions by manipulating individual registers using the KVM_SET_ONE_REG API. 1285 1286See KVM_GET_VCPU_EVENTS for the data structure. 1287 1288 12894.33 KVM_GET_DEBUGREGS 1290---------------------- 1291 1292:Capability: KVM_CAP_DEBUGREGS 1293:Architectures: x86 1294:Type: vm ioctl 1295:Parameters: struct kvm_debugregs (out) 1296:Returns: 0 on success, -1 on error 1297 1298Reads debug registers from the vcpu. 1299 1300:: 1301 1302 struct kvm_debugregs { 1303 __u64 db[4]; 1304 __u64 dr6; 1305 __u64 dr7; 1306 __u64 flags; 1307 __u64 reserved[9]; 1308 }; 1309 1310 13114.34 KVM_SET_DEBUGREGS 1312---------------------- 1313 1314:Capability: KVM_CAP_DEBUGREGS 1315:Architectures: x86 1316:Type: vm ioctl 1317:Parameters: struct kvm_debugregs (in) 1318:Returns: 0 on success, -1 on error 1319 1320Writes debug registers into the vcpu. 1321 1322See KVM_GET_DEBUGREGS for the data structure. The flags field is unused 1323yet and must be cleared on entry. 1324 1325 13264.35 KVM_SET_USER_MEMORY_REGION 1327------------------------------- 1328 1329:Capability: KVM_CAP_USER_MEMORY 1330:Architectures: all 1331:Type: vm ioctl 1332:Parameters: struct kvm_userspace_memory_region (in) 1333:Returns: 0 on success, -1 on error 1334 1335:: 1336 1337 struct kvm_userspace_memory_region { 1338 __u32 slot; 1339 __u32 flags; 1340 __u64 guest_phys_addr; 1341 __u64 memory_size; /* bytes */ 1342 __u64 userspace_addr; /* start of the userspace allocated memory */ 1343 }; 1344 1345 /* for kvm_userspace_memory_region::flags */ 1346 #define KVM_MEM_LOG_DIRTY_PAGES (1UL << 0) 1347 #define KVM_MEM_READONLY (1UL << 1) 1348 1349This ioctl allows the user to create, modify or delete a guest physical 1350memory slot. Bits 0-15 of "slot" specify the slot id and this value 1351should be less than the maximum number of user memory slots supported per 1352VM. The maximum allowed slots can be queried using KVM_CAP_NR_MEMSLOTS. 1353Slots may not overlap in guest physical address space. 1354 1355If KVM_CAP_MULTI_ADDRESS_SPACE is available, bits 16-31 of "slot" 1356specifies the address space which is being modified. They must be 1357less than the value that KVM_CHECK_EXTENSION returns for the 1358KVM_CAP_MULTI_ADDRESS_SPACE capability. Slots in separate address spaces 1359are unrelated; the restriction on overlapping slots only applies within 1360each address space. 1361 1362Deleting a slot is done by passing zero for memory_size. When changing 1363an existing slot, it may be moved in the guest physical memory space, 1364or its flags may be modified, but it may not be resized. 1365 1366Memory for the region is taken starting at the address denoted by the 1367field userspace_addr, which must point at user addressable memory for 1368the entire memory slot size. Any object may back this memory, including 1369anonymous memory, ordinary files, and hugetlbfs. 1370 1371On architectures that support a form of address tagging, userspace_addr must 1372be an untagged address. 1373 1374It is recommended that the lower 21 bits of guest_phys_addr and userspace_addr 1375be identical. This allows large pages in the guest to be backed by large 1376pages in the host. 1377 1378The flags field supports two flags: KVM_MEM_LOG_DIRTY_PAGES and 1379KVM_MEM_READONLY. The former can be set to instruct KVM to keep track of 1380writes to memory within the slot. See KVM_GET_DIRTY_LOG ioctl to know how to 1381use it. The latter can be set, if KVM_CAP_READONLY_MEM capability allows it, 1382to make a new slot read-only. In this case, writes to this memory will be 1383posted to userspace as KVM_EXIT_MMIO exits. 1384 1385When the KVM_CAP_SYNC_MMU capability is available, changes in the backing of 1386the memory region are automatically reflected into the guest. For example, an 1387mmap() that affects the region will be made visible immediately. Another 1388example is madvise(MADV_DROP). 1389 1390Note: On arm64, a write generated by the page-table walker (to update 1391the Access and Dirty flags, for example) never results in a 1392KVM_EXIT_MMIO exit when the slot has the KVM_MEM_READONLY flag. This 1393is because KVM cannot provide the data that would be written by the 1394page-table walker, making it impossible to emulate the access. 1395Instead, an abort (data abort if the cause of the page-table update 1396was a load or a store, instruction abort if it was an instruction 1397fetch) is injected in the guest. 1398 13994.36 KVM_SET_TSS_ADDR 1400--------------------- 1401 1402:Capability: KVM_CAP_SET_TSS_ADDR 1403:Architectures: x86 1404:Type: vm ioctl 1405:Parameters: unsigned long tss_address (in) 1406:Returns: 0 on success, -1 on error 1407 1408This ioctl defines the physical address of a three-page region in the guest 1409physical address space. The region must be within the first 4GB of the 1410guest physical address space and must not conflict with any memory slot 1411or any mmio address. The guest may malfunction if it accesses this memory 1412region. 1413 1414This ioctl is required on Intel-based hosts. This is needed on Intel hardware 1415because of a quirk in the virtualization implementation (see the internals 1416documentation when it pops into existence). 1417 1418 14194.37 KVM_ENABLE_CAP 1420------------------- 1421 1422:Capability: KVM_CAP_ENABLE_CAP 1423:Architectures: mips, ppc, s390, x86, loongarch 1424:Type: vcpu ioctl 1425:Parameters: struct kvm_enable_cap (in) 1426:Returns: 0 on success; -1 on error 1427 1428:Capability: KVM_CAP_ENABLE_CAP_VM 1429:Architectures: all 1430:Type: vm ioctl 1431:Parameters: struct kvm_enable_cap (in) 1432:Returns: 0 on success; -1 on error 1433 1434.. note:: 1435 1436 Not all extensions are enabled by default. Using this ioctl the application 1437 can enable an extension, making it available to the guest. 1438 1439On systems that do not support this ioctl, it always fails. On systems that 1440do support it, it only works for extensions that are supported for enablement. 1441 1442To check if a capability can be enabled, the KVM_CHECK_EXTENSION ioctl should 1443be used. 1444 1445:: 1446 1447 struct kvm_enable_cap { 1448 /* in */ 1449 __u32 cap; 1450 1451The capability that is supposed to get enabled. 1452 1453:: 1454 1455 __u32 flags; 1456 1457A bitfield indicating future enhancements. Has to be 0 for now. 1458 1459:: 1460 1461 __u64 args[4]; 1462 1463Arguments for enabling a feature. If a feature needs initial values to 1464function properly, this is the place to put them. 1465 1466:: 1467 1468 __u8 pad[64]; 1469 }; 1470 1471The vcpu ioctl should be used for vcpu-specific capabilities, the vm ioctl 1472for vm-wide capabilities. 1473 14744.38 KVM_GET_MP_STATE 1475--------------------- 1476 1477:Capability: KVM_CAP_MP_STATE 1478:Architectures: x86, s390, arm64, riscv, loongarch 1479:Type: vcpu ioctl 1480:Parameters: struct kvm_mp_state (out) 1481:Returns: 0 on success; -1 on error 1482 1483:: 1484 1485 struct kvm_mp_state { 1486 __u32 mp_state; 1487 }; 1488 1489Returns the vcpu's current "multiprocessing state" (though also valid on 1490uniprocessor guests). 1491 1492Possible values are: 1493 1494 ========================== =============================================== 1495 KVM_MP_STATE_RUNNABLE the vcpu is currently running 1496 [x86,arm64,riscv,loongarch] 1497 KVM_MP_STATE_UNINITIALIZED the vcpu is an application processor (AP) 1498 which has not yet received an INIT signal [x86] 1499 KVM_MP_STATE_INIT_RECEIVED the vcpu has received an INIT signal, and is 1500 now ready for a SIPI [x86] 1501 KVM_MP_STATE_HALTED the vcpu has executed a HLT instruction and 1502 is waiting for an interrupt [x86] 1503 KVM_MP_STATE_SIPI_RECEIVED the vcpu has just received a SIPI (vector 1504 accessible via KVM_GET_VCPU_EVENTS) [x86] 1505 KVM_MP_STATE_STOPPED the vcpu is stopped [s390,arm64,riscv] 1506 KVM_MP_STATE_CHECK_STOP the vcpu is in a special error state [s390] 1507 KVM_MP_STATE_OPERATING the vcpu is operating (running or halted) 1508 [s390] 1509 KVM_MP_STATE_LOAD the vcpu is in a special load/startup state 1510 [s390] 1511 KVM_MP_STATE_SUSPENDED the vcpu is in a suspend state and is waiting 1512 for a wakeup event [arm64] 1513 ========================== =============================================== 1514 1515On x86, this ioctl is only useful after KVM_CREATE_IRQCHIP. Without an 1516in-kernel irqchip, the multiprocessing state must be maintained by userspace on 1517these architectures. 1518 1519For arm64: 1520^^^^^^^^^^ 1521 1522If a vCPU is in the KVM_MP_STATE_SUSPENDED state, KVM will emulate the 1523architectural execution of a WFI instruction. 1524 1525If a wakeup event is recognized, KVM will exit to userspace with a 1526KVM_SYSTEM_EVENT exit, where the event type is KVM_SYSTEM_EVENT_WAKEUP. If 1527userspace wants to honor the wakeup, it must set the vCPU's MP state to 1528KVM_MP_STATE_RUNNABLE. If it does not, KVM will continue to await a wakeup 1529event in subsequent calls to KVM_RUN. 1530 1531.. warning:: 1532 1533 If userspace intends to keep the vCPU in a SUSPENDED state, it is 1534 strongly recommended that userspace take action to suppress the 1535 wakeup event (such as masking an interrupt). Otherwise, subsequent 1536 calls to KVM_RUN will immediately exit with a KVM_SYSTEM_EVENT_WAKEUP 1537 event and inadvertently waste CPU cycles. 1538 1539 Additionally, if userspace takes action to suppress a wakeup event, 1540 it is strongly recommended that it also restores the vCPU to its 1541 original state when the vCPU is made RUNNABLE again. For example, 1542 if userspace masked a pending interrupt to suppress the wakeup, 1543 the interrupt should be unmasked before returning control to the 1544 guest. 1545 1546For riscv: 1547^^^^^^^^^^ 1548 1549The only states that are valid are KVM_MP_STATE_STOPPED and 1550KVM_MP_STATE_RUNNABLE which reflect if the vcpu is paused or not. 1551 1552On LoongArch, only the KVM_MP_STATE_RUNNABLE state is used to reflect 1553whether the vcpu is runnable. 1554 15554.39 KVM_SET_MP_STATE 1556--------------------- 1557 1558:Capability: KVM_CAP_MP_STATE 1559:Architectures: x86, s390, arm64, riscv, loongarch 1560:Type: vcpu ioctl 1561:Parameters: struct kvm_mp_state (in) 1562:Returns: 0 on success; -1 on error 1563 1564Sets the vcpu's current "multiprocessing state"; see KVM_GET_MP_STATE for 1565arguments. 1566 1567On x86, this ioctl is only useful after KVM_CREATE_IRQCHIP. Without an 1568in-kernel irqchip, the multiprocessing state must be maintained by userspace on 1569these architectures. 1570 1571For arm64/riscv: 1572^^^^^^^^^^^^^^^^ 1573 1574The only states that are valid are KVM_MP_STATE_STOPPED and 1575KVM_MP_STATE_RUNNABLE which reflect if the vcpu should be paused or not. 1576 1577On LoongArch, only the KVM_MP_STATE_RUNNABLE state is used to reflect 1578whether the vcpu is runnable. 1579 15804.40 KVM_SET_IDENTITY_MAP_ADDR 1581------------------------------ 1582 1583:Capability: KVM_CAP_SET_IDENTITY_MAP_ADDR 1584:Architectures: x86 1585:Type: vm ioctl 1586:Parameters: unsigned long identity (in) 1587:Returns: 0 on success, -1 on error 1588 1589This ioctl defines the physical address of a one-page region in the guest 1590physical address space. The region must be within the first 4GB of the 1591guest physical address space and must not conflict with any memory slot 1592or any mmio address. The guest may malfunction if it accesses this memory 1593region. 1594 1595Setting the address to 0 will result in resetting the address to its default 1596(0xfffbc000). 1597 1598This ioctl is required on Intel-based hosts. This is needed on Intel hardware 1599because of a quirk in the virtualization implementation (see the internals 1600documentation when it pops into existence). 1601 1602Fails if any VCPU has already been created. 1603 16044.41 KVM_SET_BOOT_CPU_ID 1605------------------------ 1606 1607:Capability: KVM_CAP_SET_BOOT_CPU_ID 1608:Architectures: x86 1609:Type: vm ioctl 1610:Parameters: unsigned long vcpu_id 1611:Returns: 0 on success, -1 on error 1612 1613Define which vcpu is the Bootstrap Processor (BSP). Values are the same 1614as the vcpu id in KVM_CREATE_VCPU. If this ioctl is not called, the default 1615is vcpu 0. This ioctl has to be called before vcpu creation, 1616otherwise it will return EBUSY error. 1617 1618 16194.42 KVM_GET_XSAVE 1620------------------ 1621 1622:Capability: KVM_CAP_XSAVE 1623:Architectures: x86 1624:Type: vcpu ioctl 1625:Parameters: struct kvm_xsave (out) 1626:Returns: 0 on success, -1 on error 1627 1628 1629:: 1630 1631 struct kvm_xsave { 1632 __u32 region[1024]; 1633 __u32 extra[0]; 1634 }; 1635 1636This ioctl would copy current vcpu's xsave struct to the userspace. 1637 1638 16394.43 KVM_SET_XSAVE 1640------------------ 1641 1642:Capability: KVM_CAP_XSAVE and KVM_CAP_XSAVE2 1643:Architectures: x86 1644:Type: vcpu ioctl 1645:Parameters: struct kvm_xsave (in) 1646:Returns: 0 on success, -1 on error 1647 1648:: 1649 1650 1651 struct kvm_xsave { 1652 __u32 region[1024]; 1653 __u32 extra[0]; 1654 }; 1655 1656This ioctl would copy userspace's xsave struct to the kernel. It copies 1657as many bytes as are returned by KVM_CHECK_EXTENSION(KVM_CAP_XSAVE2), 1658when invoked on the vm file descriptor. The size value returned by 1659KVM_CHECK_EXTENSION(KVM_CAP_XSAVE2) will always be at least 4096. 1660Currently, it is only greater than 4096 if a dynamic feature has been 1661enabled with ``arch_prctl()``, but this may change in the future. 1662 1663The offsets of the state save areas in struct kvm_xsave follow the 1664contents of CPUID leaf 0xD on the host. 1665 1666 16674.44 KVM_GET_XCRS 1668----------------- 1669 1670:Capability: KVM_CAP_XCRS 1671:Architectures: x86 1672:Type: vcpu ioctl 1673:Parameters: struct kvm_xcrs (out) 1674:Returns: 0 on success, -1 on error 1675 1676:: 1677 1678 struct kvm_xcr { 1679 __u32 xcr; 1680 __u32 reserved; 1681 __u64 value; 1682 }; 1683 1684 struct kvm_xcrs { 1685 __u32 nr_xcrs; 1686 __u32 flags; 1687 struct kvm_xcr xcrs[KVM_MAX_XCRS]; 1688 __u64 padding[16]; 1689 }; 1690 1691This ioctl would copy current vcpu's xcrs to the userspace. 1692 1693 16944.45 KVM_SET_XCRS 1695----------------- 1696 1697:Capability: KVM_CAP_XCRS 1698:Architectures: x86 1699:Type: vcpu ioctl 1700:Parameters: struct kvm_xcrs (in) 1701:Returns: 0 on success, -1 on error 1702 1703:: 1704 1705 struct kvm_xcr { 1706 __u32 xcr; 1707 __u32 reserved; 1708 __u64 value; 1709 }; 1710 1711 struct kvm_xcrs { 1712 __u32 nr_xcrs; 1713 __u32 flags; 1714 struct kvm_xcr xcrs[KVM_MAX_XCRS]; 1715 __u64 padding[16]; 1716 }; 1717 1718This ioctl would set vcpu's xcr to the value userspace specified. 1719 1720 17214.46 KVM_GET_SUPPORTED_CPUID 1722---------------------------- 1723 1724:Capability: KVM_CAP_EXT_CPUID 1725:Architectures: x86 1726:Type: system ioctl 1727:Parameters: struct kvm_cpuid2 (in/out) 1728:Returns: 0 on success, -1 on error 1729 1730:: 1731 1732 struct kvm_cpuid2 { 1733 __u32 nent; 1734 __u32 padding; 1735 struct kvm_cpuid_entry2 entries[0]; 1736 }; 1737 1738 #define KVM_CPUID_FLAG_SIGNIFCANT_INDEX BIT(0) 1739 #define KVM_CPUID_FLAG_STATEFUL_FUNC BIT(1) /* deprecated */ 1740 #define KVM_CPUID_FLAG_STATE_READ_NEXT BIT(2) /* deprecated */ 1741 1742 struct kvm_cpuid_entry2 { 1743 __u32 function; 1744 __u32 index; 1745 __u32 flags; 1746 __u32 eax; 1747 __u32 ebx; 1748 __u32 ecx; 1749 __u32 edx; 1750 __u32 padding[3]; 1751 }; 1752 1753This ioctl returns x86 cpuid features which are supported by both the 1754hardware and kvm in its default configuration. Userspace can use the 1755information returned by this ioctl to construct cpuid information (for 1756KVM_SET_CPUID2) that is consistent with hardware, kernel, and 1757userspace capabilities, and with user requirements (for example, the 1758user may wish to constrain cpuid to emulate older hardware, or for 1759feature consistency across a cluster). 1760 1761Dynamically-enabled feature bits need to be requested with 1762``arch_prctl()`` before calling this ioctl. Feature bits that have not 1763been requested are excluded from the result. 1764 1765Note that certain capabilities, such as KVM_CAP_X86_DISABLE_EXITS, may 1766expose cpuid features (e.g. MONITOR) which are not supported by kvm in 1767its default configuration. If userspace enables such capabilities, it 1768is responsible for modifying the results of this ioctl appropriately. 1769 1770Userspace invokes KVM_GET_SUPPORTED_CPUID by passing a kvm_cpuid2 structure 1771with the 'nent' field indicating the number of entries in the variable-size 1772array 'entries'. If the number of entries is too low to describe the cpu 1773capabilities, an error (E2BIG) is returned. If the number is too high, 1774the 'nent' field is adjusted and an error (ENOMEM) is returned. If the 1775number is just right, the 'nent' field is adjusted to the number of valid 1776entries in the 'entries' array, which is then filled. 1777 1778The entries returned are the host cpuid as returned by the cpuid instruction, 1779with unknown or unsupported features masked out. Some features (for example, 1780x2apic), may not be present in the host cpu, but are exposed by kvm if it can 1781emulate them efficiently. The fields in each entry are defined as follows: 1782 1783 function: 1784 the eax value used to obtain the entry 1785 1786 index: 1787 the ecx value used to obtain the entry (for entries that are 1788 affected by ecx) 1789 1790 flags: 1791 an OR of zero or more of the following: 1792 1793 KVM_CPUID_FLAG_SIGNIFCANT_INDEX: 1794 if the index field is valid 1795 1796 eax, ebx, ecx, edx: 1797 the values returned by the cpuid instruction for 1798 this function/index combination 1799 1800The TSC deadline timer feature (CPUID leaf 1, ecx[24]) is always returned 1801as false, since the feature depends on KVM_CREATE_IRQCHIP for local APIC 1802support. Instead it is reported via:: 1803 1804 ioctl(KVM_CHECK_EXTENSION, KVM_CAP_TSC_DEADLINE_TIMER) 1805 1806if that returns true and you use KVM_CREATE_IRQCHIP, or if you emulate the 1807feature in userspace, then you can enable the feature for KVM_SET_CPUID2. 1808 1809 18104.47 KVM_PPC_GET_PVINFO 1811----------------------- 1812 1813:Capability: KVM_CAP_PPC_GET_PVINFO 1814:Architectures: ppc 1815:Type: vm ioctl 1816:Parameters: struct kvm_ppc_pvinfo (out) 1817:Returns: 0 on success, !0 on error 1818 1819:: 1820 1821 struct kvm_ppc_pvinfo { 1822 __u32 flags; 1823 __u32 hcall[4]; 1824 __u8 pad[108]; 1825 }; 1826 1827This ioctl fetches PV specific information that need to be passed to the guest 1828using the device tree or other means from vm context. 1829 1830The hcall array defines 4 instructions that make up a hypercall. 1831 1832If any additional field gets added to this structure later on, a bit for that 1833additional piece of information will be set in the flags bitmap. 1834 1835The flags bitmap is defined as:: 1836 1837 /* the host supports the ePAPR idle hcall 1838 #define KVM_PPC_PVINFO_FLAGS_EV_IDLE (1<<0) 1839 18404.52 KVM_SET_GSI_ROUTING 1841------------------------ 1842 1843:Capability: KVM_CAP_IRQ_ROUTING 1844:Architectures: x86 s390 arm64 1845:Type: vm ioctl 1846:Parameters: struct kvm_irq_routing (in) 1847:Returns: 0 on success, -1 on error 1848 1849Sets the GSI routing table entries, overwriting any previously set entries. 1850 1851On arm64, GSI routing has the following limitation: 1852 1853- GSI routing does not apply to KVM_IRQ_LINE but only to KVM_IRQFD. 1854 1855:: 1856 1857 struct kvm_irq_routing { 1858 __u32 nr; 1859 __u32 flags; 1860 struct kvm_irq_routing_entry entries[0]; 1861 }; 1862 1863No flags are specified so far, the corresponding field must be set to zero. 1864 1865:: 1866 1867 struct kvm_irq_routing_entry { 1868 __u32 gsi; 1869 __u32 type; 1870 __u32 flags; 1871 __u32 pad; 1872 union { 1873 struct kvm_irq_routing_irqchip irqchip; 1874 struct kvm_irq_routing_msi msi; 1875 struct kvm_irq_routing_s390_adapter adapter; 1876 struct kvm_irq_routing_hv_sint hv_sint; 1877 struct kvm_irq_routing_xen_evtchn xen_evtchn; 1878 __u32 pad[8]; 1879 } u; 1880 }; 1881 1882 /* gsi routing entry types */ 1883 #define KVM_IRQ_ROUTING_IRQCHIP 1 1884 #define KVM_IRQ_ROUTING_MSI 2 1885 #define KVM_IRQ_ROUTING_S390_ADAPTER 3 1886 #define KVM_IRQ_ROUTING_HV_SINT 4 1887 #define KVM_IRQ_ROUTING_XEN_EVTCHN 5 1888 1889flags: 1890 1891- KVM_MSI_VALID_DEVID: used along with KVM_IRQ_ROUTING_MSI routing entry 1892 type, specifies that the devid field contains a valid value. The per-VM 1893 KVM_CAP_MSI_DEVID capability advertises the requirement to provide 1894 the device ID. If this capability is not available, userspace should 1895 never set the KVM_MSI_VALID_DEVID flag as the ioctl might fail. 1896- zero otherwise 1897 1898:: 1899 1900 struct kvm_irq_routing_irqchip { 1901 __u32 irqchip; 1902 __u32 pin; 1903 }; 1904 1905 struct kvm_irq_routing_msi { 1906 __u32 address_lo; 1907 __u32 address_hi; 1908 __u32 data; 1909 union { 1910 __u32 pad; 1911 __u32 devid; 1912 }; 1913 }; 1914 1915If KVM_MSI_VALID_DEVID is set, devid contains a unique device identifier 1916for the device that wrote the MSI message. For PCI, this is usually a 1917BFD identifier in the lower 16 bits. 1918 1919On x86, address_hi is ignored unless the KVM_X2APIC_API_USE_32BIT_IDS 1920feature of KVM_CAP_X2APIC_API capability is enabled. If it is enabled, 1921address_hi bits 31-8 provide bits 31-8 of the destination id. Bits 7-0 of 1922address_hi must be zero. 1923 1924:: 1925 1926 struct kvm_irq_routing_s390_adapter { 1927 __u64 ind_addr; 1928 __u64 summary_addr; 1929 __u64 ind_offset; 1930 __u32 summary_offset; 1931 __u32 adapter_id; 1932 }; 1933 1934 struct kvm_irq_routing_hv_sint { 1935 __u32 vcpu; 1936 __u32 sint; 1937 }; 1938 1939 struct kvm_irq_routing_xen_evtchn { 1940 __u32 port; 1941 __u32 vcpu; 1942 __u32 priority; 1943 }; 1944 1945 1946When KVM_CAP_XEN_HVM includes the KVM_XEN_HVM_CONFIG_EVTCHN_2LEVEL bit 1947in its indication of supported features, routing to Xen event channels 1948is supported. Although the priority field is present, only the value 1949KVM_XEN_HVM_CONFIG_EVTCHN_2LEVEL is supported, which means delivery by 19502 level event channels. FIFO event channel support may be added in 1951the future. 1952 1953 19544.55 KVM_SET_TSC_KHZ 1955-------------------- 1956 1957:Capability: KVM_CAP_TSC_CONTROL / KVM_CAP_VM_TSC_CONTROL 1958:Architectures: x86 1959:Type: vcpu ioctl / vm ioctl 1960:Parameters: virtual tsc_khz 1961:Returns: 0 on success, -1 on error 1962 1963Specifies the tsc frequency for the virtual machine. The unit of the 1964frequency is KHz. 1965 1966If the KVM_CAP_VM_TSC_CONTROL capability is advertised, this can also 1967be used as a vm ioctl to set the initial tsc frequency of subsequently 1968created vCPUs. 1969 19704.56 KVM_GET_TSC_KHZ 1971-------------------- 1972 1973:Capability: KVM_CAP_GET_TSC_KHZ / KVM_CAP_VM_TSC_CONTROL 1974:Architectures: x86 1975:Type: vcpu ioctl / vm ioctl 1976:Parameters: none 1977:Returns: virtual tsc-khz on success, negative value on error 1978 1979Returns the tsc frequency of the guest. The unit of the return value is 1980KHz. If the host has unstable tsc this ioctl returns -EIO instead as an 1981error. 1982 1983 19844.57 KVM_GET_LAPIC 1985------------------ 1986 1987:Capability: KVM_CAP_IRQCHIP 1988:Architectures: x86 1989:Type: vcpu ioctl 1990:Parameters: struct kvm_lapic_state (out) 1991:Returns: 0 on success, -1 on error 1992 1993:: 1994 1995 #define KVM_APIC_REG_SIZE 0x400 1996 struct kvm_lapic_state { 1997 char regs[KVM_APIC_REG_SIZE]; 1998 }; 1999 2000Reads the Local APIC registers and copies them into the input argument. The 2001data format and layout are the same as documented in the architecture manual. 2002 2003If KVM_X2APIC_API_USE_32BIT_IDS feature of KVM_CAP_X2APIC_API is 2004enabled, then the format of APIC_ID register depends on the APIC mode 2005(reported by MSR_IA32_APICBASE) of its VCPU. x2APIC stores APIC ID in 2006the APIC_ID register (bytes 32-35). xAPIC only allows an 8-bit APIC ID 2007which is stored in bits 31-24 of the APIC register, or equivalently in 2008byte 35 of struct kvm_lapic_state's regs field. KVM_GET_LAPIC must then 2009be called after MSR_IA32_APICBASE has been set with KVM_SET_MSR. 2010 2011If KVM_X2APIC_API_USE_32BIT_IDS feature is disabled, struct kvm_lapic_state 2012always uses xAPIC format. 2013 2014 20154.58 KVM_SET_LAPIC 2016------------------ 2017 2018:Capability: KVM_CAP_IRQCHIP 2019:Architectures: x86 2020:Type: vcpu ioctl 2021:Parameters: struct kvm_lapic_state (in) 2022:Returns: 0 on success, -1 on error 2023 2024:: 2025 2026 #define KVM_APIC_REG_SIZE 0x400 2027 struct kvm_lapic_state { 2028 char regs[KVM_APIC_REG_SIZE]; 2029 }; 2030 2031Copies the input argument into the Local APIC registers. The data format 2032and layout are the same as documented in the architecture manual. 2033 2034The format of the APIC ID register (bytes 32-35 of struct kvm_lapic_state's 2035regs field) depends on the state of the KVM_CAP_X2APIC_API capability. 2036See the note in KVM_GET_LAPIC. 2037 2038 20394.59 KVM_IOEVENTFD 2040------------------ 2041 2042:Capability: KVM_CAP_IOEVENTFD 2043:Architectures: all 2044:Type: vm ioctl 2045:Parameters: struct kvm_ioeventfd (in) 2046:Returns: 0 on success, !0 on error 2047 2048This ioctl attaches or detaches an ioeventfd to a legal pio/mmio address 2049within the guest. A guest write in the registered address will signal the 2050provided event instead of triggering an exit. 2051 2052:: 2053 2054 struct kvm_ioeventfd { 2055 __u64 datamatch; 2056 __u64 addr; /* legal pio/mmio address */ 2057 __u32 len; /* 0, 1, 2, 4, or 8 bytes */ 2058 __s32 fd; 2059 __u32 flags; 2060 __u8 pad[36]; 2061 }; 2062 2063For the special case of virtio-ccw devices on s390, the ioevent is matched 2064to a subchannel/virtqueue tuple instead. 2065 2066The following flags are defined:: 2067 2068 #define KVM_IOEVENTFD_FLAG_DATAMATCH (1 << kvm_ioeventfd_flag_nr_datamatch) 2069 #define KVM_IOEVENTFD_FLAG_PIO (1 << kvm_ioeventfd_flag_nr_pio) 2070 #define KVM_IOEVENTFD_FLAG_DEASSIGN (1 << kvm_ioeventfd_flag_nr_deassign) 2071 #define KVM_IOEVENTFD_FLAG_VIRTIO_CCW_NOTIFY \ 2072 (1 << kvm_ioeventfd_flag_nr_virtio_ccw_notify) 2073 2074If datamatch flag is set, the event will be signaled only if the written value 2075to the registered address is equal to datamatch in struct kvm_ioeventfd. 2076 2077For virtio-ccw devices, addr contains the subchannel id and datamatch the 2078virtqueue index. 2079 2080With KVM_CAP_IOEVENTFD_ANY_LENGTH, a zero length ioeventfd is allowed, and 2081the kernel will ignore the length of guest write and may get a faster vmexit. 2082The speedup may only apply to specific architectures, but the ioeventfd will 2083work anyway. 2084 20854.60 KVM_DIRTY_TLB 2086------------------ 2087 2088:Capability: KVM_CAP_SW_TLB 2089:Architectures: ppc 2090:Type: vcpu ioctl 2091:Parameters: struct kvm_dirty_tlb (in) 2092:Returns: 0 on success, -1 on error 2093 2094:: 2095 2096 struct kvm_dirty_tlb { 2097 __u64 bitmap; 2098 __u32 num_dirty; 2099 }; 2100 2101This must be called whenever userspace has changed an entry in the shared 2102TLB, prior to calling KVM_RUN on the associated vcpu. 2103 2104The "bitmap" field is the userspace address of an array. This array 2105consists of a number of bits, equal to the total number of TLB entries as 2106determined by the last successful call to KVM_CONFIG_TLB, rounded up to the 2107nearest multiple of 64. 2108 2109Each bit corresponds to one TLB entry, ordered the same as in the shared TLB 2110array. 2111 2112The array is little-endian: the bit 0 is the least significant bit of the 2113first byte, bit 8 is the least significant bit of the second byte, etc. 2114This avoids any complications with differing word sizes. 2115 2116The "num_dirty" field is a performance hint for KVM to determine whether it 2117should skip processing the bitmap and just invalidate everything. It must 2118be set to the number of set bits in the bitmap. 2119 2120 21214.62 KVM_CREATE_SPAPR_TCE 2122------------------------- 2123 2124:Capability: KVM_CAP_SPAPR_TCE 2125:Architectures: powerpc 2126:Type: vm ioctl 2127:Parameters: struct kvm_create_spapr_tce (in) 2128:Returns: file descriptor for manipulating the created TCE table 2129 2130This creates a virtual TCE (translation control entry) table, which 2131is an IOMMU for PAPR-style virtual I/O. It is used to translate 2132logical addresses used in virtual I/O into guest physical addresses, 2133and provides a scatter/gather capability for PAPR virtual I/O. 2134 2135:: 2136 2137 /* for KVM_CAP_SPAPR_TCE */ 2138 struct kvm_create_spapr_tce { 2139 __u64 liobn; 2140 __u32 window_size; 2141 }; 2142 2143The liobn field gives the logical IO bus number for which to create a 2144TCE table. The window_size field specifies the size of the DMA window 2145which this TCE table will translate - the table will contain one 64 2146bit TCE entry for every 4kiB of the DMA window. 2147 2148When the guest issues an H_PUT_TCE hcall on a liobn for which a TCE 2149table has been created using this ioctl(), the kernel will handle it 2150in real mode, updating the TCE table. H_PUT_TCE calls for other 2151liobns will cause a vm exit and must be handled by userspace. 2152 2153The return value is a file descriptor which can be passed to mmap(2) 2154to map the created TCE table into userspace. This lets userspace read 2155the entries written by kernel-handled H_PUT_TCE calls, and also lets 2156userspace update the TCE table directly which is useful in some 2157circumstances. 2158 2159 21604.63 KVM_ALLOCATE_RMA 2161--------------------- 2162 2163:Capability: KVM_CAP_PPC_RMA 2164:Architectures: powerpc 2165:Type: vm ioctl 2166:Parameters: struct kvm_allocate_rma (out) 2167:Returns: file descriptor for mapping the allocated RMA 2168 2169This allocates a Real Mode Area (RMA) from the pool allocated at boot 2170time by the kernel. An RMA is a physically-contiguous, aligned region 2171of memory used on older POWER processors to provide the memory which 2172will be accessed by real-mode (MMU off) accesses in a KVM guest. 2173POWER processors support a set of sizes for the RMA that usually 2174includes 64MB, 128MB, 256MB and some larger powers of two. 2175 2176:: 2177 2178 /* for KVM_ALLOCATE_RMA */ 2179 struct kvm_allocate_rma { 2180 __u64 rma_size; 2181 }; 2182 2183The return value is a file descriptor which can be passed to mmap(2) 2184to map the allocated RMA into userspace. The mapped area can then be 2185passed to the KVM_SET_USER_MEMORY_REGION ioctl to establish it as the 2186RMA for a virtual machine. The size of the RMA in bytes (which is 2187fixed at host kernel boot time) is returned in the rma_size field of 2188the argument structure. 2189 2190The KVM_CAP_PPC_RMA capability is 1 or 2 if the KVM_ALLOCATE_RMA ioctl 2191is supported; 2 if the processor requires all virtual machines to have 2192an RMA, or 1 if the processor can use an RMA but doesn't require it, 2193because it supports the Virtual RMA (VRMA) facility. 2194 2195 21964.64 KVM_NMI 2197------------ 2198 2199:Capability: KVM_CAP_USER_NMI 2200:Architectures: x86 2201:Type: vcpu ioctl 2202:Parameters: none 2203:Returns: 0 on success, -1 on error 2204 2205Queues an NMI on the thread's vcpu. Note this is well defined only 2206when KVM_CREATE_IRQCHIP has not been called, since this is an interface 2207between the virtual cpu core and virtual local APIC. After KVM_CREATE_IRQCHIP 2208has been called, this interface is completely emulated within the kernel. 2209 2210To use this to emulate the LINT1 input with KVM_CREATE_IRQCHIP, use the 2211following algorithm: 2212 2213 - pause the vcpu 2214 - read the local APIC's state (KVM_GET_LAPIC) 2215 - check whether changing LINT1 will queue an NMI (see the LVT entry for LINT1) 2216 - if so, issue KVM_NMI 2217 - resume the vcpu 2218 2219Some guests configure the LINT1 NMI input to cause a panic, aiding in 2220debugging. 2221 2222 22234.65 KVM_S390_UCAS_MAP 2224---------------------- 2225 2226:Capability: KVM_CAP_S390_UCONTROL 2227:Architectures: s390 2228:Type: vcpu ioctl 2229:Parameters: struct kvm_s390_ucas_mapping (in) 2230:Returns: 0 in case of success 2231 2232The parameter is defined like this:: 2233 2234 struct kvm_s390_ucas_mapping { 2235 __u64 user_addr; 2236 __u64 vcpu_addr; 2237 __u64 length; 2238 }; 2239 2240This ioctl maps the memory at "user_addr" with the length "length" to 2241the vcpu's address space starting at "vcpu_addr". All parameters need to 2242be aligned by 1 megabyte. 2243 2244 22454.66 KVM_S390_UCAS_UNMAP 2246------------------------ 2247 2248:Capability: KVM_CAP_S390_UCONTROL 2249:Architectures: s390 2250:Type: vcpu ioctl 2251:Parameters: struct kvm_s390_ucas_mapping (in) 2252:Returns: 0 in case of success 2253 2254The parameter is defined like this:: 2255 2256 struct kvm_s390_ucas_mapping { 2257 __u64 user_addr; 2258 __u64 vcpu_addr; 2259 __u64 length; 2260 }; 2261 2262This ioctl unmaps the memory in the vcpu's address space starting at 2263"vcpu_addr" with the length "length". The field "user_addr" is ignored. 2264All parameters need to be aligned by 1 megabyte. 2265 2266 22674.67 KVM_S390_VCPU_FAULT 2268------------------------ 2269 2270:Capability: KVM_CAP_S390_UCONTROL 2271:Architectures: s390 2272:Type: vcpu ioctl 2273:Parameters: vcpu absolute address (in) 2274:Returns: 0 in case of success 2275 2276This call creates a page table entry on the virtual cpu's address space 2277(for user controlled virtual machines) or the virtual machine's address 2278space (for regular virtual machines). This only works for minor faults, 2279thus it's recommended to access subject memory page via the user page 2280table upfront. This is useful to handle validity intercepts for user 2281controlled virtual machines to fault in the virtual cpu's lowcore pages 2282prior to calling the KVM_RUN ioctl. 2283 2284 22854.68 KVM_SET_ONE_REG 2286-------------------- 2287 2288:Capability: KVM_CAP_ONE_REG 2289:Architectures: all 2290:Type: vcpu ioctl 2291:Parameters: struct kvm_one_reg (in) 2292:Returns: 0 on success, negative value on failure 2293 2294Errors: 2295 2296 ====== ============================================================ 2297 ENOENT no such register 2298 EINVAL invalid register ID, or no such register or used with VMs in 2299 protected virtualization mode on s390 2300 EPERM (arm64) register access not allowed before vcpu finalization 2301 EBUSY (riscv) changing register value not allowed after the vcpu 2302 has run at least once 2303 ====== ============================================================ 2304 2305(These error codes are indicative only: do not rely on a specific error 2306code being returned in a specific situation.) 2307 2308:: 2309 2310 struct kvm_one_reg { 2311 __u64 id; 2312 __u64 addr; 2313 }; 2314 2315Using this ioctl, a single vcpu register can be set to a specific value 2316defined by user space with the passed in struct kvm_one_reg, where id 2317refers to the register identifier as described below and addr is a pointer 2318to a variable with the respective size. There can be architecture agnostic 2319and architecture specific registers. Each have their own range of operation 2320and their own constants and width. To keep track of the implemented 2321registers, find a list below: 2322 2323 ======= =============================== ============ 2324 Arch Register Width (bits) 2325 ======= =============================== ============ 2326 PPC KVM_REG_PPC_HIOR 64 2327 PPC KVM_REG_PPC_IAC1 64 2328 PPC KVM_REG_PPC_IAC2 64 2329 PPC KVM_REG_PPC_IAC3 64 2330 PPC KVM_REG_PPC_IAC4 64 2331 PPC KVM_REG_PPC_DAC1 64 2332 PPC KVM_REG_PPC_DAC2 64 2333 PPC KVM_REG_PPC_DABR 64 2334 PPC KVM_REG_PPC_DSCR 64 2335 PPC KVM_REG_PPC_PURR 64 2336 PPC KVM_REG_PPC_SPURR 64 2337 PPC KVM_REG_PPC_DAR 64 2338 PPC KVM_REG_PPC_DSISR 32 2339 PPC KVM_REG_PPC_AMR 64 2340 PPC KVM_REG_PPC_UAMOR 64 2341 PPC KVM_REG_PPC_MMCR0 64 2342 PPC KVM_REG_PPC_MMCR1 64 2343 PPC KVM_REG_PPC_MMCRA 64 2344 PPC KVM_REG_PPC_MMCR2 64 2345 PPC KVM_REG_PPC_MMCRS 64 2346 PPC KVM_REG_PPC_MMCR3 64 2347 PPC KVM_REG_PPC_SIAR 64 2348 PPC KVM_REG_PPC_SDAR 64 2349 PPC KVM_REG_PPC_SIER 64 2350 PPC KVM_REG_PPC_SIER2 64 2351 PPC KVM_REG_PPC_SIER3 64 2352 PPC KVM_REG_PPC_PMC1 32 2353 PPC KVM_REG_PPC_PMC2 32 2354 PPC KVM_REG_PPC_PMC3 32 2355 PPC KVM_REG_PPC_PMC4 32 2356 PPC KVM_REG_PPC_PMC5 32 2357 PPC KVM_REG_PPC_PMC6 32 2358 PPC KVM_REG_PPC_PMC7 32 2359 PPC KVM_REG_PPC_PMC8 32 2360 PPC KVM_REG_PPC_FPR0 64 2361 ... 2362 PPC KVM_REG_PPC_FPR31 64 2363 PPC KVM_REG_PPC_VR0 128 2364 ... 2365 PPC KVM_REG_PPC_VR31 128 2366 PPC KVM_REG_PPC_VSR0 128 2367 ... 2368 PPC KVM_REG_PPC_VSR31 128 2369 PPC KVM_REG_PPC_FPSCR 64 2370 PPC KVM_REG_PPC_VSCR 32 2371 PPC KVM_REG_PPC_VPA_ADDR 64 2372 PPC KVM_REG_PPC_VPA_SLB 128 2373 PPC KVM_REG_PPC_VPA_DTL 128 2374 PPC KVM_REG_PPC_EPCR 32 2375 PPC KVM_REG_PPC_EPR 32 2376 PPC KVM_REG_PPC_TCR 32 2377 PPC KVM_REG_PPC_TSR 32 2378 PPC KVM_REG_PPC_OR_TSR 32 2379 PPC KVM_REG_PPC_CLEAR_TSR 32 2380 PPC KVM_REG_PPC_MAS0 32 2381 PPC KVM_REG_PPC_MAS1 32 2382 PPC KVM_REG_PPC_MAS2 64 2383 PPC KVM_REG_PPC_MAS7_3 64 2384 PPC KVM_REG_PPC_MAS4 32 2385 PPC KVM_REG_PPC_MAS6 32 2386 PPC KVM_REG_PPC_MMUCFG 32 2387 PPC KVM_REG_PPC_TLB0CFG 32 2388 PPC KVM_REG_PPC_TLB1CFG 32 2389 PPC KVM_REG_PPC_TLB2CFG 32 2390 PPC KVM_REG_PPC_TLB3CFG 32 2391 PPC KVM_REG_PPC_TLB0PS 32 2392 PPC KVM_REG_PPC_TLB1PS 32 2393 PPC KVM_REG_PPC_TLB2PS 32 2394 PPC KVM_REG_PPC_TLB3PS 32 2395 PPC KVM_REG_PPC_EPTCFG 32 2396 PPC KVM_REG_PPC_ICP_STATE 64 2397 PPC KVM_REG_PPC_VP_STATE 128 2398 PPC KVM_REG_PPC_TB_OFFSET 64 2399 PPC KVM_REG_PPC_SPMC1 32 2400 PPC KVM_REG_PPC_SPMC2 32 2401 PPC KVM_REG_PPC_IAMR 64 2402 PPC KVM_REG_PPC_TFHAR 64 2403 PPC KVM_REG_PPC_TFIAR 64 2404 PPC KVM_REG_PPC_TEXASR 64 2405 PPC KVM_REG_PPC_FSCR 64 2406 PPC KVM_REG_PPC_PSPB 32 2407 PPC KVM_REG_PPC_EBBHR 64 2408 PPC KVM_REG_PPC_EBBRR 64 2409 PPC KVM_REG_PPC_BESCR 64 2410 PPC KVM_REG_PPC_TAR 64 2411 PPC KVM_REG_PPC_DPDES 64 2412 PPC KVM_REG_PPC_DAWR 64 2413 PPC KVM_REG_PPC_DAWRX 64 2414 PPC KVM_REG_PPC_CIABR 64 2415 PPC KVM_REG_PPC_IC 64 2416 PPC KVM_REG_PPC_VTB 64 2417 PPC KVM_REG_PPC_CSIGR 64 2418 PPC KVM_REG_PPC_TACR 64 2419 PPC KVM_REG_PPC_TCSCR 64 2420 PPC KVM_REG_PPC_PID 64 2421 PPC KVM_REG_PPC_ACOP 64 2422 PPC KVM_REG_PPC_VRSAVE 32 2423 PPC KVM_REG_PPC_LPCR 32 2424 PPC KVM_REG_PPC_LPCR_64 64 2425 PPC KVM_REG_PPC_PPR 64 2426 PPC KVM_REG_PPC_ARCH_COMPAT 32 2427 PPC KVM_REG_PPC_DABRX 32 2428 PPC KVM_REG_PPC_WORT 64 2429 PPC KVM_REG_PPC_SPRG9 64 2430 PPC KVM_REG_PPC_DBSR 32 2431 PPC KVM_REG_PPC_TIDR 64 2432 PPC KVM_REG_PPC_PSSCR 64 2433 PPC KVM_REG_PPC_DEC_EXPIRY 64 2434 PPC KVM_REG_PPC_PTCR 64 2435 PPC KVM_REG_PPC_DAWR1 64 2436 PPC KVM_REG_PPC_DAWRX1 64 2437 PPC KVM_REG_PPC_TM_GPR0 64 2438 ... 2439 PPC KVM_REG_PPC_TM_GPR31 64 2440 PPC KVM_REG_PPC_TM_VSR0 128 2441 ... 2442 PPC KVM_REG_PPC_TM_VSR63 128 2443 PPC KVM_REG_PPC_TM_CR 64 2444 PPC KVM_REG_PPC_TM_LR 64 2445 PPC KVM_REG_PPC_TM_CTR 64 2446 PPC KVM_REG_PPC_TM_FPSCR 64 2447 PPC KVM_REG_PPC_TM_AMR 64 2448 PPC KVM_REG_PPC_TM_PPR 64 2449 PPC KVM_REG_PPC_TM_VRSAVE 64 2450 PPC KVM_REG_PPC_TM_VSCR 32 2451 PPC KVM_REG_PPC_TM_DSCR 64 2452 PPC KVM_REG_PPC_TM_TAR 64 2453 PPC KVM_REG_PPC_TM_XER 64 2454 2455 MIPS KVM_REG_MIPS_R0 64 2456 ... 2457 MIPS KVM_REG_MIPS_R31 64 2458 MIPS KVM_REG_MIPS_HI 64 2459 MIPS KVM_REG_MIPS_LO 64 2460 MIPS KVM_REG_MIPS_PC 64 2461 MIPS KVM_REG_MIPS_CP0_INDEX 32 2462 MIPS KVM_REG_MIPS_CP0_ENTRYLO0 64 2463 MIPS KVM_REG_MIPS_CP0_ENTRYLO1 64 2464 MIPS KVM_REG_MIPS_CP0_CONTEXT 64 2465 MIPS KVM_REG_MIPS_CP0_CONTEXTCONFIG 32 2466 MIPS KVM_REG_MIPS_CP0_USERLOCAL 64 2467 MIPS KVM_REG_MIPS_CP0_XCONTEXTCONFIG 64 2468 MIPS KVM_REG_MIPS_CP0_PAGEMASK 32 2469 MIPS KVM_REG_MIPS_CP0_PAGEGRAIN 32 2470 MIPS KVM_REG_MIPS_CP0_SEGCTL0 64 2471 MIPS KVM_REG_MIPS_CP0_SEGCTL1 64 2472 MIPS KVM_REG_MIPS_CP0_SEGCTL2 64 2473 MIPS KVM_REG_MIPS_CP0_PWBASE 64 2474 MIPS KVM_REG_MIPS_CP0_PWFIELD 64 2475 MIPS KVM_REG_MIPS_CP0_PWSIZE 64 2476 MIPS KVM_REG_MIPS_CP0_WIRED 32 2477 MIPS KVM_REG_MIPS_CP0_PWCTL 32 2478 MIPS KVM_REG_MIPS_CP0_HWRENA 32 2479 MIPS KVM_REG_MIPS_CP0_BADVADDR 64 2480 MIPS KVM_REG_MIPS_CP0_BADINSTR 32 2481 MIPS KVM_REG_MIPS_CP0_BADINSTRP 32 2482 MIPS KVM_REG_MIPS_CP0_COUNT 32 2483 MIPS KVM_REG_MIPS_CP0_ENTRYHI 64 2484 MIPS KVM_REG_MIPS_CP0_COMPARE 32 2485 MIPS KVM_REG_MIPS_CP0_STATUS 32 2486 MIPS KVM_REG_MIPS_CP0_INTCTL 32 2487 MIPS KVM_REG_MIPS_CP0_CAUSE 32 2488 MIPS KVM_REG_MIPS_CP0_EPC 64 2489 MIPS KVM_REG_MIPS_CP0_PRID 32 2490 MIPS KVM_REG_MIPS_CP0_EBASE 64 2491 MIPS KVM_REG_MIPS_CP0_CONFIG 32 2492 MIPS KVM_REG_MIPS_CP0_CONFIG1 32 2493 MIPS KVM_REG_MIPS_CP0_CONFIG2 32 2494 MIPS KVM_REG_MIPS_CP0_CONFIG3 32 2495 MIPS KVM_REG_MIPS_CP0_CONFIG4 32 2496 MIPS KVM_REG_MIPS_CP0_CONFIG5 32 2497 MIPS KVM_REG_MIPS_CP0_CONFIG7 32 2498 MIPS KVM_REG_MIPS_CP0_XCONTEXT 64 2499 MIPS KVM_REG_MIPS_CP0_ERROREPC 64 2500 MIPS KVM_REG_MIPS_CP0_KSCRATCH1 64 2501 MIPS KVM_REG_MIPS_CP0_KSCRATCH2 64 2502 MIPS KVM_REG_MIPS_CP0_KSCRATCH3 64 2503 MIPS KVM_REG_MIPS_CP0_KSCRATCH4 64 2504 MIPS KVM_REG_MIPS_CP0_KSCRATCH5 64 2505 MIPS KVM_REG_MIPS_CP0_KSCRATCH6 64 2506 MIPS KVM_REG_MIPS_CP0_MAAR(0..63) 64 2507 MIPS KVM_REG_MIPS_COUNT_CTL 64 2508 MIPS KVM_REG_MIPS_COUNT_RESUME 64 2509 MIPS KVM_REG_MIPS_COUNT_HZ 64 2510 MIPS KVM_REG_MIPS_FPR_32(0..31) 32 2511 MIPS KVM_REG_MIPS_FPR_64(0..31) 64 2512 MIPS KVM_REG_MIPS_VEC_128(0..31) 128 2513 MIPS KVM_REG_MIPS_FCR_IR 32 2514 MIPS KVM_REG_MIPS_FCR_CSR 32 2515 MIPS KVM_REG_MIPS_MSA_IR 32 2516 MIPS KVM_REG_MIPS_MSA_CSR 32 2517 ======= =============================== ============ 2518 2519ARM registers are mapped using the lower 32 bits. The upper 16 of that 2520is the register group type, or coprocessor number: 2521 2522ARM core registers have the following id bit patterns:: 2523 2524 0x4020 0000 0010 <index into the kvm_regs struct:16> 2525 2526ARM 32-bit CP15 registers have the following id bit patterns:: 2527 2528 0x4020 0000 000F <zero:1> <crn:4> <crm:4> <opc1:4> <opc2:3> 2529 2530ARM 64-bit CP15 registers have the following id bit patterns:: 2531 2532 0x4030 0000 000F <zero:1> <zero:4> <crm:4> <opc1:4> <zero:3> 2533 2534ARM CCSIDR registers are demultiplexed by CSSELR value:: 2535 2536 0x4020 0000 0011 00 <csselr:8> 2537 2538ARM 32-bit VFP control registers have the following id bit patterns:: 2539 2540 0x4020 0000 0012 1 <regno:12> 2541 2542ARM 64-bit FP registers have the following id bit patterns:: 2543 2544 0x4030 0000 0012 0 <regno:12> 2545 2546ARM firmware pseudo-registers have the following bit pattern:: 2547 2548 0x4030 0000 0014 <regno:16> 2549 2550 2551arm64 registers are mapped using the lower 32 bits. The upper 16 of 2552that is the register group type, or coprocessor number: 2553 2554arm64 core/FP-SIMD registers have the following id bit patterns. Note 2555that the size of the access is variable, as the kvm_regs structure 2556contains elements ranging from 32 to 128 bits. The index is a 32bit 2557value in the kvm_regs structure seen as a 32bit array:: 2558 2559 0x60x0 0000 0010 <index into the kvm_regs struct:16> 2560 2561Specifically: 2562 2563======================= ========= ===== ======================================= 2564 Encoding Register Bits kvm_regs member 2565======================= ========= ===== ======================================= 2566 0x6030 0000 0010 0000 X0 64 regs.regs[0] 2567 0x6030 0000 0010 0002 X1 64 regs.regs[1] 2568 ... 2569 0x6030 0000 0010 003c X30 64 regs.regs[30] 2570 0x6030 0000 0010 003e SP 64 regs.sp 2571 0x6030 0000 0010 0040 PC 64 regs.pc 2572 0x6030 0000 0010 0042 PSTATE 64 regs.pstate 2573 0x6030 0000 0010 0044 SP_EL1 64 sp_el1 2574 0x6030 0000 0010 0046 ELR_EL1 64 elr_el1 2575 0x6030 0000 0010 0048 SPSR_EL1 64 spsr[KVM_SPSR_EL1] (alias SPSR_SVC) 2576 0x6030 0000 0010 004a SPSR_ABT 64 spsr[KVM_SPSR_ABT] 2577 0x6030 0000 0010 004c SPSR_UND 64 spsr[KVM_SPSR_UND] 2578 0x6030 0000 0010 004e SPSR_IRQ 64 spsr[KVM_SPSR_IRQ] 2579 0x6060 0000 0010 0050 SPSR_FIQ 64 spsr[KVM_SPSR_FIQ] 2580 0x6040 0000 0010 0054 V0 128 fp_regs.vregs[0] [1]_ 2581 0x6040 0000 0010 0058 V1 128 fp_regs.vregs[1] [1]_ 2582 ... 2583 0x6040 0000 0010 00d0 V31 128 fp_regs.vregs[31] [1]_ 2584 0x6020 0000 0010 00d4 FPSR 32 fp_regs.fpsr 2585 0x6020 0000 0010 00d5 FPCR 32 fp_regs.fpcr 2586======================= ========= ===== ======================================= 2587 2588.. [1] These encodings are not accepted for SVE-enabled vcpus. See 2589 KVM_ARM_VCPU_INIT. 2590 2591 The equivalent register content can be accessed via bits [127:0] of 2592 the corresponding SVE Zn registers instead for vcpus that have SVE 2593 enabled (see below). 2594 2595arm64 CCSIDR registers are demultiplexed by CSSELR value:: 2596 2597 0x6020 0000 0011 00 <csselr:8> 2598 2599arm64 system registers have the following id bit patterns:: 2600 2601 0x6030 0000 0013 <op0:2> <op1:3> <crn:4> <crm:4> <op2:3> 2602 2603.. warning:: 2604 2605 Two system register IDs do not follow the specified pattern. These 2606 are KVM_REG_ARM_TIMER_CVAL and KVM_REG_ARM_TIMER_CNT, which map to 2607 system registers CNTV_CVAL_EL0 and CNTVCT_EL0 respectively. These 2608 two had their values accidentally swapped, which means TIMER_CVAL is 2609 derived from the register encoding for CNTVCT_EL0 and TIMER_CNT is 2610 derived from the register encoding for CNTV_CVAL_EL0. As this is 2611 API, it must remain this way. 2612 2613arm64 firmware pseudo-registers have the following bit pattern:: 2614 2615 0x6030 0000 0014 <regno:16> 2616 2617arm64 SVE registers have the following bit patterns:: 2618 2619 0x6080 0000 0015 00 <n:5> <slice:5> Zn bits[2048*slice + 2047 : 2048*slice] 2620 0x6050 0000 0015 04 <n:4> <slice:5> Pn bits[256*slice + 255 : 256*slice] 2621 0x6050 0000 0015 060 <slice:5> FFR bits[256*slice + 255 : 256*slice] 2622 0x6060 0000 0015 ffff KVM_REG_ARM64_SVE_VLS pseudo-register 2623 2624Access to register IDs where 2048 * slice >= 128 * max_vq will fail with 2625ENOENT. max_vq is the vcpu's maximum supported vector length in 128-bit 2626quadwords: see [2]_ below. 2627 2628These registers are only accessible on vcpus for which SVE is enabled. 2629See KVM_ARM_VCPU_INIT for details. 2630 2631In addition, except for KVM_REG_ARM64_SVE_VLS, these registers are not 2632accessible until the vcpu's SVE configuration has been finalized 2633using KVM_ARM_VCPU_FINALIZE(KVM_ARM_VCPU_SVE). See KVM_ARM_VCPU_INIT 2634and KVM_ARM_VCPU_FINALIZE for more information about this procedure. 2635 2636KVM_REG_ARM64_SVE_VLS is a pseudo-register that allows the set of vector 2637lengths supported by the vcpu to be discovered and configured by 2638userspace. When transferred to or from user memory via KVM_GET_ONE_REG 2639or KVM_SET_ONE_REG, the value of this register is of type 2640__u64[KVM_ARM64_SVE_VLS_WORDS], and encodes the set of vector lengths as 2641follows:: 2642 2643 __u64 vector_lengths[KVM_ARM64_SVE_VLS_WORDS]; 2644 2645 if (vq >= SVE_VQ_MIN && vq <= SVE_VQ_MAX && 2646 ((vector_lengths[(vq - KVM_ARM64_SVE_VQ_MIN) / 64] >> 2647 ((vq - KVM_ARM64_SVE_VQ_MIN) % 64)) & 1)) 2648 /* Vector length vq * 16 bytes supported */ 2649 else 2650 /* Vector length vq * 16 bytes not supported */ 2651 2652.. [2] The maximum value vq for which the above condition is true is 2653 max_vq. This is the maximum vector length available to the guest on 2654 this vcpu, and determines which register slices are visible through 2655 this ioctl interface. 2656 2657(See Documentation/arch/arm64/sve.rst for an explanation of the "vq" 2658nomenclature.) 2659 2660KVM_REG_ARM64_SVE_VLS is only accessible after KVM_ARM_VCPU_INIT. 2661KVM_ARM_VCPU_INIT initialises it to the best set of vector lengths that 2662the host supports. 2663 2664Userspace may subsequently modify it if desired until the vcpu's SVE 2665configuration is finalized using KVM_ARM_VCPU_FINALIZE(KVM_ARM_VCPU_SVE). 2666 2667Apart from simply removing all vector lengths from the host set that 2668exceed some value, support for arbitrarily chosen sets of vector lengths 2669is hardware-dependent and may not be available. Attempting to configure 2670an invalid set of vector lengths via KVM_SET_ONE_REG will fail with 2671EINVAL. 2672 2673After the vcpu's SVE configuration is finalized, further attempts to 2674write this register will fail with EPERM. 2675 2676arm64 bitmap feature firmware pseudo-registers have the following bit pattern:: 2677 2678 0x6030 0000 0016 <regno:16> 2679 2680The bitmap feature firmware registers exposes the hypercall services that 2681are available for userspace to configure. The set bits corresponds to the 2682services that are available for the guests to access. By default, KVM 2683sets all the supported bits during VM initialization. The userspace can 2684discover the available services via KVM_GET_ONE_REG, and write back the 2685bitmap corresponding to the features that it wishes guests to see via 2686KVM_SET_ONE_REG. 2687 2688Note: These registers are immutable once any of the vCPUs of the VM has 2689run at least once. A KVM_SET_ONE_REG in such a scenario will return 2690a -EBUSY to userspace. 2691 2692(See Documentation/virt/kvm/arm/hypercalls.rst for more details.) 2693 2694 2695MIPS registers are mapped using the lower 32 bits. The upper 16 of that is 2696the register group type: 2697 2698MIPS core registers (see above) have the following id bit patterns:: 2699 2700 0x7030 0000 0000 <reg:16> 2701 2702MIPS CP0 registers (see KVM_REG_MIPS_CP0_* above) have the following id bit 2703patterns depending on whether they're 32-bit or 64-bit registers:: 2704 2705 0x7020 0000 0001 00 <reg:5> <sel:3> (32-bit) 2706 0x7030 0000 0001 00 <reg:5> <sel:3> (64-bit) 2707 2708Note: KVM_REG_MIPS_CP0_ENTRYLO0 and KVM_REG_MIPS_CP0_ENTRYLO1 are the MIPS64 2709versions of the EntryLo registers regardless of the word size of the host 2710hardware, host kernel, guest, and whether XPA is present in the guest, i.e. 2711with the RI and XI bits (if they exist) in bits 63 and 62 respectively, and 2712the PFNX field starting at bit 30. 2713 2714MIPS MAARs (see KVM_REG_MIPS_CP0_MAAR(*) above) have the following id bit 2715patterns:: 2716 2717 0x7030 0000 0001 01 <reg:8> 2718 2719MIPS KVM control registers (see above) have the following id bit patterns:: 2720 2721 0x7030 0000 0002 <reg:16> 2722 2723MIPS FPU registers (see KVM_REG_MIPS_FPR_{32,64}() above) have the following 2724id bit patterns depending on the size of the register being accessed. They are 2725always accessed according to the current guest FPU mode (Status.FR and 2726Config5.FRE), i.e. as the guest would see them, and they become unpredictable 2727if the guest FPU mode is changed. MIPS SIMD Architecture (MSA) vector 2728registers (see KVM_REG_MIPS_VEC_128() above) have similar patterns as they 2729overlap the FPU registers:: 2730 2731 0x7020 0000 0003 00 <0:3> <reg:5> (32-bit FPU registers) 2732 0x7030 0000 0003 00 <0:3> <reg:5> (64-bit FPU registers) 2733 0x7040 0000 0003 00 <0:3> <reg:5> (128-bit MSA vector registers) 2734 2735MIPS FPU control registers (see KVM_REG_MIPS_FCR_{IR,CSR} above) have the 2736following id bit patterns:: 2737 2738 0x7020 0000 0003 01 <0:3> <reg:5> 2739 2740MIPS MSA control registers (see KVM_REG_MIPS_MSA_{IR,CSR} above) have the 2741following id bit patterns:: 2742 2743 0x7020 0000 0003 02 <0:3> <reg:5> 2744 2745RISC-V registers are mapped using the lower 32 bits. The upper 8 bits of 2746that is the register group type. 2747 2748RISC-V config registers are meant for configuring a Guest VCPU and it has 2749the following id bit patterns:: 2750 2751 0x8020 0000 01 <index into the kvm_riscv_config struct:24> (32bit Host) 2752 0x8030 0000 01 <index into the kvm_riscv_config struct:24> (64bit Host) 2753 2754Following are the RISC-V config registers: 2755 2756======================= ========= ============================================= 2757 Encoding Register Description 2758======================= ========= ============================================= 2759 0x80x0 0000 0100 0000 isa ISA feature bitmap of Guest VCPU 2760======================= ========= ============================================= 2761 2762The isa config register can be read anytime but can only be written before 2763a Guest VCPU runs. It will have ISA feature bits matching underlying host 2764set by default. 2765 2766RISC-V core registers represent the general execution state of a Guest VCPU 2767and it has the following id bit patterns:: 2768 2769 0x8020 0000 02 <index into the kvm_riscv_core struct:24> (32bit Host) 2770 0x8030 0000 02 <index into the kvm_riscv_core struct:24> (64bit Host) 2771 2772Following are the RISC-V core registers: 2773 2774======================= ========= ============================================= 2775 Encoding Register Description 2776======================= ========= ============================================= 2777 0x80x0 0000 0200 0000 regs.pc Program counter 2778 0x80x0 0000 0200 0001 regs.ra Return address 2779 0x80x0 0000 0200 0002 regs.sp Stack pointer 2780 0x80x0 0000 0200 0003 regs.gp Global pointer 2781 0x80x0 0000 0200 0004 regs.tp Task pointer 2782 0x80x0 0000 0200 0005 regs.t0 Caller saved register 0 2783 0x80x0 0000 0200 0006 regs.t1 Caller saved register 1 2784 0x80x0 0000 0200 0007 regs.t2 Caller saved register 2 2785 0x80x0 0000 0200 0008 regs.s0 Callee saved register 0 2786 0x80x0 0000 0200 0009 regs.s1 Callee saved register 1 2787 0x80x0 0000 0200 000a regs.a0 Function argument (or return value) 0 2788 0x80x0 0000 0200 000b regs.a1 Function argument (or return value) 1 2789 0x80x0 0000 0200 000c regs.a2 Function argument 2 2790 0x80x0 0000 0200 000d regs.a3 Function argument 3 2791 0x80x0 0000 0200 000e regs.a4 Function argument 4 2792 0x80x0 0000 0200 000f regs.a5 Function argument 5 2793 0x80x0 0000 0200 0010 regs.a6 Function argument 6 2794 0x80x0 0000 0200 0011 regs.a7 Function argument 7 2795 0x80x0 0000 0200 0012 regs.s2 Callee saved register 2 2796 0x80x0 0000 0200 0013 regs.s3 Callee saved register 3 2797 0x80x0 0000 0200 0014 regs.s4 Callee saved register 4 2798 0x80x0 0000 0200 0015 regs.s5 Callee saved register 5 2799 0x80x0 0000 0200 0016 regs.s6 Callee saved register 6 2800 0x80x0 0000 0200 0017 regs.s7 Callee saved register 7 2801 0x80x0 0000 0200 0018 regs.s8 Callee saved register 8 2802 0x80x0 0000 0200 0019 regs.s9 Callee saved register 9 2803 0x80x0 0000 0200 001a regs.s10 Callee saved register 10 2804 0x80x0 0000 0200 001b regs.s11 Callee saved register 11 2805 0x80x0 0000 0200 001c regs.t3 Caller saved register 3 2806 0x80x0 0000 0200 001d regs.t4 Caller saved register 4 2807 0x80x0 0000 0200 001e regs.t5 Caller saved register 5 2808 0x80x0 0000 0200 001f regs.t6 Caller saved register 6 2809 0x80x0 0000 0200 0020 mode Privilege mode (1 = S-mode or 0 = U-mode) 2810======================= ========= ============================================= 2811 2812RISC-V csr registers represent the supervisor mode control/status registers 2813of a Guest VCPU and it has the following id bit patterns:: 2814 2815 0x8020 0000 03 <index into the kvm_riscv_csr struct:24> (32bit Host) 2816 0x8030 0000 03 <index into the kvm_riscv_csr struct:24> (64bit Host) 2817 2818Following are the RISC-V csr registers: 2819 2820======================= ========= ============================================= 2821 Encoding Register Description 2822======================= ========= ============================================= 2823 0x80x0 0000 0300 0000 sstatus Supervisor status 2824 0x80x0 0000 0300 0001 sie Supervisor interrupt enable 2825 0x80x0 0000 0300 0002 stvec Supervisor trap vector base 2826 0x80x0 0000 0300 0003 sscratch Supervisor scratch register 2827 0x80x0 0000 0300 0004 sepc Supervisor exception program counter 2828 0x80x0 0000 0300 0005 scause Supervisor trap cause 2829 0x80x0 0000 0300 0006 stval Supervisor bad address or instruction 2830 0x80x0 0000 0300 0007 sip Supervisor interrupt pending 2831 0x80x0 0000 0300 0008 satp Supervisor address translation and protection 2832======================= ========= ============================================= 2833 2834RISC-V timer registers represent the timer state of a Guest VCPU and it has 2835the following id bit patterns:: 2836 2837 0x8030 0000 04 <index into the kvm_riscv_timer struct:24> 2838 2839Following are the RISC-V timer registers: 2840 2841======================= ========= ============================================= 2842 Encoding Register Description 2843======================= ========= ============================================= 2844 0x8030 0000 0400 0000 frequency Time base frequency (read-only) 2845 0x8030 0000 0400 0001 time Time value visible to Guest 2846 0x8030 0000 0400 0002 compare Time compare programmed by Guest 2847 0x8030 0000 0400 0003 state Time compare state (1 = ON or 0 = OFF) 2848======================= ========= ============================================= 2849 2850RISC-V F-extension registers represent the single precision floating point 2851state of a Guest VCPU and it has the following id bit patterns:: 2852 2853 0x8020 0000 05 <index into the __riscv_f_ext_state struct:24> 2854 2855Following are the RISC-V F-extension registers: 2856 2857======================= ========= ============================================= 2858 Encoding Register Description 2859======================= ========= ============================================= 2860 0x8020 0000 0500 0000 f[0] Floating point register 0 2861 ... 2862 0x8020 0000 0500 001f f[31] Floating point register 31 2863 0x8020 0000 0500 0020 fcsr Floating point control and status register 2864======================= ========= ============================================= 2865 2866RISC-V D-extension registers represent the double precision floating point 2867state of a Guest VCPU and it has the following id bit patterns:: 2868 2869 0x8020 0000 06 <index into the __riscv_d_ext_state struct:24> (fcsr) 2870 0x8030 0000 06 <index into the __riscv_d_ext_state struct:24> (non-fcsr) 2871 2872Following are the RISC-V D-extension registers: 2873 2874======================= ========= ============================================= 2875 Encoding Register Description 2876======================= ========= ============================================= 2877 0x8030 0000 0600 0000 f[0] Floating point register 0 2878 ... 2879 0x8030 0000 0600 001f f[31] Floating point register 31 2880 0x8020 0000 0600 0020 fcsr Floating point control and status register 2881======================= ========= ============================================= 2882 2883LoongArch registers are mapped using the lower 32 bits. The upper 16 bits of 2884that is the register group type. 2885 2886LoongArch csr registers are used to control guest cpu or get status of guest 2887cpu, and they have the following id bit patterns:: 2888 2889 0x9030 0000 0001 00 <reg:5> <sel:3> (64-bit) 2890 2891LoongArch KVM control registers are used to implement some new defined functions 2892such as set vcpu counter or reset vcpu, and they have the following id bit patterns:: 2893 2894 0x9030 0000 0002 <reg:16> 2895 2896 28974.69 KVM_GET_ONE_REG 2898-------------------- 2899 2900:Capability: KVM_CAP_ONE_REG 2901:Architectures: all 2902:Type: vcpu ioctl 2903:Parameters: struct kvm_one_reg (in and out) 2904:Returns: 0 on success, negative value on failure 2905 2906Errors include: 2907 2908 ======== ============================================================ 2909 ENOENT no such register 2910 EINVAL invalid register ID, or no such register or used with VMs in 2911 protected virtualization mode on s390 2912 EPERM (arm64) register access not allowed before vcpu finalization 2913 ======== ============================================================ 2914 2915(These error codes are indicative only: do not rely on a specific error 2916code being returned in a specific situation.) 2917 2918This ioctl allows to receive the value of a single register implemented 2919in a vcpu. The register to read is indicated by the "id" field of the 2920kvm_one_reg struct passed in. On success, the register value can be found 2921at the memory location pointed to by "addr". 2922 2923The list of registers accessible using this interface is identical to the 2924list in 4.68. 2925 2926 29274.70 KVM_KVMCLOCK_CTRL 2928---------------------- 2929 2930:Capability: KVM_CAP_KVMCLOCK_CTRL 2931:Architectures: Any that implement pvclocks (currently x86 only) 2932:Type: vcpu ioctl 2933:Parameters: None 2934:Returns: 0 on success, -1 on error 2935 2936This ioctl sets a flag accessible to the guest indicating that the specified 2937vCPU has been paused by the host userspace. 2938 2939The host will set a flag in the pvclock structure that is checked from the 2940soft lockup watchdog. The flag is part of the pvclock structure that is 2941shared between guest and host, specifically the second bit of the flags 2942field of the pvclock_vcpu_time_info structure. It will be set exclusively by 2943the host and read/cleared exclusively by the guest. The guest operation of 2944checking and clearing the flag must be an atomic operation so 2945load-link/store-conditional, or equivalent must be used. There are two cases 2946where the guest will clear the flag: when the soft lockup watchdog timer resets 2947itself or when a soft lockup is detected. This ioctl can be called any time 2948after pausing the vcpu, but before it is resumed. 2949 2950 29514.71 KVM_SIGNAL_MSI 2952------------------- 2953 2954:Capability: KVM_CAP_SIGNAL_MSI 2955:Architectures: x86 arm64 2956:Type: vm ioctl 2957:Parameters: struct kvm_msi (in) 2958:Returns: >0 on delivery, 0 if guest blocked the MSI, and -1 on error 2959 2960Directly inject a MSI message. Only valid with in-kernel irqchip that handles 2961MSI messages. 2962 2963:: 2964 2965 struct kvm_msi { 2966 __u32 address_lo; 2967 __u32 address_hi; 2968 __u32 data; 2969 __u32 flags; 2970 __u32 devid; 2971 __u8 pad[12]; 2972 }; 2973 2974flags: 2975 KVM_MSI_VALID_DEVID: devid contains a valid value. The per-VM 2976 KVM_CAP_MSI_DEVID capability advertises the requirement to provide 2977 the device ID. If this capability is not available, userspace 2978 should never set the KVM_MSI_VALID_DEVID flag as the ioctl might fail. 2979 2980If KVM_MSI_VALID_DEVID is set, devid contains a unique device identifier 2981for the device that wrote the MSI message. For PCI, this is usually a 2982BFD identifier in the lower 16 bits. 2983 2984On x86, address_hi is ignored unless the KVM_X2APIC_API_USE_32BIT_IDS 2985feature of KVM_CAP_X2APIC_API capability is enabled. If it is enabled, 2986address_hi bits 31-8 provide bits 31-8 of the destination id. Bits 7-0 of 2987address_hi must be zero. 2988 2989 29904.71 KVM_CREATE_PIT2 2991-------------------- 2992 2993:Capability: KVM_CAP_PIT2 2994:Architectures: x86 2995:Type: vm ioctl 2996:Parameters: struct kvm_pit_config (in) 2997:Returns: 0 on success, -1 on error 2998 2999Creates an in-kernel device model for the i8254 PIT. This call is only valid 3000after enabling in-kernel irqchip support via KVM_CREATE_IRQCHIP. The following 3001parameters have to be passed:: 3002 3003 struct kvm_pit_config { 3004 __u32 flags; 3005 __u32 pad[15]; 3006 }; 3007 3008Valid flags are:: 3009 3010 #define KVM_PIT_SPEAKER_DUMMY 1 /* emulate speaker port stub */ 3011 3012PIT timer interrupts may use a per-VM kernel thread for injection. If it 3013exists, this thread will have a name of the following pattern:: 3014 3015 kvm-pit/<owner-process-pid> 3016 3017When running a guest with elevated priorities, the scheduling parameters of 3018this thread may have to be adjusted accordingly. 3019 3020This IOCTL replaces the obsolete KVM_CREATE_PIT. 3021 3022 30234.72 KVM_GET_PIT2 3024----------------- 3025 3026:Capability: KVM_CAP_PIT_STATE2 3027:Architectures: x86 3028:Type: vm ioctl 3029:Parameters: struct kvm_pit_state2 (out) 3030:Returns: 0 on success, -1 on error 3031 3032Retrieves the state of the in-kernel PIT model. Only valid after 3033KVM_CREATE_PIT2. The state is returned in the following structure:: 3034 3035 struct kvm_pit_state2 { 3036 struct kvm_pit_channel_state channels[3]; 3037 __u32 flags; 3038 __u32 reserved[9]; 3039 }; 3040 3041Valid flags are:: 3042 3043 /* disable PIT in HPET legacy mode */ 3044 #define KVM_PIT_FLAGS_HPET_LEGACY 0x00000001 3045 /* speaker port data bit enabled */ 3046 #define KVM_PIT_FLAGS_SPEAKER_DATA_ON 0x00000002 3047 3048This IOCTL replaces the obsolete KVM_GET_PIT. 3049 3050 30514.73 KVM_SET_PIT2 3052----------------- 3053 3054:Capability: KVM_CAP_PIT_STATE2 3055:Architectures: x86 3056:Type: vm ioctl 3057:Parameters: struct kvm_pit_state2 (in) 3058:Returns: 0 on success, -1 on error 3059 3060Sets the state of the in-kernel PIT model. Only valid after KVM_CREATE_PIT2. 3061See KVM_GET_PIT2 for details on struct kvm_pit_state2. 3062 3063This IOCTL replaces the obsolete KVM_SET_PIT. 3064 3065 30664.74 KVM_PPC_GET_SMMU_INFO 3067-------------------------- 3068 3069:Capability: KVM_CAP_PPC_GET_SMMU_INFO 3070:Architectures: powerpc 3071:Type: vm ioctl 3072:Parameters: None 3073:Returns: 0 on success, -1 on error 3074 3075This populates and returns a structure describing the features of 3076the "Server" class MMU emulation supported by KVM. 3077This can in turn be used by userspace to generate the appropriate 3078device-tree properties for the guest operating system. 3079 3080The structure contains some global information, followed by an 3081array of supported segment page sizes:: 3082 3083 struct kvm_ppc_smmu_info { 3084 __u64 flags; 3085 __u32 slb_size; 3086 __u32 pad; 3087 struct kvm_ppc_one_seg_page_size sps[KVM_PPC_PAGE_SIZES_MAX_SZ]; 3088 }; 3089 3090The supported flags are: 3091 3092 - KVM_PPC_PAGE_SIZES_REAL: 3093 When that flag is set, guest page sizes must "fit" the backing 3094 store page sizes. When not set, any page size in the list can 3095 be used regardless of how they are backed by userspace. 3096 3097 - KVM_PPC_1T_SEGMENTS 3098 The emulated MMU supports 1T segments in addition to the 3099 standard 256M ones. 3100 3101 - KVM_PPC_NO_HASH 3102 This flag indicates that HPT guests are not supported by KVM, 3103 thus all guests must use radix MMU mode. 3104 3105The "slb_size" field indicates how many SLB entries are supported 3106 3107The "sps" array contains 8 entries indicating the supported base 3108page sizes for a segment in increasing order. Each entry is defined 3109as follow:: 3110 3111 struct kvm_ppc_one_seg_page_size { 3112 __u32 page_shift; /* Base page shift of segment (or 0) */ 3113 __u32 slb_enc; /* SLB encoding for BookS */ 3114 struct kvm_ppc_one_page_size enc[KVM_PPC_PAGE_SIZES_MAX_SZ]; 3115 }; 3116 3117An entry with a "page_shift" of 0 is unused. Because the array is 3118organized in increasing order, a lookup can stop when encountering 3119such an entry. 3120 3121The "slb_enc" field provides the encoding to use in the SLB for the 3122page size. The bits are in positions such as the value can directly 3123be OR'ed into the "vsid" argument of the slbmte instruction. 3124 3125The "enc" array is a list which for each of those segment base page 3126size provides the list of supported actual page sizes (which can be 3127only larger or equal to the base page size), along with the 3128corresponding encoding in the hash PTE. Similarly, the array is 31298 entries sorted by increasing sizes and an entry with a "0" shift 3130is an empty entry and a terminator:: 3131 3132 struct kvm_ppc_one_page_size { 3133 __u32 page_shift; /* Page shift (or 0) */ 3134 __u32 pte_enc; /* Encoding in the HPTE (>>12) */ 3135 }; 3136 3137The "pte_enc" field provides a value that can OR'ed into the hash 3138PTE's RPN field (ie, it needs to be shifted left by 12 to OR it 3139into the hash PTE second double word). 3140 31414.75 KVM_IRQFD 3142-------------- 3143 3144:Capability: KVM_CAP_IRQFD 3145:Architectures: x86 s390 arm64 3146:Type: vm ioctl 3147:Parameters: struct kvm_irqfd (in) 3148:Returns: 0 on success, -1 on error 3149 3150Allows setting an eventfd to directly trigger a guest interrupt. 3151kvm_irqfd.fd specifies the file descriptor to use as the eventfd and 3152kvm_irqfd.gsi specifies the irqchip pin toggled by this event. When 3153an event is triggered on the eventfd, an interrupt is injected into 3154the guest using the specified gsi pin. The irqfd is removed using 3155the KVM_IRQFD_FLAG_DEASSIGN flag, specifying both kvm_irqfd.fd 3156and kvm_irqfd.gsi. 3157 3158With KVM_CAP_IRQFD_RESAMPLE, KVM_IRQFD supports a de-assert and notify 3159mechanism allowing emulation of level-triggered, irqfd-based 3160interrupts. When KVM_IRQFD_FLAG_RESAMPLE is set the user must pass an 3161additional eventfd in the kvm_irqfd.resamplefd field. When operating 3162in resample mode, posting of an interrupt through kvm_irq.fd asserts 3163the specified gsi in the irqchip. When the irqchip is resampled, such 3164as from an EOI, the gsi is de-asserted and the user is notified via 3165kvm_irqfd.resamplefd. It is the user's responsibility to re-queue 3166the interrupt if the device making use of it still requires service. 3167Note that closing the resamplefd is not sufficient to disable the 3168irqfd. The KVM_IRQFD_FLAG_RESAMPLE is only necessary on assignment 3169and need not be specified with KVM_IRQFD_FLAG_DEASSIGN. 3170 3171On arm64, gsi routing being supported, the following can happen: 3172 3173- in case no routing entry is associated to this gsi, injection fails 3174- in case the gsi is associated to an irqchip routing entry, 3175 irqchip.pin + 32 corresponds to the injected SPI ID. 3176- in case the gsi is associated to an MSI routing entry, the MSI 3177 message and device ID are translated into an LPI (support restricted 3178 to GICv3 ITS in-kernel emulation). 3179 31804.76 KVM_PPC_ALLOCATE_HTAB 3181-------------------------- 3182 3183:Capability: KVM_CAP_PPC_ALLOC_HTAB 3184:Architectures: powerpc 3185:Type: vm ioctl 3186:Parameters: Pointer to u32 containing hash table order (in/out) 3187:Returns: 0 on success, -1 on error 3188 3189This requests the host kernel to allocate an MMU hash table for a 3190guest using the PAPR paravirtualization interface. This only does 3191anything if the kernel is configured to use the Book 3S HV style of 3192virtualization. Otherwise the capability doesn't exist and the ioctl 3193returns an ENOTTY error. The rest of this description assumes Book 3S 3194HV. 3195 3196There must be no vcpus running when this ioctl is called; if there 3197are, it will do nothing and return an EBUSY error. 3198 3199The parameter is a pointer to a 32-bit unsigned integer variable 3200containing the order (log base 2) of the desired size of the hash 3201table, which must be between 18 and 46. On successful return from the 3202ioctl, the value will not be changed by the kernel. 3203 3204If no hash table has been allocated when any vcpu is asked to run 3205(with the KVM_RUN ioctl), the host kernel will allocate a 3206default-sized hash table (16 MB). 3207 3208If this ioctl is called when a hash table has already been allocated, 3209with a different order from the existing hash table, the existing hash 3210table will be freed and a new one allocated. If this is ioctl is 3211called when a hash table has already been allocated of the same order 3212as specified, the kernel will clear out the existing hash table (zero 3213all HPTEs). In either case, if the guest is using the virtualized 3214real-mode area (VRMA) facility, the kernel will re-create the VMRA 3215HPTEs on the next KVM_RUN of any vcpu. 3216 32174.77 KVM_S390_INTERRUPT 3218----------------------- 3219 3220:Capability: basic 3221:Architectures: s390 3222:Type: vm ioctl, vcpu ioctl 3223:Parameters: struct kvm_s390_interrupt (in) 3224:Returns: 0 on success, -1 on error 3225 3226Allows to inject an interrupt to the guest. Interrupts can be floating 3227(vm ioctl) or per cpu (vcpu ioctl), depending on the interrupt type. 3228 3229Interrupt parameters are passed via kvm_s390_interrupt:: 3230 3231 struct kvm_s390_interrupt { 3232 __u32 type; 3233 __u32 parm; 3234 __u64 parm64; 3235 }; 3236 3237type can be one of the following: 3238 3239KVM_S390_SIGP_STOP (vcpu) 3240 - sigp stop; optional flags in parm 3241KVM_S390_PROGRAM_INT (vcpu) 3242 - program check; code in parm 3243KVM_S390_SIGP_SET_PREFIX (vcpu) 3244 - sigp set prefix; prefix address in parm 3245KVM_S390_RESTART (vcpu) 3246 - restart 3247KVM_S390_INT_CLOCK_COMP (vcpu) 3248 - clock comparator interrupt 3249KVM_S390_INT_CPU_TIMER (vcpu) 3250 - CPU timer interrupt 3251KVM_S390_INT_VIRTIO (vm) 3252 - virtio external interrupt; external interrupt 3253 parameters in parm and parm64 3254KVM_S390_INT_SERVICE (vm) 3255 - sclp external interrupt; sclp parameter in parm 3256KVM_S390_INT_EMERGENCY (vcpu) 3257 - sigp emergency; source cpu in parm 3258KVM_S390_INT_EXTERNAL_CALL (vcpu) 3259 - sigp external call; source cpu in parm 3260KVM_S390_INT_IO(ai,cssid,ssid,schid) (vm) 3261 - compound value to indicate an 3262 I/O interrupt (ai - adapter interrupt; cssid,ssid,schid - subchannel); 3263 I/O interruption parameters in parm (subchannel) and parm64 (intparm, 3264 interruption subclass) 3265KVM_S390_MCHK (vm, vcpu) 3266 - machine check interrupt; cr 14 bits in parm, machine check interrupt 3267 code in parm64 (note that machine checks needing further payload are not 3268 supported by this ioctl) 3269 3270This is an asynchronous vcpu ioctl and can be invoked from any thread. 3271 32724.78 KVM_PPC_GET_HTAB_FD 3273------------------------ 3274 3275:Capability: KVM_CAP_PPC_HTAB_FD 3276:Architectures: powerpc 3277:Type: vm ioctl 3278:Parameters: Pointer to struct kvm_get_htab_fd (in) 3279:Returns: file descriptor number (>= 0) on success, -1 on error 3280 3281This returns a file descriptor that can be used either to read out the 3282entries in the guest's hashed page table (HPT), or to write entries to 3283initialize the HPT. The returned fd can only be written to if the 3284KVM_GET_HTAB_WRITE bit is set in the flags field of the argument, and 3285can only be read if that bit is clear. The argument struct looks like 3286this:: 3287 3288 /* For KVM_PPC_GET_HTAB_FD */ 3289 struct kvm_get_htab_fd { 3290 __u64 flags; 3291 __u64 start_index; 3292 __u64 reserved[2]; 3293 }; 3294 3295 /* Values for kvm_get_htab_fd.flags */ 3296 #define KVM_GET_HTAB_BOLTED_ONLY ((__u64)0x1) 3297 #define KVM_GET_HTAB_WRITE ((__u64)0x2) 3298 3299The 'start_index' field gives the index in the HPT of the entry at 3300which to start reading. It is ignored when writing. 3301 3302Reads on the fd will initially supply information about all 3303"interesting" HPT entries. Interesting entries are those with the 3304bolted bit set, if the KVM_GET_HTAB_BOLTED_ONLY bit is set, otherwise 3305all entries. When the end of the HPT is reached, the read() will 3306return. If read() is called again on the fd, it will start again from 3307the beginning of the HPT, but will only return HPT entries that have 3308changed since they were last read. 3309 3310Data read or written is structured as a header (8 bytes) followed by a 3311series of valid HPT entries (16 bytes) each. The header indicates how 3312many valid HPT entries there are and how many invalid entries follow 3313the valid entries. The invalid entries are not represented explicitly 3314in the stream. The header format is:: 3315 3316 struct kvm_get_htab_header { 3317 __u32 index; 3318 __u16 n_valid; 3319 __u16 n_invalid; 3320 }; 3321 3322Writes to the fd create HPT entries starting at the index given in the 3323header; first 'n_valid' valid entries with contents from the data 3324written, then 'n_invalid' invalid entries, invalidating any previously 3325valid entries found. 3326 33274.79 KVM_CREATE_DEVICE 3328---------------------- 3329 3330:Capability: KVM_CAP_DEVICE_CTRL 3331:Architectures: all 3332:Type: vm ioctl 3333:Parameters: struct kvm_create_device (in/out) 3334:Returns: 0 on success, -1 on error 3335 3336Errors: 3337 3338 ====== ======================================================= 3339 ENODEV The device type is unknown or unsupported 3340 EEXIST Device already created, and this type of device may not 3341 be instantiated multiple times 3342 ====== ======================================================= 3343 3344 Other error conditions may be defined by individual device types or 3345 have their standard meanings. 3346 3347Creates an emulated device in the kernel. The file descriptor returned 3348in fd can be used with KVM_SET/GET/HAS_DEVICE_ATTR. 3349 3350If the KVM_CREATE_DEVICE_TEST flag is set, only test whether the 3351device type is supported (not necessarily whether it can be created 3352in the current vm). 3353 3354Individual devices should not define flags. Attributes should be used 3355for specifying any behavior that is not implied by the device type 3356number. 3357 3358:: 3359 3360 struct kvm_create_device { 3361 __u32 type; /* in: KVM_DEV_TYPE_xxx */ 3362 __u32 fd; /* out: device handle */ 3363 __u32 flags; /* in: KVM_CREATE_DEVICE_xxx */ 3364 }; 3365 33664.80 KVM_SET_DEVICE_ATTR/KVM_GET_DEVICE_ATTR 3367-------------------------------------------- 3368 3369:Capability: KVM_CAP_DEVICE_CTRL, KVM_CAP_VM_ATTRIBUTES for vm device, 3370 KVM_CAP_VCPU_ATTRIBUTES for vcpu device 3371 KVM_CAP_SYS_ATTRIBUTES for system (/dev/kvm) device (no set) 3372:Architectures: x86, arm64, s390 3373:Type: device ioctl, vm ioctl, vcpu ioctl 3374:Parameters: struct kvm_device_attr 3375:Returns: 0 on success, -1 on error 3376 3377Errors: 3378 3379 ===== ============================================================= 3380 ENXIO The group or attribute is unknown/unsupported for this device 3381 or hardware support is missing. 3382 EPERM The attribute cannot (currently) be accessed this way 3383 (e.g. read-only attribute, or attribute that only makes 3384 sense when the device is in a different state) 3385 ===== ============================================================= 3386 3387 Other error conditions may be defined by individual device types. 3388 3389Gets/sets a specified piece of device configuration and/or state. The 3390semantics are device-specific. See individual device documentation in 3391the "devices" directory. As with ONE_REG, the size of the data 3392transferred is defined by the particular attribute. 3393 3394:: 3395 3396 struct kvm_device_attr { 3397 __u32 flags; /* no flags currently defined */ 3398 __u32 group; /* device-defined */ 3399 __u64 attr; /* group-defined */ 3400 __u64 addr; /* userspace address of attr data */ 3401 }; 3402 34034.81 KVM_HAS_DEVICE_ATTR 3404------------------------ 3405 3406:Capability: KVM_CAP_DEVICE_CTRL, KVM_CAP_VM_ATTRIBUTES for vm device, 3407 KVM_CAP_VCPU_ATTRIBUTES for vcpu device 3408 KVM_CAP_SYS_ATTRIBUTES for system (/dev/kvm) device 3409:Type: device ioctl, vm ioctl, vcpu ioctl 3410:Parameters: struct kvm_device_attr 3411:Returns: 0 on success, -1 on error 3412 3413Errors: 3414 3415 ===== ============================================================= 3416 ENXIO The group or attribute is unknown/unsupported for this device 3417 or hardware support is missing. 3418 ===== ============================================================= 3419 3420Tests whether a device supports a particular attribute. A successful 3421return indicates the attribute is implemented. It does not necessarily 3422indicate that the attribute can be read or written in the device's 3423current state. "addr" is ignored. 3424 3425.. _KVM_ARM_VCPU_INIT: 3426 34274.82 KVM_ARM_VCPU_INIT 3428---------------------- 3429 3430:Capability: basic 3431:Architectures: arm64 3432:Type: vcpu ioctl 3433:Parameters: struct kvm_vcpu_init (in) 3434:Returns: 0 on success; -1 on error 3435 3436Errors: 3437 3438 ====== ================================================================= 3439 EINVAL the target is unknown, or the combination of features is invalid. 3440 ENOENT a features bit specified is unknown. 3441 ====== ================================================================= 3442 3443This tells KVM what type of CPU to present to the guest, and what 3444optional features it should have. This will cause a reset of the cpu 3445registers to their initial values. If this is not called, KVM_RUN will 3446return ENOEXEC for that vcpu. 3447 3448The initial values are defined as: 3449 - Processor state: 3450 * AArch64: EL1h, D, A, I and F bits set. All other bits 3451 are cleared. 3452 * AArch32: SVC, A, I and F bits set. All other bits are 3453 cleared. 3454 - General Purpose registers, including PC and SP: set to 0 3455 - FPSIMD/NEON registers: set to 0 3456 - SVE registers: set to 0 3457 - System registers: Reset to their architecturally defined 3458 values as for a warm reset to EL1 (resp. SVC) 3459 3460Note that because some registers reflect machine topology, all vcpus 3461should be created before this ioctl is invoked. 3462 3463Userspace can call this function multiple times for a given vcpu, including 3464after the vcpu has been run. This will reset the vcpu to its initial 3465state. All calls to this function after the initial call must use the same 3466target and same set of feature flags, otherwise EINVAL will be returned. 3467 3468Possible features: 3469 3470 - KVM_ARM_VCPU_POWER_OFF: Starts the CPU in a power-off state. 3471 Depends on KVM_CAP_ARM_PSCI. If not set, the CPU will be powered on 3472 and execute guest code when KVM_RUN is called. 3473 - KVM_ARM_VCPU_EL1_32BIT: Starts the CPU in a 32bit mode. 3474 Depends on KVM_CAP_ARM_EL1_32BIT (arm64 only). 3475 - KVM_ARM_VCPU_PSCI_0_2: Emulate PSCI v0.2 (or a future revision 3476 backward compatible with v0.2) for the CPU. 3477 Depends on KVM_CAP_ARM_PSCI_0_2. 3478 - KVM_ARM_VCPU_PMU_V3: Emulate PMUv3 for the CPU. 3479 Depends on KVM_CAP_ARM_PMU_V3. 3480 3481 - KVM_ARM_VCPU_PTRAUTH_ADDRESS: Enables Address Pointer authentication 3482 for arm64 only. 3483 Depends on KVM_CAP_ARM_PTRAUTH_ADDRESS. 3484 If KVM_CAP_ARM_PTRAUTH_ADDRESS and KVM_CAP_ARM_PTRAUTH_GENERIC are 3485 both present, then both KVM_ARM_VCPU_PTRAUTH_ADDRESS and 3486 KVM_ARM_VCPU_PTRAUTH_GENERIC must be requested or neither must be 3487 requested. 3488 3489 - KVM_ARM_VCPU_PTRAUTH_GENERIC: Enables Generic Pointer authentication 3490 for arm64 only. 3491 Depends on KVM_CAP_ARM_PTRAUTH_GENERIC. 3492 If KVM_CAP_ARM_PTRAUTH_ADDRESS and KVM_CAP_ARM_PTRAUTH_GENERIC are 3493 both present, then both KVM_ARM_VCPU_PTRAUTH_ADDRESS and 3494 KVM_ARM_VCPU_PTRAUTH_GENERIC must be requested or neither must be 3495 requested. 3496 3497 - KVM_ARM_VCPU_SVE: Enables SVE for the CPU (arm64 only). 3498 Depends on KVM_CAP_ARM_SVE. 3499 Requires KVM_ARM_VCPU_FINALIZE(KVM_ARM_VCPU_SVE): 3500 3501 * After KVM_ARM_VCPU_INIT: 3502 3503 - KVM_REG_ARM64_SVE_VLS may be read using KVM_GET_ONE_REG: the 3504 initial value of this pseudo-register indicates the best set of 3505 vector lengths possible for a vcpu on this host. 3506 3507 * Before KVM_ARM_VCPU_FINALIZE(KVM_ARM_VCPU_SVE): 3508 3509 - KVM_RUN and KVM_GET_REG_LIST are not available; 3510 3511 - KVM_GET_ONE_REG and KVM_SET_ONE_REG cannot be used to access 3512 the scalable architectural SVE registers 3513 KVM_REG_ARM64_SVE_ZREG(), KVM_REG_ARM64_SVE_PREG() or 3514 KVM_REG_ARM64_SVE_FFR; 3515 3516 - KVM_REG_ARM64_SVE_VLS may optionally be written using 3517 KVM_SET_ONE_REG, to modify the set of vector lengths available 3518 for the vcpu. 3519 3520 * After KVM_ARM_VCPU_FINALIZE(KVM_ARM_VCPU_SVE): 3521 3522 - the KVM_REG_ARM64_SVE_VLS pseudo-register is immutable, and can 3523 no longer be written using KVM_SET_ONE_REG. 3524 35254.83 KVM_ARM_PREFERRED_TARGET 3526----------------------------- 3527 3528:Capability: basic 3529:Architectures: arm64 3530:Type: vm ioctl 3531:Parameters: struct kvm_vcpu_init (out) 3532:Returns: 0 on success; -1 on error 3533 3534Errors: 3535 3536 ====== ========================================== 3537 ENODEV no preferred target available for the host 3538 ====== ========================================== 3539 3540This queries KVM for preferred CPU target type which can be emulated 3541by KVM on underlying host. 3542 3543The ioctl returns struct kvm_vcpu_init instance containing information 3544about preferred CPU target type and recommended features for it. The 3545kvm_vcpu_init->features bitmap returned will have feature bits set if 3546the preferred target recommends setting these features, but this is 3547not mandatory. 3548 3549The information returned by this ioctl can be used to prepare an instance 3550of struct kvm_vcpu_init for KVM_ARM_VCPU_INIT ioctl which will result in 3551VCPU matching underlying host. 3552 3553 35544.84 KVM_GET_REG_LIST 3555--------------------- 3556 3557:Capability: basic 3558:Architectures: arm64, mips, riscv 3559:Type: vcpu ioctl 3560:Parameters: struct kvm_reg_list (in/out) 3561:Returns: 0 on success; -1 on error 3562 3563Errors: 3564 3565 ===== ============================================================== 3566 E2BIG the reg index list is too big to fit in the array specified by 3567 the user (the number required will be written into n). 3568 ===== ============================================================== 3569 3570:: 3571 3572 struct kvm_reg_list { 3573 __u64 n; /* number of registers in reg[] */ 3574 __u64 reg[0]; 3575 }; 3576 3577This ioctl returns the guest registers that are supported for the 3578KVM_GET_ONE_REG/KVM_SET_ONE_REG calls. 3579 3580 35814.85 KVM_ARM_SET_DEVICE_ADDR (deprecated) 3582----------------------------------------- 3583 3584:Capability: KVM_CAP_ARM_SET_DEVICE_ADDR 3585:Architectures: arm64 3586:Type: vm ioctl 3587:Parameters: struct kvm_arm_device_address (in) 3588:Returns: 0 on success, -1 on error 3589 3590Errors: 3591 3592 ====== ============================================ 3593 ENODEV The device id is unknown 3594 ENXIO Device not supported on current system 3595 EEXIST Address already set 3596 E2BIG Address outside guest physical address space 3597 EBUSY Address overlaps with other device range 3598 ====== ============================================ 3599 3600:: 3601 3602 struct kvm_arm_device_addr { 3603 __u64 id; 3604 __u64 addr; 3605 }; 3606 3607Specify a device address in the guest's physical address space where guests 3608can access emulated or directly exposed devices, which the host kernel needs 3609to know about. The id field is an architecture specific identifier for a 3610specific device. 3611 3612arm64 divides the id field into two parts, a device id and an 3613address type id specific to the individual device:: 3614 3615 bits: | 63 ... 32 | 31 ... 16 | 15 ... 0 | 3616 field: | 0x00000000 | device id | addr type id | 3617 3618arm64 currently only require this when using the in-kernel GIC 3619support for the hardware VGIC features, using KVM_ARM_DEVICE_VGIC_V2 3620as the device id. When setting the base address for the guest's 3621mapping of the VGIC virtual CPU and distributor interface, the ioctl 3622must be called after calling KVM_CREATE_IRQCHIP, but before calling 3623KVM_RUN on any of the VCPUs. Calling this ioctl twice for any of the 3624base addresses will return -EEXIST. 3625 3626Note, this IOCTL is deprecated and the more flexible SET/GET_DEVICE_ATTR API 3627should be used instead. 3628 3629 36304.86 KVM_PPC_RTAS_DEFINE_TOKEN 3631------------------------------ 3632 3633:Capability: KVM_CAP_PPC_RTAS 3634:Architectures: ppc 3635:Type: vm ioctl 3636:Parameters: struct kvm_rtas_token_args 3637:Returns: 0 on success, -1 on error 3638 3639Defines a token value for a RTAS (Run Time Abstraction Services) 3640service in order to allow it to be handled in the kernel. The 3641argument struct gives the name of the service, which must be the name 3642of a service that has a kernel-side implementation. If the token 3643value is non-zero, it will be associated with that service, and 3644subsequent RTAS calls by the guest specifying that token will be 3645handled by the kernel. If the token value is 0, then any token 3646associated with the service will be forgotten, and subsequent RTAS 3647calls by the guest for that service will be passed to userspace to be 3648handled. 3649 36504.87 KVM_SET_GUEST_DEBUG 3651------------------------ 3652 3653:Capability: KVM_CAP_SET_GUEST_DEBUG 3654:Architectures: x86, s390, ppc, arm64 3655:Type: vcpu ioctl 3656:Parameters: struct kvm_guest_debug (in) 3657:Returns: 0 on success; -1 on error 3658 3659:: 3660 3661 struct kvm_guest_debug { 3662 __u32 control; 3663 __u32 pad; 3664 struct kvm_guest_debug_arch arch; 3665 }; 3666 3667Set up the processor specific debug registers and configure vcpu for 3668handling guest debug events. There are two parts to the structure, the 3669first a control bitfield indicates the type of debug events to handle 3670when running. Common control bits are: 3671 3672 - KVM_GUESTDBG_ENABLE: guest debugging is enabled 3673 - KVM_GUESTDBG_SINGLESTEP: the next run should single-step 3674 3675The top 16 bits of the control field are architecture specific control 3676flags which can include the following: 3677 3678 - KVM_GUESTDBG_USE_SW_BP: using software breakpoints [x86, arm64] 3679 - KVM_GUESTDBG_USE_HW_BP: using hardware breakpoints [x86, s390] 3680 - KVM_GUESTDBG_USE_HW: using hardware debug events [arm64] 3681 - KVM_GUESTDBG_INJECT_DB: inject DB type exception [x86] 3682 - KVM_GUESTDBG_INJECT_BP: inject BP type exception [x86] 3683 - KVM_GUESTDBG_EXIT_PENDING: trigger an immediate guest exit [s390] 3684 - KVM_GUESTDBG_BLOCKIRQ: avoid injecting interrupts/NMI/SMI [x86] 3685 3686For example KVM_GUESTDBG_USE_SW_BP indicates that software breakpoints 3687are enabled in memory so we need to ensure breakpoint exceptions are 3688correctly trapped and the KVM run loop exits at the breakpoint and not 3689running off into the normal guest vector. For KVM_GUESTDBG_USE_HW_BP 3690we need to ensure the guest vCPUs architecture specific registers are 3691updated to the correct (supplied) values. 3692 3693The second part of the structure is architecture specific and 3694typically contains a set of debug registers. 3695 3696For arm64 the number of debug registers is implementation defined and 3697can be determined by querying the KVM_CAP_GUEST_DEBUG_HW_BPS and 3698KVM_CAP_GUEST_DEBUG_HW_WPS capabilities which return a positive number 3699indicating the number of supported registers. 3700 3701For ppc, the KVM_CAP_PPC_GUEST_DEBUG_SSTEP capability indicates whether 3702the single-step debug event (KVM_GUESTDBG_SINGLESTEP) is supported. 3703 3704Also when supported, KVM_CAP_SET_GUEST_DEBUG2 capability indicates the 3705supported KVM_GUESTDBG_* bits in the control field. 3706 3707When debug events exit the main run loop with the reason 3708KVM_EXIT_DEBUG with the kvm_debug_exit_arch part of the kvm_run 3709structure containing architecture specific debug information. 3710 37114.88 KVM_GET_EMULATED_CPUID 3712--------------------------- 3713 3714:Capability: KVM_CAP_EXT_EMUL_CPUID 3715:Architectures: x86 3716:Type: system ioctl 3717:Parameters: struct kvm_cpuid2 (in/out) 3718:Returns: 0 on success, -1 on error 3719 3720:: 3721 3722 struct kvm_cpuid2 { 3723 __u32 nent; 3724 __u32 flags; 3725 struct kvm_cpuid_entry2 entries[0]; 3726 }; 3727 3728The member 'flags' is used for passing flags from userspace. 3729 3730:: 3731 3732 #define KVM_CPUID_FLAG_SIGNIFCANT_INDEX BIT(0) 3733 #define KVM_CPUID_FLAG_STATEFUL_FUNC BIT(1) /* deprecated */ 3734 #define KVM_CPUID_FLAG_STATE_READ_NEXT BIT(2) /* deprecated */ 3735 3736 struct kvm_cpuid_entry2 { 3737 __u32 function; 3738 __u32 index; 3739 __u32 flags; 3740 __u32 eax; 3741 __u32 ebx; 3742 __u32 ecx; 3743 __u32 edx; 3744 __u32 padding[3]; 3745 }; 3746 3747This ioctl returns x86 cpuid features which are emulated by 3748kvm.Userspace can use the information returned by this ioctl to query 3749which features are emulated by kvm instead of being present natively. 3750 3751Userspace invokes KVM_GET_EMULATED_CPUID by passing a kvm_cpuid2 3752structure with the 'nent' field indicating the number of entries in 3753the variable-size array 'entries'. If the number of entries is too low 3754to describe the cpu capabilities, an error (E2BIG) is returned. If the 3755number is too high, the 'nent' field is adjusted and an error (ENOMEM) 3756is returned. If the number is just right, the 'nent' field is adjusted 3757to the number of valid entries in the 'entries' array, which is then 3758filled. 3759 3760The entries returned are the set CPUID bits of the respective features 3761which kvm emulates, as returned by the CPUID instruction, with unknown 3762or unsupported feature bits cleared. 3763 3764Features like x2apic, for example, may not be present in the host cpu 3765but are exposed by kvm in KVM_GET_SUPPORTED_CPUID because they can be 3766emulated efficiently and thus not included here. 3767 3768The fields in each entry are defined as follows: 3769 3770 function: 3771 the eax value used to obtain the entry 3772 index: 3773 the ecx value used to obtain the entry (for entries that are 3774 affected by ecx) 3775 flags: 3776 an OR of zero or more of the following: 3777 3778 KVM_CPUID_FLAG_SIGNIFCANT_INDEX: 3779 if the index field is valid 3780 3781 eax, ebx, ecx, edx: 3782 3783 the values returned by the cpuid instruction for 3784 this function/index combination 3785 37864.89 KVM_S390_MEM_OP 3787-------------------- 3788 3789:Capability: KVM_CAP_S390_MEM_OP, KVM_CAP_S390_PROTECTED, KVM_CAP_S390_MEM_OP_EXTENSION 3790:Architectures: s390 3791:Type: vm ioctl, vcpu ioctl 3792:Parameters: struct kvm_s390_mem_op (in) 3793:Returns: = 0 on success, 3794 < 0 on generic error (e.g. -EFAULT or -ENOMEM), 3795 16 bit program exception code if the access causes such an exception 3796 3797Read or write data from/to the VM's memory. 3798The KVM_CAP_S390_MEM_OP_EXTENSION capability specifies what functionality is 3799supported. 3800 3801Parameters are specified via the following structure:: 3802 3803 struct kvm_s390_mem_op { 3804 __u64 gaddr; /* the guest address */ 3805 __u64 flags; /* flags */ 3806 __u32 size; /* amount of bytes */ 3807 __u32 op; /* type of operation */ 3808 __u64 buf; /* buffer in userspace */ 3809 union { 3810 struct { 3811 __u8 ar; /* the access register number */ 3812 __u8 key; /* access key, ignored if flag unset */ 3813 __u8 pad1[6]; /* ignored */ 3814 __u64 old_addr; /* ignored if flag unset */ 3815 }; 3816 __u32 sida_offset; /* offset into the sida */ 3817 __u8 reserved[32]; /* ignored */ 3818 }; 3819 }; 3820 3821The start address of the memory region has to be specified in the "gaddr" 3822field, and the length of the region in the "size" field (which must not 3823be 0). The maximum value for "size" can be obtained by checking the 3824KVM_CAP_S390_MEM_OP capability. "buf" is the buffer supplied by the 3825userspace application where the read data should be written to for 3826a read access, or where the data that should be written is stored for 3827a write access. The "reserved" field is meant for future extensions. 3828Reserved and unused values are ignored. Future extension that add members must 3829introduce new flags. 3830 3831The type of operation is specified in the "op" field. Flags modifying 3832their behavior can be set in the "flags" field. Undefined flag bits must 3833be set to 0. 3834 3835Possible operations are: 3836 * ``KVM_S390_MEMOP_LOGICAL_READ`` 3837 * ``KVM_S390_MEMOP_LOGICAL_WRITE`` 3838 * ``KVM_S390_MEMOP_ABSOLUTE_READ`` 3839 * ``KVM_S390_MEMOP_ABSOLUTE_WRITE`` 3840 * ``KVM_S390_MEMOP_SIDA_READ`` 3841 * ``KVM_S390_MEMOP_SIDA_WRITE`` 3842 * ``KVM_S390_MEMOP_ABSOLUTE_CMPXCHG`` 3843 3844Logical read/write: 3845^^^^^^^^^^^^^^^^^^^ 3846 3847Access logical memory, i.e. translate the given guest address to an absolute 3848address given the state of the VCPU and use the absolute address as target of 3849the access. "ar" designates the access register number to be used; the valid 3850range is 0..15. 3851Logical accesses are permitted for the VCPU ioctl only. 3852Logical accesses are permitted for non-protected guests only. 3853 3854Supported flags: 3855 * ``KVM_S390_MEMOP_F_CHECK_ONLY`` 3856 * ``KVM_S390_MEMOP_F_INJECT_EXCEPTION`` 3857 * ``KVM_S390_MEMOP_F_SKEY_PROTECTION`` 3858 3859The KVM_S390_MEMOP_F_CHECK_ONLY flag can be set to check whether the 3860corresponding memory access would cause an access exception; however, 3861no actual access to the data in memory at the destination is performed. 3862In this case, "buf" is unused and can be NULL. 3863 3864In case an access exception occurred during the access (or would occur 3865in case of KVM_S390_MEMOP_F_CHECK_ONLY), the ioctl returns a positive 3866error number indicating the type of exception. This exception is also 3867raised directly at the corresponding VCPU if the flag 3868KVM_S390_MEMOP_F_INJECT_EXCEPTION is set. 3869On protection exceptions, unless specified otherwise, the injected 3870translation-exception identifier (TEID) indicates suppression. 3871 3872If the KVM_S390_MEMOP_F_SKEY_PROTECTION flag is set, storage key 3873protection is also in effect and may cause exceptions if accesses are 3874prohibited given the access key designated by "key"; the valid range is 0..15. 3875KVM_S390_MEMOP_F_SKEY_PROTECTION is available if KVM_CAP_S390_MEM_OP_EXTENSION 3876is > 0. 3877Since the accessed memory may span multiple pages and those pages might have 3878different storage keys, it is possible that a protection exception occurs 3879after memory has been modified. In this case, if the exception is injected, 3880the TEID does not indicate suppression. 3881 3882Absolute read/write: 3883^^^^^^^^^^^^^^^^^^^^ 3884 3885Access absolute memory. This operation is intended to be used with the 3886KVM_S390_MEMOP_F_SKEY_PROTECTION flag, to allow accessing memory and performing 3887the checks required for storage key protection as one operation (as opposed to 3888user space getting the storage keys, performing the checks, and accessing 3889memory thereafter, which could lead to a delay between check and access). 3890Absolute accesses are permitted for the VM ioctl if KVM_CAP_S390_MEM_OP_EXTENSION 3891has the KVM_S390_MEMOP_EXTENSION_CAP_BASE bit set. 3892Currently absolute accesses are not permitted for VCPU ioctls. 3893Absolute accesses are permitted for non-protected guests only. 3894 3895Supported flags: 3896 * ``KVM_S390_MEMOP_F_CHECK_ONLY`` 3897 * ``KVM_S390_MEMOP_F_SKEY_PROTECTION`` 3898 3899The semantics of the flags common with logical accesses are as for logical 3900accesses. 3901 3902Absolute cmpxchg: 3903^^^^^^^^^^^^^^^^^ 3904 3905Perform cmpxchg on absolute guest memory. Intended for use with the 3906KVM_S390_MEMOP_F_SKEY_PROTECTION flag. 3907Instead of doing an unconditional write, the access occurs only if the target 3908location contains the value pointed to by "old_addr". 3909This is performed as an atomic cmpxchg with the length specified by the "size" 3910parameter. "size" must be a power of two up to and including 16. 3911If the exchange did not take place because the target value doesn't match the 3912old value, the value "old_addr" points to is replaced by the target value. 3913User space can tell if an exchange took place by checking if this replacement 3914occurred. The cmpxchg op is permitted for the VM ioctl if 3915KVM_CAP_S390_MEM_OP_EXTENSION has flag KVM_S390_MEMOP_EXTENSION_CAP_CMPXCHG set. 3916 3917Supported flags: 3918 * ``KVM_S390_MEMOP_F_SKEY_PROTECTION`` 3919 3920SIDA read/write: 3921^^^^^^^^^^^^^^^^ 3922 3923Access the secure instruction data area which contains memory operands necessary 3924for instruction emulation for protected guests. 3925SIDA accesses are available if the KVM_CAP_S390_PROTECTED capability is available. 3926SIDA accesses are permitted for the VCPU ioctl only. 3927SIDA accesses are permitted for protected guests only. 3928 3929No flags are supported. 3930 39314.90 KVM_S390_GET_SKEYS 3932----------------------- 3933 3934:Capability: KVM_CAP_S390_SKEYS 3935:Architectures: s390 3936:Type: vm ioctl 3937:Parameters: struct kvm_s390_skeys 3938:Returns: 0 on success, KVM_S390_GET_SKEYS_NONE if guest is not using storage 3939 keys, negative value on error 3940 3941This ioctl is used to get guest storage key values on the s390 3942architecture. The ioctl takes parameters via the kvm_s390_skeys struct:: 3943 3944 struct kvm_s390_skeys { 3945 __u64 start_gfn; 3946 __u64 count; 3947 __u64 skeydata_addr; 3948 __u32 flags; 3949 __u32 reserved[9]; 3950 }; 3951 3952The start_gfn field is the number of the first guest frame whose storage keys 3953you want to get. 3954 3955The count field is the number of consecutive frames (starting from start_gfn) 3956whose storage keys to get. The count field must be at least 1 and the maximum 3957allowed value is defined as KVM_S390_SKEYS_MAX. Values outside this range 3958will cause the ioctl to return -EINVAL. 3959 3960The skeydata_addr field is the address to a buffer large enough to hold count 3961bytes. This buffer will be filled with storage key data by the ioctl. 3962 39634.91 KVM_S390_SET_SKEYS 3964----------------------- 3965 3966:Capability: KVM_CAP_S390_SKEYS 3967:Architectures: s390 3968:Type: vm ioctl 3969:Parameters: struct kvm_s390_skeys 3970:Returns: 0 on success, negative value on error 3971 3972This ioctl is used to set guest storage key values on the s390 3973architecture. The ioctl takes parameters via the kvm_s390_skeys struct. 3974See section on KVM_S390_GET_SKEYS for struct definition. 3975 3976The start_gfn field is the number of the first guest frame whose storage keys 3977you want to set. 3978 3979The count field is the number of consecutive frames (starting from start_gfn) 3980whose storage keys to get. The count field must be at least 1 and the maximum 3981allowed value is defined as KVM_S390_SKEYS_MAX. Values outside this range 3982will cause the ioctl to return -EINVAL. 3983 3984The skeydata_addr field is the address to a buffer containing count bytes of 3985storage keys. Each byte in the buffer will be set as the storage key for a 3986single frame starting at start_gfn for count frames. 3987 3988Note: If any architecturally invalid key value is found in the given data then 3989the ioctl will return -EINVAL. 3990 39914.92 KVM_S390_IRQ 3992----------------- 3993 3994:Capability: KVM_CAP_S390_INJECT_IRQ 3995:Architectures: s390 3996:Type: vcpu ioctl 3997:Parameters: struct kvm_s390_irq (in) 3998:Returns: 0 on success, -1 on error 3999 4000Errors: 4001 4002 4003 ====== ================================================================= 4004 EINVAL interrupt type is invalid 4005 type is KVM_S390_SIGP_STOP and flag parameter is invalid value, 4006 type is KVM_S390_INT_EXTERNAL_CALL and code is bigger 4007 than the maximum of VCPUs 4008 EBUSY type is KVM_S390_SIGP_SET_PREFIX and vcpu is not stopped, 4009 type is KVM_S390_SIGP_STOP and a stop irq is already pending, 4010 type is KVM_S390_INT_EXTERNAL_CALL and an external call interrupt 4011 is already pending 4012 ====== ================================================================= 4013 4014Allows to inject an interrupt to the guest. 4015 4016Using struct kvm_s390_irq as a parameter allows 4017to inject additional payload which is not 4018possible via KVM_S390_INTERRUPT. 4019 4020Interrupt parameters are passed via kvm_s390_irq:: 4021 4022 struct kvm_s390_irq { 4023 __u64 type; 4024 union { 4025 struct kvm_s390_io_info io; 4026 struct kvm_s390_ext_info ext; 4027 struct kvm_s390_pgm_info pgm; 4028 struct kvm_s390_emerg_info emerg; 4029 struct kvm_s390_extcall_info extcall; 4030 struct kvm_s390_prefix_info prefix; 4031 struct kvm_s390_stop_info stop; 4032 struct kvm_s390_mchk_info mchk; 4033 char reserved[64]; 4034 } u; 4035 }; 4036 4037type can be one of the following: 4038 4039- KVM_S390_SIGP_STOP - sigp stop; parameter in .stop 4040- KVM_S390_PROGRAM_INT - program check; parameters in .pgm 4041- KVM_S390_SIGP_SET_PREFIX - sigp set prefix; parameters in .prefix 4042- KVM_S390_RESTART - restart; no parameters 4043- KVM_S390_INT_CLOCK_COMP - clock comparator interrupt; no parameters 4044- KVM_S390_INT_CPU_TIMER - CPU timer interrupt; no parameters 4045- KVM_S390_INT_EMERGENCY - sigp emergency; parameters in .emerg 4046- KVM_S390_INT_EXTERNAL_CALL - sigp external call; parameters in .extcall 4047- KVM_S390_MCHK - machine check interrupt; parameters in .mchk 4048 4049This is an asynchronous vcpu ioctl and can be invoked from any thread. 4050 40514.94 KVM_S390_GET_IRQ_STATE 4052--------------------------- 4053 4054:Capability: KVM_CAP_S390_IRQ_STATE 4055:Architectures: s390 4056:Type: vcpu ioctl 4057:Parameters: struct kvm_s390_irq_state (out) 4058:Returns: >= number of bytes copied into buffer, 4059 -EINVAL if buffer size is 0, 4060 -ENOBUFS if buffer size is too small to fit all pending interrupts, 4061 -EFAULT if the buffer address was invalid 4062 4063This ioctl allows userspace to retrieve the complete state of all currently 4064pending interrupts in a single buffer. Use cases include migration 4065and introspection. The parameter structure contains the address of a 4066userspace buffer and its length:: 4067 4068 struct kvm_s390_irq_state { 4069 __u64 buf; 4070 __u32 flags; /* will stay unused for compatibility reasons */ 4071 __u32 len; 4072 __u32 reserved[4]; /* will stay unused for compatibility reasons */ 4073 }; 4074 4075Userspace passes in the above struct and for each pending interrupt a 4076struct kvm_s390_irq is copied to the provided buffer. 4077 4078The structure contains a flags and a reserved field for future extensions. As 4079the kernel never checked for flags == 0 and QEMU never pre-zeroed flags and 4080reserved, these fields can not be used in the future without breaking 4081compatibility. 4082 4083If -ENOBUFS is returned the buffer provided was too small and userspace 4084may retry with a bigger buffer. 4085 40864.95 KVM_S390_SET_IRQ_STATE 4087--------------------------- 4088 4089:Capability: KVM_CAP_S390_IRQ_STATE 4090:Architectures: s390 4091:Type: vcpu ioctl 4092:Parameters: struct kvm_s390_irq_state (in) 4093:Returns: 0 on success, 4094 -EFAULT if the buffer address was invalid, 4095 -EINVAL for an invalid buffer length (see below), 4096 -EBUSY if there were already interrupts pending, 4097 errors occurring when actually injecting the 4098 interrupt. See KVM_S390_IRQ. 4099 4100This ioctl allows userspace to set the complete state of all cpu-local 4101interrupts currently pending for the vcpu. It is intended for restoring 4102interrupt state after a migration. The input parameter is a userspace buffer 4103containing a struct kvm_s390_irq_state:: 4104 4105 struct kvm_s390_irq_state { 4106 __u64 buf; 4107 __u32 flags; /* will stay unused for compatibility reasons */ 4108 __u32 len; 4109 __u32 reserved[4]; /* will stay unused for compatibility reasons */ 4110 }; 4111 4112The restrictions for flags and reserved apply as well. 4113(see KVM_S390_GET_IRQ_STATE) 4114 4115The userspace memory referenced by buf contains a struct kvm_s390_irq 4116for each interrupt to be injected into the guest. 4117If one of the interrupts could not be injected for some reason the 4118ioctl aborts. 4119 4120len must be a multiple of sizeof(struct kvm_s390_irq). It must be > 0 4121and it must not exceed (max_vcpus + 32) * sizeof(struct kvm_s390_irq), 4122which is the maximum number of possibly pending cpu-local interrupts. 4123 41244.96 KVM_SMI 4125------------ 4126 4127:Capability: KVM_CAP_X86_SMM 4128:Architectures: x86 4129:Type: vcpu ioctl 4130:Parameters: none 4131:Returns: 0 on success, -1 on error 4132 4133Queues an SMI on the thread's vcpu. 4134 41354.97 KVM_X86_SET_MSR_FILTER 4136---------------------------- 4137 4138:Capability: KVM_CAP_X86_MSR_FILTER 4139:Architectures: x86 4140:Type: vm ioctl 4141:Parameters: struct kvm_msr_filter 4142:Returns: 0 on success, < 0 on error 4143 4144:: 4145 4146 struct kvm_msr_filter_range { 4147 #define KVM_MSR_FILTER_READ (1 << 0) 4148 #define KVM_MSR_FILTER_WRITE (1 << 1) 4149 __u32 flags; 4150 __u32 nmsrs; /* number of msrs in bitmap */ 4151 __u32 base; /* MSR index the bitmap starts at */ 4152 __u8 *bitmap; /* a 1 bit allows the operations in flags, 0 denies */ 4153 }; 4154 4155 #define KVM_MSR_FILTER_MAX_RANGES 16 4156 struct kvm_msr_filter { 4157 #define KVM_MSR_FILTER_DEFAULT_ALLOW (0 << 0) 4158 #define KVM_MSR_FILTER_DEFAULT_DENY (1 << 0) 4159 __u32 flags; 4160 struct kvm_msr_filter_range ranges[KVM_MSR_FILTER_MAX_RANGES]; 4161 }; 4162 4163flags values for ``struct kvm_msr_filter_range``: 4164 4165``KVM_MSR_FILTER_READ`` 4166 4167 Filter read accesses to MSRs using the given bitmap. A 0 in the bitmap 4168 indicates that read accesses should be denied, while a 1 indicates that 4169 a read for a particular MSR should be allowed regardless of the default 4170 filter action. 4171 4172``KVM_MSR_FILTER_WRITE`` 4173 4174 Filter write accesses to MSRs using the given bitmap. A 0 in the bitmap 4175 indicates that write accesses should be denied, while a 1 indicates that 4176 a write for a particular MSR should be allowed regardless of the default 4177 filter action. 4178 4179flags values for ``struct kvm_msr_filter``: 4180 4181``KVM_MSR_FILTER_DEFAULT_ALLOW`` 4182 4183 If no filter range matches an MSR index that is getting accessed, KVM will 4184 allow accesses to all MSRs by default. 4185 4186``KVM_MSR_FILTER_DEFAULT_DENY`` 4187 4188 If no filter range matches an MSR index that is getting accessed, KVM will 4189 deny accesses to all MSRs by default. 4190 4191This ioctl allows userspace to define up to 16 bitmaps of MSR ranges to deny 4192guest MSR accesses that would normally be allowed by KVM. If an MSR is not 4193covered by a specific range, the "default" filtering behavior applies. Each 4194bitmap range covers MSRs from [base .. base+nmsrs). 4195 4196If an MSR access is denied by userspace, the resulting KVM behavior depends on 4197whether or not KVM_CAP_X86_USER_SPACE_MSR's KVM_MSR_EXIT_REASON_FILTER is 4198enabled. If KVM_MSR_EXIT_REASON_FILTER is enabled, KVM will exit to userspace 4199on denied accesses, i.e. userspace effectively intercepts the MSR access. If 4200KVM_MSR_EXIT_REASON_FILTER is not enabled, KVM will inject a #GP into the guest 4201on denied accesses. 4202 4203If an MSR access is allowed by userspace, KVM will emulate and/or virtualize 4204the access in accordance with the vCPU model. Note, KVM may still ultimately 4205inject a #GP if an access is allowed by userspace, e.g. if KVM doesn't support 4206the MSR, or to follow architectural behavior for the MSR. 4207 4208By default, KVM operates in KVM_MSR_FILTER_DEFAULT_ALLOW mode with no MSR range 4209filters. 4210 4211Calling this ioctl with an empty set of ranges (all nmsrs == 0) disables MSR 4212filtering. In that mode, ``KVM_MSR_FILTER_DEFAULT_DENY`` is invalid and causes 4213an error. 4214 4215.. warning:: 4216 MSR accesses as part of nested VM-Enter/VM-Exit are not filtered. 4217 This includes both writes to individual VMCS fields and reads/writes 4218 through the MSR lists pointed to by the VMCS. 4219 4220 x2APIC MSR accesses cannot be filtered (KVM silently ignores filters that 4221 cover any x2APIC MSRs). 4222 4223Note, invoking this ioctl while a vCPU is running is inherently racy. However, 4224KVM does guarantee that vCPUs will see either the previous filter or the new 4225filter, e.g. MSRs with identical settings in both the old and new filter will 4226have deterministic behavior. 4227 4228Similarly, if userspace wishes to intercept on denied accesses, 4229KVM_MSR_EXIT_REASON_FILTER must be enabled before activating any filters, and 4230left enabled until after all filters are deactivated. Failure to do so may 4231result in KVM injecting a #GP instead of exiting to userspace. 4232 42334.98 KVM_CREATE_SPAPR_TCE_64 4234---------------------------- 4235 4236:Capability: KVM_CAP_SPAPR_TCE_64 4237:Architectures: powerpc 4238:Type: vm ioctl 4239:Parameters: struct kvm_create_spapr_tce_64 (in) 4240:Returns: file descriptor for manipulating the created TCE table 4241 4242This is an extension for KVM_CAP_SPAPR_TCE which only supports 32bit 4243windows, described in 4.62 KVM_CREATE_SPAPR_TCE 4244 4245This capability uses extended struct in ioctl interface:: 4246 4247 /* for KVM_CAP_SPAPR_TCE_64 */ 4248 struct kvm_create_spapr_tce_64 { 4249 __u64 liobn; 4250 __u32 page_shift; 4251 __u32 flags; 4252 __u64 offset; /* in pages */ 4253 __u64 size; /* in pages */ 4254 }; 4255 4256The aim of extension is to support an additional bigger DMA window with 4257a variable page size. 4258KVM_CREATE_SPAPR_TCE_64 receives a 64bit window size, an IOMMU page shift and 4259a bus offset of the corresponding DMA window, @size and @offset are numbers 4260of IOMMU pages. 4261 4262@flags are not used at the moment. 4263 4264The rest of functionality is identical to KVM_CREATE_SPAPR_TCE. 4265 42664.99 KVM_REINJECT_CONTROL 4267------------------------- 4268 4269:Capability: KVM_CAP_REINJECT_CONTROL 4270:Architectures: x86 4271:Type: vm ioctl 4272:Parameters: struct kvm_reinject_control (in) 4273:Returns: 0 on success, 4274 -EFAULT if struct kvm_reinject_control cannot be read, 4275 -ENXIO if KVM_CREATE_PIT or KVM_CREATE_PIT2 didn't succeed earlier. 4276 4277i8254 (PIT) has two modes, reinject and !reinject. The default is reinject, 4278where KVM queues elapsed i8254 ticks and monitors completion of interrupt from 4279vector(s) that i8254 injects. Reinject mode dequeues a tick and injects its 4280interrupt whenever there isn't a pending interrupt from i8254. 4281!reinject mode injects an interrupt as soon as a tick arrives. 4282 4283:: 4284 4285 struct kvm_reinject_control { 4286 __u8 pit_reinject; 4287 __u8 reserved[31]; 4288 }; 4289 4290pit_reinject = 0 (!reinject mode) is recommended, unless running an old 4291operating system that uses the PIT for timing (e.g. Linux 2.4.x). 4292 42934.100 KVM_PPC_CONFIGURE_V3_MMU 4294------------------------------ 4295 4296:Capability: KVM_CAP_PPC_RADIX_MMU or KVM_CAP_PPC_HASH_MMU_V3 4297:Architectures: ppc 4298:Type: vm ioctl 4299:Parameters: struct kvm_ppc_mmuv3_cfg (in) 4300:Returns: 0 on success, 4301 -EFAULT if struct kvm_ppc_mmuv3_cfg cannot be read, 4302 -EINVAL if the configuration is invalid 4303 4304This ioctl controls whether the guest will use radix or HPT (hashed 4305page table) translation, and sets the pointer to the process table for 4306the guest. 4307 4308:: 4309 4310 struct kvm_ppc_mmuv3_cfg { 4311 __u64 flags; 4312 __u64 process_table; 4313 }; 4314 4315There are two bits that can be set in flags; KVM_PPC_MMUV3_RADIX and 4316KVM_PPC_MMUV3_GTSE. KVM_PPC_MMUV3_RADIX, if set, configures the guest 4317to use radix tree translation, and if clear, to use HPT translation. 4318KVM_PPC_MMUV3_GTSE, if set and if KVM permits it, configures the guest 4319to be able to use the global TLB and SLB invalidation instructions; 4320if clear, the guest may not use these instructions. 4321 4322The process_table field specifies the address and size of the guest 4323process table, which is in the guest's space. This field is formatted 4324as the second doubleword of the partition table entry, as defined in 4325the Power ISA V3.00, Book III section 5.7.6.1. 4326 43274.101 KVM_PPC_GET_RMMU_INFO 4328--------------------------- 4329 4330:Capability: KVM_CAP_PPC_RADIX_MMU 4331:Architectures: ppc 4332:Type: vm ioctl 4333:Parameters: struct kvm_ppc_rmmu_info (out) 4334:Returns: 0 on success, 4335 -EFAULT if struct kvm_ppc_rmmu_info cannot be written, 4336 -EINVAL if no useful information can be returned 4337 4338This ioctl returns a structure containing two things: (a) a list 4339containing supported radix tree geometries, and (b) a list that maps 4340page sizes to put in the "AP" (actual page size) field for the tlbie 4341(TLB invalidate entry) instruction. 4342 4343:: 4344 4345 struct kvm_ppc_rmmu_info { 4346 struct kvm_ppc_radix_geom { 4347 __u8 page_shift; 4348 __u8 level_bits[4]; 4349 __u8 pad[3]; 4350 } geometries[8]; 4351 __u32 ap_encodings[8]; 4352 }; 4353 4354The geometries[] field gives up to 8 supported geometries for the 4355radix page table, in terms of the log base 2 of the smallest page 4356size, and the number of bits indexed at each level of the tree, from 4357the PTE level up to the PGD level in that order. Any unused entries 4358will have 0 in the page_shift field. 4359 4360The ap_encodings gives the supported page sizes and their AP field 4361encodings, encoded with the AP value in the top 3 bits and the log 4362base 2 of the page size in the bottom 6 bits. 4363 43644.102 KVM_PPC_RESIZE_HPT_PREPARE 4365-------------------------------- 4366 4367:Capability: KVM_CAP_SPAPR_RESIZE_HPT 4368:Architectures: powerpc 4369:Type: vm ioctl 4370:Parameters: struct kvm_ppc_resize_hpt (in) 4371:Returns: 0 on successful completion, 4372 >0 if a new HPT is being prepared, the value is an estimated 4373 number of milliseconds until preparation is complete, 4374 -EFAULT if struct kvm_reinject_control cannot be read, 4375 -EINVAL if the supplied shift or flags are invalid, 4376 -ENOMEM if unable to allocate the new HPT, 4377 4378Used to implement the PAPR extension for runtime resizing of a guest's 4379Hashed Page Table (HPT). Specifically this starts, stops or monitors 4380the preparation of a new potential HPT for the guest, essentially 4381implementing the H_RESIZE_HPT_PREPARE hypercall. 4382 4383:: 4384 4385 struct kvm_ppc_resize_hpt { 4386 __u64 flags; 4387 __u32 shift; 4388 __u32 pad; 4389 }; 4390 4391If called with shift > 0 when there is no pending HPT for the guest, 4392this begins preparation of a new pending HPT of size 2^(shift) bytes. 4393It then returns a positive integer with the estimated number of 4394milliseconds until preparation is complete. 4395 4396If called when there is a pending HPT whose size does not match that 4397requested in the parameters, discards the existing pending HPT and 4398creates a new one as above. 4399 4400If called when there is a pending HPT of the size requested, will: 4401 4402 * If preparation of the pending HPT is already complete, return 0 4403 * If preparation of the pending HPT has failed, return an error 4404 code, then discard the pending HPT. 4405 * If preparation of the pending HPT is still in progress, return an 4406 estimated number of milliseconds until preparation is complete. 4407 4408If called with shift == 0, discards any currently pending HPT and 4409returns 0 (i.e. cancels any in-progress preparation). 4410 4411flags is reserved for future expansion, currently setting any bits in 4412flags will result in an -EINVAL. 4413 4414Normally this will be called repeatedly with the same parameters until 4415it returns <= 0. The first call will initiate preparation, subsequent 4416ones will monitor preparation until it completes or fails. 4417 44184.103 KVM_PPC_RESIZE_HPT_COMMIT 4419------------------------------- 4420 4421:Capability: KVM_CAP_SPAPR_RESIZE_HPT 4422:Architectures: powerpc 4423:Type: vm ioctl 4424:Parameters: struct kvm_ppc_resize_hpt (in) 4425:Returns: 0 on successful completion, 4426 -EFAULT if struct kvm_reinject_control cannot be read, 4427 -EINVAL if the supplied shift or flags are invalid, 4428 -ENXIO is there is no pending HPT, or the pending HPT doesn't 4429 have the requested size, 4430 -EBUSY if the pending HPT is not fully prepared, 4431 -ENOSPC if there was a hash collision when moving existing 4432 HPT entries to the new HPT, 4433 -EIO on other error conditions 4434 4435Used to implement the PAPR extension for runtime resizing of a guest's 4436Hashed Page Table (HPT). Specifically this requests that the guest be 4437transferred to working with the new HPT, essentially implementing the 4438H_RESIZE_HPT_COMMIT hypercall. 4439 4440:: 4441 4442 struct kvm_ppc_resize_hpt { 4443 __u64 flags; 4444 __u32 shift; 4445 __u32 pad; 4446 }; 4447 4448This should only be called after KVM_PPC_RESIZE_HPT_PREPARE has 4449returned 0 with the same parameters. In other cases 4450KVM_PPC_RESIZE_HPT_COMMIT will return an error (usually -ENXIO or 4451-EBUSY, though others may be possible if the preparation was started, 4452but failed). 4453 4454This will have undefined effects on the guest if it has not already 4455placed itself in a quiescent state where no vcpu will make MMU enabled 4456memory accesses. 4457 4458On successful completion, the pending HPT will become the guest's active 4459HPT and the previous HPT will be discarded. 4460 4461On failure, the guest will still be operating on its previous HPT. 4462 44634.104 KVM_X86_GET_MCE_CAP_SUPPORTED 4464----------------------------------- 4465 4466:Capability: KVM_CAP_MCE 4467:Architectures: x86 4468:Type: system ioctl 4469:Parameters: u64 mce_cap (out) 4470:Returns: 0 on success, -1 on error 4471 4472Returns supported MCE capabilities. The u64 mce_cap parameter 4473has the same format as the MSR_IA32_MCG_CAP register. Supported 4474capabilities will have the corresponding bits set. 4475 44764.105 KVM_X86_SETUP_MCE 4477----------------------- 4478 4479:Capability: KVM_CAP_MCE 4480:Architectures: x86 4481:Type: vcpu ioctl 4482:Parameters: u64 mcg_cap (in) 4483:Returns: 0 on success, 4484 -EFAULT if u64 mcg_cap cannot be read, 4485 -EINVAL if the requested number of banks is invalid, 4486 -EINVAL if requested MCE capability is not supported. 4487 4488Initializes MCE support for use. The u64 mcg_cap parameter 4489has the same format as the MSR_IA32_MCG_CAP register and 4490specifies which capabilities should be enabled. The maximum 4491supported number of error-reporting banks can be retrieved when 4492checking for KVM_CAP_MCE. The supported capabilities can be 4493retrieved with KVM_X86_GET_MCE_CAP_SUPPORTED. 4494 44954.106 KVM_X86_SET_MCE 4496--------------------- 4497 4498:Capability: KVM_CAP_MCE 4499:Architectures: x86 4500:Type: vcpu ioctl 4501:Parameters: struct kvm_x86_mce (in) 4502:Returns: 0 on success, 4503 -EFAULT if struct kvm_x86_mce cannot be read, 4504 -EINVAL if the bank number is invalid, 4505 -EINVAL if VAL bit is not set in status field. 4506 4507Inject a machine check error (MCE) into the guest. The input 4508parameter is:: 4509 4510 struct kvm_x86_mce { 4511 __u64 status; 4512 __u64 addr; 4513 __u64 misc; 4514 __u64 mcg_status; 4515 __u8 bank; 4516 __u8 pad1[7]; 4517 __u64 pad2[3]; 4518 }; 4519 4520If the MCE being reported is an uncorrected error, KVM will 4521inject it as an MCE exception into the guest. If the guest 4522MCG_STATUS register reports that an MCE is in progress, KVM 4523causes an KVM_EXIT_SHUTDOWN vmexit. 4524 4525Otherwise, if the MCE is a corrected error, KVM will just 4526store it in the corresponding bank (provided this bank is 4527not holding a previously reported uncorrected error). 4528 45294.107 KVM_S390_GET_CMMA_BITS 4530---------------------------- 4531 4532:Capability: KVM_CAP_S390_CMMA_MIGRATION 4533:Architectures: s390 4534:Type: vm ioctl 4535:Parameters: struct kvm_s390_cmma_log (in, out) 4536:Returns: 0 on success, a negative value on error 4537 4538Errors: 4539 4540 ====== ============================================================= 4541 ENOMEM not enough memory can be allocated to complete the task 4542 ENXIO if CMMA is not enabled 4543 EINVAL if KVM_S390_CMMA_PEEK is not set but migration mode was not enabled 4544 EINVAL if KVM_S390_CMMA_PEEK is not set but dirty tracking has been 4545 disabled (and thus migration mode was automatically disabled) 4546 EFAULT if the userspace address is invalid or if no page table is 4547 present for the addresses (e.g. when using hugepages). 4548 ====== ============================================================= 4549 4550This ioctl is used to get the values of the CMMA bits on the s390 4551architecture. It is meant to be used in two scenarios: 4552 4553- During live migration to save the CMMA values. Live migration needs 4554 to be enabled via the KVM_REQ_START_MIGRATION VM property. 4555- To non-destructively peek at the CMMA values, with the flag 4556 KVM_S390_CMMA_PEEK set. 4557 4558The ioctl takes parameters via the kvm_s390_cmma_log struct. The desired 4559values are written to a buffer whose location is indicated via the "values" 4560member in the kvm_s390_cmma_log struct. The values in the input struct are 4561also updated as needed. 4562 4563Each CMMA value takes up one byte. 4564 4565:: 4566 4567 struct kvm_s390_cmma_log { 4568 __u64 start_gfn; 4569 __u32 count; 4570 __u32 flags; 4571 union { 4572 __u64 remaining; 4573 __u64 mask; 4574 }; 4575 __u64 values; 4576 }; 4577 4578start_gfn is the number of the first guest frame whose CMMA values are 4579to be retrieved, 4580 4581count is the length of the buffer in bytes, 4582 4583values points to the buffer where the result will be written to. 4584 4585If count is greater than KVM_S390_SKEYS_MAX, then it is considered to be 4586KVM_S390_SKEYS_MAX. KVM_S390_SKEYS_MAX is re-used for consistency with 4587other ioctls. 4588 4589The result is written in the buffer pointed to by the field values, and 4590the values of the input parameter are updated as follows. 4591 4592Depending on the flags, different actions are performed. The only 4593supported flag so far is KVM_S390_CMMA_PEEK. 4594 4595The default behaviour if KVM_S390_CMMA_PEEK is not set is: 4596start_gfn will indicate the first page frame whose CMMA bits were dirty. 4597It is not necessarily the same as the one passed as input, as clean pages 4598are skipped. 4599 4600count will indicate the number of bytes actually written in the buffer. 4601It can (and very often will) be smaller than the input value, since the 4602buffer is only filled until 16 bytes of clean values are found (which 4603are then not copied in the buffer). Since a CMMA migration block needs 4604the base address and the length, for a total of 16 bytes, we will send 4605back some clean data if there is some dirty data afterwards, as long as 4606the size of the clean data does not exceed the size of the header. This 4607allows to minimize the amount of data to be saved or transferred over 4608the network at the expense of more roundtrips to userspace. The next 4609invocation of the ioctl will skip over all the clean values, saving 4610potentially more than just the 16 bytes we found. 4611 4612If KVM_S390_CMMA_PEEK is set: 4613the existing storage attributes are read even when not in migration 4614mode, and no other action is performed; 4615 4616the output start_gfn will be equal to the input start_gfn, 4617 4618the output count will be equal to the input count, except if the end of 4619memory has been reached. 4620 4621In both cases: 4622the field "remaining" will indicate the total number of dirty CMMA values 4623still remaining, or 0 if KVM_S390_CMMA_PEEK is set and migration mode is 4624not enabled. 4625 4626mask is unused. 4627 4628values points to the userspace buffer where the result will be stored. 4629 46304.108 KVM_S390_SET_CMMA_BITS 4631---------------------------- 4632 4633:Capability: KVM_CAP_S390_CMMA_MIGRATION 4634:Architectures: s390 4635:Type: vm ioctl 4636:Parameters: struct kvm_s390_cmma_log (in) 4637:Returns: 0 on success, a negative value on error 4638 4639This ioctl is used to set the values of the CMMA bits on the s390 4640architecture. It is meant to be used during live migration to restore 4641the CMMA values, but there are no restrictions on its use. 4642The ioctl takes parameters via the kvm_s390_cmma_values struct. 4643Each CMMA value takes up one byte. 4644 4645:: 4646 4647 struct kvm_s390_cmma_log { 4648 __u64 start_gfn; 4649 __u32 count; 4650 __u32 flags; 4651 union { 4652 __u64 remaining; 4653 __u64 mask; 4654 }; 4655 __u64 values; 4656 }; 4657 4658start_gfn indicates the starting guest frame number, 4659 4660count indicates how many values are to be considered in the buffer, 4661 4662flags is not used and must be 0. 4663 4664mask indicates which PGSTE bits are to be considered. 4665 4666remaining is not used. 4667 4668values points to the buffer in userspace where to store the values. 4669 4670This ioctl can fail with -ENOMEM if not enough memory can be allocated to 4671complete the task, with -ENXIO if CMMA is not enabled, with -EINVAL if 4672the count field is too large (e.g. more than KVM_S390_CMMA_SIZE_MAX) or 4673if the flags field was not 0, with -EFAULT if the userspace address is 4674invalid, if invalid pages are written to (e.g. after the end of memory) 4675or if no page table is present for the addresses (e.g. when using 4676hugepages). 4677 46784.109 KVM_PPC_GET_CPU_CHAR 4679-------------------------- 4680 4681:Capability: KVM_CAP_PPC_GET_CPU_CHAR 4682:Architectures: powerpc 4683:Type: vm ioctl 4684:Parameters: struct kvm_ppc_cpu_char (out) 4685:Returns: 0 on successful completion, 4686 -EFAULT if struct kvm_ppc_cpu_char cannot be written 4687 4688This ioctl gives userspace information about certain characteristics 4689of the CPU relating to speculative execution of instructions and 4690possible information leakage resulting from speculative execution (see 4691CVE-2017-5715, CVE-2017-5753 and CVE-2017-5754). The information is 4692returned in struct kvm_ppc_cpu_char, which looks like this:: 4693 4694 struct kvm_ppc_cpu_char { 4695 __u64 character; /* characteristics of the CPU */ 4696 __u64 behaviour; /* recommended software behaviour */ 4697 __u64 character_mask; /* valid bits in character */ 4698 __u64 behaviour_mask; /* valid bits in behaviour */ 4699 }; 4700 4701For extensibility, the character_mask and behaviour_mask fields 4702indicate which bits of character and behaviour have been filled in by 4703the kernel. If the set of defined bits is extended in future then 4704userspace will be able to tell whether it is running on a kernel that 4705knows about the new bits. 4706 4707The character field describes attributes of the CPU which can help 4708with preventing inadvertent information disclosure - specifically, 4709whether there is an instruction to flash-invalidate the L1 data cache 4710(ori 30,30,0 or mtspr SPRN_TRIG2,rN), whether the L1 data cache is set 4711to a mode where entries can only be used by the thread that created 4712them, whether the bcctr[l] instruction prevents speculation, and 4713whether a speculation barrier instruction (ori 31,31,0) is provided. 4714 4715The behaviour field describes actions that software should take to 4716prevent inadvertent information disclosure, and thus describes which 4717vulnerabilities the hardware is subject to; specifically whether the 4718L1 data cache should be flushed when returning to user mode from the 4719kernel, and whether a speculation barrier should be placed between an 4720array bounds check and the array access. 4721 4722These fields use the same bit definitions as the new 4723H_GET_CPU_CHARACTERISTICS hypercall. 4724 47254.110 KVM_MEMORY_ENCRYPT_OP 4726--------------------------- 4727 4728:Capability: basic 4729:Architectures: x86 4730:Type: vm 4731:Parameters: an opaque platform specific structure (in/out) 4732:Returns: 0 on success; -1 on error 4733 4734If the platform supports creating encrypted VMs then this ioctl can be used 4735for issuing platform-specific memory encryption commands to manage those 4736encrypted VMs. 4737 4738Currently, this ioctl is used for issuing Secure Encrypted Virtualization 4739(SEV) commands on AMD Processors. The SEV commands are defined in 4740Documentation/virt/kvm/x86/amd-memory-encryption.rst. 4741 47424.111 KVM_MEMORY_ENCRYPT_REG_REGION 4743----------------------------------- 4744 4745:Capability: basic 4746:Architectures: x86 4747:Type: system 4748:Parameters: struct kvm_enc_region (in) 4749:Returns: 0 on success; -1 on error 4750 4751This ioctl can be used to register a guest memory region which may 4752contain encrypted data (e.g. guest RAM, SMRAM etc). 4753 4754It is used in the SEV-enabled guest. When encryption is enabled, a guest 4755memory region may contain encrypted data. The SEV memory encryption 4756engine uses a tweak such that two identical plaintext pages, each at 4757different locations will have differing ciphertexts. So swapping or 4758moving ciphertext of those pages will not result in plaintext being 4759swapped. So relocating (or migrating) physical backing pages for the SEV 4760guest will require some additional steps. 4761 4762Note: The current SEV key management spec does not provide commands to 4763swap or migrate (move) ciphertext pages. Hence, for now we pin the guest 4764memory region registered with the ioctl. 4765 47664.112 KVM_MEMORY_ENCRYPT_UNREG_REGION 4767------------------------------------- 4768 4769:Capability: basic 4770:Architectures: x86 4771:Type: system 4772:Parameters: struct kvm_enc_region (in) 4773:Returns: 0 on success; -1 on error 4774 4775This ioctl can be used to unregister the guest memory region registered 4776with KVM_MEMORY_ENCRYPT_REG_REGION ioctl above. 4777 47784.113 KVM_HYPERV_EVENTFD 4779------------------------ 4780 4781:Capability: KVM_CAP_HYPERV_EVENTFD 4782:Architectures: x86 4783:Type: vm ioctl 4784:Parameters: struct kvm_hyperv_eventfd (in) 4785 4786This ioctl (un)registers an eventfd to receive notifications from the guest on 4787the specified Hyper-V connection id through the SIGNAL_EVENT hypercall, without 4788causing a user exit. SIGNAL_EVENT hypercall with non-zero event flag number 4789(bits 24-31) still triggers a KVM_EXIT_HYPERV_HCALL user exit. 4790 4791:: 4792 4793 struct kvm_hyperv_eventfd { 4794 __u32 conn_id; 4795 __s32 fd; 4796 __u32 flags; 4797 __u32 padding[3]; 4798 }; 4799 4800The conn_id field should fit within 24 bits:: 4801 4802 #define KVM_HYPERV_CONN_ID_MASK 0x00ffffff 4803 4804The acceptable values for the flags field are:: 4805 4806 #define KVM_HYPERV_EVENTFD_DEASSIGN (1 << 0) 4807 4808:Returns: 0 on success, 4809 -EINVAL if conn_id or flags is outside the allowed range, 4810 -ENOENT on deassign if the conn_id isn't registered, 4811 -EEXIST on assign if the conn_id is already registered 4812 48134.114 KVM_GET_NESTED_STATE 4814-------------------------- 4815 4816:Capability: KVM_CAP_NESTED_STATE 4817:Architectures: x86 4818:Type: vcpu ioctl 4819:Parameters: struct kvm_nested_state (in/out) 4820:Returns: 0 on success, -1 on error 4821 4822Errors: 4823 4824 ===== ============================================================= 4825 E2BIG the total state size exceeds the value of 'size' specified by 4826 the user; the size required will be written into size. 4827 ===== ============================================================= 4828 4829:: 4830 4831 struct kvm_nested_state { 4832 __u16 flags; 4833 __u16 format; 4834 __u32 size; 4835 4836 union { 4837 struct kvm_vmx_nested_state_hdr vmx; 4838 struct kvm_svm_nested_state_hdr svm; 4839 4840 /* Pad the header to 128 bytes. */ 4841 __u8 pad[120]; 4842 } hdr; 4843 4844 union { 4845 struct kvm_vmx_nested_state_data vmx[0]; 4846 struct kvm_svm_nested_state_data svm[0]; 4847 } data; 4848 }; 4849 4850 #define KVM_STATE_NESTED_GUEST_MODE 0x00000001 4851 #define KVM_STATE_NESTED_RUN_PENDING 0x00000002 4852 #define KVM_STATE_NESTED_EVMCS 0x00000004 4853 4854 #define KVM_STATE_NESTED_FORMAT_VMX 0 4855 #define KVM_STATE_NESTED_FORMAT_SVM 1 4856 4857 #define KVM_STATE_NESTED_VMX_VMCS_SIZE 0x1000 4858 4859 #define KVM_STATE_NESTED_VMX_SMM_GUEST_MODE 0x00000001 4860 #define KVM_STATE_NESTED_VMX_SMM_VMXON 0x00000002 4861 4862 #define KVM_STATE_VMX_PREEMPTION_TIMER_DEADLINE 0x00000001 4863 4864 struct kvm_vmx_nested_state_hdr { 4865 __u64 vmxon_pa; 4866 __u64 vmcs12_pa; 4867 4868 struct { 4869 __u16 flags; 4870 } smm; 4871 4872 __u32 flags; 4873 __u64 preemption_timer_deadline; 4874 }; 4875 4876 struct kvm_vmx_nested_state_data { 4877 __u8 vmcs12[KVM_STATE_NESTED_VMX_VMCS_SIZE]; 4878 __u8 shadow_vmcs12[KVM_STATE_NESTED_VMX_VMCS_SIZE]; 4879 }; 4880 4881This ioctl copies the vcpu's nested virtualization state from the kernel to 4882userspace. 4883 4884The maximum size of the state can be retrieved by passing KVM_CAP_NESTED_STATE 4885to the KVM_CHECK_EXTENSION ioctl(). 4886 48874.115 KVM_SET_NESTED_STATE 4888-------------------------- 4889 4890:Capability: KVM_CAP_NESTED_STATE 4891:Architectures: x86 4892:Type: vcpu ioctl 4893:Parameters: struct kvm_nested_state (in) 4894:Returns: 0 on success, -1 on error 4895 4896This copies the vcpu's kvm_nested_state struct from userspace to the kernel. 4897For the definition of struct kvm_nested_state, see KVM_GET_NESTED_STATE. 4898 48994.116 KVM_(UN)REGISTER_COALESCED_MMIO 4900------------------------------------- 4901 4902:Capability: KVM_CAP_COALESCED_MMIO (for coalesced mmio) 4903 KVM_CAP_COALESCED_PIO (for coalesced pio) 4904:Architectures: all 4905:Type: vm ioctl 4906:Parameters: struct kvm_coalesced_mmio_zone 4907:Returns: 0 on success, < 0 on error 4908 4909Coalesced I/O is a performance optimization that defers hardware 4910register write emulation so that userspace exits are avoided. It is 4911typically used to reduce the overhead of emulating frequently accessed 4912hardware registers. 4913 4914When a hardware register is configured for coalesced I/O, write accesses 4915do not exit to userspace and their value is recorded in a ring buffer 4916that is shared between kernel and userspace. 4917 4918Coalesced I/O is used if one or more write accesses to a hardware 4919register can be deferred until a read or a write to another hardware 4920register on the same device. This last access will cause a vmexit and 4921userspace will process accesses from the ring buffer before emulating 4922it. That will avoid exiting to userspace on repeated writes. 4923 4924Coalesced pio is based on coalesced mmio. There is little difference 4925between coalesced mmio and pio except that coalesced pio records accesses 4926to I/O ports. 4927 49284.117 KVM_CLEAR_DIRTY_LOG (vm ioctl) 4929------------------------------------ 4930 4931:Capability: KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2 4932:Architectures: x86, arm64, mips 4933:Type: vm ioctl 4934:Parameters: struct kvm_clear_dirty_log (in) 4935:Returns: 0 on success, -1 on error 4936 4937:: 4938 4939 /* for KVM_CLEAR_DIRTY_LOG */ 4940 struct kvm_clear_dirty_log { 4941 __u32 slot; 4942 __u32 num_pages; 4943 __u64 first_page; 4944 union { 4945 void __user *dirty_bitmap; /* one bit per page */ 4946 __u64 padding; 4947 }; 4948 }; 4949 4950The ioctl clears the dirty status of pages in a memory slot, according to 4951the bitmap that is passed in struct kvm_clear_dirty_log's dirty_bitmap 4952field. Bit 0 of the bitmap corresponds to page "first_page" in the 4953memory slot, and num_pages is the size in bits of the input bitmap. 4954first_page must be a multiple of 64; num_pages must also be a multiple of 495564 unless first_page + num_pages is the size of the memory slot. For each 4956bit that is set in the input bitmap, the corresponding page is marked "clean" 4957in KVM's dirty bitmap, and dirty tracking is re-enabled for that page 4958(for example via write-protection, or by clearing the dirty bit in 4959a page table entry). 4960 4961If KVM_CAP_MULTI_ADDRESS_SPACE is available, bits 16-31 of slot field specifies 4962the address space for which you want to clear the dirty status. See 4963KVM_SET_USER_MEMORY_REGION for details on the usage of slot field. 4964 4965This ioctl is mostly useful when KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2 4966is enabled; for more information, see the description of the capability. 4967However, it can always be used as long as KVM_CHECK_EXTENSION confirms 4968that KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2 is present. 4969 49704.118 KVM_GET_SUPPORTED_HV_CPUID 4971-------------------------------- 4972 4973:Capability: KVM_CAP_HYPERV_CPUID (vcpu), KVM_CAP_SYS_HYPERV_CPUID (system) 4974:Architectures: x86 4975:Type: system ioctl, vcpu ioctl 4976:Parameters: struct kvm_cpuid2 (in/out) 4977:Returns: 0 on success, -1 on error 4978 4979:: 4980 4981 struct kvm_cpuid2 { 4982 __u32 nent; 4983 __u32 padding; 4984 struct kvm_cpuid_entry2 entries[0]; 4985 }; 4986 4987 struct kvm_cpuid_entry2 { 4988 __u32 function; 4989 __u32 index; 4990 __u32 flags; 4991 __u32 eax; 4992 __u32 ebx; 4993 __u32 ecx; 4994 __u32 edx; 4995 __u32 padding[3]; 4996 }; 4997 4998This ioctl returns x86 cpuid features leaves related to Hyper-V emulation in 4999KVM. Userspace can use the information returned by this ioctl to construct 5000cpuid information presented to guests consuming Hyper-V enlightenments (e.g. 5001Windows or Hyper-V guests). 5002 5003CPUID feature leaves returned by this ioctl are defined by Hyper-V Top Level 5004Functional Specification (TLFS). These leaves can't be obtained with 5005KVM_GET_SUPPORTED_CPUID ioctl because some of them intersect with KVM feature 5006leaves (0x40000000, 0x40000001). 5007 5008Currently, the following list of CPUID leaves are returned: 5009 5010 - HYPERV_CPUID_VENDOR_AND_MAX_FUNCTIONS 5011 - HYPERV_CPUID_INTERFACE 5012 - HYPERV_CPUID_VERSION 5013 - HYPERV_CPUID_FEATURES 5014 - HYPERV_CPUID_ENLIGHTMENT_INFO 5015 - HYPERV_CPUID_IMPLEMENT_LIMITS 5016 - HYPERV_CPUID_NESTED_FEATURES 5017 - HYPERV_CPUID_SYNDBG_VENDOR_AND_MAX_FUNCTIONS 5018 - HYPERV_CPUID_SYNDBG_INTERFACE 5019 - HYPERV_CPUID_SYNDBG_PLATFORM_CAPABILITIES 5020 5021Userspace invokes KVM_GET_SUPPORTED_HV_CPUID by passing a kvm_cpuid2 structure 5022with the 'nent' field indicating the number of entries in the variable-size 5023array 'entries'. If the number of entries is too low to describe all Hyper-V 5024feature leaves, an error (E2BIG) is returned. If the number is more or equal 5025to the number of Hyper-V feature leaves, the 'nent' field is adjusted to the 5026number of valid entries in the 'entries' array, which is then filled. 5027 5028'index' and 'flags' fields in 'struct kvm_cpuid_entry2' are currently reserved, 5029userspace should not expect to get any particular value there. 5030 5031Note, vcpu version of KVM_GET_SUPPORTED_HV_CPUID is currently deprecated. Unlike 5032system ioctl which exposes all supported feature bits unconditionally, vcpu 5033version has the following quirks: 5034 5035- HYPERV_CPUID_NESTED_FEATURES leaf and HV_X64_ENLIGHTENED_VMCS_RECOMMENDED 5036 feature bit are only exposed when Enlightened VMCS was previously enabled 5037 on the corresponding vCPU (KVM_CAP_HYPERV_ENLIGHTENED_VMCS). 5038- HV_STIMER_DIRECT_MODE_AVAILABLE bit is only exposed with in-kernel LAPIC. 5039 (presumes KVM_CREATE_IRQCHIP has already been called). 5040 50414.119 KVM_ARM_VCPU_FINALIZE 5042--------------------------- 5043 5044:Architectures: arm64 5045:Type: vcpu ioctl 5046:Parameters: int feature (in) 5047:Returns: 0 on success, -1 on error 5048 5049Errors: 5050 5051 ====== ============================================================== 5052 EPERM feature not enabled, needs configuration, or already finalized 5053 EINVAL feature unknown or not present 5054 ====== ============================================================== 5055 5056Recognised values for feature: 5057 5058 ===== =========================================== 5059 arm64 KVM_ARM_VCPU_SVE (requires KVM_CAP_ARM_SVE) 5060 ===== =========================================== 5061 5062Finalizes the configuration of the specified vcpu feature. 5063 5064The vcpu must already have been initialised, enabling the affected feature, by 5065means of a successful KVM_ARM_VCPU_INIT call with the appropriate flag set in 5066features[]. 5067 5068For affected vcpu features, this is a mandatory step that must be performed 5069before the vcpu is fully usable. 5070 5071Between KVM_ARM_VCPU_INIT and KVM_ARM_VCPU_FINALIZE, the feature may be 5072configured by use of ioctls such as KVM_SET_ONE_REG. The exact configuration 5073that should be performed and how to do it are feature-dependent. 5074 5075Other calls that depend on a particular feature being finalized, such as 5076KVM_RUN, KVM_GET_REG_LIST, KVM_GET_ONE_REG and KVM_SET_ONE_REG, will fail with 5077-EPERM unless the feature has already been finalized by means of a 5078KVM_ARM_VCPU_FINALIZE call. 5079 5080See KVM_ARM_VCPU_INIT for details of vcpu features that require finalization 5081using this ioctl. 5082 50834.120 KVM_SET_PMU_EVENT_FILTER 5084------------------------------ 5085 5086:Capability: KVM_CAP_PMU_EVENT_FILTER 5087:Architectures: x86 5088:Type: vm ioctl 5089:Parameters: struct kvm_pmu_event_filter (in) 5090:Returns: 0 on success, -1 on error 5091 5092Errors: 5093 5094 ====== ============================================================ 5095 EFAULT args[0] cannot be accessed 5096 EINVAL args[0] contains invalid data in the filter or filter events 5097 E2BIG nevents is too large 5098 EBUSY not enough memory to allocate the filter 5099 ====== ============================================================ 5100 5101:: 5102 5103 struct kvm_pmu_event_filter { 5104 __u32 action; 5105 __u32 nevents; 5106 __u32 fixed_counter_bitmap; 5107 __u32 flags; 5108 __u32 pad[4]; 5109 __u64 events[0]; 5110 }; 5111 5112This ioctl restricts the set of PMU events the guest can program by limiting 5113which event select and unit mask combinations are permitted. 5114 5115The argument holds a list of filter events which will be allowed or denied. 5116 5117Filter events only control general purpose counters; fixed purpose counters 5118are controlled by the fixed_counter_bitmap. 5119 5120Valid values for 'flags':: 5121 5122``0`` 5123 5124To use this mode, clear the 'flags' field. 5125 5126In this mode each event will contain an event select + unit mask. 5127 5128When the guest attempts to program the PMU the guest's event select + 5129unit mask is compared against the filter events to determine whether the 5130guest should have access. 5131 5132``KVM_PMU_EVENT_FLAG_MASKED_EVENTS`` 5133:Capability: KVM_CAP_PMU_EVENT_MASKED_EVENTS 5134 5135In this mode each filter event will contain an event select, mask, match, and 5136exclude value. To encode a masked event use:: 5137 5138 KVM_PMU_ENCODE_MASKED_ENTRY() 5139 5140An encoded event will follow this layout:: 5141 5142 Bits Description 5143 ---- ----------- 5144 7:0 event select (low bits) 5145 15:8 umask match 5146 31:16 unused 5147 35:32 event select (high bits) 5148 36:54 unused 5149 55 exclude bit 5150 63:56 umask mask 5151 5152When the guest attempts to program the PMU, these steps are followed in 5153determining if the guest should have access: 5154 5155 1. Match the event select from the guest against the filter events. 5156 2. If a match is found, match the guest's unit mask to the mask and match 5157 values of the included filter events. 5158 I.e. (unit mask & mask) == match && !exclude. 5159 3. If a match is found, match the guest's unit mask to the mask and match 5160 values of the excluded filter events. 5161 I.e. (unit mask & mask) == match && exclude. 5162 4. 5163 a. If an included match is found and an excluded match is not found, filter 5164 the event. 5165 b. For everything else, do not filter the event. 5166 5. 5167 a. If the event is filtered and it's an allow list, allow the guest to 5168 program the event. 5169 b. If the event is filtered and it's a deny list, do not allow the guest to 5170 program the event. 5171 5172When setting a new pmu event filter, -EINVAL will be returned if any of the 5173unused fields are set or if any of the high bits (35:32) in the event 5174select are set when called on Intel. 5175 5176Valid values for 'action':: 5177 5178 #define KVM_PMU_EVENT_ALLOW 0 5179 #define KVM_PMU_EVENT_DENY 1 5180 5181Via this API, KVM userspace can also control the behavior of the VM's fixed 5182counters (if any) by configuring the "action" and "fixed_counter_bitmap" fields. 5183 5184Specifically, KVM follows the following pseudo-code when determining whether to 5185allow the guest FixCtr[i] to count its pre-defined fixed event:: 5186 5187 FixCtr[i]_is_allowed = (action == ALLOW) && (bitmap & BIT(i)) || 5188 (action == DENY) && !(bitmap & BIT(i)); 5189 FixCtr[i]_is_denied = !FixCtr[i]_is_allowed; 5190 5191KVM always consumes fixed_counter_bitmap, it's userspace's responsibility to 5192ensure fixed_counter_bitmap is set correctly, e.g. if userspace wants to define 5193a filter that only affects general purpose counters. 5194 5195Note, the "events" field also applies to fixed counters' hardcoded event_select 5196and unit_mask values. "fixed_counter_bitmap" has higher priority than "events" 5197if there is a contradiction between the two. 5198 51994.121 KVM_PPC_SVM_OFF 5200--------------------- 5201 5202:Capability: basic 5203:Architectures: powerpc 5204:Type: vm ioctl 5205:Parameters: none 5206:Returns: 0 on successful completion, 5207 5208Errors: 5209 5210 ====== ================================================================ 5211 EINVAL if ultravisor failed to terminate the secure guest 5212 ENOMEM if hypervisor failed to allocate new radix page tables for guest 5213 ====== ================================================================ 5214 5215This ioctl is used to turn off the secure mode of the guest or transition 5216the guest from secure mode to normal mode. This is invoked when the guest 5217is reset. This has no effect if called for a normal guest. 5218 5219This ioctl issues an ultravisor call to terminate the secure guest, 5220unpins the VPA pages and releases all the device pages that are used to 5221track the secure pages by hypervisor. 5222 52234.122 KVM_S390_NORMAL_RESET 5224--------------------------- 5225 5226:Capability: KVM_CAP_S390_VCPU_RESETS 5227:Architectures: s390 5228:Type: vcpu ioctl 5229:Parameters: none 5230:Returns: 0 5231 5232This ioctl resets VCPU registers and control structures according to 5233the cpu reset definition in the POP (Principles Of Operation). 5234 52354.123 KVM_S390_INITIAL_RESET 5236---------------------------- 5237 5238:Capability: none 5239:Architectures: s390 5240:Type: vcpu ioctl 5241:Parameters: none 5242:Returns: 0 5243 5244This ioctl resets VCPU registers and control structures according to 5245the initial cpu reset definition in the POP. However, the cpu is not 5246put into ESA mode. This reset is a superset of the normal reset. 5247 52484.124 KVM_S390_CLEAR_RESET 5249-------------------------- 5250 5251:Capability: KVM_CAP_S390_VCPU_RESETS 5252:Architectures: s390 5253:Type: vcpu ioctl 5254:Parameters: none 5255:Returns: 0 5256 5257This ioctl resets VCPU registers and control structures according to 5258the clear cpu reset definition in the POP. However, the cpu is not put 5259into ESA mode. This reset is a superset of the initial reset. 5260 5261 52624.125 KVM_S390_PV_COMMAND 5263------------------------- 5264 5265:Capability: KVM_CAP_S390_PROTECTED 5266:Architectures: s390 5267:Type: vm ioctl 5268:Parameters: struct kvm_pv_cmd 5269:Returns: 0 on success, < 0 on error 5270 5271:: 5272 5273 struct kvm_pv_cmd { 5274 __u32 cmd; /* Command to be executed */ 5275 __u16 rc; /* Ultravisor return code */ 5276 __u16 rrc; /* Ultravisor return reason code */ 5277 __u64 data; /* Data or address */ 5278 __u32 flags; /* flags for future extensions. Must be 0 for now */ 5279 __u32 reserved[3]; 5280 }; 5281 5282**Ultravisor return codes** 5283The Ultravisor return (reason) codes are provided by the kernel if a 5284Ultravisor call has been executed to achieve the results expected by 5285the command. Therefore they are independent of the IOCTL return 5286code. If KVM changes `rc`, its value will always be greater than 0 5287hence setting it to 0 before issuing a PV command is advised to be 5288able to detect a change of `rc`. 5289 5290**cmd values:** 5291 5292KVM_PV_ENABLE 5293 Allocate memory and register the VM with the Ultravisor, thereby 5294 donating memory to the Ultravisor that will become inaccessible to 5295 KVM. All existing CPUs are converted to protected ones. After this 5296 command has succeeded, any CPU added via hotplug will become 5297 protected during its creation as well. 5298 5299 Errors: 5300 5301 ===== ============================= 5302 EINTR an unmasked signal is pending 5303 ===== ============================= 5304 5305KVM_PV_DISABLE 5306 Deregister the VM from the Ultravisor and reclaim the memory that had 5307 been donated to the Ultravisor, making it usable by the kernel again. 5308 All registered VCPUs are converted back to non-protected ones. If a 5309 previous protected VM had been prepared for asynchronous teardown with 5310 KVM_PV_ASYNC_CLEANUP_PREPARE and not subsequently torn down with 5311 KVM_PV_ASYNC_CLEANUP_PERFORM, it will be torn down in this call 5312 together with the current protected VM. 5313 5314KVM_PV_VM_SET_SEC_PARMS 5315 Pass the image header from VM memory to the Ultravisor in 5316 preparation of image unpacking and verification. 5317 5318KVM_PV_VM_UNPACK 5319 Unpack (protect and decrypt) a page of the encrypted boot image. 5320 5321KVM_PV_VM_VERIFY 5322 Verify the integrity of the unpacked image. Only if this succeeds, 5323 KVM is allowed to start protected VCPUs. 5324 5325KVM_PV_INFO 5326 :Capability: KVM_CAP_S390_PROTECTED_DUMP 5327 5328 Presents an API that provides Ultravisor related data to userspace 5329 via subcommands. len_max is the size of the user space buffer, 5330 len_written is KVM's indication of how much bytes of that buffer 5331 were actually written to. len_written can be used to determine the 5332 valid fields if more response fields are added in the future. 5333 5334 :: 5335 5336 enum pv_cmd_info_id { 5337 KVM_PV_INFO_VM, 5338 KVM_PV_INFO_DUMP, 5339 }; 5340 5341 struct kvm_s390_pv_info_header { 5342 __u32 id; 5343 __u32 len_max; 5344 __u32 len_written; 5345 __u32 reserved; 5346 }; 5347 5348 struct kvm_s390_pv_info { 5349 struct kvm_s390_pv_info_header header; 5350 struct kvm_s390_pv_info_dump dump; 5351 struct kvm_s390_pv_info_vm vm; 5352 }; 5353 5354**subcommands:** 5355 5356 KVM_PV_INFO_VM 5357 This subcommand provides basic Ultravisor information for PV 5358 hosts. These values are likely also exported as files in the sysfs 5359 firmware UV query interface but they are more easily available to 5360 programs in this API. 5361 5362 The installed calls and feature_indication members provide the 5363 installed UV calls and the UV's other feature indications. 5364 5365 The max_* members provide information about the maximum number of PV 5366 vcpus, PV guests and PV guest memory size. 5367 5368 :: 5369 5370 struct kvm_s390_pv_info_vm { 5371 __u64 inst_calls_list[4]; 5372 __u64 max_cpus; 5373 __u64 max_guests; 5374 __u64 max_guest_addr; 5375 __u64 feature_indication; 5376 }; 5377 5378 5379 KVM_PV_INFO_DUMP 5380 This subcommand provides information related to dumping PV guests. 5381 5382 :: 5383 5384 struct kvm_s390_pv_info_dump { 5385 __u64 dump_cpu_buffer_len; 5386 __u64 dump_config_mem_buffer_per_1m; 5387 __u64 dump_config_finalize_len; 5388 }; 5389 5390KVM_PV_DUMP 5391 :Capability: KVM_CAP_S390_PROTECTED_DUMP 5392 5393 Presents an API that provides calls which facilitate dumping a 5394 protected VM. 5395 5396 :: 5397 5398 struct kvm_s390_pv_dmp { 5399 __u64 subcmd; 5400 __u64 buff_addr; 5401 __u64 buff_len; 5402 __u64 gaddr; /* For dump storage state */ 5403 }; 5404 5405 **subcommands:** 5406 5407 KVM_PV_DUMP_INIT 5408 Initializes the dump process of a protected VM. If this call does 5409 not succeed all other subcommands will fail with -EINVAL. This 5410 subcommand will return -EINVAL if a dump process has not yet been 5411 completed. 5412 5413 Not all PV vms can be dumped, the owner needs to set `dump 5414 allowed` PCF bit 34 in the SE header to allow dumping. 5415 5416 KVM_PV_DUMP_CONFIG_STOR_STATE 5417 Stores `buff_len` bytes of tweak component values starting with 5418 the 1MB block specified by the absolute guest address 5419 (`gaddr`). `buff_len` needs to be `conf_dump_storage_state_len` 5420 aligned and at least >= the `conf_dump_storage_state_len` value 5421 provided by the dump uv_info data. buff_user might be written to 5422 even if an error rc is returned. For instance if we encounter a 5423 fault after writing the first page of data. 5424 5425 KVM_PV_DUMP_COMPLETE 5426 If the subcommand succeeds it completes the dump process and lets 5427 KVM_PV_DUMP_INIT be called again. 5428 5429 On success `conf_dump_finalize_len` bytes of completion data will be 5430 stored to the `buff_addr`. The completion data contains a key 5431 derivation seed, IV, tweak nonce and encryption keys as well as an 5432 authentication tag all of which are needed to decrypt the dump at a 5433 later time. 5434 5435KVM_PV_ASYNC_CLEANUP_PREPARE 5436 :Capability: KVM_CAP_S390_PROTECTED_ASYNC_DISABLE 5437 5438 Prepare the current protected VM for asynchronous teardown. Most 5439 resources used by the current protected VM will be set aside for a 5440 subsequent asynchronous teardown. The current protected VM will then 5441 resume execution immediately as non-protected. There can be at most 5442 one protected VM prepared for asynchronous teardown at any time. If 5443 a protected VM had already been prepared for teardown without 5444 subsequently calling KVM_PV_ASYNC_CLEANUP_PERFORM, this call will 5445 fail. In that case, the userspace process should issue a normal 5446 KVM_PV_DISABLE. The resources set aside with this call will need to 5447 be cleaned up with a subsequent call to KVM_PV_ASYNC_CLEANUP_PERFORM 5448 or KVM_PV_DISABLE, otherwise they will be cleaned up when KVM 5449 terminates. KVM_PV_ASYNC_CLEANUP_PREPARE can be called again as soon 5450 as cleanup starts, i.e. before KVM_PV_ASYNC_CLEANUP_PERFORM finishes. 5451 5452KVM_PV_ASYNC_CLEANUP_PERFORM 5453 :Capability: KVM_CAP_S390_PROTECTED_ASYNC_DISABLE 5454 5455 Tear down the protected VM previously prepared for teardown with 5456 KVM_PV_ASYNC_CLEANUP_PREPARE. The resources that had been set aside 5457 will be freed during the execution of this command. This PV command 5458 should ideally be issued by userspace from a separate thread. If a 5459 fatal signal is received (or the process terminates naturally), the 5460 command will terminate immediately without completing, and the normal 5461 KVM shutdown procedure will take care of cleaning up all remaining 5462 protected VMs, including the ones whose teardown was interrupted by 5463 process termination. 5464 54654.126 KVM_XEN_HVM_SET_ATTR 5466-------------------------- 5467 5468:Capability: KVM_CAP_XEN_HVM / KVM_XEN_HVM_CONFIG_SHARED_INFO 5469:Architectures: x86 5470:Type: vm ioctl 5471:Parameters: struct kvm_xen_hvm_attr 5472:Returns: 0 on success, < 0 on error 5473 5474:: 5475 5476 struct kvm_xen_hvm_attr { 5477 __u16 type; 5478 __u16 pad[3]; 5479 union { 5480 __u8 long_mode; 5481 __u8 vector; 5482 __u8 runstate_update_flag; 5483 struct { 5484 __u64 gfn; 5485 } shared_info; 5486 struct { 5487 __u32 send_port; 5488 __u32 type; /* EVTCHNSTAT_ipi / EVTCHNSTAT_interdomain */ 5489 __u32 flags; 5490 union { 5491 struct { 5492 __u32 port; 5493 __u32 vcpu; 5494 __u32 priority; 5495 } port; 5496 struct { 5497 __u32 port; /* Zero for eventfd */ 5498 __s32 fd; 5499 } eventfd; 5500 __u32 padding[4]; 5501 } deliver; 5502 } evtchn; 5503 __u32 xen_version; 5504 __u64 pad[8]; 5505 } u; 5506 }; 5507 5508type values: 5509 5510KVM_XEN_ATTR_TYPE_LONG_MODE 5511 Sets the ABI mode of the VM to 32-bit or 64-bit (long mode). This 5512 determines the layout of the shared info pages exposed to the VM. 5513 5514KVM_XEN_ATTR_TYPE_SHARED_INFO 5515 Sets the guest physical frame number at which the Xen "shared info" 5516 page resides. Note that although Xen places vcpu_info for the first 5517 32 vCPUs in the shared_info page, KVM does not automatically do so 5518 and instead requires that KVM_XEN_VCPU_ATTR_TYPE_VCPU_INFO be used 5519 explicitly even when the vcpu_info for a given vCPU resides at the 5520 "default" location in the shared_info page. This is because KVM may 5521 not be aware of the Xen CPU id which is used as the index into the 5522 vcpu_info[] array, so may know the correct default location. 5523 5524 Note that the shared info page may be constantly written to by KVM; 5525 it contains the event channel bitmap used to deliver interrupts to 5526 a Xen guest, amongst other things. It is exempt from dirty tracking 5527 mechanisms — KVM will not explicitly mark the page as dirty each 5528 time an event channel interrupt is delivered to the guest! Thus, 5529 userspace should always assume that the designated GFN is dirty if 5530 any vCPU has been running or any event channel interrupts can be 5531 routed to the guest. 5532 5533 Setting the gfn to KVM_XEN_INVALID_GFN will disable the shared info 5534 page. 5535 5536KVM_XEN_ATTR_TYPE_UPCALL_VECTOR 5537 Sets the exception vector used to deliver Xen event channel upcalls. 5538 This is the HVM-wide vector injected directly by the hypervisor 5539 (not through the local APIC), typically configured by a guest via 5540 HVM_PARAM_CALLBACK_IRQ. This can be disabled again (e.g. for guest 5541 SHUTDOWN_soft_reset) by setting it to zero. 5542 5543KVM_XEN_ATTR_TYPE_EVTCHN 5544 This attribute is available when the KVM_CAP_XEN_HVM ioctl indicates 5545 support for KVM_XEN_HVM_CONFIG_EVTCHN_SEND features. It configures 5546 an outbound port number for interception of EVTCHNOP_send requests 5547 from the guest. A given sending port number may be directed back to 5548 a specified vCPU (by APIC ID) / port / priority on the guest, or to 5549 trigger events on an eventfd. The vCPU and priority can be changed 5550 by setting KVM_XEN_EVTCHN_UPDATE in a subsequent call, but other 5551 fields cannot change for a given sending port. A port mapping is 5552 removed by using KVM_XEN_EVTCHN_DEASSIGN in the flags field. Passing 5553 KVM_XEN_EVTCHN_RESET in the flags field removes all interception of 5554 outbound event channels. The values of the flags field are mutually 5555 exclusive and cannot be combined as a bitmask. 5556 5557KVM_XEN_ATTR_TYPE_XEN_VERSION 5558 This attribute is available when the KVM_CAP_XEN_HVM ioctl indicates 5559 support for KVM_XEN_HVM_CONFIG_EVTCHN_SEND features. It configures 5560 the 32-bit version code returned to the guest when it invokes the 5561 XENVER_version call; typically (XEN_MAJOR << 16 | XEN_MINOR). PV 5562 Xen guests will often use this to as a dummy hypercall to trigger 5563 event channel delivery, so responding within the kernel without 5564 exiting to userspace is beneficial. 5565 5566KVM_XEN_ATTR_TYPE_RUNSTATE_UPDATE_FLAG 5567 This attribute is available when the KVM_CAP_XEN_HVM ioctl indicates 5568 support for KVM_XEN_HVM_CONFIG_RUNSTATE_UPDATE_FLAG. It enables the 5569 XEN_RUNSTATE_UPDATE flag which allows guest vCPUs to safely read 5570 other vCPUs' vcpu_runstate_info. Xen guests enable this feature via 5571 the VMASST_TYPE_runstate_update_flag of the HYPERVISOR_vm_assist 5572 hypercall. 5573 55744.127 KVM_XEN_HVM_GET_ATTR 5575-------------------------- 5576 5577:Capability: KVM_CAP_XEN_HVM / KVM_XEN_HVM_CONFIG_SHARED_INFO 5578:Architectures: x86 5579:Type: vm ioctl 5580:Parameters: struct kvm_xen_hvm_attr 5581:Returns: 0 on success, < 0 on error 5582 5583Allows Xen VM attributes to be read. For the structure and types, 5584see KVM_XEN_HVM_SET_ATTR above. The KVM_XEN_ATTR_TYPE_EVTCHN 5585attribute cannot be read. 5586 55874.128 KVM_XEN_VCPU_SET_ATTR 5588--------------------------- 5589 5590:Capability: KVM_CAP_XEN_HVM / KVM_XEN_HVM_CONFIG_SHARED_INFO 5591:Architectures: x86 5592:Type: vcpu ioctl 5593:Parameters: struct kvm_xen_vcpu_attr 5594:Returns: 0 on success, < 0 on error 5595 5596:: 5597 5598 struct kvm_xen_vcpu_attr { 5599 __u16 type; 5600 __u16 pad[3]; 5601 union { 5602 __u64 gpa; 5603 __u64 pad[4]; 5604 struct { 5605 __u64 state; 5606 __u64 state_entry_time; 5607 __u64 time_running; 5608 __u64 time_runnable; 5609 __u64 time_blocked; 5610 __u64 time_offline; 5611 } runstate; 5612 __u32 vcpu_id; 5613 struct { 5614 __u32 port; 5615 __u32 priority; 5616 __u64 expires_ns; 5617 } timer; 5618 __u8 vector; 5619 } u; 5620 }; 5621 5622type values: 5623 5624KVM_XEN_VCPU_ATTR_TYPE_VCPU_INFO 5625 Sets the guest physical address of the vcpu_info for a given vCPU. 5626 As with the shared_info page for the VM, the corresponding page may be 5627 dirtied at any time if event channel interrupt delivery is enabled, so 5628 userspace should always assume that the page is dirty without relying 5629 on dirty logging. Setting the gpa to KVM_XEN_INVALID_GPA will disable 5630 the vcpu_info. 5631 5632KVM_XEN_VCPU_ATTR_TYPE_VCPU_TIME_INFO 5633 Sets the guest physical address of an additional pvclock structure 5634 for a given vCPU. This is typically used for guest vsyscall support. 5635 Setting the gpa to KVM_XEN_INVALID_GPA will disable the structure. 5636 5637KVM_XEN_VCPU_ATTR_TYPE_RUNSTATE_ADDR 5638 Sets the guest physical address of the vcpu_runstate_info for a given 5639 vCPU. This is how a Xen guest tracks CPU state such as steal time. 5640 Setting the gpa to KVM_XEN_INVALID_GPA will disable the runstate area. 5641 5642KVM_XEN_VCPU_ATTR_TYPE_RUNSTATE_CURRENT 5643 Sets the runstate (RUNSTATE_running/_runnable/_blocked/_offline) of 5644 the given vCPU from the .u.runstate.state member of the structure. 5645 KVM automatically accounts running and runnable time but blocked 5646 and offline states are only entered explicitly. 5647 5648KVM_XEN_VCPU_ATTR_TYPE_RUNSTATE_DATA 5649 Sets all fields of the vCPU runstate data from the .u.runstate member 5650 of the structure, including the current runstate. The state_entry_time 5651 must equal the sum of the other four times. 5652 5653KVM_XEN_VCPU_ATTR_TYPE_RUNSTATE_ADJUST 5654 This *adds* the contents of the .u.runstate members of the structure 5655 to the corresponding members of the given vCPU's runstate data, thus 5656 permitting atomic adjustments to the runstate times. The adjustment 5657 to the state_entry_time must equal the sum of the adjustments to the 5658 other four times. The state field must be set to -1, or to a valid 5659 runstate value (RUNSTATE_running, RUNSTATE_runnable, RUNSTATE_blocked 5660 or RUNSTATE_offline) to set the current accounted state as of the 5661 adjusted state_entry_time. 5662 5663KVM_XEN_VCPU_ATTR_TYPE_VCPU_ID 5664 This attribute is available when the KVM_CAP_XEN_HVM ioctl indicates 5665 support for KVM_XEN_HVM_CONFIG_EVTCHN_SEND features. It sets the Xen 5666 vCPU ID of the given vCPU, to allow timer-related VCPU operations to 5667 be intercepted by KVM. 5668 5669KVM_XEN_VCPU_ATTR_TYPE_TIMER 5670 This attribute is available when the KVM_CAP_XEN_HVM ioctl indicates 5671 support for KVM_XEN_HVM_CONFIG_EVTCHN_SEND features. It sets the 5672 event channel port/priority for the VIRQ_TIMER of the vCPU, as well 5673 as allowing a pending timer to be saved/restored. Setting the timer 5674 port to zero disables kernel handling of the singleshot timer. 5675 5676KVM_XEN_VCPU_ATTR_TYPE_UPCALL_VECTOR 5677 This attribute is available when the KVM_CAP_XEN_HVM ioctl indicates 5678 support for KVM_XEN_HVM_CONFIG_EVTCHN_SEND features. It sets the 5679 per-vCPU local APIC upcall vector, configured by a Xen guest with 5680 the HVMOP_set_evtchn_upcall_vector hypercall. This is typically 5681 used by Windows guests, and is distinct from the HVM-wide upcall 5682 vector configured with HVM_PARAM_CALLBACK_IRQ. It is disabled by 5683 setting the vector to zero. 5684 5685 56864.129 KVM_XEN_VCPU_GET_ATTR 5687--------------------------- 5688 5689:Capability: KVM_CAP_XEN_HVM / KVM_XEN_HVM_CONFIG_SHARED_INFO 5690:Architectures: x86 5691:Type: vcpu ioctl 5692:Parameters: struct kvm_xen_vcpu_attr 5693:Returns: 0 on success, < 0 on error 5694 5695Allows Xen vCPU attributes to be read. For the structure and types, 5696see KVM_XEN_VCPU_SET_ATTR above. 5697 5698The KVM_XEN_VCPU_ATTR_TYPE_RUNSTATE_ADJUST type may not be used 5699with the KVM_XEN_VCPU_GET_ATTR ioctl. 5700 57014.130 KVM_ARM_MTE_COPY_TAGS 5702--------------------------- 5703 5704:Capability: KVM_CAP_ARM_MTE 5705:Architectures: arm64 5706:Type: vm ioctl 5707:Parameters: struct kvm_arm_copy_mte_tags 5708:Returns: number of bytes copied, < 0 on error (-EINVAL for incorrect 5709 arguments, -EFAULT if memory cannot be accessed). 5710 5711:: 5712 5713 struct kvm_arm_copy_mte_tags { 5714 __u64 guest_ipa; 5715 __u64 length; 5716 void __user *addr; 5717 __u64 flags; 5718 __u64 reserved[2]; 5719 }; 5720 5721Copies Memory Tagging Extension (MTE) tags to/from guest tag memory. The 5722``guest_ipa`` and ``length`` fields must be ``PAGE_SIZE`` aligned. 5723``length`` must not be bigger than 2^31 - PAGE_SIZE bytes. The ``addr`` 5724field must point to a buffer which the tags will be copied to or from. 5725 5726``flags`` specifies the direction of copy, either ``KVM_ARM_TAGS_TO_GUEST`` or 5727``KVM_ARM_TAGS_FROM_GUEST``. 5728 5729The size of the buffer to store the tags is ``(length / 16)`` bytes 5730(granules in MTE are 16 bytes long). Each byte contains a single tag 5731value. This matches the format of ``PTRACE_PEEKMTETAGS`` and 5732``PTRACE_POKEMTETAGS``. 5733 5734If an error occurs before any data is copied then a negative error code is 5735returned. If some tags have been copied before an error occurs then the number 5736of bytes successfully copied is returned. If the call completes successfully 5737then ``length`` is returned. 5738 57394.131 KVM_GET_SREGS2 5740-------------------- 5741 5742:Capability: KVM_CAP_SREGS2 5743:Architectures: x86 5744:Type: vcpu ioctl 5745:Parameters: struct kvm_sregs2 (out) 5746:Returns: 0 on success, -1 on error 5747 5748Reads special registers from the vcpu. 5749This ioctl (when supported) replaces the KVM_GET_SREGS. 5750 5751:: 5752 5753 struct kvm_sregs2 { 5754 /* out (KVM_GET_SREGS2) / in (KVM_SET_SREGS2) */ 5755 struct kvm_segment cs, ds, es, fs, gs, ss; 5756 struct kvm_segment tr, ldt; 5757 struct kvm_dtable gdt, idt; 5758 __u64 cr0, cr2, cr3, cr4, cr8; 5759 __u64 efer; 5760 __u64 apic_base; 5761 __u64 flags; 5762 __u64 pdptrs[4]; 5763 }; 5764 5765flags values for ``kvm_sregs2``: 5766 5767``KVM_SREGS2_FLAGS_PDPTRS_VALID`` 5768 5769 Indicates that the struct contains valid PDPTR values. 5770 5771 57724.132 KVM_SET_SREGS2 5773-------------------- 5774 5775:Capability: KVM_CAP_SREGS2 5776:Architectures: x86 5777:Type: vcpu ioctl 5778:Parameters: struct kvm_sregs2 (in) 5779:Returns: 0 on success, -1 on error 5780 5781Writes special registers into the vcpu. 5782See KVM_GET_SREGS2 for the data structures. 5783This ioctl (when supported) replaces the KVM_SET_SREGS. 5784 57854.133 KVM_GET_STATS_FD 5786---------------------- 5787 5788:Capability: KVM_CAP_STATS_BINARY_FD 5789:Architectures: all 5790:Type: vm ioctl, vcpu ioctl 5791:Parameters: none 5792:Returns: statistics file descriptor on success, < 0 on error 5793 5794Errors: 5795 5796 ====== ====================================================== 5797 ENOMEM if the fd could not be created due to lack of memory 5798 EMFILE if the number of opened files exceeds the limit 5799 ====== ====================================================== 5800 5801The returned file descriptor can be used to read VM/vCPU statistics data in 5802binary format. The data in the file descriptor consists of four blocks 5803organized as follows: 5804 5805+-------------+ 5806| Header | 5807+-------------+ 5808| id string | 5809+-------------+ 5810| Descriptors | 5811+-------------+ 5812| Stats Data | 5813+-------------+ 5814 5815Apart from the header starting at offset 0, please be aware that it is 5816not guaranteed that the four blocks are adjacent or in the above order; 5817the offsets of the id, descriptors and data blocks are found in the 5818header. However, all four blocks are aligned to 64 bit offsets in the 5819file and they do not overlap. 5820 5821All blocks except the data block are immutable. Userspace can read them 5822only one time after retrieving the file descriptor, and then use ``pread`` or 5823``lseek`` to read the statistics repeatedly. 5824 5825All data is in system endianness. 5826 5827The format of the header is as follows:: 5828 5829 struct kvm_stats_header { 5830 __u32 flags; 5831 __u32 name_size; 5832 __u32 num_desc; 5833 __u32 id_offset; 5834 __u32 desc_offset; 5835 __u32 data_offset; 5836 }; 5837 5838The ``flags`` field is not used at the moment. It is always read as 0. 5839 5840The ``name_size`` field is the size (in byte) of the statistics name string 5841(including trailing '\0') which is contained in the "id string" block and 5842appended at the end of every descriptor. 5843 5844The ``num_desc`` field is the number of descriptors that are included in the 5845descriptor block. (The actual number of values in the data block may be 5846larger, since each descriptor may comprise more than one value). 5847 5848The ``id_offset`` field is the offset of the id string from the start of the 5849file indicated by the file descriptor. It is a multiple of 8. 5850 5851The ``desc_offset`` field is the offset of the Descriptors block from the start 5852of the file indicated by the file descriptor. It is a multiple of 8. 5853 5854The ``data_offset`` field is the offset of the Stats Data block from the start 5855of the file indicated by the file descriptor. It is a multiple of 8. 5856 5857The id string block contains a string which identifies the file descriptor on 5858which KVM_GET_STATS_FD was invoked. The size of the block, including the 5859trailing ``'\0'``, is indicated by the ``name_size`` field in the header. 5860 5861The descriptors block is only needed to be read once for the lifetime of the 5862file descriptor contains a sequence of ``struct kvm_stats_desc``, each followed 5863by a string of size ``name_size``. 5864:: 5865 5866 #define KVM_STATS_TYPE_SHIFT 0 5867 #define KVM_STATS_TYPE_MASK (0xF << KVM_STATS_TYPE_SHIFT) 5868 #define KVM_STATS_TYPE_CUMULATIVE (0x0 << KVM_STATS_TYPE_SHIFT) 5869 #define KVM_STATS_TYPE_INSTANT (0x1 << KVM_STATS_TYPE_SHIFT) 5870 #define KVM_STATS_TYPE_PEAK (0x2 << KVM_STATS_TYPE_SHIFT) 5871 #define KVM_STATS_TYPE_LINEAR_HIST (0x3 << KVM_STATS_TYPE_SHIFT) 5872 #define KVM_STATS_TYPE_LOG_HIST (0x4 << KVM_STATS_TYPE_SHIFT) 5873 #define KVM_STATS_TYPE_MAX KVM_STATS_TYPE_LOG_HIST 5874 5875 #define KVM_STATS_UNIT_SHIFT 4 5876 #define KVM_STATS_UNIT_MASK (0xF << KVM_STATS_UNIT_SHIFT) 5877 #define KVM_STATS_UNIT_NONE (0x0 << KVM_STATS_UNIT_SHIFT) 5878 #define KVM_STATS_UNIT_BYTES (0x1 << KVM_STATS_UNIT_SHIFT) 5879 #define KVM_STATS_UNIT_SECONDS (0x2 << KVM_STATS_UNIT_SHIFT) 5880 #define KVM_STATS_UNIT_CYCLES (0x3 << KVM_STATS_UNIT_SHIFT) 5881 #define KVM_STATS_UNIT_BOOLEAN (0x4 << KVM_STATS_UNIT_SHIFT) 5882 #define KVM_STATS_UNIT_MAX KVM_STATS_UNIT_BOOLEAN 5883 5884 #define KVM_STATS_BASE_SHIFT 8 5885 #define KVM_STATS_BASE_MASK (0xF << KVM_STATS_BASE_SHIFT) 5886 #define KVM_STATS_BASE_POW10 (0x0 << KVM_STATS_BASE_SHIFT) 5887 #define KVM_STATS_BASE_POW2 (0x1 << KVM_STATS_BASE_SHIFT) 5888 #define KVM_STATS_BASE_MAX KVM_STATS_BASE_POW2 5889 5890 struct kvm_stats_desc { 5891 __u32 flags; 5892 __s16 exponent; 5893 __u16 size; 5894 __u32 offset; 5895 __u32 bucket_size; 5896 char name[]; 5897 }; 5898 5899The ``flags`` field contains the type and unit of the statistics data described 5900by this descriptor. Its endianness is CPU native. 5901The following flags are supported: 5902 5903Bits 0-3 of ``flags`` encode the type: 5904 5905 * ``KVM_STATS_TYPE_CUMULATIVE`` 5906 The statistics reports a cumulative count. The value of data can only be increased. 5907 Most of the counters used in KVM are of this type. 5908 The corresponding ``size`` field for this type is always 1. 5909 All cumulative statistics data are read/write. 5910 * ``KVM_STATS_TYPE_INSTANT`` 5911 The statistics reports an instantaneous value. Its value can be increased or 5912 decreased. This type is usually used as a measurement of some resources, 5913 like the number of dirty pages, the number of large pages, etc. 5914 All instant statistics are read only. 5915 The corresponding ``size`` field for this type is always 1. 5916 * ``KVM_STATS_TYPE_PEAK`` 5917 The statistics data reports a peak value, for example the maximum number 5918 of items in a hash table bucket, the longest time waited and so on. 5919 The value of data can only be increased. 5920 The corresponding ``size`` field for this type is always 1. 5921 * ``KVM_STATS_TYPE_LINEAR_HIST`` 5922 The statistic is reported as a linear histogram. The number of 5923 buckets is specified by the ``size`` field. The size of buckets is specified 5924 by the ``hist_param`` field. The range of the Nth bucket (1 <= N < ``size``) 5925 is [``hist_param``*(N-1), ``hist_param``*N), while the range of the last 5926 bucket is [``hist_param``*(``size``-1), +INF). (+INF means positive infinity 5927 value.) 5928 * ``KVM_STATS_TYPE_LOG_HIST`` 5929 The statistic is reported as a logarithmic histogram. The number of 5930 buckets is specified by the ``size`` field. The range of the first bucket is 5931 [0, 1), while the range of the last bucket is [pow(2, ``size``-2), +INF). 5932 Otherwise, The Nth bucket (1 < N < ``size``) covers 5933 [pow(2, N-2), pow(2, N-1)). 5934 5935Bits 4-7 of ``flags`` encode the unit: 5936 5937 * ``KVM_STATS_UNIT_NONE`` 5938 There is no unit for the value of statistics data. This usually means that 5939 the value is a simple counter of an event. 5940 * ``KVM_STATS_UNIT_BYTES`` 5941 It indicates that the statistics data is used to measure memory size, in the 5942 unit of Byte, KiByte, MiByte, GiByte, etc. The unit of the data is 5943 determined by the ``exponent`` field in the descriptor. 5944 * ``KVM_STATS_UNIT_SECONDS`` 5945 It indicates that the statistics data is used to measure time or latency. 5946 * ``KVM_STATS_UNIT_CYCLES`` 5947 It indicates that the statistics data is used to measure CPU clock cycles. 5948 * ``KVM_STATS_UNIT_BOOLEAN`` 5949 It indicates that the statistic will always be either 0 or 1. Boolean 5950 statistics of "peak" type will never go back from 1 to 0. Boolean 5951 statistics can be linear histograms (with two buckets) but not logarithmic 5952 histograms. 5953 5954Note that, in the case of histograms, the unit applies to the bucket 5955ranges, while the bucket value indicates how many samples fell in the 5956bucket's range. 5957 5958Bits 8-11 of ``flags``, together with ``exponent``, encode the scale of the 5959unit: 5960 5961 * ``KVM_STATS_BASE_POW10`` 5962 The scale is based on power of 10. It is used for measurement of time and 5963 CPU clock cycles. For example, an exponent of -9 can be used with 5964 ``KVM_STATS_UNIT_SECONDS`` to express that the unit is nanoseconds. 5965 * ``KVM_STATS_BASE_POW2`` 5966 The scale is based on power of 2. It is used for measurement of memory size. 5967 For example, an exponent of 20 can be used with ``KVM_STATS_UNIT_BYTES`` to 5968 express that the unit is MiB. 5969 5970The ``size`` field is the number of values of this statistics data. Its 5971value is usually 1 for most of simple statistics. 1 means it contains an 5972unsigned 64bit data. 5973 5974The ``offset`` field is the offset from the start of Data Block to the start of 5975the corresponding statistics data. 5976 5977The ``bucket_size`` field is used as a parameter for histogram statistics data. 5978It is only used by linear histogram statistics data, specifying the size of a 5979bucket in the unit expressed by bits 4-11 of ``flags`` together with ``exponent``. 5980 5981The ``name`` field is the name string of the statistics data. The name string 5982starts at the end of ``struct kvm_stats_desc``. The maximum length including 5983the trailing ``'\0'``, is indicated by ``name_size`` in the header. 5984 5985The Stats Data block contains an array of 64-bit values in the same order 5986as the descriptors in Descriptors block. 5987 59884.134 KVM_GET_XSAVE2 5989-------------------- 5990 5991:Capability: KVM_CAP_XSAVE2 5992:Architectures: x86 5993:Type: vcpu ioctl 5994:Parameters: struct kvm_xsave (out) 5995:Returns: 0 on success, -1 on error 5996 5997 5998:: 5999 6000 struct kvm_xsave { 6001 __u32 region[1024]; 6002 __u32 extra[0]; 6003 }; 6004 6005This ioctl would copy current vcpu's xsave struct to the userspace. It 6006copies as many bytes as are returned by KVM_CHECK_EXTENSION(KVM_CAP_XSAVE2) 6007when invoked on the vm file descriptor. The size value returned by 6008KVM_CHECK_EXTENSION(KVM_CAP_XSAVE2) will always be at least 4096. 6009Currently, it is only greater than 4096 if a dynamic feature has been 6010enabled with ``arch_prctl()``, but this may change in the future. 6011 6012The offsets of the state save areas in struct kvm_xsave follow the contents 6013of CPUID leaf 0xD on the host. 6014 60154.135 KVM_XEN_HVM_EVTCHN_SEND 6016----------------------------- 6017 6018:Capability: KVM_CAP_XEN_HVM / KVM_XEN_HVM_CONFIG_EVTCHN_SEND 6019:Architectures: x86 6020:Type: vm ioctl 6021:Parameters: struct kvm_irq_routing_xen_evtchn 6022:Returns: 0 on success, < 0 on error 6023 6024 6025:: 6026 6027 struct kvm_irq_routing_xen_evtchn { 6028 __u32 port; 6029 __u32 vcpu; 6030 __u32 priority; 6031 }; 6032 6033This ioctl injects an event channel interrupt directly to the guest vCPU. 6034 60354.136 KVM_S390_PV_CPU_COMMAND 6036----------------------------- 6037 6038:Capability: KVM_CAP_S390_PROTECTED_DUMP 6039:Architectures: s390 6040:Type: vcpu ioctl 6041:Parameters: none 6042:Returns: 0 on success, < 0 on error 6043 6044This ioctl closely mirrors `KVM_S390_PV_COMMAND` but handles requests 6045for vcpus. It re-uses the kvm_s390_pv_dmp struct and hence also shares 6046the command ids. 6047 6048**command:** 6049 6050KVM_PV_DUMP 6051 Presents an API that provides calls which facilitate dumping a vcpu 6052 of a protected VM. 6053 6054**subcommand:** 6055 6056KVM_PV_DUMP_CPU 6057 Provides encrypted dump data like register values. 6058 The length of the returned data is provided by uv_info.guest_cpu_stor_len. 6059 60604.137 KVM_S390_ZPCI_OP 6061---------------------- 6062 6063:Capability: KVM_CAP_S390_ZPCI_OP 6064:Architectures: s390 6065:Type: vm ioctl 6066:Parameters: struct kvm_s390_zpci_op (in) 6067:Returns: 0 on success, <0 on error 6068 6069Used to manage hardware-assisted virtualization features for zPCI devices. 6070 6071Parameters are specified via the following structure:: 6072 6073 struct kvm_s390_zpci_op { 6074 /* in */ 6075 __u32 fh; /* target device */ 6076 __u8 op; /* operation to perform */ 6077 __u8 pad[3]; 6078 union { 6079 /* for KVM_S390_ZPCIOP_REG_AEN */ 6080 struct { 6081 __u64 ibv; /* Guest addr of interrupt bit vector */ 6082 __u64 sb; /* Guest addr of summary bit */ 6083 __u32 flags; 6084 __u32 noi; /* Number of interrupts */ 6085 __u8 isc; /* Guest interrupt subclass */ 6086 __u8 sbo; /* Offset of guest summary bit vector */ 6087 __u16 pad; 6088 } reg_aen; 6089 __u64 reserved[8]; 6090 } u; 6091 }; 6092 6093The type of operation is specified in the "op" field. 6094KVM_S390_ZPCIOP_REG_AEN is used to register the VM for adapter event 6095notification interpretation, which will allow firmware delivery of adapter 6096events directly to the vm, with KVM providing a backup delivery mechanism; 6097KVM_S390_ZPCIOP_DEREG_AEN is used to subsequently disable interpretation of 6098adapter event notifications. 6099 6100The target zPCI function must also be specified via the "fh" field. For the 6101KVM_S390_ZPCIOP_REG_AEN operation, additional information to establish firmware 6102delivery must be provided via the "reg_aen" struct. 6103 6104The "pad" and "reserved" fields may be used for future extensions and should be 6105set to 0s by userspace. 6106 61074.138 KVM_ARM_SET_COUNTER_OFFSET 6108-------------------------------- 6109 6110:Capability: KVM_CAP_COUNTER_OFFSET 6111:Architectures: arm64 6112:Type: vm ioctl 6113:Parameters: struct kvm_arm_counter_offset (in) 6114:Returns: 0 on success, < 0 on error 6115 6116This capability indicates that userspace is able to apply a single VM-wide 6117offset to both the virtual and physical counters as viewed by the guest 6118using the KVM_ARM_SET_CNT_OFFSET ioctl and the following data structure: 6119 6120:: 6121 6122 struct kvm_arm_counter_offset { 6123 __u64 counter_offset; 6124 __u64 reserved; 6125 }; 6126 6127The offset describes a number of counter cycles that are subtracted from 6128both virtual and physical counter views (similar to the effects of the 6129CNTVOFF_EL2 and CNTPOFF_EL2 system registers, but only global). The offset 6130always applies to all vcpus (already created or created after this ioctl) 6131for this VM. 6132 6133It is userspace's responsibility to compute the offset based, for example, 6134on previous values of the guest counters. 6135 6136Any value other than 0 for the "reserved" field may result in an error 6137(-EINVAL) being returned. This ioctl can also return -EBUSY if any vcpu 6138ioctl is issued concurrently. 6139 6140Note that using this ioctl results in KVM ignoring subsequent userspace 6141writes to the CNTVCT_EL0 and CNTPCT_EL0 registers using the SET_ONE_REG 6142interface. No error will be returned, but the resulting offset will not be 6143applied. 6144 6145.. _KVM_ARM_GET_REG_WRITABLE_MASKS: 6146 61474.139 KVM_ARM_GET_REG_WRITABLE_MASKS 6148------------------------------------------- 6149 6150:Capability: KVM_CAP_ARM_SUPPORTED_REG_MASK_RANGES 6151:Architectures: arm64 6152:Type: vm ioctl 6153:Parameters: struct reg_mask_range (in/out) 6154:Returns: 0 on success, < 0 on error 6155 6156 6157:: 6158 6159 #define KVM_ARM_FEATURE_ID_RANGE 0 6160 #define KVM_ARM_FEATURE_ID_RANGE_SIZE (3 * 8 * 8) 6161 6162 struct reg_mask_range { 6163 __u64 addr; /* Pointer to mask array */ 6164 __u32 range; /* Requested range */ 6165 __u32 reserved[13]; 6166 }; 6167 6168This ioctl copies the writable masks for a selected range of registers to 6169userspace. 6170 6171The ``addr`` field is a pointer to the destination array where KVM copies 6172the writable masks. 6173 6174The ``range`` field indicates the requested range of registers. 6175``KVM_CHECK_EXTENSION`` for the ``KVM_CAP_ARM_SUPPORTED_REG_MASK_RANGES`` 6176capability returns the supported ranges, expressed as a set of flags. Each 6177flag's bit index represents a possible value for the ``range`` field. 6178All other values are reserved for future use and KVM may return an error. 6179 6180The ``reserved[13]`` array is reserved for future use and should be 0, or 6181KVM may return an error. 6182 6183KVM_ARM_FEATURE_ID_RANGE (0) 6184^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6185 6186The Feature ID range is defined as the AArch64 System register space with 6187op0==3, op1=={0, 1, 3}, CRn==0, CRm=={0-7}, op2=={0-7}. 6188 6189The mask returned array pointed to by ``addr`` is indexed by the macro 6190``ARM64_FEATURE_ID_RANGE_IDX(op0, op1, crn, crm, op2)``, allowing userspace 6191to know what fields can be changed for the system register described by 6192``op0, op1, crn, crm, op2``. KVM rejects ID register values that describe a 6193superset of the features supported by the system. 6194 61955. The kvm_run structure 6196======================== 6197 6198Application code obtains a pointer to the kvm_run structure by 6199mmap()ing a vcpu fd. From that point, application code can control 6200execution by changing fields in kvm_run prior to calling the KVM_RUN 6201ioctl, and obtain information about the reason KVM_RUN returned by 6202looking up structure members. 6203 6204:: 6205 6206 struct kvm_run { 6207 /* in */ 6208 __u8 request_interrupt_window; 6209 6210Request that KVM_RUN return when it becomes possible to inject external 6211interrupts into the guest. Useful in conjunction with KVM_INTERRUPT. 6212 6213:: 6214 6215 __u8 immediate_exit; 6216 6217This field is polled once when KVM_RUN starts; if non-zero, KVM_RUN 6218exits immediately, returning -EINTR. In the common scenario where a 6219signal is used to "kick" a VCPU out of KVM_RUN, this field can be used 6220to avoid usage of KVM_SET_SIGNAL_MASK, which has worse scalability. 6221Rather than blocking the signal outside KVM_RUN, userspace can set up 6222a signal handler that sets run->immediate_exit to a non-zero value. 6223 6224This field is ignored if KVM_CAP_IMMEDIATE_EXIT is not available. 6225 6226:: 6227 6228 __u8 padding1[6]; 6229 6230 /* out */ 6231 __u32 exit_reason; 6232 6233When KVM_RUN has returned successfully (return value 0), this informs 6234application code why KVM_RUN has returned. Allowable values for this 6235field are detailed below. 6236 6237:: 6238 6239 __u8 ready_for_interrupt_injection; 6240 6241If request_interrupt_window has been specified, this field indicates 6242an interrupt can be injected now with KVM_INTERRUPT. 6243 6244:: 6245 6246 __u8 if_flag; 6247 6248The value of the current interrupt flag. Only valid if in-kernel 6249local APIC is not used. 6250 6251:: 6252 6253 __u16 flags; 6254 6255More architecture-specific flags detailing state of the VCPU that may 6256affect the device's behavior. Current defined flags:: 6257 6258 /* x86, set if the VCPU is in system management mode */ 6259 #define KVM_RUN_X86_SMM (1 << 0) 6260 /* x86, set if bus lock detected in VM */ 6261 #define KVM_RUN_BUS_LOCK (1 << 1) 6262 /* arm64, set for KVM_EXIT_DEBUG */ 6263 #define KVM_DEBUG_ARCH_HSR_HIGH_VALID (1 << 0) 6264 6265:: 6266 6267 /* in (pre_kvm_run), out (post_kvm_run) */ 6268 __u64 cr8; 6269 6270The value of the cr8 register. Only valid if in-kernel local APIC is 6271not used. Both input and output. 6272 6273:: 6274 6275 __u64 apic_base; 6276 6277The value of the APIC BASE msr. Only valid if in-kernel local 6278APIC is not used. Both input and output. 6279 6280:: 6281 6282 union { 6283 /* KVM_EXIT_UNKNOWN */ 6284 struct { 6285 __u64 hardware_exit_reason; 6286 } hw; 6287 6288If exit_reason is KVM_EXIT_UNKNOWN, the vcpu has exited due to unknown 6289reasons. Further architecture-specific information is available in 6290hardware_exit_reason. 6291 6292:: 6293 6294 /* KVM_EXIT_FAIL_ENTRY */ 6295 struct { 6296 __u64 hardware_entry_failure_reason; 6297 __u32 cpu; /* if KVM_LAST_CPU */ 6298 } fail_entry; 6299 6300If exit_reason is KVM_EXIT_FAIL_ENTRY, the vcpu could not be run due 6301to unknown reasons. Further architecture-specific information is 6302available in hardware_entry_failure_reason. 6303 6304:: 6305 6306 /* KVM_EXIT_EXCEPTION */ 6307 struct { 6308 __u32 exception; 6309 __u32 error_code; 6310 } ex; 6311 6312Unused. 6313 6314:: 6315 6316 /* KVM_EXIT_IO */ 6317 struct { 6318 #define KVM_EXIT_IO_IN 0 6319 #define KVM_EXIT_IO_OUT 1 6320 __u8 direction; 6321 __u8 size; /* bytes */ 6322 __u16 port; 6323 __u32 count; 6324 __u64 data_offset; /* relative to kvm_run start */ 6325 } io; 6326 6327If exit_reason is KVM_EXIT_IO, then the vcpu has 6328executed a port I/O instruction which could not be satisfied by kvm. 6329data_offset describes where the data is located (KVM_EXIT_IO_OUT) or 6330where kvm expects application code to place the data for the next 6331KVM_RUN invocation (KVM_EXIT_IO_IN). Data format is a packed array. 6332 6333:: 6334 6335 /* KVM_EXIT_DEBUG */ 6336 struct { 6337 struct kvm_debug_exit_arch arch; 6338 } debug; 6339 6340If the exit_reason is KVM_EXIT_DEBUG, then a vcpu is processing a debug event 6341for which architecture specific information is returned. 6342 6343:: 6344 6345 /* KVM_EXIT_MMIO */ 6346 struct { 6347 __u64 phys_addr; 6348 __u8 data[8]; 6349 __u32 len; 6350 __u8 is_write; 6351 } mmio; 6352 6353If exit_reason is KVM_EXIT_MMIO, then the vcpu has 6354executed a memory-mapped I/O instruction which could not be satisfied 6355by kvm. The 'data' member contains the written data if 'is_write' is 6356true, and should be filled by application code otherwise. 6357 6358The 'data' member contains, in its first 'len' bytes, the value as it would 6359appear if the VCPU performed a load or store of the appropriate width directly 6360to the byte array. 6361 6362.. note:: 6363 6364 For KVM_EXIT_IO, KVM_EXIT_MMIO, KVM_EXIT_OSI, KVM_EXIT_PAPR, KVM_EXIT_XEN, 6365 KVM_EXIT_EPR, KVM_EXIT_X86_RDMSR and KVM_EXIT_X86_WRMSR the corresponding 6366 operations are complete (and guest state is consistent) only after userspace 6367 has re-entered the kernel with KVM_RUN. The kernel side will first finish 6368 incomplete operations and then check for pending signals. 6369 6370 The pending state of the operation is not preserved in state which is 6371 visible to userspace, thus userspace should ensure that the operation is 6372 completed before performing a live migration. Userspace can re-enter the 6373 guest with an unmasked signal pending or with the immediate_exit field set 6374 to complete pending operations without allowing any further instructions 6375 to be executed. 6376 6377:: 6378 6379 /* KVM_EXIT_HYPERCALL */ 6380 struct { 6381 __u64 nr; 6382 __u64 args[6]; 6383 __u64 ret; 6384 __u64 flags; 6385 } hypercall; 6386 6387 6388It is strongly recommended that userspace use ``KVM_EXIT_IO`` (x86) or 6389``KVM_EXIT_MMIO`` (all except s390) to implement functionality that 6390requires a guest to interact with host userspace. 6391 6392.. note:: KVM_EXIT_IO is significantly faster than KVM_EXIT_MMIO. 6393 6394For arm64: 6395---------- 6396 6397SMCCC exits can be enabled depending on the configuration of the SMCCC 6398filter. See the Documentation/virt/kvm/devices/vm.rst 6399``KVM_ARM_SMCCC_FILTER`` for more details. 6400 6401``nr`` contains the function ID of the guest's SMCCC call. Userspace is 6402expected to use the ``KVM_GET_ONE_REG`` ioctl to retrieve the call 6403parameters from the vCPU's GPRs. 6404 6405Definition of ``flags``: 6406 - ``KVM_HYPERCALL_EXIT_SMC``: Indicates that the guest used the SMC 6407 conduit to initiate the SMCCC call. If this bit is 0 then the guest 6408 used the HVC conduit for the SMCCC call. 6409 6410 - ``KVM_HYPERCALL_EXIT_16BIT``: Indicates that the guest used a 16bit 6411 instruction to initiate the SMCCC call. If this bit is 0 then the 6412 guest used a 32bit instruction. An AArch64 guest always has this 6413 bit set to 0. 6414 6415At the point of exit, PC points to the instruction immediately following 6416the trapping instruction. 6417 6418:: 6419 6420 /* KVM_EXIT_TPR_ACCESS */ 6421 struct { 6422 __u64 rip; 6423 __u32 is_write; 6424 __u32 pad; 6425 } tpr_access; 6426 6427To be documented (KVM_TPR_ACCESS_REPORTING). 6428 6429:: 6430 6431 /* KVM_EXIT_S390_SIEIC */ 6432 struct { 6433 __u8 icptcode; 6434 __u64 mask; /* psw upper half */ 6435 __u64 addr; /* psw lower half */ 6436 __u16 ipa; 6437 __u32 ipb; 6438 } s390_sieic; 6439 6440s390 specific. 6441 6442:: 6443 6444 /* KVM_EXIT_S390_RESET */ 6445 #define KVM_S390_RESET_POR 1 6446 #define KVM_S390_RESET_CLEAR 2 6447 #define KVM_S390_RESET_SUBSYSTEM 4 6448 #define KVM_S390_RESET_CPU_INIT 8 6449 #define KVM_S390_RESET_IPL 16 6450 __u64 s390_reset_flags; 6451 6452s390 specific. 6453 6454:: 6455 6456 /* KVM_EXIT_S390_UCONTROL */ 6457 struct { 6458 __u64 trans_exc_code; 6459 __u32 pgm_code; 6460 } s390_ucontrol; 6461 6462s390 specific. A page fault has occurred for a user controlled virtual 6463machine (KVM_VM_S390_UNCONTROL) on its host page table that cannot be 6464resolved by the kernel. 6465The program code and the translation exception code that were placed 6466in the cpu's lowcore are presented here as defined by the z Architecture 6467Principles of Operation Book in the Chapter for Dynamic Address Translation 6468(DAT) 6469 6470:: 6471 6472 /* KVM_EXIT_DCR */ 6473 struct { 6474 __u32 dcrn; 6475 __u32 data; 6476 __u8 is_write; 6477 } dcr; 6478 6479Deprecated - was used for 440 KVM. 6480 6481:: 6482 6483 /* KVM_EXIT_OSI */ 6484 struct { 6485 __u64 gprs[32]; 6486 } osi; 6487 6488MOL uses a special hypercall interface it calls 'OSI'. To enable it, we catch 6489hypercalls and exit with this exit struct that contains all the guest gprs. 6490 6491If exit_reason is KVM_EXIT_OSI, then the vcpu has triggered such a hypercall. 6492Userspace can now handle the hypercall and when it's done modify the gprs as 6493necessary. Upon guest entry all guest GPRs will then be replaced by the values 6494in this struct. 6495 6496:: 6497 6498 /* KVM_EXIT_PAPR_HCALL */ 6499 struct { 6500 __u64 nr; 6501 __u64 ret; 6502 __u64 args[9]; 6503 } papr_hcall; 6504 6505This is used on 64-bit PowerPC when emulating a pSeries partition, 6506e.g. with the 'pseries' machine type in qemu. It occurs when the 6507guest does a hypercall using the 'sc 1' instruction. The 'nr' field 6508contains the hypercall number (from the guest R3), and 'args' contains 6509the arguments (from the guest R4 - R12). Userspace should put the 6510return code in 'ret' and any extra returned values in args[]. 6511The possible hypercalls are defined in the Power Architecture Platform 6512Requirements (PAPR) document available from www.power.org (free 6513developer registration required to access it). 6514 6515:: 6516 6517 /* KVM_EXIT_S390_TSCH */ 6518 struct { 6519 __u16 subchannel_id; 6520 __u16 subchannel_nr; 6521 __u32 io_int_parm; 6522 __u32 io_int_word; 6523 __u32 ipb; 6524 __u8 dequeued; 6525 } s390_tsch; 6526 6527s390 specific. This exit occurs when KVM_CAP_S390_CSS_SUPPORT has been enabled 6528and TEST SUBCHANNEL was intercepted. If dequeued is set, a pending I/O 6529interrupt for the target subchannel has been dequeued and subchannel_id, 6530subchannel_nr, io_int_parm and io_int_word contain the parameters for that 6531interrupt. ipb is needed for instruction parameter decoding. 6532 6533:: 6534 6535 /* KVM_EXIT_EPR */ 6536 struct { 6537 __u32 epr; 6538 } epr; 6539 6540On FSL BookE PowerPC chips, the interrupt controller has a fast patch 6541interrupt acknowledge path to the core. When the core successfully 6542delivers an interrupt, it automatically populates the EPR register with 6543the interrupt vector number and acknowledges the interrupt inside 6544the interrupt controller. 6545 6546In case the interrupt controller lives in user space, we need to do 6547the interrupt acknowledge cycle through it to fetch the next to be 6548delivered interrupt vector using this exit. 6549 6550It gets triggered whenever both KVM_CAP_PPC_EPR are enabled and an 6551external interrupt has just been delivered into the guest. User space 6552should put the acknowledged interrupt vector into the 'epr' field. 6553 6554:: 6555 6556 /* KVM_EXIT_SYSTEM_EVENT */ 6557 struct { 6558 #define KVM_SYSTEM_EVENT_SHUTDOWN 1 6559 #define KVM_SYSTEM_EVENT_RESET 2 6560 #define KVM_SYSTEM_EVENT_CRASH 3 6561 #define KVM_SYSTEM_EVENT_WAKEUP 4 6562 #define KVM_SYSTEM_EVENT_SUSPEND 5 6563 #define KVM_SYSTEM_EVENT_SEV_TERM 6 6564 __u32 type; 6565 __u32 ndata; 6566 __u64 data[16]; 6567 } system_event; 6568 6569If exit_reason is KVM_EXIT_SYSTEM_EVENT then the vcpu has triggered 6570a system-level event using some architecture specific mechanism (hypercall 6571or some special instruction). In case of ARM64, this is triggered using 6572HVC instruction based PSCI call from the vcpu. 6573 6574The 'type' field describes the system-level event type. 6575Valid values for 'type' are: 6576 6577 - KVM_SYSTEM_EVENT_SHUTDOWN -- the guest has requested a shutdown of the 6578 VM. Userspace is not obliged to honour this, and if it does honour 6579 this does not need to destroy the VM synchronously (ie it may call 6580 KVM_RUN again before shutdown finally occurs). 6581 - KVM_SYSTEM_EVENT_RESET -- the guest has requested a reset of the VM. 6582 As with SHUTDOWN, userspace can choose to ignore the request, or 6583 to schedule the reset to occur in the future and may call KVM_RUN again. 6584 - KVM_SYSTEM_EVENT_CRASH -- the guest crash occurred and the guest 6585 has requested a crash condition maintenance. Userspace can choose 6586 to ignore the request, or to gather VM memory core dump and/or 6587 reset/shutdown of the VM. 6588 - KVM_SYSTEM_EVENT_SEV_TERM -- an AMD SEV guest requested termination. 6589 The guest physical address of the guest's GHCB is stored in `data[0]`. 6590 - KVM_SYSTEM_EVENT_WAKEUP -- the exiting vCPU is in a suspended state and 6591 KVM has recognized a wakeup event. Userspace may honor this event by 6592 marking the exiting vCPU as runnable, or deny it and call KVM_RUN again. 6593 - KVM_SYSTEM_EVENT_SUSPEND -- the guest has requested a suspension of 6594 the VM. 6595 6596If KVM_CAP_SYSTEM_EVENT_DATA is present, the 'data' field can contain 6597architecture specific information for the system-level event. Only 6598the first `ndata` items (possibly zero) of the data array are valid. 6599 6600 - for arm64, data[0] is set to KVM_SYSTEM_EVENT_RESET_FLAG_PSCI_RESET2 if 6601 the guest issued a SYSTEM_RESET2 call according to v1.1 of the PSCI 6602 specification. 6603 6604 - for RISC-V, data[0] is set to the value of the second argument of the 6605 ``sbi_system_reset`` call. 6606 6607Previous versions of Linux defined a `flags` member in this struct. The 6608field is now aliased to `data[0]`. Userspace can assume that it is only 6609written if ndata is greater than 0. 6610 6611For arm/arm64: 6612-------------- 6613 6614KVM_SYSTEM_EVENT_SUSPEND exits are enabled with the 6615KVM_CAP_ARM_SYSTEM_SUSPEND VM capability. If a guest invokes the PSCI 6616SYSTEM_SUSPEND function, KVM will exit to userspace with this event 6617type. 6618 6619It is the sole responsibility of userspace to implement the PSCI 6620SYSTEM_SUSPEND call according to ARM DEN0022D.b 5.19 "SYSTEM_SUSPEND". 6621KVM does not change the vCPU's state before exiting to userspace, so 6622the call parameters are left in-place in the vCPU registers. 6623 6624Userspace is _required_ to take action for such an exit. It must 6625either: 6626 6627 - Honor the guest request to suspend the VM. Userspace can request 6628 in-kernel emulation of suspension by setting the calling vCPU's 6629 state to KVM_MP_STATE_SUSPENDED. Userspace must configure the vCPU's 6630 state according to the parameters passed to the PSCI function when 6631 the calling vCPU is resumed. See ARM DEN0022D.b 5.19.1 "Intended use" 6632 for details on the function parameters. 6633 6634 - Deny the guest request to suspend the VM. See ARM DEN0022D.b 5.19.2 6635 "Caller responsibilities" for possible return values. 6636 6637:: 6638 6639 /* KVM_EXIT_IOAPIC_EOI */ 6640 struct { 6641 __u8 vector; 6642 } eoi; 6643 6644Indicates that the VCPU's in-kernel local APIC received an EOI for a 6645level-triggered IOAPIC interrupt. This exit only triggers when the 6646IOAPIC is implemented in userspace (i.e. KVM_CAP_SPLIT_IRQCHIP is enabled); 6647the userspace IOAPIC should process the EOI and retrigger the interrupt if 6648it is still asserted. Vector is the LAPIC interrupt vector for which the 6649EOI was received. 6650 6651:: 6652 6653 struct kvm_hyperv_exit { 6654 #define KVM_EXIT_HYPERV_SYNIC 1 6655 #define KVM_EXIT_HYPERV_HCALL 2 6656 #define KVM_EXIT_HYPERV_SYNDBG 3 6657 __u32 type; 6658 __u32 pad1; 6659 union { 6660 struct { 6661 __u32 msr; 6662 __u32 pad2; 6663 __u64 control; 6664 __u64 evt_page; 6665 __u64 msg_page; 6666 } synic; 6667 struct { 6668 __u64 input; 6669 __u64 result; 6670 __u64 params[2]; 6671 } hcall; 6672 struct { 6673 __u32 msr; 6674 __u32 pad2; 6675 __u64 control; 6676 __u64 status; 6677 __u64 send_page; 6678 __u64 recv_page; 6679 __u64 pending_page; 6680 } syndbg; 6681 } u; 6682 }; 6683 /* KVM_EXIT_HYPERV */ 6684 struct kvm_hyperv_exit hyperv; 6685 6686Indicates that the VCPU exits into userspace to process some tasks 6687related to Hyper-V emulation. 6688 6689Valid values for 'type' are: 6690 6691 - KVM_EXIT_HYPERV_SYNIC -- synchronously notify user-space about 6692 6693Hyper-V SynIC state change. Notification is used to remap SynIC 6694event/message pages and to enable/disable SynIC messages/events processing 6695in userspace. 6696 6697 - KVM_EXIT_HYPERV_SYNDBG -- synchronously notify user-space about 6698 6699Hyper-V Synthetic debugger state change. Notification is used to either update 6700the pending_page location or to send a control command (send the buffer located 6701in send_page or recv a buffer to recv_page). 6702 6703:: 6704 6705 /* KVM_EXIT_ARM_NISV */ 6706 struct { 6707 __u64 esr_iss; 6708 __u64 fault_ipa; 6709 } arm_nisv; 6710 6711Used on arm64 systems. If a guest accesses memory not in a memslot, 6712KVM will typically return to userspace and ask it to do MMIO emulation on its 6713behalf. However, for certain classes of instructions, no instruction decode 6714(direction, length of memory access) is provided, and fetching and decoding 6715the instruction from the VM is overly complicated to live in the kernel. 6716 6717Historically, when this situation occurred, KVM would print a warning and kill 6718the VM. KVM assumed that if the guest accessed non-memslot memory, it was 6719trying to do I/O, which just couldn't be emulated, and the warning message was 6720phrased accordingly. However, what happened more often was that a guest bug 6721caused access outside the guest memory areas which should lead to a more 6722meaningful warning message and an external abort in the guest, if the access 6723did not fall within an I/O window. 6724 6725Userspace implementations can query for KVM_CAP_ARM_NISV_TO_USER, and enable 6726this capability at VM creation. Once this is done, these types of errors will 6727instead return to userspace with KVM_EXIT_ARM_NISV, with the valid bits from 6728the ESR_EL2 in the esr_iss field, and the faulting IPA in the fault_ipa field. 6729Userspace can either fix up the access if it's actually an I/O access by 6730decoding the instruction from guest memory (if it's very brave) and continue 6731executing the guest, or it can decide to suspend, dump, or restart the guest. 6732 6733Note that KVM does not skip the faulting instruction as it does for 6734KVM_EXIT_MMIO, but userspace has to emulate any change to the processing state 6735if it decides to decode and emulate the instruction. 6736 6737:: 6738 6739 /* KVM_EXIT_X86_RDMSR / KVM_EXIT_X86_WRMSR */ 6740 struct { 6741 __u8 error; /* user -> kernel */ 6742 __u8 pad[7]; 6743 __u32 reason; /* kernel -> user */ 6744 __u32 index; /* kernel -> user */ 6745 __u64 data; /* kernel <-> user */ 6746 } msr; 6747 6748Used on x86 systems. When the VM capability KVM_CAP_X86_USER_SPACE_MSR is 6749enabled, MSR accesses to registers that would invoke a #GP by KVM kernel code 6750may instead trigger a KVM_EXIT_X86_RDMSR exit for reads and KVM_EXIT_X86_WRMSR 6751exit for writes. 6752 6753The "reason" field specifies why the MSR interception occurred. Userspace will 6754only receive MSR exits when a particular reason was requested during through 6755ENABLE_CAP. Currently valid exit reasons are: 6756 6757============================ ======================================== 6758 KVM_MSR_EXIT_REASON_UNKNOWN access to MSR that is unknown to KVM 6759 KVM_MSR_EXIT_REASON_INVAL access to invalid MSRs or reserved bits 6760 KVM_MSR_EXIT_REASON_FILTER access blocked by KVM_X86_SET_MSR_FILTER 6761============================ ======================================== 6762 6763For KVM_EXIT_X86_RDMSR, the "index" field tells userspace which MSR the guest 6764wants to read. To respond to this request with a successful read, userspace 6765writes the respective data into the "data" field and must continue guest 6766execution to ensure the read data is transferred into guest register state. 6767 6768If the RDMSR request was unsuccessful, userspace indicates that with a "1" in 6769the "error" field. This will inject a #GP into the guest when the VCPU is 6770executed again. 6771 6772For KVM_EXIT_X86_WRMSR, the "index" field tells userspace which MSR the guest 6773wants to write. Once finished processing the event, userspace must continue 6774vCPU execution. If the MSR write was unsuccessful, userspace also sets the 6775"error" field to "1". 6776 6777See KVM_X86_SET_MSR_FILTER for details on the interaction with MSR filtering. 6778 6779:: 6780 6781 6782 struct kvm_xen_exit { 6783 #define KVM_EXIT_XEN_HCALL 1 6784 __u32 type; 6785 union { 6786 struct { 6787 __u32 longmode; 6788 __u32 cpl; 6789 __u64 input; 6790 __u64 result; 6791 __u64 params[6]; 6792 } hcall; 6793 } u; 6794 }; 6795 /* KVM_EXIT_XEN */ 6796 struct kvm_hyperv_exit xen; 6797 6798Indicates that the VCPU exits into userspace to process some tasks 6799related to Xen emulation. 6800 6801Valid values for 'type' are: 6802 6803 - KVM_EXIT_XEN_HCALL -- synchronously notify user-space about Xen hypercall. 6804 Userspace is expected to place the hypercall result into the appropriate 6805 field before invoking KVM_RUN again. 6806 6807:: 6808 6809 /* KVM_EXIT_RISCV_SBI */ 6810 struct { 6811 unsigned long extension_id; 6812 unsigned long function_id; 6813 unsigned long args[6]; 6814 unsigned long ret[2]; 6815 } riscv_sbi; 6816 6817If exit reason is KVM_EXIT_RISCV_SBI then it indicates that the VCPU has 6818done a SBI call which is not handled by KVM RISC-V kernel module. The details 6819of the SBI call are available in 'riscv_sbi' member of kvm_run structure. The 6820'extension_id' field of 'riscv_sbi' represents SBI extension ID whereas the 6821'function_id' field represents function ID of given SBI extension. The 'args' 6822array field of 'riscv_sbi' represents parameters for the SBI call and 'ret' 6823array field represents return values. The userspace should update the return 6824values of SBI call before resuming the VCPU. For more details on RISC-V SBI 6825spec refer, https://github.com/riscv/riscv-sbi-doc. 6826 6827:: 6828 6829 /* KVM_EXIT_NOTIFY */ 6830 struct { 6831 #define KVM_NOTIFY_CONTEXT_INVALID (1 << 0) 6832 __u32 flags; 6833 } notify; 6834 6835Used on x86 systems. When the VM capability KVM_CAP_X86_NOTIFY_VMEXIT is 6836enabled, a VM exit generated if no event window occurs in VM non-root mode 6837for a specified amount of time. Once KVM_X86_NOTIFY_VMEXIT_USER is set when 6838enabling the cap, it would exit to userspace with the exit reason 6839KVM_EXIT_NOTIFY for further handling. The "flags" field contains more 6840detailed info. 6841 6842The valid value for 'flags' is: 6843 6844 - KVM_NOTIFY_CONTEXT_INVALID -- the VM context is corrupted and not valid 6845 in VMCS. It would run into unknown result if resume the target VM. 6846 6847:: 6848 6849 /* Fix the size of the union. */ 6850 char padding[256]; 6851 }; 6852 6853 /* 6854 * shared registers between kvm and userspace. 6855 * kvm_valid_regs specifies the register classes set by the host 6856 * kvm_dirty_regs specified the register classes dirtied by userspace 6857 * struct kvm_sync_regs is architecture specific, as well as the 6858 * bits for kvm_valid_regs and kvm_dirty_regs 6859 */ 6860 __u64 kvm_valid_regs; 6861 __u64 kvm_dirty_regs; 6862 union { 6863 struct kvm_sync_regs regs; 6864 char padding[SYNC_REGS_SIZE_BYTES]; 6865 } s; 6866 6867If KVM_CAP_SYNC_REGS is defined, these fields allow userspace to access 6868certain guest registers without having to call SET/GET_*REGS. Thus we can 6869avoid some system call overhead if userspace has to handle the exit. 6870Userspace can query the validity of the structure by checking 6871kvm_valid_regs for specific bits. These bits are architecture specific 6872and usually define the validity of a groups of registers. (e.g. one bit 6873for general purpose registers) 6874 6875Please note that the kernel is allowed to use the kvm_run structure as the 6876primary storage for certain register types. Therefore, the kernel may use the 6877values in kvm_run even if the corresponding bit in kvm_dirty_regs is not set. 6878 6879 68806. Capabilities that can be enabled on vCPUs 6881============================================ 6882 6883There are certain capabilities that change the behavior of the virtual CPU or 6884the virtual machine when enabled. To enable them, please see section 4.37. 6885Below you can find a list of capabilities and what their effect on the vCPU or 6886the virtual machine is when enabling them. 6887 6888The following information is provided along with the description: 6889 6890 Architectures: 6891 which instruction set architectures provide this ioctl. 6892 x86 includes both i386 and x86_64. 6893 6894 Target: 6895 whether this is a per-vcpu or per-vm capability. 6896 6897 Parameters: 6898 what parameters are accepted by the capability. 6899 6900 Returns: 6901 the return value. General error numbers (EBADF, ENOMEM, EINVAL) 6902 are not detailed, but errors with specific meanings are. 6903 6904 69056.1 KVM_CAP_PPC_OSI 6906------------------- 6907 6908:Architectures: ppc 6909:Target: vcpu 6910:Parameters: none 6911:Returns: 0 on success; -1 on error 6912 6913This capability enables interception of OSI hypercalls that otherwise would 6914be treated as normal system calls to be injected into the guest. OSI hypercalls 6915were invented by Mac-on-Linux to have a standardized communication mechanism 6916between the guest and the host. 6917 6918When this capability is enabled, KVM_EXIT_OSI can occur. 6919 6920 69216.2 KVM_CAP_PPC_PAPR 6922-------------------- 6923 6924:Architectures: ppc 6925:Target: vcpu 6926:Parameters: none 6927:Returns: 0 on success; -1 on error 6928 6929This capability enables interception of PAPR hypercalls. PAPR hypercalls are 6930done using the hypercall instruction "sc 1". 6931 6932It also sets the guest privilege level to "supervisor" mode. Usually the guest 6933runs in "hypervisor" privilege mode with a few missing features. 6934 6935In addition to the above, it changes the semantics of SDR1. In this mode, the 6936HTAB address part of SDR1 contains an HVA instead of a GPA, as PAPR keeps the 6937HTAB invisible to the guest. 6938 6939When this capability is enabled, KVM_EXIT_PAPR_HCALL can occur. 6940 6941 69426.3 KVM_CAP_SW_TLB 6943------------------ 6944 6945:Architectures: ppc 6946:Target: vcpu 6947:Parameters: args[0] is the address of a struct kvm_config_tlb 6948:Returns: 0 on success; -1 on error 6949 6950:: 6951 6952 struct kvm_config_tlb { 6953 __u64 params; 6954 __u64 array; 6955 __u32 mmu_type; 6956 __u32 array_len; 6957 }; 6958 6959Configures the virtual CPU's TLB array, establishing a shared memory area 6960between userspace and KVM. The "params" and "array" fields are userspace 6961addresses of mmu-type-specific data structures. The "array_len" field is an 6962safety mechanism, and should be set to the size in bytes of the memory that 6963userspace has reserved for the array. It must be at least the size dictated 6964by "mmu_type" and "params". 6965 6966While KVM_RUN is active, the shared region is under control of KVM. Its 6967contents are undefined, and any modification by userspace results in 6968boundedly undefined behavior. 6969 6970On return from KVM_RUN, the shared region will reflect the current state of 6971the guest's TLB. If userspace makes any changes, it must call KVM_DIRTY_TLB 6972to tell KVM which entries have been changed, prior to calling KVM_RUN again 6973on this vcpu. 6974 6975For mmu types KVM_MMU_FSL_BOOKE_NOHV and KVM_MMU_FSL_BOOKE_HV: 6976 6977 - The "params" field is of type "struct kvm_book3e_206_tlb_params". 6978 - The "array" field points to an array of type "struct 6979 kvm_book3e_206_tlb_entry". 6980 - The array consists of all entries in the first TLB, followed by all 6981 entries in the second TLB. 6982 - Within a TLB, entries are ordered first by increasing set number. Within a 6983 set, entries are ordered by way (increasing ESEL). 6984 - The hash for determining set number in TLB0 is: (MAS2 >> 12) & (num_sets - 1) 6985 where "num_sets" is the tlb_sizes[] value divided by the tlb_ways[] value. 6986 - The tsize field of mas1 shall be set to 4K on TLB0, even though the 6987 hardware ignores this value for TLB0. 6988 69896.4 KVM_CAP_S390_CSS_SUPPORT 6990---------------------------- 6991 6992:Architectures: s390 6993:Target: vcpu 6994:Parameters: none 6995:Returns: 0 on success; -1 on error 6996 6997This capability enables support for handling of channel I/O instructions. 6998 6999TEST PENDING INTERRUPTION and the interrupt portion of TEST SUBCHANNEL are 7000handled in-kernel, while the other I/O instructions are passed to userspace. 7001 7002When this capability is enabled, KVM_EXIT_S390_TSCH will occur on TEST 7003SUBCHANNEL intercepts. 7004 7005Note that even though this capability is enabled per-vcpu, the complete 7006virtual machine is affected. 7007 70086.5 KVM_CAP_PPC_EPR 7009------------------- 7010 7011:Architectures: ppc 7012:Target: vcpu 7013:Parameters: args[0] defines whether the proxy facility is active 7014:Returns: 0 on success; -1 on error 7015 7016This capability enables or disables the delivery of interrupts through the 7017external proxy facility. 7018 7019When enabled (args[0] != 0), every time the guest gets an external interrupt 7020delivered, it automatically exits into user space with a KVM_EXIT_EPR exit 7021to receive the topmost interrupt vector. 7022 7023When disabled (args[0] == 0), behavior is as if this facility is unsupported. 7024 7025When this capability is enabled, KVM_EXIT_EPR can occur. 7026 70276.6 KVM_CAP_IRQ_MPIC 7028-------------------- 7029 7030:Architectures: ppc 7031:Parameters: args[0] is the MPIC device fd; 7032 args[1] is the MPIC CPU number for this vcpu 7033 7034This capability connects the vcpu to an in-kernel MPIC device. 7035 70366.7 KVM_CAP_IRQ_XICS 7037-------------------- 7038 7039:Architectures: ppc 7040:Target: vcpu 7041:Parameters: args[0] is the XICS device fd; 7042 args[1] is the XICS CPU number (server ID) for this vcpu 7043 7044This capability connects the vcpu to an in-kernel XICS device. 7045 70466.8 KVM_CAP_S390_IRQCHIP 7047------------------------ 7048 7049:Architectures: s390 7050:Target: vm 7051:Parameters: none 7052 7053This capability enables the in-kernel irqchip for s390. Please refer to 7054"4.24 KVM_CREATE_IRQCHIP" for details. 7055 70566.9 KVM_CAP_MIPS_FPU 7057-------------------- 7058 7059:Architectures: mips 7060:Target: vcpu 7061:Parameters: args[0] is reserved for future use (should be 0). 7062 7063This capability allows the use of the host Floating Point Unit by the guest. It 7064allows the Config1.FP bit to be set to enable the FPU in the guest. Once this is 7065done the ``KVM_REG_MIPS_FPR_*`` and ``KVM_REG_MIPS_FCR_*`` registers can be 7066accessed (depending on the current guest FPU register mode), and the Status.FR, 7067Config5.FRE bits are accessible via the KVM API and also from the guest, 7068depending on them being supported by the FPU. 7069 70706.10 KVM_CAP_MIPS_MSA 7071--------------------- 7072 7073:Architectures: mips 7074:Target: vcpu 7075:Parameters: args[0] is reserved for future use (should be 0). 7076 7077This capability allows the use of the MIPS SIMD Architecture (MSA) by the guest. 7078It allows the Config3.MSAP bit to be set to enable the use of MSA by the guest. 7079Once this is done the ``KVM_REG_MIPS_VEC_*`` and ``KVM_REG_MIPS_MSA_*`` 7080registers can be accessed, and the Config5.MSAEn bit is accessible via the 7081KVM API and also from the guest. 7082 70836.74 KVM_CAP_SYNC_REGS 7084---------------------- 7085 7086:Architectures: s390, x86 7087:Target: s390: always enabled, x86: vcpu 7088:Parameters: none 7089:Returns: x86: KVM_CHECK_EXTENSION returns a bit-array indicating which register 7090 sets are supported 7091 (bitfields defined in arch/x86/include/uapi/asm/kvm.h). 7092 7093As described above in the kvm_sync_regs struct info in section 5 (kvm_run): 7094KVM_CAP_SYNC_REGS "allow[s] userspace to access certain guest registers 7095without having to call SET/GET_*REGS". This reduces overhead by eliminating 7096repeated ioctl calls for setting and/or getting register values. This is 7097particularly important when userspace is making synchronous guest state 7098modifications, e.g. when emulating and/or intercepting instructions in 7099userspace. 7100 7101For s390 specifics, please refer to the source code. 7102 7103For x86: 7104 7105- the register sets to be copied out to kvm_run are selectable 7106 by userspace (rather that all sets being copied out for every exit). 7107- vcpu_events are available in addition to regs and sregs. 7108 7109For x86, the 'kvm_valid_regs' field of struct kvm_run is overloaded to 7110function as an input bit-array field set by userspace to indicate the 7111specific register sets to be copied out on the next exit. 7112 7113To indicate when userspace has modified values that should be copied into 7114the vCPU, the all architecture bitarray field, 'kvm_dirty_regs' must be set. 7115This is done using the same bitflags as for the 'kvm_valid_regs' field. 7116If the dirty bit is not set, then the register set values will not be copied 7117into the vCPU even if they've been modified. 7118 7119Unused bitfields in the bitarrays must be set to zero. 7120 7121:: 7122 7123 struct kvm_sync_regs { 7124 struct kvm_regs regs; 7125 struct kvm_sregs sregs; 7126 struct kvm_vcpu_events events; 7127 }; 7128 71296.75 KVM_CAP_PPC_IRQ_XIVE 7130------------------------- 7131 7132:Architectures: ppc 7133:Target: vcpu 7134:Parameters: args[0] is the XIVE device fd; 7135 args[1] is the XIVE CPU number (server ID) for this vcpu 7136 7137This capability connects the vcpu to an in-kernel XIVE device. 7138 71397. Capabilities that can be enabled on VMs 7140========================================== 7141 7142There are certain capabilities that change the behavior of the virtual 7143machine when enabled. To enable them, please see section 4.37. Below 7144you can find a list of capabilities and what their effect on the VM 7145is when enabling them. 7146 7147The following information is provided along with the description: 7148 7149 Architectures: 7150 which instruction set architectures provide this ioctl. 7151 x86 includes both i386 and x86_64. 7152 7153 Parameters: 7154 what parameters are accepted by the capability. 7155 7156 Returns: 7157 the return value. General error numbers (EBADF, ENOMEM, EINVAL) 7158 are not detailed, but errors with specific meanings are. 7159 7160 71617.1 KVM_CAP_PPC_ENABLE_HCALL 7162---------------------------- 7163 7164:Architectures: ppc 7165:Parameters: args[0] is the sPAPR hcall number; 7166 args[1] is 0 to disable, 1 to enable in-kernel handling 7167 7168This capability controls whether individual sPAPR hypercalls (hcalls) 7169get handled by the kernel or not. Enabling or disabling in-kernel 7170handling of an hcall is effective across the VM. On creation, an 7171initial set of hcalls are enabled for in-kernel handling, which 7172consists of those hcalls for which in-kernel handlers were implemented 7173before this capability was implemented. If disabled, the kernel will 7174not to attempt to handle the hcall, but will always exit to userspace 7175to handle it. Note that it may not make sense to enable some and 7176disable others of a group of related hcalls, but KVM does not prevent 7177userspace from doing that. 7178 7179If the hcall number specified is not one that has an in-kernel 7180implementation, the KVM_ENABLE_CAP ioctl will fail with an EINVAL 7181error. 7182 71837.2 KVM_CAP_S390_USER_SIGP 7184-------------------------- 7185 7186:Architectures: s390 7187:Parameters: none 7188 7189This capability controls which SIGP orders will be handled completely in user 7190space. With this capability enabled, all fast orders will be handled completely 7191in the kernel: 7192 7193- SENSE 7194- SENSE RUNNING 7195- EXTERNAL CALL 7196- EMERGENCY SIGNAL 7197- CONDITIONAL EMERGENCY SIGNAL 7198 7199All other orders will be handled completely in user space. 7200 7201Only privileged operation exceptions will be checked for in the kernel (or even 7202in the hardware prior to interception). If this capability is not enabled, the 7203old way of handling SIGP orders is used (partially in kernel and user space). 7204 72057.3 KVM_CAP_S390_VECTOR_REGISTERS 7206--------------------------------- 7207 7208:Architectures: s390 7209:Parameters: none 7210:Returns: 0 on success, negative value on error 7211 7212Allows use of the vector registers introduced with z13 processor, and 7213provides for the synchronization between host and user space. Will 7214return -EINVAL if the machine does not support vectors. 7215 72167.4 KVM_CAP_S390_USER_STSI 7217-------------------------- 7218 7219:Architectures: s390 7220:Parameters: none 7221 7222This capability allows post-handlers for the STSI instruction. After 7223initial handling in the kernel, KVM exits to user space with 7224KVM_EXIT_S390_STSI to allow user space to insert further data. 7225 7226Before exiting to userspace, kvm handlers should fill in s390_stsi field of 7227vcpu->run:: 7228 7229 struct { 7230 __u64 addr; 7231 __u8 ar; 7232 __u8 reserved; 7233 __u8 fc; 7234 __u8 sel1; 7235 __u16 sel2; 7236 } s390_stsi; 7237 7238 @addr - guest address of STSI SYSIB 7239 @fc - function code 7240 @sel1 - selector 1 7241 @sel2 - selector 2 7242 @ar - access register number 7243 7244KVM handlers should exit to userspace with rc = -EREMOTE. 7245 72467.5 KVM_CAP_SPLIT_IRQCHIP 7247------------------------- 7248 7249:Architectures: x86 7250:Parameters: args[0] - number of routes reserved for userspace IOAPICs 7251:Returns: 0 on success, -1 on error 7252 7253Create a local apic for each processor in the kernel. This can be used 7254instead of KVM_CREATE_IRQCHIP if the userspace VMM wishes to emulate the 7255IOAPIC and PIC (and also the PIT, even though this has to be enabled 7256separately). 7257 7258This capability also enables in kernel routing of interrupt requests; 7259when KVM_CAP_SPLIT_IRQCHIP only routes of KVM_IRQ_ROUTING_MSI type are 7260used in the IRQ routing table. The first args[0] MSI routes are reserved 7261for the IOAPIC pins. Whenever the LAPIC receives an EOI for these routes, 7262a KVM_EXIT_IOAPIC_EOI vmexit will be reported to userspace. 7263 7264Fails if VCPU has already been created, or if the irqchip is already in the 7265kernel (i.e. KVM_CREATE_IRQCHIP has already been called). 7266 72677.6 KVM_CAP_S390_RI 7268------------------- 7269 7270:Architectures: s390 7271:Parameters: none 7272 7273Allows use of runtime-instrumentation introduced with zEC12 processor. 7274Will return -EINVAL if the machine does not support runtime-instrumentation. 7275Will return -EBUSY if a VCPU has already been created. 7276 72777.7 KVM_CAP_X2APIC_API 7278---------------------- 7279 7280:Architectures: x86 7281:Parameters: args[0] - features that should be enabled 7282:Returns: 0 on success, -EINVAL when args[0] contains invalid features 7283 7284Valid feature flags in args[0] are:: 7285 7286 #define KVM_X2APIC_API_USE_32BIT_IDS (1ULL << 0) 7287 #define KVM_X2APIC_API_DISABLE_BROADCAST_QUIRK (1ULL << 1) 7288 7289Enabling KVM_X2APIC_API_USE_32BIT_IDS changes the behavior of 7290KVM_SET_GSI_ROUTING, KVM_SIGNAL_MSI, KVM_SET_LAPIC, and KVM_GET_LAPIC, 7291allowing the use of 32-bit APIC IDs. See KVM_CAP_X2APIC_API in their 7292respective sections. 7293 7294KVM_X2APIC_API_DISABLE_BROADCAST_QUIRK must be enabled for x2APIC to work 7295in logical mode or with more than 255 VCPUs. Otherwise, KVM treats 0xff 7296as a broadcast even in x2APIC mode in order to support physical x2APIC 7297without interrupt remapping. This is undesirable in logical mode, 7298where 0xff represents CPUs 0-7 in cluster 0. 7299 73007.8 KVM_CAP_S390_USER_INSTR0 7301---------------------------- 7302 7303:Architectures: s390 7304:Parameters: none 7305 7306With this capability enabled, all illegal instructions 0x0000 (2 bytes) will 7307be intercepted and forwarded to user space. User space can use this 7308mechanism e.g. to realize 2-byte software breakpoints. The kernel will 7309not inject an operating exception for these instructions, user space has 7310to take care of that. 7311 7312This capability can be enabled dynamically even if VCPUs were already 7313created and are running. 7314 73157.9 KVM_CAP_S390_GS 7316------------------- 7317 7318:Architectures: s390 7319:Parameters: none 7320:Returns: 0 on success; -EINVAL if the machine does not support 7321 guarded storage; -EBUSY if a VCPU has already been created. 7322 7323Allows use of guarded storage for the KVM guest. 7324 73257.10 KVM_CAP_S390_AIS 7326--------------------- 7327 7328:Architectures: s390 7329:Parameters: none 7330 7331Allow use of adapter-interruption suppression. 7332:Returns: 0 on success; -EBUSY if a VCPU has already been created. 7333 73347.11 KVM_CAP_PPC_SMT 7335-------------------- 7336 7337:Architectures: ppc 7338:Parameters: vsmt_mode, flags 7339 7340Enabling this capability on a VM provides userspace with a way to set 7341the desired virtual SMT mode (i.e. the number of virtual CPUs per 7342virtual core). The virtual SMT mode, vsmt_mode, must be a power of 2 7343between 1 and 8. On POWER8, vsmt_mode must also be no greater than 7344the number of threads per subcore for the host. Currently flags must 7345be 0. A successful call to enable this capability will result in 7346vsmt_mode being returned when the KVM_CAP_PPC_SMT capability is 7347subsequently queried for the VM. This capability is only supported by 7348HV KVM, and can only be set before any VCPUs have been created. 7349The KVM_CAP_PPC_SMT_POSSIBLE capability indicates which virtual SMT 7350modes are available. 7351 73527.12 KVM_CAP_PPC_FWNMI 7353---------------------- 7354 7355:Architectures: ppc 7356:Parameters: none 7357 7358With this capability a machine check exception in the guest address 7359space will cause KVM to exit the guest with NMI exit reason. This 7360enables QEMU to build error log and branch to guest kernel registered 7361machine check handling routine. Without this capability KVM will 7362branch to guests' 0x200 interrupt vector. 7363 73647.13 KVM_CAP_X86_DISABLE_EXITS 7365------------------------------ 7366 7367:Architectures: x86 7368:Parameters: args[0] defines which exits are disabled 7369:Returns: 0 on success, -EINVAL when args[0] contains invalid exits 7370 7371Valid bits in args[0] are:: 7372 7373 #define KVM_X86_DISABLE_EXITS_MWAIT (1 << 0) 7374 #define KVM_X86_DISABLE_EXITS_HLT (1 << 1) 7375 #define KVM_X86_DISABLE_EXITS_PAUSE (1 << 2) 7376 #define KVM_X86_DISABLE_EXITS_CSTATE (1 << 3) 7377 7378Enabling this capability on a VM provides userspace with a way to no 7379longer intercept some instructions for improved latency in some 7380workloads, and is suggested when vCPUs are associated to dedicated 7381physical CPUs. More bits can be added in the future; userspace can 7382just pass the KVM_CHECK_EXTENSION result to KVM_ENABLE_CAP to disable 7383all such vmexits. 7384 7385Do not enable KVM_FEATURE_PV_UNHALT if you disable HLT exits. 7386 73877.14 KVM_CAP_S390_HPAGE_1M 7388-------------------------- 7389 7390:Architectures: s390 7391:Parameters: none 7392:Returns: 0 on success, -EINVAL if hpage module parameter was not set 7393 or cmma is enabled, or the VM has the KVM_VM_S390_UCONTROL 7394 flag set 7395 7396With this capability the KVM support for memory backing with 1m pages 7397through hugetlbfs can be enabled for a VM. After the capability is 7398enabled, cmma can't be enabled anymore and pfmfi and the storage key 7399interpretation are disabled. If cmma has already been enabled or the 7400hpage module parameter is not set to 1, -EINVAL is returned. 7401 7402While it is generally possible to create a huge page backed VM without 7403this capability, the VM will not be able to run. 7404 74057.15 KVM_CAP_MSR_PLATFORM_INFO 7406------------------------------ 7407 7408:Architectures: x86 7409:Parameters: args[0] whether feature should be enabled or not 7410 7411With this capability, a guest may read the MSR_PLATFORM_INFO MSR. Otherwise, 7412a #GP would be raised when the guest tries to access. Currently, this 7413capability does not enable write permissions of this MSR for the guest. 7414 74157.16 KVM_CAP_PPC_NESTED_HV 7416-------------------------- 7417 7418:Architectures: ppc 7419:Parameters: none 7420:Returns: 0 on success, -EINVAL when the implementation doesn't support 7421 nested-HV virtualization. 7422 7423HV-KVM on POWER9 and later systems allows for "nested-HV" 7424virtualization, which provides a way for a guest VM to run guests that 7425can run using the CPU's supervisor mode (privileged non-hypervisor 7426state). Enabling this capability on a VM depends on the CPU having 7427the necessary functionality and on the facility being enabled with a 7428kvm-hv module parameter. 7429 74307.17 KVM_CAP_EXCEPTION_PAYLOAD 7431------------------------------ 7432 7433:Architectures: x86 7434:Parameters: args[0] whether feature should be enabled or not 7435 7436With this capability enabled, CR2 will not be modified prior to the 7437emulated VM-exit when L1 intercepts a #PF exception that occurs in 7438L2. Similarly, for kvm-intel only, DR6 will not be modified prior to 7439the emulated VM-exit when L1 intercepts a #DB exception that occurs in 7440L2. As a result, when KVM_GET_VCPU_EVENTS reports a pending #PF (or 7441#DB) exception for L2, exception.has_payload will be set and the 7442faulting address (or the new DR6 bits*) will be reported in the 7443exception_payload field. Similarly, when userspace injects a #PF (or 7444#DB) into L2 using KVM_SET_VCPU_EVENTS, it is expected to set 7445exception.has_payload and to put the faulting address - or the new DR6 7446bits\ [#]_ - in the exception_payload field. 7447 7448This capability also enables exception.pending in struct 7449kvm_vcpu_events, which allows userspace to distinguish between pending 7450and injected exceptions. 7451 7452 7453.. [#] For the new DR6 bits, note that bit 16 is set iff the #DB exception 7454 will clear DR6.RTM. 7455 74567.18 KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2 7457-------------------------------------- 7458 7459:Architectures: x86, arm64, mips 7460:Parameters: args[0] whether feature should be enabled or not 7461 7462Valid flags are:: 7463 7464 #define KVM_DIRTY_LOG_MANUAL_PROTECT_ENABLE (1 << 0) 7465 #define KVM_DIRTY_LOG_INITIALLY_SET (1 << 1) 7466 7467With KVM_DIRTY_LOG_MANUAL_PROTECT_ENABLE is set, KVM_GET_DIRTY_LOG will not 7468automatically clear and write-protect all pages that are returned as dirty. 7469Rather, userspace will have to do this operation separately using 7470KVM_CLEAR_DIRTY_LOG. 7471 7472At the cost of a slightly more complicated operation, this provides better 7473scalability and responsiveness for two reasons. First, 7474KVM_CLEAR_DIRTY_LOG ioctl can operate on a 64-page granularity rather 7475than requiring to sync a full memslot; this ensures that KVM does not 7476take spinlocks for an extended period of time. Second, in some cases a 7477large amount of time can pass between a call to KVM_GET_DIRTY_LOG and 7478userspace actually using the data in the page. Pages can be modified 7479during this time, which is inefficient for both the guest and userspace: 7480the guest will incur a higher penalty due to write protection faults, 7481while userspace can see false reports of dirty pages. Manual reprotection 7482helps reducing this time, improving guest performance and reducing the 7483number of dirty log false positives. 7484 7485With KVM_DIRTY_LOG_INITIALLY_SET set, all the bits of the dirty bitmap 7486will be initialized to 1 when created. This also improves performance because 7487dirty logging can be enabled gradually in small chunks on the first call 7488to KVM_CLEAR_DIRTY_LOG. KVM_DIRTY_LOG_INITIALLY_SET depends on 7489KVM_DIRTY_LOG_MANUAL_PROTECT_ENABLE (it is also only available on 7490x86 and arm64 for now). 7491 7492KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2 was previously available under the name 7493KVM_CAP_MANUAL_DIRTY_LOG_PROTECT, but the implementation had bugs that make 7494it hard or impossible to use it correctly. The availability of 7495KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2 signals that those bugs are fixed. 7496Userspace should not try to use KVM_CAP_MANUAL_DIRTY_LOG_PROTECT. 7497 74987.19 KVM_CAP_PPC_SECURE_GUEST 7499------------------------------ 7500 7501:Architectures: ppc 7502 7503This capability indicates that KVM is running on a host that has 7504ultravisor firmware and thus can support a secure guest. On such a 7505system, a guest can ask the ultravisor to make it a secure guest, 7506one whose memory is inaccessible to the host except for pages which 7507are explicitly requested to be shared with the host. The ultravisor 7508notifies KVM when a guest requests to become a secure guest, and KVM 7509has the opportunity to veto the transition. 7510 7511If present, this capability can be enabled for a VM, meaning that KVM 7512will allow the transition to secure guest mode. Otherwise KVM will 7513veto the transition. 7514 75157.20 KVM_CAP_HALT_POLL 7516---------------------- 7517 7518:Architectures: all 7519:Target: VM 7520:Parameters: args[0] is the maximum poll time in nanoseconds 7521:Returns: 0 on success; -1 on error 7522 7523KVM_CAP_HALT_POLL overrides the kvm.halt_poll_ns module parameter to set the 7524maximum halt-polling time for all vCPUs in the target VM. This capability can 7525be invoked at any time and any number of times to dynamically change the 7526maximum halt-polling time. 7527 7528See Documentation/virt/kvm/halt-polling.rst for more information on halt 7529polling. 7530 75317.21 KVM_CAP_X86_USER_SPACE_MSR 7532------------------------------- 7533 7534:Architectures: x86 7535:Target: VM 7536:Parameters: args[0] contains the mask of KVM_MSR_EXIT_REASON_* events to report 7537:Returns: 0 on success; -1 on error 7538 7539This capability allows userspace to intercept RDMSR and WRMSR instructions if 7540access to an MSR is denied. By default, KVM injects #GP on denied accesses. 7541 7542When a guest requests to read or write an MSR, KVM may not implement all MSRs 7543that are relevant to a respective system. It also does not differentiate by 7544CPU type. 7545 7546To allow more fine grained control over MSR handling, userspace may enable 7547this capability. With it enabled, MSR accesses that match the mask specified in 7548args[0] and would trigger a #GP inside the guest will instead trigger 7549KVM_EXIT_X86_RDMSR and KVM_EXIT_X86_WRMSR exit notifications. Userspace 7550can then implement model specific MSR handling and/or user notifications 7551to inform a user that an MSR was not emulated/virtualized by KVM. 7552 7553The valid mask flags are: 7554 7555============================ =============================================== 7556 KVM_MSR_EXIT_REASON_UNKNOWN intercept accesses to unknown (to KVM) MSRs 7557 KVM_MSR_EXIT_REASON_INVAL intercept accesses that are architecturally 7558 invalid according to the vCPU model and/or mode 7559 KVM_MSR_EXIT_REASON_FILTER intercept accesses that are denied by userspace 7560 via KVM_X86_SET_MSR_FILTER 7561============================ =============================================== 7562 75637.22 KVM_CAP_X86_BUS_LOCK_EXIT 7564------------------------------- 7565 7566:Architectures: x86 7567:Target: VM 7568:Parameters: args[0] defines the policy used when bus locks detected in guest 7569:Returns: 0 on success, -EINVAL when args[0] contains invalid bits 7570 7571Valid bits in args[0] are:: 7572 7573 #define KVM_BUS_LOCK_DETECTION_OFF (1 << 0) 7574 #define KVM_BUS_LOCK_DETECTION_EXIT (1 << 1) 7575 7576Enabling this capability on a VM provides userspace with a way to select 7577a policy to handle the bus locks detected in guest. Userspace can obtain 7578the supported modes from the result of KVM_CHECK_EXTENSION and define it 7579through the KVM_ENABLE_CAP. 7580 7581KVM_BUS_LOCK_DETECTION_OFF and KVM_BUS_LOCK_DETECTION_EXIT are supported 7582currently and mutually exclusive with each other. More bits can be added in 7583the future. 7584 7585With KVM_BUS_LOCK_DETECTION_OFF set, bus locks in guest will not cause vm exits 7586so that no additional actions are needed. This is the default mode. 7587 7588With KVM_BUS_LOCK_DETECTION_EXIT set, vm exits happen when bus lock detected 7589in VM. KVM just exits to userspace when handling them. Userspace can enforce 7590its own throttling or other policy based mitigations. 7591 7592This capability is aimed to address the thread that VM can exploit bus locks to 7593degree the performance of the whole system. Once the userspace enable this 7594capability and select the KVM_BUS_LOCK_DETECTION_EXIT mode, KVM will set the 7595KVM_RUN_BUS_LOCK flag in vcpu-run->flags field and exit to userspace. Concerning 7596the bus lock vm exit can be preempted by a higher priority VM exit, the exit 7597notifications to userspace can be KVM_EXIT_BUS_LOCK or other reasons. 7598KVM_RUN_BUS_LOCK flag is used to distinguish between them. 7599 76007.23 KVM_CAP_PPC_DAWR1 7601---------------------- 7602 7603:Architectures: ppc 7604:Parameters: none 7605:Returns: 0 on success, -EINVAL when CPU doesn't support 2nd DAWR 7606 7607This capability can be used to check / enable 2nd DAWR feature provided 7608by POWER10 processor. 7609 7610 76117.24 KVM_CAP_VM_COPY_ENC_CONTEXT_FROM 7612------------------------------------- 7613 7614Architectures: x86 SEV enabled 7615Type: vm 7616Parameters: args[0] is the fd of the source vm 7617Returns: 0 on success; ENOTTY on error 7618 7619This capability enables userspace to copy encryption context from the vm 7620indicated by the fd to the vm this is called on. 7621 7622This is intended to support in-guest workloads scheduled by the host. This 7623allows the in-guest workload to maintain its own NPTs and keeps the two vms 7624from accidentally clobbering each other with interrupts and the like (separate 7625APIC/MSRs/etc). 7626 76277.25 KVM_CAP_SGX_ATTRIBUTE 7628-------------------------- 7629 7630:Architectures: x86 7631:Target: VM 7632:Parameters: args[0] is a file handle of a SGX attribute file in securityfs 7633:Returns: 0 on success, -EINVAL if the file handle is invalid or if a requested 7634 attribute is not supported by KVM. 7635 7636KVM_CAP_SGX_ATTRIBUTE enables a userspace VMM to grant a VM access to one or 7637more privileged enclave attributes. args[0] must hold a file handle to a valid 7638SGX attribute file corresponding to an attribute that is supported/restricted 7639by KVM (currently only PROVISIONKEY). 7640 7641The SGX subsystem restricts access to a subset of enclave attributes to provide 7642additional security for an uncompromised kernel, e.g. use of the PROVISIONKEY 7643is restricted to deter malware from using the PROVISIONKEY to obtain a stable 7644system fingerprint. To prevent userspace from circumventing such restrictions 7645by running an enclave in a VM, KVM prevents access to privileged attributes by 7646default. 7647 7648See Documentation/arch/x86/sgx.rst for more details. 7649 76507.26 KVM_CAP_PPC_RPT_INVALIDATE 7651------------------------------- 7652 7653:Capability: KVM_CAP_PPC_RPT_INVALIDATE 7654:Architectures: ppc 7655:Type: vm 7656 7657This capability indicates that the kernel is capable of handling 7658H_RPT_INVALIDATE hcall. 7659 7660In order to enable the use of H_RPT_INVALIDATE in the guest, 7661user space might have to advertise it for the guest. For example, 7662IBM pSeries (sPAPR) guest starts using it if "hcall-rpt-invalidate" is 7663present in the "ibm,hypertas-functions" device-tree property. 7664 7665This capability is enabled for hypervisors on platforms like POWER9 7666that support radix MMU. 7667 76687.27 KVM_CAP_EXIT_ON_EMULATION_FAILURE 7669-------------------------------------- 7670 7671:Architectures: x86 7672:Parameters: args[0] whether the feature should be enabled or not 7673 7674When this capability is enabled, an emulation failure will result in an exit 7675to userspace with KVM_INTERNAL_ERROR (except when the emulator was invoked 7676to handle a VMware backdoor instruction). Furthermore, KVM will now provide up 7677to 15 instruction bytes for any exit to userspace resulting from an emulation 7678failure. When these exits to userspace occur use the emulation_failure struct 7679instead of the internal struct. They both have the same layout, but the 7680emulation_failure struct matches the content better. It also explicitly 7681defines the 'flags' field which is used to describe the fields in the struct 7682that are valid (ie: if KVM_INTERNAL_ERROR_EMULATION_FLAG_INSTRUCTION_BYTES is 7683set in the 'flags' field then both 'insn_size' and 'insn_bytes' have valid data 7684in them.) 7685 76867.28 KVM_CAP_ARM_MTE 7687-------------------- 7688 7689:Architectures: arm64 7690:Parameters: none 7691 7692This capability indicates that KVM (and the hardware) supports exposing the 7693Memory Tagging Extensions (MTE) to the guest. It must also be enabled by the 7694VMM before creating any VCPUs to allow the guest access. Note that MTE is only 7695available to a guest running in AArch64 mode and enabling this capability will 7696cause attempts to create AArch32 VCPUs to fail. 7697 7698When enabled the guest is able to access tags associated with any memory given 7699to the guest. KVM will ensure that the tags are maintained during swap or 7700hibernation of the host; however the VMM needs to manually save/restore the 7701tags as appropriate if the VM is migrated. 7702 7703When this capability is enabled all memory in memslots must be mapped as 7704``MAP_ANONYMOUS`` or with a RAM-based file mapping (``tmpfs``, ``memfd``), 7705attempts to create a memslot with an invalid mmap will result in an 7706-EINVAL return. 7707 7708When enabled the VMM may make use of the ``KVM_ARM_MTE_COPY_TAGS`` ioctl to 7709perform a bulk copy of tags to/from the guest. 7710 77117.29 KVM_CAP_VM_MOVE_ENC_CONTEXT_FROM 7712------------------------------------- 7713 7714Architectures: x86 SEV enabled 7715Type: vm 7716Parameters: args[0] is the fd of the source vm 7717Returns: 0 on success 7718 7719This capability enables userspace to migrate the encryption context from the VM 7720indicated by the fd to the VM this is called on. 7721 7722This is intended to support intra-host migration of VMs between userspace VMMs, 7723upgrading the VMM process without interrupting the guest. 7724 77257.30 KVM_CAP_PPC_AIL_MODE_3 7726------------------------------- 7727 7728:Capability: KVM_CAP_PPC_AIL_MODE_3 7729:Architectures: ppc 7730:Type: vm 7731 7732This capability indicates that the kernel supports the mode 3 setting for the 7733"Address Translation Mode on Interrupt" aka "Alternate Interrupt Location" 7734resource that is controlled with the H_SET_MODE hypercall. 7735 7736This capability allows a guest kernel to use a better-performance mode for 7737handling interrupts and system calls. 7738 77397.31 KVM_CAP_DISABLE_QUIRKS2 7740---------------------------- 7741 7742:Capability: KVM_CAP_DISABLE_QUIRKS2 7743:Parameters: args[0] - set of KVM quirks to disable 7744:Architectures: x86 7745:Type: vm 7746 7747This capability, if enabled, will cause KVM to disable some behavior 7748quirks. 7749 7750Calling KVM_CHECK_EXTENSION for this capability returns a bitmask of 7751quirks that can be disabled in KVM. 7752 7753The argument to KVM_ENABLE_CAP for this capability is a bitmask of 7754quirks to disable, and must be a subset of the bitmask returned by 7755KVM_CHECK_EXTENSION. 7756 7757The valid bits in cap.args[0] are: 7758 7759=================================== ============================================ 7760 KVM_X86_QUIRK_LINT0_REENABLED By default, the reset value for the LVT 7761 LINT0 register is 0x700 (APIC_MODE_EXTINT). 7762 When this quirk is disabled, the reset value 7763 is 0x10000 (APIC_LVT_MASKED). 7764 7765 KVM_X86_QUIRK_CD_NW_CLEARED By default, KVM clears CR0.CD and CR0.NW. 7766 When this quirk is disabled, KVM does not 7767 change the value of CR0.CD and CR0.NW. 7768 7769 KVM_X86_QUIRK_LAPIC_MMIO_HOLE By default, the MMIO LAPIC interface is 7770 available even when configured for x2APIC 7771 mode. When this quirk is disabled, KVM 7772 disables the MMIO LAPIC interface if the 7773 LAPIC is in x2APIC mode. 7774 7775 KVM_X86_QUIRK_OUT_7E_INC_RIP By default, KVM pre-increments %rip before 7776 exiting to userspace for an OUT instruction 7777 to port 0x7e. When this quirk is disabled, 7778 KVM does not pre-increment %rip before 7779 exiting to userspace. 7780 7781 KVM_X86_QUIRK_MISC_ENABLE_NO_MWAIT When this quirk is disabled, KVM sets 7782 CPUID.01H:ECX[bit 3] (MONITOR/MWAIT) if 7783 IA32_MISC_ENABLE[bit 18] (MWAIT) is set. 7784 Additionally, when this quirk is disabled, 7785 KVM clears CPUID.01H:ECX[bit 3] if 7786 IA32_MISC_ENABLE[bit 18] is cleared. 7787 7788 KVM_X86_QUIRK_FIX_HYPERCALL_INSN By default, KVM rewrites guest 7789 VMMCALL/VMCALL instructions to match the 7790 vendor's hypercall instruction for the 7791 system. When this quirk is disabled, KVM 7792 will no longer rewrite invalid guest 7793 hypercall instructions. Executing the 7794 incorrect hypercall instruction will 7795 generate a #UD within the guest. 7796 7797KVM_X86_QUIRK_MWAIT_NEVER_UD_FAULTS By default, KVM emulates MONITOR/MWAIT (if 7798 they are intercepted) as NOPs regardless of 7799 whether or not MONITOR/MWAIT are supported 7800 according to guest CPUID. When this quirk 7801 is disabled and KVM_X86_DISABLE_EXITS_MWAIT 7802 is not set (MONITOR/MWAIT are intercepted), 7803 KVM will inject a #UD on MONITOR/MWAIT if 7804 they're unsupported per guest CPUID. Note, 7805 KVM will modify MONITOR/MWAIT support in 7806 guest CPUID on writes to MISC_ENABLE if 7807 KVM_X86_QUIRK_MISC_ENABLE_NO_MWAIT is 7808 disabled. 7809=================================== ============================================ 7810 78117.32 KVM_CAP_MAX_VCPU_ID 7812------------------------ 7813 7814:Architectures: x86 7815:Target: VM 7816:Parameters: args[0] - maximum APIC ID value set for current VM 7817:Returns: 0 on success, -EINVAL if args[0] is beyond KVM_MAX_VCPU_IDS 7818 supported in KVM or if it has been set. 7819 7820This capability allows userspace to specify maximum possible APIC ID 7821assigned for current VM session prior to the creation of vCPUs, saving 7822memory for data structures indexed by the APIC ID. Userspace is able 7823to calculate the limit to APIC ID values from designated 7824CPU topology. 7825 7826The value can be changed only until KVM_ENABLE_CAP is set to a nonzero 7827value or until a vCPU is created. Upon creation of the first vCPU, 7828if the value was set to zero or KVM_ENABLE_CAP was not invoked, KVM 7829uses the return value of KVM_CHECK_EXTENSION(KVM_CAP_MAX_VCPU_ID) as 7830the maximum APIC ID. 7831 78327.33 KVM_CAP_X86_NOTIFY_VMEXIT 7833------------------------------ 7834 7835:Architectures: x86 7836:Target: VM 7837:Parameters: args[0] is the value of notify window as well as some flags 7838:Returns: 0 on success, -EINVAL if args[0] contains invalid flags or notify 7839 VM exit is unsupported. 7840 7841Bits 63:32 of args[0] are used for notify window. 7842Bits 31:0 of args[0] are for some flags. Valid bits are:: 7843 7844 #define KVM_X86_NOTIFY_VMEXIT_ENABLED (1 << 0) 7845 #define KVM_X86_NOTIFY_VMEXIT_USER (1 << 1) 7846 7847This capability allows userspace to configure the notify VM exit on/off 7848in per-VM scope during VM creation. Notify VM exit is disabled by default. 7849When userspace sets KVM_X86_NOTIFY_VMEXIT_ENABLED bit in args[0], VMM will 7850enable this feature with the notify window provided, which will generate 7851a VM exit if no event window occurs in VM non-root mode for a specified of 7852time (notify window). 7853 7854If KVM_X86_NOTIFY_VMEXIT_USER is set in args[0], upon notify VM exits happen, 7855KVM would exit to userspace for handling. 7856 7857This capability is aimed to mitigate the threat that malicious VMs can 7858cause CPU stuck (due to event windows don't open up) and make the CPU 7859unavailable to host or other VMs. 7860 78618. Other capabilities. 7862====================== 7863 7864This section lists capabilities that give information about other 7865features of the KVM implementation. 7866 78678.1 KVM_CAP_PPC_HWRNG 7868--------------------- 7869 7870:Architectures: ppc 7871 7872This capability, if KVM_CHECK_EXTENSION indicates that it is 7873available, means that the kernel has an implementation of the 7874H_RANDOM hypercall backed by a hardware random-number generator. 7875If present, the kernel H_RANDOM handler can be enabled for guest use 7876with the KVM_CAP_PPC_ENABLE_HCALL capability. 7877 78788.2 KVM_CAP_HYPERV_SYNIC 7879------------------------ 7880 7881:Architectures: x86 7882 7883This capability, if KVM_CHECK_EXTENSION indicates that it is 7884available, means that the kernel has an implementation of the 7885Hyper-V Synthetic interrupt controller(SynIC). Hyper-V SynIC is 7886used to support Windows Hyper-V based guest paravirt drivers(VMBus). 7887 7888In order to use SynIC, it has to be activated by setting this 7889capability via KVM_ENABLE_CAP ioctl on the vcpu fd. Note that this 7890will disable the use of APIC hardware virtualization even if supported 7891by the CPU, as it's incompatible with SynIC auto-EOI behavior. 7892 78938.3 KVM_CAP_PPC_RADIX_MMU 7894------------------------- 7895 7896:Architectures: ppc 7897 7898This capability, if KVM_CHECK_EXTENSION indicates that it is 7899available, means that the kernel can support guests using the 7900radix MMU defined in Power ISA V3.00 (as implemented in the POWER9 7901processor). 7902 79038.4 KVM_CAP_PPC_HASH_MMU_V3 7904--------------------------- 7905 7906:Architectures: ppc 7907 7908This capability, if KVM_CHECK_EXTENSION indicates that it is 7909available, means that the kernel can support guests using the 7910hashed page table MMU defined in Power ISA V3.00 (as implemented in 7911the POWER9 processor), including in-memory segment tables. 7912 79138.5 KVM_CAP_MIPS_VZ 7914------------------- 7915 7916:Architectures: mips 7917 7918This capability, if KVM_CHECK_EXTENSION on the main kvm handle indicates that 7919it is available, means that full hardware assisted virtualization capabilities 7920of the hardware are available for use through KVM. An appropriate 7921KVM_VM_MIPS_* type must be passed to KVM_CREATE_VM to create a VM which 7922utilises it. 7923 7924If KVM_CHECK_EXTENSION on a kvm VM handle indicates that this capability is 7925available, it means that the VM is using full hardware assisted virtualization 7926capabilities of the hardware. This is useful to check after creating a VM with 7927KVM_VM_MIPS_DEFAULT. 7928 7929The value returned by KVM_CHECK_EXTENSION should be compared against known 7930values (see below). All other values are reserved. This is to allow for the 7931possibility of other hardware assisted virtualization implementations which 7932may be incompatible with the MIPS VZ ASE. 7933 7934== ========================================================================== 7935 0 The trap & emulate implementation is in use to run guest code in user 7936 mode. Guest virtual memory segments are rearranged to fit the guest in the 7937 user mode address space. 7938 7939 1 The MIPS VZ ASE is in use, providing full hardware assisted 7940 virtualization, including standard guest virtual memory segments. 7941== ========================================================================== 7942 79438.6 KVM_CAP_MIPS_TE 7944------------------- 7945 7946:Architectures: mips 7947 7948This capability, if KVM_CHECK_EXTENSION on the main kvm handle indicates that 7949it is available, means that the trap & emulate implementation is available to 7950run guest code in user mode, even if KVM_CAP_MIPS_VZ indicates that hardware 7951assisted virtualisation is also available. KVM_VM_MIPS_TE (0) must be passed 7952to KVM_CREATE_VM to create a VM which utilises it. 7953 7954If KVM_CHECK_EXTENSION on a kvm VM handle indicates that this capability is 7955available, it means that the VM is using trap & emulate. 7956 79578.7 KVM_CAP_MIPS_64BIT 7958---------------------- 7959 7960:Architectures: mips 7961 7962This capability indicates the supported architecture type of the guest, i.e. the 7963supported register and address width. 7964 7965The values returned when this capability is checked by KVM_CHECK_EXTENSION on a 7966kvm VM handle correspond roughly to the CP0_Config.AT register field, and should 7967be checked specifically against known values (see below). All other values are 7968reserved. 7969 7970== ======================================================================== 7971 0 MIPS32 or microMIPS32. 7972 Both registers and addresses are 32-bits wide. 7973 It will only be possible to run 32-bit guest code. 7974 7975 1 MIPS64 or microMIPS64 with access only to 32-bit compatibility segments. 7976 Registers are 64-bits wide, but addresses are 32-bits wide. 7977 64-bit guest code may run but cannot access MIPS64 memory segments. 7978 It will also be possible to run 32-bit guest code. 7979 7980 2 MIPS64 or microMIPS64 with access to all address segments. 7981 Both registers and addresses are 64-bits wide. 7982 It will be possible to run 64-bit or 32-bit guest code. 7983== ======================================================================== 7984 79858.9 KVM_CAP_ARM_USER_IRQ 7986------------------------ 7987 7988:Architectures: arm64 7989 7990This capability, if KVM_CHECK_EXTENSION indicates that it is available, means 7991that if userspace creates a VM without an in-kernel interrupt controller, it 7992will be notified of changes to the output level of in-kernel emulated devices, 7993which can generate virtual interrupts, presented to the VM. 7994For such VMs, on every return to userspace, the kernel 7995updates the vcpu's run->s.regs.device_irq_level field to represent the actual 7996output level of the device. 7997 7998Whenever kvm detects a change in the device output level, kvm guarantees at 7999least one return to userspace before running the VM. This exit could either 8000be a KVM_EXIT_INTR or any other exit event, like KVM_EXIT_MMIO. This way, 8001userspace can always sample the device output level and re-compute the state of 8002the userspace interrupt controller. Userspace should always check the state 8003of run->s.regs.device_irq_level on every kvm exit. 8004The value in run->s.regs.device_irq_level can represent both level and edge 8005triggered interrupt signals, depending on the device. Edge triggered interrupt 8006signals will exit to userspace with the bit in run->s.regs.device_irq_level 8007set exactly once per edge signal. 8008 8009The field run->s.regs.device_irq_level is available independent of 8010run->kvm_valid_regs or run->kvm_dirty_regs bits. 8011 8012If KVM_CAP_ARM_USER_IRQ is supported, the KVM_CHECK_EXTENSION ioctl returns a 8013number larger than 0 indicating the version of this capability is implemented 8014and thereby which bits in run->s.regs.device_irq_level can signal values. 8015 8016Currently the following bits are defined for the device_irq_level bitmap:: 8017 8018 KVM_CAP_ARM_USER_IRQ >= 1: 8019 8020 KVM_ARM_DEV_EL1_VTIMER - EL1 virtual timer 8021 KVM_ARM_DEV_EL1_PTIMER - EL1 physical timer 8022 KVM_ARM_DEV_PMU - ARM PMU overflow interrupt signal 8023 8024Future versions of kvm may implement additional events. These will get 8025indicated by returning a higher number from KVM_CHECK_EXTENSION and will be 8026listed above. 8027 80288.10 KVM_CAP_PPC_SMT_POSSIBLE 8029----------------------------- 8030 8031:Architectures: ppc 8032 8033Querying this capability returns a bitmap indicating the possible 8034virtual SMT modes that can be set using KVM_CAP_PPC_SMT. If bit N 8035(counting from the right) is set, then a virtual SMT mode of 2^N is 8036available. 8037 80388.11 KVM_CAP_HYPERV_SYNIC2 8039-------------------------- 8040 8041:Architectures: x86 8042 8043This capability enables a newer version of Hyper-V Synthetic interrupt 8044controller (SynIC). The only difference with KVM_CAP_HYPERV_SYNIC is that KVM 8045doesn't clear SynIC message and event flags pages when they are enabled by 8046writing to the respective MSRs. 8047 80488.12 KVM_CAP_HYPERV_VP_INDEX 8049---------------------------- 8050 8051:Architectures: x86 8052 8053This capability indicates that userspace can load HV_X64_MSR_VP_INDEX msr. Its 8054value is used to denote the target vcpu for a SynIC interrupt. For 8055compatibility, KVM initializes this msr to KVM's internal vcpu index. When this 8056capability is absent, userspace can still query this msr's value. 8057 80588.13 KVM_CAP_S390_AIS_MIGRATION 8059------------------------------- 8060 8061:Architectures: s390 8062:Parameters: none 8063 8064This capability indicates if the flic device will be able to get/set the 8065AIS states for migration via the KVM_DEV_FLIC_AISM_ALL attribute and allows 8066to discover this without having to create a flic device. 8067 80688.14 KVM_CAP_S390_PSW 8069--------------------- 8070 8071:Architectures: s390 8072 8073This capability indicates that the PSW is exposed via the kvm_run structure. 8074 80758.15 KVM_CAP_S390_GMAP 8076---------------------- 8077 8078:Architectures: s390 8079 8080This capability indicates that the user space memory used as guest mapping can 8081be anywhere in the user memory address space, as long as the memory slots are 8082aligned and sized to a segment (1MB) boundary. 8083 80848.16 KVM_CAP_S390_COW 8085--------------------- 8086 8087:Architectures: s390 8088 8089This capability indicates that the user space memory used as guest mapping can 8090use copy-on-write semantics as well as dirty pages tracking via read-only page 8091tables. 8092 80938.17 KVM_CAP_S390_BPB 8094--------------------- 8095 8096:Architectures: s390 8097 8098This capability indicates that kvm will implement the interfaces to handle 8099reset, migration and nested KVM for branch prediction blocking. The stfle 8100facility 82 should not be provided to the guest without this capability. 8101 81028.18 KVM_CAP_HYPERV_TLBFLUSH 8103---------------------------- 8104 8105:Architectures: x86 8106 8107This capability indicates that KVM supports paravirtualized Hyper-V TLB Flush 8108hypercalls: 8109HvFlushVirtualAddressSpace, HvFlushVirtualAddressSpaceEx, 8110HvFlushVirtualAddressList, HvFlushVirtualAddressListEx. 8111 81128.19 KVM_CAP_ARM_INJECT_SERROR_ESR 8113---------------------------------- 8114 8115:Architectures: arm64 8116 8117This capability indicates that userspace can specify (via the 8118KVM_SET_VCPU_EVENTS ioctl) the syndrome value reported to the guest when it 8119takes a virtual SError interrupt exception. 8120If KVM advertises this capability, userspace can only specify the ISS field for 8121the ESR syndrome. Other parts of the ESR, such as the EC are generated by the 8122CPU when the exception is taken. If this virtual SError is taken to EL1 using 8123AArch64, this value will be reported in the ISS field of ESR_ELx. 8124 8125See KVM_CAP_VCPU_EVENTS for more details. 8126 81278.20 KVM_CAP_HYPERV_SEND_IPI 8128---------------------------- 8129 8130:Architectures: x86 8131 8132This capability indicates that KVM supports paravirtualized Hyper-V IPI send 8133hypercalls: 8134HvCallSendSyntheticClusterIpi, HvCallSendSyntheticClusterIpiEx. 8135 81368.21 KVM_CAP_HYPERV_DIRECT_TLBFLUSH 8137----------------------------------- 8138 8139:Architectures: x86 8140 8141This capability indicates that KVM running on top of Hyper-V hypervisor 8142enables Direct TLB flush for its guests meaning that TLB flush 8143hypercalls are handled by Level 0 hypervisor (Hyper-V) bypassing KVM. 8144Due to the different ABI for hypercall parameters between Hyper-V and 8145KVM, enabling this capability effectively disables all hypercall 8146handling by KVM (as some KVM hypercall may be mistakenly treated as TLB 8147flush hypercalls by Hyper-V) so userspace should disable KVM identification 8148in CPUID and only exposes Hyper-V identification. In this case, guest 8149thinks it's running on Hyper-V and only use Hyper-V hypercalls. 8150 81518.22 KVM_CAP_S390_VCPU_RESETS 8152----------------------------- 8153 8154:Architectures: s390 8155 8156This capability indicates that the KVM_S390_NORMAL_RESET and 8157KVM_S390_CLEAR_RESET ioctls are available. 8158 81598.23 KVM_CAP_S390_PROTECTED 8160--------------------------- 8161 8162:Architectures: s390 8163 8164This capability indicates that the Ultravisor has been initialized and 8165KVM can therefore start protected VMs. 8166This capability governs the KVM_S390_PV_COMMAND ioctl and the 8167KVM_MP_STATE_LOAD MP_STATE. KVM_SET_MP_STATE can fail for protected 8168guests when the state change is invalid. 8169 81708.24 KVM_CAP_STEAL_TIME 8171----------------------- 8172 8173:Architectures: arm64, x86 8174 8175This capability indicates that KVM supports steal time accounting. 8176When steal time accounting is supported it may be enabled with 8177architecture-specific interfaces. This capability and the architecture- 8178specific interfaces must be consistent, i.e. if one says the feature 8179is supported, than the other should as well and vice versa. For arm64 8180see Documentation/virt/kvm/devices/vcpu.rst "KVM_ARM_VCPU_PVTIME_CTRL". 8181For x86 see Documentation/virt/kvm/x86/msr.rst "MSR_KVM_STEAL_TIME". 8182 81838.25 KVM_CAP_S390_DIAG318 8184------------------------- 8185 8186:Architectures: s390 8187 8188This capability enables a guest to set information about its control program 8189(i.e. guest kernel type and version). The information is helpful during 8190system/firmware service events, providing additional data about the guest 8191environments running on the machine. 8192 8193The information is associated with the DIAGNOSE 0x318 instruction, which sets 8194an 8-byte value consisting of a one-byte Control Program Name Code (CPNC) and 8195a 7-byte Control Program Version Code (CPVC). The CPNC determines what 8196environment the control program is running in (e.g. Linux, z/VM...), and the 8197CPVC is used for information specific to OS (e.g. Linux version, Linux 8198distribution...) 8199 8200If this capability is available, then the CPNC and CPVC can be synchronized 8201between KVM and userspace via the sync regs mechanism (KVM_SYNC_DIAG318). 8202 82038.26 KVM_CAP_X86_USER_SPACE_MSR 8204------------------------------- 8205 8206:Architectures: x86 8207 8208This capability indicates that KVM supports deflection of MSR reads and 8209writes to user space. It can be enabled on a VM level. If enabled, MSR 8210accesses that would usually trigger a #GP by KVM into the guest will 8211instead get bounced to user space through the KVM_EXIT_X86_RDMSR and 8212KVM_EXIT_X86_WRMSR exit notifications. 8213 82148.27 KVM_CAP_X86_MSR_FILTER 8215--------------------------- 8216 8217:Architectures: x86 8218 8219This capability indicates that KVM supports that accesses to user defined MSRs 8220may be rejected. With this capability exposed, KVM exports new VM ioctl 8221KVM_X86_SET_MSR_FILTER which user space can call to specify bitmaps of MSR 8222ranges that KVM should deny access to. 8223 8224In combination with KVM_CAP_X86_USER_SPACE_MSR, this allows user space to 8225trap and emulate MSRs that are outside of the scope of KVM as well as 8226limit the attack surface on KVM's MSR emulation code. 8227 82288.28 KVM_CAP_ENFORCE_PV_FEATURE_CPUID 8229------------------------------------- 8230 8231Architectures: x86 8232 8233When enabled, KVM will disable paravirtual features provided to the 8234guest according to the bits in the KVM_CPUID_FEATURES CPUID leaf 8235(0x40000001). Otherwise, a guest may use the paravirtual features 8236regardless of what has actually been exposed through the CPUID leaf. 8237 82388.29 KVM_CAP_DIRTY_LOG_RING/KVM_CAP_DIRTY_LOG_RING_ACQ_REL 8239---------------------------------------------------------- 8240 8241:Architectures: x86, arm64 8242:Parameters: args[0] - size of the dirty log ring 8243 8244KVM is capable of tracking dirty memory using ring buffers that are 8245mmapped into userspace; there is one dirty ring per vcpu. 8246 8247The dirty ring is available to userspace as an array of 8248``struct kvm_dirty_gfn``. Each dirty entry is defined as:: 8249 8250 struct kvm_dirty_gfn { 8251 __u32 flags; 8252 __u32 slot; /* as_id | slot_id */ 8253 __u64 offset; 8254 }; 8255 8256The following values are defined for the flags field to define the 8257current state of the entry:: 8258 8259 #define KVM_DIRTY_GFN_F_DIRTY BIT(0) 8260 #define KVM_DIRTY_GFN_F_RESET BIT(1) 8261 #define KVM_DIRTY_GFN_F_MASK 0x3 8262 8263Userspace should call KVM_ENABLE_CAP ioctl right after KVM_CREATE_VM 8264ioctl to enable this capability for the new guest and set the size of 8265the rings. Enabling the capability is only allowed before creating any 8266vCPU, and the size of the ring must be a power of two. The larger the 8267ring buffer, the less likely the ring is full and the VM is forced to 8268exit to userspace. The optimal size depends on the workload, but it is 8269recommended that it be at least 64 KiB (4096 entries). 8270 8271Just like for dirty page bitmaps, the buffer tracks writes to 8272all user memory regions for which the KVM_MEM_LOG_DIRTY_PAGES flag was 8273set in KVM_SET_USER_MEMORY_REGION. Once a memory region is registered 8274with the flag set, userspace can start harvesting dirty pages from the 8275ring buffer. 8276 8277An entry in the ring buffer can be unused (flag bits ``00``), 8278dirty (flag bits ``01``) or harvested (flag bits ``1X``). The 8279state machine for the entry is as follows:: 8280 8281 dirtied harvested reset 8282 00 -----------> 01 -------------> 1X -------+ 8283 ^ | 8284 | | 8285 +------------------------------------------+ 8286 8287To harvest the dirty pages, userspace accesses the mmapped ring buffer 8288to read the dirty GFNs. If the flags has the DIRTY bit set (at this stage 8289the RESET bit must be cleared), then it means this GFN is a dirty GFN. 8290The userspace should harvest this GFN and mark the flags from state 8291``01b`` to ``1Xb`` (bit 0 will be ignored by KVM, but bit 1 must be set 8292to show that this GFN is harvested and waiting for a reset), and move 8293on to the next GFN. The userspace should continue to do this until the 8294flags of a GFN have the DIRTY bit cleared, meaning that it has harvested 8295all the dirty GFNs that were available. 8296 8297Note that on weakly ordered architectures, userspace accesses to the 8298ring buffer (and more specifically the 'flags' field) must be ordered, 8299using load-acquire/store-release accessors when available, or any 8300other memory barrier that will ensure this ordering. 8301 8302It's not necessary for userspace to harvest the all dirty GFNs at once. 8303However it must collect the dirty GFNs in sequence, i.e., the userspace 8304program cannot skip one dirty GFN to collect the one next to it. 8305 8306After processing one or more entries in the ring buffer, userspace 8307calls the VM ioctl KVM_RESET_DIRTY_RINGS to notify the kernel about 8308it, so that the kernel will reprotect those collected GFNs. 8309Therefore, the ioctl must be called *before* reading the content of 8310the dirty pages. 8311 8312The dirty ring can get full. When it happens, the KVM_RUN of the 8313vcpu will return with exit reason KVM_EXIT_DIRTY_LOG_FULL. 8314 8315The dirty ring interface has a major difference comparing to the 8316KVM_GET_DIRTY_LOG interface in that, when reading the dirty ring from 8317userspace, it's still possible that the kernel has not yet flushed the 8318processor's dirty page buffers into the kernel buffer (with dirty bitmaps, the 8319flushing is done by the KVM_GET_DIRTY_LOG ioctl). To achieve that, one 8320needs to kick the vcpu out of KVM_RUN using a signal. The resulting 8321vmexit ensures that all dirty GFNs are flushed to the dirty rings. 8322 8323NOTE: KVM_CAP_DIRTY_LOG_RING_ACQ_REL is the only capability that 8324should be exposed by weakly ordered architecture, in order to indicate 8325the additional memory ordering requirements imposed on userspace when 8326reading the state of an entry and mutating it from DIRTY to HARVESTED. 8327Architecture with TSO-like ordering (such as x86) are allowed to 8328expose both KVM_CAP_DIRTY_LOG_RING and KVM_CAP_DIRTY_LOG_RING_ACQ_REL 8329to userspace. 8330 8331After enabling the dirty rings, the userspace needs to detect the 8332capability of KVM_CAP_DIRTY_LOG_RING_WITH_BITMAP to see whether the 8333ring structures can be backed by per-slot bitmaps. With this capability 8334advertised, it means the architecture can dirty guest pages without 8335vcpu/ring context, so that some of the dirty information will still be 8336maintained in the bitmap structure. KVM_CAP_DIRTY_LOG_RING_WITH_BITMAP 8337can't be enabled if the capability of KVM_CAP_DIRTY_LOG_RING_ACQ_REL 8338hasn't been enabled, or any memslot has been existing. 8339 8340Note that the bitmap here is only a backup of the ring structure. The 8341use of the ring and bitmap combination is only beneficial if there is 8342only a very small amount of memory that is dirtied out of vcpu/ring 8343context. Otherwise, the stand-alone per-slot bitmap mechanism needs to 8344be considered. 8345 8346To collect dirty bits in the backup bitmap, userspace can use the same 8347KVM_GET_DIRTY_LOG ioctl. KVM_CLEAR_DIRTY_LOG isn't needed as long as all 8348the generation of the dirty bits is done in a single pass. Collecting 8349the dirty bitmap should be the very last thing that the VMM does before 8350considering the state as complete. VMM needs to ensure that the dirty 8351state is final and avoid missing dirty pages from another ioctl ordered 8352after the bitmap collection. 8353 8354NOTE: Multiple examples of using the backup bitmap: (1) save vgic/its 8355tables through command KVM_DEV_ARM_{VGIC_GRP_CTRL, ITS_SAVE_TABLES} on 8356KVM device "kvm-arm-vgic-its". (2) restore vgic/its tables through 8357command KVM_DEV_ARM_{VGIC_GRP_CTRL, ITS_RESTORE_TABLES} on KVM device 8358"kvm-arm-vgic-its". VGICv3 LPI pending status is restored. (3) save 8359vgic3 pending table through KVM_DEV_ARM_VGIC_{GRP_CTRL, SAVE_PENDING_TABLES} 8360command on KVM device "kvm-arm-vgic-v3". 8361 83628.30 KVM_CAP_XEN_HVM 8363-------------------- 8364 8365:Architectures: x86 8366 8367This capability indicates the features that Xen supports for hosting Xen 8368PVHVM guests. Valid flags are:: 8369 8370 #define KVM_XEN_HVM_CONFIG_HYPERCALL_MSR (1 << 0) 8371 #define KVM_XEN_HVM_CONFIG_INTERCEPT_HCALL (1 << 1) 8372 #define KVM_XEN_HVM_CONFIG_SHARED_INFO (1 << 2) 8373 #define KVM_XEN_HVM_CONFIG_RUNSTATE (1 << 3) 8374 #define KVM_XEN_HVM_CONFIG_EVTCHN_2LEVEL (1 << 4) 8375 #define KVM_XEN_HVM_CONFIG_EVTCHN_SEND (1 << 5) 8376 #define KVM_XEN_HVM_CONFIG_RUNSTATE_UPDATE_FLAG (1 << 6) 8377 8378The KVM_XEN_HVM_CONFIG_HYPERCALL_MSR flag indicates that the KVM_XEN_HVM_CONFIG 8379ioctl is available, for the guest to set its hypercall page. 8380 8381If KVM_XEN_HVM_CONFIG_INTERCEPT_HCALL is also set, the same flag may also be 8382provided in the flags to KVM_XEN_HVM_CONFIG, without providing hypercall page 8383contents, to request that KVM generate hypercall page content automatically 8384and also enable interception of guest hypercalls with KVM_EXIT_XEN. 8385 8386The KVM_XEN_HVM_CONFIG_SHARED_INFO flag indicates the availability of the 8387KVM_XEN_HVM_SET_ATTR, KVM_XEN_HVM_GET_ATTR, KVM_XEN_VCPU_SET_ATTR and 8388KVM_XEN_VCPU_GET_ATTR ioctls, as well as the delivery of exception vectors 8389for event channel upcalls when the evtchn_upcall_pending field of a vcpu's 8390vcpu_info is set. 8391 8392The KVM_XEN_HVM_CONFIG_RUNSTATE flag indicates that the runstate-related 8393features KVM_XEN_VCPU_ATTR_TYPE_RUNSTATE_ADDR/_CURRENT/_DATA/_ADJUST are 8394supported by the KVM_XEN_VCPU_SET_ATTR/KVM_XEN_VCPU_GET_ATTR ioctls. 8395 8396The KVM_XEN_HVM_CONFIG_EVTCHN_2LEVEL flag indicates that IRQ routing entries 8397of the type KVM_IRQ_ROUTING_XEN_EVTCHN are supported, with the priority 8398field set to indicate 2 level event channel delivery. 8399 8400The KVM_XEN_HVM_CONFIG_EVTCHN_SEND flag indicates that KVM supports 8401injecting event channel events directly into the guest with the 8402KVM_XEN_HVM_EVTCHN_SEND ioctl. It also indicates support for the 8403KVM_XEN_ATTR_TYPE_EVTCHN/XEN_VERSION HVM attributes and the 8404KVM_XEN_VCPU_ATTR_TYPE_VCPU_ID/TIMER/UPCALL_VECTOR vCPU attributes. 8405related to event channel delivery, timers, and the XENVER_version 8406interception. 8407 8408The KVM_XEN_HVM_CONFIG_RUNSTATE_UPDATE_FLAG flag indicates that KVM supports 8409the KVM_XEN_ATTR_TYPE_RUNSTATE_UPDATE_FLAG attribute in the KVM_XEN_SET_ATTR 8410and KVM_XEN_GET_ATTR ioctls. This controls whether KVM will set the 8411XEN_RUNSTATE_UPDATE flag in guest memory mapped vcpu_runstate_info during 8412updates of the runstate information. Note that versions of KVM which support 8413the RUNSTATE feature above, but not the RUNSTATE_UPDATE_FLAG feature, will 8414always set the XEN_RUNSTATE_UPDATE flag when updating the guest structure, 8415which is perhaps counterintuitive. When this flag is advertised, KVM will 8416behave more correctly, not using the XEN_RUNSTATE_UPDATE flag until/unless 8417specifically enabled (by the guest making the hypercall, causing the VMM 8418to enable the KVM_XEN_ATTR_TYPE_RUNSTATE_UPDATE_FLAG attribute). 8419 84208.31 KVM_CAP_PPC_MULTITCE 8421------------------------- 8422 8423:Capability: KVM_CAP_PPC_MULTITCE 8424:Architectures: ppc 8425:Type: vm 8426 8427This capability means the kernel is capable of handling hypercalls 8428H_PUT_TCE_INDIRECT and H_STUFF_TCE without passing those into the user 8429space. This significantly accelerates DMA operations for PPC KVM guests. 8430User space should expect that its handlers for these hypercalls 8431are not going to be called if user space previously registered LIOBN 8432in KVM (via KVM_CREATE_SPAPR_TCE or similar calls). 8433 8434In order to enable H_PUT_TCE_INDIRECT and H_STUFF_TCE use in the guest, 8435user space might have to advertise it for the guest. For example, 8436IBM pSeries (sPAPR) guest starts using them if "hcall-multi-tce" is 8437present in the "ibm,hypertas-functions" device-tree property. 8438 8439The hypercalls mentioned above may or may not be processed successfully 8440in the kernel based fast path. If they can not be handled by the kernel, 8441they will get passed on to user space. So user space still has to have 8442an implementation for these despite the in kernel acceleration. 8443 8444This capability is always enabled. 8445 84468.32 KVM_CAP_PTP_KVM 8447-------------------- 8448 8449:Architectures: arm64 8450 8451This capability indicates that the KVM virtual PTP service is 8452supported in the host. A VMM can check whether the service is 8453available to the guest on migration. 8454 84558.33 KVM_CAP_HYPERV_ENFORCE_CPUID 8456--------------------------------- 8457 8458Architectures: x86 8459 8460When enabled, KVM will disable emulated Hyper-V features provided to the 8461guest according to the bits Hyper-V CPUID feature leaves. Otherwise, all 8462currently implemented Hyper-V features are provided unconditionally when 8463Hyper-V identification is set in the HYPERV_CPUID_INTERFACE (0x40000001) 8464leaf. 8465 84668.34 KVM_CAP_EXIT_HYPERCALL 8467--------------------------- 8468 8469:Capability: KVM_CAP_EXIT_HYPERCALL 8470:Architectures: x86 8471:Type: vm 8472 8473This capability, if enabled, will cause KVM to exit to userspace 8474with KVM_EXIT_HYPERCALL exit reason to process some hypercalls. 8475 8476Calling KVM_CHECK_EXTENSION for this capability will return a bitmask 8477of hypercalls that can be configured to exit to userspace. 8478Right now, the only such hypercall is KVM_HC_MAP_GPA_RANGE. 8479 8480The argument to KVM_ENABLE_CAP is also a bitmask, and must be a subset 8481of the result of KVM_CHECK_EXTENSION. KVM will forward to userspace 8482the hypercalls whose corresponding bit is in the argument, and return 8483ENOSYS for the others. 8484 84858.35 KVM_CAP_PMU_CAPABILITY 8486--------------------------- 8487 8488:Capability: KVM_CAP_PMU_CAPABILITY 8489:Architectures: x86 8490:Type: vm 8491:Parameters: arg[0] is bitmask of PMU virtualization capabilities. 8492:Returns: 0 on success, -EINVAL when arg[0] contains invalid bits 8493 8494This capability alters PMU virtualization in KVM. 8495 8496Calling KVM_CHECK_EXTENSION for this capability returns a bitmask of 8497PMU virtualization capabilities that can be adjusted on a VM. 8498 8499The argument to KVM_ENABLE_CAP is also a bitmask and selects specific 8500PMU virtualization capabilities to be applied to the VM. This can 8501only be invoked on a VM prior to the creation of VCPUs. 8502 8503At this time, KVM_PMU_CAP_DISABLE is the only capability. Setting 8504this capability will disable PMU virtualization for that VM. Usermode 8505should adjust CPUID leaf 0xA to reflect that the PMU is disabled. 8506 85078.36 KVM_CAP_ARM_SYSTEM_SUSPEND 8508------------------------------- 8509 8510:Capability: KVM_CAP_ARM_SYSTEM_SUSPEND 8511:Architectures: arm64 8512:Type: vm 8513 8514When enabled, KVM will exit to userspace with KVM_EXIT_SYSTEM_EVENT of 8515type KVM_SYSTEM_EVENT_SUSPEND to process the guest suspend request. 8516 85178.37 KVM_CAP_S390_PROTECTED_DUMP 8518-------------------------------- 8519 8520:Capability: KVM_CAP_S390_PROTECTED_DUMP 8521:Architectures: s390 8522:Type: vm 8523 8524This capability indicates that KVM and the Ultravisor support dumping 8525PV guests. The `KVM_PV_DUMP` command is available for the 8526`KVM_S390_PV_COMMAND` ioctl and the `KVM_PV_INFO` command provides 8527dump related UV data. Also the vcpu ioctl `KVM_S390_PV_CPU_COMMAND` is 8528available and supports the `KVM_PV_DUMP_CPU` subcommand. 8529 85308.38 KVM_CAP_VM_DISABLE_NX_HUGE_PAGES 8531------------------------------------- 8532 8533:Capability: KVM_CAP_VM_DISABLE_NX_HUGE_PAGES 8534:Architectures: x86 8535:Type: vm 8536:Parameters: arg[0] must be 0. 8537:Returns: 0 on success, -EPERM if the userspace process does not 8538 have CAP_SYS_BOOT, -EINVAL if args[0] is not 0 or any vCPUs have been 8539 created. 8540 8541This capability disables the NX huge pages mitigation for iTLB MULTIHIT. 8542 8543The capability has no effect if the nx_huge_pages module parameter is not set. 8544 8545This capability may only be set before any vCPUs are created. 8546 85478.39 KVM_CAP_S390_CPU_TOPOLOGY 8548------------------------------ 8549 8550:Capability: KVM_CAP_S390_CPU_TOPOLOGY 8551:Architectures: s390 8552:Type: vm 8553 8554This capability indicates that KVM will provide the S390 CPU Topology 8555facility which consist of the interpretation of the PTF instruction for 8556the function code 2 along with interception and forwarding of both the 8557PTF instruction with function codes 0 or 1 and the STSI(15,1,x) 8558instruction to the userland hypervisor. 8559 8560The stfle facility 11, CPU Topology facility, should not be indicated 8561to the guest without this capability. 8562 8563When this capability is present, KVM provides a new attribute group 8564on vm fd, KVM_S390_VM_CPU_TOPOLOGY. 8565This new attribute allows to get, set or clear the Modified Change 8566Topology Report (MTCR) bit of the SCA through the kvm_device_attr 8567structure. 8568 8569When getting the Modified Change Topology Report value, the attr->addr 8570must point to a byte where the value will be stored or retrieved from. 8571 85728.40 KVM_CAP_ARM_EAGER_SPLIT_CHUNK_SIZE 8573--------------------------------------- 8574 8575:Capability: KVM_CAP_ARM_EAGER_SPLIT_CHUNK_SIZE 8576:Architectures: arm64 8577:Type: vm 8578:Parameters: arg[0] is the new split chunk size. 8579:Returns: 0 on success, -EINVAL if any memslot was already created. 8580 8581This capability sets the chunk size used in Eager Page Splitting. 8582 8583Eager Page Splitting improves the performance of dirty-logging (used 8584in live migrations) when guest memory is backed by huge-pages. It 8585avoids splitting huge-pages (into PAGE_SIZE pages) on fault, by doing 8586it eagerly when enabling dirty logging (with the 8587KVM_MEM_LOG_DIRTY_PAGES flag for a memory region), or when using 8588KVM_CLEAR_DIRTY_LOG. 8589 8590The chunk size specifies how many pages to break at a time, using a 8591single allocation for each chunk. Bigger the chunk size, more pages 8592need to be allocated ahead of time. 8593 8594The chunk size needs to be a valid block size. The list of acceptable 8595block sizes is exposed in KVM_CAP_ARM_SUPPORTED_BLOCK_SIZES as a 859664-bit bitmap (each bit describing a block size). The default value is 85970, to disable the eager page splitting. 8598 85999. Known KVM API problems 8600========================= 8601 8602In some cases, KVM's API has some inconsistencies or common pitfalls 8603that userspace need to be aware of. This section details some of 8604these issues. 8605 8606Most of them are architecture specific, so the section is split by 8607architecture. 8608 86099.1. x86 8610-------- 8611 8612``KVM_GET_SUPPORTED_CPUID`` issues 8613^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 8614 8615In general, ``KVM_GET_SUPPORTED_CPUID`` is designed so that it is possible 8616to take its result and pass it directly to ``KVM_SET_CPUID2``. This section 8617documents some cases in which that requires some care. 8618 8619Local APIC features 8620~~~~~~~~~~~~~~~~~~~ 8621 8622CPU[EAX=1]:ECX[21] (X2APIC) is reported by ``KVM_GET_SUPPORTED_CPUID``, 8623but it can only be enabled if ``KVM_CREATE_IRQCHIP`` or 8624``KVM_ENABLE_CAP(KVM_CAP_IRQCHIP_SPLIT)`` are used to enable in-kernel emulation of 8625the local APIC. 8626 8627The same is true for the ``KVM_FEATURE_PV_UNHALT`` paravirtualized feature. 8628 8629CPU[EAX=1]:ECX[24] (TSC_DEADLINE) is not reported by ``KVM_GET_SUPPORTED_CPUID``. 8630It can be enabled if ``KVM_CAP_TSC_DEADLINE_TIMER`` is present and the kernel 8631has enabled in-kernel emulation of the local APIC. 8632 8633CPU topology 8634~~~~~~~~~~~~ 8635 8636Several CPUID values include topology information for the host CPU: 86370x0b and 0x1f for Intel systems, 0x8000001e for AMD systems. Different 8638versions of KVM return different values for this information and userspace 8639should not rely on it. Currently they return all zeroes. 8640 8641If userspace wishes to set up a guest topology, it should be careful that 8642the values of these three leaves differ for each CPU. In particular, 8643the APIC ID is found in EDX for all subleaves of 0x0b and 0x1f, and in EAX 8644for 0x8000001e; the latter also encodes the core id and node id in bits 86457:0 of EBX and ECX respectively. 8646 8647Obsolete ioctls and capabilities 8648^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 8649 8650KVM_CAP_DISABLE_QUIRKS does not let userspace know which quirks are actually 8651available. Use ``KVM_CHECK_EXTENSION(KVM_CAP_DISABLE_QUIRKS2)`` instead if 8652available. 8653 8654Ordering of KVM_GET_*/KVM_SET_* ioctls 8655^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 8656 8657TBD 8658