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 althought 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 154To use hardware assisted virtualization on MIPS (VZ ASE) rather than 155the default trap & emulate implementation (which changes the virtual 156memory layout to fit in user mode), check KVM_CAP_MIPS_VZ and use the 157flag KVM_VM_MIPS_VZ. 158 159 160On arm64, the physical address size for a VM (IPA Size limit) is limited 161to 40bits by default. The limit can be configured if the host supports the 162extension KVM_CAP_ARM_VM_IPA_SIZE. When supported, use 163KVM_VM_TYPE_ARM_IPA_SIZE(IPA_Bits) to set the size in the machine type 164identifier, where IPA_Bits is the maximum width of any physical 165address used by the VM. The IPA_Bits is encoded in bits[7-0] of the 166machine type identifier. 167 168e.g, to configure a guest to use 48bit physical address size:: 169 170 vm_fd = ioctl(dev_fd, KVM_CREATE_VM, KVM_VM_TYPE_ARM_IPA_SIZE(48)); 171 172The requested size (IPA_Bits) must be: 173 174 == ========================================================= 175 0 Implies default size, 40bits (for backward compatibility) 176 N Implies N bits, where N is a positive integer such that, 177 32 <= N <= Host_IPA_Limit 178 == ========================================================= 179 180Host_IPA_Limit is the maximum possible value for IPA_Bits on the host and 181is dependent on the CPU capability and the kernel configuration. The limit can 182be retrieved using KVM_CAP_ARM_VM_IPA_SIZE of the KVM_CHECK_EXTENSION 183ioctl() at run-time. 184 185Please note that configuring the IPA size does not affect the capability 186exposed by the guest CPUs in ID_AA64MMFR0_EL1[PARange]. It only affects 187size of the address translated by the stage2 level (guest physical to 188host physical address translations). 189 190 1914.3 KVM_GET_MSR_INDEX_LIST, KVM_GET_MSR_FEATURE_INDEX_LIST 192---------------------------------------------------------- 193 194:Capability: basic, KVM_CAP_GET_MSR_FEATURES for KVM_GET_MSR_FEATURE_INDEX_LIST 195:Architectures: x86 196:Type: system ioctl 197:Parameters: struct kvm_msr_list (in/out) 198:Returns: 0 on success; -1 on error 199 200Errors: 201 202 ====== ============================================================ 203 EFAULT the msr index list cannot be read from or written to 204 E2BIG the msr index list is to be to fit in the array specified by 205 the user. 206 ====== ============================================================ 207 208:: 209 210 struct kvm_msr_list { 211 __u32 nmsrs; /* number of msrs in entries */ 212 __u32 indices[0]; 213 }; 214 215The user fills in the size of the indices array in nmsrs, and in return 216kvm adjusts nmsrs to reflect the actual number of msrs and fills in the 217indices array with their numbers. 218 219KVM_GET_MSR_INDEX_LIST returns the guest msrs that are supported. The list 220varies by kvm version and host processor, but does not change otherwise. 221 222Note: if kvm indicates supports MCE (KVM_CAP_MCE), then the MCE bank MSRs are 223not returned in the MSR list, as different vcpus can have a different number 224of banks, as set via the KVM_X86_SETUP_MCE ioctl. 225 226KVM_GET_MSR_FEATURE_INDEX_LIST returns the list of MSRs that can be passed 227to the KVM_GET_MSRS system ioctl. This lets userspace probe host capabilities 228and processor features that are exposed via MSRs (e.g., VMX capabilities). 229This list also varies by kvm version and host processor, but does not change 230otherwise. 231 232 2334.4 KVM_CHECK_EXTENSION 234----------------------- 235 236:Capability: basic, KVM_CAP_CHECK_EXTENSION_VM for vm ioctl 237:Architectures: all 238:Type: system ioctl, vm ioctl 239:Parameters: extension identifier (KVM_CAP_*) 240:Returns: 0 if unsupported; 1 (or some other positive integer) if supported 241 242The API allows the application to query about extensions to the core 243kvm API. Userspace passes an extension identifier (an integer) and 244receives an integer that describes the extension availability. 245Generally 0 means no and 1 means yes, but some extensions may report 246additional information in the integer return value. 247 248Based on their initialization different VMs may have different capabilities. 249It is thus encouraged to use the vm ioctl to query for capabilities (available 250with KVM_CAP_CHECK_EXTENSION_VM on the vm fd) 251 2524.5 KVM_GET_VCPU_MMAP_SIZE 253-------------------------- 254 255:Capability: basic 256:Architectures: all 257:Type: system ioctl 258:Parameters: none 259:Returns: size of vcpu mmap area, in bytes 260 261The KVM_RUN ioctl (cf.) communicates with userspace via a shared 262memory region. This ioctl returns the size of that region. See the 263KVM_RUN documentation for details. 264 265Besides the size of the KVM_RUN communication region, other areas of 266the VCPU file descriptor can be mmap-ed, including: 267 268- if KVM_CAP_COALESCED_MMIO is available, a page at 269 KVM_COALESCED_MMIO_PAGE_OFFSET * PAGE_SIZE; for historical reasons, 270 this page is included in the result of KVM_GET_VCPU_MMAP_SIZE. 271 KVM_CAP_COALESCED_MMIO is not documented yet. 272 273- if KVM_CAP_DIRTY_LOG_RING is available, a number of pages at 274 KVM_DIRTY_LOG_PAGE_OFFSET * PAGE_SIZE. For more information on 275 KVM_CAP_DIRTY_LOG_RING, see section 8.3. 276 277 2784.6 KVM_SET_MEMORY_REGION 279------------------------- 280 281:Capability: basic 282:Architectures: all 283:Type: vm ioctl 284:Parameters: struct kvm_memory_region (in) 285:Returns: 0 on success, -1 on error 286 287This ioctl is obsolete and has been removed. 288 289 2904.7 KVM_CREATE_VCPU 291------------------- 292 293:Capability: basic 294:Architectures: all 295:Type: vm ioctl 296:Parameters: vcpu id (apic id on x86) 297:Returns: vcpu fd on success, -1 on error 298 299This API adds a vcpu to a virtual machine. No more than max_vcpus may be added. 300The vcpu id is an integer in the range [0, max_vcpu_id). 301 302The recommended max_vcpus value can be retrieved using the KVM_CAP_NR_VCPUS of 303the KVM_CHECK_EXTENSION ioctl() at run-time. 304The maximum possible value for max_vcpus can be retrieved using the 305KVM_CAP_MAX_VCPUS of the KVM_CHECK_EXTENSION ioctl() at run-time. 306 307If the KVM_CAP_NR_VCPUS does not exist, you should assume that max_vcpus is 4 308cpus max. 309If the KVM_CAP_MAX_VCPUS does not exist, you should assume that max_vcpus is 310same as the value returned from KVM_CAP_NR_VCPUS. 311 312The maximum possible value for max_vcpu_id can be retrieved using the 313KVM_CAP_MAX_VCPU_ID of the KVM_CHECK_EXTENSION ioctl() at run-time. 314 315If the KVM_CAP_MAX_VCPU_ID does not exist, you should assume that max_vcpu_id 316is the same as the value returned from KVM_CAP_MAX_VCPUS. 317 318On powerpc using book3s_hv mode, the vcpus are mapped onto virtual 319threads in one or more virtual CPU cores. (This is because the 320hardware requires all the hardware threads in a CPU core to be in the 321same partition.) The KVM_CAP_PPC_SMT capability indicates the number 322of vcpus per virtual core (vcore). The vcore id is obtained by 323dividing the vcpu id by the number of vcpus per vcore. The vcpus in a 324given vcore will always be in the same physical core as each other 325(though that might be a different physical core from time to time). 326Userspace can control the threading (SMT) mode of the guest by its 327allocation of vcpu ids. For example, if userspace wants 328single-threaded guest vcpus, it should make all vcpu ids be a multiple 329of the number of vcpus per vcore. 330 331For virtual cpus that have been created with S390 user controlled virtual 332machines, the resulting vcpu fd can be memory mapped at page offset 333KVM_S390_SIE_PAGE_OFFSET in order to obtain a memory map of the virtual 334cpu's hardware control block. 335 336 3374.8 KVM_GET_DIRTY_LOG (vm ioctl) 338-------------------------------- 339 340:Capability: basic 341:Architectures: all 342:Type: vm ioctl 343:Parameters: struct kvm_dirty_log (in/out) 344:Returns: 0 on success, -1 on error 345 346:: 347 348 /* for KVM_GET_DIRTY_LOG */ 349 struct kvm_dirty_log { 350 __u32 slot; 351 __u32 padding; 352 union { 353 void __user *dirty_bitmap; /* one bit per page */ 354 __u64 padding; 355 }; 356 }; 357 358Given a memory slot, return a bitmap containing any pages dirtied 359since the last call to this ioctl. Bit 0 is the first page in the 360memory slot. Ensure the entire structure is cleared to avoid padding 361issues. 362 363If KVM_CAP_MULTI_ADDRESS_SPACE is available, bits 16-31 specifies 364the address space for which you want to return the dirty bitmap. 365They must be less than the value that KVM_CHECK_EXTENSION returns for 366the KVM_CAP_MULTI_ADDRESS_SPACE capability. 367 368The bits in the dirty bitmap are cleared before the ioctl returns, unless 369KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2 is enabled. For more information, 370see the description of the capability. 371 3724.9 KVM_SET_MEMORY_ALIAS 373------------------------ 374 375:Capability: basic 376:Architectures: x86 377:Type: vm ioctl 378:Parameters: struct kvm_memory_alias (in) 379:Returns: 0 (success), -1 (error) 380 381This ioctl is obsolete and has been removed. 382 383 3844.10 KVM_RUN 385------------ 386 387:Capability: basic 388:Architectures: all 389:Type: vcpu ioctl 390:Parameters: none 391:Returns: 0 on success, -1 on error 392 393Errors: 394 395 ===== ============================= 396 EINTR an unmasked signal is pending 397 ===== ============================= 398 399This ioctl is used to run a guest virtual cpu. While there are no 400explicit parameters, there is an implicit parameter block that can be 401obtained by mmap()ing the vcpu fd at offset 0, with the size given by 402KVM_GET_VCPU_MMAP_SIZE. The parameter block is formatted as a 'struct 403kvm_run' (see below). 404 405 4064.11 KVM_GET_REGS 407----------------- 408 409:Capability: basic 410:Architectures: all except ARM, arm64 411:Type: vcpu ioctl 412:Parameters: struct kvm_regs (out) 413:Returns: 0 on success, -1 on error 414 415Reads the general purpose registers from the vcpu. 416 417:: 418 419 /* x86 */ 420 struct kvm_regs { 421 /* out (KVM_GET_REGS) / in (KVM_SET_REGS) */ 422 __u64 rax, rbx, rcx, rdx; 423 __u64 rsi, rdi, rsp, rbp; 424 __u64 r8, r9, r10, r11; 425 __u64 r12, r13, r14, r15; 426 __u64 rip, rflags; 427 }; 428 429 /* mips */ 430 struct kvm_regs { 431 /* out (KVM_GET_REGS) / in (KVM_SET_REGS) */ 432 __u64 gpr[32]; 433 __u64 hi; 434 __u64 lo; 435 __u64 pc; 436 }; 437 438 4394.12 KVM_SET_REGS 440----------------- 441 442:Capability: basic 443:Architectures: all except ARM, arm64 444:Type: vcpu ioctl 445:Parameters: struct kvm_regs (in) 446:Returns: 0 on success, -1 on error 447 448Writes the general purpose registers into the vcpu. 449 450See KVM_GET_REGS for the data structure. 451 452 4534.13 KVM_GET_SREGS 454------------------ 455 456:Capability: basic 457:Architectures: x86, ppc 458:Type: vcpu ioctl 459:Parameters: struct kvm_sregs (out) 460:Returns: 0 on success, -1 on error 461 462Reads special registers from the vcpu. 463 464:: 465 466 /* x86 */ 467 struct kvm_sregs { 468 struct kvm_segment cs, ds, es, fs, gs, ss; 469 struct kvm_segment tr, ldt; 470 struct kvm_dtable gdt, idt; 471 __u64 cr0, cr2, cr3, cr4, cr8; 472 __u64 efer; 473 __u64 apic_base; 474 __u64 interrupt_bitmap[(KVM_NR_INTERRUPTS + 63) / 64]; 475 }; 476 477 /* ppc -- see arch/powerpc/include/uapi/asm/kvm.h */ 478 479interrupt_bitmap is a bitmap of pending external interrupts. At most 480one bit may be set. This interrupt has been acknowledged by the APIC 481but not yet injected into the cpu core. 482 483 4844.14 KVM_SET_SREGS 485------------------ 486 487:Capability: basic 488:Architectures: x86, ppc 489:Type: vcpu ioctl 490:Parameters: struct kvm_sregs (in) 491:Returns: 0 on success, -1 on error 492 493Writes special registers into the vcpu. See KVM_GET_SREGS for the 494data structures. 495 496 4974.15 KVM_TRANSLATE 498------------------ 499 500:Capability: basic 501:Architectures: x86 502:Type: vcpu ioctl 503:Parameters: struct kvm_translation (in/out) 504:Returns: 0 on success, -1 on error 505 506Translates a virtual address according to the vcpu's current address 507translation mode. 508 509:: 510 511 struct kvm_translation { 512 /* in */ 513 __u64 linear_address; 514 515 /* out */ 516 __u64 physical_address; 517 __u8 valid; 518 __u8 writeable; 519 __u8 usermode; 520 __u8 pad[5]; 521 }; 522 523 5244.16 KVM_INTERRUPT 525------------------ 526 527:Capability: basic 528:Architectures: x86, ppc, mips 529:Type: vcpu ioctl 530:Parameters: struct kvm_interrupt (in) 531:Returns: 0 on success, negative on failure. 532 533Queues a hardware interrupt vector to be injected. 534 535:: 536 537 /* for KVM_INTERRUPT */ 538 struct kvm_interrupt { 539 /* in */ 540 __u32 irq; 541 }; 542 543X86: 544^^^^ 545 546:Returns: 547 548 ========= =================================== 549 0 on success, 550 -EEXIST if an interrupt is already enqueued 551 -EINVAL the irq number is invalid 552 -ENXIO if the PIC is in the kernel 553 -EFAULT if the pointer is invalid 554 ========= =================================== 555 556Note 'irq' is an interrupt vector, not an interrupt pin or line. This 557ioctl is useful if the in-kernel PIC is not used. 558 559PPC: 560^^^^ 561 562Queues an external interrupt to be injected. This ioctl is overleaded 563with 3 different irq values: 564 565a) KVM_INTERRUPT_SET 566 567 This injects an edge type external interrupt into the guest once it's ready 568 to receive interrupts. When injected, the interrupt is done. 569 570b) KVM_INTERRUPT_UNSET 571 572 This unsets any pending interrupt. 573 574 Only available with KVM_CAP_PPC_UNSET_IRQ. 575 576c) KVM_INTERRUPT_SET_LEVEL 577 578 This injects a level type external interrupt into the guest context. The 579 interrupt stays pending until a specific ioctl with KVM_INTERRUPT_UNSET 580 is triggered. 581 582 Only available with KVM_CAP_PPC_IRQ_LEVEL. 583 584Note that any value for 'irq' other than the ones stated above is invalid 585and incurs unexpected behavior. 586 587This is an asynchronous vcpu ioctl and can be invoked from any thread. 588 589MIPS: 590^^^^^ 591 592Queues an external interrupt to be injected into the virtual CPU. A negative 593interrupt number dequeues the interrupt. 594 595This is an asynchronous vcpu ioctl and can be invoked from any thread. 596 597 5984.17 KVM_DEBUG_GUEST 599-------------------- 600 601:Capability: basic 602:Architectures: none 603:Type: vcpu ioctl 604:Parameters: none) 605:Returns: -1 on error 606 607Support for this has been removed. Use KVM_SET_GUEST_DEBUG instead. 608 609 6104.18 KVM_GET_MSRS 611----------------- 612 613:Capability: basic (vcpu), KVM_CAP_GET_MSR_FEATURES (system) 614:Architectures: x86 615:Type: system ioctl, vcpu ioctl 616:Parameters: struct kvm_msrs (in/out) 617:Returns: number of msrs successfully returned; 618 -1 on error 619 620When used as a system ioctl: 621Reads the values of MSR-based features that are available for the VM. This 622is similar to KVM_GET_SUPPORTED_CPUID, but it returns MSR indices and values. 623The list of msr-based features can be obtained using KVM_GET_MSR_FEATURE_INDEX_LIST 624in a system ioctl. 625 626When used as a vcpu ioctl: 627Reads model-specific registers from the vcpu. Supported msr indices can 628be obtained using KVM_GET_MSR_INDEX_LIST in a system ioctl. 629 630:: 631 632 struct kvm_msrs { 633 __u32 nmsrs; /* number of msrs in entries */ 634 __u32 pad; 635 636 struct kvm_msr_entry entries[0]; 637 }; 638 639 struct kvm_msr_entry { 640 __u32 index; 641 __u32 reserved; 642 __u64 data; 643 }; 644 645Application code should set the 'nmsrs' member (which indicates the 646size of the entries array) and the 'index' member of each array entry. 647kvm will fill in the 'data' member. 648 649 6504.19 KVM_SET_MSRS 651----------------- 652 653:Capability: basic 654:Architectures: x86 655:Type: vcpu ioctl 656:Parameters: struct kvm_msrs (in) 657:Returns: number of msrs successfully set (see below), -1 on error 658 659Writes model-specific registers to the vcpu. See KVM_GET_MSRS for the 660data structures. 661 662Application code should set the 'nmsrs' member (which indicates the 663size of the entries array), and the 'index' and 'data' members of each 664array entry. 665 666It tries to set the MSRs in array entries[] one by one. If setting an MSR 667fails, e.g., due to setting reserved bits, the MSR isn't supported/emulated 668by KVM, etc..., it stops processing the MSR list and returns the number of 669MSRs that have been set successfully. 670 671 6724.20 KVM_SET_CPUID 673------------------ 674 675:Capability: basic 676:Architectures: x86 677:Type: vcpu ioctl 678:Parameters: struct kvm_cpuid (in) 679:Returns: 0 on success, -1 on error 680 681Defines the vcpu responses to the cpuid instruction. Applications 682should use the KVM_SET_CPUID2 ioctl if available. 683 684Note, when this IOCTL fails, KVM gives no guarantees that previous valid CPUID 685configuration (if there is) is not corrupted. Userspace can get a copy of the 686resulting CPUID configuration through KVM_GET_CPUID2 in case. 687 688:: 689 690 struct kvm_cpuid_entry { 691 __u32 function; 692 __u32 eax; 693 __u32 ebx; 694 __u32 ecx; 695 __u32 edx; 696 __u32 padding; 697 }; 698 699 /* for KVM_SET_CPUID */ 700 struct kvm_cpuid { 701 __u32 nent; 702 __u32 padding; 703 struct kvm_cpuid_entry entries[0]; 704 }; 705 706 7074.21 KVM_SET_SIGNAL_MASK 708------------------------ 709 710:Capability: basic 711:Architectures: all 712:Type: vcpu ioctl 713:Parameters: struct kvm_signal_mask (in) 714:Returns: 0 on success, -1 on error 715 716Defines which signals are blocked during execution of KVM_RUN. This 717signal mask temporarily overrides the threads signal mask. Any 718unblocked signal received (except SIGKILL and SIGSTOP, which retain 719their traditional behaviour) will cause KVM_RUN to return with -EINTR. 720 721Note the signal will only be delivered if not blocked by the original 722signal mask. 723 724:: 725 726 /* for KVM_SET_SIGNAL_MASK */ 727 struct kvm_signal_mask { 728 __u32 len; 729 __u8 sigset[0]; 730 }; 731 732 7334.22 KVM_GET_FPU 734---------------- 735 736:Capability: basic 737:Architectures: x86 738:Type: vcpu ioctl 739:Parameters: struct kvm_fpu (out) 740:Returns: 0 on success, -1 on error 741 742Reads the floating point state from the vcpu. 743 744:: 745 746 /* for KVM_GET_FPU and KVM_SET_FPU */ 747 struct kvm_fpu { 748 __u8 fpr[8][16]; 749 __u16 fcw; 750 __u16 fsw; 751 __u8 ftwx; /* in fxsave format */ 752 __u8 pad1; 753 __u16 last_opcode; 754 __u64 last_ip; 755 __u64 last_dp; 756 __u8 xmm[16][16]; 757 __u32 mxcsr; 758 __u32 pad2; 759 }; 760 761 7624.23 KVM_SET_FPU 763---------------- 764 765:Capability: basic 766:Architectures: x86 767:Type: vcpu ioctl 768:Parameters: struct kvm_fpu (in) 769:Returns: 0 on success, -1 on error 770 771Writes the floating point state to the vcpu. 772 773:: 774 775 /* for KVM_GET_FPU and KVM_SET_FPU */ 776 struct kvm_fpu { 777 __u8 fpr[8][16]; 778 __u16 fcw; 779 __u16 fsw; 780 __u8 ftwx; /* in fxsave format */ 781 __u8 pad1; 782 __u16 last_opcode; 783 __u64 last_ip; 784 __u64 last_dp; 785 __u8 xmm[16][16]; 786 __u32 mxcsr; 787 __u32 pad2; 788 }; 789 790 7914.24 KVM_CREATE_IRQCHIP 792----------------------- 793 794:Capability: KVM_CAP_IRQCHIP, KVM_CAP_S390_IRQCHIP (s390) 795:Architectures: x86, ARM, arm64, s390 796:Type: vm ioctl 797:Parameters: none 798:Returns: 0 on success, -1 on error 799 800Creates an interrupt controller model in the kernel. 801On x86, creates a virtual ioapic, a virtual PIC (two PICs, nested), and sets up 802future vcpus to have a local APIC. IRQ routing for GSIs 0-15 is set to both 803PIC and IOAPIC; GSI 16-23 only go to the IOAPIC. 804On ARM/arm64, a GICv2 is created. Any other GIC versions require the usage of 805KVM_CREATE_DEVICE, which also supports creating a GICv2. Using 806KVM_CREATE_DEVICE is preferred over KVM_CREATE_IRQCHIP for GICv2. 807On s390, a dummy irq routing table is created. 808 809Note that on s390 the KVM_CAP_S390_IRQCHIP vm capability needs to be enabled 810before KVM_CREATE_IRQCHIP can be used. 811 812 8134.25 KVM_IRQ_LINE 814----------------- 815 816:Capability: KVM_CAP_IRQCHIP 817:Architectures: x86, arm, arm64 818:Type: vm ioctl 819:Parameters: struct kvm_irq_level 820:Returns: 0 on success, -1 on error 821 822Sets the level of a GSI input to the interrupt controller model in the kernel. 823On some architectures it is required that an interrupt controller model has 824been previously created with KVM_CREATE_IRQCHIP. Note that edge-triggered 825interrupts require the level to be set to 1 and then back to 0. 826 827On real hardware, interrupt pins can be active-low or active-high. This 828does not matter for the level field of struct kvm_irq_level: 1 always 829means active (asserted), 0 means inactive (deasserted). 830 831x86 allows the operating system to program the interrupt polarity 832(active-low/active-high) for level-triggered interrupts, and KVM used 833to consider the polarity. However, due to bitrot in the handling of 834active-low interrupts, the above convention is now valid on x86 too. 835This is signaled by KVM_CAP_X86_IOAPIC_POLARITY_IGNORED. Userspace 836should not present interrupts to the guest as active-low unless this 837capability is present (or unless it is not using the in-kernel irqchip, 838of course). 839 840 841ARM/arm64 can signal an interrupt either at the CPU level, or at the 842in-kernel irqchip (GIC), and for in-kernel irqchip can tell the GIC to 843use PPIs designated for specific cpus. The irq field is interpreted 844like this:: 845 846 bits: | 31 ... 28 | 27 ... 24 | 23 ... 16 | 15 ... 0 | 847 field: | vcpu2_index | irq_type | vcpu_index | irq_id | 848 849The irq_type field has the following values: 850 851- irq_type[0]: 852 out-of-kernel GIC: irq_id 0 is IRQ, irq_id 1 is FIQ 853- irq_type[1]: 854 in-kernel GIC: SPI, irq_id between 32 and 1019 (incl.) 855 (the vcpu_index field is ignored) 856- irq_type[2]: 857 in-kernel GIC: PPI, irq_id between 16 and 31 (incl.) 858 859(The irq_id field thus corresponds nicely to the IRQ ID in the ARM GIC specs) 860 861In both cases, level is used to assert/deassert the line. 862 863When KVM_CAP_ARM_IRQ_LINE_LAYOUT_2 is supported, the target vcpu is 864identified as (256 * vcpu2_index + vcpu_index). Otherwise, vcpu2_index 865must be zero. 866 867Note that on arm/arm64, the KVM_CAP_IRQCHIP capability only conditions 868injection of interrupts for the in-kernel irqchip. KVM_IRQ_LINE can always 869be used for a userspace interrupt controller. 870 871:: 872 873 struct kvm_irq_level { 874 union { 875 __u32 irq; /* GSI */ 876 __s32 status; /* not used for KVM_IRQ_LEVEL */ 877 }; 878 __u32 level; /* 0 or 1 */ 879 }; 880 881 8824.26 KVM_GET_IRQCHIP 883-------------------- 884 885:Capability: KVM_CAP_IRQCHIP 886:Architectures: x86 887:Type: vm ioctl 888:Parameters: struct kvm_irqchip (in/out) 889:Returns: 0 on success, -1 on error 890 891Reads the state of a kernel interrupt controller created with 892KVM_CREATE_IRQCHIP into a buffer provided by the caller. 893 894:: 895 896 struct kvm_irqchip { 897 __u32 chip_id; /* 0 = PIC1, 1 = PIC2, 2 = IOAPIC */ 898 __u32 pad; 899 union { 900 char dummy[512]; /* reserving space */ 901 struct kvm_pic_state pic; 902 struct kvm_ioapic_state ioapic; 903 } chip; 904 }; 905 906 9074.27 KVM_SET_IRQCHIP 908-------------------- 909 910:Capability: KVM_CAP_IRQCHIP 911:Architectures: x86 912:Type: vm ioctl 913:Parameters: struct kvm_irqchip (in) 914:Returns: 0 on success, -1 on error 915 916Sets the state of a kernel interrupt controller created with 917KVM_CREATE_IRQCHIP from a buffer provided by the caller. 918 919:: 920 921 struct kvm_irqchip { 922 __u32 chip_id; /* 0 = PIC1, 1 = PIC2, 2 = IOAPIC */ 923 __u32 pad; 924 union { 925 char dummy[512]; /* reserving space */ 926 struct kvm_pic_state pic; 927 struct kvm_ioapic_state ioapic; 928 } chip; 929 }; 930 931 9324.28 KVM_XEN_HVM_CONFIG 933----------------------- 934 935:Capability: KVM_CAP_XEN_HVM 936:Architectures: x86 937:Type: vm ioctl 938:Parameters: struct kvm_xen_hvm_config (in) 939:Returns: 0 on success, -1 on error 940 941Sets the MSR that the Xen HVM guest uses to initialize its hypercall 942page, and provides the starting address and size of the hypercall 943blobs in userspace. When the guest writes the MSR, kvm copies one 944page of a blob (32- or 64-bit, depending on the vcpu mode) to guest 945memory. 946 947:: 948 949 struct kvm_xen_hvm_config { 950 __u32 flags; 951 __u32 msr; 952 __u64 blob_addr_32; 953 __u64 blob_addr_64; 954 __u8 blob_size_32; 955 __u8 blob_size_64; 956 __u8 pad2[30]; 957 }; 958 959 9604.29 KVM_GET_CLOCK 961------------------ 962 963:Capability: KVM_CAP_ADJUST_CLOCK 964:Architectures: x86 965:Type: vm ioctl 966:Parameters: struct kvm_clock_data (out) 967:Returns: 0 on success, -1 on error 968 969Gets the current timestamp of kvmclock as seen by the current guest. In 970conjunction with KVM_SET_CLOCK, it is used to ensure monotonicity on scenarios 971such as migration. 972 973When KVM_CAP_ADJUST_CLOCK is passed to KVM_CHECK_EXTENSION, it returns the 974set of bits that KVM can return in struct kvm_clock_data's flag member. 975 976The only flag defined now is KVM_CLOCK_TSC_STABLE. If set, the returned 977value is the exact kvmclock value seen by all VCPUs at the instant 978when KVM_GET_CLOCK was called. If clear, the returned value is simply 979CLOCK_MONOTONIC plus a constant offset; the offset can be modified 980with KVM_SET_CLOCK. KVM will try to make all VCPUs follow this clock, 981but the exact value read by each VCPU could differ, because the host 982TSC is not stable. 983 984:: 985 986 struct kvm_clock_data { 987 __u64 clock; /* kvmclock current value */ 988 __u32 flags; 989 __u32 pad[9]; 990 }; 991 992 9934.30 KVM_SET_CLOCK 994------------------ 995 996:Capability: KVM_CAP_ADJUST_CLOCK 997:Architectures: x86 998:Type: vm ioctl 999:Parameters: struct kvm_clock_data (in) 1000:Returns: 0 on success, -1 on error 1001 1002Sets the current timestamp of kvmclock to the value specified in its parameter. 1003In conjunction with KVM_GET_CLOCK, it is used to ensure monotonicity on scenarios 1004such as migration. 1005 1006:: 1007 1008 struct kvm_clock_data { 1009 __u64 clock; /* kvmclock current value */ 1010 __u32 flags; 1011 __u32 pad[9]; 1012 }; 1013 1014 10154.31 KVM_GET_VCPU_EVENTS 1016------------------------ 1017 1018:Capability: KVM_CAP_VCPU_EVENTS 1019:Extended by: KVM_CAP_INTR_SHADOW 1020:Architectures: x86, arm, arm64 1021:Type: vcpu ioctl 1022:Parameters: struct kvm_vcpu_event (out) 1023:Returns: 0 on success, -1 on error 1024 1025X86: 1026^^^^ 1027 1028Gets currently pending exceptions, interrupts, and NMIs as well as related 1029states of the vcpu. 1030 1031:: 1032 1033 struct kvm_vcpu_events { 1034 struct { 1035 __u8 injected; 1036 __u8 nr; 1037 __u8 has_error_code; 1038 __u8 pending; 1039 __u32 error_code; 1040 } exception; 1041 struct { 1042 __u8 injected; 1043 __u8 nr; 1044 __u8 soft; 1045 __u8 shadow; 1046 } interrupt; 1047 struct { 1048 __u8 injected; 1049 __u8 pending; 1050 __u8 masked; 1051 __u8 pad; 1052 } nmi; 1053 __u32 sipi_vector; 1054 __u32 flags; 1055 struct { 1056 __u8 smm; 1057 __u8 pending; 1058 __u8 smm_inside_nmi; 1059 __u8 latched_init; 1060 } smi; 1061 __u8 reserved[27]; 1062 __u8 exception_has_payload; 1063 __u64 exception_payload; 1064 }; 1065 1066The following bits are defined in the flags field: 1067 1068- KVM_VCPUEVENT_VALID_SHADOW may be set to signal that 1069 interrupt.shadow contains a valid state. 1070 1071- KVM_VCPUEVENT_VALID_SMM may be set to signal that smi contains a 1072 valid state. 1073 1074- KVM_VCPUEVENT_VALID_PAYLOAD may be set to signal that the 1075 exception_has_payload, exception_payload, and exception.pending 1076 fields contain a valid state. This bit will be set whenever 1077 KVM_CAP_EXCEPTION_PAYLOAD is enabled. 1078 1079ARM/ARM64: 1080^^^^^^^^^^ 1081 1082If the guest accesses a device that is being emulated by the host kernel in 1083such a way that a real device would generate a physical SError, KVM may make 1084a virtual SError pending for that VCPU. This system error interrupt remains 1085pending until the guest takes the exception by unmasking PSTATE.A. 1086 1087Running the VCPU may cause it to take a pending SError, or make an access that 1088causes an SError to become pending. The event's description is only valid while 1089the VPCU is not running. 1090 1091This API provides a way to read and write the pending 'event' state that is not 1092visible to the guest. To save, restore or migrate a VCPU the struct representing 1093the state can be read then written using this GET/SET API, along with the other 1094guest-visible registers. It is not possible to 'cancel' an SError that has been 1095made pending. 1096 1097A device being emulated in user-space may also wish to generate an SError. To do 1098this the events structure can be populated by user-space. The current state 1099should be read first, to ensure no existing SError is pending. If an existing 1100SError is pending, the architecture's 'Multiple SError interrupts' rules should 1101be followed. (2.5.3 of DDI0587.a "ARM Reliability, Availability, and 1102Serviceability (RAS) Specification"). 1103 1104SError exceptions always have an ESR value. Some CPUs have the ability to 1105specify what the virtual SError's ESR value should be. These systems will 1106advertise KVM_CAP_ARM_INJECT_SERROR_ESR. In this case exception.has_esr will 1107always have a non-zero value when read, and the agent making an SError pending 1108should specify the ISS field in the lower 24 bits of exception.serror_esr. If 1109the system supports KVM_CAP_ARM_INJECT_SERROR_ESR, but user-space sets the events 1110with exception.has_esr as zero, KVM will choose an ESR. 1111 1112Specifying exception.has_esr on a system that does not support it will return 1113-EINVAL. Setting anything other than the lower 24bits of exception.serror_esr 1114will return -EINVAL. 1115 1116It is not possible to read back a pending external abort (injected via 1117KVM_SET_VCPU_EVENTS or otherwise) because such an exception is always delivered 1118directly to the virtual CPU). 1119 1120:: 1121 1122 struct kvm_vcpu_events { 1123 struct { 1124 __u8 serror_pending; 1125 __u8 serror_has_esr; 1126 __u8 ext_dabt_pending; 1127 /* Align it to 8 bytes */ 1128 __u8 pad[5]; 1129 __u64 serror_esr; 1130 } exception; 1131 __u32 reserved[12]; 1132 }; 1133 11344.32 KVM_SET_VCPU_EVENTS 1135------------------------ 1136 1137:Capability: KVM_CAP_VCPU_EVENTS 1138:Extended by: KVM_CAP_INTR_SHADOW 1139:Architectures: x86, arm, arm64 1140:Type: vcpu ioctl 1141:Parameters: struct kvm_vcpu_event (in) 1142:Returns: 0 on success, -1 on error 1143 1144X86: 1145^^^^ 1146 1147Set pending exceptions, interrupts, and NMIs as well as related states of the 1148vcpu. 1149 1150See KVM_GET_VCPU_EVENTS for the data structure. 1151 1152Fields that may be modified asynchronously by running VCPUs can be excluded 1153from the update. These fields are nmi.pending, sipi_vector, smi.smm, 1154smi.pending. Keep the corresponding bits in the flags field cleared to 1155suppress overwriting the current in-kernel state. The bits are: 1156 1157=============================== ================================== 1158KVM_VCPUEVENT_VALID_NMI_PENDING transfer nmi.pending to the kernel 1159KVM_VCPUEVENT_VALID_SIPI_VECTOR transfer sipi_vector 1160KVM_VCPUEVENT_VALID_SMM transfer the smi sub-struct. 1161=============================== ================================== 1162 1163If KVM_CAP_INTR_SHADOW is available, KVM_VCPUEVENT_VALID_SHADOW can be set in 1164the flags field to signal that interrupt.shadow contains a valid state and 1165shall be written into the VCPU. 1166 1167KVM_VCPUEVENT_VALID_SMM can only be set if KVM_CAP_X86_SMM is available. 1168 1169If KVM_CAP_EXCEPTION_PAYLOAD is enabled, KVM_VCPUEVENT_VALID_PAYLOAD 1170can be set in the flags field to signal that the 1171exception_has_payload, exception_payload, and exception.pending fields 1172contain a valid state and shall be written into the VCPU. 1173 1174ARM/ARM64: 1175^^^^^^^^^^ 1176 1177User space may need to inject several types of events to the guest. 1178 1179Set the pending SError exception state for this VCPU. It is not possible to 1180'cancel' an Serror that has been made pending. 1181 1182If the guest performed an access to I/O memory which could not be handled by 1183userspace, for example because of missing instruction syndrome decode 1184information or because there is no device mapped at the accessed IPA, then 1185userspace can ask the kernel to inject an external abort using the address 1186from the exiting fault on the VCPU. It is a programming error to set 1187ext_dabt_pending after an exit which was not either KVM_EXIT_MMIO or 1188KVM_EXIT_ARM_NISV. This feature is only available if the system supports 1189KVM_CAP_ARM_INJECT_EXT_DABT. This is a helper which provides commonality in 1190how userspace reports accesses for the above cases to guests, across different 1191userspace implementations. Nevertheless, userspace can still emulate all Arm 1192exceptions by manipulating individual registers using the KVM_SET_ONE_REG API. 1193 1194See KVM_GET_VCPU_EVENTS for the data structure. 1195 1196 11974.33 KVM_GET_DEBUGREGS 1198---------------------- 1199 1200:Capability: KVM_CAP_DEBUGREGS 1201:Architectures: x86 1202:Type: vm ioctl 1203:Parameters: struct kvm_debugregs (out) 1204:Returns: 0 on success, -1 on error 1205 1206Reads debug registers from the vcpu. 1207 1208:: 1209 1210 struct kvm_debugregs { 1211 __u64 db[4]; 1212 __u64 dr6; 1213 __u64 dr7; 1214 __u64 flags; 1215 __u64 reserved[9]; 1216 }; 1217 1218 12194.34 KVM_SET_DEBUGREGS 1220---------------------- 1221 1222:Capability: KVM_CAP_DEBUGREGS 1223:Architectures: x86 1224:Type: vm ioctl 1225:Parameters: struct kvm_debugregs (in) 1226:Returns: 0 on success, -1 on error 1227 1228Writes debug registers into the vcpu. 1229 1230See KVM_GET_DEBUGREGS for the data structure. The flags field is unused 1231yet and must be cleared on entry. 1232 1233 12344.35 KVM_SET_USER_MEMORY_REGION 1235------------------------------- 1236 1237:Capability: KVM_CAP_USER_MEMORY 1238:Architectures: all 1239:Type: vm ioctl 1240:Parameters: struct kvm_userspace_memory_region (in) 1241:Returns: 0 on success, -1 on error 1242 1243:: 1244 1245 struct kvm_userspace_memory_region { 1246 __u32 slot; 1247 __u32 flags; 1248 __u64 guest_phys_addr; 1249 __u64 memory_size; /* bytes */ 1250 __u64 userspace_addr; /* start of the userspace allocated memory */ 1251 }; 1252 1253 /* for kvm_memory_region::flags */ 1254 #define KVM_MEM_LOG_DIRTY_PAGES (1UL << 0) 1255 #define KVM_MEM_READONLY (1UL << 1) 1256 1257This ioctl allows the user to create, modify or delete a guest physical 1258memory slot. Bits 0-15 of "slot" specify the slot id and this value 1259should be less than the maximum number of user memory slots supported per 1260VM. The maximum allowed slots can be queried using KVM_CAP_NR_MEMSLOTS. 1261Slots may not overlap in guest physical address space. 1262 1263If KVM_CAP_MULTI_ADDRESS_SPACE is available, bits 16-31 of "slot" 1264specifies the address space which is being modified. They must be 1265less than the value that KVM_CHECK_EXTENSION returns for the 1266KVM_CAP_MULTI_ADDRESS_SPACE capability. Slots in separate address spaces 1267are unrelated; the restriction on overlapping slots only applies within 1268each address space. 1269 1270Deleting a slot is done by passing zero for memory_size. When changing 1271an existing slot, it may be moved in the guest physical memory space, 1272or its flags may be modified, but it may not be resized. 1273 1274Memory for the region is taken starting at the address denoted by the 1275field userspace_addr, which must point at user addressable memory for 1276the entire memory slot size. Any object may back this memory, including 1277anonymous memory, ordinary files, and hugetlbfs. 1278 1279It is recommended that the lower 21 bits of guest_phys_addr and userspace_addr 1280be identical. This allows large pages in the guest to be backed by large 1281pages in the host. 1282 1283The flags field supports two flags: KVM_MEM_LOG_DIRTY_PAGES and 1284KVM_MEM_READONLY. The former can be set to instruct KVM to keep track of 1285writes to memory within the slot. See KVM_GET_DIRTY_LOG ioctl to know how to 1286use it. The latter can be set, if KVM_CAP_READONLY_MEM capability allows it, 1287to make a new slot read-only. In this case, writes to this memory will be 1288posted to userspace as KVM_EXIT_MMIO exits. 1289 1290When the KVM_CAP_SYNC_MMU capability is available, changes in the backing of 1291the memory region are automatically reflected into the guest. For example, an 1292mmap() that affects the region will be made visible immediately. Another 1293example is madvise(MADV_DROP). 1294 1295It is recommended to use this API instead of the KVM_SET_MEMORY_REGION ioctl. 1296The KVM_SET_MEMORY_REGION does not allow fine grained control over memory 1297allocation and is deprecated. 1298 1299 13004.36 KVM_SET_TSS_ADDR 1301--------------------- 1302 1303:Capability: KVM_CAP_SET_TSS_ADDR 1304:Architectures: x86 1305:Type: vm ioctl 1306:Parameters: unsigned long tss_address (in) 1307:Returns: 0 on success, -1 on error 1308 1309This ioctl defines the physical address of a three-page region in the guest 1310physical address space. The region must be within the first 4GB of the 1311guest physical address space and must not conflict with any memory slot 1312or any mmio address. The guest may malfunction if it accesses this memory 1313region. 1314 1315This ioctl is required on Intel-based hosts. This is needed on Intel hardware 1316because of a quirk in the virtualization implementation (see the internals 1317documentation when it pops into existence). 1318 1319 13204.37 KVM_ENABLE_CAP 1321------------------- 1322 1323:Capability: KVM_CAP_ENABLE_CAP 1324:Architectures: mips, ppc, s390 1325:Type: vcpu ioctl 1326:Parameters: struct kvm_enable_cap (in) 1327:Returns: 0 on success; -1 on error 1328 1329:Capability: KVM_CAP_ENABLE_CAP_VM 1330:Architectures: all 1331:Type: vcpu ioctl 1332:Parameters: struct kvm_enable_cap (in) 1333:Returns: 0 on success; -1 on error 1334 1335.. note:: 1336 1337 Not all extensions are enabled by default. Using this ioctl the application 1338 can enable an extension, making it available to the guest. 1339 1340On systems that do not support this ioctl, it always fails. On systems that 1341do support it, it only works for extensions that are supported for enablement. 1342 1343To check if a capability can be enabled, the KVM_CHECK_EXTENSION ioctl should 1344be used. 1345 1346:: 1347 1348 struct kvm_enable_cap { 1349 /* in */ 1350 __u32 cap; 1351 1352The capability that is supposed to get enabled. 1353 1354:: 1355 1356 __u32 flags; 1357 1358A bitfield indicating future enhancements. Has to be 0 for now. 1359 1360:: 1361 1362 __u64 args[4]; 1363 1364Arguments for enabling a feature. If a feature needs initial values to 1365function properly, this is the place to put them. 1366 1367:: 1368 1369 __u8 pad[64]; 1370 }; 1371 1372The vcpu ioctl should be used for vcpu-specific capabilities, the vm ioctl 1373for vm-wide capabilities. 1374 13754.38 KVM_GET_MP_STATE 1376--------------------- 1377 1378:Capability: KVM_CAP_MP_STATE 1379:Architectures: x86, s390, arm, arm64 1380:Type: vcpu ioctl 1381:Parameters: struct kvm_mp_state (out) 1382:Returns: 0 on success; -1 on error 1383 1384:: 1385 1386 struct kvm_mp_state { 1387 __u32 mp_state; 1388 }; 1389 1390Returns the vcpu's current "multiprocessing state" (though also valid on 1391uniprocessor guests). 1392 1393Possible values are: 1394 1395 ========================== =============================================== 1396 KVM_MP_STATE_RUNNABLE the vcpu is currently running [x86,arm/arm64] 1397 KVM_MP_STATE_UNINITIALIZED the vcpu is an application processor (AP) 1398 which has not yet received an INIT signal [x86] 1399 KVM_MP_STATE_INIT_RECEIVED the vcpu has received an INIT signal, and is 1400 now ready for a SIPI [x86] 1401 KVM_MP_STATE_HALTED the vcpu has executed a HLT instruction and 1402 is waiting for an interrupt [x86] 1403 KVM_MP_STATE_SIPI_RECEIVED the vcpu has just received a SIPI (vector 1404 accessible via KVM_GET_VCPU_EVENTS) [x86] 1405 KVM_MP_STATE_STOPPED the vcpu is stopped [s390,arm/arm64] 1406 KVM_MP_STATE_CHECK_STOP the vcpu is in a special error state [s390] 1407 KVM_MP_STATE_OPERATING the vcpu is operating (running or halted) 1408 [s390] 1409 KVM_MP_STATE_LOAD the vcpu is in a special load/startup state 1410 [s390] 1411 ========================== =============================================== 1412 1413On x86, this ioctl is only useful after KVM_CREATE_IRQCHIP. Without an 1414in-kernel irqchip, the multiprocessing state must be maintained by userspace on 1415these architectures. 1416 1417For arm/arm64: 1418^^^^^^^^^^^^^^ 1419 1420The only states that are valid are KVM_MP_STATE_STOPPED and 1421KVM_MP_STATE_RUNNABLE which reflect if the vcpu is paused or not. 1422 14234.39 KVM_SET_MP_STATE 1424--------------------- 1425 1426:Capability: KVM_CAP_MP_STATE 1427:Architectures: x86, s390, arm, arm64 1428:Type: vcpu ioctl 1429:Parameters: struct kvm_mp_state (in) 1430:Returns: 0 on success; -1 on error 1431 1432Sets the vcpu's current "multiprocessing state"; see KVM_GET_MP_STATE for 1433arguments. 1434 1435On x86, this ioctl is only useful after KVM_CREATE_IRQCHIP. Without an 1436in-kernel irqchip, the multiprocessing state must be maintained by userspace on 1437these architectures. 1438 1439For arm/arm64: 1440^^^^^^^^^^^^^^ 1441 1442The only states that are valid are KVM_MP_STATE_STOPPED and 1443KVM_MP_STATE_RUNNABLE which reflect if the vcpu should be paused or not. 1444 14454.40 KVM_SET_IDENTITY_MAP_ADDR 1446------------------------------ 1447 1448:Capability: KVM_CAP_SET_IDENTITY_MAP_ADDR 1449:Architectures: x86 1450:Type: vm ioctl 1451:Parameters: unsigned long identity (in) 1452:Returns: 0 on success, -1 on error 1453 1454This ioctl defines the physical address of a one-page region in the guest 1455physical address space. The region must be within the first 4GB of the 1456guest physical address space and must not conflict with any memory slot 1457or any mmio address. The guest may malfunction if it accesses this memory 1458region. 1459 1460Setting the address to 0 will result in resetting the address to its default 1461(0xfffbc000). 1462 1463This ioctl is required on Intel-based hosts. This is needed on Intel hardware 1464because of a quirk in the virtualization implementation (see the internals 1465documentation when it pops into existence). 1466 1467Fails if any VCPU has already been created. 1468 14694.41 KVM_SET_BOOT_CPU_ID 1470------------------------ 1471 1472:Capability: KVM_CAP_SET_BOOT_CPU_ID 1473:Architectures: x86 1474:Type: vm ioctl 1475:Parameters: unsigned long vcpu_id 1476:Returns: 0 on success, -1 on error 1477 1478Define which vcpu is the Bootstrap Processor (BSP). Values are the same 1479as the vcpu id in KVM_CREATE_VCPU. If this ioctl is not called, the default 1480is vcpu 0. 1481 1482 14834.42 KVM_GET_XSAVE 1484------------------ 1485 1486:Capability: KVM_CAP_XSAVE 1487:Architectures: x86 1488:Type: vcpu ioctl 1489:Parameters: struct kvm_xsave (out) 1490:Returns: 0 on success, -1 on error 1491 1492 1493:: 1494 1495 struct kvm_xsave { 1496 __u32 region[1024]; 1497 }; 1498 1499This ioctl would copy current vcpu's xsave struct to the userspace. 1500 1501 15024.43 KVM_SET_XSAVE 1503------------------ 1504 1505:Capability: KVM_CAP_XSAVE 1506:Architectures: x86 1507:Type: vcpu ioctl 1508:Parameters: struct kvm_xsave (in) 1509:Returns: 0 on success, -1 on error 1510 1511:: 1512 1513 1514 struct kvm_xsave { 1515 __u32 region[1024]; 1516 }; 1517 1518This ioctl would copy userspace's xsave struct to the kernel. 1519 1520 15214.44 KVM_GET_XCRS 1522----------------- 1523 1524:Capability: KVM_CAP_XCRS 1525:Architectures: x86 1526:Type: vcpu ioctl 1527:Parameters: struct kvm_xcrs (out) 1528:Returns: 0 on success, -1 on error 1529 1530:: 1531 1532 struct kvm_xcr { 1533 __u32 xcr; 1534 __u32 reserved; 1535 __u64 value; 1536 }; 1537 1538 struct kvm_xcrs { 1539 __u32 nr_xcrs; 1540 __u32 flags; 1541 struct kvm_xcr xcrs[KVM_MAX_XCRS]; 1542 __u64 padding[16]; 1543 }; 1544 1545This ioctl would copy current vcpu's xcrs to the userspace. 1546 1547 15484.45 KVM_SET_XCRS 1549----------------- 1550 1551:Capability: KVM_CAP_XCRS 1552:Architectures: x86 1553:Type: vcpu ioctl 1554:Parameters: struct kvm_xcrs (in) 1555:Returns: 0 on success, -1 on error 1556 1557:: 1558 1559 struct kvm_xcr { 1560 __u32 xcr; 1561 __u32 reserved; 1562 __u64 value; 1563 }; 1564 1565 struct kvm_xcrs { 1566 __u32 nr_xcrs; 1567 __u32 flags; 1568 struct kvm_xcr xcrs[KVM_MAX_XCRS]; 1569 __u64 padding[16]; 1570 }; 1571 1572This ioctl would set vcpu's xcr to the value userspace specified. 1573 1574 15754.46 KVM_GET_SUPPORTED_CPUID 1576---------------------------- 1577 1578:Capability: KVM_CAP_EXT_CPUID 1579:Architectures: x86 1580:Type: system ioctl 1581:Parameters: struct kvm_cpuid2 (in/out) 1582:Returns: 0 on success, -1 on error 1583 1584:: 1585 1586 struct kvm_cpuid2 { 1587 __u32 nent; 1588 __u32 padding; 1589 struct kvm_cpuid_entry2 entries[0]; 1590 }; 1591 1592 #define KVM_CPUID_FLAG_SIGNIFCANT_INDEX BIT(0) 1593 #define KVM_CPUID_FLAG_STATEFUL_FUNC BIT(1) /* deprecated */ 1594 #define KVM_CPUID_FLAG_STATE_READ_NEXT BIT(2) /* deprecated */ 1595 1596 struct kvm_cpuid_entry2 { 1597 __u32 function; 1598 __u32 index; 1599 __u32 flags; 1600 __u32 eax; 1601 __u32 ebx; 1602 __u32 ecx; 1603 __u32 edx; 1604 __u32 padding[3]; 1605 }; 1606 1607This ioctl returns x86 cpuid features which are supported by both the 1608hardware and kvm in its default configuration. Userspace can use the 1609information returned by this ioctl to construct cpuid information (for 1610KVM_SET_CPUID2) that is consistent with hardware, kernel, and 1611userspace capabilities, and with user requirements (for example, the 1612user may wish to constrain cpuid to emulate older hardware, or for 1613feature consistency across a cluster). 1614 1615Note that certain capabilities, such as KVM_CAP_X86_DISABLE_EXITS, may 1616expose cpuid features (e.g. MONITOR) which are not supported by kvm in 1617its default configuration. If userspace enables such capabilities, it 1618is responsible for modifying the results of this ioctl appropriately. 1619 1620Userspace invokes KVM_GET_SUPPORTED_CPUID by passing a kvm_cpuid2 structure 1621with the 'nent' field indicating the number of entries in the variable-size 1622array 'entries'. If the number of entries is too low to describe the cpu 1623capabilities, an error (E2BIG) is returned. If the number is too high, 1624the 'nent' field is adjusted and an error (ENOMEM) is returned. If the 1625number is just right, the 'nent' field is adjusted to the number of valid 1626entries in the 'entries' array, which is then filled. 1627 1628The entries returned are the host cpuid as returned by the cpuid instruction, 1629with unknown or unsupported features masked out. Some features (for example, 1630x2apic), may not be present in the host cpu, but are exposed by kvm if it can 1631emulate them efficiently. The fields in each entry are defined as follows: 1632 1633 function: 1634 the eax value used to obtain the entry 1635 1636 index: 1637 the ecx value used to obtain the entry (for entries that are 1638 affected by ecx) 1639 1640 flags: 1641 an OR of zero or more of the following: 1642 1643 KVM_CPUID_FLAG_SIGNIFCANT_INDEX: 1644 if the index field is valid 1645 1646 eax, ebx, ecx, edx: 1647 the values returned by the cpuid instruction for 1648 this function/index combination 1649 1650The TSC deadline timer feature (CPUID leaf 1, ecx[24]) is always returned 1651as false, since the feature depends on KVM_CREATE_IRQCHIP for local APIC 1652support. Instead it is reported via:: 1653 1654 ioctl(KVM_CHECK_EXTENSION, KVM_CAP_TSC_DEADLINE_TIMER) 1655 1656if that returns true and you use KVM_CREATE_IRQCHIP, or if you emulate the 1657feature in userspace, then you can enable the feature for KVM_SET_CPUID2. 1658 1659 16604.47 KVM_PPC_GET_PVINFO 1661----------------------- 1662 1663:Capability: KVM_CAP_PPC_GET_PVINFO 1664:Architectures: ppc 1665:Type: vm ioctl 1666:Parameters: struct kvm_ppc_pvinfo (out) 1667:Returns: 0 on success, !0 on error 1668 1669:: 1670 1671 struct kvm_ppc_pvinfo { 1672 __u32 flags; 1673 __u32 hcall[4]; 1674 __u8 pad[108]; 1675 }; 1676 1677This ioctl fetches PV specific information that need to be passed to the guest 1678using the device tree or other means from vm context. 1679 1680The hcall array defines 4 instructions that make up a hypercall. 1681 1682If any additional field gets added to this structure later on, a bit for that 1683additional piece of information will be set in the flags bitmap. 1684 1685The flags bitmap is defined as:: 1686 1687 /* the host supports the ePAPR idle hcall 1688 #define KVM_PPC_PVINFO_FLAGS_EV_IDLE (1<<0) 1689 16904.52 KVM_SET_GSI_ROUTING 1691------------------------ 1692 1693:Capability: KVM_CAP_IRQ_ROUTING 1694:Architectures: x86 s390 arm arm64 1695:Type: vm ioctl 1696:Parameters: struct kvm_irq_routing (in) 1697:Returns: 0 on success, -1 on error 1698 1699Sets the GSI routing table entries, overwriting any previously set entries. 1700 1701On arm/arm64, GSI routing has the following limitation: 1702 1703- GSI routing does not apply to KVM_IRQ_LINE but only to KVM_IRQFD. 1704 1705:: 1706 1707 struct kvm_irq_routing { 1708 __u32 nr; 1709 __u32 flags; 1710 struct kvm_irq_routing_entry entries[0]; 1711 }; 1712 1713No flags are specified so far, the corresponding field must be set to zero. 1714 1715:: 1716 1717 struct kvm_irq_routing_entry { 1718 __u32 gsi; 1719 __u32 type; 1720 __u32 flags; 1721 __u32 pad; 1722 union { 1723 struct kvm_irq_routing_irqchip irqchip; 1724 struct kvm_irq_routing_msi msi; 1725 struct kvm_irq_routing_s390_adapter adapter; 1726 struct kvm_irq_routing_hv_sint hv_sint; 1727 __u32 pad[8]; 1728 } u; 1729 }; 1730 1731 /* gsi routing entry types */ 1732 #define KVM_IRQ_ROUTING_IRQCHIP 1 1733 #define KVM_IRQ_ROUTING_MSI 2 1734 #define KVM_IRQ_ROUTING_S390_ADAPTER 3 1735 #define KVM_IRQ_ROUTING_HV_SINT 4 1736 1737flags: 1738 1739- KVM_MSI_VALID_DEVID: used along with KVM_IRQ_ROUTING_MSI routing entry 1740 type, specifies that the devid field contains a valid value. The per-VM 1741 KVM_CAP_MSI_DEVID capability advertises the requirement to provide 1742 the device ID. If this capability is not available, userspace should 1743 never set the KVM_MSI_VALID_DEVID flag as the ioctl might fail. 1744- zero otherwise 1745 1746:: 1747 1748 struct kvm_irq_routing_irqchip { 1749 __u32 irqchip; 1750 __u32 pin; 1751 }; 1752 1753 struct kvm_irq_routing_msi { 1754 __u32 address_lo; 1755 __u32 address_hi; 1756 __u32 data; 1757 union { 1758 __u32 pad; 1759 __u32 devid; 1760 }; 1761 }; 1762 1763If KVM_MSI_VALID_DEVID is set, devid contains a unique device identifier 1764for the device that wrote the MSI message. For PCI, this is usually a 1765BFD identifier in the lower 16 bits. 1766 1767On x86, address_hi is ignored unless the KVM_X2APIC_API_USE_32BIT_IDS 1768feature of KVM_CAP_X2APIC_API capability is enabled. If it is enabled, 1769address_hi bits 31-8 provide bits 31-8 of the destination id. Bits 7-0 of 1770address_hi must be zero. 1771 1772:: 1773 1774 struct kvm_irq_routing_s390_adapter { 1775 __u64 ind_addr; 1776 __u64 summary_addr; 1777 __u64 ind_offset; 1778 __u32 summary_offset; 1779 __u32 adapter_id; 1780 }; 1781 1782 struct kvm_irq_routing_hv_sint { 1783 __u32 vcpu; 1784 __u32 sint; 1785 }; 1786 1787 17884.55 KVM_SET_TSC_KHZ 1789-------------------- 1790 1791:Capability: KVM_CAP_TSC_CONTROL 1792:Architectures: x86 1793:Type: vcpu ioctl 1794:Parameters: virtual tsc_khz 1795:Returns: 0 on success, -1 on error 1796 1797Specifies the tsc frequency for the virtual machine. The unit of the 1798frequency is KHz. 1799 1800 18014.56 KVM_GET_TSC_KHZ 1802-------------------- 1803 1804:Capability: KVM_CAP_GET_TSC_KHZ 1805:Architectures: x86 1806:Type: vcpu ioctl 1807:Parameters: none 1808:Returns: virtual tsc-khz on success, negative value on error 1809 1810Returns the tsc frequency of the guest. The unit of the return value is 1811KHz. If the host has unstable tsc this ioctl returns -EIO instead as an 1812error. 1813 1814 18154.57 KVM_GET_LAPIC 1816------------------ 1817 1818:Capability: KVM_CAP_IRQCHIP 1819:Architectures: x86 1820:Type: vcpu ioctl 1821:Parameters: struct kvm_lapic_state (out) 1822:Returns: 0 on success, -1 on error 1823 1824:: 1825 1826 #define KVM_APIC_REG_SIZE 0x400 1827 struct kvm_lapic_state { 1828 char regs[KVM_APIC_REG_SIZE]; 1829 }; 1830 1831Reads the Local APIC registers and copies them into the input argument. The 1832data format and layout are the same as documented in the architecture manual. 1833 1834If KVM_X2APIC_API_USE_32BIT_IDS feature of KVM_CAP_X2APIC_API is 1835enabled, then the format of APIC_ID register depends on the APIC mode 1836(reported by MSR_IA32_APICBASE) of its VCPU. x2APIC stores APIC ID in 1837the APIC_ID register (bytes 32-35). xAPIC only allows an 8-bit APIC ID 1838which is stored in bits 31-24 of the APIC register, or equivalently in 1839byte 35 of struct kvm_lapic_state's regs field. KVM_GET_LAPIC must then 1840be called after MSR_IA32_APICBASE has been set with KVM_SET_MSR. 1841 1842If KVM_X2APIC_API_USE_32BIT_IDS feature is disabled, struct kvm_lapic_state 1843always uses xAPIC format. 1844 1845 18464.58 KVM_SET_LAPIC 1847------------------ 1848 1849:Capability: KVM_CAP_IRQCHIP 1850:Architectures: x86 1851:Type: vcpu ioctl 1852:Parameters: struct kvm_lapic_state (in) 1853:Returns: 0 on success, -1 on error 1854 1855:: 1856 1857 #define KVM_APIC_REG_SIZE 0x400 1858 struct kvm_lapic_state { 1859 char regs[KVM_APIC_REG_SIZE]; 1860 }; 1861 1862Copies the input argument into the Local APIC registers. The data format 1863and layout are the same as documented in the architecture manual. 1864 1865The format of the APIC ID register (bytes 32-35 of struct kvm_lapic_state's 1866regs field) depends on the state of the KVM_CAP_X2APIC_API capability. 1867See the note in KVM_GET_LAPIC. 1868 1869 18704.59 KVM_IOEVENTFD 1871------------------ 1872 1873:Capability: KVM_CAP_IOEVENTFD 1874:Architectures: all 1875:Type: vm ioctl 1876:Parameters: struct kvm_ioeventfd (in) 1877:Returns: 0 on success, !0 on error 1878 1879This ioctl attaches or detaches an ioeventfd to a legal pio/mmio address 1880within the guest. A guest write in the registered address will signal the 1881provided event instead of triggering an exit. 1882 1883:: 1884 1885 struct kvm_ioeventfd { 1886 __u64 datamatch; 1887 __u64 addr; /* legal pio/mmio address */ 1888 __u32 len; /* 0, 1, 2, 4, or 8 bytes */ 1889 __s32 fd; 1890 __u32 flags; 1891 __u8 pad[36]; 1892 }; 1893 1894For the special case of virtio-ccw devices on s390, the ioevent is matched 1895to a subchannel/virtqueue tuple instead. 1896 1897The following flags are defined:: 1898 1899 #define KVM_IOEVENTFD_FLAG_DATAMATCH (1 << kvm_ioeventfd_flag_nr_datamatch) 1900 #define KVM_IOEVENTFD_FLAG_PIO (1 << kvm_ioeventfd_flag_nr_pio) 1901 #define KVM_IOEVENTFD_FLAG_DEASSIGN (1 << kvm_ioeventfd_flag_nr_deassign) 1902 #define KVM_IOEVENTFD_FLAG_VIRTIO_CCW_NOTIFY \ 1903 (1 << kvm_ioeventfd_flag_nr_virtio_ccw_notify) 1904 1905If datamatch flag is set, the event will be signaled only if the written value 1906to the registered address is equal to datamatch in struct kvm_ioeventfd. 1907 1908For virtio-ccw devices, addr contains the subchannel id and datamatch the 1909virtqueue index. 1910 1911With KVM_CAP_IOEVENTFD_ANY_LENGTH, a zero length ioeventfd is allowed, and 1912the kernel will ignore the length of guest write and may get a faster vmexit. 1913The speedup may only apply to specific architectures, but the ioeventfd will 1914work anyway. 1915 19164.60 KVM_DIRTY_TLB 1917------------------ 1918 1919:Capability: KVM_CAP_SW_TLB 1920:Architectures: ppc 1921:Type: vcpu ioctl 1922:Parameters: struct kvm_dirty_tlb (in) 1923:Returns: 0 on success, -1 on error 1924 1925:: 1926 1927 struct kvm_dirty_tlb { 1928 __u64 bitmap; 1929 __u32 num_dirty; 1930 }; 1931 1932This must be called whenever userspace has changed an entry in the shared 1933TLB, prior to calling KVM_RUN on the associated vcpu. 1934 1935The "bitmap" field is the userspace address of an array. This array 1936consists of a number of bits, equal to the total number of TLB entries as 1937determined by the last successful call to KVM_CONFIG_TLB, rounded up to the 1938nearest multiple of 64. 1939 1940Each bit corresponds to one TLB entry, ordered the same as in the shared TLB 1941array. 1942 1943The array is little-endian: the bit 0 is the least significant bit of the 1944first byte, bit 8 is the least significant bit of the second byte, etc. 1945This avoids any complications with differing word sizes. 1946 1947The "num_dirty" field is a performance hint for KVM to determine whether it 1948should skip processing the bitmap and just invalidate everything. It must 1949be set to the number of set bits in the bitmap. 1950 1951 19524.62 KVM_CREATE_SPAPR_TCE 1953------------------------- 1954 1955:Capability: KVM_CAP_SPAPR_TCE 1956:Architectures: powerpc 1957:Type: vm ioctl 1958:Parameters: struct kvm_create_spapr_tce (in) 1959:Returns: file descriptor for manipulating the created TCE table 1960 1961This creates a virtual TCE (translation control entry) table, which 1962is an IOMMU for PAPR-style virtual I/O. It is used to translate 1963logical addresses used in virtual I/O into guest physical addresses, 1964and provides a scatter/gather capability for PAPR virtual I/O. 1965 1966:: 1967 1968 /* for KVM_CAP_SPAPR_TCE */ 1969 struct kvm_create_spapr_tce { 1970 __u64 liobn; 1971 __u32 window_size; 1972 }; 1973 1974The liobn field gives the logical IO bus number for which to create a 1975TCE table. The window_size field specifies the size of the DMA window 1976which this TCE table will translate - the table will contain one 64 1977bit TCE entry for every 4kiB of the DMA window. 1978 1979When the guest issues an H_PUT_TCE hcall on a liobn for which a TCE 1980table has been created using this ioctl(), the kernel will handle it 1981in real mode, updating the TCE table. H_PUT_TCE calls for other 1982liobns will cause a vm exit and must be handled by userspace. 1983 1984The return value is a file descriptor which can be passed to mmap(2) 1985to map the created TCE table into userspace. This lets userspace read 1986the entries written by kernel-handled H_PUT_TCE calls, and also lets 1987userspace update the TCE table directly which is useful in some 1988circumstances. 1989 1990 19914.63 KVM_ALLOCATE_RMA 1992--------------------- 1993 1994:Capability: KVM_CAP_PPC_RMA 1995:Architectures: powerpc 1996:Type: vm ioctl 1997:Parameters: struct kvm_allocate_rma (out) 1998:Returns: file descriptor for mapping the allocated RMA 1999 2000This allocates a Real Mode Area (RMA) from the pool allocated at boot 2001time by the kernel. An RMA is a physically-contiguous, aligned region 2002of memory used on older POWER processors to provide the memory which 2003will be accessed by real-mode (MMU off) accesses in a KVM guest. 2004POWER processors support a set of sizes for the RMA that usually 2005includes 64MB, 128MB, 256MB and some larger powers of two. 2006 2007:: 2008 2009 /* for KVM_ALLOCATE_RMA */ 2010 struct kvm_allocate_rma { 2011 __u64 rma_size; 2012 }; 2013 2014The return value is a file descriptor which can be passed to mmap(2) 2015to map the allocated RMA into userspace. The mapped area can then be 2016passed to the KVM_SET_USER_MEMORY_REGION ioctl to establish it as the 2017RMA for a virtual machine. The size of the RMA in bytes (which is 2018fixed at host kernel boot time) is returned in the rma_size field of 2019the argument structure. 2020 2021The KVM_CAP_PPC_RMA capability is 1 or 2 if the KVM_ALLOCATE_RMA ioctl 2022is supported; 2 if the processor requires all virtual machines to have 2023an RMA, or 1 if the processor can use an RMA but doesn't require it, 2024because it supports the Virtual RMA (VRMA) facility. 2025 2026 20274.64 KVM_NMI 2028------------ 2029 2030:Capability: KVM_CAP_USER_NMI 2031:Architectures: x86 2032:Type: vcpu ioctl 2033:Parameters: none 2034:Returns: 0 on success, -1 on error 2035 2036Queues an NMI on the thread's vcpu. Note this is well defined only 2037when KVM_CREATE_IRQCHIP has not been called, since this is an interface 2038between the virtual cpu core and virtual local APIC. After KVM_CREATE_IRQCHIP 2039has been called, this interface is completely emulated within the kernel. 2040 2041To use this to emulate the LINT1 input with KVM_CREATE_IRQCHIP, use the 2042following algorithm: 2043 2044 - pause the vcpu 2045 - read the local APIC's state (KVM_GET_LAPIC) 2046 - check whether changing LINT1 will queue an NMI (see the LVT entry for LINT1) 2047 - if so, issue KVM_NMI 2048 - resume the vcpu 2049 2050Some guests configure the LINT1 NMI input to cause a panic, aiding in 2051debugging. 2052 2053 20544.65 KVM_S390_UCAS_MAP 2055---------------------- 2056 2057:Capability: KVM_CAP_S390_UCONTROL 2058:Architectures: s390 2059:Type: vcpu ioctl 2060:Parameters: struct kvm_s390_ucas_mapping (in) 2061:Returns: 0 in case of success 2062 2063The parameter is defined like this:: 2064 2065 struct kvm_s390_ucas_mapping { 2066 __u64 user_addr; 2067 __u64 vcpu_addr; 2068 __u64 length; 2069 }; 2070 2071This ioctl maps the memory at "user_addr" with the length "length" to 2072the vcpu's address space starting at "vcpu_addr". All parameters need to 2073be aligned by 1 megabyte. 2074 2075 20764.66 KVM_S390_UCAS_UNMAP 2077------------------------ 2078 2079:Capability: KVM_CAP_S390_UCONTROL 2080:Architectures: s390 2081:Type: vcpu ioctl 2082:Parameters: struct kvm_s390_ucas_mapping (in) 2083:Returns: 0 in case of success 2084 2085The parameter is defined like this:: 2086 2087 struct kvm_s390_ucas_mapping { 2088 __u64 user_addr; 2089 __u64 vcpu_addr; 2090 __u64 length; 2091 }; 2092 2093This ioctl unmaps the memory in the vcpu's address space starting at 2094"vcpu_addr" with the length "length". The field "user_addr" is ignored. 2095All parameters need to be aligned by 1 megabyte. 2096 2097 20984.67 KVM_S390_VCPU_FAULT 2099------------------------ 2100 2101:Capability: KVM_CAP_S390_UCONTROL 2102:Architectures: s390 2103:Type: vcpu ioctl 2104:Parameters: vcpu absolute address (in) 2105:Returns: 0 in case of success 2106 2107This call creates a page table entry on the virtual cpu's address space 2108(for user controlled virtual machines) or the virtual machine's address 2109space (for regular virtual machines). This only works for minor faults, 2110thus it's recommended to access subject memory page via the user page 2111table upfront. This is useful to handle validity intercepts for user 2112controlled virtual machines to fault in the virtual cpu's lowcore pages 2113prior to calling the KVM_RUN ioctl. 2114 2115 21164.68 KVM_SET_ONE_REG 2117-------------------- 2118 2119:Capability: KVM_CAP_ONE_REG 2120:Architectures: all 2121:Type: vcpu ioctl 2122:Parameters: struct kvm_one_reg (in) 2123:Returns: 0 on success, negative value on failure 2124 2125Errors: 2126 2127 ====== ============================================================ 2128 ENOENT no such register 2129 EINVAL invalid register ID, or no such register or used with VMs in 2130 protected virtualization mode on s390 2131 EPERM (arm64) register access not allowed before vcpu finalization 2132 ====== ============================================================ 2133 2134(These error codes are indicative only: do not rely on a specific error 2135code being returned in a specific situation.) 2136 2137:: 2138 2139 struct kvm_one_reg { 2140 __u64 id; 2141 __u64 addr; 2142 }; 2143 2144Using this ioctl, a single vcpu register can be set to a specific value 2145defined by user space with the passed in struct kvm_one_reg, where id 2146refers to the register identifier as described below and addr is a pointer 2147to a variable with the respective size. There can be architecture agnostic 2148and architecture specific registers. Each have their own range of operation 2149and their own constants and width. To keep track of the implemented 2150registers, find a list below: 2151 2152 ======= =============================== ============ 2153 Arch Register Width (bits) 2154 ======= =============================== ============ 2155 PPC KVM_REG_PPC_HIOR 64 2156 PPC KVM_REG_PPC_IAC1 64 2157 PPC KVM_REG_PPC_IAC2 64 2158 PPC KVM_REG_PPC_IAC3 64 2159 PPC KVM_REG_PPC_IAC4 64 2160 PPC KVM_REG_PPC_DAC1 64 2161 PPC KVM_REG_PPC_DAC2 64 2162 PPC KVM_REG_PPC_DABR 64 2163 PPC KVM_REG_PPC_DSCR 64 2164 PPC KVM_REG_PPC_PURR 64 2165 PPC KVM_REG_PPC_SPURR 64 2166 PPC KVM_REG_PPC_DAR 64 2167 PPC KVM_REG_PPC_DSISR 32 2168 PPC KVM_REG_PPC_AMR 64 2169 PPC KVM_REG_PPC_UAMOR 64 2170 PPC KVM_REG_PPC_MMCR0 64 2171 PPC KVM_REG_PPC_MMCR1 64 2172 PPC KVM_REG_PPC_MMCRA 64 2173 PPC KVM_REG_PPC_MMCR2 64 2174 PPC KVM_REG_PPC_MMCRS 64 2175 PPC KVM_REG_PPC_MMCR3 64 2176 PPC KVM_REG_PPC_SIAR 64 2177 PPC KVM_REG_PPC_SDAR 64 2178 PPC KVM_REG_PPC_SIER 64 2179 PPC KVM_REG_PPC_SIER2 64 2180 PPC KVM_REG_PPC_SIER3 64 2181 PPC KVM_REG_PPC_PMC1 32 2182 PPC KVM_REG_PPC_PMC2 32 2183 PPC KVM_REG_PPC_PMC3 32 2184 PPC KVM_REG_PPC_PMC4 32 2185 PPC KVM_REG_PPC_PMC5 32 2186 PPC KVM_REG_PPC_PMC6 32 2187 PPC KVM_REG_PPC_PMC7 32 2188 PPC KVM_REG_PPC_PMC8 32 2189 PPC KVM_REG_PPC_FPR0 64 2190 ... 2191 PPC KVM_REG_PPC_FPR31 64 2192 PPC KVM_REG_PPC_VR0 128 2193 ... 2194 PPC KVM_REG_PPC_VR31 128 2195 PPC KVM_REG_PPC_VSR0 128 2196 ... 2197 PPC KVM_REG_PPC_VSR31 128 2198 PPC KVM_REG_PPC_FPSCR 64 2199 PPC KVM_REG_PPC_VSCR 32 2200 PPC KVM_REG_PPC_VPA_ADDR 64 2201 PPC KVM_REG_PPC_VPA_SLB 128 2202 PPC KVM_REG_PPC_VPA_DTL 128 2203 PPC KVM_REG_PPC_EPCR 32 2204 PPC KVM_REG_PPC_EPR 32 2205 PPC KVM_REG_PPC_TCR 32 2206 PPC KVM_REG_PPC_TSR 32 2207 PPC KVM_REG_PPC_OR_TSR 32 2208 PPC KVM_REG_PPC_CLEAR_TSR 32 2209 PPC KVM_REG_PPC_MAS0 32 2210 PPC KVM_REG_PPC_MAS1 32 2211 PPC KVM_REG_PPC_MAS2 64 2212 PPC KVM_REG_PPC_MAS7_3 64 2213 PPC KVM_REG_PPC_MAS4 32 2214 PPC KVM_REG_PPC_MAS6 32 2215 PPC KVM_REG_PPC_MMUCFG 32 2216 PPC KVM_REG_PPC_TLB0CFG 32 2217 PPC KVM_REG_PPC_TLB1CFG 32 2218 PPC KVM_REG_PPC_TLB2CFG 32 2219 PPC KVM_REG_PPC_TLB3CFG 32 2220 PPC KVM_REG_PPC_TLB0PS 32 2221 PPC KVM_REG_PPC_TLB1PS 32 2222 PPC KVM_REG_PPC_TLB2PS 32 2223 PPC KVM_REG_PPC_TLB3PS 32 2224 PPC KVM_REG_PPC_EPTCFG 32 2225 PPC KVM_REG_PPC_ICP_STATE 64 2226 PPC KVM_REG_PPC_VP_STATE 128 2227 PPC KVM_REG_PPC_TB_OFFSET 64 2228 PPC KVM_REG_PPC_SPMC1 32 2229 PPC KVM_REG_PPC_SPMC2 32 2230 PPC KVM_REG_PPC_IAMR 64 2231 PPC KVM_REG_PPC_TFHAR 64 2232 PPC KVM_REG_PPC_TFIAR 64 2233 PPC KVM_REG_PPC_TEXASR 64 2234 PPC KVM_REG_PPC_FSCR 64 2235 PPC KVM_REG_PPC_PSPB 32 2236 PPC KVM_REG_PPC_EBBHR 64 2237 PPC KVM_REG_PPC_EBBRR 64 2238 PPC KVM_REG_PPC_BESCR 64 2239 PPC KVM_REG_PPC_TAR 64 2240 PPC KVM_REG_PPC_DPDES 64 2241 PPC KVM_REG_PPC_DAWR 64 2242 PPC KVM_REG_PPC_DAWRX 64 2243 PPC KVM_REG_PPC_CIABR 64 2244 PPC KVM_REG_PPC_IC 64 2245 PPC KVM_REG_PPC_VTB 64 2246 PPC KVM_REG_PPC_CSIGR 64 2247 PPC KVM_REG_PPC_TACR 64 2248 PPC KVM_REG_PPC_TCSCR 64 2249 PPC KVM_REG_PPC_PID 64 2250 PPC KVM_REG_PPC_ACOP 64 2251 PPC KVM_REG_PPC_VRSAVE 32 2252 PPC KVM_REG_PPC_LPCR 32 2253 PPC KVM_REG_PPC_LPCR_64 64 2254 PPC KVM_REG_PPC_PPR 64 2255 PPC KVM_REG_PPC_ARCH_COMPAT 32 2256 PPC KVM_REG_PPC_DABRX 32 2257 PPC KVM_REG_PPC_WORT 64 2258 PPC KVM_REG_PPC_SPRG9 64 2259 PPC KVM_REG_PPC_DBSR 32 2260 PPC KVM_REG_PPC_TIDR 64 2261 PPC KVM_REG_PPC_PSSCR 64 2262 PPC KVM_REG_PPC_DEC_EXPIRY 64 2263 PPC KVM_REG_PPC_PTCR 64 2264 PPC KVM_REG_PPC_TM_GPR0 64 2265 ... 2266 PPC KVM_REG_PPC_TM_GPR31 64 2267 PPC KVM_REG_PPC_TM_VSR0 128 2268 ... 2269 PPC KVM_REG_PPC_TM_VSR63 128 2270 PPC KVM_REG_PPC_TM_CR 64 2271 PPC KVM_REG_PPC_TM_LR 64 2272 PPC KVM_REG_PPC_TM_CTR 64 2273 PPC KVM_REG_PPC_TM_FPSCR 64 2274 PPC KVM_REG_PPC_TM_AMR 64 2275 PPC KVM_REG_PPC_TM_PPR 64 2276 PPC KVM_REG_PPC_TM_VRSAVE 64 2277 PPC KVM_REG_PPC_TM_VSCR 32 2278 PPC KVM_REG_PPC_TM_DSCR 64 2279 PPC KVM_REG_PPC_TM_TAR 64 2280 PPC KVM_REG_PPC_TM_XER 64 2281 2282 MIPS KVM_REG_MIPS_R0 64 2283 ... 2284 MIPS KVM_REG_MIPS_R31 64 2285 MIPS KVM_REG_MIPS_HI 64 2286 MIPS KVM_REG_MIPS_LO 64 2287 MIPS KVM_REG_MIPS_PC 64 2288 MIPS KVM_REG_MIPS_CP0_INDEX 32 2289 MIPS KVM_REG_MIPS_CP0_ENTRYLO0 64 2290 MIPS KVM_REG_MIPS_CP0_ENTRYLO1 64 2291 MIPS KVM_REG_MIPS_CP0_CONTEXT 64 2292 MIPS KVM_REG_MIPS_CP0_CONTEXTCONFIG 32 2293 MIPS KVM_REG_MIPS_CP0_USERLOCAL 64 2294 MIPS KVM_REG_MIPS_CP0_XCONTEXTCONFIG 64 2295 MIPS KVM_REG_MIPS_CP0_PAGEMASK 32 2296 MIPS KVM_REG_MIPS_CP0_PAGEGRAIN 32 2297 MIPS KVM_REG_MIPS_CP0_SEGCTL0 64 2298 MIPS KVM_REG_MIPS_CP0_SEGCTL1 64 2299 MIPS KVM_REG_MIPS_CP0_SEGCTL2 64 2300 MIPS KVM_REG_MIPS_CP0_PWBASE 64 2301 MIPS KVM_REG_MIPS_CP0_PWFIELD 64 2302 MIPS KVM_REG_MIPS_CP0_PWSIZE 64 2303 MIPS KVM_REG_MIPS_CP0_WIRED 32 2304 MIPS KVM_REG_MIPS_CP0_PWCTL 32 2305 MIPS KVM_REG_MIPS_CP0_HWRENA 32 2306 MIPS KVM_REG_MIPS_CP0_BADVADDR 64 2307 MIPS KVM_REG_MIPS_CP0_BADINSTR 32 2308 MIPS KVM_REG_MIPS_CP0_BADINSTRP 32 2309 MIPS KVM_REG_MIPS_CP0_COUNT 32 2310 MIPS KVM_REG_MIPS_CP0_ENTRYHI 64 2311 MIPS KVM_REG_MIPS_CP0_COMPARE 32 2312 MIPS KVM_REG_MIPS_CP0_STATUS 32 2313 MIPS KVM_REG_MIPS_CP0_INTCTL 32 2314 MIPS KVM_REG_MIPS_CP0_CAUSE 32 2315 MIPS KVM_REG_MIPS_CP0_EPC 64 2316 MIPS KVM_REG_MIPS_CP0_PRID 32 2317 MIPS KVM_REG_MIPS_CP0_EBASE 64 2318 MIPS KVM_REG_MIPS_CP0_CONFIG 32 2319 MIPS KVM_REG_MIPS_CP0_CONFIG1 32 2320 MIPS KVM_REG_MIPS_CP0_CONFIG2 32 2321 MIPS KVM_REG_MIPS_CP0_CONFIG3 32 2322 MIPS KVM_REG_MIPS_CP0_CONFIG4 32 2323 MIPS KVM_REG_MIPS_CP0_CONFIG5 32 2324 MIPS KVM_REG_MIPS_CP0_CONFIG7 32 2325 MIPS KVM_REG_MIPS_CP0_XCONTEXT 64 2326 MIPS KVM_REG_MIPS_CP0_ERROREPC 64 2327 MIPS KVM_REG_MIPS_CP0_KSCRATCH1 64 2328 MIPS KVM_REG_MIPS_CP0_KSCRATCH2 64 2329 MIPS KVM_REG_MIPS_CP0_KSCRATCH3 64 2330 MIPS KVM_REG_MIPS_CP0_KSCRATCH4 64 2331 MIPS KVM_REG_MIPS_CP0_KSCRATCH5 64 2332 MIPS KVM_REG_MIPS_CP0_KSCRATCH6 64 2333 MIPS KVM_REG_MIPS_CP0_MAAR(0..63) 64 2334 MIPS KVM_REG_MIPS_COUNT_CTL 64 2335 MIPS KVM_REG_MIPS_COUNT_RESUME 64 2336 MIPS KVM_REG_MIPS_COUNT_HZ 64 2337 MIPS KVM_REG_MIPS_FPR_32(0..31) 32 2338 MIPS KVM_REG_MIPS_FPR_64(0..31) 64 2339 MIPS KVM_REG_MIPS_VEC_128(0..31) 128 2340 MIPS KVM_REG_MIPS_FCR_IR 32 2341 MIPS KVM_REG_MIPS_FCR_CSR 32 2342 MIPS KVM_REG_MIPS_MSA_IR 32 2343 MIPS KVM_REG_MIPS_MSA_CSR 32 2344 ======= =============================== ============ 2345 2346ARM registers are mapped using the lower 32 bits. The upper 16 of that 2347is the register group type, or coprocessor number: 2348 2349ARM core registers have the following id bit patterns:: 2350 2351 0x4020 0000 0010 <index into the kvm_regs struct:16> 2352 2353ARM 32-bit CP15 registers have the following id bit patterns:: 2354 2355 0x4020 0000 000F <zero:1> <crn:4> <crm:4> <opc1:4> <opc2:3> 2356 2357ARM 64-bit CP15 registers have the following id bit patterns:: 2358 2359 0x4030 0000 000F <zero:1> <zero:4> <crm:4> <opc1:4> <zero:3> 2360 2361ARM CCSIDR registers are demultiplexed by CSSELR value:: 2362 2363 0x4020 0000 0011 00 <csselr:8> 2364 2365ARM 32-bit VFP control registers have the following id bit patterns:: 2366 2367 0x4020 0000 0012 1 <regno:12> 2368 2369ARM 64-bit FP registers have the following id bit patterns:: 2370 2371 0x4030 0000 0012 0 <regno:12> 2372 2373ARM firmware pseudo-registers have the following bit pattern:: 2374 2375 0x4030 0000 0014 <regno:16> 2376 2377 2378arm64 registers are mapped using the lower 32 bits. The upper 16 of 2379that is the register group type, or coprocessor number: 2380 2381arm64 core/FP-SIMD registers have the following id bit patterns. Note 2382that the size of the access is variable, as the kvm_regs structure 2383contains elements ranging from 32 to 128 bits. The index is a 32bit 2384value in the kvm_regs structure seen as a 32bit array:: 2385 2386 0x60x0 0000 0010 <index into the kvm_regs struct:16> 2387 2388Specifically: 2389 2390======================= ========= ===== ======================================= 2391 Encoding Register Bits kvm_regs member 2392======================= ========= ===== ======================================= 2393 0x6030 0000 0010 0000 X0 64 regs.regs[0] 2394 0x6030 0000 0010 0002 X1 64 regs.regs[1] 2395 ... 2396 0x6030 0000 0010 003c X30 64 regs.regs[30] 2397 0x6030 0000 0010 003e SP 64 regs.sp 2398 0x6030 0000 0010 0040 PC 64 regs.pc 2399 0x6030 0000 0010 0042 PSTATE 64 regs.pstate 2400 0x6030 0000 0010 0044 SP_EL1 64 sp_el1 2401 0x6030 0000 0010 0046 ELR_EL1 64 elr_el1 2402 0x6030 0000 0010 0048 SPSR_EL1 64 spsr[KVM_SPSR_EL1] (alias SPSR_SVC) 2403 0x6030 0000 0010 004a SPSR_ABT 64 spsr[KVM_SPSR_ABT] 2404 0x6030 0000 0010 004c SPSR_UND 64 spsr[KVM_SPSR_UND] 2405 0x6030 0000 0010 004e SPSR_IRQ 64 spsr[KVM_SPSR_IRQ] 2406 0x6060 0000 0010 0050 SPSR_FIQ 64 spsr[KVM_SPSR_FIQ] 2407 0x6040 0000 0010 0054 V0 128 fp_regs.vregs[0] [1]_ 2408 0x6040 0000 0010 0058 V1 128 fp_regs.vregs[1] [1]_ 2409 ... 2410 0x6040 0000 0010 00d0 V31 128 fp_regs.vregs[31] [1]_ 2411 0x6020 0000 0010 00d4 FPSR 32 fp_regs.fpsr 2412 0x6020 0000 0010 00d5 FPCR 32 fp_regs.fpcr 2413======================= ========= ===== ======================================= 2414 2415.. [1] These encodings are not accepted for SVE-enabled vcpus. See 2416 KVM_ARM_VCPU_INIT. 2417 2418 The equivalent register content can be accessed via bits [127:0] of 2419 the corresponding SVE Zn registers instead for vcpus that have SVE 2420 enabled (see below). 2421 2422arm64 CCSIDR registers are demultiplexed by CSSELR value:: 2423 2424 0x6020 0000 0011 00 <csselr:8> 2425 2426arm64 system registers have the following id bit patterns:: 2427 2428 0x6030 0000 0013 <op0:2> <op1:3> <crn:4> <crm:4> <op2:3> 2429 2430.. warning:: 2431 2432 Two system register IDs do not follow the specified pattern. These 2433 are KVM_REG_ARM_TIMER_CVAL and KVM_REG_ARM_TIMER_CNT, which map to 2434 system registers CNTV_CVAL_EL0 and CNTVCT_EL0 respectively. These 2435 two had their values accidentally swapped, which means TIMER_CVAL is 2436 derived from the register encoding for CNTVCT_EL0 and TIMER_CNT is 2437 derived from the register encoding for CNTV_CVAL_EL0. As this is 2438 API, it must remain this way. 2439 2440arm64 firmware pseudo-registers have the following bit pattern:: 2441 2442 0x6030 0000 0014 <regno:16> 2443 2444arm64 SVE registers have the following bit patterns:: 2445 2446 0x6080 0000 0015 00 <n:5> <slice:5> Zn bits[2048*slice + 2047 : 2048*slice] 2447 0x6050 0000 0015 04 <n:4> <slice:5> Pn bits[256*slice + 255 : 256*slice] 2448 0x6050 0000 0015 060 <slice:5> FFR bits[256*slice + 255 : 256*slice] 2449 0x6060 0000 0015 ffff KVM_REG_ARM64_SVE_VLS pseudo-register 2450 2451Access to register IDs where 2048 * slice >= 128 * max_vq will fail with 2452ENOENT. max_vq is the vcpu's maximum supported vector length in 128-bit 2453quadwords: see [2]_ below. 2454 2455These registers are only accessible on vcpus for which SVE is enabled. 2456See KVM_ARM_VCPU_INIT for details. 2457 2458In addition, except for KVM_REG_ARM64_SVE_VLS, these registers are not 2459accessible until the vcpu's SVE configuration has been finalized 2460using KVM_ARM_VCPU_FINALIZE(KVM_ARM_VCPU_SVE). See KVM_ARM_VCPU_INIT 2461and KVM_ARM_VCPU_FINALIZE for more information about this procedure. 2462 2463KVM_REG_ARM64_SVE_VLS is a pseudo-register that allows the set of vector 2464lengths supported by the vcpu to be discovered and configured by 2465userspace. When transferred to or from user memory via KVM_GET_ONE_REG 2466or KVM_SET_ONE_REG, the value of this register is of type 2467__u64[KVM_ARM64_SVE_VLS_WORDS], and encodes the set of vector lengths as 2468follows:: 2469 2470 __u64 vector_lengths[KVM_ARM64_SVE_VLS_WORDS]; 2471 2472 if (vq >= SVE_VQ_MIN && vq <= SVE_VQ_MAX && 2473 ((vector_lengths[(vq - KVM_ARM64_SVE_VQ_MIN) / 64] >> 2474 ((vq - KVM_ARM64_SVE_VQ_MIN) % 64)) & 1)) 2475 /* Vector length vq * 16 bytes supported */ 2476 else 2477 /* Vector length vq * 16 bytes not supported */ 2478 2479.. [2] The maximum value vq for which the above condition is true is 2480 max_vq. This is the maximum vector length available to the guest on 2481 this vcpu, and determines which register slices are visible through 2482 this ioctl interface. 2483 2484(See Documentation/arm64/sve.rst for an explanation of the "vq" 2485nomenclature.) 2486 2487KVM_REG_ARM64_SVE_VLS is only accessible after KVM_ARM_VCPU_INIT. 2488KVM_ARM_VCPU_INIT initialises it to the best set of vector lengths that 2489the host supports. 2490 2491Userspace may subsequently modify it if desired until the vcpu's SVE 2492configuration is finalized using KVM_ARM_VCPU_FINALIZE(KVM_ARM_VCPU_SVE). 2493 2494Apart from simply removing all vector lengths from the host set that 2495exceed some value, support for arbitrarily chosen sets of vector lengths 2496is hardware-dependent and may not be available. Attempting to configure 2497an invalid set of vector lengths via KVM_SET_ONE_REG will fail with 2498EINVAL. 2499 2500After the vcpu's SVE configuration is finalized, further attempts to 2501write this register will fail with EPERM. 2502 2503 2504MIPS registers are mapped using the lower 32 bits. The upper 16 of that is 2505the register group type: 2506 2507MIPS core registers (see above) have the following id bit patterns:: 2508 2509 0x7030 0000 0000 <reg:16> 2510 2511MIPS CP0 registers (see KVM_REG_MIPS_CP0_* above) have the following id bit 2512patterns depending on whether they're 32-bit or 64-bit registers:: 2513 2514 0x7020 0000 0001 00 <reg:5> <sel:3> (32-bit) 2515 0x7030 0000 0001 00 <reg:5> <sel:3> (64-bit) 2516 2517Note: KVM_REG_MIPS_CP0_ENTRYLO0 and KVM_REG_MIPS_CP0_ENTRYLO1 are the MIPS64 2518versions of the EntryLo registers regardless of the word size of the host 2519hardware, host kernel, guest, and whether XPA is present in the guest, i.e. 2520with the RI and XI bits (if they exist) in bits 63 and 62 respectively, and 2521the PFNX field starting at bit 30. 2522 2523MIPS MAARs (see KVM_REG_MIPS_CP0_MAAR(*) above) have the following id bit 2524patterns:: 2525 2526 0x7030 0000 0001 01 <reg:8> 2527 2528MIPS KVM control registers (see above) have the following id bit patterns:: 2529 2530 0x7030 0000 0002 <reg:16> 2531 2532MIPS FPU registers (see KVM_REG_MIPS_FPR_{32,64}() above) have the following 2533id bit patterns depending on the size of the register being accessed. They are 2534always accessed according to the current guest FPU mode (Status.FR and 2535Config5.FRE), i.e. as the guest would see them, and they become unpredictable 2536if the guest FPU mode is changed. MIPS SIMD Architecture (MSA) vector 2537registers (see KVM_REG_MIPS_VEC_128() above) have similar patterns as they 2538overlap the FPU registers:: 2539 2540 0x7020 0000 0003 00 <0:3> <reg:5> (32-bit FPU registers) 2541 0x7030 0000 0003 00 <0:3> <reg:5> (64-bit FPU registers) 2542 0x7040 0000 0003 00 <0:3> <reg:5> (128-bit MSA vector registers) 2543 2544MIPS FPU control registers (see KVM_REG_MIPS_FCR_{IR,CSR} above) have the 2545following id bit patterns:: 2546 2547 0x7020 0000 0003 01 <0:3> <reg:5> 2548 2549MIPS MSA control registers (see KVM_REG_MIPS_MSA_{IR,CSR} above) have the 2550following id bit patterns:: 2551 2552 0x7020 0000 0003 02 <0:3> <reg:5> 2553 2554 25554.69 KVM_GET_ONE_REG 2556-------------------- 2557 2558:Capability: KVM_CAP_ONE_REG 2559:Architectures: all 2560:Type: vcpu ioctl 2561:Parameters: struct kvm_one_reg (in and out) 2562:Returns: 0 on success, negative value on failure 2563 2564Errors include: 2565 2566 ======== ============================================================ 2567 ENOENT no such register 2568 EINVAL invalid register ID, or no such register or used with VMs in 2569 protected virtualization mode on s390 2570 EPERM (arm64) register access not allowed before vcpu finalization 2571 ======== ============================================================ 2572 2573(These error codes are indicative only: do not rely on a specific error 2574code being returned in a specific situation.) 2575 2576This ioctl allows to receive the value of a single register implemented 2577in a vcpu. The register to read is indicated by the "id" field of the 2578kvm_one_reg struct passed in. On success, the register value can be found 2579at the memory location pointed to by "addr". 2580 2581The list of registers accessible using this interface is identical to the 2582list in 4.68. 2583 2584 25854.70 KVM_KVMCLOCK_CTRL 2586---------------------- 2587 2588:Capability: KVM_CAP_KVMCLOCK_CTRL 2589:Architectures: Any that implement pvclocks (currently x86 only) 2590:Type: vcpu ioctl 2591:Parameters: None 2592:Returns: 0 on success, -1 on error 2593 2594This ioctl sets a flag accessible to the guest indicating that the specified 2595vCPU has been paused by the host userspace. 2596 2597The host will set a flag in the pvclock structure that is checked from the 2598soft lockup watchdog. The flag is part of the pvclock structure that is 2599shared between guest and host, specifically the second bit of the flags 2600field of the pvclock_vcpu_time_info structure. It will be set exclusively by 2601the host and read/cleared exclusively by the guest. The guest operation of 2602checking and clearing the flag must be an atomic operation so 2603load-link/store-conditional, or equivalent must be used. There are two cases 2604where the guest will clear the flag: when the soft lockup watchdog timer resets 2605itself or when a soft lockup is detected. This ioctl can be called any time 2606after pausing the vcpu, but before it is resumed. 2607 2608 26094.71 KVM_SIGNAL_MSI 2610------------------- 2611 2612:Capability: KVM_CAP_SIGNAL_MSI 2613:Architectures: x86 arm arm64 2614:Type: vm ioctl 2615:Parameters: struct kvm_msi (in) 2616:Returns: >0 on delivery, 0 if guest blocked the MSI, and -1 on error 2617 2618Directly inject a MSI message. Only valid with in-kernel irqchip that handles 2619MSI messages. 2620 2621:: 2622 2623 struct kvm_msi { 2624 __u32 address_lo; 2625 __u32 address_hi; 2626 __u32 data; 2627 __u32 flags; 2628 __u32 devid; 2629 __u8 pad[12]; 2630 }; 2631 2632flags: 2633 KVM_MSI_VALID_DEVID: devid contains a valid value. The per-VM 2634 KVM_CAP_MSI_DEVID capability advertises the requirement to provide 2635 the device ID. If this capability is not available, userspace 2636 should never set the KVM_MSI_VALID_DEVID flag as the ioctl might fail. 2637 2638If KVM_MSI_VALID_DEVID is set, devid contains a unique device identifier 2639for the device that wrote the MSI message. For PCI, this is usually a 2640BFD identifier in the lower 16 bits. 2641 2642On x86, address_hi is ignored unless the KVM_X2APIC_API_USE_32BIT_IDS 2643feature of KVM_CAP_X2APIC_API capability is enabled. If it is enabled, 2644address_hi bits 31-8 provide bits 31-8 of the destination id. Bits 7-0 of 2645address_hi must be zero. 2646 2647 26484.71 KVM_CREATE_PIT2 2649-------------------- 2650 2651:Capability: KVM_CAP_PIT2 2652:Architectures: x86 2653:Type: vm ioctl 2654:Parameters: struct kvm_pit_config (in) 2655:Returns: 0 on success, -1 on error 2656 2657Creates an in-kernel device model for the i8254 PIT. This call is only valid 2658after enabling in-kernel irqchip support via KVM_CREATE_IRQCHIP. The following 2659parameters have to be passed:: 2660 2661 struct kvm_pit_config { 2662 __u32 flags; 2663 __u32 pad[15]; 2664 }; 2665 2666Valid flags are:: 2667 2668 #define KVM_PIT_SPEAKER_DUMMY 1 /* emulate speaker port stub */ 2669 2670PIT timer interrupts may use a per-VM kernel thread for injection. If it 2671exists, this thread will have a name of the following pattern:: 2672 2673 kvm-pit/<owner-process-pid> 2674 2675When running a guest with elevated priorities, the scheduling parameters of 2676this thread may have to be adjusted accordingly. 2677 2678This IOCTL replaces the obsolete KVM_CREATE_PIT. 2679 2680 26814.72 KVM_GET_PIT2 2682----------------- 2683 2684:Capability: KVM_CAP_PIT_STATE2 2685:Architectures: x86 2686:Type: vm ioctl 2687:Parameters: struct kvm_pit_state2 (out) 2688:Returns: 0 on success, -1 on error 2689 2690Retrieves the state of the in-kernel PIT model. Only valid after 2691KVM_CREATE_PIT2. The state is returned in the following structure:: 2692 2693 struct kvm_pit_state2 { 2694 struct kvm_pit_channel_state channels[3]; 2695 __u32 flags; 2696 __u32 reserved[9]; 2697 }; 2698 2699Valid flags are:: 2700 2701 /* disable PIT in HPET legacy mode */ 2702 #define KVM_PIT_FLAGS_HPET_LEGACY 0x00000001 2703 2704This IOCTL replaces the obsolete KVM_GET_PIT. 2705 2706 27074.73 KVM_SET_PIT2 2708----------------- 2709 2710:Capability: KVM_CAP_PIT_STATE2 2711:Architectures: x86 2712:Type: vm ioctl 2713:Parameters: struct kvm_pit_state2 (in) 2714:Returns: 0 on success, -1 on error 2715 2716Sets the state of the in-kernel PIT model. Only valid after KVM_CREATE_PIT2. 2717See KVM_GET_PIT2 for details on struct kvm_pit_state2. 2718 2719This IOCTL replaces the obsolete KVM_SET_PIT. 2720 2721 27224.74 KVM_PPC_GET_SMMU_INFO 2723-------------------------- 2724 2725:Capability: KVM_CAP_PPC_GET_SMMU_INFO 2726:Architectures: powerpc 2727:Type: vm ioctl 2728:Parameters: None 2729:Returns: 0 on success, -1 on error 2730 2731This populates and returns a structure describing the features of 2732the "Server" class MMU emulation supported by KVM. 2733This can in turn be used by userspace to generate the appropriate 2734device-tree properties for the guest operating system. 2735 2736The structure contains some global information, followed by an 2737array of supported segment page sizes:: 2738 2739 struct kvm_ppc_smmu_info { 2740 __u64 flags; 2741 __u32 slb_size; 2742 __u32 pad; 2743 struct kvm_ppc_one_seg_page_size sps[KVM_PPC_PAGE_SIZES_MAX_SZ]; 2744 }; 2745 2746The supported flags are: 2747 2748 - KVM_PPC_PAGE_SIZES_REAL: 2749 When that flag is set, guest page sizes must "fit" the backing 2750 store page sizes. When not set, any page size in the list can 2751 be used regardless of how they are backed by userspace. 2752 2753 - KVM_PPC_1T_SEGMENTS 2754 The emulated MMU supports 1T segments in addition to the 2755 standard 256M ones. 2756 2757 - KVM_PPC_NO_HASH 2758 This flag indicates that HPT guests are not supported by KVM, 2759 thus all guests must use radix MMU mode. 2760 2761The "slb_size" field indicates how many SLB entries are supported 2762 2763The "sps" array contains 8 entries indicating the supported base 2764page sizes for a segment in increasing order. Each entry is defined 2765as follow:: 2766 2767 struct kvm_ppc_one_seg_page_size { 2768 __u32 page_shift; /* Base page shift of segment (or 0) */ 2769 __u32 slb_enc; /* SLB encoding for BookS */ 2770 struct kvm_ppc_one_page_size enc[KVM_PPC_PAGE_SIZES_MAX_SZ]; 2771 }; 2772 2773An entry with a "page_shift" of 0 is unused. Because the array is 2774organized in increasing order, a lookup can stop when encoutering 2775such an entry. 2776 2777The "slb_enc" field provides the encoding to use in the SLB for the 2778page size. The bits are in positions such as the value can directly 2779be OR'ed into the "vsid" argument of the slbmte instruction. 2780 2781The "enc" array is a list which for each of those segment base page 2782size provides the list of supported actual page sizes (which can be 2783only larger or equal to the base page size), along with the 2784corresponding encoding in the hash PTE. Similarly, the array is 27858 entries sorted by increasing sizes and an entry with a "0" shift 2786is an empty entry and a terminator:: 2787 2788 struct kvm_ppc_one_page_size { 2789 __u32 page_shift; /* Page shift (or 0) */ 2790 __u32 pte_enc; /* Encoding in the HPTE (>>12) */ 2791 }; 2792 2793The "pte_enc" field provides a value that can OR'ed into the hash 2794PTE's RPN field (ie, it needs to be shifted left by 12 to OR it 2795into the hash PTE second double word). 2796 27974.75 KVM_IRQFD 2798-------------- 2799 2800:Capability: KVM_CAP_IRQFD 2801:Architectures: x86 s390 arm arm64 2802:Type: vm ioctl 2803:Parameters: struct kvm_irqfd (in) 2804:Returns: 0 on success, -1 on error 2805 2806Allows setting an eventfd to directly trigger a guest interrupt. 2807kvm_irqfd.fd specifies the file descriptor to use as the eventfd and 2808kvm_irqfd.gsi specifies the irqchip pin toggled by this event. When 2809an event is triggered on the eventfd, an interrupt is injected into 2810the guest using the specified gsi pin. The irqfd is removed using 2811the KVM_IRQFD_FLAG_DEASSIGN flag, specifying both kvm_irqfd.fd 2812and kvm_irqfd.gsi. 2813 2814With KVM_CAP_IRQFD_RESAMPLE, KVM_IRQFD supports a de-assert and notify 2815mechanism allowing emulation of level-triggered, irqfd-based 2816interrupts. When KVM_IRQFD_FLAG_RESAMPLE is set the user must pass an 2817additional eventfd in the kvm_irqfd.resamplefd field. When operating 2818in resample mode, posting of an interrupt through kvm_irq.fd asserts 2819the specified gsi in the irqchip. When the irqchip is resampled, such 2820as from an EOI, the gsi is de-asserted and the user is notified via 2821kvm_irqfd.resamplefd. It is the user's responsibility to re-queue 2822the interrupt if the device making use of it still requires service. 2823Note that closing the resamplefd is not sufficient to disable the 2824irqfd. The KVM_IRQFD_FLAG_RESAMPLE is only necessary on assignment 2825and need not be specified with KVM_IRQFD_FLAG_DEASSIGN. 2826 2827On arm/arm64, gsi routing being supported, the following can happen: 2828 2829- in case no routing entry is associated to this gsi, injection fails 2830- in case the gsi is associated to an irqchip routing entry, 2831 irqchip.pin + 32 corresponds to the injected SPI ID. 2832- in case the gsi is associated to an MSI routing entry, the MSI 2833 message and device ID are translated into an LPI (support restricted 2834 to GICv3 ITS in-kernel emulation). 2835 28364.76 KVM_PPC_ALLOCATE_HTAB 2837-------------------------- 2838 2839:Capability: KVM_CAP_PPC_ALLOC_HTAB 2840:Architectures: powerpc 2841:Type: vm ioctl 2842:Parameters: Pointer to u32 containing hash table order (in/out) 2843:Returns: 0 on success, -1 on error 2844 2845This requests the host kernel to allocate an MMU hash table for a 2846guest using the PAPR paravirtualization interface. This only does 2847anything if the kernel is configured to use the Book 3S HV style of 2848virtualization. Otherwise the capability doesn't exist and the ioctl 2849returns an ENOTTY error. The rest of this description assumes Book 3S 2850HV. 2851 2852There must be no vcpus running when this ioctl is called; if there 2853are, it will do nothing and return an EBUSY error. 2854 2855The parameter is a pointer to a 32-bit unsigned integer variable 2856containing the order (log base 2) of the desired size of the hash 2857table, which must be between 18 and 46. On successful return from the 2858ioctl, the value will not be changed by the kernel. 2859 2860If no hash table has been allocated when any vcpu is asked to run 2861(with the KVM_RUN ioctl), the host kernel will allocate a 2862default-sized hash table (16 MB). 2863 2864If this ioctl is called when a hash table has already been allocated, 2865with a different order from the existing hash table, the existing hash 2866table will be freed and a new one allocated. If this is ioctl is 2867called when a hash table has already been allocated of the same order 2868as specified, the kernel will clear out the existing hash table (zero 2869all HPTEs). In either case, if the guest is using the virtualized 2870real-mode area (VRMA) facility, the kernel will re-create the VMRA 2871HPTEs on the next KVM_RUN of any vcpu. 2872 28734.77 KVM_S390_INTERRUPT 2874----------------------- 2875 2876:Capability: basic 2877:Architectures: s390 2878:Type: vm ioctl, vcpu ioctl 2879:Parameters: struct kvm_s390_interrupt (in) 2880:Returns: 0 on success, -1 on error 2881 2882Allows to inject an interrupt to the guest. Interrupts can be floating 2883(vm ioctl) or per cpu (vcpu ioctl), depending on the interrupt type. 2884 2885Interrupt parameters are passed via kvm_s390_interrupt:: 2886 2887 struct kvm_s390_interrupt { 2888 __u32 type; 2889 __u32 parm; 2890 __u64 parm64; 2891 }; 2892 2893type can be one of the following: 2894 2895KVM_S390_SIGP_STOP (vcpu) 2896 - sigp stop; optional flags in parm 2897KVM_S390_PROGRAM_INT (vcpu) 2898 - program check; code in parm 2899KVM_S390_SIGP_SET_PREFIX (vcpu) 2900 - sigp set prefix; prefix address in parm 2901KVM_S390_RESTART (vcpu) 2902 - restart 2903KVM_S390_INT_CLOCK_COMP (vcpu) 2904 - clock comparator interrupt 2905KVM_S390_INT_CPU_TIMER (vcpu) 2906 - CPU timer interrupt 2907KVM_S390_INT_VIRTIO (vm) 2908 - virtio external interrupt; external interrupt 2909 parameters in parm and parm64 2910KVM_S390_INT_SERVICE (vm) 2911 - sclp external interrupt; sclp parameter in parm 2912KVM_S390_INT_EMERGENCY (vcpu) 2913 - sigp emergency; source cpu in parm 2914KVM_S390_INT_EXTERNAL_CALL (vcpu) 2915 - sigp external call; source cpu in parm 2916KVM_S390_INT_IO(ai,cssid,ssid,schid) (vm) 2917 - compound value to indicate an 2918 I/O interrupt (ai - adapter interrupt; cssid,ssid,schid - subchannel); 2919 I/O interruption parameters in parm (subchannel) and parm64 (intparm, 2920 interruption subclass) 2921KVM_S390_MCHK (vm, vcpu) 2922 - machine check interrupt; cr 14 bits in parm, machine check interrupt 2923 code in parm64 (note that machine checks needing further payload are not 2924 supported by this ioctl) 2925 2926This is an asynchronous vcpu ioctl and can be invoked from any thread. 2927 29284.78 KVM_PPC_GET_HTAB_FD 2929------------------------ 2930 2931:Capability: KVM_CAP_PPC_HTAB_FD 2932:Architectures: powerpc 2933:Type: vm ioctl 2934:Parameters: Pointer to struct kvm_get_htab_fd (in) 2935:Returns: file descriptor number (>= 0) on success, -1 on error 2936 2937This returns a file descriptor that can be used either to read out the 2938entries in the guest's hashed page table (HPT), or to write entries to 2939initialize the HPT. The returned fd can only be written to if the 2940KVM_GET_HTAB_WRITE bit is set in the flags field of the argument, and 2941can only be read if that bit is clear. The argument struct looks like 2942this:: 2943 2944 /* For KVM_PPC_GET_HTAB_FD */ 2945 struct kvm_get_htab_fd { 2946 __u64 flags; 2947 __u64 start_index; 2948 __u64 reserved[2]; 2949 }; 2950 2951 /* Values for kvm_get_htab_fd.flags */ 2952 #define KVM_GET_HTAB_BOLTED_ONLY ((__u64)0x1) 2953 #define KVM_GET_HTAB_WRITE ((__u64)0x2) 2954 2955The 'start_index' field gives the index in the HPT of the entry at 2956which to start reading. It is ignored when writing. 2957 2958Reads on the fd will initially supply information about all 2959"interesting" HPT entries. Interesting entries are those with the 2960bolted bit set, if the KVM_GET_HTAB_BOLTED_ONLY bit is set, otherwise 2961all entries. When the end of the HPT is reached, the read() will 2962return. If read() is called again on the fd, it will start again from 2963the beginning of the HPT, but will only return HPT entries that have 2964changed since they were last read. 2965 2966Data read or written is structured as a header (8 bytes) followed by a 2967series of valid HPT entries (16 bytes) each. The header indicates how 2968many valid HPT entries there are and how many invalid entries follow 2969the valid entries. The invalid entries are not represented explicitly 2970in the stream. The header format is:: 2971 2972 struct kvm_get_htab_header { 2973 __u32 index; 2974 __u16 n_valid; 2975 __u16 n_invalid; 2976 }; 2977 2978Writes to the fd create HPT entries starting at the index given in the 2979header; first 'n_valid' valid entries with contents from the data 2980written, then 'n_invalid' invalid entries, invalidating any previously 2981valid entries found. 2982 29834.79 KVM_CREATE_DEVICE 2984---------------------- 2985 2986:Capability: KVM_CAP_DEVICE_CTRL 2987:Type: vm ioctl 2988:Parameters: struct kvm_create_device (in/out) 2989:Returns: 0 on success, -1 on error 2990 2991Errors: 2992 2993 ====== ======================================================= 2994 ENODEV The device type is unknown or unsupported 2995 EEXIST Device already created, and this type of device may not 2996 be instantiated multiple times 2997 ====== ======================================================= 2998 2999 Other error conditions may be defined by individual device types or 3000 have their standard meanings. 3001 3002Creates an emulated device in the kernel. The file descriptor returned 3003in fd can be used with KVM_SET/GET/HAS_DEVICE_ATTR. 3004 3005If the KVM_CREATE_DEVICE_TEST flag is set, only test whether the 3006device type is supported (not necessarily whether it can be created 3007in the current vm). 3008 3009Individual devices should not define flags. Attributes should be used 3010for specifying any behavior that is not implied by the device type 3011number. 3012 3013:: 3014 3015 struct kvm_create_device { 3016 __u32 type; /* in: KVM_DEV_TYPE_xxx */ 3017 __u32 fd; /* out: device handle */ 3018 __u32 flags; /* in: KVM_CREATE_DEVICE_xxx */ 3019 }; 3020 30214.80 KVM_SET_DEVICE_ATTR/KVM_GET_DEVICE_ATTR 3022-------------------------------------------- 3023 3024:Capability: KVM_CAP_DEVICE_CTRL, KVM_CAP_VM_ATTRIBUTES for vm device, 3025 KVM_CAP_VCPU_ATTRIBUTES for vcpu device 3026:Type: device ioctl, vm ioctl, vcpu ioctl 3027:Parameters: struct kvm_device_attr 3028:Returns: 0 on success, -1 on error 3029 3030Errors: 3031 3032 ===== ============================================================= 3033 ENXIO The group or attribute is unknown/unsupported for this device 3034 or hardware support is missing. 3035 EPERM The attribute cannot (currently) be accessed this way 3036 (e.g. read-only attribute, or attribute that only makes 3037 sense when the device is in a different state) 3038 ===== ============================================================= 3039 3040 Other error conditions may be defined by individual device types. 3041 3042Gets/sets a specified piece of device configuration and/or state. The 3043semantics are device-specific. See individual device documentation in 3044the "devices" directory. As with ONE_REG, the size of the data 3045transferred is defined by the particular attribute. 3046 3047:: 3048 3049 struct kvm_device_attr { 3050 __u32 flags; /* no flags currently defined */ 3051 __u32 group; /* device-defined */ 3052 __u64 attr; /* group-defined */ 3053 __u64 addr; /* userspace address of attr data */ 3054 }; 3055 30564.81 KVM_HAS_DEVICE_ATTR 3057------------------------ 3058 3059:Capability: KVM_CAP_DEVICE_CTRL, KVM_CAP_VM_ATTRIBUTES for vm device, 3060 KVM_CAP_VCPU_ATTRIBUTES for vcpu device 3061:Type: device ioctl, vm ioctl, vcpu ioctl 3062:Parameters: struct kvm_device_attr 3063:Returns: 0 on success, -1 on error 3064 3065Errors: 3066 3067 ===== ============================================================= 3068 ENXIO The group or attribute is unknown/unsupported for this device 3069 or hardware support is missing. 3070 ===== ============================================================= 3071 3072Tests whether a device supports a particular attribute. A successful 3073return indicates the attribute is implemented. It does not necessarily 3074indicate that the attribute can be read or written in the device's 3075current state. "addr" is ignored. 3076 30774.82 KVM_ARM_VCPU_INIT 3078---------------------- 3079 3080:Capability: basic 3081:Architectures: arm, arm64 3082:Type: vcpu ioctl 3083:Parameters: struct kvm_vcpu_init (in) 3084:Returns: 0 on success; -1 on error 3085 3086Errors: 3087 3088 ====== ================================================================= 3089 EINVAL the target is unknown, or the combination of features is invalid. 3090 ENOENT a features bit specified is unknown. 3091 ====== ================================================================= 3092 3093This tells KVM what type of CPU to present to the guest, and what 3094optional features it should have. This will cause a reset of the cpu 3095registers to their initial values. If this is not called, KVM_RUN will 3096return ENOEXEC for that vcpu. 3097 3098Note that because some registers reflect machine topology, all vcpus 3099should be created before this ioctl is invoked. 3100 3101Userspace can call this function multiple times for a given vcpu, including 3102after the vcpu has been run. This will reset the vcpu to its initial 3103state. All calls to this function after the initial call must use the same 3104target and same set of feature flags, otherwise EINVAL will be returned. 3105 3106Possible features: 3107 3108 - KVM_ARM_VCPU_POWER_OFF: Starts the CPU in a power-off state. 3109 Depends on KVM_CAP_ARM_PSCI. If not set, the CPU will be powered on 3110 and execute guest code when KVM_RUN is called. 3111 - KVM_ARM_VCPU_EL1_32BIT: Starts the CPU in a 32bit mode. 3112 Depends on KVM_CAP_ARM_EL1_32BIT (arm64 only). 3113 - KVM_ARM_VCPU_PSCI_0_2: Emulate PSCI v0.2 (or a future revision 3114 backward compatible with v0.2) for the CPU. 3115 Depends on KVM_CAP_ARM_PSCI_0_2. 3116 - KVM_ARM_VCPU_PMU_V3: Emulate PMUv3 for the CPU. 3117 Depends on KVM_CAP_ARM_PMU_V3. 3118 3119 - KVM_ARM_VCPU_PTRAUTH_ADDRESS: Enables Address Pointer authentication 3120 for arm64 only. 3121 Depends on KVM_CAP_ARM_PTRAUTH_ADDRESS. 3122 If KVM_CAP_ARM_PTRAUTH_ADDRESS and KVM_CAP_ARM_PTRAUTH_GENERIC are 3123 both present, then both KVM_ARM_VCPU_PTRAUTH_ADDRESS and 3124 KVM_ARM_VCPU_PTRAUTH_GENERIC must be requested or neither must be 3125 requested. 3126 3127 - KVM_ARM_VCPU_PTRAUTH_GENERIC: Enables Generic Pointer authentication 3128 for arm64 only. 3129 Depends on KVM_CAP_ARM_PTRAUTH_GENERIC. 3130 If KVM_CAP_ARM_PTRAUTH_ADDRESS and KVM_CAP_ARM_PTRAUTH_GENERIC are 3131 both present, then both KVM_ARM_VCPU_PTRAUTH_ADDRESS and 3132 KVM_ARM_VCPU_PTRAUTH_GENERIC must be requested or neither must be 3133 requested. 3134 3135 - KVM_ARM_VCPU_SVE: Enables SVE for the CPU (arm64 only). 3136 Depends on KVM_CAP_ARM_SVE. 3137 Requires KVM_ARM_VCPU_FINALIZE(KVM_ARM_VCPU_SVE): 3138 3139 * After KVM_ARM_VCPU_INIT: 3140 3141 - KVM_REG_ARM64_SVE_VLS may be read using KVM_GET_ONE_REG: the 3142 initial value of this pseudo-register indicates the best set of 3143 vector lengths possible for a vcpu on this host. 3144 3145 * Before KVM_ARM_VCPU_FINALIZE(KVM_ARM_VCPU_SVE): 3146 3147 - KVM_RUN and KVM_GET_REG_LIST are not available; 3148 3149 - KVM_GET_ONE_REG and KVM_SET_ONE_REG cannot be used to access 3150 the scalable archietctural SVE registers 3151 KVM_REG_ARM64_SVE_ZREG(), KVM_REG_ARM64_SVE_PREG() or 3152 KVM_REG_ARM64_SVE_FFR; 3153 3154 - KVM_REG_ARM64_SVE_VLS may optionally be written using 3155 KVM_SET_ONE_REG, to modify the set of vector lengths available 3156 for the vcpu. 3157 3158 * After KVM_ARM_VCPU_FINALIZE(KVM_ARM_VCPU_SVE): 3159 3160 - the KVM_REG_ARM64_SVE_VLS pseudo-register is immutable, and can 3161 no longer be written using KVM_SET_ONE_REG. 3162 31634.83 KVM_ARM_PREFERRED_TARGET 3164----------------------------- 3165 3166:Capability: basic 3167:Architectures: arm, arm64 3168:Type: vm ioctl 3169:Parameters: struct kvm_vcpu_init (out) 3170:Returns: 0 on success; -1 on error 3171 3172Errors: 3173 3174 ====== ========================================== 3175 ENODEV no preferred target available for the host 3176 ====== ========================================== 3177 3178This queries KVM for preferred CPU target type which can be emulated 3179by KVM on underlying host. 3180 3181The ioctl returns struct kvm_vcpu_init instance containing information 3182about preferred CPU target type and recommended features for it. The 3183kvm_vcpu_init->features bitmap returned will have feature bits set if 3184the preferred target recommends setting these features, but this is 3185not mandatory. 3186 3187The information returned by this ioctl can be used to prepare an instance 3188of struct kvm_vcpu_init for KVM_ARM_VCPU_INIT ioctl which will result in 3189VCPU matching underlying host. 3190 3191 31924.84 KVM_GET_REG_LIST 3193--------------------- 3194 3195:Capability: basic 3196:Architectures: arm, arm64, mips 3197:Type: vcpu ioctl 3198:Parameters: struct kvm_reg_list (in/out) 3199:Returns: 0 on success; -1 on error 3200 3201Errors: 3202 3203 ===== ============================================================== 3204 E2BIG the reg index list is too big to fit in the array specified by 3205 the user (the number required will be written into n). 3206 ===== ============================================================== 3207 3208:: 3209 3210 struct kvm_reg_list { 3211 __u64 n; /* number of registers in reg[] */ 3212 __u64 reg[0]; 3213 }; 3214 3215This ioctl returns the guest registers that are supported for the 3216KVM_GET_ONE_REG/KVM_SET_ONE_REG calls. 3217 3218 32194.85 KVM_ARM_SET_DEVICE_ADDR (deprecated) 3220----------------------------------------- 3221 3222:Capability: KVM_CAP_ARM_SET_DEVICE_ADDR 3223:Architectures: arm, arm64 3224:Type: vm ioctl 3225:Parameters: struct kvm_arm_device_address (in) 3226:Returns: 0 on success, -1 on error 3227 3228Errors: 3229 3230 ====== ============================================ 3231 ENODEV The device id is unknown 3232 ENXIO Device not supported on current system 3233 EEXIST Address already set 3234 E2BIG Address outside guest physical address space 3235 EBUSY Address overlaps with other device range 3236 ====== ============================================ 3237 3238:: 3239 3240 struct kvm_arm_device_addr { 3241 __u64 id; 3242 __u64 addr; 3243 }; 3244 3245Specify a device address in the guest's physical address space where guests 3246can access emulated or directly exposed devices, which the host kernel needs 3247to know about. The id field is an architecture specific identifier for a 3248specific device. 3249 3250ARM/arm64 divides the id field into two parts, a device id and an 3251address type id specific to the individual device:: 3252 3253 bits: | 63 ... 32 | 31 ... 16 | 15 ... 0 | 3254 field: | 0x00000000 | device id | addr type id | 3255 3256ARM/arm64 currently only require this when using the in-kernel GIC 3257support for the hardware VGIC features, using KVM_ARM_DEVICE_VGIC_V2 3258as the device id. When setting the base address for the guest's 3259mapping of the VGIC virtual CPU and distributor interface, the ioctl 3260must be called after calling KVM_CREATE_IRQCHIP, but before calling 3261KVM_RUN on any of the VCPUs. Calling this ioctl twice for any of the 3262base addresses will return -EEXIST. 3263 3264Note, this IOCTL is deprecated and the more flexible SET/GET_DEVICE_ATTR API 3265should be used instead. 3266 3267 32684.86 KVM_PPC_RTAS_DEFINE_TOKEN 3269------------------------------ 3270 3271:Capability: KVM_CAP_PPC_RTAS 3272:Architectures: ppc 3273:Type: vm ioctl 3274:Parameters: struct kvm_rtas_token_args 3275:Returns: 0 on success, -1 on error 3276 3277Defines a token value for a RTAS (Run Time Abstraction Services) 3278service in order to allow it to be handled in the kernel. The 3279argument struct gives the name of the service, which must be the name 3280of a service that has a kernel-side implementation. If the token 3281value is non-zero, it will be associated with that service, and 3282subsequent RTAS calls by the guest specifying that token will be 3283handled by the kernel. If the token value is 0, then any token 3284associated with the service will be forgotten, and subsequent RTAS 3285calls by the guest for that service will be passed to userspace to be 3286handled. 3287 32884.87 KVM_SET_GUEST_DEBUG 3289------------------------ 3290 3291:Capability: KVM_CAP_SET_GUEST_DEBUG 3292:Architectures: x86, s390, ppc, arm64 3293:Type: vcpu ioctl 3294:Parameters: struct kvm_guest_debug (in) 3295:Returns: 0 on success; -1 on error 3296 3297:: 3298 3299 struct kvm_guest_debug { 3300 __u32 control; 3301 __u32 pad; 3302 struct kvm_guest_debug_arch arch; 3303 }; 3304 3305Set up the processor specific debug registers and configure vcpu for 3306handling guest debug events. There are two parts to the structure, the 3307first a control bitfield indicates the type of debug events to handle 3308when running. Common control bits are: 3309 3310 - KVM_GUESTDBG_ENABLE: guest debugging is enabled 3311 - KVM_GUESTDBG_SINGLESTEP: the next run should single-step 3312 3313The top 16 bits of the control field are architecture specific control 3314flags which can include the following: 3315 3316 - KVM_GUESTDBG_USE_SW_BP: using software breakpoints [x86, arm64] 3317 - KVM_GUESTDBG_USE_HW_BP: using hardware breakpoints [x86, s390, arm64] 3318 - KVM_GUESTDBG_INJECT_DB: inject DB type exception [x86] 3319 - KVM_GUESTDBG_INJECT_BP: inject BP type exception [x86] 3320 - KVM_GUESTDBG_EXIT_PENDING: trigger an immediate guest exit [s390] 3321 3322For example KVM_GUESTDBG_USE_SW_BP indicates that software breakpoints 3323are enabled in memory so we need to ensure breakpoint exceptions are 3324correctly trapped and the KVM run loop exits at the breakpoint and not 3325running off into the normal guest vector. For KVM_GUESTDBG_USE_HW_BP 3326we need to ensure the guest vCPUs architecture specific registers are 3327updated to the correct (supplied) values. 3328 3329The second part of the structure is architecture specific and 3330typically contains a set of debug registers. 3331 3332For arm64 the number of debug registers is implementation defined and 3333can be determined by querying the KVM_CAP_GUEST_DEBUG_HW_BPS and 3334KVM_CAP_GUEST_DEBUG_HW_WPS capabilities which return a positive number 3335indicating the number of supported registers. 3336 3337For ppc, the KVM_CAP_PPC_GUEST_DEBUG_SSTEP capability indicates whether 3338the single-step debug event (KVM_GUESTDBG_SINGLESTEP) is supported. 3339 3340When debug events exit the main run loop with the reason 3341KVM_EXIT_DEBUG with the kvm_debug_exit_arch part of the kvm_run 3342structure containing architecture specific debug information. 3343 33444.88 KVM_GET_EMULATED_CPUID 3345--------------------------- 3346 3347:Capability: KVM_CAP_EXT_EMUL_CPUID 3348:Architectures: x86 3349:Type: system ioctl 3350:Parameters: struct kvm_cpuid2 (in/out) 3351:Returns: 0 on success, -1 on error 3352 3353:: 3354 3355 struct kvm_cpuid2 { 3356 __u32 nent; 3357 __u32 flags; 3358 struct kvm_cpuid_entry2 entries[0]; 3359 }; 3360 3361The member 'flags' is used for passing flags from userspace. 3362 3363:: 3364 3365 #define KVM_CPUID_FLAG_SIGNIFCANT_INDEX BIT(0) 3366 #define KVM_CPUID_FLAG_STATEFUL_FUNC BIT(1) /* deprecated */ 3367 #define KVM_CPUID_FLAG_STATE_READ_NEXT BIT(2) /* deprecated */ 3368 3369 struct kvm_cpuid_entry2 { 3370 __u32 function; 3371 __u32 index; 3372 __u32 flags; 3373 __u32 eax; 3374 __u32 ebx; 3375 __u32 ecx; 3376 __u32 edx; 3377 __u32 padding[3]; 3378 }; 3379 3380This ioctl returns x86 cpuid features which are emulated by 3381kvm.Userspace can use the information returned by this ioctl to query 3382which features are emulated by kvm instead of being present natively. 3383 3384Userspace invokes KVM_GET_EMULATED_CPUID by passing a kvm_cpuid2 3385structure with the 'nent' field indicating the number of entries in 3386the variable-size array 'entries'. If the number of entries is too low 3387to describe the cpu capabilities, an error (E2BIG) is returned. If the 3388number is too high, the 'nent' field is adjusted and an error (ENOMEM) 3389is returned. If the number is just right, the 'nent' field is adjusted 3390to the number of valid entries in the 'entries' array, which is then 3391filled. 3392 3393The entries returned are the set CPUID bits of the respective features 3394which kvm emulates, as returned by the CPUID instruction, with unknown 3395or unsupported feature bits cleared. 3396 3397Features like x2apic, for example, may not be present in the host cpu 3398but are exposed by kvm in KVM_GET_SUPPORTED_CPUID because they can be 3399emulated efficiently and thus not included here. 3400 3401The fields in each entry are defined as follows: 3402 3403 function: 3404 the eax value used to obtain the entry 3405 index: 3406 the ecx value used to obtain the entry (for entries that are 3407 affected by ecx) 3408 flags: 3409 an OR of zero or more of the following: 3410 3411 KVM_CPUID_FLAG_SIGNIFCANT_INDEX: 3412 if the index field is valid 3413 3414 eax, ebx, ecx, edx: 3415 3416 the values returned by the cpuid instruction for 3417 this function/index combination 3418 34194.89 KVM_S390_MEM_OP 3420-------------------- 3421 3422:Capability: KVM_CAP_S390_MEM_OP 3423:Architectures: s390 3424:Type: vcpu ioctl 3425:Parameters: struct kvm_s390_mem_op (in) 3426:Returns: = 0 on success, 3427 < 0 on generic error (e.g. -EFAULT or -ENOMEM), 3428 > 0 if an exception occurred while walking the page tables 3429 3430Read or write data from/to the logical (virtual) memory of a VCPU. 3431 3432Parameters are specified via the following structure:: 3433 3434 struct kvm_s390_mem_op { 3435 __u64 gaddr; /* the guest address */ 3436 __u64 flags; /* flags */ 3437 __u32 size; /* amount of bytes */ 3438 __u32 op; /* type of operation */ 3439 __u64 buf; /* buffer in userspace */ 3440 __u8 ar; /* the access register number */ 3441 __u8 reserved[31]; /* should be set to 0 */ 3442 }; 3443 3444The type of operation is specified in the "op" field. It is either 3445KVM_S390_MEMOP_LOGICAL_READ for reading from logical memory space or 3446KVM_S390_MEMOP_LOGICAL_WRITE for writing to logical memory space. The 3447KVM_S390_MEMOP_F_CHECK_ONLY flag can be set in the "flags" field to check 3448whether the corresponding memory access would create an access exception 3449(without touching the data in the memory at the destination). In case an 3450access exception occurred while walking the MMU tables of the guest, the 3451ioctl returns a positive error number to indicate the type of exception. 3452This exception is also raised directly at the corresponding VCPU if the 3453flag KVM_S390_MEMOP_F_INJECT_EXCEPTION is set in the "flags" field. 3454 3455The start address of the memory region has to be specified in the "gaddr" 3456field, and the length of the region in the "size" field (which must not 3457be 0). The maximum value for "size" can be obtained by checking the 3458KVM_CAP_S390_MEM_OP capability. "buf" is the buffer supplied by the 3459userspace application where the read data should be written to for 3460KVM_S390_MEMOP_LOGICAL_READ, or where the data that should be written is 3461stored for a KVM_S390_MEMOP_LOGICAL_WRITE. When KVM_S390_MEMOP_F_CHECK_ONLY 3462is specified, "buf" is unused and can be NULL. "ar" designates the access 3463register number to be used; the valid range is 0..15. 3464 3465The "reserved" field is meant for future extensions. It is not used by 3466KVM with the currently defined set of flags. 3467 34684.90 KVM_S390_GET_SKEYS 3469----------------------- 3470 3471:Capability: KVM_CAP_S390_SKEYS 3472:Architectures: s390 3473:Type: vm ioctl 3474:Parameters: struct kvm_s390_skeys 3475:Returns: 0 on success, KVM_S390_GET_KEYS_NONE if guest is not using storage 3476 keys, negative value on error 3477 3478This ioctl is used to get guest storage key values on the s390 3479architecture. The ioctl takes parameters via the kvm_s390_skeys struct:: 3480 3481 struct kvm_s390_skeys { 3482 __u64 start_gfn; 3483 __u64 count; 3484 __u64 skeydata_addr; 3485 __u32 flags; 3486 __u32 reserved[9]; 3487 }; 3488 3489The start_gfn field is the number of the first guest frame whose storage keys 3490you want to get. 3491 3492The count field is the number of consecutive frames (starting from start_gfn) 3493whose storage keys to get. The count field must be at least 1 and the maximum 3494allowed value is defined as KVM_S390_SKEYS_ALLOC_MAX. Values outside this range 3495will cause the ioctl to return -EINVAL. 3496 3497The skeydata_addr field is the address to a buffer large enough to hold count 3498bytes. This buffer will be filled with storage key data by the ioctl. 3499 35004.91 KVM_S390_SET_SKEYS 3501----------------------- 3502 3503:Capability: KVM_CAP_S390_SKEYS 3504:Architectures: s390 3505:Type: vm ioctl 3506:Parameters: struct kvm_s390_skeys 3507:Returns: 0 on success, negative value on error 3508 3509This ioctl is used to set guest storage key values on the s390 3510architecture. The ioctl takes parameters via the kvm_s390_skeys struct. 3511See section on KVM_S390_GET_SKEYS for struct definition. 3512 3513The start_gfn field is the number of the first guest frame whose storage keys 3514you want to set. 3515 3516The count field is the number of consecutive frames (starting from start_gfn) 3517whose storage keys to get. The count field must be at least 1 and the maximum 3518allowed value is defined as KVM_S390_SKEYS_ALLOC_MAX. Values outside this range 3519will cause the ioctl to return -EINVAL. 3520 3521The skeydata_addr field is the address to a buffer containing count bytes of 3522storage keys. Each byte in the buffer will be set as the storage key for a 3523single frame starting at start_gfn for count frames. 3524 3525Note: If any architecturally invalid key value is found in the given data then 3526the ioctl will return -EINVAL. 3527 35284.92 KVM_S390_IRQ 3529----------------- 3530 3531:Capability: KVM_CAP_S390_INJECT_IRQ 3532:Architectures: s390 3533:Type: vcpu ioctl 3534:Parameters: struct kvm_s390_irq (in) 3535:Returns: 0 on success, -1 on error 3536 3537Errors: 3538 3539 3540 ====== ================================================================= 3541 EINVAL interrupt type is invalid 3542 type is KVM_S390_SIGP_STOP and flag parameter is invalid value, 3543 type is KVM_S390_INT_EXTERNAL_CALL and code is bigger 3544 than the maximum of VCPUs 3545 EBUSY type is KVM_S390_SIGP_SET_PREFIX and vcpu is not stopped, 3546 type is KVM_S390_SIGP_STOP and a stop irq is already pending, 3547 type is KVM_S390_INT_EXTERNAL_CALL and an external call interrupt 3548 is already pending 3549 ====== ================================================================= 3550 3551Allows to inject an interrupt to the guest. 3552 3553Using struct kvm_s390_irq as a parameter allows 3554to inject additional payload which is not 3555possible via KVM_S390_INTERRUPT. 3556 3557Interrupt parameters are passed via kvm_s390_irq:: 3558 3559 struct kvm_s390_irq { 3560 __u64 type; 3561 union { 3562 struct kvm_s390_io_info io; 3563 struct kvm_s390_ext_info ext; 3564 struct kvm_s390_pgm_info pgm; 3565 struct kvm_s390_emerg_info emerg; 3566 struct kvm_s390_extcall_info extcall; 3567 struct kvm_s390_prefix_info prefix; 3568 struct kvm_s390_stop_info stop; 3569 struct kvm_s390_mchk_info mchk; 3570 char reserved[64]; 3571 } u; 3572 }; 3573 3574type can be one of the following: 3575 3576- KVM_S390_SIGP_STOP - sigp stop; parameter in .stop 3577- KVM_S390_PROGRAM_INT - program check; parameters in .pgm 3578- KVM_S390_SIGP_SET_PREFIX - sigp set prefix; parameters in .prefix 3579- KVM_S390_RESTART - restart; no parameters 3580- KVM_S390_INT_CLOCK_COMP - clock comparator interrupt; no parameters 3581- KVM_S390_INT_CPU_TIMER - CPU timer interrupt; no parameters 3582- KVM_S390_INT_EMERGENCY - sigp emergency; parameters in .emerg 3583- KVM_S390_INT_EXTERNAL_CALL - sigp external call; parameters in .extcall 3584- KVM_S390_MCHK - machine check interrupt; parameters in .mchk 3585 3586This is an asynchronous vcpu ioctl and can be invoked from any thread. 3587 35884.94 KVM_S390_GET_IRQ_STATE 3589--------------------------- 3590 3591:Capability: KVM_CAP_S390_IRQ_STATE 3592:Architectures: s390 3593:Type: vcpu ioctl 3594:Parameters: struct kvm_s390_irq_state (out) 3595:Returns: >= number of bytes copied into buffer, 3596 -EINVAL if buffer size is 0, 3597 -ENOBUFS if buffer size is too small to fit all pending interrupts, 3598 -EFAULT if the buffer address was invalid 3599 3600This ioctl allows userspace to retrieve the complete state of all currently 3601pending interrupts in a single buffer. Use cases include migration 3602and introspection. The parameter structure contains the address of a 3603userspace buffer and its length:: 3604 3605 struct kvm_s390_irq_state { 3606 __u64 buf; 3607 __u32 flags; /* will stay unused for compatibility reasons */ 3608 __u32 len; 3609 __u32 reserved[4]; /* will stay unused for compatibility reasons */ 3610 }; 3611 3612Userspace passes in the above struct and for each pending interrupt a 3613struct kvm_s390_irq is copied to the provided buffer. 3614 3615The structure contains a flags and a reserved field for future extensions. As 3616the kernel never checked for flags == 0 and QEMU never pre-zeroed flags and 3617reserved, these fields can not be used in the future without breaking 3618compatibility. 3619 3620If -ENOBUFS is returned the buffer provided was too small and userspace 3621may retry with a bigger buffer. 3622 36234.95 KVM_S390_SET_IRQ_STATE 3624--------------------------- 3625 3626:Capability: KVM_CAP_S390_IRQ_STATE 3627:Architectures: s390 3628:Type: vcpu ioctl 3629:Parameters: struct kvm_s390_irq_state (in) 3630:Returns: 0 on success, 3631 -EFAULT if the buffer address was invalid, 3632 -EINVAL for an invalid buffer length (see below), 3633 -EBUSY if there were already interrupts pending, 3634 errors occurring when actually injecting the 3635 interrupt. See KVM_S390_IRQ. 3636 3637This ioctl allows userspace to set the complete state of all cpu-local 3638interrupts currently pending for the vcpu. It is intended for restoring 3639interrupt state after a migration. The input parameter is a userspace buffer 3640containing a struct kvm_s390_irq_state:: 3641 3642 struct kvm_s390_irq_state { 3643 __u64 buf; 3644 __u32 flags; /* will stay unused for compatibility reasons */ 3645 __u32 len; 3646 __u32 reserved[4]; /* will stay unused for compatibility reasons */ 3647 }; 3648 3649The restrictions for flags and reserved apply as well. 3650(see KVM_S390_GET_IRQ_STATE) 3651 3652The userspace memory referenced by buf contains a struct kvm_s390_irq 3653for each interrupt to be injected into the guest. 3654If one of the interrupts could not be injected for some reason the 3655ioctl aborts. 3656 3657len must be a multiple of sizeof(struct kvm_s390_irq). It must be > 0 3658and it must not exceed (max_vcpus + 32) * sizeof(struct kvm_s390_irq), 3659which is the maximum number of possibly pending cpu-local interrupts. 3660 36614.96 KVM_SMI 3662------------ 3663 3664:Capability: KVM_CAP_X86_SMM 3665:Architectures: x86 3666:Type: vcpu ioctl 3667:Parameters: none 3668:Returns: 0 on success, -1 on error 3669 3670Queues an SMI on the thread's vcpu. 3671 36724.97 KVM_CAP_PPC_MULTITCE 3673------------------------- 3674 3675:Capability: KVM_CAP_PPC_MULTITCE 3676:Architectures: ppc 3677:Type: vm 3678 3679This capability means the kernel is capable of handling hypercalls 3680H_PUT_TCE_INDIRECT and H_STUFF_TCE without passing those into the user 3681space. This significantly accelerates DMA operations for PPC KVM guests. 3682User space should expect that its handlers for these hypercalls 3683are not going to be called if user space previously registered LIOBN 3684in KVM (via KVM_CREATE_SPAPR_TCE or similar calls). 3685 3686In order to enable H_PUT_TCE_INDIRECT and H_STUFF_TCE use in the guest, 3687user space might have to advertise it for the guest. For example, 3688IBM pSeries (sPAPR) guest starts using them if "hcall-multi-tce" is 3689present in the "ibm,hypertas-functions" device-tree property. 3690 3691The hypercalls mentioned above may or may not be processed successfully 3692in the kernel based fast path. If they can not be handled by the kernel, 3693they will get passed on to user space. So user space still has to have 3694an implementation for these despite the in kernel acceleration. 3695 3696This capability is always enabled. 3697 36984.98 KVM_CREATE_SPAPR_TCE_64 3699---------------------------- 3700 3701:Capability: KVM_CAP_SPAPR_TCE_64 3702:Architectures: powerpc 3703:Type: vm ioctl 3704:Parameters: struct kvm_create_spapr_tce_64 (in) 3705:Returns: file descriptor for manipulating the created TCE table 3706 3707This is an extension for KVM_CAP_SPAPR_TCE which only supports 32bit 3708windows, described in 4.62 KVM_CREATE_SPAPR_TCE 3709 3710This capability uses extended struct in ioctl interface:: 3711 3712 /* for KVM_CAP_SPAPR_TCE_64 */ 3713 struct kvm_create_spapr_tce_64 { 3714 __u64 liobn; 3715 __u32 page_shift; 3716 __u32 flags; 3717 __u64 offset; /* in pages */ 3718 __u64 size; /* in pages */ 3719 }; 3720 3721The aim of extension is to support an additional bigger DMA window with 3722a variable page size. 3723KVM_CREATE_SPAPR_TCE_64 receives a 64bit window size, an IOMMU page shift and 3724a bus offset of the corresponding DMA window, @size and @offset are numbers 3725of IOMMU pages. 3726 3727@flags are not used at the moment. 3728 3729The rest of functionality is identical to KVM_CREATE_SPAPR_TCE. 3730 37314.99 KVM_REINJECT_CONTROL 3732------------------------- 3733 3734:Capability: KVM_CAP_REINJECT_CONTROL 3735:Architectures: x86 3736:Type: vm ioctl 3737:Parameters: struct kvm_reinject_control (in) 3738:Returns: 0 on success, 3739 -EFAULT if struct kvm_reinject_control cannot be read, 3740 -ENXIO if KVM_CREATE_PIT or KVM_CREATE_PIT2 didn't succeed earlier. 3741 3742i8254 (PIT) has two modes, reinject and !reinject. The default is reinject, 3743where KVM queues elapsed i8254 ticks and monitors completion of interrupt from 3744vector(s) that i8254 injects. Reinject mode dequeues a tick and injects its 3745interrupt whenever there isn't a pending interrupt from i8254. 3746!reinject mode injects an interrupt as soon as a tick arrives. 3747 3748:: 3749 3750 struct kvm_reinject_control { 3751 __u8 pit_reinject; 3752 __u8 reserved[31]; 3753 }; 3754 3755pit_reinject = 0 (!reinject mode) is recommended, unless running an old 3756operating system that uses the PIT for timing (e.g. Linux 2.4.x). 3757 37584.100 KVM_PPC_CONFIGURE_V3_MMU 3759------------------------------ 3760 3761:Capability: KVM_CAP_PPC_RADIX_MMU or KVM_CAP_PPC_HASH_MMU_V3 3762:Architectures: ppc 3763:Type: vm ioctl 3764:Parameters: struct kvm_ppc_mmuv3_cfg (in) 3765:Returns: 0 on success, 3766 -EFAULT if struct kvm_ppc_mmuv3_cfg cannot be read, 3767 -EINVAL if the configuration is invalid 3768 3769This ioctl controls whether the guest will use radix or HPT (hashed 3770page table) translation, and sets the pointer to the process table for 3771the guest. 3772 3773:: 3774 3775 struct kvm_ppc_mmuv3_cfg { 3776 __u64 flags; 3777 __u64 process_table; 3778 }; 3779 3780There are two bits that can be set in flags; KVM_PPC_MMUV3_RADIX and 3781KVM_PPC_MMUV3_GTSE. KVM_PPC_MMUV3_RADIX, if set, configures the guest 3782to use radix tree translation, and if clear, to use HPT translation. 3783KVM_PPC_MMUV3_GTSE, if set and if KVM permits it, configures the guest 3784to be able to use the global TLB and SLB invalidation instructions; 3785if clear, the guest may not use these instructions. 3786 3787The process_table field specifies the address and size of the guest 3788process table, which is in the guest's space. This field is formatted 3789as the second doubleword of the partition table entry, as defined in 3790the Power ISA V3.00, Book III section 5.7.6.1. 3791 37924.101 KVM_PPC_GET_RMMU_INFO 3793--------------------------- 3794 3795:Capability: KVM_CAP_PPC_RADIX_MMU 3796:Architectures: ppc 3797:Type: vm ioctl 3798:Parameters: struct kvm_ppc_rmmu_info (out) 3799:Returns: 0 on success, 3800 -EFAULT if struct kvm_ppc_rmmu_info cannot be written, 3801 -EINVAL if no useful information can be returned 3802 3803This ioctl returns a structure containing two things: (a) a list 3804containing supported radix tree geometries, and (b) a list that maps 3805page sizes to put in the "AP" (actual page size) field for the tlbie 3806(TLB invalidate entry) instruction. 3807 3808:: 3809 3810 struct kvm_ppc_rmmu_info { 3811 struct kvm_ppc_radix_geom { 3812 __u8 page_shift; 3813 __u8 level_bits[4]; 3814 __u8 pad[3]; 3815 } geometries[8]; 3816 __u32 ap_encodings[8]; 3817 }; 3818 3819The geometries[] field gives up to 8 supported geometries for the 3820radix page table, in terms of the log base 2 of the smallest page 3821size, and the number of bits indexed at each level of the tree, from 3822the PTE level up to the PGD level in that order. Any unused entries 3823will have 0 in the page_shift field. 3824 3825The ap_encodings gives the supported page sizes and their AP field 3826encodings, encoded with the AP value in the top 3 bits and the log 3827base 2 of the page size in the bottom 6 bits. 3828 38294.102 KVM_PPC_RESIZE_HPT_PREPARE 3830-------------------------------- 3831 3832:Capability: KVM_CAP_SPAPR_RESIZE_HPT 3833:Architectures: powerpc 3834:Type: vm ioctl 3835:Parameters: struct kvm_ppc_resize_hpt (in) 3836:Returns: 0 on successful completion, 3837 >0 if a new HPT is being prepared, the value is an estimated 3838 number of milliseconds until preparation is complete, 3839 -EFAULT if struct kvm_reinject_control cannot be read, 3840 -EINVAL if the supplied shift or flags are invalid, 3841 -ENOMEM if unable to allocate the new HPT, 3842 -ENOSPC if there was a hash collision 3843 3844:: 3845 3846 struct kvm_ppc_rmmu_info { 3847 struct kvm_ppc_radix_geom { 3848 __u8 page_shift; 3849 __u8 level_bits[4]; 3850 __u8 pad[3]; 3851 } geometries[8]; 3852 __u32 ap_encodings[8]; 3853 }; 3854 3855The geometries[] field gives up to 8 supported geometries for the 3856radix page table, in terms of the log base 2 of the smallest page 3857size, and the number of bits indexed at each level of the tree, from 3858the PTE level up to the PGD level in that order. Any unused entries 3859will have 0 in the page_shift field. 3860 3861The ap_encodings gives the supported page sizes and their AP field 3862encodings, encoded with the AP value in the top 3 bits and the log 3863base 2 of the page size in the bottom 6 bits. 3864 38654.102 KVM_PPC_RESIZE_HPT_PREPARE 3866-------------------------------- 3867 3868:Capability: KVM_CAP_SPAPR_RESIZE_HPT 3869:Architectures: powerpc 3870:Type: vm ioctl 3871:Parameters: struct kvm_ppc_resize_hpt (in) 3872:Returns: 0 on successful completion, 3873 >0 if a new HPT is being prepared, the value is an estimated 3874 number of milliseconds until preparation is complete, 3875 -EFAULT if struct kvm_reinject_control cannot be read, 3876 -EINVAL if the supplied shift or flags are invalid,when moving existing 3877 HPT entries to the new HPT, 3878 -EIO on other error conditions 3879 3880Used to implement the PAPR extension for runtime resizing of a guest's 3881Hashed Page Table (HPT). Specifically this starts, stops or monitors 3882the preparation of a new potential HPT for the guest, essentially 3883implementing the H_RESIZE_HPT_PREPARE hypercall. 3884 3885If called with shift > 0 when there is no pending HPT for the guest, 3886this begins preparation of a new pending HPT of size 2^(shift) bytes. 3887It then returns a positive integer with the estimated number of 3888milliseconds until preparation is complete. 3889 3890If called when there is a pending HPT whose size does not match that 3891requested in the parameters, discards the existing pending HPT and 3892creates a new one as above. 3893 3894If called when there is a pending HPT of the size requested, will: 3895 3896 * If preparation of the pending HPT is already complete, return 0 3897 * If preparation of the pending HPT has failed, return an error 3898 code, then discard the pending HPT. 3899 * If preparation of the pending HPT is still in progress, return an 3900 estimated number of milliseconds until preparation is complete. 3901 3902If called with shift == 0, discards any currently pending HPT and 3903returns 0 (i.e. cancels any in-progress preparation). 3904 3905flags is reserved for future expansion, currently setting any bits in 3906flags will result in an -EINVAL. 3907 3908Normally this will be called repeatedly with the same parameters until 3909it returns <= 0. The first call will initiate preparation, subsequent 3910ones will monitor preparation until it completes or fails. 3911 3912:: 3913 3914 struct kvm_ppc_resize_hpt { 3915 __u64 flags; 3916 __u32 shift; 3917 __u32 pad; 3918 }; 3919 39204.103 KVM_PPC_RESIZE_HPT_COMMIT 3921------------------------------- 3922 3923:Capability: KVM_CAP_SPAPR_RESIZE_HPT 3924:Architectures: powerpc 3925:Type: vm ioctl 3926:Parameters: struct kvm_ppc_resize_hpt (in) 3927:Returns: 0 on successful completion, 3928 -EFAULT if struct kvm_reinject_control cannot be read, 3929 -EINVAL if the supplied shift or flags are invalid, 3930 -ENXIO is there is no pending HPT, or the pending HPT doesn't 3931 have the requested size, 3932 -EBUSY if the pending HPT is not fully prepared, 3933 -ENOSPC if there was a hash collision when moving existing 3934 HPT entries to the new HPT, 3935 -EIO on other error conditions 3936 3937Used to implement the PAPR extension for runtime resizing of a guest's 3938Hashed Page Table (HPT). Specifically this requests that the guest be 3939transferred to working with the new HPT, essentially implementing the 3940H_RESIZE_HPT_COMMIT hypercall. 3941 3942This should only be called after KVM_PPC_RESIZE_HPT_PREPARE has 3943returned 0 with the same parameters. In other cases 3944KVM_PPC_RESIZE_HPT_COMMIT will return an error (usually -ENXIO or 3945-EBUSY, though others may be possible if the preparation was started, 3946but failed). 3947 3948This will have undefined effects on the guest if it has not already 3949placed itself in a quiescent state where no vcpu will make MMU enabled 3950memory accesses. 3951 3952On succsful completion, the pending HPT will become the guest's active 3953HPT and the previous HPT will be discarded. 3954 3955On failure, the guest will still be operating on its previous HPT. 3956 3957:: 3958 3959 struct kvm_ppc_resize_hpt { 3960 __u64 flags; 3961 __u32 shift; 3962 __u32 pad; 3963 }; 3964 39654.104 KVM_X86_GET_MCE_CAP_SUPPORTED 3966----------------------------------- 3967 3968:Capability: KVM_CAP_MCE 3969:Architectures: x86 3970:Type: system ioctl 3971:Parameters: u64 mce_cap (out) 3972:Returns: 0 on success, -1 on error 3973 3974Returns supported MCE capabilities. The u64 mce_cap parameter 3975has the same format as the MSR_IA32_MCG_CAP register. Supported 3976capabilities will have the corresponding bits set. 3977 39784.105 KVM_X86_SETUP_MCE 3979----------------------- 3980 3981:Capability: KVM_CAP_MCE 3982:Architectures: x86 3983:Type: vcpu ioctl 3984:Parameters: u64 mcg_cap (in) 3985:Returns: 0 on success, 3986 -EFAULT if u64 mcg_cap cannot be read, 3987 -EINVAL if the requested number of banks is invalid, 3988 -EINVAL if requested MCE capability is not supported. 3989 3990Initializes MCE support for use. The u64 mcg_cap parameter 3991has the same format as the MSR_IA32_MCG_CAP register and 3992specifies which capabilities should be enabled. The maximum 3993supported number of error-reporting banks can be retrieved when 3994checking for KVM_CAP_MCE. The supported capabilities can be 3995retrieved with KVM_X86_GET_MCE_CAP_SUPPORTED. 3996 39974.106 KVM_X86_SET_MCE 3998--------------------- 3999 4000:Capability: KVM_CAP_MCE 4001:Architectures: x86 4002:Type: vcpu ioctl 4003:Parameters: struct kvm_x86_mce (in) 4004:Returns: 0 on success, 4005 -EFAULT if struct kvm_x86_mce cannot be read, 4006 -EINVAL if the bank number is invalid, 4007 -EINVAL if VAL bit is not set in status field. 4008 4009Inject a machine check error (MCE) into the guest. The input 4010parameter is:: 4011 4012 struct kvm_x86_mce { 4013 __u64 status; 4014 __u64 addr; 4015 __u64 misc; 4016 __u64 mcg_status; 4017 __u8 bank; 4018 __u8 pad1[7]; 4019 __u64 pad2[3]; 4020 }; 4021 4022If the MCE being reported is an uncorrected error, KVM will 4023inject it as an MCE exception into the guest. If the guest 4024MCG_STATUS register reports that an MCE is in progress, KVM 4025causes an KVM_EXIT_SHUTDOWN vmexit. 4026 4027Otherwise, if the MCE is a corrected error, KVM will just 4028store it in the corresponding bank (provided this bank is 4029not holding a previously reported uncorrected error). 4030 40314.107 KVM_S390_GET_CMMA_BITS 4032---------------------------- 4033 4034:Capability: KVM_CAP_S390_CMMA_MIGRATION 4035:Architectures: s390 4036:Type: vm ioctl 4037:Parameters: struct kvm_s390_cmma_log (in, out) 4038:Returns: 0 on success, a negative value on error 4039 4040This ioctl is used to get the values of the CMMA bits on the s390 4041architecture. It is meant to be used in two scenarios: 4042 4043- During live migration to save the CMMA values. Live migration needs 4044 to be enabled via the KVM_REQ_START_MIGRATION VM property. 4045- To non-destructively peek at the CMMA values, with the flag 4046 KVM_S390_CMMA_PEEK set. 4047 4048The ioctl takes parameters via the kvm_s390_cmma_log struct. The desired 4049values are written to a buffer whose location is indicated via the "values" 4050member in the kvm_s390_cmma_log struct. The values in the input struct are 4051also updated as needed. 4052 4053Each CMMA value takes up one byte. 4054 4055:: 4056 4057 struct kvm_s390_cmma_log { 4058 __u64 start_gfn; 4059 __u32 count; 4060 __u32 flags; 4061 union { 4062 __u64 remaining; 4063 __u64 mask; 4064 }; 4065 __u64 values; 4066 }; 4067 4068start_gfn is the number of the first guest frame whose CMMA values are 4069to be retrieved, 4070 4071count is the length of the buffer in bytes, 4072 4073values points to the buffer where the result will be written to. 4074 4075If count is greater than KVM_S390_SKEYS_MAX, then it is considered to be 4076KVM_S390_SKEYS_MAX. KVM_S390_SKEYS_MAX is re-used for consistency with 4077other ioctls. 4078 4079The result is written in the buffer pointed to by the field values, and 4080the values of the input parameter are updated as follows. 4081 4082Depending on the flags, different actions are performed. The only 4083supported flag so far is KVM_S390_CMMA_PEEK. 4084 4085The default behaviour if KVM_S390_CMMA_PEEK is not set is: 4086start_gfn will indicate the first page frame whose CMMA bits were dirty. 4087It is not necessarily the same as the one passed as input, as clean pages 4088are skipped. 4089 4090count will indicate the number of bytes actually written in the buffer. 4091It can (and very often will) be smaller than the input value, since the 4092buffer is only filled until 16 bytes of clean values are found (which 4093are then not copied in the buffer). Since a CMMA migration block needs 4094the base address and the length, for a total of 16 bytes, we will send 4095back some clean data if there is some dirty data afterwards, as long as 4096the size of the clean data does not exceed the size of the header. This 4097allows to minimize the amount of data to be saved or transferred over 4098the network at the expense of more roundtrips to userspace. The next 4099invocation of the ioctl will skip over all the clean values, saving 4100potentially more than just the 16 bytes we found. 4101 4102If KVM_S390_CMMA_PEEK is set: 4103the existing storage attributes are read even when not in migration 4104mode, and no other action is performed; 4105 4106the output start_gfn will be equal to the input start_gfn, 4107 4108the output count will be equal to the input count, except if the end of 4109memory has been reached. 4110 4111In both cases: 4112the field "remaining" will indicate the total number of dirty CMMA values 4113still remaining, or 0 if KVM_S390_CMMA_PEEK is set and migration mode is 4114not enabled. 4115 4116mask is unused. 4117 4118values points to the userspace buffer where the result will be stored. 4119 4120This ioctl can fail with -ENOMEM if not enough memory can be allocated to 4121complete the task, with -ENXIO if CMMA is not enabled, with -EINVAL if 4122KVM_S390_CMMA_PEEK is not set but migration mode was not enabled, with 4123-EFAULT if the userspace address is invalid or if no page table is 4124present for the addresses (e.g. when using hugepages). 4125 41264.108 KVM_S390_SET_CMMA_BITS 4127---------------------------- 4128 4129:Capability: KVM_CAP_S390_CMMA_MIGRATION 4130:Architectures: s390 4131:Type: vm ioctl 4132:Parameters: struct kvm_s390_cmma_log (in) 4133:Returns: 0 on success, a negative value on error 4134 4135This ioctl is used to set the values of the CMMA bits on the s390 4136architecture. It is meant to be used during live migration to restore 4137the CMMA values, but there are no restrictions on its use. 4138The ioctl takes parameters via the kvm_s390_cmma_values struct. 4139Each CMMA value takes up one byte. 4140 4141:: 4142 4143 struct kvm_s390_cmma_log { 4144 __u64 start_gfn; 4145 __u32 count; 4146 __u32 flags; 4147 union { 4148 __u64 remaining; 4149 __u64 mask; 4150 }; 4151 __u64 values; 4152 }; 4153 4154start_gfn indicates the starting guest frame number, 4155 4156count indicates how many values are to be considered in the buffer, 4157 4158flags is not used and must be 0. 4159 4160mask indicates which PGSTE bits are to be considered. 4161 4162remaining is not used. 4163 4164values points to the buffer in userspace where to store the values. 4165 4166This ioctl can fail with -ENOMEM if not enough memory can be allocated to 4167complete the task, with -ENXIO if CMMA is not enabled, with -EINVAL if 4168the count field is too large (e.g. more than KVM_S390_CMMA_SIZE_MAX) or 4169if the flags field was not 0, with -EFAULT if the userspace address is 4170invalid, if invalid pages are written to (e.g. after the end of memory) 4171or if no page table is present for the addresses (e.g. when using 4172hugepages). 4173 41744.109 KVM_PPC_GET_CPU_CHAR 4175-------------------------- 4176 4177:Capability: KVM_CAP_PPC_GET_CPU_CHAR 4178:Architectures: powerpc 4179:Type: vm ioctl 4180:Parameters: struct kvm_ppc_cpu_char (out) 4181:Returns: 0 on successful completion, 4182 -EFAULT if struct kvm_ppc_cpu_char cannot be written 4183 4184This ioctl gives userspace information about certain characteristics 4185of the CPU relating to speculative execution of instructions and 4186possible information leakage resulting from speculative execution (see 4187CVE-2017-5715, CVE-2017-5753 and CVE-2017-5754). The information is 4188returned in struct kvm_ppc_cpu_char, which looks like this:: 4189 4190 struct kvm_ppc_cpu_char { 4191 __u64 character; /* characteristics of the CPU */ 4192 __u64 behaviour; /* recommended software behaviour */ 4193 __u64 character_mask; /* valid bits in character */ 4194 __u64 behaviour_mask; /* valid bits in behaviour */ 4195 }; 4196 4197For extensibility, the character_mask and behaviour_mask fields 4198indicate which bits of character and behaviour have been filled in by 4199the kernel. If the set of defined bits is extended in future then 4200userspace will be able to tell whether it is running on a kernel that 4201knows about the new bits. 4202 4203The character field describes attributes of the CPU which can help 4204with preventing inadvertent information disclosure - specifically, 4205whether there is an instruction to flash-invalidate the L1 data cache 4206(ori 30,30,0 or mtspr SPRN_TRIG2,rN), whether the L1 data cache is set 4207to a mode where entries can only be used by the thread that created 4208them, whether the bcctr[l] instruction prevents speculation, and 4209whether a speculation barrier instruction (ori 31,31,0) is provided. 4210 4211The behaviour field describes actions that software should take to 4212prevent inadvertent information disclosure, and thus describes which 4213vulnerabilities the hardware is subject to; specifically whether the 4214L1 data cache should be flushed when returning to user mode from the 4215kernel, and whether a speculation barrier should be placed between an 4216array bounds check and the array access. 4217 4218These fields use the same bit definitions as the new 4219H_GET_CPU_CHARACTERISTICS hypercall. 4220 42214.110 KVM_MEMORY_ENCRYPT_OP 4222--------------------------- 4223 4224:Capability: basic 4225:Architectures: x86 4226:Type: vm 4227:Parameters: an opaque platform specific structure (in/out) 4228:Returns: 0 on success; -1 on error 4229 4230If the platform supports creating encrypted VMs then this ioctl can be used 4231for issuing platform-specific memory encryption commands to manage those 4232encrypted VMs. 4233 4234Currently, this ioctl is used for issuing Secure Encrypted Virtualization 4235(SEV) commands on AMD Processors. The SEV commands are defined in 4236Documentation/virt/kvm/amd-memory-encryption.rst. 4237 42384.111 KVM_MEMORY_ENCRYPT_REG_REGION 4239----------------------------------- 4240 4241:Capability: basic 4242:Architectures: x86 4243:Type: system 4244:Parameters: struct kvm_enc_region (in) 4245:Returns: 0 on success; -1 on error 4246 4247This ioctl can be used to register a guest memory region which may 4248contain encrypted data (e.g. guest RAM, SMRAM etc). 4249 4250It is used in the SEV-enabled guest. When encryption is enabled, a guest 4251memory region may contain encrypted data. The SEV memory encryption 4252engine uses a tweak such that two identical plaintext pages, each at 4253different locations will have differing ciphertexts. So swapping or 4254moving ciphertext of those pages will not result in plaintext being 4255swapped. So relocating (or migrating) physical backing pages for the SEV 4256guest will require some additional steps. 4257 4258Note: The current SEV key management spec does not provide commands to 4259swap or migrate (move) ciphertext pages. Hence, for now we pin the guest 4260memory region registered with the ioctl. 4261 42624.112 KVM_MEMORY_ENCRYPT_UNREG_REGION 4263------------------------------------- 4264 4265:Capability: basic 4266:Architectures: x86 4267:Type: system 4268:Parameters: struct kvm_enc_region (in) 4269:Returns: 0 on success; -1 on error 4270 4271This ioctl can be used to unregister the guest memory region registered 4272with KVM_MEMORY_ENCRYPT_REG_REGION ioctl above. 4273 42744.113 KVM_HYPERV_EVENTFD 4275------------------------ 4276 4277:Capability: KVM_CAP_HYPERV_EVENTFD 4278:Architectures: x86 4279:Type: vm ioctl 4280:Parameters: struct kvm_hyperv_eventfd (in) 4281 4282This ioctl (un)registers an eventfd to receive notifications from the guest on 4283the specified Hyper-V connection id through the SIGNAL_EVENT hypercall, without 4284causing a user exit. SIGNAL_EVENT hypercall with non-zero event flag number 4285(bits 24-31) still triggers a KVM_EXIT_HYPERV_HCALL user exit. 4286 4287:: 4288 4289 struct kvm_hyperv_eventfd { 4290 __u32 conn_id; 4291 __s32 fd; 4292 __u32 flags; 4293 __u32 padding[3]; 4294 }; 4295 4296The conn_id field should fit within 24 bits:: 4297 4298 #define KVM_HYPERV_CONN_ID_MASK 0x00ffffff 4299 4300The acceptable values for the flags field are:: 4301 4302 #define KVM_HYPERV_EVENTFD_DEASSIGN (1 << 0) 4303 4304:Returns: 0 on success, 4305 -EINVAL if conn_id or flags is outside the allowed range, 4306 -ENOENT on deassign if the conn_id isn't registered, 4307 -EEXIST on assign if the conn_id is already registered 4308 43094.114 KVM_GET_NESTED_STATE 4310-------------------------- 4311 4312:Capability: KVM_CAP_NESTED_STATE 4313:Architectures: x86 4314:Type: vcpu ioctl 4315:Parameters: struct kvm_nested_state (in/out) 4316:Returns: 0 on success, -1 on error 4317 4318Errors: 4319 4320 ===== ============================================================= 4321 E2BIG the total state size exceeds the value of 'size' specified by 4322 the user; the size required will be written into size. 4323 ===== ============================================================= 4324 4325:: 4326 4327 struct kvm_nested_state { 4328 __u16 flags; 4329 __u16 format; 4330 __u32 size; 4331 4332 union { 4333 struct kvm_vmx_nested_state_hdr vmx; 4334 struct kvm_svm_nested_state_hdr svm; 4335 4336 /* Pad the header to 128 bytes. */ 4337 __u8 pad[120]; 4338 } hdr; 4339 4340 union { 4341 struct kvm_vmx_nested_state_data vmx[0]; 4342 struct kvm_svm_nested_state_data svm[0]; 4343 } data; 4344 }; 4345 4346 #define KVM_STATE_NESTED_GUEST_MODE 0x00000001 4347 #define KVM_STATE_NESTED_RUN_PENDING 0x00000002 4348 #define KVM_STATE_NESTED_EVMCS 0x00000004 4349 4350 #define KVM_STATE_NESTED_FORMAT_VMX 0 4351 #define KVM_STATE_NESTED_FORMAT_SVM 1 4352 4353 #define KVM_STATE_NESTED_VMX_VMCS_SIZE 0x1000 4354 4355 #define KVM_STATE_NESTED_VMX_SMM_GUEST_MODE 0x00000001 4356 #define KVM_STATE_NESTED_VMX_SMM_VMXON 0x00000002 4357 4358 #define KVM_STATE_VMX_PREEMPTION_TIMER_DEADLINE 0x00000001 4359 4360 struct kvm_vmx_nested_state_hdr { 4361 __u64 vmxon_pa; 4362 __u64 vmcs12_pa; 4363 4364 struct { 4365 __u16 flags; 4366 } smm; 4367 4368 __u32 flags; 4369 __u64 preemption_timer_deadline; 4370 }; 4371 4372 struct kvm_vmx_nested_state_data { 4373 __u8 vmcs12[KVM_STATE_NESTED_VMX_VMCS_SIZE]; 4374 __u8 shadow_vmcs12[KVM_STATE_NESTED_VMX_VMCS_SIZE]; 4375 }; 4376 4377This ioctl copies the vcpu's nested virtualization state from the kernel to 4378userspace. 4379 4380The maximum size of the state can be retrieved by passing KVM_CAP_NESTED_STATE 4381to the KVM_CHECK_EXTENSION ioctl(). 4382 43834.115 KVM_SET_NESTED_STATE 4384-------------------------- 4385 4386:Capability: KVM_CAP_NESTED_STATE 4387:Architectures: x86 4388:Type: vcpu ioctl 4389:Parameters: struct kvm_nested_state (in) 4390:Returns: 0 on success, -1 on error 4391 4392This copies the vcpu's kvm_nested_state struct from userspace to the kernel. 4393For the definition of struct kvm_nested_state, see KVM_GET_NESTED_STATE. 4394 43954.116 KVM_(UN)REGISTER_COALESCED_MMIO 4396------------------------------------- 4397 4398:Capability: KVM_CAP_COALESCED_MMIO (for coalesced mmio) 4399 KVM_CAP_COALESCED_PIO (for coalesced pio) 4400:Architectures: all 4401:Type: vm ioctl 4402:Parameters: struct kvm_coalesced_mmio_zone 4403:Returns: 0 on success, < 0 on error 4404 4405Coalesced I/O is a performance optimization that defers hardware 4406register write emulation so that userspace exits are avoided. It is 4407typically used to reduce the overhead of emulating frequently accessed 4408hardware registers. 4409 4410When a hardware register is configured for coalesced I/O, write accesses 4411do not exit to userspace and their value is recorded in a ring buffer 4412that is shared between kernel and userspace. 4413 4414Coalesced I/O is used if one or more write accesses to a hardware 4415register can be deferred until a read or a write to another hardware 4416register on the same device. This last access will cause a vmexit and 4417userspace will process accesses from the ring buffer before emulating 4418it. That will avoid exiting to userspace on repeated writes. 4419 4420Coalesced pio is based on coalesced mmio. There is little difference 4421between coalesced mmio and pio except that coalesced pio records accesses 4422to I/O ports. 4423 44244.117 KVM_CLEAR_DIRTY_LOG (vm ioctl) 4425------------------------------------ 4426 4427:Capability: KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2 4428:Architectures: x86, arm, arm64, mips 4429:Type: vm ioctl 4430:Parameters: struct kvm_dirty_log (in) 4431:Returns: 0 on success, -1 on error 4432 4433:: 4434 4435 /* for KVM_CLEAR_DIRTY_LOG */ 4436 struct kvm_clear_dirty_log { 4437 __u32 slot; 4438 __u32 num_pages; 4439 __u64 first_page; 4440 union { 4441 void __user *dirty_bitmap; /* one bit per page */ 4442 __u64 padding; 4443 }; 4444 }; 4445 4446The ioctl clears the dirty status of pages in a memory slot, according to 4447the bitmap that is passed in struct kvm_clear_dirty_log's dirty_bitmap 4448field. Bit 0 of the bitmap corresponds to page "first_page" in the 4449memory slot, and num_pages is the size in bits of the input bitmap. 4450first_page must be a multiple of 64; num_pages must also be a multiple of 445164 unless first_page + num_pages is the size of the memory slot. For each 4452bit that is set in the input bitmap, the corresponding page is marked "clean" 4453in KVM's dirty bitmap, and dirty tracking is re-enabled for that page 4454(for example via write-protection, or by clearing the dirty bit in 4455a page table entry). 4456 4457If KVM_CAP_MULTI_ADDRESS_SPACE is available, bits 16-31 specifies 4458the address space for which you want to return the dirty bitmap. 4459They must be less than the value that KVM_CHECK_EXTENSION returns for 4460the KVM_CAP_MULTI_ADDRESS_SPACE capability. 4461 4462This ioctl is mostly useful when KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2 4463is enabled; for more information, see the description of the capability. 4464However, it can always be used as long as KVM_CHECK_EXTENSION confirms 4465that KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2 is present. 4466 44674.118 KVM_GET_SUPPORTED_HV_CPUID 4468-------------------------------- 4469 4470:Capability: KVM_CAP_HYPERV_CPUID (vcpu), KVM_CAP_SYS_HYPERV_CPUID (system) 4471:Architectures: x86 4472:Type: system ioctl, vcpu ioctl 4473:Parameters: struct kvm_cpuid2 (in/out) 4474:Returns: 0 on success, -1 on error 4475 4476:: 4477 4478 struct kvm_cpuid2 { 4479 __u32 nent; 4480 __u32 padding; 4481 struct kvm_cpuid_entry2 entries[0]; 4482 }; 4483 4484 struct kvm_cpuid_entry2 { 4485 __u32 function; 4486 __u32 index; 4487 __u32 flags; 4488 __u32 eax; 4489 __u32 ebx; 4490 __u32 ecx; 4491 __u32 edx; 4492 __u32 padding[3]; 4493 }; 4494 4495This ioctl returns x86 cpuid features leaves related to Hyper-V emulation in 4496KVM. Userspace can use the information returned by this ioctl to construct 4497cpuid information presented to guests consuming Hyper-V enlightenments (e.g. 4498Windows or Hyper-V guests). 4499 4500CPUID feature leaves returned by this ioctl are defined by Hyper-V Top Level 4501Functional Specification (TLFS). These leaves can't be obtained with 4502KVM_GET_SUPPORTED_CPUID ioctl because some of them intersect with KVM feature 4503leaves (0x40000000, 0x40000001). 4504 4505Currently, the following list of CPUID leaves are returned: 4506 - HYPERV_CPUID_VENDOR_AND_MAX_FUNCTIONS 4507 - HYPERV_CPUID_INTERFACE 4508 - HYPERV_CPUID_VERSION 4509 - HYPERV_CPUID_FEATURES 4510 - HYPERV_CPUID_ENLIGHTMENT_INFO 4511 - HYPERV_CPUID_IMPLEMENT_LIMITS 4512 - HYPERV_CPUID_NESTED_FEATURES 4513 - HYPERV_CPUID_SYNDBG_VENDOR_AND_MAX_FUNCTIONS 4514 - HYPERV_CPUID_SYNDBG_INTERFACE 4515 - HYPERV_CPUID_SYNDBG_PLATFORM_CAPABILITIES 4516 4517Userspace invokes KVM_GET_SUPPORTED_HV_CPUID by passing a kvm_cpuid2 structure 4518with the 'nent' field indicating the number of entries in the variable-size 4519array 'entries'. If the number of entries is too low to describe all Hyper-V 4520feature leaves, an error (E2BIG) is returned. If the number is more or equal 4521to the number of Hyper-V feature leaves, the 'nent' field is adjusted to the 4522number of valid entries in the 'entries' array, which is then filled. 4523 4524'index' and 'flags' fields in 'struct kvm_cpuid_entry2' are currently reserved, 4525userspace should not expect to get any particular value there. 4526 4527Note, vcpu version of KVM_GET_SUPPORTED_HV_CPUID is currently deprecated. Unlike 4528system ioctl which exposes all supported feature bits unconditionally, vcpu 4529version has the following quirks: 4530- HYPERV_CPUID_NESTED_FEATURES leaf and HV_X64_ENLIGHTENED_VMCS_RECOMMENDED 4531 feature bit are only exposed when Enlightened VMCS was previously enabled 4532 on the corresponding vCPU (KVM_CAP_HYPERV_ENLIGHTENED_VMCS). 4533- HV_STIMER_DIRECT_MODE_AVAILABLE bit is only exposed with in-kernel LAPIC. 4534 (presumes KVM_CREATE_IRQCHIP has already been called). 4535 45364.119 KVM_ARM_VCPU_FINALIZE 4537--------------------------- 4538 4539:Architectures: arm, arm64 4540:Type: vcpu ioctl 4541:Parameters: int feature (in) 4542:Returns: 0 on success, -1 on error 4543 4544Errors: 4545 4546 ====== ============================================================== 4547 EPERM feature not enabled, needs configuration, or already finalized 4548 EINVAL feature unknown or not present 4549 ====== ============================================================== 4550 4551Recognised values for feature: 4552 4553 ===== =========================================== 4554 arm64 KVM_ARM_VCPU_SVE (requires KVM_CAP_ARM_SVE) 4555 ===== =========================================== 4556 4557Finalizes the configuration of the specified vcpu feature. 4558 4559The vcpu must already have been initialised, enabling the affected feature, by 4560means of a successful KVM_ARM_VCPU_INIT call with the appropriate flag set in 4561features[]. 4562 4563For affected vcpu features, this is a mandatory step that must be performed 4564before the vcpu is fully usable. 4565 4566Between KVM_ARM_VCPU_INIT and KVM_ARM_VCPU_FINALIZE, the feature may be 4567configured by use of ioctls such as KVM_SET_ONE_REG. The exact configuration 4568that should be performaned and how to do it are feature-dependent. 4569 4570Other calls that depend on a particular feature being finalized, such as 4571KVM_RUN, KVM_GET_REG_LIST, KVM_GET_ONE_REG and KVM_SET_ONE_REG, will fail with 4572-EPERM unless the feature has already been finalized by means of a 4573KVM_ARM_VCPU_FINALIZE call. 4574 4575See KVM_ARM_VCPU_INIT for details of vcpu features that require finalization 4576using this ioctl. 4577 45784.120 KVM_SET_PMU_EVENT_FILTER 4579------------------------------ 4580 4581:Capability: KVM_CAP_PMU_EVENT_FILTER 4582:Architectures: x86 4583:Type: vm ioctl 4584:Parameters: struct kvm_pmu_event_filter (in) 4585:Returns: 0 on success, -1 on error 4586 4587:: 4588 4589 struct kvm_pmu_event_filter { 4590 __u32 action; 4591 __u32 nevents; 4592 __u32 fixed_counter_bitmap; 4593 __u32 flags; 4594 __u32 pad[4]; 4595 __u64 events[0]; 4596 }; 4597 4598This ioctl restricts the set of PMU events that the guest can program. 4599The argument holds a list of events which will be allowed or denied. 4600The eventsel+umask of each event the guest attempts to program is compared 4601against the events field to determine whether the guest should have access. 4602The events field only controls general purpose counters; fixed purpose 4603counters are controlled by the fixed_counter_bitmap. 4604 4605No flags are defined yet, the field must be zero. 4606 4607Valid values for 'action':: 4608 4609 #define KVM_PMU_EVENT_ALLOW 0 4610 #define KVM_PMU_EVENT_DENY 1 4611 46124.121 KVM_PPC_SVM_OFF 4613--------------------- 4614 4615:Capability: basic 4616:Architectures: powerpc 4617:Type: vm ioctl 4618:Parameters: none 4619:Returns: 0 on successful completion, 4620 4621Errors: 4622 4623 ====== ================================================================ 4624 EINVAL if ultravisor failed to terminate the secure guest 4625 ENOMEM if hypervisor failed to allocate new radix page tables for guest 4626 ====== ================================================================ 4627 4628This ioctl is used to turn off the secure mode of the guest or transition 4629the guest from secure mode to normal mode. This is invoked when the guest 4630is reset. This has no effect if called for a normal guest. 4631 4632This ioctl issues an ultravisor call to terminate the secure guest, 4633unpins the VPA pages and releases all the device pages that are used to 4634track the secure pages by hypervisor. 4635 46364.122 KVM_S390_NORMAL_RESET 4637--------------------------- 4638 4639:Capability: KVM_CAP_S390_VCPU_RESETS 4640:Architectures: s390 4641:Type: vcpu ioctl 4642:Parameters: none 4643:Returns: 0 4644 4645This ioctl resets VCPU registers and control structures according to 4646the cpu reset definition in the POP (Principles Of Operation). 4647 46484.123 KVM_S390_INITIAL_RESET 4649---------------------------- 4650 4651:Capability: none 4652:Architectures: s390 4653:Type: vcpu ioctl 4654:Parameters: none 4655:Returns: 0 4656 4657This ioctl resets VCPU registers and control structures according to 4658the initial cpu reset definition in the POP. However, the cpu is not 4659put into ESA mode. This reset is a superset of the normal reset. 4660 46614.124 KVM_S390_CLEAR_RESET 4662-------------------------- 4663 4664:Capability: KVM_CAP_S390_VCPU_RESETS 4665:Architectures: s390 4666:Type: vcpu ioctl 4667:Parameters: none 4668:Returns: 0 4669 4670This ioctl resets VCPU registers and control structures according to 4671the clear cpu reset definition in the POP. However, the cpu is not put 4672into ESA mode. This reset is a superset of the initial reset. 4673 4674 46754.125 KVM_S390_PV_COMMAND 4676------------------------- 4677 4678:Capability: KVM_CAP_S390_PROTECTED 4679:Architectures: s390 4680:Type: vm ioctl 4681:Parameters: struct kvm_pv_cmd 4682:Returns: 0 on success, < 0 on error 4683 4684:: 4685 4686 struct kvm_pv_cmd { 4687 __u32 cmd; /* Command to be executed */ 4688 __u16 rc; /* Ultravisor return code */ 4689 __u16 rrc; /* Ultravisor return reason code */ 4690 __u64 data; /* Data or address */ 4691 __u32 flags; /* flags for future extensions. Must be 0 for now */ 4692 __u32 reserved[3]; 4693 }; 4694 4695cmd values: 4696 4697KVM_PV_ENABLE 4698 Allocate memory and register the VM with the Ultravisor, thereby 4699 donating memory to the Ultravisor that will become inaccessible to 4700 KVM. All existing CPUs are converted to protected ones. After this 4701 command has succeeded, any CPU added via hotplug will become 4702 protected during its creation as well. 4703 4704 Errors: 4705 4706 ===== ============================= 4707 EINTR an unmasked signal is pending 4708 ===== ============================= 4709 4710KVM_PV_DISABLE 4711 4712 Deregister the VM from the Ultravisor and reclaim the memory that 4713 had been donated to the Ultravisor, making it usable by the kernel 4714 again. All registered VCPUs are converted back to non-protected 4715 ones. 4716 4717KVM_PV_VM_SET_SEC_PARMS 4718 Pass the image header from VM memory to the Ultravisor in 4719 preparation of image unpacking and verification. 4720 4721KVM_PV_VM_UNPACK 4722 Unpack (protect and decrypt) a page of the encrypted boot image. 4723 4724KVM_PV_VM_VERIFY 4725 Verify the integrity of the unpacked image. Only if this succeeds, 4726 KVM is allowed to start protected VCPUs. 4727 47284.126 KVM_X86_SET_MSR_FILTER 4729---------------------------- 4730 4731:Capability: KVM_X86_SET_MSR_FILTER 4732:Architectures: x86 4733:Type: vm ioctl 4734:Parameters: struct kvm_msr_filter 4735:Returns: 0 on success, < 0 on error 4736 4737:: 4738 4739 struct kvm_msr_filter_range { 4740 #define KVM_MSR_FILTER_READ (1 << 0) 4741 #define KVM_MSR_FILTER_WRITE (1 << 1) 4742 __u32 flags; 4743 __u32 nmsrs; /* number of msrs in bitmap */ 4744 __u32 base; /* MSR index the bitmap starts at */ 4745 __u8 *bitmap; /* a 1 bit allows the operations in flags, 0 denies */ 4746 }; 4747 4748 #define KVM_MSR_FILTER_MAX_RANGES 16 4749 struct kvm_msr_filter { 4750 #define KVM_MSR_FILTER_DEFAULT_ALLOW (0 << 0) 4751 #define KVM_MSR_FILTER_DEFAULT_DENY (1 << 0) 4752 __u32 flags; 4753 struct kvm_msr_filter_range ranges[KVM_MSR_FILTER_MAX_RANGES]; 4754 }; 4755 4756flags values for ``struct kvm_msr_filter_range``: 4757 4758``KVM_MSR_FILTER_READ`` 4759 4760 Filter read accesses to MSRs using the given bitmap. A 0 in the bitmap 4761 indicates that a read should immediately fail, while a 1 indicates that 4762 a read for a particular MSR should be handled regardless of the default 4763 filter action. 4764 4765``KVM_MSR_FILTER_WRITE`` 4766 4767 Filter write accesses to MSRs using the given bitmap. A 0 in the bitmap 4768 indicates that a write should immediately fail, while a 1 indicates that 4769 a write for a particular MSR should be handled regardless of the default 4770 filter action. 4771 4772``KVM_MSR_FILTER_READ | KVM_MSR_FILTER_WRITE`` 4773 4774 Filter both read and write accesses to MSRs using the given bitmap. A 0 4775 in the bitmap indicates that both reads and writes should immediately fail, 4776 while a 1 indicates that reads and writes for a particular MSR are not 4777 filtered by this range. 4778 4779flags values for ``struct kvm_msr_filter``: 4780 4781``KVM_MSR_FILTER_DEFAULT_ALLOW`` 4782 4783 If no filter range matches an MSR index that is getting accessed, KVM will 4784 fall back to allowing access to the MSR. 4785 4786``KVM_MSR_FILTER_DEFAULT_DENY`` 4787 4788 If no filter range matches an MSR index that is getting accessed, KVM will 4789 fall back to rejecting access to the MSR. In this mode, all MSRs that should 4790 be processed by KVM need to explicitly be marked as allowed in the bitmaps. 4791 4792This ioctl allows user space to define up to 16 bitmaps of MSR ranges to 4793specify whether a certain MSR access should be explicitly filtered for or not. 4794 4795If this ioctl has never been invoked, MSR accesses are not guarded and the 4796default KVM in-kernel emulation behavior is fully preserved. 4797 4798Calling this ioctl with an empty set of ranges (all nmsrs == 0) disables MSR 4799filtering. In that mode, ``KVM_MSR_FILTER_DEFAULT_DENY`` is invalid and causes 4800an error. 4801 4802As soon as the filtering is in place, every MSR access is processed through 4803the filtering except for accesses to the x2APIC MSRs (from 0x800 to 0x8ff); 4804x2APIC MSRs are always allowed, independent of the ``default_allow`` setting, 4805and their behavior depends on the ``X2APIC_ENABLE`` bit of the APIC base 4806register. 4807 4808If a bit is within one of the defined ranges, read and write accesses are 4809guarded by the bitmap's value for the MSR index if the kind of access 4810is included in the ``struct kvm_msr_filter_range`` flags. If no range 4811cover this particular access, the behavior is determined by the flags 4812field in the kvm_msr_filter struct: ``KVM_MSR_FILTER_DEFAULT_ALLOW`` 4813and ``KVM_MSR_FILTER_DEFAULT_DENY``. 4814 4815Each bitmap range specifies a range of MSRs to potentially allow access on. 4816The range goes from MSR index [base .. base+nmsrs]. The flags field 4817indicates whether reads, writes or both reads and writes are filtered 4818by setting a 1 bit in the bitmap for the corresponding MSR index. 4819 4820If an MSR access is not permitted through the filtering, it generates a 4821#GP inside the guest. When combined with KVM_CAP_X86_USER_SPACE_MSR, that 4822allows user space to deflect and potentially handle various MSR accesses 4823into user space. 4824 4825If a vCPU is in running state while this ioctl is invoked, the vCPU may 4826experience inconsistent filtering behavior on MSR accesses. 4827 4828 48295. The kvm_run structure 4830======================== 4831 4832Application code obtains a pointer to the kvm_run structure by 4833mmap()ing a vcpu fd. From that point, application code can control 4834execution by changing fields in kvm_run prior to calling the KVM_RUN 4835ioctl, and obtain information about the reason KVM_RUN returned by 4836looking up structure members. 4837 4838:: 4839 4840 struct kvm_run { 4841 /* in */ 4842 __u8 request_interrupt_window; 4843 4844Request that KVM_RUN return when it becomes possible to inject external 4845interrupts into the guest. Useful in conjunction with KVM_INTERRUPT. 4846 4847:: 4848 4849 __u8 immediate_exit; 4850 4851This field is polled once when KVM_RUN starts; if non-zero, KVM_RUN 4852exits immediately, returning -EINTR. In the common scenario where a 4853signal is used to "kick" a VCPU out of KVM_RUN, this field can be used 4854to avoid usage of KVM_SET_SIGNAL_MASK, which has worse scalability. 4855Rather than blocking the signal outside KVM_RUN, userspace can set up 4856a signal handler that sets run->immediate_exit to a non-zero value. 4857 4858This field is ignored if KVM_CAP_IMMEDIATE_EXIT is not available. 4859 4860:: 4861 4862 __u8 padding1[6]; 4863 4864 /* out */ 4865 __u32 exit_reason; 4866 4867When KVM_RUN has returned successfully (return value 0), this informs 4868application code why KVM_RUN has returned. Allowable values for this 4869field are detailed below. 4870 4871:: 4872 4873 __u8 ready_for_interrupt_injection; 4874 4875If request_interrupt_window has been specified, this field indicates 4876an interrupt can be injected now with KVM_INTERRUPT. 4877 4878:: 4879 4880 __u8 if_flag; 4881 4882The value of the current interrupt flag. Only valid if in-kernel 4883local APIC is not used. 4884 4885:: 4886 4887 __u16 flags; 4888 4889More architecture-specific flags detailing state of the VCPU that may 4890affect the device's behavior. The only currently defined flag is 4891KVM_RUN_X86_SMM, which is valid on x86 machines and is set if the 4892VCPU is in system management mode. 4893 4894:: 4895 4896 /* in (pre_kvm_run), out (post_kvm_run) */ 4897 __u64 cr8; 4898 4899The value of the cr8 register. Only valid if in-kernel local APIC is 4900not used. Both input and output. 4901 4902:: 4903 4904 __u64 apic_base; 4905 4906The value of the APIC BASE msr. Only valid if in-kernel local 4907APIC is not used. Both input and output. 4908 4909:: 4910 4911 union { 4912 /* KVM_EXIT_UNKNOWN */ 4913 struct { 4914 __u64 hardware_exit_reason; 4915 } hw; 4916 4917If exit_reason is KVM_EXIT_UNKNOWN, the vcpu has exited due to unknown 4918reasons. Further architecture-specific information is available in 4919hardware_exit_reason. 4920 4921:: 4922 4923 /* KVM_EXIT_FAIL_ENTRY */ 4924 struct { 4925 __u64 hardware_entry_failure_reason; 4926 __u32 cpu; /* if KVM_LAST_CPU */ 4927 } fail_entry; 4928 4929If exit_reason is KVM_EXIT_FAIL_ENTRY, the vcpu could not be run due 4930to unknown reasons. Further architecture-specific information is 4931available in hardware_entry_failure_reason. 4932 4933:: 4934 4935 /* KVM_EXIT_EXCEPTION */ 4936 struct { 4937 __u32 exception; 4938 __u32 error_code; 4939 } ex; 4940 4941Unused. 4942 4943:: 4944 4945 /* KVM_EXIT_IO */ 4946 struct { 4947 #define KVM_EXIT_IO_IN 0 4948 #define KVM_EXIT_IO_OUT 1 4949 __u8 direction; 4950 __u8 size; /* bytes */ 4951 __u16 port; 4952 __u32 count; 4953 __u64 data_offset; /* relative to kvm_run start */ 4954 } io; 4955 4956If exit_reason is KVM_EXIT_IO, then the vcpu has 4957executed a port I/O instruction which could not be satisfied by kvm. 4958data_offset describes where the data is located (KVM_EXIT_IO_OUT) or 4959where kvm expects application code to place the data for the next 4960KVM_RUN invocation (KVM_EXIT_IO_IN). Data format is a packed array. 4961 4962:: 4963 4964 /* KVM_EXIT_DEBUG */ 4965 struct { 4966 struct kvm_debug_exit_arch arch; 4967 } debug; 4968 4969If the exit_reason is KVM_EXIT_DEBUG, then a vcpu is processing a debug event 4970for which architecture specific information is returned. 4971 4972:: 4973 4974 /* KVM_EXIT_MMIO */ 4975 struct { 4976 __u64 phys_addr; 4977 __u8 data[8]; 4978 __u32 len; 4979 __u8 is_write; 4980 } mmio; 4981 4982If exit_reason is KVM_EXIT_MMIO, then the vcpu has 4983executed a memory-mapped I/O instruction which could not be satisfied 4984by kvm. The 'data' member contains the written data if 'is_write' is 4985true, and should be filled by application code otherwise. 4986 4987The 'data' member contains, in its first 'len' bytes, the value as it would 4988appear if the VCPU performed a load or store of the appropriate width directly 4989to the byte array. 4990 4991.. note:: 4992 4993 For KVM_EXIT_IO, KVM_EXIT_MMIO, KVM_EXIT_OSI, KVM_EXIT_PAPR, 4994 KVM_EXIT_EPR, KVM_EXIT_X86_RDMSR and KVM_EXIT_X86_WRMSR the corresponding 4995 operations are complete (and guest state is consistent) only after userspace 4996 has re-entered the kernel with KVM_RUN. The kernel side will first finish 4997 incomplete operations and then check for pending signals. Userspace 4998 can re-enter the guest with an unmasked signal pending to complete 4999 pending operations. 5000 5001:: 5002 5003 /* KVM_EXIT_HYPERCALL */ 5004 struct { 5005 __u64 nr; 5006 __u64 args[6]; 5007 __u64 ret; 5008 __u32 longmode; 5009 __u32 pad; 5010 } hypercall; 5011 5012Unused. This was once used for 'hypercall to userspace'. To implement 5013such functionality, use KVM_EXIT_IO (x86) or KVM_EXIT_MMIO (all except s390). 5014 5015.. note:: KVM_EXIT_IO is significantly faster than KVM_EXIT_MMIO. 5016 5017:: 5018 5019 /* KVM_EXIT_TPR_ACCESS */ 5020 struct { 5021 __u64 rip; 5022 __u32 is_write; 5023 __u32 pad; 5024 } tpr_access; 5025 5026To be documented (KVM_TPR_ACCESS_REPORTING). 5027 5028:: 5029 5030 /* KVM_EXIT_S390_SIEIC */ 5031 struct { 5032 __u8 icptcode; 5033 __u64 mask; /* psw upper half */ 5034 __u64 addr; /* psw lower half */ 5035 __u16 ipa; 5036 __u32 ipb; 5037 } s390_sieic; 5038 5039s390 specific. 5040 5041:: 5042 5043 /* KVM_EXIT_S390_RESET */ 5044 #define KVM_S390_RESET_POR 1 5045 #define KVM_S390_RESET_CLEAR 2 5046 #define KVM_S390_RESET_SUBSYSTEM 4 5047 #define KVM_S390_RESET_CPU_INIT 8 5048 #define KVM_S390_RESET_IPL 16 5049 __u64 s390_reset_flags; 5050 5051s390 specific. 5052 5053:: 5054 5055 /* KVM_EXIT_S390_UCONTROL */ 5056 struct { 5057 __u64 trans_exc_code; 5058 __u32 pgm_code; 5059 } s390_ucontrol; 5060 5061s390 specific. A page fault has occurred for a user controlled virtual 5062machine (KVM_VM_S390_UNCONTROL) on it's host page table that cannot be 5063resolved by the kernel. 5064The program code and the translation exception code that were placed 5065in the cpu's lowcore are presented here as defined by the z Architecture 5066Principles of Operation Book in the Chapter for Dynamic Address Translation 5067(DAT) 5068 5069:: 5070 5071 /* KVM_EXIT_DCR */ 5072 struct { 5073 __u32 dcrn; 5074 __u32 data; 5075 __u8 is_write; 5076 } dcr; 5077 5078Deprecated - was used for 440 KVM. 5079 5080:: 5081 5082 /* KVM_EXIT_OSI */ 5083 struct { 5084 __u64 gprs[32]; 5085 } osi; 5086 5087MOL uses a special hypercall interface it calls 'OSI'. To enable it, we catch 5088hypercalls and exit with this exit struct that contains all the guest gprs. 5089 5090If exit_reason is KVM_EXIT_OSI, then the vcpu has triggered such a hypercall. 5091Userspace can now handle the hypercall and when it's done modify the gprs as 5092necessary. Upon guest entry all guest GPRs will then be replaced by the values 5093in this struct. 5094 5095:: 5096 5097 /* KVM_EXIT_PAPR_HCALL */ 5098 struct { 5099 __u64 nr; 5100 __u64 ret; 5101 __u64 args[9]; 5102 } papr_hcall; 5103 5104This is used on 64-bit PowerPC when emulating a pSeries partition, 5105e.g. with the 'pseries' machine type in qemu. It occurs when the 5106guest does a hypercall using the 'sc 1' instruction. The 'nr' field 5107contains the hypercall number (from the guest R3), and 'args' contains 5108the arguments (from the guest R4 - R12). Userspace should put the 5109return code in 'ret' and any extra returned values in args[]. 5110The possible hypercalls are defined in the Power Architecture Platform 5111Requirements (PAPR) document available from www.power.org (free 5112developer registration required to access it). 5113 5114:: 5115 5116 /* KVM_EXIT_S390_TSCH */ 5117 struct { 5118 __u16 subchannel_id; 5119 __u16 subchannel_nr; 5120 __u32 io_int_parm; 5121 __u32 io_int_word; 5122 __u32 ipb; 5123 __u8 dequeued; 5124 } s390_tsch; 5125 5126s390 specific. This exit occurs when KVM_CAP_S390_CSS_SUPPORT has been enabled 5127and TEST SUBCHANNEL was intercepted. If dequeued is set, a pending I/O 5128interrupt for the target subchannel has been dequeued and subchannel_id, 5129subchannel_nr, io_int_parm and io_int_word contain the parameters for that 5130interrupt. ipb is needed for instruction parameter decoding. 5131 5132:: 5133 5134 /* KVM_EXIT_EPR */ 5135 struct { 5136 __u32 epr; 5137 } epr; 5138 5139On FSL BookE PowerPC chips, the interrupt controller has a fast patch 5140interrupt acknowledge path to the core. When the core successfully 5141delivers an interrupt, it automatically populates the EPR register with 5142the interrupt vector number and acknowledges the interrupt inside 5143the interrupt controller. 5144 5145In case the interrupt controller lives in user space, we need to do 5146the interrupt acknowledge cycle through it to fetch the next to be 5147delivered interrupt vector using this exit. 5148 5149It gets triggered whenever both KVM_CAP_PPC_EPR are enabled and an 5150external interrupt has just been delivered into the guest. User space 5151should put the acknowledged interrupt vector into the 'epr' field. 5152 5153:: 5154 5155 /* KVM_EXIT_SYSTEM_EVENT */ 5156 struct { 5157 #define KVM_SYSTEM_EVENT_SHUTDOWN 1 5158 #define KVM_SYSTEM_EVENT_RESET 2 5159 #define KVM_SYSTEM_EVENT_CRASH 3 5160 __u32 type; 5161 __u64 flags; 5162 } system_event; 5163 5164If exit_reason is KVM_EXIT_SYSTEM_EVENT then the vcpu has triggered 5165a system-level event using some architecture specific mechanism (hypercall 5166or some special instruction). In case of ARM/ARM64, this is triggered using 5167HVC instruction based PSCI call from the vcpu. The 'type' field describes 5168the system-level event type. The 'flags' field describes architecture 5169specific flags for the system-level event. 5170 5171Valid values for 'type' are: 5172 5173 - KVM_SYSTEM_EVENT_SHUTDOWN -- the guest has requested a shutdown of the 5174 VM. Userspace is not obliged to honour this, and if it does honour 5175 this does not need to destroy the VM synchronously (ie it may call 5176 KVM_RUN again before shutdown finally occurs). 5177 - KVM_SYSTEM_EVENT_RESET -- the guest has requested a reset of the VM. 5178 As with SHUTDOWN, userspace can choose to ignore the request, or 5179 to schedule the reset to occur in the future and may call KVM_RUN again. 5180 - KVM_SYSTEM_EVENT_CRASH -- the guest crash occurred and the guest 5181 has requested a crash condition maintenance. Userspace can choose 5182 to ignore the request, or to gather VM memory core dump and/or 5183 reset/shutdown of the VM. 5184 5185:: 5186 5187 /* KVM_EXIT_IOAPIC_EOI */ 5188 struct { 5189 __u8 vector; 5190 } eoi; 5191 5192Indicates that the VCPU's in-kernel local APIC received an EOI for a 5193level-triggered IOAPIC interrupt. This exit only triggers when the 5194IOAPIC is implemented in userspace (i.e. KVM_CAP_SPLIT_IRQCHIP is enabled); 5195the userspace IOAPIC should process the EOI and retrigger the interrupt if 5196it is still asserted. Vector is the LAPIC interrupt vector for which the 5197EOI was received. 5198 5199:: 5200 5201 struct kvm_hyperv_exit { 5202 #define KVM_EXIT_HYPERV_SYNIC 1 5203 #define KVM_EXIT_HYPERV_HCALL 2 5204 #define KVM_EXIT_HYPERV_SYNDBG 3 5205 __u32 type; 5206 __u32 pad1; 5207 union { 5208 struct { 5209 __u32 msr; 5210 __u32 pad2; 5211 __u64 control; 5212 __u64 evt_page; 5213 __u64 msg_page; 5214 } synic; 5215 struct { 5216 __u64 input; 5217 __u64 result; 5218 __u64 params[2]; 5219 } hcall; 5220 struct { 5221 __u32 msr; 5222 __u32 pad2; 5223 __u64 control; 5224 __u64 status; 5225 __u64 send_page; 5226 __u64 recv_page; 5227 __u64 pending_page; 5228 } syndbg; 5229 } u; 5230 }; 5231 /* KVM_EXIT_HYPERV */ 5232 struct kvm_hyperv_exit hyperv; 5233 5234Indicates that the VCPU exits into userspace to process some tasks 5235related to Hyper-V emulation. 5236 5237Valid values for 'type' are: 5238 5239 - KVM_EXIT_HYPERV_SYNIC -- synchronously notify user-space about 5240 5241Hyper-V SynIC state change. Notification is used to remap SynIC 5242event/message pages and to enable/disable SynIC messages/events processing 5243in userspace. 5244 5245 - KVM_EXIT_HYPERV_SYNDBG -- synchronously notify user-space about 5246 5247Hyper-V Synthetic debugger state change. Notification is used to either update 5248the pending_page location or to send a control command (send the buffer located 5249in send_page or recv a buffer to recv_page). 5250 5251:: 5252 5253 /* KVM_EXIT_ARM_NISV */ 5254 struct { 5255 __u64 esr_iss; 5256 __u64 fault_ipa; 5257 } arm_nisv; 5258 5259Used on arm and arm64 systems. If a guest accesses memory not in a memslot, 5260KVM will typically return to userspace and ask it to do MMIO emulation on its 5261behalf. However, for certain classes of instructions, no instruction decode 5262(direction, length of memory access) is provided, and fetching and decoding 5263the instruction from the VM is overly complicated to live in the kernel. 5264 5265Historically, when this situation occurred, KVM would print a warning and kill 5266the VM. KVM assumed that if the guest accessed non-memslot memory, it was 5267trying to do I/O, which just couldn't be emulated, and the warning message was 5268phrased accordingly. However, what happened more often was that a guest bug 5269caused access outside the guest memory areas which should lead to a more 5270meaningful warning message and an external abort in the guest, if the access 5271did not fall within an I/O window. 5272 5273Userspace implementations can query for KVM_CAP_ARM_NISV_TO_USER, and enable 5274this capability at VM creation. Once this is done, these types of errors will 5275instead return to userspace with KVM_EXIT_ARM_NISV, with the valid bits from 5276the HSR (arm) and ESR_EL2 (arm64) in the esr_iss field, and the faulting IPA 5277in the fault_ipa field. Userspace can either fix up the access if it's 5278actually an I/O access by decoding the instruction from guest memory (if it's 5279very brave) and continue executing the guest, or it can decide to suspend, 5280dump, or restart the guest. 5281 5282Note that KVM does not skip the faulting instruction as it does for 5283KVM_EXIT_MMIO, but userspace has to emulate any change to the processing state 5284if it decides to decode and emulate the instruction. 5285 5286:: 5287 5288 /* KVM_EXIT_X86_RDMSR / KVM_EXIT_X86_WRMSR */ 5289 struct { 5290 __u8 error; /* user -> kernel */ 5291 __u8 pad[7]; 5292 __u32 reason; /* kernel -> user */ 5293 __u32 index; /* kernel -> user */ 5294 __u64 data; /* kernel <-> user */ 5295 } msr; 5296 5297Used on x86 systems. When the VM capability KVM_CAP_X86_USER_SPACE_MSR is 5298enabled, MSR accesses to registers that would invoke a #GP by KVM kernel code 5299will instead trigger a KVM_EXIT_X86_RDMSR exit for reads and KVM_EXIT_X86_WRMSR 5300exit for writes. 5301 5302The "reason" field specifies why the MSR trap occurred. User space will only 5303receive MSR exit traps when a particular reason was requested during through 5304ENABLE_CAP. Currently valid exit reasons are: 5305 5306 KVM_MSR_EXIT_REASON_UNKNOWN - access to MSR that is unknown to KVM 5307 KVM_MSR_EXIT_REASON_INVAL - access to invalid MSRs or reserved bits 5308 KVM_MSR_EXIT_REASON_FILTER - access blocked by KVM_X86_SET_MSR_FILTER 5309 5310For KVM_EXIT_X86_RDMSR, the "index" field tells user space which MSR the guest 5311wants to read. To respond to this request with a successful read, user space 5312writes the respective data into the "data" field and must continue guest 5313execution to ensure the read data is transferred into guest register state. 5314 5315If the RDMSR request was unsuccessful, user space indicates that with a "1" in 5316the "error" field. This will inject a #GP into the guest when the VCPU is 5317executed again. 5318 5319For KVM_EXIT_X86_WRMSR, the "index" field tells user space which MSR the guest 5320wants to write. Once finished processing the event, user space must continue 5321vCPU execution. If the MSR write was unsuccessful, user space also sets the 5322"error" field to "1". 5323 5324:: 5325 5326 /* Fix the size of the union. */ 5327 char padding[256]; 5328 }; 5329 5330 /* 5331 * shared registers between kvm and userspace. 5332 * kvm_valid_regs specifies the register classes set by the host 5333 * kvm_dirty_regs specified the register classes dirtied by userspace 5334 * struct kvm_sync_regs is architecture specific, as well as the 5335 * bits for kvm_valid_regs and kvm_dirty_regs 5336 */ 5337 __u64 kvm_valid_regs; 5338 __u64 kvm_dirty_regs; 5339 union { 5340 struct kvm_sync_regs regs; 5341 char padding[SYNC_REGS_SIZE_BYTES]; 5342 } s; 5343 5344If KVM_CAP_SYNC_REGS is defined, these fields allow userspace to access 5345certain guest registers without having to call SET/GET_*REGS. Thus we can 5346avoid some system call overhead if userspace has to handle the exit. 5347Userspace can query the validity of the structure by checking 5348kvm_valid_regs for specific bits. These bits are architecture specific 5349and usually define the validity of a groups of registers. (e.g. one bit 5350for general purpose registers) 5351 5352Please note that the kernel is allowed to use the kvm_run structure as the 5353primary storage for certain register types. Therefore, the kernel may use the 5354values in kvm_run even if the corresponding bit in kvm_dirty_regs is not set. 5355 5356:: 5357 5358 }; 5359 5360 5361 53626. Capabilities that can be enabled on vCPUs 5363============================================ 5364 5365There are certain capabilities that change the behavior of the virtual CPU or 5366the virtual machine when enabled. To enable them, please see section 4.37. 5367Below you can find a list of capabilities and what their effect on the vCPU or 5368the virtual machine is when enabling them. 5369 5370The following information is provided along with the description: 5371 5372 Architectures: 5373 which instruction set architectures provide this ioctl. 5374 x86 includes both i386 and x86_64. 5375 5376 Target: 5377 whether this is a per-vcpu or per-vm capability. 5378 5379 Parameters: 5380 what parameters are accepted by the capability. 5381 5382 Returns: 5383 the return value. General error numbers (EBADF, ENOMEM, EINVAL) 5384 are not detailed, but errors with specific meanings are. 5385 5386 53876.1 KVM_CAP_PPC_OSI 5388------------------- 5389 5390:Architectures: ppc 5391:Target: vcpu 5392:Parameters: none 5393:Returns: 0 on success; -1 on error 5394 5395This capability enables interception of OSI hypercalls that otherwise would 5396be treated as normal system calls to be injected into the guest. OSI hypercalls 5397were invented by Mac-on-Linux to have a standardized communication mechanism 5398between the guest and the host. 5399 5400When this capability is enabled, KVM_EXIT_OSI can occur. 5401 5402 54036.2 KVM_CAP_PPC_PAPR 5404-------------------- 5405 5406:Architectures: ppc 5407:Target: vcpu 5408:Parameters: none 5409:Returns: 0 on success; -1 on error 5410 5411This capability enables interception of PAPR hypercalls. PAPR hypercalls are 5412done using the hypercall instruction "sc 1". 5413 5414It also sets the guest privilege level to "supervisor" mode. Usually the guest 5415runs in "hypervisor" privilege mode with a few missing features. 5416 5417In addition to the above, it changes the semantics of SDR1. In this mode, the 5418HTAB address part of SDR1 contains an HVA instead of a GPA, as PAPR keeps the 5419HTAB invisible to the guest. 5420 5421When this capability is enabled, KVM_EXIT_PAPR_HCALL can occur. 5422 5423 54246.3 KVM_CAP_SW_TLB 5425------------------ 5426 5427:Architectures: ppc 5428:Target: vcpu 5429:Parameters: args[0] is the address of a struct kvm_config_tlb 5430:Returns: 0 on success; -1 on error 5431 5432:: 5433 5434 struct kvm_config_tlb { 5435 __u64 params; 5436 __u64 array; 5437 __u32 mmu_type; 5438 __u32 array_len; 5439 }; 5440 5441Configures the virtual CPU's TLB array, establishing a shared memory area 5442between userspace and KVM. The "params" and "array" fields are userspace 5443addresses of mmu-type-specific data structures. The "array_len" field is an 5444safety mechanism, and should be set to the size in bytes of the memory that 5445userspace has reserved for the array. It must be at least the size dictated 5446by "mmu_type" and "params". 5447 5448While KVM_RUN is active, the shared region is under control of KVM. Its 5449contents are undefined, and any modification by userspace results in 5450boundedly undefined behavior. 5451 5452On return from KVM_RUN, the shared region will reflect the current state of 5453the guest's TLB. If userspace makes any changes, it must call KVM_DIRTY_TLB 5454to tell KVM which entries have been changed, prior to calling KVM_RUN again 5455on this vcpu. 5456 5457For mmu types KVM_MMU_FSL_BOOKE_NOHV and KVM_MMU_FSL_BOOKE_HV: 5458 5459 - The "params" field is of type "struct kvm_book3e_206_tlb_params". 5460 - The "array" field points to an array of type "struct 5461 kvm_book3e_206_tlb_entry". 5462 - The array consists of all entries in the first TLB, followed by all 5463 entries in the second TLB. 5464 - Within a TLB, entries are ordered first by increasing set number. Within a 5465 set, entries are ordered by way (increasing ESEL). 5466 - The hash for determining set number in TLB0 is: (MAS2 >> 12) & (num_sets - 1) 5467 where "num_sets" is the tlb_sizes[] value divided by the tlb_ways[] value. 5468 - The tsize field of mas1 shall be set to 4K on TLB0, even though the 5469 hardware ignores this value for TLB0. 5470 54716.4 KVM_CAP_S390_CSS_SUPPORT 5472---------------------------- 5473 5474:Architectures: s390 5475:Target: vcpu 5476:Parameters: none 5477:Returns: 0 on success; -1 on error 5478 5479This capability enables support for handling of channel I/O instructions. 5480 5481TEST PENDING INTERRUPTION and the interrupt portion of TEST SUBCHANNEL are 5482handled in-kernel, while the other I/O instructions are passed to userspace. 5483 5484When this capability is enabled, KVM_EXIT_S390_TSCH will occur on TEST 5485SUBCHANNEL intercepts. 5486 5487Note that even though this capability is enabled per-vcpu, the complete 5488virtual machine is affected. 5489 54906.5 KVM_CAP_PPC_EPR 5491------------------- 5492 5493:Architectures: ppc 5494:Target: vcpu 5495:Parameters: args[0] defines whether the proxy facility is active 5496:Returns: 0 on success; -1 on error 5497 5498This capability enables or disables the delivery of interrupts through the 5499external proxy facility. 5500 5501When enabled (args[0] != 0), every time the guest gets an external interrupt 5502delivered, it automatically exits into user space with a KVM_EXIT_EPR exit 5503to receive the topmost interrupt vector. 5504 5505When disabled (args[0] == 0), behavior is as if this facility is unsupported. 5506 5507When this capability is enabled, KVM_EXIT_EPR can occur. 5508 55096.6 KVM_CAP_IRQ_MPIC 5510-------------------- 5511 5512:Architectures: ppc 5513:Parameters: args[0] is the MPIC device fd; 5514 args[1] is the MPIC CPU number for this vcpu 5515 5516This capability connects the vcpu to an in-kernel MPIC device. 5517 55186.7 KVM_CAP_IRQ_XICS 5519-------------------- 5520 5521:Architectures: ppc 5522:Target: vcpu 5523:Parameters: args[0] is the XICS device fd; 5524 args[1] is the XICS CPU number (server ID) for this vcpu 5525 5526This capability connects the vcpu to an in-kernel XICS device. 5527 55286.8 KVM_CAP_S390_IRQCHIP 5529------------------------ 5530 5531:Architectures: s390 5532:Target: vm 5533:Parameters: none 5534 5535This capability enables the in-kernel irqchip for s390. Please refer to 5536"4.24 KVM_CREATE_IRQCHIP" for details. 5537 55386.9 KVM_CAP_MIPS_FPU 5539-------------------- 5540 5541:Architectures: mips 5542:Target: vcpu 5543:Parameters: args[0] is reserved for future use (should be 0). 5544 5545This capability allows the use of the host Floating Point Unit by the guest. It 5546allows the Config1.FP bit to be set to enable the FPU in the guest. Once this is 5547done the ``KVM_REG_MIPS_FPR_*`` and ``KVM_REG_MIPS_FCR_*`` registers can be 5548accessed (depending on the current guest FPU register mode), and the Status.FR, 5549Config5.FRE bits are accessible via the KVM API and also from the guest, 5550depending on them being supported by the FPU. 5551 55526.10 KVM_CAP_MIPS_MSA 5553--------------------- 5554 5555:Architectures: mips 5556:Target: vcpu 5557:Parameters: args[0] is reserved for future use (should be 0). 5558 5559This capability allows the use of the MIPS SIMD Architecture (MSA) by the guest. 5560It allows the Config3.MSAP bit to be set to enable the use of MSA by the guest. 5561Once this is done the ``KVM_REG_MIPS_VEC_*`` and ``KVM_REG_MIPS_MSA_*`` 5562registers can be accessed, and the Config5.MSAEn bit is accessible via the 5563KVM API and also from the guest. 5564 55656.74 KVM_CAP_SYNC_REGS 5566---------------------- 5567 5568:Architectures: s390, x86 5569:Target: s390: always enabled, x86: vcpu 5570:Parameters: none 5571:Returns: x86: KVM_CHECK_EXTENSION returns a bit-array indicating which register 5572 sets are supported 5573 (bitfields defined in arch/x86/include/uapi/asm/kvm.h). 5574 5575As described above in the kvm_sync_regs struct info in section 5 (kvm_run): 5576KVM_CAP_SYNC_REGS "allow[s] userspace to access certain guest registers 5577without having to call SET/GET_*REGS". This reduces overhead by eliminating 5578repeated ioctl calls for setting and/or getting register values. This is 5579particularly important when userspace is making synchronous guest state 5580modifications, e.g. when emulating and/or intercepting instructions in 5581userspace. 5582 5583For s390 specifics, please refer to the source code. 5584 5585For x86: 5586 5587- the register sets to be copied out to kvm_run are selectable 5588 by userspace (rather that all sets being copied out for every exit). 5589- vcpu_events are available in addition to regs and sregs. 5590 5591For x86, the 'kvm_valid_regs' field of struct kvm_run is overloaded to 5592function as an input bit-array field set by userspace to indicate the 5593specific register sets to be copied out on the next exit. 5594 5595To indicate when userspace has modified values that should be copied into 5596the vCPU, the all architecture bitarray field, 'kvm_dirty_regs' must be set. 5597This is done using the same bitflags as for the 'kvm_valid_regs' field. 5598If the dirty bit is not set, then the register set values will not be copied 5599into the vCPU even if they've been modified. 5600 5601Unused bitfields in the bitarrays must be set to zero. 5602 5603:: 5604 5605 struct kvm_sync_regs { 5606 struct kvm_regs regs; 5607 struct kvm_sregs sregs; 5608 struct kvm_vcpu_events events; 5609 }; 5610 56116.75 KVM_CAP_PPC_IRQ_XIVE 5612------------------------- 5613 5614:Architectures: ppc 5615:Target: vcpu 5616:Parameters: args[0] is the XIVE device fd; 5617 args[1] is the XIVE CPU number (server ID) for this vcpu 5618 5619This capability connects the vcpu to an in-kernel XIVE device. 5620 56217. Capabilities that can be enabled on VMs 5622========================================== 5623 5624There are certain capabilities that change the behavior of the virtual 5625machine when enabled. To enable them, please see section 4.37. Below 5626you can find a list of capabilities and what their effect on the VM 5627is when enabling them. 5628 5629The following information is provided along with the description: 5630 5631 Architectures: 5632 which instruction set architectures provide this ioctl. 5633 x86 includes both i386 and x86_64. 5634 5635 Parameters: 5636 what parameters are accepted by the capability. 5637 5638 Returns: 5639 the return value. General error numbers (EBADF, ENOMEM, EINVAL) 5640 are not detailed, but errors with specific meanings are. 5641 5642 56437.1 KVM_CAP_PPC_ENABLE_HCALL 5644---------------------------- 5645 5646:Architectures: ppc 5647:Parameters: args[0] is the sPAPR hcall number; 5648 args[1] is 0 to disable, 1 to enable in-kernel handling 5649 5650This capability controls whether individual sPAPR hypercalls (hcalls) 5651get handled by the kernel or not. Enabling or disabling in-kernel 5652handling of an hcall is effective across the VM. On creation, an 5653initial set of hcalls are enabled for in-kernel handling, which 5654consists of those hcalls for which in-kernel handlers were implemented 5655before this capability was implemented. If disabled, the kernel will 5656not to attempt to handle the hcall, but will always exit to userspace 5657to handle it. Note that it may not make sense to enable some and 5658disable others of a group of related hcalls, but KVM does not prevent 5659userspace from doing that. 5660 5661If the hcall number specified is not one that has an in-kernel 5662implementation, the KVM_ENABLE_CAP ioctl will fail with an EINVAL 5663error. 5664 56657.2 KVM_CAP_S390_USER_SIGP 5666-------------------------- 5667 5668:Architectures: s390 5669:Parameters: none 5670 5671This capability controls which SIGP orders will be handled completely in user 5672space. With this capability enabled, all fast orders will be handled completely 5673in the kernel: 5674 5675- SENSE 5676- SENSE RUNNING 5677- EXTERNAL CALL 5678- EMERGENCY SIGNAL 5679- CONDITIONAL EMERGENCY SIGNAL 5680 5681All other orders will be handled completely in user space. 5682 5683Only privileged operation exceptions will be checked for in the kernel (or even 5684in the hardware prior to interception). If this capability is not enabled, the 5685old way of handling SIGP orders is used (partially in kernel and user space). 5686 56877.3 KVM_CAP_S390_VECTOR_REGISTERS 5688--------------------------------- 5689 5690:Architectures: s390 5691:Parameters: none 5692:Returns: 0 on success, negative value on error 5693 5694Allows use of the vector registers introduced with z13 processor, and 5695provides for the synchronization between host and user space. Will 5696return -EINVAL if the machine does not support vectors. 5697 56987.4 KVM_CAP_S390_USER_STSI 5699-------------------------- 5700 5701:Architectures: s390 5702:Parameters: none 5703 5704This capability allows post-handlers for the STSI instruction. After 5705initial handling in the kernel, KVM exits to user space with 5706KVM_EXIT_S390_STSI to allow user space to insert further data. 5707 5708Before exiting to userspace, kvm handlers should fill in s390_stsi field of 5709vcpu->run:: 5710 5711 struct { 5712 __u64 addr; 5713 __u8 ar; 5714 __u8 reserved; 5715 __u8 fc; 5716 __u8 sel1; 5717 __u16 sel2; 5718 } s390_stsi; 5719 5720 @addr - guest address of STSI SYSIB 5721 @fc - function code 5722 @sel1 - selector 1 5723 @sel2 - selector 2 5724 @ar - access register number 5725 5726KVM handlers should exit to userspace with rc = -EREMOTE. 5727 57287.5 KVM_CAP_SPLIT_IRQCHIP 5729------------------------- 5730 5731:Architectures: x86 5732:Parameters: args[0] - number of routes reserved for userspace IOAPICs 5733:Returns: 0 on success, -1 on error 5734 5735Create a local apic for each processor in the kernel. This can be used 5736instead of KVM_CREATE_IRQCHIP if the userspace VMM wishes to emulate the 5737IOAPIC and PIC (and also the PIT, even though this has to be enabled 5738separately). 5739 5740This capability also enables in kernel routing of interrupt requests; 5741when KVM_CAP_SPLIT_IRQCHIP only routes of KVM_IRQ_ROUTING_MSI type are 5742used in the IRQ routing table. The first args[0] MSI routes are reserved 5743for the IOAPIC pins. Whenever the LAPIC receives an EOI for these routes, 5744a KVM_EXIT_IOAPIC_EOI vmexit will be reported to userspace. 5745 5746Fails if VCPU has already been created, or if the irqchip is already in the 5747kernel (i.e. KVM_CREATE_IRQCHIP has already been called). 5748 57497.6 KVM_CAP_S390_RI 5750------------------- 5751 5752:Architectures: s390 5753:Parameters: none 5754 5755Allows use of runtime-instrumentation introduced with zEC12 processor. 5756Will return -EINVAL if the machine does not support runtime-instrumentation. 5757Will return -EBUSY if a VCPU has already been created. 5758 57597.7 KVM_CAP_X2APIC_API 5760---------------------- 5761 5762:Architectures: x86 5763:Parameters: args[0] - features that should be enabled 5764:Returns: 0 on success, -EINVAL when args[0] contains invalid features 5765 5766Valid feature flags in args[0] are:: 5767 5768 #define KVM_X2APIC_API_USE_32BIT_IDS (1ULL << 0) 5769 #define KVM_X2APIC_API_DISABLE_BROADCAST_QUIRK (1ULL << 1) 5770 5771Enabling KVM_X2APIC_API_USE_32BIT_IDS changes the behavior of 5772KVM_SET_GSI_ROUTING, KVM_SIGNAL_MSI, KVM_SET_LAPIC, and KVM_GET_LAPIC, 5773allowing the use of 32-bit APIC IDs. See KVM_CAP_X2APIC_API in their 5774respective sections. 5775 5776KVM_X2APIC_API_DISABLE_BROADCAST_QUIRK must be enabled for x2APIC to work 5777in logical mode or with more than 255 VCPUs. Otherwise, KVM treats 0xff 5778as a broadcast even in x2APIC mode in order to support physical x2APIC 5779without interrupt remapping. This is undesirable in logical mode, 5780where 0xff represents CPUs 0-7 in cluster 0. 5781 57827.8 KVM_CAP_S390_USER_INSTR0 5783---------------------------- 5784 5785:Architectures: s390 5786:Parameters: none 5787 5788With this capability enabled, all illegal instructions 0x0000 (2 bytes) will 5789be intercepted and forwarded to user space. User space can use this 5790mechanism e.g. to realize 2-byte software breakpoints. The kernel will 5791not inject an operating exception for these instructions, user space has 5792to take care of that. 5793 5794This capability can be enabled dynamically even if VCPUs were already 5795created and are running. 5796 57977.9 KVM_CAP_S390_GS 5798------------------- 5799 5800:Architectures: s390 5801:Parameters: none 5802:Returns: 0 on success; -EINVAL if the machine does not support 5803 guarded storage; -EBUSY if a VCPU has already been created. 5804 5805Allows use of guarded storage for the KVM guest. 5806 58077.10 KVM_CAP_S390_AIS 5808--------------------- 5809 5810:Architectures: s390 5811:Parameters: none 5812 5813Allow use of adapter-interruption suppression. 5814:Returns: 0 on success; -EBUSY if a VCPU has already been created. 5815 58167.11 KVM_CAP_PPC_SMT 5817-------------------- 5818 5819:Architectures: ppc 5820:Parameters: vsmt_mode, flags 5821 5822Enabling this capability on a VM provides userspace with a way to set 5823the desired virtual SMT mode (i.e. the number of virtual CPUs per 5824virtual core). The virtual SMT mode, vsmt_mode, must be a power of 2 5825between 1 and 8. On POWER8, vsmt_mode must also be no greater than 5826the number of threads per subcore for the host. Currently flags must 5827be 0. A successful call to enable this capability will result in 5828vsmt_mode being returned when the KVM_CAP_PPC_SMT capability is 5829subsequently queried for the VM. This capability is only supported by 5830HV KVM, and can only be set before any VCPUs have been created. 5831The KVM_CAP_PPC_SMT_POSSIBLE capability indicates which virtual SMT 5832modes are available. 5833 58347.12 KVM_CAP_PPC_FWNMI 5835---------------------- 5836 5837:Architectures: ppc 5838:Parameters: none 5839 5840With this capability a machine check exception in the guest address 5841space will cause KVM to exit the guest with NMI exit reason. This 5842enables QEMU to build error log and branch to guest kernel registered 5843machine check handling routine. Without this capability KVM will 5844branch to guests' 0x200 interrupt vector. 5845 58467.13 KVM_CAP_X86_DISABLE_EXITS 5847------------------------------ 5848 5849:Architectures: x86 5850:Parameters: args[0] defines which exits are disabled 5851:Returns: 0 on success, -EINVAL when args[0] contains invalid exits 5852 5853Valid bits in args[0] are:: 5854 5855 #define KVM_X86_DISABLE_EXITS_MWAIT (1 << 0) 5856 #define KVM_X86_DISABLE_EXITS_HLT (1 << 1) 5857 #define KVM_X86_DISABLE_EXITS_PAUSE (1 << 2) 5858 #define KVM_X86_DISABLE_EXITS_CSTATE (1 << 3) 5859 5860Enabling this capability on a VM provides userspace with a way to no 5861longer intercept some instructions for improved latency in some 5862workloads, and is suggested when vCPUs are associated to dedicated 5863physical CPUs. More bits can be added in the future; userspace can 5864just pass the KVM_CHECK_EXTENSION result to KVM_ENABLE_CAP to disable 5865all such vmexits. 5866 5867Do not enable KVM_FEATURE_PV_UNHALT if you disable HLT exits. 5868 58697.14 KVM_CAP_S390_HPAGE_1M 5870-------------------------- 5871 5872:Architectures: s390 5873:Parameters: none 5874:Returns: 0 on success, -EINVAL if hpage module parameter was not set 5875 or cmma is enabled, or the VM has the KVM_VM_S390_UCONTROL 5876 flag set 5877 5878With this capability the KVM support for memory backing with 1m pages 5879through hugetlbfs can be enabled for a VM. After the capability is 5880enabled, cmma can't be enabled anymore and pfmfi and the storage key 5881interpretation are disabled. If cmma has already been enabled or the 5882hpage module parameter is not set to 1, -EINVAL is returned. 5883 5884While it is generally possible to create a huge page backed VM without 5885this capability, the VM will not be able to run. 5886 58877.15 KVM_CAP_MSR_PLATFORM_INFO 5888------------------------------ 5889 5890:Architectures: x86 5891:Parameters: args[0] whether feature should be enabled or not 5892 5893With this capability, a guest may read the MSR_PLATFORM_INFO MSR. Otherwise, 5894a #GP would be raised when the guest tries to access. Currently, this 5895capability does not enable write permissions of this MSR for the guest. 5896 58977.16 KVM_CAP_PPC_NESTED_HV 5898-------------------------- 5899 5900:Architectures: ppc 5901:Parameters: none 5902:Returns: 0 on success, -EINVAL when the implementation doesn't support 5903 nested-HV virtualization. 5904 5905HV-KVM on POWER9 and later systems allows for "nested-HV" 5906virtualization, which provides a way for a guest VM to run guests that 5907can run using the CPU's supervisor mode (privileged non-hypervisor 5908state). Enabling this capability on a VM depends on the CPU having 5909the necessary functionality and on the facility being enabled with a 5910kvm-hv module parameter. 5911 59127.17 KVM_CAP_EXCEPTION_PAYLOAD 5913------------------------------ 5914 5915:Architectures: x86 5916:Parameters: args[0] whether feature should be enabled or not 5917 5918With this capability enabled, CR2 will not be modified prior to the 5919emulated VM-exit when L1 intercepts a #PF exception that occurs in 5920L2. Similarly, for kvm-intel only, DR6 will not be modified prior to 5921the emulated VM-exit when L1 intercepts a #DB exception that occurs in 5922L2. As a result, when KVM_GET_VCPU_EVENTS reports a pending #PF (or 5923#DB) exception for L2, exception.has_payload will be set and the 5924faulting address (or the new DR6 bits*) will be reported in the 5925exception_payload field. Similarly, when userspace injects a #PF (or 5926#DB) into L2 using KVM_SET_VCPU_EVENTS, it is expected to set 5927exception.has_payload and to put the faulting address - or the new DR6 5928bits\ [#]_ - in the exception_payload field. 5929 5930This capability also enables exception.pending in struct 5931kvm_vcpu_events, which allows userspace to distinguish between pending 5932and injected exceptions. 5933 5934 5935.. [#] For the new DR6 bits, note that bit 16 is set iff the #DB exception 5936 will clear DR6.RTM. 5937 59387.18 KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2 5939 5940:Architectures: x86, arm, arm64, mips 5941:Parameters: args[0] whether feature should be enabled or not 5942 5943Valid flags are:: 5944 5945 #define KVM_DIRTY_LOG_MANUAL_PROTECT_ENABLE (1 << 0) 5946 #define KVM_DIRTY_LOG_INITIALLY_SET (1 << 1) 5947 5948With KVM_DIRTY_LOG_MANUAL_PROTECT_ENABLE is set, KVM_GET_DIRTY_LOG will not 5949automatically clear and write-protect all pages that are returned as dirty. 5950Rather, userspace will have to do this operation separately using 5951KVM_CLEAR_DIRTY_LOG. 5952 5953At the cost of a slightly more complicated operation, this provides better 5954scalability and responsiveness for two reasons. First, 5955KVM_CLEAR_DIRTY_LOG ioctl can operate on a 64-page granularity rather 5956than requiring to sync a full memslot; this ensures that KVM does not 5957take spinlocks for an extended period of time. Second, in some cases a 5958large amount of time can pass between a call to KVM_GET_DIRTY_LOG and 5959userspace actually using the data in the page. Pages can be modified 5960during this time, which is inefficient for both the guest and userspace: 5961the guest will incur a higher penalty due to write protection faults, 5962while userspace can see false reports of dirty pages. Manual reprotection 5963helps reducing this time, improving guest performance and reducing the 5964number of dirty log false positives. 5965 5966With KVM_DIRTY_LOG_INITIALLY_SET set, all the bits of the dirty bitmap 5967will be initialized to 1 when created. This also improves performance because 5968dirty logging can be enabled gradually in small chunks on the first call 5969to KVM_CLEAR_DIRTY_LOG. KVM_DIRTY_LOG_INITIALLY_SET depends on 5970KVM_DIRTY_LOG_MANUAL_PROTECT_ENABLE (it is also only available on 5971x86 and arm64 for now). 5972 5973KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2 was previously available under the name 5974KVM_CAP_MANUAL_DIRTY_LOG_PROTECT, but the implementation had bugs that make 5975it hard or impossible to use it correctly. The availability of 5976KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2 signals that those bugs are fixed. 5977Userspace should not try to use KVM_CAP_MANUAL_DIRTY_LOG_PROTECT. 5978 59797.19 KVM_CAP_PPC_SECURE_GUEST 5980------------------------------ 5981 5982:Architectures: ppc 5983 5984This capability indicates that KVM is running on a host that has 5985ultravisor firmware and thus can support a secure guest. On such a 5986system, a guest can ask the ultravisor to make it a secure guest, 5987one whose memory is inaccessible to the host except for pages which 5988are explicitly requested to be shared with the host. The ultravisor 5989notifies KVM when a guest requests to become a secure guest, and KVM 5990has the opportunity to veto the transition. 5991 5992If present, this capability can be enabled for a VM, meaning that KVM 5993will allow the transition to secure guest mode. Otherwise KVM will 5994veto the transition. 5995 59967.20 KVM_CAP_HALT_POLL 5997---------------------- 5998 5999:Architectures: all 6000:Target: VM 6001:Parameters: args[0] is the maximum poll time in nanoseconds 6002:Returns: 0 on success; -1 on error 6003 6004This capability overrides the kvm module parameter halt_poll_ns for the 6005target VM. 6006 6007VCPU polling allows a VCPU to poll for wakeup events instead of immediately 6008scheduling during guest halts. The maximum time a VCPU can spend polling is 6009controlled by the kvm module parameter halt_poll_ns. This capability allows 6010the maximum halt time to specified on a per-VM basis, effectively overriding 6011the module parameter for the target VM. 6012 60137.21 KVM_CAP_X86_USER_SPACE_MSR 6014------------------------------- 6015 6016:Architectures: x86 6017:Target: VM 6018:Parameters: args[0] contains the mask of KVM_MSR_EXIT_REASON_* events to report 6019:Returns: 0 on success; -1 on error 6020 6021This capability enables trapping of #GP invoking RDMSR and WRMSR instructions 6022into user space. 6023 6024When a guest requests to read or write an MSR, KVM may not implement all MSRs 6025that are relevant to a respective system. It also does not differentiate by 6026CPU type. 6027 6028To allow more fine grained control over MSR handling, user space may enable 6029this capability. With it enabled, MSR accesses that match the mask specified in 6030args[0] and trigger a #GP event inside the guest by KVM will instead trigger 6031KVM_EXIT_X86_RDMSR and KVM_EXIT_X86_WRMSR exit notifications which user space 6032can then handle to implement model specific MSR handling and/or user notifications 6033to inform a user that an MSR was not handled. 6034 60358. Other capabilities. 6036====================== 6037 6038This section lists capabilities that give information about other 6039features of the KVM implementation. 6040 60418.1 KVM_CAP_PPC_HWRNG 6042--------------------- 6043 6044:Architectures: ppc 6045 6046This capability, if KVM_CHECK_EXTENSION indicates that it is 6047available, means that the kernel has an implementation of the 6048H_RANDOM hypercall backed by a hardware random-number generator. 6049If present, the kernel H_RANDOM handler can be enabled for guest use 6050with the KVM_CAP_PPC_ENABLE_HCALL capability. 6051 60528.2 KVM_CAP_HYPERV_SYNIC 6053------------------------ 6054 6055:Architectures: x86 6056 6057This capability, if KVM_CHECK_EXTENSION indicates that it is 6058available, means that the kernel has an implementation of the 6059Hyper-V Synthetic interrupt controller(SynIC). Hyper-V SynIC is 6060used to support Windows Hyper-V based guest paravirt drivers(VMBus). 6061 6062In order to use SynIC, it has to be activated by setting this 6063capability via KVM_ENABLE_CAP ioctl on the vcpu fd. Note that this 6064will disable the use of APIC hardware virtualization even if supported 6065by the CPU, as it's incompatible with SynIC auto-EOI behavior. 6066 60678.3 KVM_CAP_PPC_RADIX_MMU 6068------------------------- 6069 6070:Architectures: ppc 6071 6072This capability, if KVM_CHECK_EXTENSION indicates that it is 6073available, means that the kernel can support guests using the 6074radix MMU defined in Power ISA V3.00 (as implemented in the POWER9 6075processor). 6076 60778.4 KVM_CAP_PPC_HASH_MMU_V3 6078--------------------------- 6079 6080:Architectures: ppc 6081 6082This capability, if KVM_CHECK_EXTENSION indicates that it is 6083available, means that the kernel can support guests using the 6084hashed page table MMU defined in Power ISA V3.00 (as implemented in 6085the POWER9 processor), including in-memory segment tables. 6086 60878.5 KVM_CAP_MIPS_VZ 6088------------------- 6089 6090:Architectures: mips 6091 6092This capability, if KVM_CHECK_EXTENSION on the main kvm handle indicates that 6093it is available, means that full hardware assisted virtualization capabilities 6094of the hardware are available for use through KVM. An appropriate 6095KVM_VM_MIPS_* type must be passed to KVM_CREATE_VM to create a VM which 6096utilises it. 6097 6098If KVM_CHECK_EXTENSION on a kvm VM handle indicates that this capability is 6099available, it means that the VM is using full hardware assisted virtualization 6100capabilities of the hardware. This is useful to check after creating a VM with 6101KVM_VM_MIPS_DEFAULT. 6102 6103The value returned by KVM_CHECK_EXTENSION should be compared against known 6104values (see below). All other values are reserved. This is to allow for the 6105possibility of other hardware assisted virtualization implementations which 6106may be incompatible with the MIPS VZ ASE. 6107 6108== ========================================================================== 6109 0 The trap & emulate implementation is in use to run guest code in user 6110 mode. Guest virtual memory segments are rearranged to fit the guest in the 6111 user mode address space. 6112 6113 1 The MIPS VZ ASE is in use, providing full hardware assisted 6114 virtualization, including standard guest virtual memory segments. 6115== ========================================================================== 6116 61178.6 KVM_CAP_MIPS_TE 6118------------------- 6119 6120:Architectures: mips 6121 6122This capability, if KVM_CHECK_EXTENSION on the main kvm handle indicates that 6123it is available, means that the trap & emulate implementation is available to 6124run guest code in user mode, even if KVM_CAP_MIPS_VZ indicates that hardware 6125assisted virtualisation is also available. KVM_VM_MIPS_TE (0) must be passed 6126to KVM_CREATE_VM to create a VM which utilises it. 6127 6128If KVM_CHECK_EXTENSION on a kvm VM handle indicates that this capability is 6129available, it means that the VM is using trap & emulate. 6130 61318.7 KVM_CAP_MIPS_64BIT 6132---------------------- 6133 6134:Architectures: mips 6135 6136This capability indicates the supported architecture type of the guest, i.e. the 6137supported register and address width. 6138 6139The values returned when this capability is checked by KVM_CHECK_EXTENSION on a 6140kvm VM handle correspond roughly to the CP0_Config.AT register field, and should 6141be checked specifically against known values (see below). All other values are 6142reserved. 6143 6144== ======================================================================== 6145 0 MIPS32 or microMIPS32. 6146 Both registers and addresses are 32-bits wide. 6147 It will only be possible to run 32-bit guest code. 6148 6149 1 MIPS64 or microMIPS64 with access only to 32-bit compatibility segments. 6150 Registers are 64-bits wide, but addresses are 32-bits wide. 6151 64-bit guest code may run but cannot access MIPS64 memory segments. 6152 It will also be possible to run 32-bit guest code. 6153 6154 2 MIPS64 or microMIPS64 with access to all address segments. 6155 Both registers and addresses are 64-bits wide. 6156 It will be possible to run 64-bit or 32-bit guest code. 6157== ======================================================================== 6158 61598.9 KVM_CAP_ARM_USER_IRQ 6160------------------------ 6161 6162:Architectures: arm, arm64 6163 6164This capability, if KVM_CHECK_EXTENSION indicates that it is available, means 6165that if userspace creates a VM without an in-kernel interrupt controller, it 6166will be notified of changes to the output level of in-kernel emulated devices, 6167which can generate virtual interrupts, presented to the VM. 6168For such VMs, on every return to userspace, the kernel 6169updates the vcpu's run->s.regs.device_irq_level field to represent the actual 6170output level of the device. 6171 6172Whenever kvm detects a change in the device output level, kvm guarantees at 6173least one return to userspace before running the VM. This exit could either 6174be a KVM_EXIT_INTR or any other exit event, like KVM_EXIT_MMIO. This way, 6175userspace can always sample the device output level and re-compute the state of 6176the userspace interrupt controller. Userspace should always check the state 6177of run->s.regs.device_irq_level on every kvm exit. 6178The value in run->s.regs.device_irq_level can represent both level and edge 6179triggered interrupt signals, depending on the device. Edge triggered interrupt 6180signals will exit to userspace with the bit in run->s.regs.device_irq_level 6181set exactly once per edge signal. 6182 6183The field run->s.regs.device_irq_level is available independent of 6184run->kvm_valid_regs or run->kvm_dirty_regs bits. 6185 6186If KVM_CAP_ARM_USER_IRQ is supported, the KVM_CHECK_EXTENSION ioctl returns a 6187number larger than 0 indicating the version of this capability is implemented 6188and thereby which bits in run->s.regs.device_irq_level can signal values. 6189 6190Currently the following bits are defined for the device_irq_level bitmap:: 6191 6192 KVM_CAP_ARM_USER_IRQ >= 1: 6193 6194 KVM_ARM_DEV_EL1_VTIMER - EL1 virtual timer 6195 KVM_ARM_DEV_EL1_PTIMER - EL1 physical timer 6196 KVM_ARM_DEV_PMU - ARM PMU overflow interrupt signal 6197 6198Future versions of kvm may implement additional events. These will get 6199indicated by returning a higher number from KVM_CHECK_EXTENSION and will be 6200listed above. 6201 62028.10 KVM_CAP_PPC_SMT_POSSIBLE 6203----------------------------- 6204 6205:Architectures: ppc 6206 6207Querying this capability returns a bitmap indicating the possible 6208virtual SMT modes that can be set using KVM_CAP_PPC_SMT. If bit N 6209(counting from the right) is set, then a virtual SMT mode of 2^N is 6210available. 6211 62128.11 KVM_CAP_HYPERV_SYNIC2 6213-------------------------- 6214 6215:Architectures: x86 6216 6217This capability enables a newer version of Hyper-V Synthetic interrupt 6218controller (SynIC). The only difference with KVM_CAP_HYPERV_SYNIC is that KVM 6219doesn't clear SynIC message and event flags pages when they are enabled by 6220writing to the respective MSRs. 6221 62228.12 KVM_CAP_HYPERV_VP_INDEX 6223---------------------------- 6224 6225:Architectures: x86 6226 6227This capability indicates that userspace can load HV_X64_MSR_VP_INDEX msr. Its 6228value is used to denote the target vcpu for a SynIC interrupt. For 6229compatibilty, KVM initializes this msr to KVM's internal vcpu index. When this 6230capability is absent, userspace can still query this msr's value. 6231 62328.13 KVM_CAP_S390_AIS_MIGRATION 6233------------------------------- 6234 6235:Architectures: s390 6236:Parameters: none 6237 6238This capability indicates if the flic device will be able to get/set the 6239AIS states for migration via the KVM_DEV_FLIC_AISM_ALL attribute and allows 6240to discover this without having to create a flic device. 6241 62428.14 KVM_CAP_S390_PSW 6243--------------------- 6244 6245:Architectures: s390 6246 6247This capability indicates that the PSW is exposed via the kvm_run structure. 6248 62498.15 KVM_CAP_S390_GMAP 6250---------------------- 6251 6252:Architectures: s390 6253 6254This capability indicates that the user space memory used as guest mapping can 6255be anywhere in the user memory address space, as long as the memory slots are 6256aligned and sized to a segment (1MB) boundary. 6257 62588.16 KVM_CAP_S390_COW 6259--------------------- 6260 6261:Architectures: s390 6262 6263This capability indicates that the user space memory used as guest mapping can 6264use copy-on-write semantics as well as dirty pages tracking via read-only page 6265tables. 6266 62678.17 KVM_CAP_S390_BPB 6268--------------------- 6269 6270:Architectures: s390 6271 6272This capability indicates that kvm will implement the interfaces to handle 6273reset, migration and nested KVM for branch prediction blocking. The stfle 6274facility 82 should not be provided to the guest without this capability. 6275 62768.18 KVM_CAP_HYPERV_TLBFLUSH 6277---------------------------- 6278 6279:Architectures: x86 6280 6281This capability indicates that KVM supports paravirtualized Hyper-V TLB Flush 6282hypercalls: 6283HvFlushVirtualAddressSpace, HvFlushVirtualAddressSpaceEx, 6284HvFlushVirtualAddressList, HvFlushVirtualAddressListEx. 6285 62868.19 KVM_CAP_ARM_INJECT_SERROR_ESR 6287---------------------------------- 6288 6289:Architectures: arm, arm64 6290 6291This capability indicates that userspace can specify (via the 6292KVM_SET_VCPU_EVENTS ioctl) the syndrome value reported to the guest when it 6293takes a virtual SError interrupt exception. 6294If KVM advertises this capability, userspace can only specify the ISS field for 6295the ESR syndrome. Other parts of the ESR, such as the EC are generated by the 6296CPU when the exception is taken. If this virtual SError is taken to EL1 using 6297AArch64, this value will be reported in the ISS field of ESR_ELx. 6298 6299See KVM_CAP_VCPU_EVENTS for more details. 6300 63018.20 KVM_CAP_HYPERV_SEND_IPI 6302---------------------------- 6303 6304:Architectures: x86 6305 6306This capability indicates that KVM supports paravirtualized Hyper-V IPI send 6307hypercalls: 6308HvCallSendSyntheticClusterIpi, HvCallSendSyntheticClusterIpiEx. 6309 63108.21 KVM_CAP_HYPERV_DIRECT_TLBFLUSH 6311----------------------------------- 6312 6313:Architectures: x86 6314 6315This capability indicates that KVM running on top of Hyper-V hypervisor 6316enables Direct TLB flush for its guests meaning that TLB flush 6317hypercalls are handled by Level 0 hypervisor (Hyper-V) bypassing KVM. 6318Due to the different ABI for hypercall parameters between Hyper-V and 6319KVM, enabling this capability effectively disables all hypercall 6320handling by KVM (as some KVM hypercall may be mistakenly treated as TLB 6321flush hypercalls by Hyper-V) so userspace should disable KVM identification 6322in CPUID and only exposes Hyper-V identification. In this case, guest 6323thinks it's running on Hyper-V and only use Hyper-V hypercalls. 6324 63258.22 KVM_CAP_S390_VCPU_RESETS 6326----------------------------- 6327 6328:Architectures: s390 6329 6330This capability indicates that the KVM_S390_NORMAL_RESET and 6331KVM_S390_CLEAR_RESET ioctls are available. 6332 63338.23 KVM_CAP_S390_PROTECTED 6334--------------------------- 6335 6336:Architectures: s390 6337 6338This capability indicates that the Ultravisor has been initialized and 6339KVM can therefore start protected VMs. 6340This capability governs the KVM_S390_PV_COMMAND ioctl and the 6341KVM_MP_STATE_LOAD MP_STATE. KVM_SET_MP_STATE can fail for protected 6342guests when the state change is invalid. 6343 63448.24 KVM_CAP_STEAL_TIME 6345----------------------- 6346 6347:Architectures: arm64, x86 6348 6349This capability indicates that KVM supports steal time accounting. 6350When steal time accounting is supported it may be enabled with 6351architecture-specific interfaces. This capability and the architecture- 6352specific interfaces must be consistent, i.e. if one says the feature 6353is supported, than the other should as well and vice versa. For arm64 6354see Documentation/virt/kvm/devices/vcpu.rst "KVM_ARM_VCPU_PVTIME_CTRL". 6355For x86 see Documentation/virt/kvm/msr.rst "MSR_KVM_STEAL_TIME". 6356 63578.25 KVM_CAP_S390_DIAG318 6358------------------------- 6359 6360:Architectures: s390 6361 6362This capability enables a guest to set information about its control program 6363(i.e. guest kernel type and version). The information is helpful during 6364system/firmware service events, providing additional data about the guest 6365environments running on the machine. 6366 6367The information is associated with the DIAGNOSE 0x318 instruction, which sets 6368an 8-byte value consisting of a one-byte Control Program Name Code (CPNC) and 6369a 7-byte Control Program Version Code (CPVC). The CPNC determines what 6370environment the control program is running in (e.g. Linux, z/VM...), and the 6371CPVC is used for information specific to OS (e.g. Linux version, Linux 6372distribution...) 6373 6374If this capability is available, then the CPNC and CPVC can be synchronized 6375between KVM and userspace via the sync regs mechanism (KVM_SYNC_DIAG318). 6376 63778.26 KVM_CAP_X86_USER_SPACE_MSR 6378------------------------------- 6379 6380:Architectures: x86 6381 6382This capability indicates that KVM supports deflection of MSR reads and 6383writes to user space. It can be enabled on a VM level. If enabled, MSR 6384accesses that would usually trigger a #GP by KVM into the guest will 6385instead get bounced to user space through the KVM_EXIT_X86_RDMSR and 6386KVM_EXIT_X86_WRMSR exit notifications. 6387 63888.27 KVM_X86_SET_MSR_FILTER 6389--------------------------- 6390 6391:Architectures: x86 6392 6393This capability indicates that KVM supports that accesses to user defined MSRs 6394may be rejected. With this capability exposed, KVM exports new VM ioctl 6395KVM_X86_SET_MSR_FILTER which user space can call to specify bitmaps of MSR 6396ranges that KVM should reject access to. 6397 6398In combination with KVM_CAP_X86_USER_SPACE_MSR, this allows user space to 6399trap and emulate MSRs that are outside of the scope of KVM as well as 6400limit the attack surface on KVM's MSR emulation code. 6401 64028.28 KVM_CAP_ENFORCE_PV_CPUID 6403----------------------------- 6404 6405Architectures: x86 6406 6407When enabled, KVM will disable paravirtual features provided to the 6408guest according to the bits in the KVM_CPUID_FEATURES CPUID leaf 6409(0x40000001). Otherwise, a guest may use the paravirtual features 6410regardless of what has actually been exposed through the CPUID leaf. 6411 6412 64138.29 KVM_CAP_DIRTY_LOG_RING 6414--------------------------- 6415 6416:Architectures: x86 6417:Parameters: args[0] - size of the dirty log ring 6418 6419KVM is capable of tracking dirty memory using ring buffers that are 6420mmaped into userspace; there is one dirty ring per vcpu. 6421 6422The dirty ring is available to userspace as an array of 6423``struct kvm_dirty_gfn``. Each dirty entry it's defined as:: 6424 6425 struct kvm_dirty_gfn { 6426 __u32 flags; 6427 __u32 slot; /* as_id | slot_id */ 6428 __u64 offset; 6429 }; 6430 6431The following values are defined for the flags field to define the 6432current state of the entry:: 6433 6434 #define KVM_DIRTY_GFN_F_DIRTY BIT(0) 6435 #define KVM_DIRTY_GFN_F_RESET BIT(1) 6436 #define KVM_DIRTY_GFN_F_MASK 0x3 6437 6438Userspace should call KVM_ENABLE_CAP ioctl right after KVM_CREATE_VM 6439ioctl to enable this capability for the new guest and set the size of 6440the rings. Enabling the capability is only allowed before creating any 6441vCPU, and the size of the ring must be a power of two. The larger the 6442ring buffer, the less likely the ring is full and the VM is forced to 6443exit to userspace. The optimal size depends on the workload, but it is 6444recommended that it be at least 64 KiB (4096 entries). 6445 6446Just like for dirty page bitmaps, the buffer tracks writes to 6447all user memory regions for which the KVM_MEM_LOG_DIRTY_PAGES flag was 6448set in KVM_SET_USER_MEMORY_REGION. Once a memory region is registered 6449with the flag set, userspace can start harvesting dirty pages from the 6450ring buffer. 6451 6452An entry in the ring buffer can be unused (flag bits ``00``), 6453dirty (flag bits ``01``) or harvested (flag bits ``1X``). The 6454state machine for the entry is as follows:: 6455 6456 dirtied harvested reset 6457 00 -----------> 01 -------------> 1X -------+ 6458 ^ | 6459 | | 6460 +------------------------------------------+ 6461 6462To harvest the dirty pages, userspace accesses the mmaped ring buffer 6463to read the dirty GFNs. If the flags has the DIRTY bit set (at this stage 6464the RESET bit must be cleared), then it means this GFN is a dirty GFN. 6465The userspace should harvest this GFN and mark the flags from state 6466``01b`` to ``1Xb`` (bit 0 will be ignored by KVM, but bit 1 must be set 6467to show that this GFN is harvested and waiting for a reset), and move 6468on to the next GFN. The userspace should continue to do this until the 6469flags of a GFN have the DIRTY bit cleared, meaning that it has harvested 6470all the dirty GFNs that were available. 6471 6472It's not necessary for userspace to harvest the all dirty GFNs at once. 6473However it must collect the dirty GFNs in sequence, i.e., the userspace 6474program cannot skip one dirty GFN to collect the one next to it. 6475 6476After processing one or more entries in the ring buffer, userspace 6477calls the VM ioctl KVM_RESET_DIRTY_RINGS to notify the kernel about 6478it, so that the kernel will reprotect those collected GFNs. 6479Therefore, the ioctl must be called *before* reading the content of 6480the dirty pages. 6481 6482The dirty ring can get full. When it happens, the KVM_RUN of the 6483vcpu will return with exit reason KVM_EXIT_DIRTY_LOG_FULL. 6484 6485The dirty ring interface has a major difference comparing to the 6486KVM_GET_DIRTY_LOG interface in that, when reading the dirty ring from 6487userspace, it's still possible that the kernel has not yet flushed the 6488processor's dirty page buffers into the kernel buffer (with dirty bitmaps, the 6489flushing is done by the KVM_GET_DIRTY_LOG ioctl). To achieve that, one 6490needs to kick the vcpu out of KVM_RUN using a signal. The resulting 6491vmexit ensures that all dirty GFNs are flushed to the dirty rings. 6492 6493NOTE: the capability KVM_CAP_DIRTY_LOG_RING and the corresponding 6494ioctl KVM_RESET_DIRTY_RINGS are mutual exclusive to the existing ioctls 6495KVM_GET_DIRTY_LOG and KVM_CLEAR_DIRTY_LOG. After enabling 6496KVM_CAP_DIRTY_LOG_RING with an acceptable dirty ring size, the virtual 6497machine will switch to ring-buffer dirty page tracking and further 6498KVM_GET_DIRTY_LOG or KVM_CLEAR_DIRTY_LOG ioctls will fail. 6499