api.txt 83 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802
  1. The Definitive KVM (Kernel-based Virtual Machine) API Documentation
  2. ===================================================================
  3. 1. General description
  4. ----------------------
  5. The kvm API is a set of ioctls that are issued to control various aspects
  6. of a virtual machine. The ioctls belong to three classes
  7. - System ioctls: These query and set global attributes which affect the
  8. whole kvm subsystem. In addition a system ioctl is used to create
  9. virtual machines
  10. - VM ioctls: These query and set attributes that affect an entire virtual
  11. machine, for example memory layout. In addition a VM ioctl is used to
  12. create virtual cpus (vcpus).
  13. Only run VM ioctls from the same process (address space) that was used
  14. to create the VM.
  15. - vcpu ioctls: These query and set attributes that control the operation
  16. of a single virtual cpu.
  17. Only run vcpu ioctls from the same thread that was used to create the
  18. vcpu.
  19. 2. File descriptors
  20. -------------------
  21. The kvm API is centered around file descriptors. An initial
  22. open("/dev/kvm") obtains a handle to the kvm subsystem; this handle
  23. can be used to issue system ioctls. A KVM_CREATE_VM ioctl on this
  24. handle will create a VM file descriptor which can be used to issue VM
  25. ioctls. A KVM_CREATE_VCPU ioctl on a VM fd will create a virtual cpu
  26. and return a file descriptor pointing to it. Finally, ioctls on a vcpu
  27. fd can be used to control the vcpu, including the important task of
  28. actually running guest code.
  29. In general file descriptors can be migrated among processes by means
  30. of fork() and the SCM_RIGHTS facility of unix domain socket. These
  31. kinds of tricks are explicitly not supported by kvm. While they will
  32. not cause harm to the host, their actual behavior is not guaranteed by
  33. the API. The only supported use is one virtual machine per process,
  34. and one vcpu per thread.
  35. 3. Extensions
  36. -------------
  37. As of Linux 2.6.22, the KVM ABI has been stabilized: no backward
  38. incompatible change are allowed. However, there is an extension
  39. facility that allows backward-compatible extensions to the API to be
  40. queried and used.
  41. The extension mechanism is not based on on the Linux version number.
  42. Instead, kvm defines extension identifiers and a facility to query
  43. whether a particular extension identifier is available. If it is, a
  44. set of ioctls is available for application use.
  45. 4. API description
  46. ------------------
  47. This section describes ioctls that can be used to control kvm guests.
  48. For each ioctl, the following information is provided along with a
  49. description:
  50. Capability: which KVM extension provides this ioctl. Can be 'basic',
  51. which means that is will be provided by any kernel that supports
  52. API version 12 (see section 4.1), or a KVM_CAP_xyz constant, which
  53. means availability needs to be checked with KVM_CHECK_EXTENSION
  54. (see section 4.4).
  55. Architectures: which instruction set architectures provide this ioctl.
  56. x86 includes both i386 and x86_64.
  57. Type: system, vm, or vcpu.
  58. Parameters: what parameters are accepted by the ioctl.
  59. Returns: the return value. General error numbers (EBADF, ENOMEM, EINVAL)
  60. are not detailed, but errors with specific meanings are.
  61. 4.1 KVM_GET_API_VERSION
  62. Capability: basic
  63. Architectures: all
  64. Type: system ioctl
  65. Parameters: none
  66. Returns: the constant KVM_API_VERSION (=12)
  67. This identifies the API version as the stable kvm API. It is not
  68. expected that this number will change. However, Linux 2.6.20 and
  69. 2.6.21 report earlier versions; these are not documented and not
  70. supported. Applications should refuse to run if KVM_GET_API_VERSION
  71. returns a value other than 12. If this check passes, all ioctls
  72. described as 'basic' will be available.
  73. 4.2 KVM_CREATE_VM
  74. Capability: basic
  75. Architectures: all
  76. Type: system ioctl
  77. Parameters: machine type identifier (KVM_VM_*)
  78. Returns: a VM fd that can be used to control the new virtual machine.
  79. The new VM has no virtual cpus and no memory. An mmap() of a VM fd
  80. will access the virtual machine's physical address space; offset zero
  81. corresponds to guest physical address zero. Use of mmap() on a VM fd
  82. is discouraged if userspace memory allocation (KVM_CAP_USER_MEMORY) is
  83. available.
  84. You most certainly want to use 0 as machine type.
  85. In order to create user controlled virtual machines on S390, check
  86. KVM_CAP_S390_UCONTROL and use the flag KVM_VM_S390_UCONTROL as
  87. privileged user (CAP_SYS_ADMIN).
  88. 4.3 KVM_GET_MSR_INDEX_LIST
  89. Capability: basic
  90. Architectures: x86
  91. Type: system
  92. Parameters: struct kvm_msr_list (in/out)
  93. Returns: 0 on success; -1 on error
  94. Errors:
  95. E2BIG: the msr index list is to be to fit in the array specified by
  96. the user.
  97. struct kvm_msr_list {
  98. __u32 nmsrs; /* number of msrs in entries */
  99. __u32 indices[0];
  100. };
  101. This ioctl returns the guest msrs that are supported. The list varies
  102. by kvm version and host processor, but does not change otherwise. The
  103. user fills in the size of the indices array in nmsrs, and in return
  104. kvm adjusts nmsrs to reflect the actual number of msrs and fills in
  105. the indices array with their numbers.
  106. Note: if kvm indicates supports MCE (KVM_CAP_MCE), then the MCE bank MSRs are
  107. not returned in the MSR list, as different vcpus can have a different number
  108. of banks, as set via the KVM_X86_SETUP_MCE ioctl.
  109. 4.4 KVM_CHECK_EXTENSION
  110. Capability: basic
  111. Architectures: all
  112. Type: system ioctl
  113. Parameters: extension identifier (KVM_CAP_*)
  114. Returns: 0 if unsupported; 1 (or some other positive integer) if supported
  115. The API allows the application to query about extensions to the core
  116. kvm API. Userspace passes an extension identifier (an integer) and
  117. receives an integer that describes the extension availability.
  118. Generally 0 means no and 1 means yes, but some extensions may report
  119. additional information in the integer return value.
  120. 4.5 KVM_GET_VCPU_MMAP_SIZE
  121. Capability: basic
  122. Architectures: all
  123. Type: system ioctl
  124. Parameters: none
  125. Returns: size of vcpu mmap area, in bytes
  126. The KVM_RUN ioctl (cf.) communicates with userspace via a shared
  127. memory region. This ioctl returns the size of that region. See the
  128. KVM_RUN documentation for details.
  129. 4.6 KVM_SET_MEMORY_REGION
  130. Capability: basic
  131. Architectures: all
  132. Type: vm ioctl
  133. Parameters: struct kvm_memory_region (in)
  134. Returns: 0 on success, -1 on error
  135. This ioctl is obsolete and has been removed.
  136. 4.7 KVM_CREATE_VCPU
  137. Capability: basic
  138. Architectures: all
  139. Type: vm ioctl
  140. Parameters: vcpu id (apic id on x86)
  141. Returns: vcpu fd on success, -1 on error
  142. This API adds a vcpu to a virtual machine. The vcpu id is a small integer
  143. in the range [0, max_vcpus).
  144. The recommended max_vcpus value can be retrieved using the KVM_CAP_NR_VCPUS of
  145. the KVM_CHECK_EXTENSION ioctl() at run-time.
  146. The maximum possible value for max_vcpus can be retrieved using the
  147. KVM_CAP_MAX_VCPUS of the KVM_CHECK_EXTENSION ioctl() at run-time.
  148. If the KVM_CAP_NR_VCPUS does not exist, you should assume that max_vcpus is 4
  149. cpus max.
  150. If the KVM_CAP_MAX_VCPUS does not exist, you should assume that max_vcpus is
  151. same as the value returned from KVM_CAP_NR_VCPUS.
  152. On powerpc using book3s_hv mode, the vcpus are mapped onto virtual
  153. threads in one or more virtual CPU cores. (This is because the
  154. hardware requires all the hardware threads in a CPU core to be in the
  155. same partition.) The KVM_CAP_PPC_SMT capability indicates the number
  156. of vcpus per virtual core (vcore). The vcore id is obtained by
  157. dividing the vcpu id by the number of vcpus per vcore. The vcpus in a
  158. given vcore will always be in the same physical core as each other
  159. (though that might be a different physical core from time to time).
  160. Userspace can control the threading (SMT) mode of the guest by its
  161. allocation of vcpu ids. For example, if userspace wants
  162. single-threaded guest vcpus, it should make all vcpu ids be a multiple
  163. of the number of vcpus per vcore.
  164. For virtual cpus that have been created with S390 user controlled virtual
  165. machines, the resulting vcpu fd can be memory mapped at page offset
  166. KVM_S390_SIE_PAGE_OFFSET in order to obtain a memory map of the virtual
  167. cpu's hardware control block.
  168. 4.8 KVM_GET_DIRTY_LOG (vm ioctl)
  169. Capability: basic
  170. Architectures: x86
  171. Type: vm ioctl
  172. Parameters: struct kvm_dirty_log (in/out)
  173. Returns: 0 on success, -1 on error
  174. /* for KVM_GET_DIRTY_LOG */
  175. struct kvm_dirty_log {
  176. __u32 slot;
  177. __u32 padding;
  178. union {
  179. void __user *dirty_bitmap; /* one bit per page */
  180. __u64 padding;
  181. };
  182. };
  183. Given a memory slot, return a bitmap containing any pages dirtied
  184. since the last call to this ioctl. Bit 0 is the first page in the
  185. memory slot. Ensure the entire structure is cleared to avoid padding
  186. issues.
  187. 4.9 KVM_SET_MEMORY_ALIAS
  188. Capability: basic
  189. Architectures: x86
  190. Type: vm ioctl
  191. Parameters: struct kvm_memory_alias (in)
  192. Returns: 0 (success), -1 (error)
  193. This ioctl is obsolete and has been removed.
  194. 4.10 KVM_RUN
  195. Capability: basic
  196. Architectures: all
  197. Type: vcpu ioctl
  198. Parameters: none
  199. Returns: 0 on success, -1 on error
  200. Errors:
  201. EINTR: an unmasked signal is pending
  202. This ioctl is used to run a guest virtual cpu. While there are no
  203. explicit parameters, there is an implicit parameter block that can be
  204. obtained by mmap()ing the vcpu fd at offset 0, with the size given by
  205. KVM_GET_VCPU_MMAP_SIZE. The parameter block is formatted as a 'struct
  206. kvm_run' (see below).
  207. 4.11 KVM_GET_REGS
  208. Capability: basic
  209. Architectures: all except ARM, arm64
  210. Type: vcpu ioctl
  211. Parameters: struct kvm_regs (out)
  212. Returns: 0 on success, -1 on error
  213. Reads the general purpose registers from the vcpu.
  214. /* x86 */
  215. struct kvm_regs {
  216. /* out (KVM_GET_REGS) / in (KVM_SET_REGS) */
  217. __u64 rax, rbx, rcx, rdx;
  218. __u64 rsi, rdi, rsp, rbp;
  219. __u64 r8, r9, r10, r11;
  220. __u64 r12, r13, r14, r15;
  221. __u64 rip, rflags;
  222. };
  223. 4.12 KVM_SET_REGS
  224. Capability: basic
  225. Architectures: all except ARM, arm64
  226. Type: vcpu ioctl
  227. Parameters: struct kvm_regs (in)
  228. Returns: 0 on success, -1 on error
  229. Writes the general purpose registers into the vcpu.
  230. See KVM_GET_REGS for the data structure.
  231. 4.13 KVM_GET_SREGS
  232. Capability: basic
  233. Architectures: x86, ppc
  234. Type: vcpu ioctl
  235. Parameters: struct kvm_sregs (out)
  236. Returns: 0 on success, -1 on error
  237. Reads special registers from the vcpu.
  238. /* x86 */
  239. struct kvm_sregs {
  240. struct kvm_segment cs, ds, es, fs, gs, ss;
  241. struct kvm_segment tr, ldt;
  242. struct kvm_dtable gdt, idt;
  243. __u64 cr0, cr2, cr3, cr4, cr8;
  244. __u64 efer;
  245. __u64 apic_base;
  246. __u64 interrupt_bitmap[(KVM_NR_INTERRUPTS + 63) / 64];
  247. };
  248. /* ppc -- see arch/powerpc/include/uapi/asm/kvm.h */
  249. interrupt_bitmap is a bitmap of pending external interrupts. At most
  250. one bit may be set. This interrupt has been acknowledged by the APIC
  251. but not yet injected into the cpu core.
  252. 4.14 KVM_SET_SREGS
  253. Capability: basic
  254. Architectures: x86, ppc
  255. Type: vcpu ioctl
  256. Parameters: struct kvm_sregs (in)
  257. Returns: 0 on success, -1 on error
  258. Writes special registers into the vcpu. See KVM_GET_SREGS for the
  259. data structures.
  260. 4.15 KVM_TRANSLATE
  261. Capability: basic
  262. Architectures: x86
  263. Type: vcpu ioctl
  264. Parameters: struct kvm_translation (in/out)
  265. Returns: 0 on success, -1 on error
  266. Translates a virtual address according to the vcpu's current address
  267. translation mode.
  268. struct kvm_translation {
  269. /* in */
  270. __u64 linear_address;
  271. /* out */
  272. __u64 physical_address;
  273. __u8 valid;
  274. __u8 writeable;
  275. __u8 usermode;
  276. __u8 pad[5];
  277. };
  278. 4.16 KVM_INTERRUPT
  279. Capability: basic
  280. Architectures: x86, ppc
  281. Type: vcpu ioctl
  282. Parameters: struct kvm_interrupt (in)
  283. Returns: 0 on success, -1 on error
  284. Queues a hardware interrupt vector to be injected. This is only
  285. useful if in-kernel local APIC or equivalent is not used.
  286. /* for KVM_INTERRUPT */
  287. struct kvm_interrupt {
  288. /* in */
  289. __u32 irq;
  290. };
  291. X86:
  292. Note 'irq' is an interrupt vector, not an interrupt pin or line.
  293. PPC:
  294. Queues an external interrupt to be injected. This ioctl is overleaded
  295. with 3 different irq values:
  296. a) KVM_INTERRUPT_SET
  297. This injects an edge type external interrupt into the guest once it's ready
  298. to receive interrupts. When injected, the interrupt is done.
  299. b) KVM_INTERRUPT_UNSET
  300. This unsets any pending interrupt.
  301. Only available with KVM_CAP_PPC_UNSET_IRQ.
  302. c) KVM_INTERRUPT_SET_LEVEL
  303. This injects a level type external interrupt into the guest context. The
  304. interrupt stays pending until a specific ioctl with KVM_INTERRUPT_UNSET
  305. is triggered.
  306. Only available with KVM_CAP_PPC_IRQ_LEVEL.
  307. Note that any value for 'irq' other than the ones stated above is invalid
  308. and incurs unexpected behavior.
  309. 4.17 KVM_DEBUG_GUEST
  310. Capability: basic
  311. Architectures: none
  312. Type: vcpu ioctl
  313. Parameters: none)
  314. Returns: -1 on error
  315. Support for this has been removed. Use KVM_SET_GUEST_DEBUG instead.
  316. 4.18 KVM_GET_MSRS
  317. Capability: basic
  318. Architectures: x86
  319. Type: vcpu ioctl
  320. Parameters: struct kvm_msrs (in/out)
  321. Returns: 0 on success, -1 on error
  322. Reads model-specific registers from the vcpu. Supported msr indices can
  323. be obtained using KVM_GET_MSR_INDEX_LIST.
  324. struct kvm_msrs {
  325. __u32 nmsrs; /* number of msrs in entries */
  326. __u32 pad;
  327. struct kvm_msr_entry entries[0];
  328. };
  329. struct kvm_msr_entry {
  330. __u32 index;
  331. __u32 reserved;
  332. __u64 data;
  333. };
  334. Application code should set the 'nmsrs' member (which indicates the
  335. size of the entries array) and the 'index' member of each array entry.
  336. kvm will fill in the 'data' member.
  337. 4.19 KVM_SET_MSRS
  338. Capability: basic
  339. Architectures: x86
  340. Type: vcpu ioctl
  341. Parameters: struct kvm_msrs (in)
  342. Returns: 0 on success, -1 on error
  343. Writes model-specific registers to the vcpu. See KVM_GET_MSRS for the
  344. data structures.
  345. Application code should set the 'nmsrs' member (which indicates the
  346. size of the entries array), and the 'index' and 'data' members of each
  347. array entry.
  348. 4.20 KVM_SET_CPUID
  349. Capability: basic
  350. Architectures: x86
  351. Type: vcpu ioctl
  352. Parameters: struct kvm_cpuid (in)
  353. Returns: 0 on success, -1 on error
  354. Defines the vcpu responses to the cpuid instruction. Applications
  355. should use the KVM_SET_CPUID2 ioctl if available.
  356. struct kvm_cpuid_entry {
  357. __u32 function;
  358. __u32 eax;
  359. __u32 ebx;
  360. __u32 ecx;
  361. __u32 edx;
  362. __u32 padding;
  363. };
  364. /* for KVM_SET_CPUID */
  365. struct kvm_cpuid {
  366. __u32 nent;
  367. __u32 padding;
  368. struct kvm_cpuid_entry entries[0];
  369. };
  370. 4.21 KVM_SET_SIGNAL_MASK
  371. Capability: basic
  372. Architectures: x86
  373. Type: vcpu ioctl
  374. Parameters: struct kvm_signal_mask (in)
  375. Returns: 0 on success, -1 on error
  376. Defines which signals are blocked during execution of KVM_RUN. This
  377. signal mask temporarily overrides the threads signal mask. Any
  378. unblocked signal received (except SIGKILL and SIGSTOP, which retain
  379. their traditional behaviour) will cause KVM_RUN to return with -EINTR.
  380. Note the signal will only be delivered if not blocked by the original
  381. signal mask.
  382. /* for KVM_SET_SIGNAL_MASK */
  383. struct kvm_signal_mask {
  384. __u32 len;
  385. __u8 sigset[0];
  386. };
  387. 4.22 KVM_GET_FPU
  388. Capability: basic
  389. Architectures: x86
  390. Type: vcpu ioctl
  391. Parameters: struct kvm_fpu (out)
  392. Returns: 0 on success, -1 on error
  393. Reads the floating point state from the vcpu.
  394. /* for KVM_GET_FPU and KVM_SET_FPU */
  395. struct kvm_fpu {
  396. __u8 fpr[8][16];
  397. __u16 fcw;
  398. __u16 fsw;
  399. __u8 ftwx; /* in fxsave format */
  400. __u8 pad1;
  401. __u16 last_opcode;
  402. __u64 last_ip;
  403. __u64 last_dp;
  404. __u8 xmm[16][16];
  405. __u32 mxcsr;
  406. __u32 pad2;
  407. };
  408. 4.23 KVM_SET_FPU
  409. Capability: basic
  410. Architectures: x86
  411. Type: vcpu ioctl
  412. Parameters: struct kvm_fpu (in)
  413. Returns: 0 on success, -1 on error
  414. Writes the floating point state to the vcpu.
  415. /* for KVM_GET_FPU and KVM_SET_FPU */
  416. struct kvm_fpu {
  417. __u8 fpr[8][16];
  418. __u16 fcw;
  419. __u16 fsw;
  420. __u8 ftwx; /* in fxsave format */
  421. __u8 pad1;
  422. __u16 last_opcode;
  423. __u64 last_ip;
  424. __u64 last_dp;
  425. __u8 xmm[16][16];
  426. __u32 mxcsr;
  427. __u32 pad2;
  428. };
  429. 4.24 KVM_CREATE_IRQCHIP
  430. Capability: KVM_CAP_IRQCHIP
  431. Architectures: x86, ia64, ARM, arm64
  432. Type: vm ioctl
  433. Parameters: none
  434. Returns: 0 on success, -1 on error
  435. Creates an interrupt controller model in the kernel. On x86, creates a virtual
  436. ioapic, a virtual PIC (two PICs, nested), and sets up future vcpus to have a
  437. local APIC. IRQ routing for GSIs 0-15 is set to both PIC and IOAPIC; GSI 16-23
  438. only go to the IOAPIC. On ia64, a IOSAPIC is created. On ARM/arm64, a GIC is
  439. created.
  440. 4.25 KVM_IRQ_LINE
  441. Capability: KVM_CAP_IRQCHIP
  442. Architectures: x86, ia64, arm, arm64
  443. Type: vm ioctl
  444. Parameters: struct kvm_irq_level
  445. Returns: 0 on success, -1 on error
  446. Sets the level of a GSI input to the interrupt controller model in the kernel.
  447. On some architectures it is required that an interrupt controller model has
  448. been previously created with KVM_CREATE_IRQCHIP. Note that edge-triggered
  449. interrupts require the level to be set to 1 and then back to 0.
  450. ARM/arm64 can signal an interrupt either at the CPU level, or at the
  451. in-kernel irqchip (GIC), and for in-kernel irqchip can tell the GIC to
  452. use PPIs designated for specific cpus. The irq field is interpreted
  453. like this:
  454.  bits: | 31 ... 24 | 23 ... 16 | 15 ... 0 |
  455. field: | irq_type | vcpu_index | irq_id |
  456. The irq_type field has the following values:
  457. - irq_type[0]: out-of-kernel GIC: irq_id 0 is IRQ, irq_id 1 is FIQ
  458. - irq_type[1]: in-kernel GIC: SPI, irq_id between 32 and 1019 (incl.)
  459. (the vcpu_index field is ignored)
  460. - irq_type[2]: in-kernel GIC: PPI, irq_id between 16 and 31 (incl.)
  461. (The irq_id field thus corresponds nicely to the IRQ ID in the ARM GIC specs)
  462. In both cases, level is used to raise/lower the line.
  463. struct kvm_irq_level {
  464. union {
  465. __u32 irq; /* GSI */
  466. __s32 status; /* not used for KVM_IRQ_LEVEL */
  467. };
  468. __u32 level; /* 0 or 1 */
  469. };
  470. 4.26 KVM_GET_IRQCHIP
  471. Capability: KVM_CAP_IRQCHIP
  472. Architectures: x86, ia64
  473. Type: vm ioctl
  474. Parameters: struct kvm_irqchip (in/out)
  475. Returns: 0 on success, -1 on error
  476. Reads the state of a kernel interrupt controller created with
  477. KVM_CREATE_IRQCHIP into a buffer provided by the caller.
  478. struct kvm_irqchip {
  479. __u32 chip_id; /* 0 = PIC1, 1 = PIC2, 2 = IOAPIC */
  480. __u32 pad;
  481. union {
  482. char dummy[512]; /* reserving space */
  483. struct kvm_pic_state pic;
  484. struct kvm_ioapic_state ioapic;
  485. } chip;
  486. };
  487. 4.27 KVM_SET_IRQCHIP
  488. Capability: KVM_CAP_IRQCHIP
  489. Architectures: x86, ia64
  490. Type: vm ioctl
  491. Parameters: struct kvm_irqchip (in)
  492. Returns: 0 on success, -1 on error
  493. Sets the state of a kernel interrupt controller created with
  494. KVM_CREATE_IRQCHIP from a buffer provided by the caller.
  495. struct kvm_irqchip {
  496. __u32 chip_id; /* 0 = PIC1, 1 = PIC2, 2 = IOAPIC */
  497. __u32 pad;
  498. union {
  499. char dummy[512]; /* reserving space */
  500. struct kvm_pic_state pic;
  501. struct kvm_ioapic_state ioapic;
  502. } chip;
  503. };
  504. 4.28 KVM_XEN_HVM_CONFIG
  505. Capability: KVM_CAP_XEN_HVM
  506. Architectures: x86
  507. Type: vm ioctl
  508. Parameters: struct kvm_xen_hvm_config (in)
  509. Returns: 0 on success, -1 on error
  510. Sets the MSR that the Xen HVM guest uses to initialize its hypercall
  511. page, and provides the starting address and size of the hypercall
  512. blobs in userspace. When the guest writes the MSR, kvm copies one
  513. page of a blob (32- or 64-bit, depending on the vcpu mode) to guest
  514. memory.
  515. struct kvm_xen_hvm_config {
  516. __u32 flags;
  517. __u32 msr;
  518. __u64 blob_addr_32;
  519. __u64 blob_addr_64;
  520. __u8 blob_size_32;
  521. __u8 blob_size_64;
  522. __u8 pad2[30];
  523. };
  524. 4.29 KVM_GET_CLOCK
  525. Capability: KVM_CAP_ADJUST_CLOCK
  526. Architectures: x86
  527. Type: vm ioctl
  528. Parameters: struct kvm_clock_data (out)
  529. Returns: 0 on success, -1 on error
  530. Gets the current timestamp of kvmclock as seen by the current guest. In
  531. conjunction with KVM_SET_CLOCK, it is used to ensure monotonicity on scenarios
  532. such as migration.
  533. struct kvm_clock_data {
  534. __u64 clock; /* kvmclock current value */
  535. __u32 flags;
  536. __u32 pad[9];
  537. };
  538. 4.30 KVM_SET_CLOCK
  539. Capability: KVM_CAP_ADJUST_CLOCK
  540. Architectures: x86
  541. Type: vm ioctl
  542. Parameters: struct kvm_clock_data (in)
  543. Returns: 0 on success, -1 on error
  544. Sets the current timestamp of kvmclock to the value specified in its parameter.
  545. In conjunction with KVM_GET_CLOCK, it is used to ensure monotonicity on scenarios
  546. such as migration.
  547. struct kvm_clock_data {
  548. __u64 clock; /* kvmclock current value */
  549. __u32 flags;
  550. __u32 pad[9];
  551. };
  552. 4.31 KVM_GET_VCPU_EVENTS
  553. Capability: KVM_CAP_VCPU_EVENTS
  554. Extended by: KVM_CAP_INTR_SHADOW
  555. Architectures: x86
  556. Type: vm ioctl
  557. Parameters: struct kvm_vcpu_event (out)
  558. Returns: 0 on success, -1 on error
  559. Gets currently pending exceptions, interrupts, and NMIs as well as related
  560. states of the vcpu.
  561. struct kvm_vcpu_events {
  562. struct {
  563. __u8 injected;
  564. __u8 nr;
  565. __u8 has_error_code;
  566. __u8 pad;
  567. __u32 error_code;
  568. } exception;
  569. struct {
  570. __u8 injected;
  571. __u8 nr;
  572. __u8 soft;
  573. __u8 shadow;
  574. } interrupt;
  575. struct {
  576. __u8 injected;
  577. __u8 pending;
  578. __u8 masked;
  579. __u8 pad;
  580. } nmi;
  581. __u32 sipi_vector;
  582. __u32 flags;
  583. };
  584. KVM_VCPUEVENT_VALID_SHADOW may be set in the flags field to signal that
  585. interrupt.shadow contains a valid state. Otherwise, this field is undefined.
  586. 4.32 KVM_SET_VCPU_EVENTS
  587. Capability: KVM_CAP_VCPU_EVENTS
  588. Extended by: KVM_CAP_INTR_SHADOW
  589. Architectures: x86
  590. Type: vm ioctl
  591. Parameters: struct kvm_vcpu_event (in)
  592. Returns: 0 on success, -1 on error
  593. Set pending exceptions, interrupts, and NMIs as well as related states of the
  594. vcpu.
  595. See KVM_GET_VCPU_EVENTS for the data structure.
  596. Fields that may be modified asynchronously by running VCPUs can be excluded
  597. from the update. These fields are nmi.pending and sipi_vector. Keep the
  598. corresponding bits in the flags field cleared to suppress overwriting the
  599. current in-kernel state. The bits are:
  600. KVM_VCPUEVENT_VALID_NMI_PENDING - transfer nmi.pending to the kernel
  601. KVM_VCPUEVENT_VALID_SIPI_VECTOR - transfer sipi_vector
  602. If KVM_CAP_INTR_SHADOW is available, KVM_VCPUEVENT_VALID_SHADOW can be set in
  603. the flags field to signal that interrupt.shadow contains a valid state and
  604. shall be written into the VCPU.
  605. 4.33 KVM_GET_DEBUGREGS
  606. Capability: KVM_CAP_DEBUGREGS
  607. Architectures: x86
  608. Type: vm ioctl
  609. Parameters: struct kvm_debugregs (out)
  610. Returns: 0 on success, -1 on error
  611. Reads debug registers from the vcpu.
  612. struct kvm_debugregs {
  613. __u64 db[4];
  614. __u64 dr6;
  615. __u64 dr7;
  616. __u64 flags;
  617. __u64 reserved[9];
  618. };
  619. 4.34 KVM_SET_DEBUGREGS
  620. Capability: KVM_CAP_DEBUGREGS
  621. Architectures: x86
  622. Type: vm ioctl
  623. Parameters: struct kvm_debugregs (in)
  624. Returns: 0 on success, -1 on error
  625. Writes debug registers into the vcpu.
  626. See KVM_GET_DEBUGREGS for the data structure. The flags field is unused
  627. yet and must be cleared on entry.
  628. 4.35 KVM_SET_USER_MEMORY_REGION
  629. Capability: KVM_CAP_USER_MEM
  630. Architectures: all
  631. Type: vm ioctl
  632. Parameters: struct kvm_userspace_memory_region (in)
  633. Returns: 0 on success, -1 on error
  634. struct kvm_userspace_memory_region {
  635. __u32 slot;
  636. __u32 flags;
  637. __u64 guest_phys_addr;
  638. __u64 memory_size; /* bytes */
  639. __u64 userspace_addr; /* start of the userspace allocated memory */
  640. };
  641. /* for kvm_memory_region::flags */
  642. #define KVM_MEM_LOG_DIRTY_PAGES (1UL << 0)
  643. #define KVM_MEM_READONLY (1UL << 1)
  644. This ioctl allows the user to create or modify a guest physical memory
  645. slot. When changing an existing slot, it may be moved in the guest
  646. physical memory space, or its flags may be modified. It may not be
  647. resized. Slots may not overlap in guest physical address space.
  648. Memory for the region is taken starting at the address denoted by the
  649. field userspace_addr, which must point at user addressable memory for
  650. the entire memory slot size. Any object may back this memory, including
  651. anonymous memory, ordinary files, and hugetlbfs.
  652. It is recommended that the lower 21 bits of guest_phys_addr and userspace_addr
  653. be identical. This allows large pages in the guest to be backed by large
  654. pages in the host.
  655. The flags field supports two flags: KVM_MEM_LOG_DIRTY_PAGES and
  656. KVM_MEM_READONLY. The former can be set to instruct KVM to keep track of
  657. writes to memory within the slot. See KVM_GET_DIRTY_LOG ioctl to know how to
  658. use it. The latter can be set, if KVM_CAP_READONLY_MEM capability allows it,
  659. to make a new slot read-only. In this case, writes to this memory will be
  660. posted to userspace as KVM_EXIT_MMIO exits.
  661. When the KVM_CAP_SYNC_MMU capability is available, changes in the backing of
  662. the memory region are automatically reflected into the guest. For example, an
  663. mmap() that affects the region will be made visible immediately. Another
  664. example is madvise(MADV_DROP).
  665. It is recommended to use this API instead of the KVM_SET_MEMORY_REGION ioctl.
  666. The KVM_SET_MEMORY_REGION does not allow fine grained control over memory
  667. allocation and is deprecated.
  668. 4.36 KVM_SET_TSS_ADDR
  669. Capability: KVM_CAP_SET_TSS_ADDR
  670. Architectures: x86
  671. Type: vm ioctl
  672. Parameters: unsigned long tss_address (in)
  673. Returns: 0 on success, -1 on error
  674. This ioctl defines the physical address of a three-page region in the guest
  675. physical address space. The region must be within the first 4GB of the
  676. guest physical address space and must not conflict with any memory slot
  677. or any mmio address. The guest may malfunction if it accesses this memory
  678. region.
  679. This ioctl is required on Intel-based hosts. This is needed on Intel hardware
  680. because of a quirk in the virtualization implementation (see the internals
  681. documentation when it pops into existence).
  682. 4.37 KVM_ENABLE_CAP
  683. Capability: KVM_CAP_ENABLE_CAP
  684. Architectures: ppc, s390
  685. Type: vcpu ioctl
  686. Parameters: struct kvm_enable_cap (in)
  687. Returns: 0 on success; -1 on error
  688. +Not all extensions are enabled by default. Using this ioctl the application
  689. can enable an extension, making it available to the guest.
  690. On systems that do not support this ioctl, it always fails. On systems that
  691. do support it, it only works for extensions that are supported for enablement.
  692. To check if a capability can be enabled, the KVM_CHECK_EXTENSION ioctl should
  693. be used.
  694. struct kvm_enable_cap {
  695. /* in */
  696. __u32 cap;
  697. The capability that is supposed to get enabled.
  698. __u32 flags;
  699. A bitfield indicating future enhancements. Has to be 0 for now.
  700. __u64 args[4];
  701. Arguments for enabling a feature. If a feature needs initial values to
  702. function properly, this is the place to put them.
  703. __u8 pad[64];
  704. };
  705. 4.38 KVM_GET_MP_STATE
  706. Capability: KVM_CAP_MP_STATE
  707. Architectures: x86, ia64
  708. Type: vcpu ioctl
  709. Parameters: struct kvm_mp_state (out)
  710. Returns: 0 on success; -1 on error
  711. struct kvm_mp_state {
  712. __u32 mp_state;
  713. };
  714. Returns the vcpu's current "multiprocessing state" (though also valid on
  715. uniprocessor guests).
  716. Possible values are:
  717. - KVM_MP_STATE_RUNNABLE: the vcpu is currently running
  718. - KVM_MP_STATE_UNINITIALIZED: the vcpu is an application processor (AP)
  719. which has not yet received an INIT signal
  720. - KVM_MP_STATE_INIT_RECEIVED: the vcpu has received an INIT signal, and is
  721. now ready for a SIPI
  722. - KVM_MP_STATE_HALTED: the vcpu has executed a HLT instruction and
  723. is waiting for an interrupt
  724. - KVM_MP_STATE_SIPI_RECEIVED: the vcpu has just received a SIPI (vector
  725. accessible via KVM_GET_VCPU_EVENTS)
  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.39 KVM_SET_MP_STATE
  729. Capability: KVM_CAP_MP_STATE
  730. Architectures: x86, ia64
  731. Type: vcpu ioctl
  732. Parameters: struct kvm_mp_state (in)
  733. Returns: 0 on success; -1 on error
  734. Sets the vcpu's current "multiprocessing state"; see KVM_GET_MP_STATE for
  735. arguments.
  736. This ioctl is only useful after KVM_CREATE_IRQCHIP. Without an in-kernel
  737. irqchip, the multiprocessing state must be maintained by userspace.
  738. 4.40 KVM_SET_IDENTITY_MAP_ADDR
  739. Capability: KVM_CAP_SET_IDENTITY_MAP_ADDR
  740. Architectures: x86
  741. Type: vm ioctl
  742. Parameters: unsigned long identity (in)
  743. Returns: 0 on success, -1 on error
  744. This ioctl defines the physical address of a one-page region in the guest
  745. physical address space. The region must be within the first 4GB of the
  746. guest physical address space and must not conflict with any memory slot
  747. or any mmio address. The guest may malfunction if it accesses this memory
  748. region.
  749. This ioctl is required on Intel-based hosts. This is needed on Intel hardware
  750. because of a quirk in the virtualization implementation (see the internals
  751. documentation when it pops into existence).
  752. 4.41 KVM_SET_BOOT_CPU_ID
  753. Capability: KVM_CAP_SET_BOOT_CPU_ID
  754. Architectures: x86, ia64
  755. Type: vm ioctl
  756. Parameters: unsigned long vcpu_id
  757. Returns: 0 on success, -1 on error
  758. Define which vcpu is the Bootstrap Processor (BSP). Values are the same
  759. as the vcpu id in KVM_CREATE_VCPU. If this ioctl is not called, the default
  760. is vcpu 0.
  761. 4.42 KVM_GET_XSAVE
  762. Capability: KVM_CAP_XSAVE
  763. Architectures: x86
  764. Type: vcpu ioctl
  765. Parameters: struct kvm_xsave (out)
  766. Returns: 0 on success, -1 on error
  767. struct kvm_xsave {
  768. __u32 region[1024];
  769. };
  770. This ioctl would copy current vcpu's xsave struct to the userspace.
  771. 4.43 KVM_SET_XSAVE
  772. Capability: KVM_CAP_XSAVE
  773. Architectures: x86
  774. Type: vcpu ioctl
  775. Parameters: struct kvm_xsave (in)
  776. Returns: 0 on success, -1 on error
  777. struct kvm_xsave {
  778. __u32 region[1024];
  779. };
  780. This ioctl would copy userspace's xsave struct to the kernel.
  781. 4.44 KVM_GET_XCRS
  782. Capability: KVM_CAP_XCRS
  783. Architectures: x86
  784. Type: vcpu ioctl
  785. Parameters: struct kvm_xcrs (out)
  786. Returns: 0 on success, -1 on error
  787. struct kvm_xcr {
  788. __u32 xcr;
  789. __u32 reserved;
  790. __u64 value;
  791. };
  792. struct kvm_xcrs {
  793. __u32 nr_xcrs;
  794. __u32 flags;
  795. struct kvm_xcr xcrs[KVM_MAX_XCRS];
  796. __u64 padding[16];
  797. };
  798. This ioctl would copy current vcpu's xcrs to the userspace.
  799. 4.45 KVM_SET_XCRS
  800. Capability: KVM_CAP_XCRS
  801. Architectures: x86
  802. Type: vcpu ioctl
  803. Parameters: struct kvm_xcrs (in)
  804. Returns: 0 on success, -1 on error
  805. struct kvm_xcr {
  806. __u32 xcr;
  807. __u32 reserved;
  808. __u64 value;
  809. };
  810. struct kvm_xcrs {
  811. __u32 nr_xcrs;
  812. __u32 flags;
  813. struct kvm_xcr xcrs[KVM_MAX_XCRS];
  814. __u64 padding[16];
  815. };
  816. This ioctl would set vcpu's xcr to the value userspace specified.
  817. 4.46 KVM_GET_SUPPORTED_CPUID
  818. Capability: KVM_CAP_EXT_CPUID
  819. Architectures: x86
  820. Type: system ioctl
  821. Parameters: struct kvm_cpuid2 (in/out)
  822. Returns: 0 on success, -1 on error
  823. struct kvm_cpuid2 {
  824. __u32 nent;
  825. __u32 padding;
  826. struct kvm_cpuid_entry2 entries[0];
  827. };
  828. #define KVM_CPUID_FLAG_SIGNIFCANT_INDEX 1
  829. #define KVM_CPUID_FLAG_STATEFUL_FUNC 2
  830. #define KVM_CPUID_FLAG_STATE_READ_NEXT 4
  831. struct kvm_cpuid_entry2 {
  832. __u32 function;
  833. __u32 index;
  834. __u32 flags;
  835. __u32 eax;
  836. __u32 ebx;
  837. __u32 ecx;
  838. __u32 edx;
  839. __u32 padding[3];
  840. };
  841. This ioctl returns x86 cpuid features which are supported by both the hardware
  842. and kvm. Userspace can use the information returned by this ioctl to
  843. construct cpuid information (for KVM_SET_CPUID2) that is consistent with
  844. hardware, kernel, and userspace capabilities, and with user requirements (for
  845. example, the user may wish to constrain cpuid to emulate older hardware,
  846. or for feature consistency across a cluster).
  847. Userspace invokes KVM_GET_SUPPORTED_CPUID by passing a kvm_cpuid2 structure
  848. with the 'nent' field indicating the number of entries in the variable-size
  849. array 'entries'. If the number of entries is too low to describe the cpu
  850. capabilities, an error (E2BIG) is returned. If the number is too high,
  851. the 'nent' field is adjusted and an error (ENOMEM) is returned. If the
  852. number is just right, the 'nent' field is adjusted to the number of valid
  853. entries in the 'entries' array, which is then filled.
  854. The entries returned are the host cpuid as returned by the cpuid instruction,
  855. with unknown or unsupported features masked out. Some features (for example,
  856. x2apic), may not be present in the host cpu, but are exposed by kvm if it can
  857. emulate them efficiently. The fields in each entry are defined as follows:
  858. function: the eax value used to obtain the entry
  859. index: the ecx value used to obtain the entry (for entries that are
  860. affected by ecx)
  861. flags: an OR of zero or more of the following:
  862. KVM_CPUID_FLAG_SIGNIFCANT_INDEX:
  863. if the index field is valid
  864. KVM_CPUID_FLAG_STATEFUL_FUNC:
  865. if cpuid for this function returns different values for successive
  866. invocations; there will be several entries with the same function,
  867. all with this flag set
  868. KVM_CPUID_FLAG_STATE_READ_NEXT:
  869. for KVM_CPUID_FLAG_STATEFUL_FUNC entries, set if this entry is
  870. the first entry to be read by a cpu
  871. eax, ebx, ecx, edx: the values returned by the cpuid instruction for
  872. this function/index combination
  873. The TSC deadline timer feature (CPUID leaf 1, ecx[24]) is always returned
  874. as false, since the feature depends on KVM_CREATE_IRQCHIP for local APIC
  875. support. Instead it is reported via
  876. ioctl(KVM_CHECK_EXTENSION, KVM_CAP_TSC_DEADLINE_TIMER)
  877. if that returns true and you use KVM_CREATE_IRQCHIP, or if you emulate the
  878. feature in userspace, then you can enable the feature for KVM_SET_CPUID2.
  879. 4.47 KVM_PPC_GET_PVINFO
  880. Capability: KVM_CAP_PPC_GET_PVINFO
  881. Architectures: ppc
  882. Type: vm ioctl
  883. Parameters: struct kvm_ppc_pvinfo (out)
  884. Returns: 0 on success, !0 on error
  885. struct kvm_ppc_pvinfo {
  886. __u32 flags;
  887. __u32 hcall[4];
  888. __u8 pad[108];
  889. };
  890. This ioctl fetches PV specific information that need to be passed to the guest
  891. using the device tree or other means from vm context.
  892. The hcall array defines 4 instructions that make up a hypercall.
  893. If any additional field gets added to this structure later on, a bit for that
  894. additional piece of information will be set in the flags bitmap.
  895. The flags bitmap is defined as:
  896. /* the host supports the ePAPR idle hcall
  897. #define KVM_PPC_PVINFO_FLAGS_EV_IDLE (1<<0)
  898. 4.48 KVM_ASSIGN_PCI_DEVICE
  899. Capability: KVM_CAP_DEVICE_ASSIGNMENT
  900. Architectures: x86 ia64
  901. Type: vm ioctl
  902. Parameters: struct kvm_assigned_pci_dev (in)
  903. Returns: 0 on success, -1 on error
  904. Assigns a host PCI device to the VM.
  905. struct kvm_assigned_pci_dev {
  906. __u32 assigned_dev_id;
  907. __u32 busnr;
  908. __u32 devfn;
  909. __u32 flags;
  910. __u32 segnr;
  911. union {
  912. __u32 reserved[11];
  913. };
  914. };
  915. The PCI device is specified by the triple segnr, busnr, and devfn.
  916. Identification in succeeding service requests is done via assigned_dev_id. The
  917. following flags are specified:
  918. /* Depends on KVM_CAP_IOMMU */
  919. #define KVM_DEV_ASSIGN_ENABLE_IOMMU (1 << 0)
  920. /* The following two depend on KVM_CAP_PCI_2_3 */
  921. #define KVM_DEV_ASSIGN_PCI_2_3 (1 << 1)
  922. #define KVM_DEV_ASSIGN_MASK_INTX (1 << 2)
  923. If KVM_DEV_ASSIGN_PCI_2_3 is set, the kernel will manage legacy INTx interrupts
  924. via the PCI-2.3-compliant device-level mask, thus enable IRQ sharing with other
  925. assigned devices or host devices. KVM_DEV_ASSIGN_MASK_INTX specifies the
  926. guest's view on the INTx mask, see KVM_ASSIGN_SET_INTX_MASK for details.
  927. The KVM_DEV_ASSIGN_ENABLE_IOMMU flag is a mandatory option to ensure
  928. isolation of the device. Usages not specifying this flag are deprecated.
  929. Only PCI header type 0 devices with PCI BAR resources are supported by
  930. device assignment. The user requesting this ioctl must have read/write
  931. access to the PCI sysfs resource files associated with the device.
  932. 4.49 KVM_DEASSIGN_PCI_DEVICE
  933. Capability: KVM_CAP_DEVICE_DEASSIGNMENT
  934. Architectures: x86 ia64
  935. Type: vm ioctl
  936. Parameters: struct kvm_assigned_pci_dev (in)
  937. Returns: 0 on success, -1 on error
  938. Ends PCI device assignment, releasing all associated resources.
  939. See KVM_CAP_DEVICE_ASSIGNMENT for the data structure. Only assigned_dev_id is
  940. used in kvm_assigned_pci_dev to identify the device.
  941. 4.50 KVM_ASSIGN_DEV_IRQ
  942. Capability: KVM_CAP_ASSIGN_DEV_IRQ
  943. Architectures: x86 ia64
  944. Type: vm ioctl
  945. Parameters: struct kvm_assigned_irq (in)
  946. Returns: 0 on success, -1 on error
  947. Assigns an IRQ to a passed-through device.
  948. struct kvm_assigned_irq {
  949. __u32 assigned_dev_id;
  950. __u32 host_irq; /* ignored (legacy field) */
  951. __u32 guest_irq;
  952. __u32 flags;
  953. union {
  954. __u32 reserved[12];
  955. };
  956. };
  957. The following flags are defined:
  958. #define KVM_DEV_IRQ_HOST_INTX (1 << 0)
  959. #define KVM_DEV_IRQ_HOST_MSI (1 << 1)
  960. #define KVM_DEV_IRQ_HOST_MSIX (1 << 2)
  961. #define KVM_DEV_IRQ_GUEST_INTX (1 << 8)
  962. #define KVM_DEV_IRQ_GUEST_MSI (1 << 9)
  963. #define KVM_DEV_IRQ_GUEST_MSIX (1 << 10)
  964. It is not valid to specify multiple types per host or guest IRQ. However, the
  965. IRQ type of host and guest can differ or can even be null.
  966. 4.51 KVM_DEASSIGN_DEV_IRQ
  967. Capability: KVM_CAP_ASSIGN_DEV_IRQ
  968. Architectures: x86 ia64
  969. Type: vm ioctl
  970. Parameters: struct kvm_assigned_irq (in)
  971. Returns: 0 on success, -1 on error
  972. Ends an IRQ assignment to a passed-through device.
  973. See KVM_ASSIGN_DEV_IRQ for the data structure. The target device is specified
  974. by assigned_dev_id, flags must correspond to the IRQ type specified on
  975. KVM_ASSIGN_DEV_IRQ. Partial deassignment of host or guest IRQ is allowed.
  976. 4.52 KVM_SET_GSI_ROUTING
  977. Capability: KVM_CAP_IRQ_ROUTING
  978. Architectures: x86 ia64
  979. Type: vm ioctl
  980. Parameters: struct kvm_irq_routing (in)
  981. Returns: 0 on success, -1 on error
  982. Sets the GSI routing table entries, overwriting any previously set entries.
  983. struct kvm_irq_routing {
  984. __u32 nr;
  985. __u32 flags;
  986. struct kvm_irq_routing_entry entries[0];
  987. };
  988. No flags are specified so far, the corresponding field must be set to zero.
  989. struct kvm_irq_routing_entry {
  990. __u32 gsi;
  991. __u32 type;
  992. __u32 flags;
  993. __u32 pad;
  994. union {
  995. struct kvm_irq_routing_irqchip irqchip;
  996. struct kvm_irq_routing_msi msi;
  997. __u32 pad[8];
  998. } u;
  999. };
  1000. /* gsi routing entry types */
  1001. #define KVM_IRQ_ROUTING_IRQCHIP 1
  1002. #define KVM_IRQ_ROUTING_MSI 2
  1003. No flags are specified so far, the corresponding field must be set to zero.
  1004. struct kvm_irq_routing_irqchip {
  1005. __u32 irqchip;
  1006. __u32 pin;
  1007. };
  1008. struct kvm_irq_routing_msi {
  1009. __u32 address_lo;
  1010. __u32 address_hi;
  1011. __u32 data;
  1012. __u32 pad;
  1013. };
  1014. 4.53 KVM_ASSIGN_SET_MSIX_NR
  1015. Capability: KVM_CAP_DEVICE_MSIX
  1016. Architectures: x86 ia64
  1017. Type: vm ioctl
  1018. Parameters: struct kvm_assigned_msix_nr (in)
  1019. Returns: 0 on success, -1 on error
  1020. Set the number of MSI-X interrupts for an assigned device. The number is
  1021. reset again by terminating the MSI-X assignment of the device via
  1022. KVM_DEASSIGN_DEV_IRQ. Calling this service more than once at any earlier
  1023. point will fail.
  1024. struct kvm_assigned_msix_nr {
  1025. __u32 assigned_dev_id;
  1026. __u16 entry_nr;
  1027. __u16 padding;
  1028. };
  1029. #define KVM_MAX_MSIX_PER_DEV 256
  1030. 4.54 KVM_ASSIGN_SET_MSIX_ENTRY
  1031. Capability: KVM_CAP_DEVICE_MSIX
  1032. Architectures: x86 ia64
  1033. Type: vm ioctl
  1034. Parameters: struct kvm_assigned_msix_entry (in)
  1035. Returns: 0 on success, -1 on error
  1036. Specifies the routing of an MSI-X assigned device interrupt to a GSI. Setting
  1037. the GSI vector to zero means disabling the interrupt.
  1038. struct kvm_assigned_msix_entry {
  1039. __u32 assigned_dev_id;
  1040. __u32 gsi;
  1041. __u16 entry; /* The index of entry in the MSI-X table */
  1042. __u16 padding[3];
  1043. };
  1044. 4.55 KVM_SET_TSC_KHZ
  1045. Capability: KVM_CAP_TSC_CONTROL
  1046. Architectures: x86
  1047. Type: vcpu ioctl
  1048. Parameters: virtual tsc_khz
  1049. Returns: 0 on success, -1 on error
  1050. Specifies the tsc frequency for the virtual machine. The unit of the
  1051. frequency is KHz.
  1052. 4.56 KVM_GET_TSC_KHZ
  1053. Capability: KVM_CAP_GET_TSC_KHZ
  1054. Architectures: x86
  1055. Type: vcpu ioctl
  1056. Parameters: none
  1057. Returns: virtual tsc-khz on success, negative value on error
  1058. Returns the tsc frequency of the guest. The unit of the return value is
  1059. KHz. If the host has unstable tsc this ioctl returns -EIO instead as an
  1060. error.
  1061. 4.57 KVM_GET_LAPIC
  1062. Capability: KVM_CAP_IRQCHIP
  1063. Architectures: x86
  1064. Type: vcpu ioctl
  1065. Parameters: struct kvm_lapic_state (out)
  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. Reads the Local APIC registers and copies them into the input argument. The
  1072. data format and layout are the same as documented in the architecture manual.
  1073. 4.58 KVM_SET_LAPIC
  1074. Capability: KVM_CAP_IRQCHIP
  1075. Architectures: x86
  1076. Type: vcpu ioctl
  1077. Parameters: struct kvm_lapic_state (in)
  1078. Returns: 0 on success, -1 on error
  1079. #define KVM_APIC_REG_SIZE 0x400
  1080. struct kvm_lapic_state {
  1081. char regs[KVM_APIC_REG_SIZE];
  1082. };
  1083. Copies the input argument into the the Local APIC registers. The data format
  1084. and layout are the same as documented in the architecture manual.
  1085. 4.59 KVM_IOEVENTFD
  1086. Capability: KVM_CAP_IOEVENTFD
  1087. Architectures: all
  1088. Type: vm ioctl
  1089. Parameters: struct kvm_ioeventfd (in)
  1090. Returns: 0 on success, !0 on error
  1091. This ioctl attaches or detaches an ioeventfd to a legal pio/mmio address
  1092. within the guest. A guest write in the registered address will signal the
  1093. provided event instead of triggering an exit.
  1094. struct kvm_ioeventfd {
  1095. __u64 datamatch;
  1096. __u64 addr; /* legal pio/mmio address */
  1097. __u32 len; /* 1, 2, 4, or 8 bytes */
  1098. __s32 fd;
  1099. __u32 flags;
  1100. __u8 pad[36];
  1101. };
  1102. For the special case of virtio-ccw devices on s390, the ioevent is matched
  1103. to a subchannel/virtqueue tuple instead.
  1104. The following flags are defined:
  1105. #define KVM_IOEVENTFD_FLAG_DATAMATCH (1 << kvm_ioeventfd_flag_nr_datamatch)
  1106. #define KVM_IOEVENTFD_FLAG_PIO (1 << kvm_ioeventfd_flag_nr_pio)
  1107. #define KVM_IOEVENTFD_FLAG_DEASSIGN (1 << kvm_ioeventfd_flag_nr_deassign)
  1108. #define KVM_IOEVENTFD_FLAG_VIRTIO_CCW_NOTIFY \
  1109. (1 << kvm_ioeventfd_flag_nr_virtio_ccw_notify)
  1110. If datamatch flag is set, the event will be signaled only if the written value
  1111. to the registered address is equal to datamatch in struct kvm_ioeventfd.
  1112. For virtio-ccw devices, addr contains the subchannel id and datamatch the
  1113. virtqueue index.
  1114. 4.60 KVM_DIRTY_TLB
  1115. Capability: KVM_CAP_SW_TLB
  1116. Architectures: ppc
  1117. Type: vcpu ioctl
  1118. Parameters: struct kvm_dirty_tlb (in)
  1119. Returns: 0 on success, -1 on error
  1120. struct kvm_dirty_tlb {
  1121. __u64 bitmap;
  1122. __u32 num_dirty;
  1123. };
  1124. This must be called whenever userspace has changed an entry in the shared
  1125. TLB, prior to calling KVM_RUN on the associated vcpu.
  1126. The "bitmap" field is the userspace address of an array. This array
  1127. consists of a number of bits, equal to the total number of TLB entries as
  1128. determined by the last successful call to KVM_CONFIG_TLB, rounded up to the
  1129. nearest multiple of 64.
  1130. Each bit corresponds to one TLB entry, ordered the same as in the shared TLB
  1131. array.
  1132. The array is little-endian: the bit 0 is the least significant bit of the
  1133. first byte, bit 8 is the least significant bit of the second byte, etc.
  1134. This avoids any complications with differing word sizes.
  1135. The "num_dirty" field is a performance hint for KVM to determine whether it
  1136. should skip processing the bitmap and just invalidate everything. It must
  1137. be set to the number of set bits in the bitmap.
  1138. 4.61 KVM_ASSIGN_SET_INTX_MASK
  1139. Capability: KVM_CAP_PCI_2_3
  1140. Architectures: x86
  1141. Type: vm ioctl
  1142. Parameters: struct kvm_assigned_pci_dev (in)
  1143. Returns: 0 on success, -1 on error
  1144. Allows userspace to mask PCI INTx interrupts from the assigned device. The
  1145. kernel will not deliver INTx interrupts to the guest between setting and
  1146. clearing of KVM_ASSIGN_SET_INTX_MASK via this interface. This enables use of
  1147. and emulation of PCI 2.3 INTx disable command register behavior.
  1148. This may be used for both PCI 2.3 devices supporting INTx disable natively and
  1149. older devices lacking this support. Userspace is responsible for emulating the
  1150. read value of the INTx disable bit in the guest visible PCI command register.
  1151. When modifying the INTx disable state, userspace should precede updating the
  1152. physical device command register by calling this ioctl to inform the kernel of
  1153. the new intended INTx mask state.
  1154. Note that the kernel uses the device INTx disable bit to internally manage the
  1155. device interrupt state for PCI 2.3 devices. Reads of this register may
  1156. therefore not match the expected value. Writes should always use the guest
  1157. intended INTx disable value rather than attempting to read-copy-update the
  1158. current physical device state. Races between user and kernel updates to the
  1159. INTx disable bit are handled lazily in the kernel. It's possible the device
  1160. may generate unintended interrupts, but they will not be injected into the
  1161. guest.
  1162. See KVM_ASSIGN_DEV_IRQ for the data structure. The target device is specified
  1163. by assigned_dev_id. In the flags field, only KVM_DEV_ASSIGN_MASK_INTX is
  1164. evaluated.
  1165. 4.62 KVM_CREATE_SPAPR_TCE
  1166. Capability: KVM_CAP_SPAPR_TCE
  1167. Architectures: powerpc
  1168. Type: vm ioctl
  1169. Parameters: struct kvm_create_spapr_tce (in)
  1170. Returns: file descriptor for manipulating the created TCE table
  1171. This creates a virtual TCE (translation control entry) table, which
  1172. is an IOMMU for PAPR-style virtual I/O. It is used to translate
  1173. logical addresses used in virtual I/O into guest physical addresses,
  1174. and provides a scatter/gather capability for PAPR virtual I/O.
  1175. /* for KVM_CAP_SPAPR_TCE */
  1176. struct kvm_create_spapr_tce {
  1177. __u64 liobn;
  1178. __u32 window_size;
  1179. };
  1180. The liobn field gives the logical IO bus number for which to create a
  1181. TCE table. The window_size field specifies the size of the DMA window
  1182. which this TCE table will translate - the table will contain one 64
  1183. bit TCE entry for every 4kiB of the DMA window.
  1184. When the guest issues an H_PUT_TCE hcall on a liobn for which a TCE
  1185. table has been created using this ioctl(), the kernel will handle it
  1186. in real mode, updating the TCE table. H_PUT_TCE calls for other
  1187. liobns will cause a vm exit and must be handled by userspace.
  1188. The return value is a file descriptor which can be passed to mmap(2)
  1189. to map the created TCE table into userspace. This lets userspace read
  1190. the entries written by kernel-handled H_PUT_TCE calls, and also lets
  1191. userspace update the TCE table directly which is useful in some
  1192. circumstances.
  1193. 4.63 KVM_ALLOCATE_RMA
  1194. Capability: KVM_CAP_PPC_RMA
  1195. Architectures: powerpc
  1196. Type: vm ioctl
  1197. Parameters: struct kvm_allocate_rma (out)
  1198. Returns: file descriptor for mapping the allocated RMA
  1199. This allocates a Real Mode Area (RMA) from the pool allocated at boot
  1200. time by the kernel. An RMA is a physically-contiguous, aligned region
  1201. of memory used on older POWER processors to provide the memory which
  1202. will be accessed by real-mode (MMU off) accesses in a KVM guest.
  1203. POWER processors support a set of sizes for the RMA that usually
  1204. includes 64MB, 128MB, 256MB and some larger powers of two.
  1205. /* for KVM_ALLOCATE_RMA */
  1206. struct kvm_allocate_rma {
  1207. __u64 rma_size;
  1208. };
  1209. The return value is a file descriptor which can be passed to mmap(2)
  1210. to map the allocated RMA into userspace. The mapped area can then be
  1211. passed to the KVM_SET_USER_MEMORY_REGION ioctl to establish it as the
  1212. RMA for a virtual machine. The size of the RMA in bytes (which is
  1213. fixed at host kernel boot time) is returned in the rma_size field of
  1214. the argument structure.
  1215. The KVM_CAP_PPC_RMA capability is 1 or 2 if the KVM_ALLOCATE_RMA ioctl
  1216. is supported; 2 if the processor requires all virtual machines to have
  1217. an RMA, or 1 if the processor can use an RMA but doesn't require it,
  1218. because it supports the Virtual RMA (VRMA) facility.
  1219. 4.64 KVM_NMI
  1220. Capability: KVM_CAP_USER_NMI
  1221. Architectures: x86
  1222. Type: vcpu ioctl
  1223. Parameters: none
  1224. Returns: 0 on success, -1 on error
  1225. Queues an NMI on the thread's vcpu. Note this is well defined only
  1226. when KVM_CREATE_IRQCHIP has not been called, since this is an interface
  1227. between the virtual cpu core and virtual local APIC. After KVM_CREATE_IRQCHIP
  1228. has been called, this interface is completely emulated within the kernel.
  1229. To use this to emulate the LINT1 input with KVM_CREATE_IRQCHIP, use the
  1230. following algorithm:
  1231. - pause the vpcu
  1232. - read the local APIC's state (KVM_GET_LAPIC)
  1233. - check whether changing LINT1 will queue an NMI (see the LVT entry for LINT1)
  1234. - if so, issue KVM_NMI
  1235. - resume the vcpu
  1236. Some guests configure the LINT1 NMI input to cause a panic, aiding in
  1237. debugging.
  1238. 4.65 KVM_S390_UCAS_MAP
  1239. Capability: KVM_CAP_S390_UCONTROL
  1240. Architectures: s390
  1241. Type: vcpu ioctl
  1242. Parameters: struct kvm_s390_ucas_mapping (in)
  1243. Returns: 0 in case of success
  1244. The parameter is defined like this:
  1245. struct kvm_s390_ucas_mapping {
  1246. __u64 user_addr;
  1247. __u64 vcpu_addr;
  1248. __u64 length;
  1249. };
  1250. This ioctl maps the memory at "user_addr" with the length "length" to
  1251. the vcpu's address space starting at "vcpu_addr". All parameters need to
  1252. be aligned by 1 megabyte.
  1253. 4.66 KVM_S390_UCAS_UNMAP
  1254. Capability: KVM_CAP_S390_UCONTROL
  1255. Architectures: s390
  1256. Type: vcpu ioctl
  1257. Parameters: struct kvm_s390_ucas_mapping (in)
  1258. Returns: 0 in case of success
  1259. The parameter is defined like this:
  1260. struct kvm_s390_ucas_mapping {
  1261. __u64 user_addr;
  1262. __u64 vcpu_addr;
  1263. __u64 length;
  1264. };
  1265. This ioctl unmaps the memory in the vcpu's address space starting at
  1266. "vcpu_addr" with the length "length". The field "user_addr" is ignored.
  1267. All parameters need to be aligned by 1 megabyte.
  1268. 4.67 KVM_S390_VCPU_FAULT
  1269. Capability: KVM_CAP_S390_UCONTROL
  1270. Architectures: s390
  1271. Type: vcpu ioctl
  1272. Parameters: vcpu absolute address (in)
  1273. Returns: 0 in case of success
  1274. This call creates a page table entry on the virtual cpu's address space
  1275. (for user controlled virtual machines) or the virtual machine's address
  1276. space (for regular virtual machines). This only works for minor faults,
  1277. thus it's recommended to access subject memory page via the user page
  1278. table upfront. This is useful to handle validity intercepts for user
  1279. controlled virtual machines to fault in the virtual cpu's lowcore pages
  1280. prior to calling the KVM_RUN ioctl.
  1281. 4.68 KVM_SET_ONE_REG
  1282. Capability: KVM_CAP_ONE_REG
  1283. Architectures: all
  1284. Type: vcpu ioctl
  1285. Parameters: struct kvm_one_reg (in)
  1286. Returns: 0 on success, negative value on failure
  1287. struct kvm_one_reg {
  1288. __u64 id;
  1289. __u64 addr;
  1290. };
  1291. Using this ioctl, a single vcpu register can be set to a specific value
  1292. defined by user space with the passed in struct kvm_one_reg, where id
  1293. refers to the register identifier as described below and addr is a pointer
  1294. to a variable with the respective size. There can be architecture agnostic
  1295. and architecture specific registers. Each have their own range of operation
  1296. and their own constants and width. To keep track of the implemented
  1297. registers, find a list below:
  1298. Arch | Register | Width (bits)
  1299. | |
  1300. PPC | KVM_REG_PPC_HIOR | 64
  1301. PPC | KVM_REG_PPC_IAC1 | 64
  1302. PPC | KVM_REG_PPC_IAC2 | 64
  1303. PPC | KVM_REG_PPC_IAC3 | 64
  1304. PPC | KVM_REG_PPC_IAC4 | 64
  1305. PPC | KVM_REG_PPC_DAC1 | 64
  1306. PPC | KVM_REG_PPC_DAC2 | 64
  1307. PPC | KVM_REG_PPC_DABR | 64
  1308. PPC | KVM_REG_PPC_DSCR | 64
  1309. PPC | KVM_REG_PPC_PURR | 64
  1310. PPC | KVM_REG_PPC_SPURR | 64
  1311. PPC | KVM_REG_PPC_DAR | 64
  1312. PPC | KVM_REG_PPC_DSISR | 32
  1313. PPC | KVM_REG_PPC_AMR | 64
  1314. PPC | KVM_REG_PPC_UAMOR | 64
  1315. PPC | KVM_REG_PPC_MMCR0 | 64
  1316. PPC | KVM_REG_PPC_MMCR1 | 64
  1317. PPC | KVM_REG_PPC_MMCRA | 64
  1318. PPC | KVM_REG_PPC_PMC1 | 32
  1319. PPC | KVM_REG_PPC_PMC2 | 32
  1320. PPC | KVM_REG_PPC_PMC3 | 32
  1321. PPC | KVM_REG_PPC_PMC4 | 32
  1322. PPC | KVM_REG_PPC_PMC5 | 32
  1323. PPC | KVM_REG_PPC_PMC6 | 32
  1324. PPC | KVM_REG_PPC_PMC7 | 32
  1325. PPC | KVM_REG_PPC_PMC8 | 32
  1326. PPC | KVM_REG_PPC_FPR0 | 64
  1327. ...
  1328. PPC | KVM_REG_PPC_FPR31 | 64
  1329. PPC | KVM_REG_PPC_VR0 | 128
  1330. ...
  1331. PPC | KVM_REG_PPC_VR31 | 128
  1332. PPC | KVM_REG_PPC_VSR0 | 128
  1333. ...
  1334. PPC | KVM_REG_PPC_VSR31 | 128
  1335. PPC | KVM_REG_PPC_FPSCR | 64
  1336. PPC | KVM_REG_PPC_VSCR | 32
  1337. PPC | KVM_REG_PPC_VPA_ADDR | 64
  1338. PPC | KVM_REG_PPC_VPA_SLB | 128
  1339. PPC | KVM_REG_PPC_VPA_DTL | 128
  1340. PPC | KVM_REG_PPC_EPCR | 32
  1341. PPC | KVM_REG_PPC_EPR | 32
  1342. PPC | KVM_REG_PPC_TCR | 32
  1343. PPC | KVM_REG_PPC_TSR | 32
  1344. PPC | KVM_REG_PPC_OR_TSR | 32
  1345. PPC | KVM_REG_PPC_CLEAR_TSR | 32
  1346. PPC | KVM_REG_PPC_MAS0 | 32
  1347. PPC | KVM_REG_PPC_MAS1 | 32
  1348. PPC | KVM_REG_PPC_MAS2 | 64
  1349. PPC | KVM_REG_PPC_MAS7_3 | 64
  1350. PPC | KVM_REG_PPC_MAS4 | 32
  1351. PPC | KVM_REG_PPC_MAS6 | 32
  1352. PPC | KVM_REG_PPC_MMUCFG | 32
  1353. PPC | KVM_REG_PPC_TLB0CFG | 32
  1354. PPC | KVM_REG_PPC_TLB1CFG | 32
  1355. PPC | KVM_REG_PPC_TLB2CFG | 32
  1356. PPC | KVM_REG_PPC_TLB3CFG | 32
  1357. PPC | KVM_REG_PPC_TLB0PS | 32
  1358. PPC | KVM_REG_PPC_TLB1PS | 32
  1359. PPC | KVM_REG_PPC_TLB2PS | 32
  1360. PPC | KVM_REG_PPC_TLB3PS | 32
  1361. PPC | KVM_REG_PPC_EPTCFG | 32
  1362. PPC | KVM_REG_PPC_ICP_STATE | 64
  1363. ARM registers are mapped using the lower 32 bits. The upper 16 of that
  1364. is the register group type, or coprocessor number:
  1365. ARM core registers have the following id bit patterns:
  1366. 0x4020 0000 0010 <index into the kvm_regs struct:16>
  1367. ARM 32-bit CP15 registers have the following id bit patterns:
  1368. 0x4020 0000 000F <zero:1> <crn:4> <crm:4> <opc1:4> <opc2:3>
  1369. ARM 64-bit CP15 registers have the following id bit patterns:
  1370. 0x4030 0000 000F <zero:1> <zero:4> <crm:4> <opc1:4> <zero:3>
  1371. ARM CCSIDR registers are demultiplexed by CSSELR value:
  1372. 0x4020 0000 0011 00 <csselr:8>
  1373. ARM 32-bit VFP control registers have the following id bit patterns:
  1374. 0x4020 0000 0012 1 <regno:12>
  1375. ARM 64-bit FP registers have the following id bit patterns:
  1376. 0x4030 0000 0012 0 <regno:12>
  1377. arm64 registers are mapped using the lower 32 bits. The upper 16 of
  1378. that is the register group type, or coprocessor number:
  1379. arm64 core/FP-SIMD registers have the following id bit patterns. Note
  1380. that the size of the access is variable, as the kvm_regs structure
  1381. contains elements ranging from 32 to 128 bits. The index is a 32bit
  1382. value in the kvm_regs structure seen as a 32bit array.
  1383. 0x60x0 0000 0010 <index into the kvm_regs struct:16>
  1384. arm64 CCSIDR registers are demultiplexed by CSSELR value:
  1385. 0x6020 0000 0011 00 <csselr:8>
  1386. arm64 system registers have the following id bit patterns:
  1387. 0x6030 0000 0013 <op0:2> <op1:3> <crn:4> <crm:4> <op2:3>
  1388. 4.69 KVM_GET_ONE_REG
  1389. Capability: KVM_CAP_ONE_REG
  1390. Architectures: all
  1391. Type: vcpu ioctl
  1392. Parameters: struct kvm_one_reg (in and out)
  1393. Returns: 0 on success, negative value on failure
  1394. This ioctl allows to receive the value of a single register implemented
  1395. in a vcpu. The register to read is indicated by the "id" field of the
  1396. kvm_one_reg struct passed in. On success, the register value can be found
  1397. at the memory location pointed to by "addr".
  1398. The list of registers accessible using this interface is identical to the
  1399. list in 4.68.
  1400. 4.70 KVM_KVMCLOCK_CTRL
  1401. Capability: KVM_CAP_KVMCLOCK_CTRL
  1402. Architectures: Any that implement pvclocks (currently x86 only)
  1403. Type: vcpu ioctl
  1404. Parameters: None
  1405. Returns: 0 on success, -1 on error
  1406. This signals to the host kernel that the specified guest is being paused by
  1407. userspace. The host will set a flag in the pvclock structure that is checked
  1408. from the soft lockup watchdog. The flag is part of the pvclock structure that
  1409. is shared between guest and host, specifically the second bit of the flags
  1410. field of the pvclock_vcpu_time_info structure. It will be set exclusively by
  1411. the host and read/cleared exclusively by the guest. The guest operation of
  1412. checking and clearing the flag must an atomic operation so
  1413. load-link/store-conditional, or equivalent must be used. There are two cases
  1414. where the guest will clear the flag: when the soft lockup watchdog timer resets
  1415. itself or when a soft lockup is detected. This ioctl can be called any time
  1416. after pausing the vcpu, but before it is resumed.
  1417. 4.71 KVM_SIGNAL_MSI
  1418. Capability: KVM_CAP_SIGNAL_MSI
  1419. Architectures: x86
  1420. Type: vm ioctl
  1421. Parameters: struct kvm_msi (in)
  1422. Returns: >0 on delivery, 0 if guest blocked the MSI, and -1 on error
  1423. Directly inject a MSI message. Only valid with in-kernel irqchip that handles
  1424. MSI messages.
  1425. struct kvm_msi {
  1426. __u32 address_lo;
  1427. __u32 address_hi;
  1428. __u32 data;
  1429. __u32 flags;
  1430. __u8 pad[16];
  1431. };
  1432. No flags are defined so far. The corresponding field must be 0.
  1433. 4.71 KVM_CREATE_PIT2
  1434. Capability: KVM_CAP_PIT2
  1435. Architectures: x86
  1436. Type: vm ioctl
  1437. Parameters: struct kvm_pit_config (in)
  1438. Returns: 0 on success, -1 on error
  1439. Creates an in-kernel device model for the i8254 PIT. This call is only valid
  1440. after enabling in-kernel irqchip support via KVM_CREATE_IRQCHIP. The following
  1441. parameters have to be passed:
  1442. struct kvm_pit_config {
  1443. __u32 flags;
  1444. __u32 pad[15];
  1445. };
  1446. Valid flags are:
  1447. #define KVM_PIT_SPEAKER_DUMMY 1 /* emulate speaker port stub */
  1448. PIT timer interrupts may use a per-VM kernel thread for injection. If it
  1449. exists, this thread will have a name of the following pattern:
  1450. kvm-pit/<owner-process-pid>
  1451. When running a guest with elevated priorities, the scheduling parameters of
  1452. this thread may have to be adjusted accordingly.
  1453. This IOCTL replaces the obsolete KVM_CREATE_PIT.
  1454. 4.72 KVM_GET_PIT2
  1455. Capability: KVM_CAP_PIT_STATE2
  1456. Architectures: x86
  1457. Type: vm ioctl
  1458. Parameters: struct kvm_pit_state2 (out)
  1459. Returns: 0 on success, -1 on error
  1460. Retrieves the state of the in-kernel PIT model. Only valid after
  1461. KVM_CREATE_PIT2. The state is returned in the following structure:
  1462. struct kvm_pit_state2 {
  1463. struct kvm_pit_channel_state channels[3];
  1464. __u32 flags;
  1465. __u32 reserved[9];
  1466. };
  1467. Valid flags are:
  1468. /* disable PIT in HPET legacy mode */
  1469. #define KVM_PIT_FLAGS_HPET_LEGACY 0x00000001
  1470. This IOCTL replaces the obsolete KVM_GET_PIT.
  1471. 4.73 KVM_SET_PIT2
  1472. Capability: KVM_CAP_PIT_STATE2
  1473. Architectures: x86
  1474. Type: vm ioctl
  1475. Parameters: struct kvm_pit_state2 (in)
  1476. Returns: 0 on success, -1 on error
  1477. Sets the state of the in-kernel PIT model. Only valid after KVM_CREATE_PIT2.
  1478. See KVM_GET_PIT2 for details on struct kvm_pit_state2.
  1479. This IOCTL replaces the obsolete KVM_SET_PIT.
  1480. 4.74 KVM_PPC_GET_SMMU_INFO
  1481. Capability: KVM_CAP_PPC_GET_SMMU_INFO
  1482. Architectures: powerpc
  1483. Type: vm ioctl
  1484. Parameters: None
  1485. Returns: 0 on success, -1 on error
  1486. This populates and returns a structure describing the features of
  1487. the "Server" class MMU emulation supported by KVM.
  1488. This can in turn be used by userspace to generate the appropriate
  1489. device-tree properties for the guest operating system.
  1490. The structure contains some global informations, followed by an
  1491. array of supported segment page sizes:
  1492. struct kvm_ppc_smmu_info {
  1493. __u64 flags;
  1494. __u32 slb_size;
  1495. __u32 pad;
  1496. struct kvm_ppc_one_seg_page_size sps[KVM_PPC_PAGE_SIZES_MAX_SZ];
  1497. };
  1498. The supported flags are:
  1499. - KVM_PPC_PAGE_SIZES_REAL:
  1500. When that flag is set, guest page sizes must "fit" the backing
  1501. store page sizes. When not set, any page size in the list can
  1502. be used regardless of how they are backed by userspace.
  1503. - KVM_PPC_1T_SEGMENTS
  1504. The emulated MMU supports 1T segments in addition to the
  1505. standard 256M ones.
  1506. The "slb_size" field indicates how many SLB entries are supported
  1507. The "sps" array contains 8 entries indicating the supported base
  1508. page sizes for a segment in increasing order. Each entry is defined
  1509. as follow:
  1510. struct kvm_ppc_one_seg_page_size {
  1511. __u32 page_shift; /* Base page shift of segment (or 0) */
  1512. __u32 slb_enc; /* SLB encoding for BookS */
  1513. struct kvm_ppc_one_page_size enc[KVM_PPC_PAGE_SIZES_MAX_SZ];
  1514. };
  1515. An entry with a "page_shift" of 0 is unused. Because the array is
  1516. organized in increasing order, a lookup can stop when encoutering
  1517. such an entry.
  1518. The "slb_enc" field provides the encoding to use in the SLB for the
  1519. page size. The bits are in positions such as the value can directly
  1520. be OR'ed into the "vsid" argument of the slbmte instruction.
  1521. The "enc" array is a list which for each of those segment base page
  1522. size provides the list of supported actual page sizes (which can be
  1523. only larger or equal to the base page size), along with the
  1524. corresponding encoding in the hash PTE. Similarly, the array is
  1525. 8 entries sorted by increasing sizes and an entry with a "0" shift
  1526. is an empty entry and a terminator:
  1527. struct kvm_ppc_one_page_size {
  1528. __u32 page_shift; /* Page shift (or 0) */
  1529. __u32 pte_enc; /* Encoding in the HPTE (>>12) */
  1530. };
  1531. The "pte_enc" field provides a value that can OR'ed into the hash
  1532. PTE's RPN field (ie, it needs to be shifted left by 12 to OR it
  1533. into the hash PTE second double word).
  1534. 4.75 KVM_IRQFD
  1535. Capability: KVM_CAP_IRQFD
  1536. Architectures: x86
  1537. Type: vm ioctl
  1538. Parameters: struct kvm_irqfd (in)
  1539. Returns: 0 on success, -1 on error
  1540. Allows setting an eventfd to directly trigger a guest interrupt.
  1541. kvm_irqfd.fd specifies the file descriptor to use as the eventfd and
  1542. kvm_irqfd.gsi specifies the irqchip pin toggled by this event. When
  1543. an event is tiggered on the eventfd, an interrupt is injected into
  1544. the guest using the specified gsi pin. The irqfd is removed using
  1545. the KVM_IRQFD_FLAG_DEASSIGN flag, specifying both kvm_irqfd.fd
  1546. and kvm_irqfd.gsi.
  1547. With KVM_CAP_IRQFD_RESAMPLE, KVM_IRQFD supports a de-assert and notify
  1548. mechanism allowing emulation of level-triggered, irqfd-based
  1549. interrupts. When KVM_IRQFD_FLAG_RESAMPLE is set the user must pass an
  1550. additional eventfd in the kvm_irqfd.resamplefd field. When operating
  1551. in resample mode, posting of an interrupt through kvm_irq.fd asserts
  1552. the specified gsi in the irqchip. When the irqchip is resampled, such
  1553. as from an EOI, the gsi is de-asserted and the user is notifed via
  1554. kvm_irqfd.resamplefd. It is the user's responsibility to re-queue
  1555. the interrupt if the device making use of it still requires service.
  1556. Note that closing the resamplefd is not sufficient to disable the
  1557. irqfd. The KVM_IRQFD_FLAG_RESAMPLE is only necessary on assignment
  1558. and need not be specified with KVM_IRQFD_FLAG_DEASSIGN.
  1559. 4.76 KVM_PPC_ALLOCATE_HTAB
  1560. Capability: KVM_CAP_PPC_ALLOC_HTAB
  1561. Architectures: powerpc
  1562. Type: vm ioctl
  1563. Parameters: Pointer to u32 containing hash table order (in/out)
  1564. Returns: 0 on success, -1 on error
  1565. This requests the host kernel to allocate an MMU hash table for a
  1566. guest using the PAPR paravirtualization interface. This only does
  1567. anything if the kernel is configured to use the Book 3S HV style of
  1568. virtualization. Otherwise the capability doesn't exist and the ioctl
  1569. returns an ENOTTY error. The rest of this description assumes Book 3S
  1570. HV.
  1571. There must be no vcpus running when this ioctl is called; if there
  1572. are, it will do nothing and return an EBUSY error.
  1573. The parameter is a pointer to a 32-bit unsigned integer variable
  1574. containing the order (log base 2) of the desired size of the hash
  1575. table, which must be between 18 and 46. On successful return from the
  1576. ioctl, it will have been updated with the order of the hash table that
  1577. was allocated.
  1578. If no hash table has been allocated when any vcpu is asked to run
  1579. (with the KVM_RUN ioctl), the host kernel will allocate a
  1580. default-sized hash table (16 MB).
  1581. If this ioctl is called when a hash table has already been allocated,
  1582. the kernel will clear out the existing hash table (zero all HPTEs) and
  1583. return the hash table order in the parameter. (If the guest is using
  1584. the virtualized real-mode area (VRMA) facility, the kernel will
  1585. re-create the VMRA HPTEs on the next KVM_RUN of any vcpu.)
  1586. 4.77 KVM_S390_INTERRUPT
  1587. Capability: basic
  1588. Architectures: s390
  1589. Type: vm ioctl, vcpu ioctl
  1590. Parameters: struct kvm_s390_interrupt (in)
  1591. Returns: 0 on success, -1 on error
  1592. Allows to inject an interrupt to the guest. Interrupts can be floating
  1593. (vm ioctl) or per cpu (vcpu ioctl), depending on the interrupt type.
  1594. Interrupt parameters are passed via kvm_s390_interrupt:
  1595. struct kvm_s390_interrupt {
  1596. __u32 type;
  1597. __u32 parm;
  1598. __u64 parm64;
  1599. };
  1600. type can be one of the following:
  1601. KVM_S390_SIGP_STOP (vcpu) - sigp restart
  1602. KVM_S390_PROGRAM_INT (vcpu) - program check; code in parm
  1603. KVM_S390_SIGP_SET_PREFIX (vcpu) - sigp set prefix; prefix address in parm
  1604. KVM_S390_RESTART (vcpu) - restart
  1605. KVM_S390_INT_VIRTIO (vm) - virtio external interrupt; external interrupt
  1606. parameters in parm and parm64
  1607. KVM_S390_INT_SERVICE (vm) - sclp external interrupt; sclp parameter in parm
  1608. KVM_S390_INT_EMERGENCY (vcpu) - sigp emergency; source cpu in parm
  1609. KVM_S390_INT_EXTERNAL_CALL (vcpu) - sigp external call; source cpu in parm
  1610. KVM_S390_INT_IO(ai,cssid,ssid,schid) (vm) - compound value to indicate an
  1611. I/O interrupt (ai - adapter interrupt; cssid,ssid,schid - subchannel);
  1612. I/O interruption parameters in parm (subchannel) and parm64 (intparm,
  1613. interruption subclass)
  1614. KVM_S390_MCHK (vm, vcpu) - machine check interrupt; cr 14 bits in parm,
  1615. machine check interrupt code in parm64 (note that
  1616. machine checks needing further payload are not
  1617. supported by this ioctl)
  1618. Note that the vcpu ioctl is asynchronous to vcpu execution.
  1619. 4.78 KVM_PPC_GET_HTAB_FD
  1620. Capability: KVM_CAP_PPC_HTAB_FD
  1621. Architectures: powerpc
  1622. Type: vm ioctl
  1623. Parameters: Pointer to struct kvm_get_htab_fd (in)
  1624. Returns: file descriptor number (>= 0) on success, -1 on error
  1625. This returns a file descriptor that can be used either to read out the
  1626. entries in the guest's hashed page table (HPT), or to write entries to
  1627. initialize the HPT. The returned fd can only be written to if the
  1628. KVM_GET_HTAB_WRITE bit is set in the flags field of the argument, and
  1629. can only be read if that bit is clear. The argument struct looks like
  1630. this:
  1631. /* For KVM_PPC_GET_HTAB_FD */
  1632. struct kvm_get_htab_fd {
  1633. __u64 flags;
  1634. __u64 start_index;
  1635. __u64 reserved[2];
  1636. };
  1637. /* Values for kvm_get_htab_fd.flags */
  1638. #define KVM_GET_HTAB_BOLTED_ONLY ((__u64)0x1)
  1639. #define KVM_GET_HTAB_WRITE ((__u64)0x2)
  1640. The `start_index' field gives the index in the HPT of the entry at
  1641. which to start reading. It is ignored when writing.
  1642. Reads on the fd will initially supply information about all
  1643. "interesting" HPT entries. Interesting entries are those with the
  1644. bolted bit set, if the KVM_GET_HTAB_BOLTED_ONLY bit is set, otherwise
  1645. all entries. When the end of the HPT is reached, the read() will
  1646. return. If read() is called again on the fd, it will start again from
  1647. the beginning of the HPT, but will only return HPT entries that have
  1648. changed since they were last read.
  1649. Data read or written is structured as a header (8 bytes) followed by a
  1650. series of valid HPT entries (16 bytes) each. The header indicates how
  1651. many valid HPT entries there are and how many invalid entries follow
  1652. the valid entries. The invalid entries are not represented explicitly
  1653. in the stream. The header format is:
  1654. struct kvm_get_htab_header {
  1655. __u32 index;
  1656. __u16 n_valid;
  1657. __u16 n_invalid;
  1658. };
  1659. Writes to the fd create HPT entries starting at the index given in the
  1660. header; first `n_valid' valid entries with contents from the data
  1661. written, then `n_invalid' invalid entries, invalidating any previously
  1662. valid entries found.
  1663. 4.79 KVM_CREATE_DEVICE
  1664. Capability: KVM_CAP_DEVICE_CTRL
  1665. Type: vm ioctl
  1666. Parameters: struct kvm_create_device (in/out)
  1667. Returns: 0 on success, -1 on error
  1668. Errors:
  1669. ENODEV: The device type is unknown or unsupported
  1670. EEXIST: Device already created, and this type of device may not
  1671. be instantiated multiple times
  1672. Other error conditions may be defined by individual device types or
  1673. have their standard meanings.
  1674. Creates an emulated device in the kernel. The file descriptor returned
  1675. in fd can be used with KVM_SET/GET/HAS_DEVICE_ATTR.
  1676. If the KVM_CREATE_DEVICE_TEST flag is set, only test whether the
  1677. device type is supported (not necessarily whether it can be created
  1678. in the current vm).
  1679. Individual devices should not define flags. Attributes should be used
  1680. for specifying any behavior that is not implied by the device type
  1681. number.
  1682. struct kvm_create_device {
  1683. __u32 type; /* in: KVM_DEV_TYPE_xxx */
  1684. __u32 fd; /* out: device handle */
  1685. __u32 flags; /* in: KVM_CREATE_DEVICE_xxx */
  1686. };
  1687. 4.80 KVM_SET_DEVICE_ATTR/KVM_GET_DEVICE_ATTR
  1688. Capability: KVM_CAP_DEVICE_CTRL
  1689. Type: device ioctl
  1690. Parameters: struct kvm_device_attr
  1691. Returns: 0 on success, -1 on error
  1692. Errors:
  1693. ENXIO: The group or attribute is unknown/unsupported for this device
  1694. EPERM: The attribute cannot (currently) be accessed this way
  1695. (e.g. read-only attribute, or attribute that only makes
  1696. sense when the device is in a different state)
  1697. Other error conditions may be defined by individual device types.
  1698. Gets/sets a specified piece of device configuration and/or state. The
  1699. semantics are device-specific. See individual device documentation in
  1700. the "devices" directory. As with ONE_REG, the size of the data
  1701. transferred is defined by the particular attribute.
  1702. struct kvm_device_attr {
  1703. __u32 flags; /* no flags currently defined */
  1704. __u32 group; /* device-defined */
  1705. __u64 attr; /* group-defined */
  1706. __u64 addr; /* userspace address of attr data */
  1707. };
  1708. 4.81 KVM_HAS_DEVICE_ATTR
  1709. Capability: KVM_CAP_DEVICE_CTRL
  1710. Type: device ioctl
  1711. Parameters: struct kvm_device_attr
  1712. Returns: 0 on success, -1 on error
  1713. Errors:
  1714. ENXIO: The group or attribute is unknown/unsupported for this device
  1715. Tests whether a device supports a particular attribute. A successful
  1716. return indicates the attribute is implemented. It does not necessarily
  1717. indicate that the attribute can be read or written in the device's
  1718. current state. "addr" is ignored.
  1719. 4.82 KVM_ARM_VCPU_INIT
  1720. Capability: basic
  1721. Architectures: arm, arm64
  1722. Type: vcpu ioctl
  1723. Parameters: struct struct kvm_vcpu_init (in)
  1724. Returns: 0 on success; -1 on error
  1725. Errors:
  1726.  EINVAL:    the target is unknown, or the combination of features is invalid.
  1727.  ENOENT:    a features bit specified is unknown.
  1728. This tells KVM what type of CPU to present to the guest, and what
  1729. optional features it should have.  This will cause a reset of the cpu
  1730. registers to their initial values.  If this is not called, KVM_RUN will
  1731. return ENOEXEC for that vcpu.
  1732. Note that because some registers reflect machine topology, all vcpus
  1733. should be created before this ioctl is invoked.
  1734. Possible features:
  1735. - KVM_ARM_VCPU_POWER_OFF: Starts the CPU in a power-off state.
  1736. Depends on KVM_CAP_ARM_PSCI.
  1737. - KVM_ARM_VCPU_EL1_32BIT: Starts the CPU in a 32bit mode.
  1738. Depends on KVM_CAP_ARM_EL1_32BIT (arm64 only).
  1739. 4.83 KVM_GET_REG_LIST
  1740. Capability: basic
  1741. Architectures: arm, arm64
  1742. Type: vcpu ioctl
  1743. Parameters: struct kvm_reg_list (in/out)
  1744. Returns: 0 on success; -1 on error
  1745. Errors:
  1746.  E2BIG:     the reg index list is too big to fit in the array specified by
  1747.             the user (the number required will be written into n).
  1748. struct kvm_reg_list {
  1749. __u64 n; /* number of registers in reg[] */
  1750. __u64 reg[0];
  1751. };
  1752. This ioctl returns the guest registers that are supported for the
  1753. KVM_GET_ONE_REG/KVM_SET_ONE_REG calls.
  1754. 4.84 KVM_ARM_SET_DEVICE_ADDR
  1755. Capability: KVM_CAP_ARM_SET_DEVICE_ADDR
  1756. Architectures: arm, arm64
  1757. Type: vm ioctl
  1758. Parameters: struct kvm_arm_device_address (in)
  1759. Returns: 0 on success, -1 on error
  1760. Errors:
  1761. ENODEV: The device id is unknown
  1762. ENXIO: Device not supported on current system
  1763. EEXIST: Address already set
  1764. E2BIG: Address outside guest physical address space
  1765. EBUSY: Address overlaps with other device range
  1766. struct kvm_arm_device_addr {
  1767. __u64 id;
  1768. __u64 addr;
  1769. };
  1770. Specify a device address in the guest's physical address space where guests
  1771. can access emulated or directly exposed devices, which the host kernel needs
  1772. to know about. The id field is an architecture specific identifier for a
  1773. specific device.
  1774. ARM/arm64 divides the id field into two parts, a device id and an
  1775. address type id specific to the individual device.
  1776.  bits: | 63 ... 32 | 31 ... 16 | 15 ... 0 |
  1777. field: | 0x00000000 | device id | addr type id |
  1778. ARM/arm64 currently only require this when using the in-kernel GIC
  1779. support for the hardware VGIC features, using KVM_ARM_DEVICE_VGIC_V2
  1780. as the device id. When setting the base address for the guest's
  1781. mapping of the VGIC virtual CPU and distributor interface, the ioctl
  1782. must be called after calling KVM_CREATE_IRQCHIP, but before calling
  1783. KVM_RUN on any of the VCPUs. Calling this ioctl twice for any of the
  1784. base addresses will return -EEXIST.
  1785. 4.85 KVM_PPC_RTAS_DEFINE_TOKEN
  1786. Capability: KVM_CAP_PPC_RTAS
  1787. Architectures: ppc
  1788. Type: vm ioctl
  1789. Parameters: struct kvm_rtas_token_args
  1790. Returns: 0 on success, -1 on error
  1791. Defines a token value for a RTAS (Run Time Abstraction Services)
  1792. service in order to allow it to be handled in the kernel. The
  1793. argument struct gives the name of the service, which must be the name
  1794. of a service that has a kernel-side implementation. If the token
  1795. value is non-zero, it will be associated with that service, and
  1796. subsequent RTAS calls by the guest specifying that token will be
  1797. handled by the kernel. If the token value is 0, then any token
  1798. associated with the service will be forgotten, and subsequent RTAS
  1799. calls by the guest for that service will be passed to userspace to be
  1800. handled.
  1801. 5. The kvm_run structure
  1802. ------------------------
  1803. Application code obtains a pointer to the kvm_run structure by
  1804. mmap()ing a vcpu fd. From that point, application code can control
  1805. execution by changing fields in kvm_run prior to calling the KVM_RUN
  1806. ioctl, and obtain information about the reason KVM_RUN returned by
  1807. looking up structure members.
  1808. struct kvm_run {
  1809. /* in */
  1810. __u8 request_interrupt_window;
  1811. Request that KVM_RUN return when it becomes possible to inject external
  1812. interrupts into the guest. Useful in conjunction with KVM_INTERRUPT.
  1813. __u8 padding1[7];
  1814. /* out */
  1815. __u32 exit_reason;
  1816. When KVM_RUN has returned successfully (return value 0), this informs
  1817. application code why KVM_RUN has returned. Allowable values for this
  1818. field are detailed below.
  1819. __u8 ready_for_interrupt_injection;
  1820. If request_interrupt_window has been specified, this field indicates
  1821. an interrupt can be injected now with KVM_INTERRUPT.
  1822. __u8 if_flag;
  1823. The value of the current interrupt flag. Only valid if in-kernel
  1824. local APIC is not used.
  1825. __u8 padding2[2];
  1826. /* in (pre_kvm_run), out (post_kvm_run) */
  1827. __u64 cr8;
  1828. The value of the cr8 register. Only valid if in-kernel local APIC is
  1829. not used. Both input and output.
  1830. __u64 apic_base;
  1831. The value of the APIC BASE msr. Only valid if in-kernel local
  1832. APIC is not used. Both input and output.
  1833. union {
  1834. /* KVM_EXIT_UNKNOWN */
  1835. struct {
  1836. __u64 hardware_exit_reason;
  1837. } hw;
  1838. If exit_reason is KVM_EXIT_UNKNOWN, the vcpu has exited due to unknown
  1839. reasons. Further architecture-specific information is available in
  1840. hardware_exit_reason.
  1841. /* KVM_EXIT_FAIL_ENTRY */
  1842. struct {
  1843. __u64 hardware_entry_failure_reason;
  1844. } fail_entry;
  1845. If exit_reason is KVM_EXIT_FAIL_ENTRY, the vcpu could not be run due
  1846. to unknown reasons. Further architecture-specific information is
  1847. available in hardware_entry_failure_reason.
  1848. /* KVM_EXIT_EXCEPTION */
  1849. struct {
  1850. __u32 exception;
  1851. __u32 error_code;
  1852. } ex;
  1853. Unused.
  1854. /* KVM_EXIT_IO */
  1855. struct {
  1856. #define KVM_EXIT_IO_IN 0
  1857. #define KVM_EXIT_IO_OUT 1
  1858. __u8 direction;
  1859. __u8 size; /* bytes */
  1860. __u16 port;
  1861. __u32 count;
  1862. __u64 data_offset; /* relative to kvm_run start */
  1863. } io;
  1864. If exit_reason is KVM_EXIT_IO, then the vcpu has
  1865. executed a port I/O instruction which could not be satisfied by kvm.
  1866. data_offset describes where the data is located (KVM_EXIT_IO_OUT) or
  1867. where kvm expects application code to place the data for the next
  1868. KVM_RUN invocation (KVM_EXIT_IO_IN). Data format is a packed array.
  1869. struct {
  1870. struct kvm_debug_exit_arch arch;
  1871. } debug;
  1872. Unused.
  1873. /* KVM_EXIT_MMIO */
  1874. struct {
  1875. __u64 phys_addr;
  1876. __u8 data[8];
  1877. __u32 len;
  1878. __u8 is_write;
  1879. } mmio;
  1880. If exit_reason is KVM_EXIT_MMIO, then the vcpu has
  1881. executed a memory-mapped I/O instruction which could not be satisfied
  1882. by kvm. The 'data' member contains the written data if 'is_write' is
  1883. true, and should be filled by application code otherwise.
  1884. NOTE: For KVM_EXIT_IO, KVM_EXIT_MMIO, KVM_EXIT_OSI, KVM_EXIT_DCR,
  1885. KVM_EXIT_PAPR and KVM_EXIT_EPR the corresponding
  1886. operations are complete (and guest state is consistent) only after userspace
  1887. has re-entered the kernel with KVM_RUN. The kernel side will first finish
  1888. incomplete operations and then check for pending signals. Userspace
  1889. can re-enter the guest with an unmasked signal pending to complete
  1890. pending operations.
  1891. /* KVM_EXIT_HYPERCALL */
  1892. struct {
  1893. __u64 nr;
  1894. __u64 args[6];
  1895. __u64 ret;
  1896. __u32 longmode;
  1897. __u32 pad;
  1898. } hypercall;
  1899. Unused. This was once used for 'hypercall to userspace'. To implement
  1900. such functionality, use KVM_EXIT_IO (x86) or KVM_EXIT_MMIO (all except s390).
  1901. Note KVM_EXIT_IO is significantly faster than KVM_EXIT_MMIO.
  1902. /* KVM_EXIT_TPR_ACCESS */
  1903. struct {
  1904. __u64 rip;
  1905. __u32 is_write;
  1906. __u32 pad;
  1907. } tpr_access;
  1908. To be documented (KVM_TPR_ACCESS_REPORTING).
  1909. /* KVM_EXIT_S390_SIEIC */
  1910. struct {
  1911. __u8 icptcode;
  1912. __u64 mask; /* psw upper half */
  1913. __u64 addr; /* psw lower half */
  1914. __u16 ipa;
  1915. __u32 ipb;
  1916. } s390_sieic;
  1917. s390 specific.
  1918. /* KVM_EXIT_S390_RESET */
  1919. #define KVM_S390_RESET_POR 1
  1920. #define KVM_S390_RESET_CLEAR 2
  1921. #define KVM_S390_RESET_SUBSYSTEM 4
  1922. #define KVM_S390_RESET_CPU_INIT 8
  1923. #define KVM_S390_RESET_IPL 16
  1924. __u64 s390_reset_flags;
  1925. s390 specific.
  1926. /* KVM_EXIT_S390_UCONTROL */
  1927. struct {
  1928. __u64 trans_exc_code;
  1929. __u32 pgm_code;
  1930. } s390_ucontrol;
  1931. s390 specific. A page fault has occurred for a user controlled virtual
  1932. machine (KVM_VM_S390_UNCONTROL) on it's host page table that cannot be
  1933. resolved by the kernel.
  1934. The program code and the translation exception code that were placed
  1935. in the cpu's lowcore are presented here as defined by the z Architecture
  1936. Principles of Operation Book in the Chapter for Dynamic Address Translation
  1937. (DAT)
  1938. /* KVM_EXIT_DCR */
  1939. struct {
  1940. __u32 dcrn;
  1941. __u32 data;
  1942. __u8 is_write;
  1943. } dcr;
  1944. powerpc specific.
  1945. /* KVM_EXIT_OSI */
  1946. struct {
  1947. __u64 gprs[32];
  1948. } osi;
  1949. MOL uses a special hypercall interface it calls 'OSI'. To enable it, we catch
  1950. hypercalls and exit with this exit struct that contains all the guest gprs.
  1951. If exit_reason is KVM_EXIT_OSI, then the vcpu has triggered such a hypercall.
  1952. Userspace can now handle the hypercall and when it's done modify the gprs as
  1953. necessary. Upon guest entry all guest GPRs will then be replaced by the values
  1954. in this struct.
  1955. /* KVM_EXIT_PAPR_HCALL */
  1956. struct {
  1957. __u64 nr;
  1958. __u64 ret;
  1959. __u64 args[9];
  1960. } papr_hcall;
  1961. This is used on 64-bit PowerPC when emulating a pSeries partition,
  1962. e.g. with the 'pseries' machine type in qemu. It occurs when the
  1963. guest does a hypercall using the 'sc 1' instruction. The 'nr' field
  1964. contains the hypercall number (from the guest R3), and 'args' contains
  1965. the arguments (from the guest R4 - R12). Userspace should put the
  1966. return code in 'ret' and any extra returned values in args[].
  1967. The possible hypercalls are defined in the Power Architecture Platform
  1968. Requirements (PAPR) document available from www.power.org (free
  1969. developer registration required to access it).
  1970. /* KVM_EXIT_S390_TSCH */
  1971. struct {
  1972. __u16 subchannel_id;
  1973. __u16 subchannel_nr;
  1974. __u32 io_int_parm;
  1975. __u32 io_int_word;
  1976. __u32 ipb;
  1977. __u8 dequeued;
  1978. } s390_tsch;
  1979. s390 specific. This exit occurs when KVM_CAP_S390_CSS_SUPPORT has been enabled
  1980. and TEST SUBCHANNEL was intercepted. If dequeued is set, a pending I/O
  1981. interrupt for the target subchannel has been dequeued and subchannel_id,
  1982. subchannel_nr, io_int_parm and io_int_word contain the parameters for that
  1983. interrupt. ipb is needed for instruction parameter decoding.
  1984. /* KVM_EXIT_EPR */
  1985. struct {
  1986. __u32 epr;
  1987. } epr;
  1988. On FSL BookE PowerPC chips, the interrupt controller has a fast patch
  1989. interrupt acknowledge path to the core. When the core successfully
  1990. delivers an interrupt, it automatically populates the EPR register with
  1991. the interrupt vector number and acknowledges the interrupt inside
  1992. the interrupt controller.
  1993. In case the interrupt controller lives in user space, we need to do
  1994. the interrupt acknowledge cycle through it to fetch the next to be
  1995. delivered interrupt vector using this exit.
  1996. It gets triggered whenever both KVM_CAP_PPC_EPR are enabled and an
  1997. external interrupt has just been delivered into the guest. User space
  1998. should put the acknowledged interrupt vector into the 'epr' field.
  1999. /* Fix the size of the union. */
  2000. char padding[256];
  2001. };
  2002. /*
  2003. * shared registers between kvm and userspace.
  2004. * kvm_valid_regs specifies the register classes set by the host
  2005. * kvm_dirty_regs specified the register classes dirtied by userspace
  2006. * struct kvm_sync_regs is architecture specific, as well as the
  2007. * bits for kvm_valid_regs and kvm_dirty_regs
  2008. */
  2009. __u64 kvm_valid_regs;
  2010. __u64 kvm_dirty_regs;
  2011. union {
  2012. struct kvm_sync_regs regs;
  2013. char padding[1024];
  2014. } s;
  2015. If KVM_CAP_SYNC_REGS is defined, these fields allow userspace to access
  2016. certain guest registers without having to call SET/GET_*REGS. Thus we can
  2017. avoid some system call overhead if userspace has to handle the exit.
  2018. Userspace can query the validity of the structure by checking
  2019. kvm_valid_regs for specific bits. These bits are architecture specific
  2020. and usually define the validity of a groups of registers. (e.g. one bit
  2021. for general purpose registers)
  2022. };
  2023. 6. Capabilities that can be enabled
  2024. -----------------------------------
  2025. There are certain capabilities that change the behavior of the virtual CPU when
  2026. enabled. To enable them, please see section 4.37. Below you can find a list of
  2027. capabilities and what their effect on the vCPU is when enabling them.
  2028. The following information is provided along with the description:
  2029. Architectures: which instruction set architectures provide this ioctl.
  2030. x86 includes both i386 and x86_64.
  2031. Parameters: what parameters are accepted by the capability.
  2032. Returns: the return value. General error numbers (EBADF, ENOMEM, EINVAL)
  2033. are not detailed, but errors with specific meanings are.
  2034. 6.1 KVM_CAP_PPC_OSI
  2035. Architectures: ppc
  2036. Parameters: none
  2037. Returns: 0 on success; -1 on error
  2038. This capability enables interception of OSI hypercalls that otherwise would
  2039. be treated as normal system calls to be injected into the guest. OSI hypercalls
  2040. were invented by Mac-on-Linux to have a standardized communication mechanism
  2041. between the guest and the host.
  2042. When this capability is enabled, KVM_EXIT_OSI can occur.
  2043. 6.2 KVM_CAP_PPC_PAPR
  2044. Architectures: ppc
  2045. Parameters: none
  2046. Returns: 0 on success; -1 on error
  2047. This capability enables interception of PAPR hypercalls. PAPR hypercalls are
  2048. done using the hypercall instruction "sc 1".
  2049. It also sets the guest privilege level to "supervisor" mode. Usually the guest
  2050. runs in "hypervisor" privilege mode with a few missing features.
  2051. In addition to the above, it changes the semantics of SDR1. In this mode, the
  2052. HTAB address part of SDR1 contains an HVA instead of a GPA, as PAPR keeps the
  2053. HTAB invisible to the guest.
  2054. When this capability is enabled, KVM_EXIT_PAPR_HCALL can occur.
  2055. 6.3 KVM_CAP_SW_TLB
  2056. Architectures: ppc
  2057. Parameters: args[0] is the address of a struct kvm_config_tlb
  2058. Returns: 0 on success; -1 on error
  2059. struct kvm_config_tlb {
  2060. __u64 params;
  2061. __u64 array;
  2062. __u32 mmu_type;
  2063. __u32 array_len;
  2064. };
  2065. Configures the virtual CPU's TLB array, establishing a shared memory area
  2066. between userspace and KVM. The "params" and "array" fields are userspace
  2067. addresses of mmu-type-specific data structures. The "array_len" field is an
  2068. safety mechanism, and should be set to the size in bytes of the memory that
  2069. userspace has reserved for the array. It must be at least the size dictated
  2070. by "mmu_type" and "params".
  2071. While KVM_RUN is active, the shared region is under control of KVM. Its
  2072. contents are undefined, and any modification by userspace results in
  2073. boundedly undefined behavior.
  2074. On return from KVM_RUN, the shared region will reflect the current state of
  2075. the guest's TLB. If userspace makes any changes, it must call KVM_DIRTY_TLB
  2076. to tell KVM which entries have been changed, prior to calling KVM_RUN again
  2077. on this vcpu.
  2078. For mmu types KVM_MMU_FSL_BOOKE_NOHV and KVM_MMU_FSL_BOOKE_HV:
  2079. - The "params" field is of type "struct kvm_book3e_206_tlb_params".
  2080. - The "array" field points to an array of type "struct
  2081. kvm_book3e_206_tlb_entry".
  2082. - The array consists of all entries in the first TLB, followed by all
  2083. entries in the second TLB.
  2084. - Within a TLB, entries are ordered first by increasing set number. Within a
  2085. set, entries are ordered by way (increasing ESEL).
  2086. - The hash for determining set number in TLB0 is: (MAS2 >> 12) & (num_sets - 1)
  2087. where "num_sets" is the tlb_sizes[] value divided by the tlb_ways[] value.
  2088. - The tsize field of mas1 shall be set to 4K on TLB0, even though the
  2089. hardware ignores this value for TLB0.
  2090. 6.4 KVM_CAP_S390_CSS_SUPPORT
  2091. Architectures: s390
  2092. Parameters: none
  2093. Returns: 0 on success; -1 on error
  2094. This capability enables support for handling of channel I/O instructions.
  2095. TEST PENDING INTERRUPTION and the interrupt portion of TEST SUBCHANNEL are
  2096. handled in-kernel, while the other I/O instructions are passed to userspace.
  2097. When this capability is enabled, KVM_EXIT_S390_TSCH will occur on TEST
  2098. SUBCHANNEL intercepts.
  2099. 6.5 KVM_CAP_PPC_EPR
  2100. Architectures: ppc
  2101. Parameters: args[0] defines whether the proxy facility is active
  2102. Returns: 0 on success; -1 on error
  2103. This capability enables or disables the delivery of interrupts through the
  2104. external proxy facility.
  2105. When enabled (args[0] != 0), every time the guest gets an external interrupt
  2106. delivered, it automatically exits into user space with a KVM_EXIT_EPR exit
  2107. to receive the topmost interrupt vector.
  2108. When disabled (args[0] == 0), behavior is as if this facility is unsupported.
  2109. When this capability is enabled, KVM_EXIT_EPR can occur.
  2110. 6.6 KVM_CAP_IRQ_MPIC
  2111. Architectures: ppc
  2112. Parameters: args[0] is the MPIC device fd
  2113. args[1] is the MPIC CPU number for this vcpu
  2114. This capability connects the vcpu to an in-kernel MPIC device.
  2115. 6.7 KVM_CAP_IRQ_XICS
  2116. Architectures: ppc
  2117. Parameters: args[0] is the XICS device fd
  2118. args[1] is the XICS CPU number (server ID) for this vcpu
  2119. This capability connects the vcpu to an in-kernel XICS device.