api.txt 39 KB

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