api.txt 159 KB

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