api.txt 47 KB

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