api.txt 136 KB

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