api.txt 158 KB

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