api.txt 101 KB

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