api.txt 96 KB

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