api.txt 115 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645
  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 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), a KVM_CAP_xyz constant, which
  53. means availability needs to be checked with KVM_CHECK_EXTENSION
  54. (see section 4.4), or 'none' which means that while not all kernels
  55. support this ioctl, there's no capability bit to check its
  56. availability: for kernels that don't support the ioctl,
  57. the ioctl returns -ENOTTY.
  58. Architectures: which instruction set architectures provide this ioctl.
  59. x86 includes both i386 and x86_64.
  60. Type: system, vm, or vcpu.
  61. Parameters: what parameters are accepted by the ioctl.
  62. Returns: the return value. General error numbers (EBADF, ENOMEM, EINVAL)
  63. are not detailed, but errors with specific meanings are.
  64. 4.1 KVM_GET_API_VERSION
  65. Capability: basic
  66. Architectures: all
  67. Type: system ioctl
  68. Parameters: none
  69. Returns: the constant KVM_API_VERSION (=12)
  70. This identifies the API version as the stable kvm API. It is not
  71. expected that this number will change. However, Linux 2.6.20 and
  72. 2.6.21 report earlier versions; these are not documented and not
  73. supported. Applications should refuse to run if KVM_GET_API_VERSION
  74. returns a value other than 12. If this check passes, all ioctls
  75. described as 'basic' will be available.
  76. 4.2 KVM_CREATE_VM
  77. Capability: basic
  78. Architectures: all
  79. Type: system ioctl
  80. Parameters: machine type identifier (KVM_VM_*)
  81. Returns: a VM fd that can be used to control the new virtual machine.
  82. The new VM has no virtual cpus and no memory. An mmap() of a VM fd
  83. will access the virtual machine's physical address space; offset zero
  84. corresponds to guest physical address zero. Use of mmap() on a VM fd
  85. is discouraged if userspace memory allocation (KVM_CAP_USER_MEMORY) is
  86. available.
  87. You most certainly want to use 0 as machine type.
  88. In order to create user controlled virtual machines on S390, check
  89. KVM_CAP_S390_UCONTROL and use the flag KVM_VM_S390_UCONTROL as
  90. privileged user (CAP_SYS_ADMIN).
  91. 4.3 KVM_GET_MSR_INDEX_LIST
  92. Capability: basic
  93. Architectures: x86
  94. Type: system
  95. Parameters: struct kvm_msr_list (in/out)
  96. Returns: 0 on success; -1 on error
  97. Errors:
  98. E2BIG: the msr index list is to be to fit in the array specified by
  99. the user.
  100. struct kvm_msr_list {
  101. __u32 nmsrs; /* number of msrs in entries */
  102. __u32 indices[0];
  103. };
  104. This ioctl returns the guest msrs that are supported. The list varies
  105. by kvm version and host processor, but does not change otherwise. The
  106. user fills in the size of the indices array in nmsrs, and in return
  107. kvm adjusts nmsrs to reflect the actual number of msrs and fills in
  108. the indices array with their numbers.
  109. Note: if kvm indicates supports MCE (KVM_CAP_MCE), then the MCE bank MSRs are
  110. not returned in the MSR list, as different vcpus can have a different number
  111. of banks, as set via the KVM_X86_SETUP_MCE ioctl.
  112. 4.4 KVM_CHECK_EXTENSION
  113. Capability: basic, KVM_CAP_CHECK_EXTENSION_VM for vm ioctl
  114. Architectures: all
  115. Type: system ioctl, vm ioctl
  116. Parameters: extension identifier (KVM_CAP_*)
  117. Returns: 0 if unsupported; 1 (or some other positive integer) if supported
  118. The API allows the application to query about extensions to the core
  119. kvm API. Userspace passes an extension identifier (an integer) and
  120. receives an integer that describes the extension availability.
  121. Generally 0 means no and 1 means yes, but some extensions may report
  122. additional information in the integer return value.
  123. Based on their initialization different VMs may have different capabilities.
  124. It is thus encouraged to use the vm ioctl to query for capabilities (available
  125. with KVM_CAP_CHECK_EXTENSION_VM on the vm fd)
  126. 4.5 KVM_GET_VCPU_MMAP_SIZE
  127. Capability: basic
  128. Architectures: all
  129. Type: system ioctl
  130. Parameters: none
  131. Returns: size of vcpu mmap area, in bytes
  132. The KVM_RUN ioctl (cf.) communicates with userspace via a shared
  133. memory region. This ioctl returns the size of that region. See the
  134. KVM_RUN documentation for details.
  135. 4.6 KVM_SET_MEMORY_REGION
  136. Capability: basic
  137. Architectures: all
  138. Type: vm ioctl
  139. Parameters: struct kvm_memory_region (in)
  140. Returns: 0 on success, -1 on error
  141. This ioctl is obsolete and has been removed.
  142. 4.7 KVM_CREATE_VCPU
  143. Capability: basic
  144. Architectures: all
  145. Type: vm ioctl
  146. Parameters: vcpu id (apic id on x86)
  147. Returns: vcpu fd on success, -1 on error
  148. This API adds a vcpu to a virtual machine. The vcpu id is a small integer
  149. in the range [0, max_vcpus).
  150. The recommended max_vcpus value can be retrieved using the KVM_CAP_NR_VCPUS of
  151. the KVM_CHECK_EXTENSION ioctl() at run-time.
  152. The maximum possible value for max_vcpus can be retrieved using the
  153. KVM_CAP_MAX_VCPUS of the KVM_CHECK_EXTENSION ioctl() at run-time.
  154. If the KVM_CAP_NR_VCPUS does not exist, you should assume that max_vcpus is 4
  155. cpus max.
  156. If the KVM_CAP_MAX_VCPUS does not exist, you should assume that max_vcpus is
  157. same as the value returned from KVM_CAP_NR_VCPUS.
  158. On powerpc using book3s_hv mode, the vcpus are mapped onto virtual
  159. threads in one or more virtual CPU cores. (This is because the
  160. hardware requires all the hardware threads in a CPU core to be in the
  161. same partition.) The KVM_CAP_PPC_SMT capability indicates the number
  162. of vcpus per virtual core (vcore). The vcore id is obtained by
  163. dividing the vcpu id by the number of vcpus per vcore. The vcpus in a
  164. given vcore will always be in the same physical core as each other
  165. (though that might be a different physical core from time to time).
  166. Userspace can control the threading (SMT) mode of the guest by its
  167. allocation of vcpu ids. For example, if userspace wants
  168. single-threaded guest vcpus, it should make all vcpu ids be a multiple
  169. of the number of vcpus per vcore.
  170. For virtual cpus that have been created with S390 user controlled virtual
  171. machines, the resulting vcpu fd can be memory mapped at page offset
  172. KVM_S390_SIE_PAGE_OFFSET in order to obtain a memory map of the virtual
  173. cpu's hardware control block.
  174. 4.8 KVM_GET_DIRTY_LOG (vm ioctl)
  175. Capability: basic
  176. Architectures: x86
  177. Type: vm ioctl
  178. Parameters: struct kvm_dirty_log (in/out)
  179. Returns: 0 on success, -1 on error
  180. /* for KVM_GET_DIRTY_LOG */
  181. struct kvm_dirty_log {
  182. __u32 slot;
  183. __u32 padding;
  184. union {
  185. void __user *dirty_bitmap; /* one bit per page */
  186. __u64 padding;
  187. };
  188. };
  189. Given a memory slot, return a bitmap containing any pages dirtied
  190. since the last call to this ioctl. Bit 0 is the first page in the
  191. memory slot. Ensure the entire structure is cleared to avoid padding
  192. issues.
  193. If KVM_CAP_MULTI_ADDRESS_SPACE is available, bits 16-31 specifies
  194. the address space for which you want to return the dirty bitmap.
  195. They must be less than the value that KVM_CHECK_EXTENSION returns for
  196. the KVM_CAP_MULTI_ADDRESS_SPACE capability.
  197. 4.9 KVM_SET_MEMORY_ALIAS
  198. Capability: basic
  199. Architectures: x86
  200. Type: vm ioctl
  201. Parameters: struct kvm_memory_alias (in)
  202. Returns: 0 (success), -1 (error)
  203. This ioctl is obsolete and has been removed.
  204. 4.10 KVM_RUN
  205. Capability: basic
  206. Architectures: all
  207. Type: vcpu ioctl
  208. Parameters: none
  209. Returns: 0 on success, -1 on error
  210. Errors:
  211. EINTR: an unmasked signal is pending
  212. This ioctl is used to run a guest virtual cpu. While there are no
  213. explicit parameters, there is an implicit parameter block that can be
  214. obtained by mmap()ing the vcpu fd at offset 0, with the size given by
  215. KVM_GET_VCPU_MMAP_SIZE. The parameter block is formatted as a 'struct
  216. kvm_run' (see below).
  217. 4.11 KVM_GET_REGS
  218. Capability: basic
  219. Architectures: all except ARM, arm64
  220. Type: vcpu ioctl
  221. Parameters: struct kvm_regs (out)
  222. Returns: 0 on success, -1 on error
  223. Reads the general purpose registers from the vcpu.
  224. /* x86 */
  225. struct kvm_regs {
  226. /* out (KVM_GET_REGS) / in (KVM_SET_REGS) */
  227. __u64 rax, rbx, rcx, rdx;
  228. __u64 rsi, rdi, rsp, rbp;
  229. __u64 r8, r9, r10, r11;
  230. __u64 r12, r13, r14, r15;
  231. __u64 rip, rflags;
  232. };
  233. /* mips */
  234. struct kvm_regs {
  235. /* out (KVM_GET_REGS) / in (KVM_SET_REGS) */
  236. __u64 gpr[32];
  237. __u64 hi;
  238. __u64 lo;
  239. __u64 pc;
  240. };
  241. 4.12 KVM_SET_REGS
  242. Capability: basic
  243. Architectures: all except ARM, arm64
  244. Type: vcpu ioctl
  245. Parameters: struct kvm_regs (in)
  246. Returns: 0 on success, -1 on error
  247. Writes the general purpose registers into the vcpu.
  248. See KVM_GET_REGS for the data structure.
  249. 4.13 KVM_GET_SREGS
  250. Capability: basic
  251. Architectures: x86, ppc
  252. Type: vcpu ioctl
  253. Parameters: struct kvm_sregs (out)
  254. Returns: 0 on success, -1 on error
  255. Reads special registers from the vcpu.
  256. /* x86 */
  257. struct kvm_sregs {
  258. struct kvm_segment cs, ds, es, fs, gs, ss;
  259. struct kvm_segment tr, ldt;
  260. struct kvm_dtable gdt, idt;
  261. __u64 cr0, cr2, cr3, cr4, cr8;
  262. __u64 efer;
  263. __u64 apic_base;
  264. __u64 interrupt_bitmap[(KVM_NR_INTERRUPTS + 63) / 64];
  265. };
  266. /* ppc -- see arch/powerpc/include/uapi/asm/kvm.h */
  267. interrupt_bitmap is a bitmap of pending external interrupts. At most
  268. one bit may be set. This interrupt has been acknowledged by the APIC
  269. but not yet injected into the cpu core.
  270. 4.14 KVM_SET_SREGS
  271. Capability: basic
  272. Architectures: x86, ppc
  273. Type: vcpu ioctl
  274. Parameters: struct kvm_sregs (in)
  275. Returns: 0 on success, -1 on error
  276. Writes special registers into the vcpu. See KVM_GET_SREGS for the
  277. data structures.
  278. 4.15 KVM_TRANSLATE
  279. Capability: basic
  280. Architectures: x86
  281. Type: vcpu ioctl
  282. Parameters: struct kvm_translation (in/out)
  283. Returns: 0 on success, -1 on error
  284. Translates a virtual address according to the vcpu's current address
  285. translation mode.
  286. struct kvm_translation {
  287. /* in */
  288. __u64 linear_address;
  289. /* out */
  290. __u64 physical_address;
  291. __u8 valid;
  292. __u8 writeable;
  293. __u8 usermode;
  294. __u8 pad[5];
  295. };
  296. 4.16 KVM_INTERRUPT
  297. Capability: basic
  298. Architectures: x86, ppc, mips
  299. Type: vcpu ioctl
  300. Parameters: struct kvm_interrupt (in)
  301. Returns: 0 on success, -1 on error
  302. Queues a hardware interrupt vector to be injected. This is only
  303. useful if in-kernel local APIC or equivalent is not used.
  304. /* for KVM_INTERRUPT */
  305. struct kvm_interrupt {
  306. /* in */
  307. __u32 irq;
  308. };
  309. X86:
  310. Note 'irq' is an interrupt vector, not an interrupt pin or line.
  311. PPC:
  312. Queues an external interrupt to be injected. This ioctl is overleaded
  313. with 3 different irq values:
  314. a) KVM_INTERRUPT_SET
  315. This injects an edge type external interrupt into the guest once it's ready
  316. to receive interrupts. When injected, the interrupt is done.
  317. b) KVM_INTERRUPT_UNSET
  318. This unsets any pending interrupt.
  319. Only available with KVM_CAP_PPC_UNSET_IRQ.
  320. c) KVM_INTERRUPT_SET_LEVEL
  321. This injects a level type external interrupt into the guest context. The
  322. interrupt stays pending until a specific ioctl with KVM_INTERRUPT_UNSET
  323. is triggered.
  324. Only available with KVM_CAP_PPC_IRQ_LEVEL.
  325. Note that any value for 'irq' other than the ones stated above is invalid
  326. and incurs unexpected behavior.
  327. MIPS:
  328. Queues an external interrupt to be injected into the virtual CPU. A negative
  329. interrupt number dequeues the interrupt.
  330. 4.17 KVM_DEBUG_GUEST
  331. Capability: basic
  332. Architectures: none
  333. Type: vcpu ioctl
  334. Parameters: none)
  335. Returns: -1 on error
  336. Support for this has been removed. Use KVM_SET_GUEST_DEBUG instead.
  337. 4.18 KVM_GET_MSRS
  338. Capability: basic
  339. Architectures: x86
  340. Type: vcpu ioctl
  341. Parameters: struct kvm_msrs (in/out)
  342. Returns: 0 on success, -1 on error
  343. Reads model-specific registers from the vcpu. Supported msr indices can
  344. be obtained using KVM_GET_MSR_INDEX_LIST.
  345. struct kvm_msrs {
  346. __u32 nmsrs; /* number of msrs in entries */
  347. __u32 pad;
  348. struct kvm_msr_entry entries[0];
  349. };
  350. struct kvm_msr_entry {
  351. __u32 index;
  352. __u32 reserved;
  353. __u64 data;
  354. };
  355. Application code should set the 'nmsrs' member (which indicates the
  356. size of the entries array) and the 'index' member of each array entry.
  357. kvm will fill in the 'data' member.
  358. 4.19 KVM_SET_MSRS
  359. Capability: basic
  360. Architectures: x86
  361. Type: vcpu ioctl
  362. Parameters: struct kvm_msrs (in)
  363. Returns: 0 on success, -1 on error
  364. Writes model-specific registers to the vcpu. See KVM_GET_MSRS for the
  365. data structures.
  366. Application code should set the 'nmsrs' member (which indicates the
  367. size of the entries array), and the 'index' and 'data' members of each
  368. array entry.
  369. 4.20 KVM_SET_CPUID
  370. Capability: basic
  371. Architectures: x86
  372. Type: vcpu ioctl
  373. Parameters: struct kvm_cpuid (in)
  374. Returns: 0 on success, -1 on error
  375. Defines the vcpu responses to the cpuid instruction. Applications
  376. should use the KVM_SET_CPUID2 ioctl if available.
  377. struct kvm_cpuid_entry {
  378. __u32 function;
  379. __u32 eax;
  380. __u32 ebx;
  381. __u32 ecx;
  382. __u32 edx;
  383. __u32 padding;
  384. };
  385. /* for KVM_SET_CPUID */
  386. struct kvm_cpuid {
  387. __u32 nent;
  388. __u32 padding;
  389. struct kvm_cpuid_entry entries[0];
  390. };
  391. 4.21 KVM_SET_SIGNAL_MASK
  392. Capability: basic
  393. Architectures: all
  394. Type: vcpu ioctl
  395. Parameters: struct kvm_signal_mask (in)
  396. Returns: 0 on success, -1 on error
  397. Defines which signals are blocked during execution of KVM_RUN. This
  398. signal mask temporarily overrides the threads signal mask. Any
  399. unblocked signal received (except SIGKILL and SIGSTOP, which retain
  400. their traditional behaviour) will cause KVM_RUN to return with -EINTR.
  401. Note the signal will only be delivered if not blocked by the original
  402. signal mask.
  403. /* for KVM_SET_SIGNAL_MASK */
  404. struct kvm_signal_mask {
  405. __u32 len;
  406. __u8 sigset[0];
  407. };
  408. 4.22 KVM_GET_FPU
  409. Capability: basic
  410. Architectures: x86
  411. Type: vcpu ioctl
  412. Parameters: struct kvm_fpu (out)
  413. Returns: 0 on success, -1 on error
  414. Reads the floating point state from 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.23 KVM_SET_FPU
  430. Capability: basic
  431. Architectures: x86
  432. Type: vcpu ioctl
  433. Parameters: struct kvm_fpu (in)
  434. Returns: 0 on success, -1 on error
  435. Writes the floating point state to the vcpu.
  436. /* for KVM_GET_FPU and KVM_SET_FPU */
  437. struct kvm_fpu {
  438. __u8 fpr[8][16];
  439. __u16 fcw;
  440. __u16 fsw;
  441. __u8 ftwx; /* in fxsave format */
  442. __u8 pad1;
  443. __u16 last_opcode;
  444. __u64 last_ip;
  445. __u64 last_dp;
  446. __u8 xmm[16][16];
  447. __u32 mxcsr;
  448. __u32 pad2;
  449. };
  450. 4.24 KVM_CREATE_IRQCHIP
  451. Capability: KVM_CAP_IRQCHIP, KVM_CAP_S390_IRQCHIP (s390)
  452. Architectures: x86, ARM, arm64, s390
  453. Type: vm ioctl
  454. Parameters: none
  455. Returns: 0 on success, -1 on error
  456. Creates an interrupt controller model in the kernel.
  457. On x86, creates a virtual ioapic, a virtual PIC (two PICs, nested), and sets up
  458. future vcpus to have a local APIC. IRQ routing for GSIs 0-15 is set to both
  459. PIC and IOAPIC; GSI 16-23 only go to the IOAPIC.
  460. On ARM/arm64, a GICv2 is created. Any other GIC versions require the usage of
  461. KVM_CREATE_DEVICE, which also supports creating a GICv2. Using
  462. KVM_CREATE_DEVICE is preferred over KVM_CREATE_IRQCHIP for GICv2.
  463. On s390, a dummy irq routing table is created.
  464. Note that on s390 the KVM_CAP_S390_IRQCHIP vm capability needs to be enabled
  465. before KVM_CREATE_IRQCHIP can be used.
  466. 4.25 KVM_IRQ_LINE
  467. Capability: KVM_CAP_IRQCHIP
  468. Architectures: x86, arm, arm64
  469. Type: vm ioctl
  470. Parameters: struct kvm_irq_level
  471. Returns: 0 on success, -1 on error
  472. Sets the level of a GSI input to the interrupt controller model in the kernel.
  473. On some architectures it is required that an interrupt controller model has
  474. been previously created with KVM_CREATE_IRQCHIP. Note that edge-triggered
  475. interrupts require the level to be set to 1 and then back to 0.
  476. On real hardware, interrupt pins can be active-low or active-high. This
  477. does not matter for the level field of struct kvm_irq_level: 1 always
  478. means active (asserted), 0 means inactive (deasserted).
  479. x86 allows the operating system to program the interrupt polarity
  480. (active-low/active-high) for level-triggered interrupts, and KVM used
  481. to consider the polarity. However, due to bitrot in the handling of
  482. active-low interrupts, the above convention is now valid on x86 too.
  483. This is signaled by KVM_CAP_X86_IOAPIC_POLARITY_IGNORED. Userspace
  484. should not present interrupts to the guest as active-low unless this
  485. capability is present (or unless it is not using the in-kernel irqchip,
  486. of course).
  487. ARM/arm64 can signal an interrupt either at the CPU level, or at the
  488. in-kernel irqchip (GIC), and for in-kernel irqchip can tell the GIC to
  489. use PPIs designated for specific cpus. The irq field is interpreted
  490. like this:
  491.  bits: | 31 ... 24 | 23 ... 16 | 15 ... 0 |
  492. field: | irq_type | vcpu_index | irq_id |
  493. The irq_type field has the following values:
  494. - irq_type[0]: out-of-kernel GIC: irq_id 0 is IRQ, irq_id 1 is FIQ
  495. - irq_type[1]: in-kernel GIC: SPI, irq_id between 32 and 1019 (incl.)
  496. (the vcpu_index field is ignored)
  497. - irq_type[2]: in-kernel GIC: PPI, irq_id between 16 and 31 (incl.)
  498. (The irq_id field thus corresponds nicely to the IRQ ID in the ARM GIC specs)
  499. In both cases, level is used to assert/deassert the line.
  500. struct kvm_irq_level {
  501. union {
  502. __u32 irq; /* GSI */
  503. __s32 status; /* not used for KVM_IRQ_LEVEL */
  504. };
  505. __u32 level; /* 0 or 1 */
  506. };
  507. 4.26 KVM_GET_IRQCHIP
  508. Capability: KVM_CAP_IRQCHIP
  509. Architectures: x86
  510. Type: vm ioctl
  511. Parameters: struct kvm_irqchip (in/out)
  512. Returns: 0 on success, -1 on error
  513. Reads the state of a kernel interrupt controller created with
  514. KVM_CREATE_IRQCHIP into a buffer provided by the caller.
  515. struct kvm_irqchip {
  516. __u32 chip_id; /* 0 = PIC1, 1 = PIC2, 2 = IOAPIC */
  517. __u32 pad;
  518. union {
  519. char dummy[512]; /* reserving space */
  520. struct kvm_pic_state pic;
  521. struct kvm_ioapic_state ioapic;
  522. } chip;
  523. };
  524. 4.27 KVM_SET_IRQCHIP
  525. Capability: KVM_CAP_IRQCHIP
  526. Architectures: x86
  527. Type: vm ioctl
  528. Parameters: struct kvm_irqchip (in)
  529. Returns: 0 on success, -1 on error
  530. Sets the state of a kernel interrupt controller created with
  531. KVM_CREATE_IRQCHIP from a buffer provided by the caller.
  532. struct kvm_irqchip {
  533. __u32 chip_id; /* 0 = PIC1, 1 = PIC2, 2 = IOAPIC */
  534. __u32 pad;
  535. union {
  536. char dummy[512]; /* reserving space */
  537. struct kvm_pic_state pic;
  538. struct kvm_ioapic_state ioapic;
  539. } chip;
  540. };
  541. 4.28 KVM_XEN_HVM_CONFIG
  542. Capability: KVM_CAP_XEN_HVM
  543. Architectures: x86
  544. Type: vm ioctl
  545. Parameters: struct kvm_xen_hvm_config (in)
  546. Returns: 0 on success, -1 on error
  547. Sets the MSR that the Xen HVM guest uses to initialize its hypercall
  548. page, and provides the starting address and size of the hypercall
  549. blobs in userspace. When the guest writes the MSR, kvm copies one
  550. page of a blob (32- or 64-bit, depending on the vcpu mode) to guest
  551. memory.
  552. struct kvm_xen_hvm_config {
  553. __u32 flags;
  554. __u32 msr;
  555. __u64 blob_addr_32;
  556. __u64 blob_addr_64;
  557. __u8 blob_size_32;
  558. __u8 blob_size_64;
  559. __u8 pad2[30];
  560. };
  561. 4.29 KVM_GET_CLOCK
  562. Capability: KVM_CAP_ADJUST_CLOCK
  563. Architectures: x86
  564. Type: vm ioctl
  565. Parameters: struct kvm_clock_data (out)
  566. Returns: 0 on success, -1 on error
  567. Gets the current timestamp of kvmclock as seen by the current guest. In
  568. conjunction with KVM_SET_CLOCK, it is used to ensure monotonicity on scenarios
  569. such as migration.
  570. struct kvm_clock_data {
  571. __u64 clock; /* kvmclock current value */
  572. __u32 flags;
  573. __u32 pad[9];
  574. };
  575. 4.30 KVM_SET_CLOCK
  576. Capability: KVM_CAP_ADJUST_CLOCK
  577. Architectures: x86
  578. Type: vm ioctl
  579. Parameters: struct kvm_clock_data (in)
  580. Returns: 0 on success, -1 on error
  581. Sets the current timestamp of kvmclock to the value specified in its parameter.
  582. In conjunction with KVM_GET_CLOCK, it is used to ensure monotonicity on scenarios
  583. such as migration.
  584. struct kvm_clock_data {
  585. __u64 clock; /* kvmclock current value */
  586. __u32 flags;
  587. __u32 pad[9];
  588. };
  589. 4.31 KVM_GET_VCPU_EVENTS
  590. Capability: KVM_CAP_VCPU_EVENTS
  591. Extended by: KVM_CAP_INTR_SHADOW
  592. Architectures: x86
  593. Type: vm ioctl
  594. Parameters: struct kvm_vcpu_event (out)
  595. Returns: 0 on success, -1 on error
  596. Gets currently pending exceptions, interrupts, and NMIs as well as related
  597. states of the vcpu.
  598. struct kvm_vcpu_events {
  599. struct {
  600. __u8 injected;
  601. __u8 nr;
  602. __u8 has_error_code;
  603. __u8 pad;
  604. __u32 error_code;
  605. } exception;
  606. struct {
  607. __u8 injected;
  608. __u8 nr;
  609. __u8 soft;
  610. __u8 shadow;
  611. } interrupt;
  612. struct {
  613. __u8 injected;
  614. __u8 pending;
  615. __u8 masked;
  616. __u8 pad;
  617. } nmi;
  618. __u32 sipi_vector;
  619. __u32 flags;
  620. struct {
  621. __u8 smm;
  622. __u8 pending;
  623. __u8 smm_inside_nmi;
  624. __u8 latched_init;
  625. } smi;
  626. };
  627. Only two fields are defined in the flags field:
  628. - KVM_VCPUEVENT_VALID_SHADOW may be set in the flags field to signal that
  629. interrupt.shadow contains a valid state.
  630. - KVM_VCPUEVENT_VALID_SMM may be set in the flags field to signal that
  631. smi contains a valid state.
  632. 4.32 KVM_SET_VCPU_EVENTS
  633. Capability: KVM_CAP_VCPU_EVENTS
  634. Extended by: KVM_CAP_INTR_SHADOW
  635. Architectures: x86
  636. Type: vm ioctl
  637. Parameters: struct kvm_vcpu_event (in)
  638. Returns: 0 on success, -1 on error
  639. Set pending exceptions, interrupts, and NMIs as well as related states of the
  640. vcpu.
  641. See KVM_GET_VCPU_EVENTS for the data structure.
  642. Fields that may be modified asynchronously by running VCPUs can be excluded
  643. from the update. These fields are nmi.pending, sipi_vector, smi.smm,
  644. smi.pending. Keep the corresponding bits in the flags field cleared to
  645. suppress overwriting the current in-kernel state. The bits are:
  646. KVM_VCPUEVENT_VALID_NMI_PENDING - transfer nmi.pending to the kernel
  647. KVM_VCPUEVENT_VALID_SIPI_VECTOR - transfer sipi_vector
  648. KVM_VCPUEVENT_VALID_SMM - transfer the smi sub-struct.
  649. If KVM_CAP_INTR_SHADOW is available, KVM_VCPUEVENT_VALID_SHADOW can be set in
  650. the flags field to signal that interrupt.shadow contains a valid state and
  651. shall be written into the VCPU.
  652. KVM_VCPUEVENT_VALID_SMM can only be set if KVM_CAP_X86_SMM is available.
  653. 4.33 KVM_GET_DEBUGREGS
  654. Capability: KVM_CAP_DEBUGREGS
  655. Architectures: x86
  656. Type: vm ioctl
  657. Parameters: struct kvm_debugregs (out)
  658. Returns: 0 on success, -1 on error
  659. Reads debug registers from the vcpu.
  660. struct kvm_debugregs {
  661. __u64 db[4];
  662. __u64 dr6;
  663. __u64 dr7;
  664. __u64 flags;
  665. __u64 reserved[9];
  666. };
  667. 4.34 KVM_SET_DEBUGREGS
  668. Capability: KVM_CAP_DEBUGREGS
  669. Architectures: x86
  670. Type: vm ioctl
  671. Parameters: struct kvm_debugregs (in)
  672. Returns: 0 on success, -1 on error
  673. Writes debug registers into the vcpu.
  674. See KVM_GET_DEBUGREGS for the data structure. The flags field is unused
  675. yet and must be cleared on entry.
  676. 4.35 KVM_SET_USER_MEMORY_REGION
  677. Capability: KVM_CAP_USER_MEM
  678. Architectures: all
  679. Type: vm ioctl
  680. Parameters: struct kvm_userspace_memory_region (in)
  681. Returns: 0 on success, -1 on error
  682. struct kvm_userspace_memory_region {
  683. __u32 slot;
  684. __u32 flags;
  685. __u64 guest_phys_addr;
  686. __u64 memory_size; /* bytes */
  687. __u64 userspace_addr; /* start of the userspace allocated memory */
  688. };
  689. /* for kvm_memory_region::flags */
  690. #define KVM_MEM_LOG_DIRTY_PAGES (1UL << 0)
  691. #define KVM_MEM_READONLY (1UL << 1)
  692. This ioctl allows the user to create or modify a guest physical memory
  693. slot. When changing an existing slot, it may be moved in the guest
  694. physical memory space, or its flags may be modified. It may not be
  695. resized. Slots may not overlap in guest physical address space.
  696. If KVM_CAP_MULTI_ADDRESS_SPACE is available, bits 16-31 of "slot"
  697. specifies the address space which is being modified. They must be
  698. less than the value that KVM_CHECK_EXTENSION returns for the
  699. KVM_CAP_MULTI_ADDRESS_SPACE capability. Slots in separate address spaces
  700. are unrelated; the restriction on overlapping slots only applies within
  701. each address space.
  702. Memory for the region is taken starting at the address denoted by the
  703. field userspace_addr, which must point at user addressable memory for
  704. the entire memory slot size. Any object may back this memory, including
  705. anonymous memory, ordinary files, and hugetlbfs.
  706. It is recommended that the lower 21 bits of guest_phys_addr and userspace_addr
  707. be identical. This allows large pages in the guest to be backed by large
  708. pages in the host.
  709. The flags field supports two flags: KVM_MEM_LOG_DIRTY_PAGES and
  710. KVM_MEM_READONLY. The former can be set to instruct KVM to keep track of
  711. writes to memory within the slot. See KVM_GET_DIRTY_LOG ioctl to know how to
  712. use it. The latter can be set, if KVM_CAP_READONLY_MEM capability allows it,
  713. to make a new slot read-only. In this case, writes to this memory will be
  714. posted to userspace as KVM_EXIT_MMIO exits.
  715. When the KVM_CAP_SYNC_MMU capability is available, changes in the backing of
  716. the memory region are automatically reflected into the guest. For example, an
  717. mmap() that affects the region will be made visible immediately. Another
  718. example is madvise(MADV_DROP).
  719. It is recommended to use this API instead of the KVM_SET_MEMORY_REGION ioctl.
  720. The KVM_SET_MEMORY_REGION does not allow fine grained control over memory
  721. allocation and is deprecated.
  722. 4.36 KVM_SET_TSS_ADDR
  723. Capability: KVM_CAP_SET_TSS_ADDR
  724. Architectures: x86
  725. Type: vm ioctl
  726. Parameters: unsigned long tss_address (in)
  727. Returns: 0 on success, -1 on error
  728. This ioctl defines the physical address of a three-page region in the guest
  729. physical address space. The region must be within the first 4GB of the
  730. guest physical address space and must not conflict with any memory slot
  731. or any mmio address. The guest may malfunction if it accesses this memory
  732. region.
  733. This ioctl is required on Intel-based hosts. This is needed on Intel hardware
  734. because of a quirk in the virtualization implementation (see the internals
  735. documentation when it pops into existence).
  736. 4.37 KVM_ENABLE_CAP
  737. Capability: KVM_CAP_ENABLE_CAP, KVM_CAP_ENABLE_CAP_VM
  738. Architectures: x86 (only KVM_CAP_ENABLE_CAP_VM),
  739. mips (only KVM_CAP_ENABLE_CAP), ppc, s390
  740. Type: vcpu ioctl, vm ioctl (with KVM_CAP_ENABLE_CAP_VM)
  741. Parameters: struct kvm_enable_cap (in)
  742. Returns: 0 on success; -1 on error
  743. +Not all extensions are enabled by default. Using this ioctl the application
  744. can enable an extension, making it available to the guest.
  745. On systems that do not support this ioctl, it always fails. On systems that
  746. do support it, it only works for extensions that are supported for enablement.
  747. To check if a capability can be enabled, the KVM_CHECK_EXTENSION ioctl should
  748. be used.
  749. struct kvm_enable_cap {
  750. /* in */
  751. __u32 cap;
  752. The capability that is supposed to get enabled.
  753. __u32 flags;
  754. A bitfield indicating future enhancements. Has to be 0 for now.
  755. __u64 args[4];
  756. Arguments for enabling a feature. If a feature needs initial values to
  757. function properly, this is the place to put them.
  758. __u8 pad[64];
  759. };
  760. The vcpu ioctl should be used for vcpu-specific capabilities, the vm ioctl
  761. for vm-wide capabilities.
  762. 4.38 KVM_GET_MP_STATE
  763. Capability: KVM_CAP_MP_STATE
  764. Architectures: x86, s390, arm, arm64
  765. Type: vcpu ioctl
  766. Parameters: struct kvm_mp_state (out)
  767. Returns: 0 on success; -1 on error
  768. struct kvm_mp_state {
  769. __u32 mp_state;
  770. };
  771. Returns the vcpu's current "multiprocessing state" (though also valid on
  772. uniprocessor guests).
  773. Possible values are:
  774. - KVM_MP_STATE_RUNNABLE: the vcpu is currently running [x86,arm/arm64]
  775. - KVM_MP_STATE_UNINITIALIZED: the vcpu is an application processor (AP)
  776. which has not yet received an INIT signal [x86]
  777. - KVM_MP_STATE_INIT_RECEIVED: the vcpu has received an INIT signal, and is
  778. now ready for a SIPI [x86]
  779. - KVM_MP_STATE_HALTED: the vcpu has executed a HLT instruction and
  780. is waiting for an interrupt [x86]
  781. - KVM_MP_STATE_SIPI_RECEIVED: the vcpu has just received a SIPI (vector
  782. accessible via KVM_GET_VCPU_EVENTS) [x86]
  783. - KVM_MP_STATE_STOPPED: the vcpu is stopped [s390,arm/arm64]
  784. - KVM_MP_STATE_CHECK_STOP: the vcpu is in a special error state [s390]
  785. - KVM_MP_STATE_OPERATING: the vcpu is operating (running or halted)
  786. [s390]
  787. - KVM_MP_STATE_LOAD: the vcpu is in a special load/startup state
  788. [s390]
  789. On x86, this ioctl is only useful after KVM_CREATE_IRQCHIP. Without an
  790. in-kernel irqchip, the multiprocessing state must be maintained by userspace on
  791. these architectures.
  792. For arm/arm64:
  793. The only states that are valid are KVM_MP_STATE_STOPPED and
  794. KVM_MP_STATE_RUNNABLE which reflect if the vcpu is paused or not.
  795. 4.39 KVM_SET_MP_STATE
  796. Capability: KVM_CAP_MP_STATE
  797. Architectures: x86, s390, arm, arm64
  798. Type: vcpu ioctl
  799. Parameters: struct kvm_mp_state (in)
  800. Returns: 0 on success; -1 on error
  801. Sets the vcpu's current "multiprocessing state"; see KVM_GET_MP_STATE for
  802. arguments.
  803. On x86, this ioctl is only useful after KVM_CREATE_IRQCHIP. Without an
  804. in-kernel irqchip, the multiprocessing state must be maintained by userspace on
  805. these architectures.
  806. For arm/arm64:
  807. The only states that are valid are KVM_MP_STATE_STOPPED and
  808. KVM_MP_STATE_RUNNABLE which reflect if the vcpu should be paused or not.
  809. 4.40 KVM_SET_IDENTITY_MAP_ADDR
  810. Capability: KVM_CAP_SET_IDENTITY_MAP_ADDR
  811. Architectures: x86
  812. Type: vm ioctl
  813. Parameters: unsigned long identity (in)
  814. Returns: 0 on success, -1 on error
  815. This ioctl defines the physical address of a one-page region in the guest
  816. physical address space. The region must be within the first 4GB of the
  817. guest physical address space and must not conflict with any memory slot
  818. or any mmio address. The guest may malfunction if it accesses this memory
  819. region.
  820. This ioctl is required on Intel-based hosts. This is needed on Intel hardware
  821. because of a quirk in the virtualization implementation (see the internals
  822. documentation when it pops into existence).
  823. 4.41 KVM_SET_BOOT_CPU_ID
  824. Capability: KVM_CAP_SET_BOOT_CPU_ID
  825. Architectures: x86
  826. Type: vm ioctl
  827. Parameters: unsigned long vcpu_id
  828. Returns: 0 on success, -1 on error
  829. Define which vcpu is the Bootstrap Processor (BSP). Values are the same
  830. as the vcpu id in KVM_CREATE_VCPU. If this ioctl is not called, the default
  831. is vcpu 0.
  832. 4.42 KVM_GET_XSAVE
  833. Capability: KVM_CAP_XSAVE
  834. Architectures: x86
  835. Type: vcpu ioctl
  836. Parameters: struct kvm_xsave (out)
  837. Returns: 0 on success, -1 on error
  838. struct kvm_xsave {
  839. __u32 region[1024];
  840. };
  841. This ioctl would copy current vcpu's xsave struct to the userspace.
  842. 4.43 KVM_SET_XSAVE
  843. Capability: KVM_CAP_XSAVE
  844. Architectures: x86
  845. Type: vcpu ioctl
  846. Parameters: struct kvm_xsave (in)
  847. Returns: 0 on success, -1 on error
  848. struct kvm_xsave {
  849. __u32 region[1024];
  850. };
  851. This ioctl would copy userspace's xsave struct to the kernel.
  852. 4.44 KVM_GET_XCRS
  853. Capability: KVM_CAP_XCRS
  854. Architectures: x86
  855. Type: vcpu ioctl
  856. Parameters: struct kvm_xcrs (out)
  857. Returns: 0 on success, -1 on error
  858. struct kvm_xcr {
  859. __u32 xcr;
  860. __u32 reserved;
  861. __u64 value;
  862. };
  863. struct kvm_xcrs {
  864. __u32 nr_xcrs;
  865. __u32 flags;
  866. struct kvm_xcr xcrs[KVM_MAX_XCRS];
  867. __u64 padding[16];
  868. };
  869. This ioctl would copy current vcpu's xcrs to the userspace.
  870. 4.45 KVM_SET_XCRS
  871. Capability: KVM_CAP_XCRS
  872. Architectures: x86
  873. Type: vcpu ioctl
  874. Parameters: struct kvm_xcrs (in)
  875. Returns: 0 on success, -1 on error
  876. struct kvm_xcr {
  877. __u32 xcr;
  878. __u32 reserved;
  879. __u64 value;
  880. };
  881. struct kvm_xcrs {
  882. __u32 nr_xcrs;
  883. __u32 flags;
  884. struct kvm_xcr xcrs[KVM_MAX_XCRS];
  885. __u64 padding[16];
  886. };
  887. This ioctl would set vcpu's xcr to the value userspace specified.
  888. 4.46 KVM_GET_SUPPORTED_CPUID
  889. Capability: KVM_CAP_EXT_CPUID
  890. Architectures: x86
  891. Type: system ioctl
  892. Parameters: struct kvm_cpuid2 (in/out)
  893. Returns: 0 on success, -1 on error
  894. struct kvm_cpuid2 {
  895. __u32 nent;
  896. __u32 padding;
  897. struct kvm_cpuid_entry2 entries[0];
  898. };
  899. #define KVM_CPUID_FLAG_SIGNIFCANT_INDEX BIT(0)
  900. #define KVM_CPUID_FLAG_STATEFUL_FUNC BIT(1)
  901. #define KVM_CPUID_FLAG_STATE_READ_NEXT BIT(2)
  902. struct kvm_cpuid_entry2 {
  903. __u32 function;
  904. __u32 index;
  905. __u32 flags;
  906. __u32 eax;
  907. __u32 ebx;
  908. __u32 ecx;
  909. __u32 edx;
  910. __u32 padding[3];
  911. };
  912. This ioctl returns x86 cpuid features which are supported by both the hardware
  913. and kvm. Userspace can use the information returned by this ioctl to
  914. construct cpuid information (for KVM_SET_CPUID2) that is consistent with
  915. hardware, kernel, and userspace capabilities, and with user requirements (for
  916. example, the user may wish to constrain cpuid to emulate older hardware,
  917. or for feature consistency across a cluster).
  918. Userspace invokes KVM_GET_SUPPORTED_CPUID by passing a kvm_cpuid2 structure
  919. with the 'nent' field indicating the number of entries in the variable-size
  920. array 'entries'. If the number of entries is too low to describe the cpu
  921. capabilities, an error (E2BIG) is returned. If the number is too high,
  922. the 'nent' field is adjusted and an error (ENOMEM) is returned. If the
  923. number is just right, the 'nent' field is adjusted to the number of valid
  924. entries in the 'entries' array, which is then filled.
  925. The entries returned are the host cpuid as returned by the cpuid instruction,
  926. with unknown or unsupported features masked out. Some features (for example,
  927. x2apic), may not be present in the host cpu, but are exposed by kvm if it can
  928. emulate them efficiently. The fields in each entry are defined as follows:
  929. function: the eax value used to obtain the entry
  930. index: the ecx value used to obtain the entry (for entries that are
  931. affected by ecx)
  932. flags: an OR of zero or more of the following:
  933. KVM_CPUID_FLAG_SIGNIFCANT_INDEX:
  934. if the index field is valid
  935. KVM_CPUID_FLAG_STATEFUL_FUNC:
  936. if cpuid for this function returns different values for successive
  937. invocations; there will be several entries with the same function,
  938. all with this flag set
  939. KVM_CPUID_FLAG_STATE_READ_NEXT:
  940. for KVM_CPUID_FLAG_STATEFUL_FUNC entries, set if this entry is
  941. the first entry to be read by a cpu
  942. eax, ebx, ecx, edx: the values returned by the cpuid instruction for
  943. this function/index combination
  944. The TSC deadline timer feature (CPUID leaf 1, ecx[24]) is always returned
  945. as false, since the feature depends on KVM_CREATE_IRQCHIP for local APIC
  946. support. Instead it is reported via
  947. ioctl(KVM_CHECK_EXTENSION, KVM_CAP_TSC_DEADLINE_TIMER)
  948. if that returns true and you use KVM_CREATE_IRQCHIP, or if you emulate the
  949. feature in userspace, then you can enable the feature for KVM_SET_CPUID2.
  950. 4.47 KVM_PPC_GET_PVINFO
  951. Capability: KVM_CAP_PPC_GET_PVINFO
  952. Architectures: ppc
  953. Type: vm ioctl
  954. Parameters: struct kvm_ppc_pvinfo (out)
  955. Returns: 0 on success, !0 on error
  956. struct kvm_ppc_pvinfo {
  957. __u32 flags;
  958. __u32 hcall[4];
  959. __u8 pad[108];
  960. };
  961. This ioctl fetches PV specific information that need to be passed to the guest
  962. using the device tree or other means from vm context.
  963. The hcall array defines 4 instructions that make up a hypercall.
  964. If any additional field gets added to this structure later on, a bit for that
  965. additional piece of information will be set in the flags bitmap.
  966. The flags bitmap is defined as:
  967. /* the host supports the ePAPR idle hcall
  968. #define KVM_PPC_PVINFO_FLAGS_EV_IDLE (1<<0)
  969. 4.48 KVM_ASSIGN_PCI_DEVICE (deprecated)
  970. Capability: none
  971. Architectures: x86
  972. Type: vm ioctl
  973. Parameters: struct kvm_assigned_pci_dev (in)
  974. Returns: 0 on success, -1 on error
  975. Assigns a host PCI device to the VM.
  976. struct kvm_assigned_pci_dev {
  977. __u32 assigned_dev_id;
  978. __u32 busnr;
  979. __u32 devfn;
  980. __u32 flags;
  981. __u32 segnr;
  982. union {
  983. __u32 reserved[11];
  984. };
  985. };
  986. The PCI device is specified by the triple segnr, busnr, and devfn.
  987. Identification in succeeding service requests is done via assigned_dev_id. The
  988. following flags are specified:
  989. /* Depends on KVM_CAP_IOMMU */
  990. #define KVM_DEV_ASSIGN_ENABLE_IOMMU (1 << 0)
  991. /* The following two depend on KVM_CAP_PCI_2_3 */
  992. #define KVM_DEV_ASSIGN_PCI_2_3 (1 << 1)
  993. #define KVM_DEV_ASSIGN_MASK_INTX (1 << 2)
  994. If KVM_DEV_ASSIGN_PCI_2_3 is set, the kernel will manage legacy INTx interrupts
  995. via the PCI-2.3-compliant device-level mask, thus enable IRQ sharing with other
  996. assigned devices or host devices. KVM_DEV_ASSIGN_MASK_INTX specifies the
  997. guest's view on the INTx mask, see KVM_ASSIGN_SET_INTX_MASK for details.
  998. The KVM_DEV_ASSIGN_ENABLE_IOMMU flag is a mandatory option to ensure
  999. isolation of the device. Usages not specifying this flag are deprecated.
  1000. Only PCI header type 0 devices with PCI BAR resources are supported by
  1001. device assignment. The user requesting this ioctl must have read/write
  1002. access to the PCI sysfs resource files associated with the device.
  1003. Errors:
  1004. ENOTTY: kernel does not support this ioctl
  1005. Other error conditions may be defined by individual device types or
  1006. have their standard meanings.
  1007. 4.49 KVM_DEASSIGN_PCI_DEVICE (deprecated)
  1008. Capability: none
  1009. Architectures: x86
  1010. Type: vm ioctl
  1011. Parameters: struct kvm_assigned_pci_dev (in)
  1012. Returns: 0 on success, -1 on error
  1013. Ends PCI device assignment, releasing all associated resources.
  1014. See KVM_ASSIGN_PCI_DEVICE for the data structure. Only assigned_dev_id is
  1015. used in kvm_assigned_pci_dev to identify the device.
  1016. Errors:
  1017. ENOTTY: kernel does not support this ioctl
  1018. Other error conditions may be defined by individual device types or
  1019. have their standard meanings.
  1020. 4.50 KVM_ASSIGN_DEV_IRQ (deprecated)
  1021. Capability: KVM_CAP_ASSIGN_DEV_IRQ
  1022. Architectures: x86
  1023. Type: vm ioctl
  1024. Parameters: struct kvm_assigned_irq (in)
  1025. Returns: 0 on success, -1 on error
  1026. Assigns an IRQ to a passed-through device.
  1027. struct kvm_assigned_irq {
  1028. __u32 assigned_dev_id;
  1029. __u32 host_irq; /* ignored (legacy field) */
  1030. __u32 guest_irq;
  1031. __u32 flags;
  1032. union {
  1033. __u32 reserved[12];
  1034. };
  1035. };
  1036. The following flags are defined:
  1037. #define KVM_DEV_IRQ_HOST_INTX (1 << 0)
  1038. #define KVM_DEV_IRQ_HOST_MSI (1 << 1)
  1039. #define KVM_DEV_IRQ_HOST_MSIX (1 << 2)
  1040. #define KVM_DEV_IRQ_GUEST_INTX (1 << 8)
  1041. #define KVM_DEV_IRQ_GUEST_MSI (1 << 9)
  1042. #define KVM_DEV_IRQ_GUEST_MSIX (1 << 10)
  1043. It is not valid to specify multiple types per host or guest IRQ. However, the
  1044. IRQ type of host and guest can differ or can even be null.
  1045. Errors:
  1046. ENOTTY: kernel does not support this ioctl
  1047. Other error conditions may be defined by individual device types or
  1048. have their standard meanings.
  1049. 4.51 KVM_DEASSIGN_DEV_IRQ (deprecated)
  1050. Capability: KVM_CAP_ASSIGN_DEV_IRQ
  1051. Architectures: x86
  1052. Type: vm ioctl
  1053. Parameters: struct kvm_assigned_irq (in)
  1054. Returns: 0 on success, -1 on error
  1055. Ends an IRQ assignment to a passed-through device.
  1056. See KVM_ASSIGN_DEV_IRQ for the data structure. The target device is specified
  1057. by assigned_dev_id, flags must correspond to the IRQ type specified on
  1058. KVM_ASSIGN_DEV_IRQ. Partial deassignment of host or guest IRQ is allowed.
  1059. 4.52 KVM_SET_GSI_ROUTING
  1060. Capability: KVM_CAP_IRQ_ROUTING
  1061. Architectures: x86 s390
  1062. Type: vm ioctl
  1063. Parameters: struct kvm_irq_routing (in)
  1064. Returns: 0 on success, -1 on error
  1065. Sets the GSI routing table entries, overwriting any previously set entries.
  1066. struct kvm_irq_routing {
  1067. __u32 nr;
  1068. __u32 flags;
  1069. struct kvm_irq_routing_entry entries[0];
  1070. };
  1071. No flags are specified so far, the corresponding field must be set to zero.
  1072. struct kvm_irq_routing_entry {
  1073. __u32 gsi;
  1074. __u32 type;
  1075. __u32 flags;
  1076. __u32 pad;
  1077. union {
  1078. struct kvm_irq_routing_irqchip irqchip;
  1079. struct kvm_irq_routing_msi msi;
  1080. struct kvm_irq_routing_s390_adapter adapter;
  1081. __u32 pad[8];
  1082. } u;
  1083. };
  1084. /* gsi routing entry types */
  1085. #define KVM_IRQ_ROUTING_IRQCHIP 1
  1086. #define KVM_IRQ_ROUTING_MSI 2
  1087. #define KVM_IRQ_ROUTING_S390_ADAPTER 3
  1088. No flags are specified so far, the corresponding field must be set to zero.
  1089. struct kvm_irq_routing_irqchip {
  1090. __u32 irqchip;
  1091. __u32 pin;
  1092. };
  1093. struct kvm_irq_routing_msi {
  1094. __u32 address_lo;
  1095. __u32 address_hi;
  1096. __u32 data;
  1097. __u32 pad;
  1098. };
  1099. struct kvm_irq_routing_s390_adapter {
  1100. __u64 ind_addr;
  1101. __u64 summary_addr;
  1102. __u64 ind_offset;
  1103. __u32 summary_offset;
  1104. __u32 adapter_id;
  1105. };
  1106. 4.53 KVM_ASSIGN_SET_MSIX_NR (deprecated)
  1107. Capability: none
  1108. Architectures: x86
  1109. Type: vm ioctl
  1110. Parameters: struct kvm_assigned_msix_nr (in)
  1111. Returns: 0 on success, -1 on error
  1112. Set the number of MSI-X interrupts for an assigned device. The number is
  1113. reset again by terminating the MSI-X assignment of the device via
  1114. KVM_DEASSIGN_DEV_IRQ. Calling this service more than once at any earlier
  1115. point will fail.
  1116. struct kvm_assigned_msix_nr {
  1117. __u32 assigned_dev_id;
  1118. __u16 entry_nr;
  1119. __u16 padding;
  1120. };
  1121. #define KVM_MAX_MSIX_PER_DEV 256
  1122. 4.54 KVM_ASSIGN_SET_MSIX_ENTRY (deprecated)
  1123. Capability: none
  1124. Architectures: x86
  1125. Type: vm ioctl
  1126. Parameters: struct kvm_assigned_msix_entry (in)
  1127. Returns: 0 on success, -1 on error
  1128. Specifies the routing of an MSI-X assigned device interrupt to a GSI. Setting
  1129. the GSI vector to zero means disabling the interrupt.
  1130. struct kvm_assigned_msix_entry {
  1131. __u32 assigned_dev_id;
  1132. __u32 gsi;
  1133. __u16 entry; /* The index of entry in the MSI-X table */
  1134. __u16 padding[3];
  1135. };
  1136. Errors:
  1137. ENOTTY: kernel does not support this ioctl
  1138. Other error conditions may be defined by individual device types or
  1139. have their standard meanings.
  1140. 4.55 KVM_SET_TSC_KHZ
  1141. Capability: KVM_CAP_TSC_CONTROL
  1142. Architectures: x86
  1143. Type: vcpu ioctl
  1144. Parameters: virtual tsc_khz
  1145. Returns: 0 on success, -1 on error
  1146. Specifies the tsc frequency for the virtual machine. The unit of the
  1147. frequency is KHz.
  1148. 4.56 KVM_GET_TSC_KHZ
  1149. Capability: KVM_CAP_GET_TSC_KHZ
  1150. Architectures: x86
  1151. Type: vcpu ioctl
  1152. Parameters: none
  1153. Returns: virtual tsc-khz on success, negative value on error
  1154. Returns the tsc frequency of the guest. The unit of the return value is
  1155. KHz. If the host has unstable tsc this ioctl returns -EIO instead as an
  1156. error.
  1157. 4.57 KVM_GET_LAPIC
  1158. Capability: KVM_CAP_IRQCHIP
  1159. Architectures: x86
  1160. Type: vcpu ioctl
  1161. Parameters: struct kvm_lapic_state (out)
  1162. Returns: 0 on success, -1 on error
  1163. #define KVM_APIC_REG_SIZE 0x400
  1164. struct kvm_lapic_state {
  1165. char regs[KVM_APIC_REG_SIZE];
  1166. };
  1167. Reads the Local APIC registers and copies them into the input argument. The
  1168. data format and layout are the same as documented in the architecture manual.
  1169. 4.58 KVM_SET_LAPIC
  1170. Capability: KVM_CAP_IRQCHIP
  1171. Architectures: x86
  1172. Type: vcpu ioctl
  1173. Parameters: struct kvm_lapic_state (in)
  1174. Returns: 0 on success, -1 on error
  1175. #define KVM_APIC_REG_SIZE 0x400
  1176. struct kvm_lapic_state {
  1177. char regs[KVM_APIC_REG_SIZE];
  1178. };
  1179. Copies the input argument into the Local APIC registers. The data format
  1180. and layout are the same as documented in the architecture manual.
  1181. 4.59 KVM_IOEVENTFD
  1182. Capability: KVM_CAP_IOEVENTFD
  1183. Architectures: all
  1184. Type: vm ioctl
  1185. Parameters: struct kvm_ioeventfd (in)
  1186. Returns: 0 on success, !0 on error
  1187. This ioctl attaches or detaches an ioeventfd to a legal pio/mmio address
  1188. within the guest. A guest write in the registered address will signal the
  1189. provided event instead of triggering an exit.
  1190. struct kvm_ioeventfd {
  1191. __u64 datamatch;
  1192. __u64 addr; /* legal pio/mmio address */
  1193. __u32 len; /* 1, 2, 4, or 8 bytes */
  1194. __s32 fd;
  1195. __u32 flags;
  1196. __u8 pad[36];
  1197. };
  1198. For the special case of virtio-ccw devices on s390, the ioevent is matched
  1199. to a subchannel/virtqueue tuple instead.
  1200. The following flags are defined:
  1201. #define KVM_IOEVENTFD_FLAG_DATAMATCH (1 << kvm_ioeventfd_flag_nr_datamatch)
  1202. #define KVM_IOEVENTFD_FLAG_PIO (1 << kvm_ioeventfd_flag_nr_pio)
  1203. #define KVM_IOEVENTFD_FLAG_DEASSIGN (1 << kvm_ioeventfd_flag_nr_deassign)
  1204. #define KVM_IOEVENTFD_FLAG_VIRTIO_CCW_NOTIFY \
  1205. (1 << kvm_ioeventfd_flag_nr_virtio_ccw_notify)
  1206. If datamatch flag is set, the event will be signaled only if the written value
  1207. to the registered address is equal to datamatch in struct kvm_ioeventfd.
  1208. For virtio-ccw devices, addr contains the subchannel id and datamatch the
  1209. virtqueue index.
  1210. 4.60 KVM_DIRTY_TLB
  1211. Capability: KVM_CAP_SW_TLB
  1212. Architectures: ppc
  1213. Type: vcpu ioctl
  1214. Parameters: struct kvm_dirty_tlb (in)
  1215. Returns: 0 on success, -1 on error
  1216. struct kvm_dirty_tlb {
  1217. __u64 bitmap;
  1218. __u32 num_dirty;
  1219. };
  1220. This must be called whenever userspace has changed an entry in the shared
  1221. TLB, prior to calling KVM_RUN on the associated vcpu.
  1222. The "bitmap" field is the userspace address of an array. This array
  1223. consists of a number of bits, equal to the total number of TLB entries as
  1224. determined by the last successful call to KVM_CONFIG_TLB, rounded up to the
  1225. nearest multiple of 64.
  1226. Each bit corresponds to one TLB entry, ordered the same as in the shared TLB
  1227. array.
  1228. The array is little-endian: the bit 0 is the least significant bit of the
  1229. first byte, bit 8 is the least significant bit of the second byte, etc.
  1230. This avoids any complications with differing word sizes.
  1231. The "num_dirty" field is a performance hint for KVM to determine whether it
  1232. should skip processing the bitmap and just invalidate everything. It must
  1233. be set to the number of set bits in the bitmap.
  1234. 4.61 KVM_ASSIGN_SET_INTX_MASK (deprecated)
  1235. Capability: KVM_CAP_PCI_2_3
  1236. Architectures: x86
  1237. Type: vm ioctl
  1238. Parameters: struct kvm_assigned_pci_dev (in)
  1239. Returns: 0 on success, -1 on error
  1240. Allows userspace to mask PCI INTx interrupts from the assigned device. The
  1241. kernel will not deliver INTx interrupts to the guest between setting and
  1242. clearing of KVM_ASSIGN_SET_INTX_MASK via this interface. This enables use of
  1243. and emulation of PCI 2.3 INTx disable command register behavior.
  1244. This may be used for both PCI 2.3 devices supporting INTx disable natively and
  1245. older devices lacking this support. Userspace is responsible for emulating the
  1246. read value of the INTx disable bit in the guest visible PCI command register.
  1247. When modifying the INTx disable state, userspace should precede updating the
  1248. physical device command register by calling this ioctl to inform the kernel of
  1249. the new intended INTx mask state.
  1250. Note that the kernel uses the device INTx disable bit to internally manage the
  1251. device interrupt state for PCI 2.3 devices. Reads of this register may
  1252. therefore not match the expected value. Writes should always use the guest
  1253. intended INTx disable value rather than attempting to read-copy-update the
  1254. current physical device state. Races between user and kernel updates to the
  1255. INTx disable bit are handled lazily in the kernel. It's possible the device
  1256. may generate unintended interrupts, but they will not be injected into the
  1257. guest.
  1258. See KVM_ASSIGN_DEV_IRQ for the data structure. The target device is specified
  1259. by assigned_dev_id. In the flags field, only KVM_DEV_ASSIGN_MASK_INTX is
  1260. evaluated.
  1261. 4.62 KVM_CREATE_SPAPR_TCE
  1262. Capability: KVM_CAP_SPAPR_TCE
  1263. Architectures: powerpc
  1264. Type: vm ioctl
  1265. Parameters: struct kvm_create_spapr_tce (in)
  1266. Returns: file descriptor for manipulating the created TCE table
  1267. This creates a virtual TCE (translation control entry) table, which
  1268. is an IOMMU for PAPR-style virtual I/O. It is used to translate
  1269. logical addresses used in virtual I/O into guest physical addresses,
  1270. and provides a scatter/gather capability for PAPR virtual I/O.
  1271. /* for KVM_CAP_SPAPR_TCE */
  1272. struct kvm_create_spapr_tce {
  1273. __u64 liobn;
  1274. __u32 window_size;
  1275. };
  1276. The liobn field gives the logical IO bus number for which to create a
  1277. TCE table. The window_size field specifies the size of the DMA window
  1278. which this TCE table will translate - the table will contain one 64
  1279. bit TCE entry for every 4kiB of the DMA window.
  1280. When the guest issues an H_PUT_TCE hcall on a liobn for which a TCE
  1281. table has been created using this ioctl(), the kernel will handle it
  1282. in real mode, updating the TCE table. H_PUT_TCE calls for other
  1283. liobns will cause a vm exit and must be handled by userspace.
  1284. The return value is a file descriptor which can be passed to mmap(2)
  1285. to map the created TCE table into userspace. This lets userspace read
  1286. the entries written by kernel-handled H_PUT_TCE calls, and also lets
  1287. userspace update the TCE table directly which is useful in some
  1288. circumstances.
  1289. 4.63 KVM_ALLOCATE_RMA
  1290. Capability: KVM_CAP_PPC_RMA
  1291. Architectures: powerpc
  1292. Type: vm ioctl
  1293. Parameters: struct kvm_allocate_rma (out)
  1294. Returns: file descriptor for mapping the allocated RMA
  1295. This allocates a Real Mode Area (RMA) from the pool allocated at boot
  1296. time by the kernel. An RMA is a physically-contiguous, aligned region
  1297. of memory used on older POWER processors to provide the memory which
  1298. will be accessed by real-mode (MMU off) accesses in a KVM guest.
  1299. POWER processors support a set of sizes for the RMA that usually
  1300. includes 64MB, 128MB, 256MB and some larger powers of two.
  1301. /* for KVM_ALLOCATE_RMA */
  1302. struct kvm_allocate_rma {
  1303. __u64 rma_size;
  1304. };
  1305. The return value is a file descriptor which can be passed to mmap(2)
  1306. to map the allocated RMA into userspace. The mapped area can then be
  1307. passed to the KVM_SET_USER_MEMORY_REGION ioctl to establish it as the
  1308. RMA for a virtual machine. The size of the RMA in bytes (which is
  1309. fixed at host kernel boot time) is returned in the rma_size field of
  1310. the argument structure.
  1311. The KVM_CAP_PPC_RMA capability is 1 or 2 if the KVM_ALLOCATE_RMA ioctl
  1312. is supported; 2 if the processor requires all virtual machines to have
  1313. an RMA, or 1 if the processor can use an RMA but doesn't require it,
  1314. because it supports the Virtual RMA (VRMA) facility.
  1315. 4.64 KVM_NMI
  1316. Capability: KVM_CAP_USER_NMI
  1317. Architectures: x86
  1318. Type: vcpu ioctl
  1319. Parameters: none
  1320. Returns: 0 on success, -1 on error
  1321. Queues an NMI on the thread's vcpu. Note this is well defined only
  1322. when KVM_CREATE_IRQCHIP has not been called, since this is an interface
  1323. between the virtual cpu core and virtual local APIC. After KVM_CREATE_IRQCHIP
  1324. has been called, this interface is completely emulated within the kernel.
  1325. To use this to emulate the LINT1 input with KVM_CREATE_IRQCHIP, use the
  1326. following algorithm:
  1327. - pause the vpcu
  1328. - read the local APIC's state (KVM_GET_LAPIC)
  1329. - check whether changing LINT1 will queue an NMI (see the LVT entry for LINT1)
  1330. - if so, issue KVM_NMI
  1331. - resume the vcpu
  1332. Some guests configure the LINT1 NMI input to cause a panic, aiding in
  1333. debugging.
  1334. 4.65 KVM_S390_UCAS_MAP
  1335. Capability: KVM_CAP_S390_UCONTROL
  1336. Architectures: s390
  1337. Type: vcpu ioctl
  1338. Parameters: struct kvm_s390_ucas_mapping (in)
  1339. Returns: 0 in case of success
  1340. The parameter is defined like this:
  1341. struct kvm_s390_ucas_mapping {
  1342. __u64 user_addr;
  1343. __u64 vcpu_addr;
  1344. __u64 length;
  1345. };
  1346. This ioctl maps the memory at "user_addr" with the length "length" to
  1347. the vcpu's address space starting at "vcpu_addr". All parameters need to
  1348. be aligned by 1 megabyte.
  1349. 4.66 KVM_S390_UCAS_UNMAP
  1350. Capability: KVM_CAP_S390_UCONTROL
  1351. Architectures: s390
  1352. Type: vcpu ioctl
  1353. Parameters: struct kvm_s390_ucas_mapping (in)
  1354. Returns: 0 in case of success
  1355. The parameter is defined like this:
  1356. struct kvm_s390_ucas_mapping {
  1357. __u64 user_addr;
  1358. __u64 vcpu_addr;
  1359. __u64 length;
  1360. };
  1361. This ioctl unmaps the memory in the vcpu's address space starting at
  1362. "vcpu_addr" with the length "length". The field "user_addr" is ignored.
  1363. All parameters need to be aligned by 1 megabyte.
  1364. 4.67 KVM_S390_VCPU_FAULT
  1365. Capability: KVM_CAP_S390_UCONTROL
  1366. Architectures: s390
  1367. Type: vcpu ioctl
  1368. Parameters: vcpu absolute address (in)
  1369. Returns: 0 in case of success
  1370. This call creates a page table entry on the virtual cpu's address space
  1371. (for user controlled virtual machines) or the virtual machine's address
  1372. space (for regular virtual machines). This only works for minor faults,
  1373. thus it's recommended to access subject memory page via the user page
  1374. table upfront. This is useful to handle validity intercepts for user
  1375. controlled virtual machines to fault in the virtual cpu's lowcore pages
  1376. prior to calling the KVM_RUN ioctl.
  1377. 4.68 KVM_SET_ONE_REG
  1378. Capability: KVM_CAP_ONE_REG
  1379. Architectures: all
  1380. Type: vcpu ioctl
  1381. Parameters: struct kvm_one_reg (in)
  1382. Returns: 0 on success, negative value on failure
  1383. struct kvm_one_reg {
  1384. __u64 id;
  1385. __u64 addr;
  1386. };
  1387. Using this ioctl, a single vcpu register can be set to a specific value
  1388. defined by user space with the passed in struct kvm_one_reg, where id
  1389. refers to the register identifier as described below and addr is a pointer
  1390. to a variable with the respective size. There can be architecture agnostic
  1391. and architecture specific registers. Each have their own range of operation
  1392. and their own constants and width. To keep track of the implemented
  1393. registers, find a list below:
  1394. Arch | Register | Width (bits)
  1395. | |
  1396. PPC | KVM_REG_PPC_HIOR | 64
  1397. PPC | KVM_REG_PPC_IAC1 | 64
  1398. PPC | KVM_REG_PPC_IAC2 | 64
  1399. PPC | KVM_REG_PPC_IAC3 | 64
  1400. PPC | KVM_REG_PPC_IAC4 | 64
  1401. PPC | KVM_REG_PPC_DAC1 | 64
  1402. PPC | KVM_REG_PPC_DAC2 | 64
  1403. PPC | KVM_REG_PPC_DABR | 64
  1404. PPC | KVM_REG_PPC_DSCR | 64
  1405. PPC | KVM_REG_PPC_PURR | 64
  1406. PPC | KVM_REG_PPC_SPURR | 64
  1407. PPC | KVM_REG_PPC_DAR | 64
  1408. PPC | KVM_REG_PPC_DSISR | 32
  1409. PPC | KVM_REG_PPC_AMR | 64
  1410. PPC | KVM_REG_PPC_UAMOR | 64
  1411. PPC | KVM_REG_PPC_MMCR0 | 64
  1412. PPC | KVM_REG_PPC_MMCR1 | 64
  1413. PPC | KVM_REG_PPC_MMCRA | 64
  1414. PPC | KVM_REG_PPC_MMCR2 | 64
  1415. PPC | KVM_REG_PPC_MMCRS | 64
  1416. PPC | KVM_REG_PPC_SIAR | 64
  1417. PPC | KVM_REG_PPC_SDAR | 64
  1418. PPC | KVM_REG_PPC_SIER | 64
  1419. PPC | KVM_REG_PPC_PMC1 | 32
  1420. PPC | KVM_REG_PPC_PMC2 | 32
  1421. PPC | KVM_REG_PPC_PMC3 | 32
  1422. PPC | KVM_REG_PPC_PMC4 | 32
  1423. PPC | KVM_REG_PPC_PMC5 | 32
  1424. PPC | KVM_REG_PPC_PMC6 | 32
  1425. PPC | KVM_REG_PPC_PMC7 | 32
  1426. PPC | KVM_REG_PPC_PMC8 | 32
  1427. PPC | KVM_REG_PPC_FPR0 | 64
  1428. ...
  1429. PPC | KVM_REG_PPC_FPR31 | 64
  1430. PPC | KVM_REG_PPC_VR0 | 128
  1431. ...
  1432. PPC | KVM_REG_PPC_VR31 | 128
  1433. PPC | KVM_REG_PPC_VSR0 | 128
  1434. ...
  1435. PPC | KVM_REG_PPC_VSR31 | 128
  1436. PPC | KVM_REG_PPC_FPSCR | 64
  1437. PPC | KVM_REG_PPC_VSCR | 32
  1438. PPC | KVM_REG_PPC_VPA_ADDR | 64
  1439. PPC | KVM_REG_PPC_VPA_SLB | 128
  1440. PPC | KVM_REG_PPC_VPA_DTL | 128
  1441. PPC | KVM_REG_PPC_EPCR | 32
  1442. PPC | KVM_REG_PPC_EPR | 32
  1443. PPC | KVM_REG_PPC_TCR | 32
  1444. PPC | KVM_REG_PPC_TSR | 32
  1445. PPC | KVM_REG_PPC_OR_TSR | 32
  1446. PPC | KVM_REG_PPC_CLEAR_TSR | 32
  1447. PPC | KVM_REG_PPC_MAS0 | 32
  1448. PPC | KVM_REG_PPC_MAS1 | 32
  1449. PPC | KVM_REG_PPC_MAS2 | 64
  1450. PPC | KVM_REG_PPC_MAS7_3 | 64
  1451. PPC | KVM_REG_PPC_MAS4 | 32
  1452. PPC | KVM_REG_PPC_MAS6 | 32
  1453. PPC | KVM_REG_PPC_MMUCFG | 32
  1454. PPC | KVM_REG_PPC_TLB0CFG | 32
  1455. PPC | KVM_REG_PPC_TLB1CFG | 32
  1456. PPC | KVM_REG_PPC_TLB2CFG | 32
  1457. PPC | KVM_REG_PPC_TLB3CFG | 32
  1458. PPC | KVM_REG_PPC_TLB0PS | 32
  1459. PPC | KVM_REG_PPC_TLB1PS | 32
  1460. PPC | KVM_REG_PPC_TLB2PS | 32
  1461. PPC | KVM_REG_PPC_TLB3PS | 32
  1462. PPC | KVM_REG_PPC_EPTCFG | 32
  1463. PPC | KVM_REG_PPC_ICP_STATE | 64
  1464. PPC | KVM_REG_PPC_TB_OFFSET | 64
  1465. PPC | KVM_REG_PPC_SPMC1 | 32
  1466. PPC | KVM_REG_PPC_SPMC2 | 32
  1467. PPC | KVM_REG_PPC_IAMR | 64
  1468. PPC | KVM_REG_PPC_TFHAR | 64
  1469. PPC | KVM_REG_PPC_TFIAR | 64
  1470. PPC | KVM_REG_PPC_TEXASR | 64
  1471. PPC | KVM_REG_PPC_FSCR | 64
  1472. PPC | KVM_REG_PPC_PSPB | 32
  1473. PPC | KVM_REG_PPC_EBBHR | 64
  1474. PPC | KVM_REG_PPC_EBBRR | 64
  1475. PPC | KVM_REG_PPC_BESCR | 64
  1476. PPC | KVM_REG_PPC_TAR | 64
  1477. PPC | KVM_REG_PPC_DPDES | 64
  1478. PPC | KVM_REG_PPC_DAWR | 64
  1479. PPC | KVM_REG_PPC_DAWRX | 64
  1480. PPC | KVM_REG_PPC_CIABR | 64
  1481. PPC | KVM_REG_PPC_IC | 64
  1482. PPC | KVM_REG_PPC_VTB | 64
  1483. PPC | KVM_REG_PPC_CSIGR | 64
  1484. PPC | KVM_REG_PPC_TACR | 64
  1485. PPC | KVM_REG_PPC_TCSCR | 64
  1486. PPC | KVM_REG_PPC_PID | 64
  1487. PPC | KVM_REG_PPC_ACOP | 64
  1488. PPC | KVM_REG_PPC_VRSAVE | 32
  1489. PPC | KVM_REG_PPC_LPCR | 32
  1490. PPC | KVM_REG_PPC_LPCR_64 | 64
  1491. PPC | KVM_REG_PPC_PPR | 64
  1492. PPC | KVM_REG_PPC_ARCH_COMPAT | 32
  1493. PPC | KVM_REG_PPC_DABRX | 32
  1494. PPC | KVM_REG_PPC_WORT | 64
  1495. PPC | KVM_REG_PPC_SPRG9 | 64
  1496. PPC | KVM_REG_PPC_DBSR | 32
  1497. PPC | KVM_REG_PPC_TM_GPR0 | 64
  1498. ...
  1499. PPC | KVM_REG_PPC_TM_GPR31 | 64
  1500. PPC | KVM_REG_PPC_TM_VSR0 | 128
  1501. ...
  1502. PPC | KVM_REG_PPC_TM_VSR63 | 128
  1503. PPC | KVM_REG_PPC_TM_CR | 64
  1504. PPC | KVM_REG_PPC_TM_LR | 64
  1505. PPC | KVM_REG_PPC_TM_CTR | 64
  1506. PPC | KVM_REG_PPC_TM_FPSCR | 64
  1507. PPC | KVM_REG_PPC_TM_AMR | 64
  1508. PPC | KVM_REG_PPC_TM_PPR | 64
  1509. PPC | KVM_REG_PPC_TM_VRSAVE | 64
  1510. PPC | KVM_REG_PPC_TM_VSCR | 32
  1511. PPC | KVM_REG_PPC_TM_DSCR | 64
  1512. PPC | KVM_REG_PPC_TM_TAR | 64
  1513. | |
  1514. MIPS | KVM_REG_MIPS_R0 | 64
  1515. ...
  1516. MIPS | KVM_REG_MIPS_R31 | 64
  1517. MIPS | KVM_REG_MIPS_HI | 64
  1518. MIPS | KVM_REG_MIPS_LO | 64
  1519. MIPS | KVM_REG_MIPS_PC | 64
  1520. MIPS | KVM_REG_MIPS_CP0_INDEX | 32
  1521. MIPS | KVM_REG_MIPS_CP0_CONTEXT | 64
  1522. MIPS | KVM_REG_MIPS_CP0_USERLOCAL | 64
  1523. MIPS | KVM_REG_MIPS_CP0_PAGEMASK | 32
  1524. MIPS | KVM_REG_MIPS_CP0_WIRED | 32
  1525. MIPS | KVM_REG_MIPS_CP0_HWRENA | 32
  1526. MIPS | KVM_REG_MIPS_CP0_BADVADDR | 64
  1527. MIPS | KVM_REG_MIPS_CP0_COUNT | 32
  1528. MIPS | KVM_REG_MIPS_CP0_ENTRYHI | 64
  1529. MIPS | KVM_REG_MIPS_CP0_COMPARE | 32
  1530. MIPS | KVM_REG_MIPS_CP0_STATUS | 32
  1531. MIPS | KVM_REG_MIPS_CP0_CAUSE | 32
  1532. MIPS | KVM_REG_MIPS_CP0_EPC | 64
  1533. MIPS | KVM_REG_MIPS_CP0_PRID | 32
  1534. MIPS | KVM_REG_MIPS_CP0_CONFIG | 32
  1535. MIPS | KVM_REG_MIPS_CP0_CONFIG1 | 32
  1536. MIPS | KVM_REG_MIPS_CP0_CONFIG2 | 32
  1537. MIPS | KVM_REG_MIPS_CP0_CONFIG3 | 32
  1538. MIPS | KVM_REG_MIPS_CP0_CONFIG4 | 32
  1539. MIPS | KVM_REG_MIPS_CP0_CONFIG5 | 32
  1540. MIPS | KVM_REG_MIPS_CP0_CONFIG7 | 32
  1541. MIPS | KVM_REG_MIPS_CP0_ERROREPC | 64
  1542. MIPS | KVM_REG_MIPS_COUNT_CTL | 64
  1543. MIPS | KVM_REG_MIPS_COUNT_RESUME | 64
  1544. MIPS | KVM_REG_MIPS_COUNT_HZ | 64
  1545. MIPS | KVM_REG_MIPS_FPR_32(0..31) | 32
  1546. MIPS | KVM_REG_MIPS_FPR_64(0..31) | 64
  1547. MIPS | KVM_REG_MIPS_VEC_128(0..31) | 128
  1548. MIPS | KVM_REG_MIPS_FCR_IR | 32
  1549. MIPS | KVM_REG_MIPS_FCR_CSR | 32
  1550. MIPS | KVM_REG_MIPS_MSA_IR | 32
  1551. MIPS | KVM_REG_MIPS_MSA_CSR | 32
  1552. ARM registers are mapped using the lower 32 bits. The upper 16 of that
  1553. is the register group type, or coprocessor number:
  1554. ARM core registers have the following id bit patterns:
  1555. 0x4020 0000 0010 <index into the kvm_regs struct:16>
  1556. ARM 32-bit CP15 registers have the following id bit patterns:
  1557. 0x4020 0000 000F <zero:1> <crn:4> <crm:4> <opc1:4> <opc2:3>
  1558. ARM 64-bit CP15 registers have the following id bit patterns:
  1559. 0x4030 0000 000F <zero:1> <zero:4> <crm:4> <opc1:4> <zero:3>
  1560. ARM CCSIDR registers are demultiplexed by CSSELR value:
  1561. 0x4020 0000 0011 00 <csselr:8>
  1562. ARM 32-bit VFP control registers have the following id bit patterns:
  1563. 0x4020 0000 0012 1 <regno:12>
  1564. ARM 64-bit FP registers have the following id bit patterns:
  1565. 0x4030 0000 0012 0 <regno:12>
  1566. arm64 registers are mapped using the lower 32 bits. The upper 16 of
  1567. that is the register group type, or coprocessor number:
  1568. arm64 core/FP-SIMD registers have the following id bit patterns. Note
  1569. that the size of the access is variable, as the kvm_regs structure
  1570. contains elements ranging from 32 to 128 bits. The index is a 32bit
  1571. value in the kvm_regs structure seen as a 32bit array.
  1572. 0x60x0 0000 0010 <index into the kvm_regs struct:16>
  1573. arm64 CCSIDR registers are demultiplexed by CSSELR value:
  1574. 0x6020 0000 0011 00 <csselr:8>
  1575. arm64 system registers have the following id bit patterns:
  1576. 0x6030 0000 0013 <op0:2> <op1:3> <crn:4> <crm:4> <op2:3>
  1577. MIPS registers are mapped using the lower 32 bits. The upper 16 of that is
  1578. the register group type:
  1579. MIPS core registers (see above) have the following id bit patterns:
  1580. 0x7030 0000 0000 <reg:16>
  1581. MIPS CP0 registers (see KVM_REG_MIPS_CP0_* above) have the following id bit
  1582. patterns depending on whether they're 32-bit or 64-bit registers:
  1583. 0x7020 0000 0001 00 <reg:5> <sel:3> (32-bit)
  1584. 0x7030 0000 0001 00 <reg:5> <sel:3> (64-bit)
  1585. MIPS KVM control registers (see above) have the following id bit patterns:
  1586. 0x7030 0000 0002 <reg:16>
  1587. MIPS FPU registers (see KVM_REG_MIPS_FPR_{32,64}() above) have the following
  1588. id bit patterns depending on the size of the register being accessed. They are
  1589. always accessed according to the current guest FPU mode (Status.FR and
  1590. Config5.FRE), i.e. as the guest would see them, and they become unpredictable
  1591. if the guest FPU mode is changed. MIPS SIMD Architecture (MSA) vector
  1592. registers (see KVM_REG_MIPS_VEC_128() above) have similar patterns as they
  1593. overlap the FPU registers:
  1594. 0x7020 0000 0003 00 <0:3> <reg:5> (32-bit FPU registers)
  1595. 0x7030 0000 0003 00 <0:3> <reg:5> (64-bit FPU registers)
  1596. 0x7040 0000 0003 00 <0:3> <reg:5> (128-bit MSA vector registers)
  1597. MIPS FPU control registers (see KVM_REG_MIPS_FCR_{IR,CSR} above) have the
  1598. following id bit patterns:
  1599. 0x7020 0000 0003 01 <0:3> <reg:5>
  1600. MIPS MSA control registers (see KVM_REG_MIPS_MSA_{IR,CSR} above) have the
  1601. following id bit patterns:
  1602. 0x7020 0000 0003 02 <0:3> <reg:5>
  1603. 4.69 KVM_GET_ONE_REG
  1604. Capability: KVM_CAP_ONE_REG
  1605. Architectures: all
  1606. Type: vcpu ioctl
  1607. Parameters: struct kvm_one_reg (in and out)
  1608. Returns: 0 on success, negative value on failure
  1609. This ioctl allows to receive the value of a single register implemented
  1610. in a vcpu. The register to read is indicated by the "id" field of the
  1611. kvm_one_reg struct passed in. On success, the register value can be found
  1612. at the memory location pointed to by "addr".
  1613. The list of registers accessible using this interface is identical to the
  1614. list in 4.68.
  1615. 4.70 KVM_KVMCLOCK_CTRL
  1616. Capability: KVM_CAP_KVMCLOCK_CTRL
  1617. Architectures: Any that implement pvclocks (currently x86 only)
  1618. Type: vcpu ioctl
  1619. Parameters: None
  1620. Returns: 0 on success, -1 on error
  1621. This signals to the host kernel that the specified guest is being paused by
  1622. userspace. The host will set a flag in the pvclock structure that is checked
  1623. from the soft lockup watchdog. The flag is part of the pvclock structure that
  1624. is shared between guest and host, specifically the second bit of the flags
  1625. field of the pvclock_vcpu_time_info structure. It will be set exclusively by
  1626. the host and read/cleared exclusively by the guest. The guest operation of
  1627. checking and clearing the flag must an atomic operation so
  1628. load-link/store-conditional, or equivalent must be used. There are two cases
  1629. where the guest will clear the flag: when the soft lockup watchdog timer resets
  1630. itself or when a soft lockup is detected. This ioctl can be called any time
  1631. after pausing the vcpu, but before it is resumed.
  1632. 4.71 KVM_SIGNAL_MSI
  1633. Capability: KVM_CAP_SIGNAL_MSI
  1634. Architectures: x86
  1635. Type: vm ioctl
  1636. Parameters: struct kvm_msi (in)
  1637. Returns: >0 on delivery, 0 if guest blocked the MSI, and -1 on error
  1638. Directly inject a MSI message. Only valid with in-kernel irqchip that handles
  1639. MSI messages.
  1640. struct kvm_msi {
  1641. __u32 address_lo;
  1642. __u32 address_hi;
  1643. __u32 data;
  1644. __u32 flags;
  1645. __u8 pad[16];
  1646. };
  1647. No flags are defined so far. The corresponding field must be 0.
  1648. 4.71 KVM_CREATE_PIT2
  1649. Capability: KVM_CAP_PIT2
  1650. Architectures: x86
  1651. Type: vm ioctl
  1652. Parameters: struct kvm_pit_config (in)
  1653. Returns: 0 on success, -1 on error
  1654. Creates an in-kernel device model for the i8254 PIT. This call is only valid
  1655. after enabling in-kernel irqchip support via KVM_CREATE_IRQCHIP. The following
  1656. parameters have to be passed:
  1657. struct kvm_pit_config {
  1658. __u32 flags;
  1659. __u32 pad[15];
  1660. };
  1661. Valid flags are:
  1662. #define KVM_PIT_SPEAKER_DUMMY 1 /* emulate speaker port stub */
  1663. PIT timer interrupts may use a per-VM kernel thread for injection. If it
  1664. exists, this thread will have a name of the following pattern:
  1665. kvm-pit/<owner-process-pid>
  1666. When running a guest with elevated priorities, the scheduling parameters of
  1667. this thread may have to be adjusted accordingly.
  1668. This IOCTL replaces the obsolete KVM_CREATE_PIT.
  1669. 4.72 KVM_GET_PIT2
  1670. Capability: KVM_CAP_PIT_STATE2
  1671. Architectures: x86
  1672. Type: vm ioctl
  1673. Parameters: struct kvm_pit_state2 (out)
  1674. Returns: 0 on success, -1 on error
  1675. Retrieves the state of the in-kernel PIT model. Only valid after
  1676. KVM_CREATE_PIT2. The state is returned in the following structure:
  1677. struct kvm_pit_state2 {
  1678. struct kvm_pit_channel_state channels[3];
  1679. __u32 flags;
  1680. __u32 reserved[9];
  1681. };
  1682. Valid flags are:
  1683. /* disable PIT in HPET legacy mode */
  1684. #define KVM_PIT_FLAGS_HPET_LEGACY 0x00000001
  1685. This IOCTL replaces the obsolete KVM_GET_PIT.
  1686. 4.73 KVM_SET_PIT2
  1687. Capability: KVM_CAP_PIT_STATE2
  1688. Architectures: x86
  1689. Type: vm ioctl
  1690. Parameters: struct kvm_pit_state2 (in)
  1691. Returns: 0 on success, -1 on error
  1692. Sets the state of the in-kernel PIT model. Only valid after KVM_CREATE_PIT2.
  1693. See KVM_GET_PIT2 for details on struct kvm_pit_state2.
  1694. This IOCTL replaces the obsolete KVM_SET_PIT.
  1695. 4.74 KVM_PPC_GET_SMMU_INFO
  1696. Capability: KVM_CAP_PPC_GET_SMMU_INFO
  1697. Architectures: powerpc
  1698. Type: vm ioctl
  1699. Parameters: None
  1700. Returns: 0 on success, -1 on error
  1701. This populates and returns a structure describing the features of
  1702. the "Server" class MMU emulation supported by KVM.
  1703. This can in turn be used by userspace to generate the appropriate
  1704. device-tree properties for the guest operating system.
  1705. The structure contains some global information, followed by an
  1706. array of supported segment page sizes:
  1707. struct kvm_ppc_smmu_info {
  1708. __u64 flags;
  1709. __u32 slb_size;
  1710. __u32 pad;
  1711. struct kvm_ppc_one_seg_page_size sps[KVM_PPC_PAGE_SIZES_MAX_SZ];
  1712. };
  1713. The supported flags are:
  1714. - KVM_PPC_PAGE_SIZES_REAL:
  1715. When that flag is set, guest page sizes must "fit" the backing
  1716. store page sizes. When not set, any page size in the list can
  1717. be used regardless of how they are backed by userspace.
  1718. - KVM_PPC_1T_SEGMENTS
  1719. The emulated MMU supports 1T segments in addition to the
  1720. standard 256M ones.
  1721. The "slb_size" field indicates how many SLB entries are supported
  1722. The "sps" array contains 8 entries indicating the supported base
  1723. page sizes for a segment in increasing order. Each entry is defined
  1724. as follow:
  1725. struct kvm_ppc_one_seg_page_size {
  1726. __u32 page_shift; /* Base page shift of segment (or 0) */
  1727. __u32 slb_enc; /* SLB encoding for BookS */
  1728. struct kvm_ppc_one_page_size enc[KVM_PPC_PAGE_SIZES_MAX_SZ];
  1729. };
  1730. An entry with a "page_shift" of 0 is unused. Because the array is
  1731. organized in increasing order, a lookup can stop when encoutering
  1732. such an entry.
  1733. The "slb_enc" field provides the encoding to use in the SLB for the
  1734. page size. The bits are in positions such as the value can directly
  1735. be OR'ed into the "vsid" argument of the slbmte instruction.
  1736. The "enc" array is a list which for each of those segment base page
  1737. size provides the list of supported actual page sizes (which can be
  1738. only larger or equal to the base page size), along with the
  1739. corresponding encoding in the hash PTE. Similarly, the array is
  1740. 8 entries sorted by increasing sizes and an entry with a "0" shift
  1741. is an empty entry and a terminator:
  1742. struct kvm_ppc_one_page_size {
  1743. __u32 page_shift; /* Page shift (or 0) */
  1744. __u32 pte_enc; /* Encoding in the HPTE (>>12) */
  1745. };
  1746. The "pte_enc" field provides a value that can OR'ed into the hash
  1747. PTE's RPN field (ie, it needs to be shifted left by 12 to OR it
  1748. into the hash PTE second double word).
  1749. 4.75 KVM_IRQFD
  1750. Capability: KVM_CAP_IRQFD
  1751. Architectures: x86 s390 arm arm64
  1752. Type: vm ioctl
  1753. Parameters: struct kvm_irqfd (in)
  1754. Returns: 0 on success, -1 on error
  1755. Allows setting an eventfd to directly trigger a guest interrupt.
  1756. kvm_irqfd.fd specifies the file descriptor to use as the eventfd and
  1757. kvm_irqfd.gsi specifies the irqchip pin toggled by this event. When
  1758. an event is triggered on the eventfd, an interrupt is injected into
  1759. the guest using the specified gsi pin. The irqfd is removed using
  1760. the KVM_IRQFD_FLAG_DEASSIGN flag, specifying both kvm_irqfd.fd
  1761. and kvm_irqfd.gsi.
  1762. With KVM_CAP_IRQFD_RESAMPLE, KVM_IRQFD supports a de-assert and notify
  1763. mechanism allowing emulation of level-triggered, irqfd-based
  1764. interrupts. When KVM_IRQFD_FLAG_RESAMPLE is set the user must pass an
  1765. additional eventfd in the kvm_irqfd.resamplefd field. When operating
  1766. in resample mode, posting of an interrupt through kvm_irq.fd asserts
  1767. the specified gsi in the irqchip. When the irqchip is resampled, such
  1768. as from an EOI, the gsi is de-asserted and the user is notified via
  1769. kvm_irqfd.resamplefd. It is the user's responsibility to re-queue
  1770. the interrupt if the device making use of it still requires service.
  1771. Note that closing the resamplefd is not sufficient to disable the
  1772. irqfd. The KVM_IRQFD_FLAG_RESAMPLE is only necessary on assignment
  1773. and need not be specified with KVM_IRQFD_FLAG_DEASSIGN.
  1774. On ARM/ARM64, the gsi field in the kvm_irqfd struct specifies the Shared
  1775. Peripheral Interrupt (SPI) index, such that the GIC interrupt ID is
  1776. given by gsi + 32.
  1777. 4.76 KVM_PPC_ALLOCATE_HTAB
  1778. Capability: KVM_CAP_PPC_ALLOC_HTAB
  1779. Architectures: powerpc
  1780. Type: vm ioctl
  1781. Parameters: Pointer to u32 containing hash table order (in/out)
  1782. Returns: 0 on success, -1 on error
  1783. This requests the host kernel to allocate an MMU hash table for a
  1784. guest using the PAPR paravirtualization interface. This only does
  1785. anything if the kernel is configured to use the Book 3S HV style of
  1786. virtualization. Otherwise the capability doesn't exist and the ioctl
  1787. returns an ENOTTY error. The rest of this description assumes Book 3S
  1788. HV.
  1789. There must be no vcpus running when this ioctl is called; if there
  1790. are, it will do nothing and return an EBUSY error.
  1791. The parameter is a pointer to a 32-bit unsigned integer variable
  1792. containing the order (log base 2) of the desired size of the hash
  1793. table, which must be between 18 and 46. On successful return from the
  1794. ioctl, it will have been updated with the order of the hash table that
  1795. was allocated.
  1796. If no hash table has been allocated when any vcpu is asked to run
  1797. (with the KVM_RUN ioctl), the host kernel will allocate a
  1798. default-sized hash table (16 MB).
  1799. If this ioctl is called when a hash table has already been allocated,
  1800. the kernel will clear out the existing hash table (zero all HPTEs) and
  1801. return the hash table order in the parameter. (If the guest is using
  1802. the virtualized real-mode area (VRMA) facility, the kernel will
  1803. re-create the VMRA HPTEs on the next KVM_RUN of any vcpu.)
  1804. 4.77 KVM_S390_INTERRUPT
  1805. Capability: basic
  1806. Architectures: s390
  1807. Type: vm ioctl, vcpu ioctl
  1808. Parameters: struct kvm_s390_interrupt (in)
  1809. Returns: 0 on success, -1 on error
  1810. Allows to inject an interrupt to the guest. Interrupts can be floating
  1811. (vm ioctl) or per cpu (vcpu ioctl), depending on the interrupt type.
  1812. Interrupt parameters are passed via kvm_s390_interrupt:
  1813. struct kvm_s390_interrupt {
  1814. __u32 type;
  1815. __u32 parm;
  1816. __u64 parm64;
  1817. };
  1818. type can be one of the following:
  1819. KVM_S390_SIGP_STOP (vcpu) - sigp stop; optional flags in parm
  1820. KVM_S390_PROGRAM_INT (vcpu) - program check; code in parm
  1821. KVM_S390_SIGP_SET_PREFIX (vcpu) - sigp set prefix; prefix address in parm
  1822. KVM_S390_RESTART (vcpu) - restart
  1823. KVM_S390_INT_CLOCK_COMP (vcpu) - clock comparator interrupt
  1824. KVM_S390_INT_CPU_TIMER (vcpu) - CPU timer interrupt
  1825. KVM_S390_INT_VIRTIO (vm) - virtio external interrupt; external interrupt
  1826. parameters in parm and parm64
  1827. KVM_S390_INT_SERVICE (vm) - sclp external interrupt; sclp parameter in parm
  1828. KVM_S390_INT_EMERGENCY (vcpu) - sigp emergency; source cpu in parm
  1829. KVM_S390_INT_EXTERNAL_CALL (vcpu) - sigp external call; source cpu in parm
  1830. KVM_S390_INT_IO(ai,cssid,ssid,schid) (vm) - compound value to indicate an
  1831. I/O interrupt (ai - adapter interrupt; cssid,ssid,schid - subchannel);
  1832. I/O interruption parameters in parm (subchannel) and parm64 (intparm,
  1833. interruption subclass)
  1834. KVM_S390_MCHK (vm, vcpu) - machine check interrupt; cr 14 bits in parm,
  1835. machine check interrupt code in parm64 (note that
  1836. machine checks needing further payload are not
  1837. supported by this ioctl)
  1838. Note that the vcpu ioctl is asynchronous to vcpu execution.
  1839. 4.78 KVM_PPC_GET_HTAB_FD
  1840. Capability: KVM_CAP_PPC_HTAB_FD
  1841. Architectures: powerpc
  1842. Type: vm ioctl
  1843. Parameters: Pointer to struct kvm_get_htab_fd (in)
  1844. Returns: file descriptor number (>= 0) on success, -1 on error
  1845. This returns a file descriptor that can be used either to read out the
  1846. entries in the guest's hashed page table (HPT), or to write entries to
  1847. initialize the HPT. The returned fd can only be written to if the
  1848. KVM_GET_HTAB_WRITE bit is set in the flags field of the argument, and
  1849. can only be read if that bit is clear. The argument struct looks like
  1850. this:
  1851. /* For KVM_PPC_GET_HTAB_FD */
  1852. struct kvm_get_htab_fd {
  1853. __u64 flags;
  1854. __u64 start_index;
  1855. __u64 reserved[2];
  1856. };
  1857. /* Values for kvm_get_htab_fd.flags */
  1858. #define KVM_GET_HTAB_BOLTED_ONLY ((__u64)0x1)
  1859. #define KVM_GET_HTAB_WRITE ((__u64)0x2)
  1860. The `start_index' field gives the index in the HPT of the entry at
  1861. which to start reading. It is ignored when writing.
  1862. Reads on the fd will initially supply information about all
  1863. "interesting" HPT entries. Interesting entries are those with the
  1864. bolted bit set, if the KVM_GET_HTAB_BOLTED_ONLY bit is set, otherwise
  1865. all entries. When the end of the HPT is reached, the read() will
  1866. return. If read() is called again on the fd, it will start again from
  1867. the beginning of the HPT, but will only return HPT entries that have
  1868. changed since they were last read.
  1869. Data read or written is structured as a header (8 bytes) followed by a
  1870. series of valid HPT entries (16 bytes) each. The header indicates how
  1871. many valid HPT entries there are and how many invalid entries follow
  1872. the valid entries. The invalid entries are not represented explicitly
  1873. in the stream. The header format is:
  1874. struct kvm_get_htab_header {
  1875. __u32 index;
  1876. __u16 n_valid;
  1877. __u16 n_invalid;
  1878. };
  1879. Writes to the fd create HPT entries starting at the index given in the
  1880. header; first `n_valid' valid entries with contents from the data
  1881. written, then `n_invalid' invalid entries, invalidating any previously
  1882. valid entries found.
  1883. 4.79 KVM_CREATE_DEVICE
  1884. Capability: KVM_CAP_DEVICE_CTRL
  1885. Type: vm ioctl
  1886. Parameters: struct kvm_create_device (in/out)
  1887. Returns: 0 on success, -1 on error
  1888. Errors:
  1889. ENODEV: The device type is unknown or unsupported
  1890. EEXIST: Device already created, and this type of device may not
  1891. be instantiated multiple times
  1892. Other error conditions may be defined by individual device types or
  1893. have their standard meanings.
  1894. Creates an emulated device in the kernel. The file descriptor returned
  1895. in fd can be used with KVM_SET/GET/HAS_DEVICE_ATTR.
  1896. If the KVM_CREATE_DEVICE_TEST flag is set, only test whether the
  1897. device type is supported (not necessarily whether it can be created
  1898. in the current vm).
  1899. Individual devices should not define flags. Attributes should be used
  1900. for specifying any behavior that is not implied by the device type
  1901. number.
  1902. struct kvm_create_device {
  1903. __u32 type; /* in: KVM_DEV_TYPE_xxx */
  1904. __u32 fd; /* out: device handle */
  1905. __u32 flags; /* in: KVM_CREATE_DEVICE_xxx */
  1906. };
  1907. 4.80 KVM_SET_DEVICE_ATTR/KVM_GET_DEVICE_ATTR
  1908. Capability: KVM_CAP_DEVICE_CTRL, KVM_CAP_VM_ATTRIBUTES for vm device
  1909. Type: device ioctl, vm ioctl
  1910. Parameters: struct kvm_device_attr
  1911. Returns: 0 on success, -1 on error
  1912. Errors:
  1913. ENXIO: The group or attribute is unknown/unsupported for this device
  1914. EPERM: The attribute cannot (currently) be accessed this way
  1915. (e.g. read-only attribute, or attribute that only makes
  1916. sense when the device is in a different state)
  1917. Other error conditions may be defined by individual device types.
  1918. Gets/sets a specified piece of device configuration and/or state. The
  1919. semantics are device-specific. See individual device documentation in
  1920. the "devices" directory. As with ONE_REG, the size of the data
  1921. transferred is defined by the particular attribute.
  1922. struct kvm_device_attr {
  1923. __u32 flags; /* no flags currently defined */
  1924. __u32 group; /* device-defined */
  1925. __u64 attr; /* group-defined */
  1926. __u64 addr; /* userspace address of attr data */
  1927. };
  1928. 4.81 KVM_HAS_DEVICE_ATTR
  1929. Capability: KVM_CAP_DEVICE_CTRL, KVM_CAP_VM_ATTRIBUTES for vm device
  1930. Type: device ioctl, vm ioctl
  1931. Parameters: struct kvm_device_attr
  1932. Returns: 0 on success, -1 on error
  1933. Errors:
  1934. ENXIO: The group or attribute is unknown/unsupported for this device
  1935. Tests whether a device supports a particular attribute. A successful
  1936. return indicates the attribute is implemented. It does not necessarily
  1937. indicate that the attribute can be read or written in the device's
  1938. current state. "addr" is ignored.
  1939. 4.82 KVM_ARM_VCPU_INIT
  1940. Capability: basic
  1941. Architectures: arm, arm64
  1942. Type: vcpu ioctl
  1943. Parameters: struct kvm_vcpu_init (in)
  1944. Returns: 0 on success; -1 on error
  1945. Errors:
  1946.  EINVAL:    the target is unknown, or the combination of features is invalid.
  1947.  ENOENT:    a features bit specified is unknown.
  1948. This tells KVM what type of CPU to present to the guest, and what
  1949. optional features it should have.  This will cause a reset of the cpu
  1950. registers to their initial values.  If this is not called, KVM_RUN will
  1951. return ENOEXEC for that vcpu.
  1952. Note that because some registers reflect machine topology, all vcpus
  1953. should be created before this ioctl is invoked.
  1954. Userspace can call this function multiple times for a given vcpu, including
  1955. after the vcpu has been run. This will reset the vcpu to its initial
  1956. state. All calls to this function after the initial call must use the same
  1957. target and same set of feature flags, otherwise EINVAL will be returned.
  1958. Possible features:
  1959. - KVM_ARM_VCPU_POWER_OFF: Starts the CPU in a power-off state.
  1960. Depends on KVM_CAP_ARM_PSCI. If not set, the CPU will be powered on
  1961. and execute guest code when KVM_RUN is called.
  1962. - KVM_ARM_VCPU_EL1_32BIT: Starts the CPU in a 32bit mode.
  1963. Depends on KVM_CAP_ARM_EL1_32BIT (arm64 only).
  1964. - KVM_ARM_VCPU_PSCI_0_2: Emulate PSCI v0.2 for the CPU.
  1965. Depends on KVM_CAP_ARM_PSCI_0_2.
  1966. 4.83 KVM_ARM_PREFERRED_TARGET
  1967. Capability: basic
  1968. Architectures: arm, arm64
  1969. Type: vm ioctl
  1970. Parameters: struct struct kvm_vcpu_init (out)
  1971. Returns: 0 on success; -1 on error
  1972. Errors:
  1973. ENODEV: no preferred target available for the host
  1974. This queries KVM for preferred CPU target type which can be emulated
  1975. by KVM on underlying host.
  1976. The ioctl returns struct kvm_vcpu_init instance containing information
  1977. about preferred CPU target type and recommended features for it. The
  1978. kvm_vcpu_init->features bitmap returned will have feature bits set if
  1979. the preferred target recommends setting these features, but this is
  1980. not mandatory.
  1981. The information returned by this ioctl can be used to prepare an instance
  1982. of struct kvm_vcpu_init for KVM_ARM_VCPU_INIT ioctl which will result in
  1983. in VCPU matching underlying host.
  1984. 4.84 KVM_GET_REG_LIST
  1985. Capability: basic
  1986. Architectures: arm, arm64, mips
  1987. Type: vcpu ioctl
  1988. Parameters: struct kvm_reg_list (in/out)
  1989. Returns: 0 on success; -1 on error
  1990. Errors:
  1991.  E2BIG:     the reg index list is too big to fit in the array specified by
  1992.             the user (the number required will be written into n).
  1993. struct kvm_reg_list {
  1994. __u64 n; /* number of registers in reg[] */
  1995. __u64 reg[0];
  1996. };
  1997. This ioctl returns the guest registers that are supported for the
  1998. KVM_GET_ONE_REG/KVM_SET_ONE_REG calls.
  1999. 4.85 KVM_ARM_SET_DEVICE_ADDR (deprecated)
  2000. Capability: KVM_CAP_ARM_SET_DEVICE_ADDR
  2001. Architectures: arm, arm64
  2002. Type: vm ioctl
  2003. Parameters: struct kvm_arm_device_address (in)
  2004. Returns: 0 on success, -1 on error
  2005. Errors:
  2006. ENODEV: The device id is unknown
  2007. ENXIO: Device not supported on current system
  2008. EEXIST: Address already set
  2009. E2BIG: Address outside guest physical address space
  2010. EBUSY: Address overlaps with other device range
  2011. struct kvm_arm_device_addr {
  2012. __u64 id;
  2013. __u64 addr;
  2014. };
  2015. Specify a device address in the guest's physical address space where guests
  2016. can access emulated or directly exposed devices, which the host kernel needs
  2017. to know about. The id field is an architecture specific identifier for a
  2018. specific device.
  2019. ARM/arm64 divides the id field into two parts, a device id and an
  2020. address type id specific to the individual device.
  2021.  bits: | 63 ... 32 | 31 ... 16 | 15 ... 0 |
  2022. field: | 0x00000000 | device id | addr type id |
  2023. ARM/arm64 currently only require this when using the in-kernel GIC
  2024. support for the hardware VGIC features, using KVM_ARM_DEVICE_VGIC_V2
  2025. as the device id. When setting the base address for the guest's
  2026. mapping of the VGIC virtual CPU and distributor interface, the ioctl
  2027. must be called after calling KVM_CREATE_IRQCHIP, but before calling
  2028. KVM_RUN on any of the VCPUs. Calling this ioctl twice for any of the
  2029. base addresses will return -EEXIST.
  2030. Note, this IOCTL is deprecated and the more flexible SET/GET_DEVICE_ATTR API
  2031. should be used instead.
  2032. 4.86 KVM_PPC_RTAS_DEFINE_TOKEN
  2033. Capability: KVM_CAP_PPC_RTAS
  2034. Architectures: ppc
  2035. Type: vm ioctl
  2036. Parameters: struct kvm_rtas_token_args
  2037. Returns: 0 on success, -1 on error
  2038. Defines a token value for a RTAS (Run Time Abstraction Services)
  2039. service in order to allow it to be handled in the kernel. The
  2040. argument struct gives the name of the service, which must be the name
  2041. of a service that has a kernel-side implementation. If the token
  2042. value is non-zero, it will be associated with that service, and
  2043. subsequent RTAS calls by the guest specifying that token will be
  2044. handled by the kernel. If the token value is 0, then any token
  2045. associated with the service will be forgotten, and subsequent RTAS
  2046. calls by the guest for that service will be passed to userspace to be
  2047. handled.
  2048. 4.87 KVM_SET_GUEST_DEBUG
  2049. Capability: KVM_CAP_SET_GUEST_DEBUG
  2050. Architectures: x86, s390, ppc, arm64
  2051. Type: vcpu ioctl
  2052. Parameters: struct kvm_guest_debug (in)
  2053. Returns: 0 on success; -1 on error
  2054. struct kvm_guest_debug {
  2055. __u32 control;
  2056. __u32 pad;
  2057. struct kvm_guest_debug_arch arch;
  2058. };
  2059. Set up the processor specific debug registers and configure vcpu for
  2060. handling guest debug events. There are two parts to the structure, the
  2061. first a control bitfield indicates the type of debug events to handle
  2062. when running. Common control bits are:
  2063. - KVM_GUESTDBG_ENABLE: guest debugging is enabled
  2064. - KVM_GUESTDBG_SINGLESTEP: the next run should single-step
  2065. The top 16 bits of the control field are architecture specific control
  2066. flags which can include the following:
  2067. - KVM_GUESTDBG_USE_SW_BP: using software breakpoints [x86, arm64]
  2068. - KVM_GUESTDBG_USE_HW_BP: using hardware breakpoints [x86, s390, arm64]
  2069. - KVM_GUESTDBG_INJECT_DB: inject DB type exception [x86]
  2070. - KVM_GUESTDBG_INJECT_BP: inject BP type exception [x86]
  2071. - KVM_GUESTDBG_EXIT_PENDING: trigger an immediate guest exit [s390]
  2072. For example KVM_GUESTDBG_USE_SW_BP indicates that software breakpoints
  2073. are enabled in memory so we need to ensure breakpoint exceptions are
  2074. correctly trapped and the KVM run loop exits at the breakpoint and not
  2075. running off into the normal guest vector. For KVM_GUESTDBG_USE_HW_BP
  2076. we need to ensure the guest vCPUs architecture specific registers are
  2077. updated to the correct (supplied) values.
  2078. The second part of the structure is architecture specific and
  2079. typically contains a set of debug registers.
  2080. For arm64 the number of debug registers is implementation defined and
  2081. can be determined by querying the KVM_CAP_GUEST_DEBUG_HW_BPS and
  2082. KVM_CAP_GUEST_DEBUG_HW_WPS capabilities which return a positive number
  2083. indicating the number of supported registers.
  2084. When debug events exit the main run loop with the reason
  2085. KVM_EXIT_DEBUG with the kvm_debug_exit_arch part of the kvm_run
  2086. structure containing architecture specific debug information.
  2087. 4.88 KVM_GET_EMULATED_CPUID
  2088. Capability: KVM_CAP_EXT_EMUL_CPUID
  2089. Architectures: x86
  2090. Type: system ioctl
  2091. Parameters: struct kvm_cpuid2 (in/out)
  2092. Returns: 0 on success, -1 on error
  2093. struct kvm_cpuid2 {
  2094. __u32 nent;
  2095. __u32 flags;
  2096. struct kvm_cpuid_entry2 entries[0];
  2097. };
  2098. The member 'flags' is used for passing flags from userspace.
  2099. #define KVM_CPUID_FLAG_SIGNIFCANT_INDEX BIT(0)
  2100. #define KVM_CPUID_FLAG_STATEFUL_FUNC BIT(1)
  2101. #define KVM_CPUID_FLAG_STATE_READ_NEXT BIT(2)
  2102. struct kvm_cpuid_entry2 {
  2103. __u32 function;
  2104. __u32 index;
  2105. __u32 flags;
  2106. __u32 eax;
  2107. __u32 ebx;
  2108. __u32 ecx;
  2109. __u32 edx;
  2110. __u32 padding[3];
  2111. };
  2112. This ioctl returns x86 cpuid features which are emulated by
  2113. kvm.Userspace can use the information returned by this ioctl to query
  2114. which features are emulated by kvm instead of being present natively.
  2115. Userspace invokes KVM_GET_EMULATED_CPUID by passing a kvm_cpuid2
  2116. structure with the 'nent' field indicating the number of entries in
  2117. the variable-size array 'entries'. If the number of entries is too low
  2118. to describe the cpu capabilities, an error (E2BIG) is returned. If the
  2119. number is too high, the 'nent' field is adjusted and an error (ENOMEM)
  2120. is returned. If the number is just right, the 'nent' field is adjusted
  2121. to the number of valid entries in the 'entries' array, which is then
  2122. filled.
  2123. The entries returned are the set CPUID bits of the respective features
  2124. which kvm emulates, as returned by the CPUID instruction, with unknown
  2125. or unsupported feature bits cleared.
  2126. Features like x2apic, for example, may not be present in the host cpu
  2127. but are exposed by kvm in KVM_GET_SUPPORTED_CPUID because they can be
  2128. emulated efficiently and thus not included here.
  2129. The fields in each entry are defined as follows:
  2130. function: the eax value used to obtain the entry
  2131. index: the ecx value used to obtain the entry (for entries that are
  2132. affected by ecx)
  2133. flags: an OR of zero or more of the following:
  2134. KVM_CPUID_FLAG_SIGNIFCANT_INDEX:
  2135. if the index field is valid
  2136. KVM_CPUID_FLAG_STATEFUL_FUNC:
  2137. if cpuid for this function returns different values for successive
  2138. invocations; there will be several entries with the same function,
  2139. all with this flag set
  2140. KVM_CPUID_FLAG_STATE_READ_NEXT:
  2141. for KVM_CPUID_FLAG_STATEFUL_FUNC entries, set if this entry is
  2142. the first entry to be read by a cpu
  2143. eax, ebx, ecx, edx: the values returned by the cpuid instruction for
  2144. this function/index combination
  2145. 4.89 KVM_S390_MEM_OP
  2146. Capability: KVM_CAP_S390_MEM_OP
  2147. Architectures: s390
  2148. Type: vcpu ioctl
  2149. Parameters: struct kvm_s390_mem_op (in)
  2150. Returns: = 0 on success,
  2151. < 0 on generic error (e.g. -EFAULT or -ENOMEM),
  2152. > 0 if an exception occurred while walking the page tables
  2153. Read or write data from/to the logical (virtual) memory of a VPCU.
  2154. Parameters are specified via the following structure:
  2155. struct kvm_s390_mem_op {
  2156. __u64 gaddr; /* the guest address */
  2157. __u64 flags; /* flags */
  2158. __u32 size; /* amount of bytes */
  2159. __u32 op; /* type of operation */
  2160. __u64 buf; /* buffer in userspace */
  2161. __u8 ar; /* the access register number */
  2162. __u8 reserved[31]; /* should be set to 0 */
  2163. };
  2164. The type of operation is specified in the "op" field. It is either
  2165. KVM_S390_MEMOP_LOGICAL_READ for reading from logical memory space or
  2166. KVM_S390_MEMOP_LOGICAL_WRITE for writing to logical memory space. The
  2167. KVM_S390_MEMOP_F_CHECK_ONLY flag can be set in the "flags" field to check
  2168. whether the corresponding memory access would create an access exception
  2169. (without touching the data in the memory at the destination). In case an
  2170. access exception occurred while walking the MMU tables of the guest, the
  2171. ioctl returns a positive error number to indicate the type of exception.
  2172. This exception is also raised directly at the corresponding VCPU if the
  2173. flag KVM_S390_MEMOP_F_INJECT_EXCEPTION is set in the "flags" field.
  2174. The start address of the memory region has to be specified in the "gaddr"
  2175. field, and the length of the region in the "size" field. "buf" is the buffer
  2176. supplied by the userspace application where the read data should be written
  2177. to for KVM_S390_MEMOP_LOGICAL_READ, or where the data that should be written
  2178. is stored for a KVM_S390_MEMOP_LOGICAL_WRITE. "buf" is unused and can be NULL
  2179. when KVM_S390_MEMOP_F_CHECK_ONLY is specified. "ar" designates the access
  2180. register number to be used.
  2181. The "reserved" field is meant for future extensions. It is not used by
  2182. KVM with the currently defined set of flags.
  2183. 4.90 KVM_S390_GET_SKEYS
  2184. Capability: KVM_CAP_S390_SKEYS
  2185. Architectures: s390
  2186. Type: vm ioctl
  2187. Parameters: struct kvm_s390_skeys
  2188. Returns: 0 on success, KVM_S390_GET_KEYS_NONE if guest is not using storage
  2189. keys, negative value on error
  2190. This ioctl is used to get guest storage key values on the s390
  2191. architecture. The ioctl takes parameters via the kvm_s390_skeys struct.
  2192. struct kvm_s390_skeys {
  2193. __u64 start_gfn;
  2194. __u64 count;
  2195. __u64 skeydata_addr;
  2196. __u32 flags;
  2197. __u32 reserved[9];
  2198. };
  2199. The start_gfn field is the number of the first guest frame whose storage keys
  2200. you want to get.
  2201. The count field is the number of consecutive frames (starting from start_gfn)
  2202. whose storage keys to get. The count field must be at least 1 and the maximum
  2203. allowed value is defined as KVM_S390_SKEYS_ALLOC_MAX. Values outside this range
  2204. will cause the ioctl to return -EINVAL.
  2205. The skeydata_addr field is the address to a buffer large enough to hold count
  2206. bytes. This buffer will be filled with storage key data by the ioctl.
  2207. 4.91 KVM_S390_SET_SKEYS
  2208. Capability: KVM_CAP_S390_SKEYS
  2209. Architectures: s390
  2210. Type: vm ioctl
  2211. Parameters: struct kvm_s390_skeys
  2212. Returns: 0 on success, negative value on error
  2213. This ioctl is used to set guest storage key values on the s390
  2214. architecture. The ioctl takes parameters via the kvm_s390_skeys struct.
  2215. See section on KVM_S390_GET_SKEYS for struct definition.
  2216. The start_gfn field is the number of the first guest frame whose storage keys
  2217. you want to set.
  2218. The count field is the number of consecutive frames (starting from start_gfn)
  2219. whose storage keys to get. The count field must be at least 1 and the maximum
  2220. allowed value is defined as KVM_S390_SKEYS_ALLOC_MAX. Values outside this range
  2221. will cause the ioctl to return -EINVAL.
  2222. The skeydata_addr field is the address to a buffer containing count bytes of
  2223. storage keys. Each byte in the buffer will be set as the storage key for a
  2224. single frame starting at start_gfn for count frames.
  2225. Note: If any architecturally invalid key value is found in the given data then
  2226. the ioctl will return -EINVAL.
  2227. 4.92 KVM_S390_IRQ
  2228. Capability: KVM_CAP_S390_INJECT_IRQ
  2229. Architectures: s390
  2230. Type: vcpu ioctl
  2231. Parameters: struct kvm_s390_irq (in)
  2232. Returns: 0 on success, -1 on error
  2233. Errors:
  2234. EINVAL: interrupt type is invalid
  2235. type is KVM_S390_SIGP_STOP and flag parameter is invalid value
  2236. type is KVM_S390_INT_EXTERNAL_CALL and code is bigger
  2237. than the maximum of VCPUs
  2238. EBUSY: type is KVM_S390_SIGP_SET_PREFIX and vcpu is not stopped
  2239. type is KVM_S390_SIGP_STOP and a stop irq is already pending
  2240. type is KVM_S390_INT_EXTERNAL_CALL and an external call interrupt
  2241. is already pending
  2242. Allows to inject an interrupt to the guest.
  2243. Using struct kvm_s390_irq as a parameter allows
  2244. to inject additional payload which is not
  2245. possible via KVM_S390_INTERRUPT.
  2246. Interrupt parameters are passed via kvm_s390_irq:
  2247. struct kvm_s390_irq {
  2248. __u64 type;
  2249. union {
  2250. struct kvm_s390_io_info io;
  2251. struct kvm_s390_ext_info ext;
  2252. struct kvm_s390_pgm_info pgm;
  2253. struct kvm_s390_emerg_info emerg;
  2254. struct kvm_s390_extcall_info extcall;
  2255. struct kvm_s390_prefix_info prefix;
  2256. struct kvm_s390_stop_info stop;
  2257. struct kvm_s390_mchk_info mchk;
  2258. char reserved[64];
  2259. } u;
  2260. };
  2261. type can be one of the following:
  2262. KVM_S390_SIGP_STOP - sigp stop; parameter in .stop
  2263. KVM_S390_PROGRAM_INT - program check; parameters in .pgm
  2264. KVM_S390_SIGP_SET_PREFIX - sigp set prefix; parameters in .prefix
  2265. KVM_S390_RESTART - restart; no parameters
  2266. KVM_S390_INT_CLOCK_COMP - clock comparator interrupt; no parameters
  2267. KVM_S390_INT_CPU_TIMER - CPU timer interrupt; no parameters
  2268. KVM_S390_INT_EMERGENCY - sigp emergency; parameters in .emerg
  2269. KVM_S390_INT_EXTERNAL_CALL - sigp external call; parameters in .extcall
  2270. KVM_S390_MCHK - machine check interrupt; parameters in .mchk
  2271. Note that the vcpu ioctl is asynchronous to vcpu execution.
  2272. 4.94 KVM_S390_GET_IRQ_STATE
  2273. Capability: KVM_CAP_S390_IRQ_STATE
  2274. Architectures: s390
  2275. Type: vcpu ioctl
  2276. Parameters: struct kvm_s390_irq_state (out)
  2277. Returns: >= number of bytes copied into buffer,
  2278. -EINVAL if buffer size is 0,
  2279. -ENOBUFS if buffer size is too small to fit all pending interrupts,
  2280. -EFAULT if the buffer address was invalid
  2281. This ioctl allows userspace to retrieve the complete state of all currently
  2282. pending interrupts in a single buffer. Use cases include migration
  2283. and introspection. The parameter structure contains the address of a
  2284. userspace buffer and its length:
  2285. struct kvm_s390_irq_state {
  2286. __u64 buf;
  2287. __u32 flags;
  2288. __u32 len;
  2289. __u32 reserved[4];
  2290. };
  2291. Userspace passes in the above struct and for each pending interrupt a
  2292. struct kvm_s390_irq is copied to the provided buffer.
  2293. If -ENOBUFS is returned the buffer provided was too small and userspace
  2294. may retry with a bigger buffer.
  2295. 4.95 KVM_S390_SET_IRQ_STATE
  2296. Capability: KVM_CAP_S390_IRQ_STATE
  2297. Architectures: s390
  2298. Type: vcpu ioctl
  2299. Parameters: struct kvm_s390_irq_state (in)
  2300. Returns: 0 on success,
  2301. -EFAULT if the buffer address was invalid,
  2302. -EINVAL for an invalid buffer length (see below),
  2303. -EBUSY if there were already interrupts pending,
  2304. errors occurring when actually injecting the
  2305. interrupt. See KVM_S390_IRQ.
  2306. This ioctl allows userspace to set the complete state of all cpu-local
  2307. interrupts currently pending for the vcpu. It is intended for restoring
  2308. interrupt state after a migration. The input parameter is a userspace buffer
  2309. containing a struct kvm_s390_irq_state:
  2310. struct kvm_s390_irq_state {
  2311. __u64 buf;
  2312. __u32 len;
  2313. __u32 pad;
  2314. };
  2315. The userspace memory referenced by buf contains a struct kvm_s390_irq
  2316. for each interrupt to be injected into the guest.
  2317. If one of the interrupts could not be injected for some reason the
  2318. ioctl aborts.
  2319. len must be a multiple of sizeof(struct kvm_s390_irq). It must be > 0
  2320. and it must not exceed (max_vcpus + 32) * sizeof(struct kvm_s390_irq),
  2321. which is the maximum number of possibly pending cpu-local interrupts.
  2322. 4.90 KVM_SMI
  2323. Capability: KVM_CAP_X86_SMM
  2324. Architectures: x86
  2325. Type: vcpu ioctl
  2326. Parameters: none
  2327. Returns: 0 on success, -1 on error
  2328. Queues an SMI on the thread's vcpu.
  2329. 5. The kvm_run structure
  2330. ------------------------
  2331. Application code obtains a pointer to the kvm_run structure by
  2332. mmap()ing a vcpu fd. From that point, application code can control
  2333. execution by changing fields in kvm_run prior to calling the KVM_RUN
  2334. ioctl, and obtain information about the reason KVM_RUN returned by
  2335. looking up structure members.
  2336. struct kvm_run {
  2337. /* in */
  2338. __u8 request_interrupt_window;
  2339. Request that KVM_RUN return when it becomes possible to inject external
  2340. interrupts into the guest. Useful in conjunction with KVM_INTERRUPT.
  2341. __u8 padding1[7];
  2342. /* out */
  2343. __u32 exit_reason;
  2344. When KVM_RUN has returned successfully (return value 0), this informs
  2345. application code why KVM_RUN has returned. Allowable values for this
  2346. field are detailed below.
  2347. __u8 ready_for_interrupt_injection;
  2348. If request_interrupt_window has been specified, this field indicates
  2349. an interrupt can be injected now with KVM_INTERRUPT.
  2350. __u8 if_flag;
  2351. The value of the current interrupt flag. Only valid if in-kernel
  2352. local APIC is not used.
  2353. __u16 flags;
  2354. More architecture-specific flags detailing state of the VCPU that may
  2355. affect the device's behavior. The only currently defined flag is
  2356. KVM_RUN_X86_SMM, which is valid on x86 machines and is set if the
  2357. VCPU is in system management mode.
  2358. /* in (pre_kvm_run), out (post_kvm_run) */
  2359. __u64 cr8;
  2360. The value of the cr8 register. Only valid if in-kernel local APIC is
  2361. not used. Both input and output.
  2362. __u64 apic_base;
  2363. The value of the APIC BASE msr. Only valid if in-kernel local
  2364. APIC is not used. Both input and output.
  2365. union {
  2366. /* KVM_EXIT_UNKNOWN */
  2367. struct {
  2368. __u64 hardware_exit_reason;
  2369. } hw;
  2370. If exit_reason is KVM_EXIT_UNKNOWN, the vcpu has exited due to unknown
  2371. reasons. Further architecture-specific information is available in
  2372. hardware_exit_reason.
  2373. /* KVM_EXIT_FAIL_ENTRY */
  2374. struct {
  2375. __u64 hardware_entry_failure_reason;
  2376. } fail_entry;
  2377. If exit_reason is KVM_EXIT_FAIL_ENTRY, the vcpu could not be run due
  2378. to unknown reasons. Further architecture-specific information is
  2379. available in hardware_entry_failure_reason.
  2380. /* KVM_EXIT_EXCEPTION */
  2381. struct {
  2382. __u32 exception;
  2383. __u32 error_code;
  2384. } ex;
  2385. Unused.
  2386. /* KVM_EXIT_IO */
  2387. struct {
  2388. #define KVM_EXIT_IO_IN 0
  2389. #define KVM_EXIT_IO_OUT 1
  2390. __u8 direction;
  2391. __u8 size; /* bytes */
  2392. __u16 port;
  2393. __u32 count;
  2394. __u64 data_offset; /* relative to kvm_run start */
  2395. } io;
  2396. If exit_reason is KVM_EXIT_IO, then the vcpu has
  2397. executed a port I/O instruction which could not be satisfied by kvm.
  2398. data_offset describes where the data is located (KVM_EXIT_IO_OUT) or
  2399. where kvm expects application code to place the data for the next
  2400. KVM_RUN invocation (KVM_EXIT_IO_IN). Data format is a packed array.
  2401. /* KVM_EXIT_DEBUG */
  2402. struct {
  2403. struct kvm_debug_exit_arch arch;
  2404. } debug;
  2405. If the exit_reason is KVM_EXIT_DEBUG, then a vcpu is processing a debug event
  2406. for which architecture specific information is returned.
  2407. /* KVM_EXIT_MMIO */
  2408. struct {
  2409. __u64 phys_addr;
  2410. __u8 data[8];
  2411. __u32 len;
  2412. __u8 is_write;
  2413. } mmio;
  2414. If exit_reason is KVM_EXIT_MMIO, then the vcpu has
  2415. executed a memory-mapped I/O instruction which could not be satisfied
  2416. by kvm. The 'data' member contains the written data if 'is_write' is
  2417. true, and should be filled by application code otherwise.
  2418. The 'data' member contains, in its first 'len' bytes, the value as it would
  2419. appear if the VCPU performed a load or store of the appropriate width directly
  2420. to the byte array.
  2421. NOTE: For KVM_EXIT_IO, KVM_EXIT_MMIO, KVM_EXIT_OSI, KVM_EXIT_PAPR and
  2422. KVM_EXIT_EPR the corresponding
  2423. operations are complete (and guest state is consistent) only after userspace
  2424. has re-entered the kernel with KVM_RUN. The kernel side will first finish
  2425. incomplete operations and then check for pending signals. Userspace
  2426. can re-enter the guest with an unmasked signal pending to complete
  2427. pending operations.
  2428. /* KVM_EXIT_HYPERCALL */
  2429. struct {
  2430. __u64 nr;
  2431. __u64 args[6];
  2432. __u64 ret;
  2433. __u32 longmode;
  2434. __u32 pad;
  2435. } hypercall;
  2436. Unused. This was once used for 'hypercall to userspace'. To implement
  2437. such functionality, use KVM_EXIT_IO (x86) or KVM_EXIT_MMIO (all except s390).
  2438. Note KVM_EXIT_IO is significantly faster than KVM_EXIT_MMIO.
  2439. /* KVM_EXIT_TPR_ACCESS */
  2440. struct {
  2441. __u64 rip;
  2442. __u32 is_write;
  2443. __u32 pad;
  2444. } tpr_access;
  2445. To be documented (KVM_TPR_ACCESS_REPORTING).
  2446. /* KVM_EXIT_S390_SIEIC */
  2447. struct {
  2448. __u8 icptcode;
  2449. __u64 mask; /* psw upper half */
  2450. __u64 addr; /* psw lower half */
  2451. __u16 ipa;
  2452. __u32 ipb;
  2453. } s390_sieic;
  2454. s390 specific.
  2455. /* KVM_EXIT_S390_RESET */
  2456. #define KVM_S390_RESET_POR 1
  2457. #define KVM_S390_RESET_CLEAR 2
  2458. #define KVM_S390_RESET_SUBSYSTEM 4
  2459. #define KVM_S390_RESET_CPU_INIT 8
  2460. #define KVM_S390_RESET_IPL 16
  2461. __u64 s390_reset_flags;
  2462. s390 specific.
  2463. /* KVM_EXIT_S390_UCONTROL */
  2464. struct {
  2465. __u64 trans_exc_code;
  2466. __u32 pgm_code;
  2467. } s390_ucontrol;
  2468. s390 specific. A page fault has occurred for a user controlled virtual
  2469. machine (KVM_VM_S390_UNCONTROL) on it's host page table that cannot be
  2470. resolved by the kernel.
  2471. The program code and the translation exception code that were placed
  2472. in the cpu's lowcore are presented here as defined by the z Architecture
  2473. Principles of Operation Book in the Chapter for Dynamic Address Translation
  2474. (DAT)
  2475. /* KVM_EXIT_DCR */
  2476. struct {
  2477. __u32 dcrn;
  2478. __u32 data;
  2479. __u8 is_write;
  2480. } dcr;
  2481. Deprecated - was used for 440 KVM.
  2482. /* KVM_EXIT_OSI */
  2483. struct {
  2484. __u64 gprs[32];
  2485. } osi;
  2486. MOL uses a special hypercall interface it calls 'OSI'. To enable it, we catch
  2487. hypercalls and exit with this exit struct that contains all the guest gprs.
  2488. If exit_reason is KVM_EXIT_OSI, then the vcpu has triggered such a hypercall.
  2489. Userspace can now handle the hypercall and when it's done modify the gprs as
  2490. necessary. Upon guest entry all guest GPRs will then be replaced by the values
  2491. in this struct.
  2492. /* KVM_EXIT_PAPR_HCALL */
  2493. struct {
  2494. __u64 nr;
  2495. __u64 ret;
  2496. __u64 args[9];
  2497. } papr_hcall;
  2498. This is used on 64-bit PowerPC when emulating a pSeries partition,
  2499. e.g. with the 'pseries' machine type in qemu. It occurs when the
  2500. guest does a hypercall using the 'sc 1' instruction. The 'nr' field
  2501. contains the hypercall number (from the guest R3), and 'args' contains
  2502. the arguments (from the guest R4 - R12). Userspace should put the
  2503. return code in 'ret' and any extra returned values in args[].
  2504. The possible hypercalls are defined in the Power Architecture Platform
  2505. Requirements (PAPR) document available from www.power.org (free
  2506. developer registration required to access it).
  2507. /* KVM_EXIT_S390_TSCH */
  2508. struct {
  2509. __u16 subchannel_id;
  2510. __u16 subchannel_nr;
  2511. __u32 io_int_parm;
  2512. __u32 io_int_word;
  2513. __u32 ipb;
  2514. __u8 dequeued;
  2515. } s390_tsch;
  2516. s390 specific. This exit occurs when KVM_CAP_S390_CSS_SUPPORT has been enabled
  2517. and TEST SUBCHANNEL was intercepted. If dequeued is set, a pending I/O
  2518. interrupt for the target subchannel has been dequeued and subchannel_id,
  2519. subchannel_nr, io_int_parm and io_int_word contain the parameters for that
  2520. interrupt. ipb is needed for instruction parameter decoding.
  2521. /* KVM_EXIT_EPR */
  2522. struct {
  2523. __u32 epr;
  2524. } epr;
  2525. On FSL BookE PowerPC chips, the interrupt controller has a fast patch
  2526. interrupt acknowledge path to the core. When the core successfully
  2527. delivers an interrupt, it automatically populates the EPR register with
  2528. the interrupt vector number and acknowledges the interrupt inside
  2529. the interrupt controller.
  2530. In case the interrupt controller lives in user space, we need to do
  2531. the interrupt acknowledge cycle through it to fetch the next to be
  2532. delivered interrupt vector using this exit.
  2533. It gets triggered whenever both KVM_CAP_PPC_EPR are enabled and an
  2534. external interrupt has just been delivered into the guest. User space
  2535. should put the acknowledged interrupt vector into the 'epr' field.
  2536. /* KVM_EXIT_SYSTEM_EVENT */
  2537. struct {
  2538. #define KVM_SYSTEM_EVENT_SHUTDOWN 1
  2539. #define KVM_SYSTEM_EVENT_RESET 2
  2540. #define KVM_SYSTEM_EVENT_CRASH 3
  2541. __u32 type;
  2542. __u64 flags;
  2543. } system_event;
  2544. If exit_reason is KVM_EXIT_SYSTEM_EVENT then the vcpu has triggered
  2545. a system-level event using some architecture specific mechanism (hypercall
  2546. or some special instruction). In case of ARM/ARM64, this is triggered using
  2547. HVC instruction based PSCI call from the vcpu. The 'type' field describes
  2548. the system-level event type. The 'flags' field describes architecture
  2549. specific flags for the system-level event.
  2550. Valid values for 'type' are:
  2551. KVM_SYSTEM_EVENT_SHUTDOWN -- the guest has requested a shutdown of the
  2552. VM. Userspace is not obliged to honour this, and if it does honour
  2553. this does not need to destroy the VM synchronously (ie it may call
  2554. KVM_RUN again before shutdown finally occurs).
  2555. KVM_SYSTEM_EVENT_RESET -- the guest has requested a reset of the VM.
  2556. As with SHUTDOWN, userspace can choose to ignore the request, or
  2557. to schedule the reset to occur in the future and may call KVM_RUN again.
  2558. KVM_SYSTEM_EVENT_CRASH -- the guest crash occurred and the guest
  2559. has requested a crash condition maintenance. Userspace can choose
  2560. to ignore the request, or to gather VM memory core dump and/or
  2561. reset/shutdown of the VM.
  2562. /* Fix the size of the union. */
  2563. char padding[256];
  2564. };
  2565. /*
  2566. * shared registers between kvm and userspace.
  2567. * kvm_valid_regs specifies the register classes set by the host
  2568. * kvm_dirty_regs specified the register classes dirtied by userspace
  2569. * struct kvm_sync_regs is architecture specific, as well as the
  2570. * bits for kvm_valid_regs and kvm_dirty_regs
  2571. */
  2572. __u64 kvm_valid_regs;
  2573. __u64 kvm_dirty_regs;
  2574. union {
  2575. struct kvm_sync_regs regs;
  2576. char padding[1024];
  2577. } s;
  2578. If KVM_CAP_SYNC_REGS is defined, these fields allow userspace to access
  2579. certain guest registers without having to call SET/GET_*REGS. Thus we can
  2580. avoid some system call overhead if userspace has to handle the exit.
  2581. Userspace can query the validity of the structure by checking
  2582. kvm_valid_regs for specific bits. These bits are architecture specific
  2583. and usually define the validity of a groups of registers. (e.g. one bit
  2584. for general purpose registers)
  2585. Please note that the kernel is allowed to use the kvm_run structure as the
  2586. primary storage for certain register types. Therefore, the kernel may use the
  2587. values in kvm_run even if the corresponding bit in kvm_dirty_regs is not set.
  2588. };
  2589. 6. Capabilities that can be enabled on vCPUs
  2590. --------------------------------------------
  2591. There are certain capabilities that change the behavior of the virtual CPU or
  2592. the virtual machine when enabled. To enable them, please see section 4.37.
  2593. Below you can find a list of capabilities and what their effect on the vCPU or
  2594. the virtual machine is when enabling them.
  2595. The following information is provided along with the description:
  2596. Architectures: which instruction set architectures provide this ioctl.
  2597. x86 includes both i386 and x86_64.
  2598. Target: whether this is a per-vcpu or per-vm capability.
  2599. Parameters: what parameters are accepted by the capability.
  2600. Returns: the return value. General error numbers (EBADF, ENOMEM, EINVAL)
  2601. are not detailed, but errors with specific meanings are.
  2602. 6.1 KVM_CAP_PPC_OSI
  2603. Architectures: ppc
  2604. Target: vcpu
  2605. Parameters: none
  2606. Returns: 0 on success; -1 on error
  2607. This capability enables interception of OSI hypercalls that otherwise would
  2608. be treated as normal system calls to be injected into the guest. OSI hypercalls
  2609. were invented by Mac-on-Linux to have a standardized communication mechanism
  2610. between the guest and the host.
  2611. When this capability is enabled, KVM_EXIT_OSI can occur.
  2612. 6.2 KVM_CAP_PPC_PAPR
  2613. Architectures: ppc
  2614. Target: vcpu
  2615. Parameters: none
  2616. Returns: 0 on success; -1 on error
  2617. This capability enables interception of PAPR hypercalls. PAPR hypercalls are
  2618. done using the hypercall instruction "sc 1".
  2619. It also sets the guest privilege level to "supervisor" mode. Usually the guest
  2620. runs in "hypervisor" privilege mode with a few missing features.
  2621. In addition to the above, it changes the semantics of SDR1. In this mode, the
  2622. HTAB address part of SDR1 contains an HVA instead of a GPA, as PAPR keeps the
  2623. HTAB invisible to the guest.
  2624. When this capability is enabled, KVM_EXIT_PAPR_HCALL can occur.
  2625. 6.3 KVM_CAP_SW_TLB
  2626. Architectures: ppc
  2627. Target: vcpu
  2628. Parameters: args[0] is the address of a struct kvm_config_tlb
  2629. Returns: 0 on success; -1 on error
  2630. struct kvm_config_tlb {
  2631. __u64 params;
  2632. __u64 array;
  2633. __u32 mmu_type;
  2634. __u32 array_len;
  2635. };
  2636. Configures the virtual CPU's TLB array, establishing a shared memory area
  2637. between userspace and KVM. The "params" and "array" fields are userspace
  2638. addresses of mmu-type-specific data structures. The "array_len" field is an
  2639. safety mechanism, and should be set to the size in bytes of the memory that
  2640. userspace has reserved for the array. It must be at least the size dictated
  2641. by "mmu_type" and "params".
  2642. While KVM_RUN is active, the shared region is under control of KVM. Its
  2643. contents are undefined, and any modification by userspace results in
  2644. boundedly undefined behavior.
  2645. On return from KVM_RUN, the shared region will reflect the current state of
  2646. the guest's TLB. If userspace makes any changes, it must call KVM_DIRTY_TLB
  2647. to tell KVM which entries have been changed, prior to calling KVM_RUN again
  2648. on this vcpu.
  2649. For mmu types KVM_MMU_FSL_BOOKE_NOHV and KVM_MMU_FSL_BOOKE_HV:
  2650. - The "params" field is of type "struct kvm_book3e_206_tlb_params".
  2651. - The "array" field points to an array of type "struct
  2652. kvm_book3e_206_tlb_entry".
  2653. - The array consists of all entries in the first TLB, followed by all
  2654. entries in the second TLB.
  2655. - Within a TLB, entries are ordered first by increasing set number. Within a
  2656. set, entries are ordered by way (increasing ESEL).
  2657. - The hash for determining set number in TLB0 is: (MAS2 >> 12) & (num_sets - 1)
  2658. where "num_sets" is the tlb_sizes[] value divided by the tlb_ways[] value.
  2659. - The tsize field of mas1 shall be set to 4K on TLB0, even though the
  2660. hardware ignores this value for TLB0.
  2661. 6.4 KVM_CAP_S390_CSS_SUPPORT
  2662. Architectures: s390
  2663. Target: vcpu
  2664. Parameters: none
  2665. Returns: 0 on success; -1 on error
  2666. This capability enables support for handling of channel I/O instructions.
  2667. TEST PENDING INTERRUPTION and the interrupt portion of TEST SUBCHANNEL are
  2668. handled in-kernel, while the other I/O instructions are passed to userspace.
  2669. When this capability is enabled, KVM_EXIT_S390_TSCH will occur on TEST
  2670. SUBCHANNEL intercepts.
  2671. Note that even though this capability is enabled per-vcpu, the complete
  2672. virtual machine is affected.
  2673. 6.5 KVM_CAP_PPC_EPR
  2674. Architectures: ppc
  2675. Target: vcpu
  2676. Parameters: args[0] defines whether the proxy facility is active
  2677. Returns: 0 on success; -1 on error
  2678. This capability enables or disables the delivery of interrupts through the
  2679. external proxy facility.
  2680. When enabled (args[0] != 0), every time the guest gets an external interrupt
  2681. delivered, it automatically exits into user space with a KVM_EXIT_EPR exit
  2682. to receive the topmost interrupt vector.
  2683. When disabled (args[0] == 0), behavior is as if this facility is unsupported.
  2684. When this capability is enabled, KVM_EXIT_EPR can occur.
  2685. 6.6 KVM_CAP_IRQ_MPIC
  2686. Architectures: ppc
  2687. Parameters: args[0] is the MPIC device fd
  2688. args[1] is the MPIC CPU number for this vcpu
  2689. This capability connects the vcpu to an in-kernel MPIC device.
  2690. 6.7 KVM_CAP_IRQ_XICS
  2691. Architectures: ppc
  2692. Target: vcpu
  2693. Parameters: args[0] is the XICS device fd
  2694. args[1] is the XICS CPU number (server ID) for this vcpu
  2695. This capability connects the vcpu to an in-kernel XICS device.
  2696. 6.8 KVM_CAP_S390_IRQCHIP
  2697. Architectures: s390
  2698. Target: vm
  2699. Parameters: none
  2700. This capability enables the in-kernel irqchip for s390. Please refer to
  2701. "4.24 KVM_CREATE_IRQCHIP" for details.
  2702. 6.9 KVM_CAP_MIPS_FPU
  2703. Architectures: mips
  2704. Target: vcpu
  2705. Parameters: args[0] is reserved for future use (should be 0).
  2706. This capability allows the use of the host Floating Point Unit by the guest. It
  2707. allows the Config1.FP bit to be set to enable the FPU in the guest. Once this is
  2708. done the KVM_REG_MIPS_FPR_* and KVM_REG_MIPS_FCR_* registers can be accessed
  2709. (depending on the current guest FPU register mode), and the Status.FR,
  2710. Config5.FRE bits are accessible via the KVM API and also from the guest,
  2711. depending on them being supported by the FPU.
  2712. 6.10 KVM_CAP_MIPS_MSA
  2713. Architectures: mips
  2714. Target: vcpu
  2715. Parameters: args[0] is reserved for future use (should be 0).
  2716. This capability allows the use of the MIPS SIMD Architecture (MSA) by the guest.
  2717. It allows the Config3.MSAP bit to be set to enable the use of MSA by the guest.
  2718. Once this is done the KVM_REG_MIPS_VEC_* and KVM_REG_MIPS_MSA_* registers can be
  2719. accessed, and the Config5.MSAEn bit is accessible via the KVM API and also from
  2720. the guest.
  2721. 7. Capabilities that can be enabled on VMs
  2722. ------------------------------------------
  2723. There are certain capabilities that change the behavior of the virtual
  2724. machine when enabled. To enable them, please see section 4.37. Below
  2725. you can find a list of capabilities and what their effect on the VM
  2726. is when enabling them.
  2727. The following information is provided along with the description:
  2728. Architectures: which instruction set architectures provide this ioctl.
  2729. x86 includes both i386 and x86_64.
  2730. Parameters: what parameters are accepted by the capability.
  2731. Returns: the return value. General error numbers (EBADF, ENOMEM, EINVAL)
  2732. are not detailed, but errors with specific meanings are.
  2733. 7.1 KVM_CAP_PPC_ENABLE_HCALL
  2734. Architectures: ppc
  2735. Parameters: args[0] is the sPAPR hcall number
  2736. args[1] is 0 to disable, 1 to enable in-kernel handling
  2737. This capability controls whether individual sPAPR hypercalls (hcalls)
  2738. get handled by the kernel or not. Enabling or disabling in-kernel
  2739. handling of an hcall is effective across the VM. On creation, an
  2740. initial set of hcalls are enabled for in-kernel handling, which
  2741. consists of those hcalls for which in-kernel handlers were implemented
  2742. before this capability was implemented. If disabled, the kernel will
  2743. not to attempt to handle the hcall, but will always exit to userspace
  2744. to handle it. Note that it may not make sense to enable some and
  2745. disable others of a group of related hcalls, but KVM does not prevent
  2746. userspace from doing that.
  2747. If the hcall number specified is not one that has an in-kernel
  2748. implementation, the KVM_ENABLE_CAP ioctl will fail with an EINVAL
  2749. error.
  2750. 7.2 KVM_CAP_S390_USER_SIGP
  2751. Architectures: s390
  2752. Parameters: none
  2753. This capability controls which SIGP orders will be handled completely in user
  2754. space. With this capability enabled, all fast orders will be handled completely
  2755. in the kernel:
  2756. - SENSE
  2757. - SENSE RUNNING
  2758. - EXTERNAL CALL
  2759. - EMERGENCY SIGNAL
  2760. - CONDITIONAL EMERGENCY SIGNAL
  2761. All other orders will be handled completely in user space.
  2762. Only privileged operation exceptions will be checked for in the kernel (or even
  2763. in the hardware prior to interception). If this capability is not enabled, the
  2764. old way of handling SIGP orders is used (partially in kernel and user space).
  2765. 7.3 KVM_CAP_S390_VECTOR_REGISTERS
  2766. Architectures: s390
  2767. Parameters: none
  2768. Returns: 0 on success, negative value on error
  2769. Allows use of the vector registers introduced with z13 processor, and
  2770. provides for the synchronization between host and user space. Will
  2771. return -EINVAL if the machine does not support vectors.
  2772. 7.4 KVM_CAP_S390_USER_STSI
  2773. Architectures: s390
  2774. Parameters: none
  2775. This capability allows post-handlers for the STSI instruction. After
  2776. initial handling in the kernel, KVM exits to user space with
  2777. KVM_EXIT_S390_STSI to allow user space to insert further data.
  2778. Before exiting to userspace, kvm handlers should fill in s390_stsi field of
  2779. vcpu->run:
  2780. struct {
  2781. __u64 addr;
  2782. __u8 ar;
  2783. __u8 reserved;
  2784. __u8 fc;
  2785. __u8 sel1;
  2786. __u16 sel2;
  2787. } s390_stsi;
  2788. @addr - guest address of STSI SYSIB
  2789. @fc - function code
  2790. @sel1 - selector 1
  2791. @sel2 - selector 2
  2792. @ar - access register number
  2793. KVM handlers should exit to userspace with rc = -EREMOTE.
  2794. 8. Other capabilities.
  2795. ----------------------
  2796. This section lists capabilities that give information about other
  2797. features of the KVM implementation.
  2798. 8.1 KVM_CAP_PPC_HWRNG
  2799. Architectures: ppc
  2800. This capability, if KVM_CHECK_EXTENSION indicates that it is
  2801. available, means that that the kernel has an implementation of the
  2802. H_RANDOM hypercall backed by a hardware random-number generator.
  2803. If present, the kernel H_RANDOM handler can be enabled for guest use
  2804. with the KVM_CAP_PPC_ENABLE_HCALL capability.