api.txt 58 KB

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