api.txt 45 KB

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