api.txt 50 KB

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