api.txt 71 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465
  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 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
  111. Architectures: all
  112. Type: system 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. 4.5 KVM_GET_VCPU_MMAP_SIZE
  121. Capability: basic
  122. Architectures: all
  123. Type: system ioctl
  124. Parameters: none
  125. Returns: size of vcpu mmap area, in bytes
  126. The KVM_RUN ioctl (cf.) communicates with userspace via a shared
  127. memory region. This ioctl returns the size of that region. See the
  128. KVM_RUN documentation for details.
  129. 4.6 KVM_SET_MEMORY_REGION
  130. Capability: basic
  131. Architectures: all
  132. Type: vm ioctl
  133. Parameters: struct kvm_memory_region (in)
  134. Returns: 0 on success, -1 on error
  135. This ioctl is obsolete and has been removed.
  136. 4.7 KVM_CREATE_VCPU
  137. Capability: basic
  138. Architectures: all
  139. Type: vm ioctl
  140. Parameters: vcpu id (apic id on x86)
  141. Returns: vcpu fd on success, -1 on error
  142. This API adds a vcpu to a virtual machine. The vcpu id is a small integer
  143. in the range [0, max_vcpus).
  144. The recommended max_vcpus value can be retrieved using the KVM_CAP_NR_VCPUS of
  145. the KVM_CHECK_EXTENSION ioctl() at run-time.
  146. The maximum possible value for max_vcpus can be retrieved using the
  147. KVM_CAP_MAX_VCPUS of the KVM_CHECK_EXTENSION ioctl() at run-time.
  148. If the KVM_CAP_NR_VCPUS does not exist, you should assume that max_vcpus is 4
  149. cpus max.
  150. If the KVM_CAP_MAX_VCPUS does not exist, you should assume that max_vcpus is
  151. same as the value returned from KVM_CAP_NR_VCPUS.
  152. On powerpc using book3s_hv mode, the vcpus are mapped onto virtual
  153. threads in one or more virtual CPU cores. (This is because the
  154. hardware requires all the hardware threads in a CPU core to be in the
  155. same partition.) The KVM_CAP_PPC_SMT capability indicates the number
  156. of vcpus per virtual core (vcore). The vcore id is obtained by
  157. dividing the vcpu id by the number of vcpus per vcore. The vcpus in a
  158. given vcore will always be in the same physical core as each other
  159. (though that might be a different physical core from time to time).
  160. Userspace can control the threading (SMT) mode of the guest by its
  161. allocation of vcpu ids. For example, if userspace wants
  162. single-threaded guest vcpus, it should make all vcpu ids be a multiple
  163. of the number of vcpus per vcore.
  164. On powerpc using book3s_hv mode, the vcpus are mapped onto virtual
  165. threads in one or more virtual CPU cores. (This is because the
  166. hardware requires all the hardware threads in a CPU core to be in the
  167. same partition.) The KVM_CAP_PPC_SMT capability indicates the number
  168. of vcpus per virtual core (vcore). The vcore id is obtained by
  169. dividing the vcpu id by the number of vcpus per vcore. The vcpus in a
  170. given vcore will always be in the same physical core as each other
  171. (though that might be a different physical core from time to time).
  172. Userspace can control the threading (SMT) mode of the guest by its
  173. allocation of vcpu ids. For example, if userspace wants
  174. single-threaded guest vcpus, it should make all vcpu ids be a multiple
  175. of the number of vcpus per vcore.
  176. For virtual cpus that have been created with S390 user controlled virtual
  177. machines, the resulting vcpu fd can be memory mapped at page offset
  178. KVM_S390_SIE_PAGE_OFFSET in order to obtain a memory map of the virtual
  179. cpu's hardware control block.
  180. 4.8 KVM_GET_DIRTY_LOG (vm ioctl)
  181. Capability: basic
  182. Architectures: x86
  183. Type: vm ioctl
  184. Parameters: struct kvm_dirty_log (in/out)
  185. Returns: 0 on success, -1 on error
  186. /* for KVM_GET_DIRTY_LOG */
  187. struct kvm_dirty_log {
  188. __u32 slot;
  189. __u32 padding;
  190. union {
  191. void __user *dirty_bitmap; /* one bit per page */
  192. __u64 padding;
  193. };
  194. };
  195. Given a memory slot, return a bitmap containing any pages dirtied
  196. since the last call to this ioctl. Bit 0 is the first page in the
  197. memory slot. Ensure the entire structure is cleared to avoid padding
  198. issues.
  199. 4.9 KVM_SET_MEMORY_ALIAS
  200. Capability: basic
  201. Architectures: x86
  202. Type: vm ioctl
  203. Parameters: struct kvm_memory_alias (in)
  204. Returns: 0 (success), -1 (error)
  205. This ioctl is obsolete and has been removed.
  206. 4.10 KVM_RUN
  207. Capability: basic
  208. Architectures: all
  209. Type: vcpu ioctl
  210. Parameters: none
  211. Returns: 0 on success, -1 on error
  212. Errors:
  213. EINTR: an unmasked signal is pending
  214. This ioctl is used to run a guest virtual cpu. While there are no
  215. explicit parameters, there is an implicit parameter block that can be
  216. obtained by mmap()ing the vcpu fd at offset 0, with the size given by
  217. KVM_GET_VCPU_MMAP_SIZE. The parameter block is formatted as a 'struct
  218. kvm_run' (see below).
  219. 4.11 KVM_GET_REGS
  220. Capability: basic
  221. Architectures: all
  222. Type: vcpu ioctl
  223. Parameters: struct kvm_regs (out)
  224. Returns: 0 on success, -1 on error
  225. Reads the general purpose registers from the vcpu.
  226. /* x86 */
  227. struct kvm_regs {
  228. /* out (KVM_GET_REGS) / in (KVM_SET_REGS) */
  229. __u64 rax, rbx, rcx, rdx;
  230. __u64 rsi, rdi, rsp, rbp;
  231. __u64 r8, r9, r10, r11;
  232. __u64 r12, r13, r14, r15;
  233. __u64 rip, rflags;
  234. };
  235. 4.12 KVM_SET_REGS
  236. Capability: basic
  237. Architectures: all
  238. Type: vcpu ioctl
  239. Parameters: struct kvm_regs (in)
  240. Returns: 0 on success, -1 on error
  241. Writes the general purpose registers into the vcpu.
  242. See KVM_GET_REGS for the data structure.
  243. 4.13 KVM_GET_SREGS
  244. Capability: basic
  245. Architectures: x86, ppc
  246. Type: vcpu ioctl
  247. Parameters: struct kvm_sregs (out)
  248. Returns: 0 on success, -1 on error
  249. Reads special registers from the vcpu.
  250. /* x86 */
  251. struct kvm_sregs {
  252. struct kvm_segment cs, ds, es, fs, gs, ss;
  253. struct kvm_segment tr, ldt;
  254. struct kvm_dtable gdt, idt;
  255. __u64 cr0, cr2, cr3, cr4, cr8;
  256. __u64 efer;
  257. __u64 apic_base;
  258. __u64 interrupt_bitmap[(KVM_NR_INTERRUPTS + 63) / 64];
  259. };
  260. /* ppc -- see arch/powerpc/include/asm/kvm.h */
  261. interrupt_bitmap is a bitmap of pending external interrupts. At most
  262. one bit may be set. This interrupt has been acknowledged by the APIC
  263. but not yet injected into the cpu core.
  264. 4.14 KVM_SET_SREGS
  265. Capability: basic
  266. Architectures: x86, ppc
  267. Type: vcpu ioctl
  268. Parameters: struct kvm_sregs (in)
  269. Returns: 0 on success, -1 on error
  270. Writes special registers into the vcpu. See KVM_GET_SREGS for the
  271. data structures.
  272. 4.15 KVM_TRANSLATE
  273. Capability: basic
  274. Architectures: x86
  275. Type: vcpu ioctl
  276. Parameters: struct kvm_translation (in/out)
  277. Returns: 0 on success, -1 on error
  278. Translates a virtual address according to the vcpu's current address
  279. translation mode.
  280. struct kvm_translation {
  281. /* in */
  282. __u64 linear_address;
  283. /* out */
  284. __u64 physical_address;
  285. __u8 valid;
  286. __u8 writeable;
  287. __u8 usermode;
  288. __u8 pad[5];
  289. };
  290. 4.16 KVM_INTERRUPT
  291. Capability: basic
  292. Architectures: x86, ppc
  293. Type: vcpu ioctl
  294. Parameters: struct kvm_interrupt (in)
  295. Returns: 0 on success, -1 on error
  296. Queues a hardware interrupt vector to be injected. This is only
  297. useful if in-kernel local APIC or equivalent is not used.
  298. /* for KVM_INTERRUPT */
  299. struct kvm_interrupt {
  300. /* in */
  301. __u32 irq;
  302. };
  303. X86:
  304. Note 'irq' is an interrupt vector, not an interrupt pin or line.
  305. PPC:
  306. Queues an external interrupt to be injected. This ioctl is overleaded
  307. with 3 different irq values:
  308. a) KVM_INTERRUPT_SET
  309. This injects an edge type external interrupt into the guest once it's ready
  310. to receive interrupts. When injected, the interrupt is done.
  311. b) KVM_INTERRUPT_UNSET
  312. This unsets any pending interrupt.
  313. Only available with KVM_CAP_PPC_UNSET_IRQ.
  314. c) KVM_INTERRUPT_SET_LEVEL
  315. This injects a level type external interrupt into the guest context. The
  316. interrupt stays pending until a specific ioctl with KVM_INTERRUPT_UNSET
  317. is triggered.
  318. Only available with KVM_CAP_PPC_IRQ_LEVEL.
  319. Note that any value for 'irq' other than the ones stated above is invalid
  320. and incurs unexpected behavior.
  321. 4.17 KVM_DEBUG_GUEST
  322. Capability: basic
  323. Architectures: none
  324. Type: vcpu ioctl
  325. Parameters: none)
  326. Returns: -1 on error
  327. Support for this has been removed. Use KVM_SET_GUEST_DEBUG instead.
  328. 4.18 KVM_GET_MSRS
  329. Capability: basic
  330. Architectures: x86
  331. Type: vcpu ioctl
  332. Parameters: struct kvm_msrs (in/out)
  333. Returns: 0 on success, -1 on error
  334. Reads model-specific registers from the vcpu. Supported msr indices can
  335. be obtained using KVM_GET_MSR_INDEX_LIST.
  336. struct kvm_msrs {
  337. __u32 nmsrs; /* number of msrs in entries */
  338. __u32 pad;
  339. struct kvm_msr_entry entries[0];
  340. };
  341. struct kvm_msr_entry {
  342. __u32 index;
  343. __u32 reserved;
  344. __u64 data;
  345. };
  346. Application code should set the 'nmsrs' member (which indicates the
  347. size of the entries array) and the 'index' member of each array entry.
  348. kvm will fill in the 'data' member.
  349. 4.19 KVM_SET_MSRS
  350. Capability: basic
  351. Architectures: x86
  352. Type: vcpu ioctl
  353. Parameters: struct kvm_msrs (in)
  354. Returns: 0 on success, -1 on error
  355. Writes model-specific registers to the vcpu. See KVM_GET_MSRS for the
  356. data structures.
  357. Application code should set the 'nmsrs' member (which indicates the
  358. size of the entries array), and the 'index' and 'data' members of each
  359. array entry.
  360. 4.20 KVM_SET_CPUID
  361. Capability: basic
  362. Architectures: x86
  363. Type: vcpu ioctl
  364. Parameters: struct kvm_cpuid (in)
  365. Returns: 0 on success, -1 on error
  366. Defines the vcpu responses to the cpuid instruction. Applications
  367. should use the KVM_SET_CPUID2 ioctl if available.
  368. struct kvm_cpuid_entry {
  369. __u32 function;
  370. __u32 eax;
  371. __u32 ebx;
  372. __u32 ecx;
  373. __u32 edx;
  374. __u32 padding;
  375. };
  376. /* for KVM_SET_CPUID */
  377. struct kvm_cpuid {
  378. __u32 nent;
  379. __u32 padding;
  380. struct kvm_cpuid_entry entries[0];
  381. };
  382. 4.21 KVM_SET_SIGNAL_MASK
  383. Capability: basic
  384. Architectures: x86
  385. Type: vcpu ioctl
  386. Parameters: struct kvm_signal_mask (in)
  387. Returns: 0 on success, -1 on error
  388. Defines which signals are blocked during execution of KVM_RUN. This
  389. signal mask temporarily overrides the threads signal mask. Any
  390. unblocked signal received (except SIGKILL and SIGSTOP, which retain
  391. their traditional behaviour) will cause KVM_RUN to return with -EINTR.
  392. Note the signal will only be delivered if not blocked by the original
  393. signal mask.
  394. /* for KVM_SET_SIGNAL_MASK */
  395. struct kvm_signal_mask {
  396. __u32 len;
  397. __u8 sigset[0];
  398. };
  399. 4.22 KVM_GET_FPU
  400. Capability: basic
  401. Architectures: x86
  402. Type: vcpu ioctl
  403. Parameters: struct kvm_fpu (out)
  404. Returns: 0 on success, -1 on error
  405. Reads the floating point state from the vcpu.
  406. /* for KVM_GET_FPU and KVM_SET_FPU */
  407. struct kvm_fpu {
  408. __u8 fpr[8][16];
  409. __u16 fcw;
  410. __u16 fsw;
  411. __u8 ftwx; /* in fxsave format */
  412. __u8 pad1;
  413. __u16 last_opcode;
  414. __u64 last_ip;
  415. __u64 last_dp;
  416. __u8 xmm[16][16];
  417. __u32 mxcsr;
  418. __u32 pad2;
  419. };
  420. 4.23 KVM_SET_FPU
  421. Capability: basic
  422. Architectures: x86
  423. Type: vcpu ioctl
  424. Parameters: struct kvm_fpu (in)
  425. Returns: 0 on success, -1 on error
  426. Writes the floating point state to the vcpu.
  427. /* for KVM_GET_FPU and KVM_SET_FPU */
  428. struct kvm_fpu {
  429. __u8 fpr[8][16];
  430. __u16 fcw;
  431. __u16 fsw;
  432. __u8 ftwx; /* in fxsave format */
  433. __u8 pad1;
  434. __u16 last_opcode;
  435. __u64 last_ip;
  436. __u64 last_dp;
  437. __u8 xmm[16][16];
  438. __u32 mxcsr;
  439. __u32 pad2;
  440. };
  441. 4.24 KVM_CREATE_IRQCHIP
  442. Capability: KVM_CAP_IRQCHIP
  443. Architectures: x86, ia64
  444. Type: vm ioctl
  445. Parameters: none
  446. Returns: 0 on success, -1 on error
  447. Creates an interrupt controller model in the kernel. On x86, creates a virtual
  448. ioapic, a virtual PIC (two PICs, nested), and sets up future vcpus to have a
  449. local APIC. IRQ routing for GSIs 0-15 is set to both PIC and IOAPIC; GSI 16-23
  450. only go to the IOAPIC. On ia64, a IOSAPIC is created.
  451. 4.25 KVM_IRQ_LINE
  452. Capability: KVM_CAP_IRQCHIP
  453. Architectures: x86, ia64
  454. Type: vm ioctl
  455. Parameters: struct kvm_irq_level
  456. Returns: 0 on success, -1 on error
  457. Sets the level of a GSI input to the interrupt controller model in the kernel.
  458. Requires that an interrupt controller model has been previously created with
  459. KVM_CREATE_IRQCHIP. Note that edge-triggered interrupts require the level
  460. to be set to 1 and then back to 0.
  461. struct kvm_irq_level {
  462. union {
  463. __u32 irq; /* GSI */
  464. __s32 status; /* not used for KVM_IRQ_LEVEL */
  465. };
  466. __u32 level; /* 0 or 1 */
  467. };
  468. 4.26 KVM_GET_IRQCHIP
  469. Capability: KVM_CAP_IRQCHIP
  470. Architectures: x86, ia64
  471. Type: vm ioctl
  472. Parameters: struct kvm_irqchip (in/out)
  473. Returns: 0 on success, -1 on error
  474. Reads the state of a kernel interrupt controller created with
  475. KVM_CREATE_IRQCHIP into a buffer provided by the caller.
  476. struct kvm_irqchip {
  477. __u32 chip_id; /* 0 = PIC1, 1 = PIC2, 2 = IOAPIC */
  478. __u32 pad;
  479. union {
  480. char dummy[512]; /* reserving space */
  481. struct kvm_pic_state pic;
  482. struct kvm_ioapic_state ioapic;
  483. } chip;
  484. };
  485. 4.27 KVM_SET_IRQCHIP
  486. Capability: KVM_CAP_IRQCHIP
  487. Architectures: x86, ia64
  488. Type: vm ioctl
  489. Parameters: struct kvm_irqchip (in)
  490. Returns: 0 on success, -1 on error
  491. Sets the state of a kernel interrupt controller created with
  492. KVM_CREATE_IRQCHIP from a buffer provided by the caller.
  493. struct kvm_irqchip {
  494. __u32 chip_id; /* 0 = PIC1, 1 = PIC2, 2 = IOAPIC */
  495. __u32 pad;
  496. union {
  497. char dummy[512]; /* reserving space */
  498. struct kvm_pic_state pic;
  499. struct kvm_ioapic_state ioapic;
  500. } chip;
  501. };
  502. 4.28 KVM_XEN_HVM_CONFIG
  503. Capability: KVM_CAP_XEN_HVM
  504. Architectures: x86
  505. Type: vm ioctl
  506. Parameters: struct kvm_xen_hvm_config (in)
  507. Returns: 0 on success, -1 on error
  508. Sets the MSR that the Xen HVM guest uses to initialize its hypercall
  509. page, and provides the starting address and size of the hypercall
  510. blobs in userspace. When the guest writes the MSR, kvm copies one
  511. page of a blob (32- or 64-bit, depending on the vcpu mode) to guest
  512. memory.
  513. struct kvm_xen_hvm_config {
  514. __u32 flags;
  515. __u32 msr;
  516. __u64 blob_addr_32;
  517. __u64 blob_addr_64;
  518. __u8 blob_size_32;
  519. __u8 blob_size_64;
  520. __u8 pad2[30];
  521. };
  522. 4.29 KVM_GET_CLOCK
  523. Capability: KVM_CAP_ADJUST_CLOCK
  524. Architectures: x86
  525. Type: vm ioctl
  526. Parameters: struct kvm_clock_data (out)
  527. Returns: 0 on success, -1 on error
  528. Gets the current timestamp of kvmclock as seen by the current guest. In
  529. conjunction with KVM_SET_CLOCK, it is used to ensure monotonicity on scenarios
  530. such as migration.
  531. struct kvm_clock_data {
  532. __u64 clock; /* kvmclock current value */
  533. __u32 flags;
  534. __u32 pad[9];
  535. };
  536. 4.30 KVM_SET_CLOCK
  537. Capability: KVM_CAP_ADJUST_CLOCK
  538. Architectures: x86
  539. Type: vm ioctl
  540. Parameters: struct kvm_clock_data (in)
  541. Returns: 0 on success, -1 on error
  542. Sets the current timestamp of kvmclock to the value specified in its parameter.
  543. In conjunction with KVM_GET_CLOCK, it is used to ensure monotonicity on scenarios
  544. such as migration.
  545. struct kvm_clock_data {
  546. __u64 clock; /* kvmclock current value */
  547. __u32 flags;
  548. __u32 pad[9];
  549. };
  550. 4.31 KVM_GET_VCPU_EVENTS
  551. Capability: KVM_CAP_VCPU_EVENTS
  552. Extended by: KVM_CAP_INTR_SHADOW
  553. Architectures: x86
  554. Type: vm ioctl
  555. Parameters: struct kvm_vcpu_event (out)
  556. Returns: 0 on success, -1 on error
  557. Gets currently pending exceptions, interrupts, and NMIs as well as related
  558. states of the vcpu.
  559. struct kvm_vcpu_events {
  560. struct {
  561. __u8 injected;
  562. __u8 nr;
  563. __u8 has_error_code;
  564. __u8 pad;
  565. __u32 error_code;
  566. } exception;
  567. struct {
  568. __u8 injected;
  569. __u8 nr;
  570. __u8 soft;
  571. __u8 shadow;
  572. } interrupt;
  573. struct {
  574. __u8 injected;
  575. __u8 pending;
  576. __u8 masked;
  577. __u8 pad;
  578. } nmi;
  579. __u32 sipi_vector;
  580. __u32 flags;
  581. };
  582. KVM_VCPUEVENT_VALID_SHADOW may be set in the flags field to signal that
  583. interrupt.shadow contains a valid state. Otherwise, this field is undefined.
  584. 4.32 KVM_SET_VCPU_EVENTS
  585. Capability: KVM_CAP_VCPU_EVENTS
  586. Extended by: KVM_CAP_INTR_SHADOW
  587. Architectures: x86
  588. Type: vm ioctl
  589. Parameters: struct kvm_vcpu_event (in)
  590. Returns: 0 on success, -1 on error
  591. Set pending exceptions, interrupts, and NMIs as well as related states of the
  592. vcpu.
  593. See KVM_GET_VCPU_EVENTS for the data structure.
  594. Fields that may be modified asynchronously by running VCPUs can be excluded
  595. from the update. These fields are nmi.pending and sipi_vector. Keep the
  596. corresponding bits in the flags field cleared to suppress overwriting the
  597. current in-kernel state. The bits are:
  598. KVM_VCPUEVENT_VALID_NMI_PENDING - transfer nmi.pending to the kernel
  599. KVM_VCPUEVENT_VALID_SIPI_VECTOR - transfer sipi_vector
  600. If KVM_CAP_INTR_SHADOW is available, KVM_VCPUEVENT_VALID_SHADOW can be set in
  601. the flags field to signal that interrupt.shadow contains a valid state and
  602. shall be written into the VCPU.
  603. 4.33 KVM_GET_DEBUGREGS
  604. Capability: KVM_CAP_DEBUGREGS
  605. Architectures: x86
  606. Type: vm ioctl
  607. Parameters: struct kvm_debugregs (out)
  608. Returns: 0 on success, -1 on error
  609. Reads debug registers from the vcpu.
  610. struct kvm_debugregs {
  611. __u64 db[4];
  612. __u64 dr6;
  613. __u64 dr7;
  614. __u64 flags;
  615. __u64 reserved[9];
  616. };
  617. 4.34 KVM_SET_DEBUGREGS
  618. Capability: KVM_CAP_DEBUGREGS
  619. Architectures: x86
  620. Type: vm ioctl
  621. Parameters: struct kvm_debugregs (in)
  622. Returns: 0 on success, -1 on error
  623. Writes debug registers into the vcpu.
  624. See KVM_GET_DEBUGREGS for the data structure. The flags field is unused
  625. yet and must be cleared on entry.
  626. 4.35 KVM_SET_USER_MEMORY_REGION
  627. Capability: KVM_CAP_USER_MEM
  628. Architectures: all
  629. Type: vm ioctl
  630. Parameters: struct kvm_userspace_memory_region (in)
  631. Returns: 0 on success, -1 on error
  632. struct kvm_userspace_memory_region {
  633. __u32 slot;
  634. __u32 flags;
  635. __u64 guest_phys_addr;
  636. __u64 memory_size; /* bytes */
  637. __u64 userspace_addr; /* start of the userspace allocated memory */
  638. };
  639. /* for kvm_memory_region::flags */
  640. #define KVM_MEM_LOG_DIRTY_PAGES (1UL << 0)
  641. #define KVM_MEM_READONLY (1UL << 1)
  642. This ioctl allows the user to create or modify a guest physical memory
  643. slot. When changing an existing slot, it may be moved in the guest
  644. physical memory space, or its flags may be modified. It may not be
  645. resized. Slots may not overlap in guest physical address space.
  646. Memory for the region is taken starting at the address denoted by the
  647. field userspace_addr, which must point at user addressable memory for
  648. the entire memory slot size. Any object may back this memory, including
  649. anonymous memory, ordinary files, and hugetlbfs.
  650. It is recommended that the lower 21 bits of guest_phys_addr and userspace_addr
  651. be identical. This allows large pages in the guest to be backed by large
  652. pages in the host.
  653. The flags field supports two flag, KVM_MEM_LOG_DIRTY_PAGES, which instructs
  654. kvm to keep track of writes to memory within the slot. See KVM_GET_DIRTY_LOG
  655. ioctl. The KVM_CAP_READONLY_MEM capability indicates the availability of the
  656. KVM_MEM_READONLY flag. When this flag is set for a memory region, KVM only
  657. allows read accesses. Writes will be posted to userspace as KVM_EXIT_MMIO
  658. exits.
  659. When the KVM_CAP_SYNC_MMU capability is available, changes in the backing of
  660. the memory region are automatically reflected into the guest. For example, an
  661. mmap() that affects the region will be made visible immediately. Another
  662. example is madvise(MADV_DROP).
  663. It is recommended to use this API instead of the KVM_SET_MEMORY_REGION ioctl.
  664. The KVM_SET_MEMORY_REGION does not allow fine grained control over memory
  665. allocation and is deprecated.
  666. 4.36 KVM_SET_TSS_ADDR
  667. Capability: KVM_CAP_SET_TSS_ADDR
  668. Architectures: x86
  669. Type: vm ioctl
  670. Parameters: unsigned long tss_address (in)
  671. Returns: 0 on success, -1 on error
  672. This ioctl defines the physical address of a three-page region in the guest
  673. physical address space. The region must be within the first 4GB of the
  674. guest physical address space and must not conflict with any memory slot
  675. or any mmio address. The guest may malfunction if it accesses this memory
  676. region.
  677. This ioctl is required on Intel-based hosts. This is needed on Intel hardware
  678. because of a quirk in the virtualization implementation (see the internals
  679. documentation when it pops into existence).
  680. 4.37 KVM_ENABLE_CAP
  681. Capability: KVM_CAP_ENABLE_CAP
  682. Architectures: ppc
  683. Type: vcpu ioctl
  684. Parameters: struct kvm_enable_cap (in)
  685. Returns: 0 on success; -1 on error
  686. +Not all extensions are enabled by default. Using this ioctl the application
  687. can enable an extension, making it available to the guest.
  688. On systems that do not support this ioctl, it always fails. On systems that
  689. do support it, it only works for extensions that are supported for enablement.
  690. To check if a capability can be enabled, the KVM_CHECK_EXTENSION ioctl should
  691. be used.
  692. struct kvm_enable_cap {
  693. /* in */
  694. __u32 cap;
  695. The capability that is supposed to get enabled.
  696. __u32 flags;
  697. A bitfield indicating future enhancements. Has to be 0 for now.
  698. __u64 args[4];
  699. Arguments for enabling a feature. If a feature needs initial values to
  700. function properly, this is the place to put them.
  701. __u8 pad[64];
  702. };
  703. 4.38 KVM_GET_MP_STATE
  704. Capability: KVM_CAP_MP_STATE
  705. Architectures: x86, ia64
  706. Type: vcpu ioctl
  707. Parameters: struct kvm_mp_state (out)
  708. Returns: 0 on success; -1 on error
  709. struct kvm_mp_state {
  710. __u32 mp_state;
  711. };
  712. Returns the vcpu's current "multiprocessing state" (though also valid on
  713. uniprocessor guests).
  714. Possible values are:
  715. - KVM_MP_STATE_RUNNABLE: the vcpu is currently running
  716. - KVM_MP_STATE_UNINITIALIZED: the vcpu is an application processor (AP)
  717. which has not yet received an INIT signal
  718. - KVM_MP_STATE_INIT_RECEIVED: the vcpu has received an INIT signal, and is
  719. now ready for a SIPI
  720. - KVM_MP_STATE_HALTED: the vcpu has executed a HLT instruction and
  721. is waiting for an interrupt
  722. - KVM_MP_STATE_SIPI_RECEIVED: the vcpu has just received a SIPI (vector
  723. accessible via KVM_GET_VCPU_EVENTS)
  724. This ioctl is only useful after KVM_CREATE_IRQCHIP. Without an in-kernel
  725. irqchip, the multiprocessing state must be maintained by userspace.
  726. 4.39 KVM_SET_MP_STATE
  727. Capability: KVM_CAP_MP_STATE
  728. Architectures: x86, ia64
  729. Type: vcpu ioctl
  730. Parameters: struct kvm_mp_state (in)
  731. Returns: 0 on success; -1 on error
  732. Sets the vcpu's current "multiprocessing state"; see KVM_GET_MP_STATE for
  733. arguments.
  734. This ioctl is only useful after KVM_CREATE_IRQCHIP. Without an in-kernel
  735. irqchip, the multiprocessing state must be maintained by userspace.
  736. 4.40 KVM_SET_IDENTITY_MAP_ADDR
  737. Capability: KVM_CAP_SET_IDENTITY_MAP_ADDR
  738. Architectures: x86
  739. Type: vm ioctl
  740. Parameters: unsigned long identity (in)
  741. Returns: 0 on success, -1 on error
  742. This ioctl defines the physical address of a one-page region in the guest
  743. physical address space. The region must be within the first 4GB of the
  744. guest physical address space and must not conflict with any memory slot
  745. or any mmio address. The guest may malfunction if it accesses this memory
  746. region.
  747. This ioctl is required on Intel-based hosts. This is needed on Intel hardware
  748. because of a quirk in the virtualization implementation (see the internals
  749. documentation when it pops into existence).
  750. 4.41 KVM_SET_BOOT_CPU_ID
  751. Capability: KVM_CAP_SET_BOOT_CPU_ID
  752. Architectures: x86, ia64
  753. Type: vm ioctl
  754. Parameters: unsigned long vcpu_id
  755. Returns: 0 on success, -1 on error
  756. Define which vcpu is the Bootstrap Processor (BSP). Values are the same
  757. as the vcpu id in KVM_CREATE_VCPU. If this ioctl is not called, the default
  758. is vcpu 0.
  759. 4.42 KVM_GET_XSAVE
  760. Capability: KVM_CAP_XSAVE
  761. Architectures: x86
  762. Type: vcpu ioctl
  763. Parameters: struct kvm_xsave (out)
  764. Returns: 0 on success, -1 on error
  765. struct kvm_xsave {
  766. __u32 region[1024];
  767. };
  768. This ioctl would copy current vcpu's xsave struct to the userspace.
  769. 4.43 KVM_SET_XSAVE
  770. Capability: KVM_CAP_XSAVE
  771. Architectures: x86
  772. Type: vcpu ioctl
  773. Parameters: struct kvm_xsave (in)
  774. Returns: 0 on success, -1 on error
  775. struct kvm_xsave {
  776. __u32 region[1024];
  777. };
  778. This ioctl would copy userspace's xsave struct to the kernel.
  779. 4.44 KVM_GET_XCRS
  780. Capability: KVM_CAP_XCRS
  781. Architectures: x86
  782. Type: vcpu ioctl
  783. Parameters: struct kvm_xcrs (out)
  784. Returns: 0 on success, -1 on error
  785. struct kvm_xcr {
  786. __u32 xcr;
  787. __u32 reserved;
  788. __u64 value;
  789. };
  790. struct kvm_xcrs {
  791. __u32 nr_xcrs;
  792. __u32 flags;
  793. struct kvm_xcr xcrs[KVM_MAX_XCRS];
  794. __u64 padding[16];
  795. };
  796. This ioctl would copy current vcpu's xcrs to the userspace.
  797. 4.45 KVM_SET_XCRS
  798. Capability: KVM_CAP_XCRS
  799. Architectures: x86
  800. Type: vcpu ioctl
  801. Parameters: struct kvm_xcrs (in)
  802. Returns: 0 on success, -1 on error
  803. struct kvm_xcr {
  804. __u32 xcr;
  805. __u32 reserved;
  806. __u64 value;
  807. };
  808. struct kvm_xcrs {
  809. __u32 nr_xcrs;
  810. __u32 flags;
  811. struct kvm_xcr xcrs[KVM_MAX_XCRS];
  812. __u64 padding[16];
  813. };
  814. This ioctl would set vcpu's xcr to the value userspace specified.
  815. 4.46 KVM_GET_SUPPORTED_CPUID
  816. Capability: KVM_CAP_EXT_CPUID
  817. Architectures: x86
  818. Type: system ioctl
  819. Parameters: struct kvm_cpuid2 (in/out)
  820. Returns: 0 on success, -1 on error
  821. struct kvm_cpuid2 {
  822. __u32 nent;
  823. __u32 padding;
  824. struct kvm_cpuid_entry2 entries[0];
  825. };
  826. #define KVM_CPUID_FLAG_SIGNIFCANT_INDEX 1
  827. #define KVM_CPUID_FLAG_STATEFUL_FUNC 2
  828. #define KVM_CPUID_FLAG_STATE_READ_NEXT 4
  829. struct kvm_cpuid_entry2 {
  830. __u32 function;
  831. __u32 index;
  832. __u32 flags;
  833. __u32 eax;
  834. __u32 ebx;
  835. __u32 ecx;
  836. __u32 edx;
  837. __u32 padding[3];
  838. };
  839. This ioctl returns x86 cpuid features which are supported by both the hardware
  840. and kvm. Userspace can use the information returned by this ioctl to
  841. construct cpuid information (for KVM_SET_CPUID2) that is consistent with
  842. hardware, kernel, and userspace capabilities, and with user requirements (for
  843. example, the user may wish to constrain cpuid to emulate older hardware,
  844. or for feature consistency across a cluster).
  845. Userspace invokes KVM_GET_SUPPORTED_CPUID by passing a kvm_cpuid2 structure
  846. with the 'nent' field indicating the number of entries in the variable-size
  847. array 'entries'. If the number of entries is too low to describe the cpu
  848. capabilities, an error (E2BIG) is returned. If the number is too high,
  849. the 'nent' field is adjusted and an error (ENOMEM) is returned. If the
  850. number is just right, the 'nent' field is adjusted to the number of valid
  851. entries in the 'entries' array, which is then filled.
  852. The entries returned are the host cpuid as returned by the cpuid instruction,
  853. with unknown or unsupported features masked out. Some features (for example,
  854. x2apic), may not be present in the host cpu, but are exposed by kvm if it can
  855. emulate them efficiently. The fields in each entry are defined as follows:
  856. function: the eax value used to obtain the entry
  857. index: the ecx value used to obtain the entry (for entries that are
  858. affected by ecx)
  859. flags: an OR of zero or more of the following:
  860. KVM_CPUID_FLAG_SIGNIFCANT_INDEX:
  861. if the index field is valid
  862. KVM_CPUID_FLAG_STATEFUL_FUNC:
  863. if cpuid for this function returns different values for successive
  864. invocations; there will be several entries with the same function,
  865. all with this flag set
  866. KVM_CPUID_FLAG_STATE_READ_NEXT:
  867. for KVM_CPUID_FLAG_STATEFUL_FUNC entries, set if this entry is
  868. the first entry to be read by a cpu
  869. eax, ebx, ecx, edx: the values returned by the cpuid instruction for
  870. this function/index combination
  871. The TSC deadline timer feature (CPUID leaf 1, ecx[24]) is always returned
  872. as false, since the feature depends on KVM_CREATE_IRQCHIP for local APIC
  873. support. Instead it is reported via
  874. ioctl(KVM_CHECK_EXTENSION, KVM_CAP_TSC_DEADLINE_TIMER)
  875. if that returns true and you use KVM_CREATE_IRQCHIP, or if you emulate the
  876. feature in userspace, then you can enable the feature for KVM_SET_CPUID2.
  877. 4.47 KVM_PPC_GET_PVINFO
  878. Capability: KVM_CAP_PPC_GET_PVINFO
  879. Architectures: ppc
  880. Type: vm ioctl
  881. Parameters: struct kvm_ppc_pvinfo (out)
  882. Returns: 0 on success, !0 on error
  883. struct kvm_ppc_pvinfo {
  884. __u32 flags;
  885. __u32 hcall[4];
  886. __u8 pad[108];
  887. };
  888. This ioctl fetches PV specific information that need to be passed to the guest
  889. using the device tree or other means from vm context.
  890. The hcall array defines 4 instructions that make up a hypercall.
  891. If any additional field gets added to this structure later on, a bit for that
  892. additional piece of information will be set in the flags bitmap.
  893. The flags bitmap is defined as:
  894. /* the host supports the ePAPR idle hcall
  895. #define KVM_PPC_PVINFO_FLAGS_EV_IDLE (1<<0)
  896. 4.48 KVM_ASSIGN_PCI_DEVICE
  897. Capability: KVM_CAP_DEVICE_ASSIGNMENT
  898. Architectures: x86 ia64
  899. Type: vm ioctl
  900. Parameters: struct kvm_assigned_pci_dev (in)
  901. Returns: 0 on success, -1 on error
  902. Assigns a host PCI device to the VM.
  903. struct kvm_assigned_pci_dev {
  904. __u32 assigned_dev_id;
  905. __u32 busnr;
  906. __u32 devfn;
  907. __u32 flags;
  908. __u32 segnr;
  909. union {
  910. __u32 reserved[11];
  911. };
  912. };
  913. The PCI device is specified by the triple segnr, busnr, and devfn.
  914. Identification in succeeding service requests is done via assigned_dev_id. The
  915. following flags are specified:
  916. /* Depends on KVM_CAP_IOMMU */
  917. #define KVM_DEV_ASSIGN_ENABLE_IOMMU (1 << 0)
  918. /* The following two depend on KVM_CAP_PCI_2_3 */
  919. #define KVM_DEV_ASSIGN_PCI_2_3 (1 << 1)
  920. #define KVM_DEV_ASSIGN_MASK_INTX (1 << 2)
  921. If KVM_DEV_ASSIGN_PCI_2_3 is set, the kernel will manage legacy INTx interrupts
  922. via the PCI-2.3-compliant device-level mask, thus enable IRQ sharing with other
  923. assigned devices or host devices. KVM_DEV_ASSIGN_MASK_INTX specifies the
  924. guest's view on the INTx mask, see KVM_ASSIGN_SET_INTX_MASK for details.
  925. The KVM_DEV_ASSIGN_ENABLE_IOMMU flag is a mandatory option to ensure
  926. isolation of the device. Usages not specifying this flag are deprecated.
  927. Only PCI header type 0 devices with PCI BAR resources are supported by
  928. device assignment. The user requesting this ioctl must have read/write
  929. access to the PCI sysfs resource files associated with the device.
  930. 4.49 KVM_DEASSIGN_PCI_DEVICE
  931. Capability: KVM_CAP_DEVICE_DEASSIGNMENT
  932. Architectures: x86 ia64
  933. Type: vm ioctl
  934. Parameters: struct kvm_assigned_pci_dev (in)
  935. Returns: 0 on success, -1 on error
  936. Ends PCI device assignment, releasing all associated resources.
  937. See KVM_CAP_DEVICE_ASSIGNMENT for the data structure. Only assigned_dev_id is
  938. used in kvm_assigned_pci_dev to identify the device.
  939. 4.50 KVM_ASSIGN_DEV_IRQ
  940. Capability: KVM_CAP_ASSIGN_DEV_IRQ
  941. Architectures: x86 ia64
  942. Type: vm ioctl
  943. Parameters: struct kvm_assigned_irq (in)
  944. Returns: 0 on success, -1 on error
  945. Assigns an IRQ to a passed-through device.
  946. struct kvm_assigned_irq {
  947. __u32 assigned_dev_id;
  948. __u32 host_irq; /* ignored (legacy field) */
  949. __u32 guest_irq;
  950. __u32 flags;
  951. union {
  952. __u32 reserved[12];
  953. };
  954. };
  955. The following flags are defined:
  956. #define KVM_DEV_IRQ_HOST_INTX (1 << 0)
  957. #define KVM_DEV_IRQ_HOST_MSI (1 << 1)
  958. #define KVM_DEV_IRQ_HOST_MSIX (1 << 2)
  959. #define KVM_DEV_IRQ_GUEST_INTX (1 << 8)
  960. #define KVM_DEV_IRQ_GUEST_MSI (1 << 9)
  961. #define KVM_DEV_IRQ_GUEST_MSIX (1 << 10)
  962. It is not valid to specify multiple types per host or guest IRQ. However, the
  963. IRQ type of host and guest can differ or can even be null.
  964. 4.51 KVM_DEASSIGN_DEV_IRQ
  965. Capability: KVM_CAP_ASSIGN_DEV_IRQ
  966. Architectures: x86 ia64
  967. Type: vm ioctl
  968. Parameters: struct kvm_assigned_irq (in)
  969. Returns: 0 on success, -1 on error
  970. Ends an IRQ assignment to a passed-through device.
  971. See KVM_ASSIGN_DEV_IRQ for the data structure. The target device is specified
  972. by assigned_dev_id, flags must correspond to the IRQ type specified on
  973. KVM_ASSIGN_DEV_IRQ. Partial deassignment of host or guest IRQ is allowed.
  974. 4.52 KVM_SET_GSI_ROUTING
  975. Capability: KVM_CAP_IRQ_ROUTING
  976. Architectures: x86 ia64
  977. Type: vm ioctl
  978. Parameters: struct kvm_irq_routing (in)
  979. Returns: 0 on success, -1 on error
  980. Sets the GSI routing table entries, overwriting any previously set entries.
  981. struct kvm_irq_routing {
  982. __u32 nr;
  983. __u32 flags;
  984. struct kvm_irq_routing_entry entries[0];
  985. };
  986. No flags are specified so far, the corresponding field must be set to zero.
  987. struct kvm_irq_routing_entry {
  988. __u32 gsi;
  989. __u32 type;
  990. __u32 flags;
  991. __u32 pad;
  992. union {
  993. struct kvm_irq_routing_irqchip irqchip;
  994. struct kvm_irq_routing_msi msi;
  995. __u32 pad[8];
  996. } u;
  997. };
  998. /* gsi routing entry types */
  999. #define KVM_IRQ_ROUTING_IRQCHIP 1
  1000. #define KVM_IRQ_ROUTING_MSI 2
  1001. No flags are specified so far, the corresponding field must be set to zero.
  1002. struct kvm_irq_routing_irqchip {
  1003. __u32 irqchip;
  1004. __u32 pin;
  1005. };
  1006. struct kvm_irq_routing_msi {
  1007. __u32 address_lo;
  1008. __u32 address_hi;
  1009. __u32 data;
  1010. __u32 pad;
  1011. };
  1012. 4.53 KVM_ASSIGN_SET_MSIX_NR
  1013. Capability: KVM_CAP_DEVICE_MSIX
  1014. Architectures: x86 ia64
  1015. Type: vm ioctl
  1016. Parameters: struct kvm_assigned_msix_nr (in)
  1017. Returns: 0 on success, -1 on error
  1018. Set the number of MSI-X interrupts for an assigned device. The number is
  1019. reset again by terminating the MSI-X assignment of the device via
  1020. KVM_DEASSIGN_DEV_IRQ. Calling this service more than once at any earlier
  1021. point will fail.
  1022. struct kvm_assigned_msix_nr {
  1023. __u32 assigned_dev_id;
  1024. __u16 entry_nr;
  1025. __u16 padding;
  1026. };
  1027. #define KVM_MAX_MSIX_PER_DEV 256
  1028. 4.54 KVM_ASSIGN_SET_MSIX_ENTRY
  1029. Capability: KVM_CAP_DEVICE_MSIX
  1030. Architectures: x86 ia64
  1031. Type: vm ioctl
  1032. Parameters: struct kvm_assigned_msix_entry (in)
  1033. Returns: 0 on success, -1 on error
  1034. Specifies the routing of an MSI-X assigned device interrupt to a GSI. Setting
  1035. the GSI vector to zero means disabling the interrupt.
  1036. struct kvm_assigned_msix_entry {
  1037. __u32 assigned_dev_id;
  1038. __u32 gsi;
  1039. __u16 entry; /* The index of entry in the MSI-X table */
  1040. __u16 padding[3];
  1041. };
  1042. 4.55 KVM_SET_TSC_KHZ
  1043. Capability: KVM_CAP_TSC_CONTROL
  1044. Architectures: x86
  1045. Type: vcpu ioctl
  1046. Parameters: virtual tsc_khz
  1047. Returns: 0 on success, -1 on error
  1048. Specifies the tsc frequency for the virtual machine. The unit of the
  1049. frequency is KHz.
  1050. 4.56 KVM_GET_TSC_KHZ
  1051. Capability: KVM_CAP_GET_TSC_KHZ
  1052. Architectures: x86
  1053. Type: vcpu ioctl
  1054. Parameters: none
  1055. Returns: virtual tsc-khz on success, negative value on error
  1056. Returns the tsc frequency of the guest. The unit of the return value is
  1057. KHz. If the host has unstable tsc this ioctl returns -EIO instead as an
  1058. error.
  1059. 4.57 KVM_GET_LAPIC
  1060. Capability: KVM_CAP_IRQCHIP
  1061. Architectures: x86
  1062. Type: vcpu ioctl
  1063. Parameters: struct kvm_lapic_state (out)
  1064. Returns: 0 on success, -1 on error
  1065. #define KVM_APIC_REG_SIZE 0x400
  1066. struct kvm_lapic_state {
  1067. char regs[KVM_APIC_REG_SIZE];
  1068. };
  1069. Reads the Local APIC registers and copies them into the input argument. The
  1070. data format and layout are the same as documented in the architecture manual.
  1071. 4.58 KVM_SET_LAPIC
  1072. Capability: KVM_CAP_IRQCHIP
  1073. Architectures: x86
  1074. Type: vcpu ioctl
  1075. Parameters: struct kvm_lapic_state (in)
  1076. Returns: 0 on success, -1 on error
  1077. #define KVM_APIC_REG_SIZE 0x400
  1078. struct kvm_lapic_state {
  1079. char regs[KVM_APIC_REG_SIZE];
  1080. };
  1081. Copies the input argument into the the Local APIC registers. The data format
  1082. and layout are the same as documented in the architecture manual.
  1083. 4.59 KVM_IOEVENTFD
  1084. Capability: KVM_CAP_IOEVENTFD
  1085. Architectures: all
  1086. Type: vm ioctl
  1087. Parameters: struct kvm_ioeventfd (in)
  1088. Returns: 0 on success, !0 on error
  1089. This ioctl attaches or detaches an ioeventfd to a legal pio/mmio address
  1090. within the guest. A guest write in the registered address will signal the
  1091. provided event instead of triggering an exit.
  1092. struct kvm_ioeventfd {
  1093. __u64 datamatch;
  1094. __u64 addr; /* legal pio/mmio address */
  1095. __u32 len; /* 1, 2, 4, or 8 bytes */
  1096. __s32 fd;
  1097. __u32 flags;
  1098. __u8 pad[36];
  1099. };
  1100. The following flags are defined:
  1101. #define KVM_IOEVENTFD_FLAG_DATAMATCH (1 << kvm_ioeventfd_flag_nr_datamatch)
  1102. #define KVM_IOEVENTFD_FLAG_PIO (1 << kvm_ioeventfd_flag_nr_pio)
  1103. #define KVM_IOEVENTFD_FLAG_DEASSIGN (1 << kvm_ioeventfd_flag_nr_deassign)
  1104. If datamatch flag is set, the event will be signaled only if the written value
  1105. to the registered address is equal to datamatch in struct kvm_ioeventfd.
  1106. 4.60 KVM_DIRTY_TLB
  1107. Capability: KVM_CAP_SW_TLB
  1108. Architectures: ppc
  1109. Type: vcpu ioctl
  1110. Parameters: struct kvm_dirty_tlb (in)
  1111. Returns: 0 on success, -1 on error
  1112. struct kvm_dirty_tlb {
  1113. __u64 bitmap;
  1114. __u32 num_dirty;
  1115. };
  1116. This must be called whenever userspace has changed an entry in the shared
  1117. TLB, prior to calling KVM_RUN on the associated vcpu.
  1118. The "bitmap" field is the userspace address of an array. This array
  1119. consists of a number of bits, equal to the total number of TLB entries as
  1120. determined by the last successful call to KVM_CONFIG_TLB, rounded up to the
  1121. nearest multiple of 64.
  1122. Each bit corresponds to one TLB entry, ordered the same as in the shared TLB
  1123. array.
  1124. The array is little-endian: the bit 0 is the least significant bit of the
  1125. first byte, bit 8 is the least significant bit of the second byte, etc.
  1126. This avoids any complications with differing word sizes.
  1127. The "num_dirty" field is a performance hint for KVM to determine whether it
  1128. should skip processing the bitmap and just invalidate everything. It must
  1129. be set to the number of set bits in the bitmap.
  1130. 4.61 KVM_ASSIGN_SET_INTX_MASK
  1131. Capability: KVM_CAP_PCI_2_3
  1132. Architectures: x86
  1133. Type: vm ioctl
  1134. Parameters: struct kvm_assigned_pci_dev (in)
  1135. Returns: 0 on success, -1 on error
  1136. Allows userspace to mask PCI INTx interrupts from the assigned device. The
  1137. kernel will not deliver INTx interrupts to the guest between setting and
  1138. clearing of KVM_ASSIGN_SET_INTX_MASK via this interface. This enables use of
  1139. and emulation of PCI 2.3 INTx disable command register behavior.
  1140. This may be used for both PCI 2.3 devices supporting INTx disable natively and
  1141. older devices lacking this support. Userspace is responsible for emulating the
  1142. read value of the INTx disable bit in the guest visible PCI command register.
  1143. When modifying the INTx disable state, userspace should precede updating the
  1144. physical device command register by calling this ioctl to inform the kernel of
  1145. the new intended INTx mask state.
  1146. Note that the kernel uses the device INTx disable bit to internally manage the
  1147. device interrupt state for PCI 2.3 devices. Reads of this register may
  1148. therefore not match the expected value. Writes should always use the guest
  1149. intended INTx disable value rather than attempting to read-copy-update the
  1150. current physical device state. Races between user and kernel updates to the
  1151. INTx disable bit are handled lazily in the kernel. It's possible the device
  1152. may generate unintended interrupts, but they will not be injected into the
  1153. guest.
  1154. See KVM_ASSIGN_DEV_IRQ for the data structure. The target device is specified
  1155. by assigned_dev_id. In the flags field, only KVM_DEV_ASSIGN_MASK_INTX is
  1156. evaluated.
  1157. 4.62 KVM_CREATE_SPAPR_TCE
  1158. Capability: KVM_CAP_SPAPR_TCE
  1159. Architectures: powerpc
  1160. Type: vm ioctl
  1161. Parameters: struct kvm_create_spapr_tce (in)
  1162. Returns: file descriptor for manipulating the created TCE table
  1163. This creates a virtual TCE (translation control entry) table, which
  1164. is an IOMMU for PAPR-style virtual I/O. It is used to translate
  1165. logical addresses used in virtual I/O into guest physical addresses,
  1166. and provides a scatter/gather capability for PAPR virtual I/O.
  1167. /* for KVM_CAP_SPAPR_TCE */
  1168. struct kvm_create_spapr_tce {
  1169. __u64 liobn;
  1170. __u32 window_size;
  1171. };
  1172. The liobn field gives the logical IO bus number for which to create a
  1173. TCE table. The window_size field specifies the size of the DMA window
  1174. which this TCE table will translate - the table will contain one 64
  1175. bit TCE entry for every 4kiB of the DMA window.
  1176. When the guest issues an H_PUT_TCE hcall on a liobn for which a TCE
  1177. table has been created using this ioctl(), the kernel will handle it
  1178. in real mode, updating the TCE table. H_PUT_TCE calls for other
  1179. liobns will cause a vm exit and must be handled by userspace.
  1180. The return value is a file descriptor which can be passed to mmap(2)
  1181. to map the created TCE table into userspace. This lets userspace read
  1182. the entries written by kernel-handled H_PUT_TCE calls, and also lets
  1183. userspace update the TCE table directly which is useful in some
  1184. circumstances.
  1185. 4.63 KVM_ALLOCATE_RMA
  1186. Capability: KVM_CAP_PPC_RMA
  1187. Architectures: powerpc
  1188. Type: vm ioctl
  1189. Parameters: struct kvm_allocate_rma (out)
  1190. Returns: file descriptor for mapping the allocated RMA
  1191. This allocates a Real Mode Area (RMA) from the pool allocated at boot
  1192. time by the kernel. An RMA is a physically-contiguous, aligned region
  1193. of memory used on older POWER processors to provide the memory which
  1194. will be accessed by real-mode (MMU off) accesses in a KVM guest.
  1195. POWER processors support a set of sizes for the RMA that usually
  1196. includes 64MB, 128MB, 256MB and some larger powers of two.
  1197. /* for KVM_ALLOCATE_RMA */
  1198. struct kvm_allocate_rma {
  1199. __u64 rma_size;
  1200. };
  1201. The return value is a file descriptor which can be passed to mmap(2)
  1202. to map the allocated RMA into userspace. The mapped area can then be
  1203. passed to the KVM_SET_USER_MEMORY_REGION ioctl to establish it as the
  1204. RMA for a virtual machine. The size of the RMA in bytes (which is
  1205. fixed at host kernel boot time) is returned in the rma_size field of
  1206. the argument structure.
  1207. The KVM_CAP_PPC_RMA capability is 1 or 2 if the KVM_ALLOCATE_RMA ioctl
  1208. is supported; 2 if the processor requires all virtual machines to have
  1209. an RMA, or 1 if the processor can use an RMA but doesn't require it,
  1210. because it supports the Virtual RMA (VRMA) facility.
  1211. 4.64 KVM_NMI
  1212. Capability: KVM_CAP_USER_NMI
  1213. Architectures: x86
  1214. Type: vcpu ioctl
  1215. Parameters: none
  1216. Returns: 0 on success, -1 on error
  1217. Queues an NMI on the thread's vcpu. Note this is well defined only
  1218. when KVM_CREATE_IRQCHIP has not been called, since this is an interface
  1219. between the virtual cpu core and virtual local APIC. After KVM_CREATE_IRQCHIP
  1220. has been called, this interface is completely emulated within the kernel.
  1221. To use this to emulate the LINT1 input with KVM_CREATE_IRQCHIP, use the
  1222. following algorithm:
  1223. - pause the vpcu
  1224. - read the local APIC's state (KVM_GET_LAPIC)
  1225. - check whether changing LINT1 will queue an NMI (see the LVT entry for LINT1)
  1226. - if so, issue KVM_NMI
  1227. - resume the vcpu
  1228. Some guests configure the LINT1 NMI input to cause a panic, aiding in
  1229. debugging.
  1230. 4.65 KVM_S390_UCAS_MAP
  1231. Capability: KVM_CAP_S390_UCONTROL
  1232. Architectures: s390
  1233. Type: vcpu ioctl
  1234. Parameters: struct kvm_s390_ucas_mapping (in)
  1235. Returns: 0 in case of success
  1236. The parameter is defined like this:
  1237. struct kvm_s390_ucas_mapping {
  1238. __u64 user_addr;
  1239. __u64 vcpu_addr;
  1240. __u64 length;
  1241. };
  1242. This ioctl maps the memory at "user_addr" with the length "length" to
  1243. the vcpu's address space starting at "vcpu_addr". All parameters need to
  1244. be alligned by 1 megabyte.
  1245. 4.66 KVM_S390_UCAS_UNMAP
  1246. Capability: KVM_CAP_S390_UCONTROL
  1247. Architectures: s390
  1248. Type: vcpu ioctl
  1249. Parameters: struct kvm_s390_ucas_mapping (in)
  1250. Returns: 0 in case of success
  1251. The parameter is defined like this:
  1252. struct kvm_s390_ucas_mapping {
  1253. __u64 user_addr;
  1254. __u64 vcpu_addr;
  1255. __u64 length;
  1256. };
  1257. This ioctl unmaps the memory in the vcpu's address space starting at
  1258. "vcpu_addr" with the length "length". The field "user_addr" is ignored.
  1259. All parameters need to be alligned by 1 megabyte.
  1260. 4.67 KVM_S390_VCPU_FAULT
  1261. Capability: KVM_CAP_S390_UCONTROL
  1262. Architectures: s390
  1263. Type: vcpu ioctl
  1264. Parameters: vcpu absolute address (in)
  1265. Returns: 0 in case of success
  1266. This call creates a page table entry on the virtual cpu's address space
  1267. (for user controlled virtual machines) or the virtual machine's address
  1268. space (for regular virtual machines). This only works for minor faults,
  1269. thus it's recommended to access subject memory page via the user page
  1270. table upfront. This is useful to handle validity intercepts for user
  1271. controlled virtual machines to fault in the virtual cpu's lowcore pages
  1272. prior to calling the KVM_RUN ioctl.
  1273. 4.68 KVM_SET_ONE_REG
  1274. Capability: KVM_CAP_ONE_REG
  1275. Architectures: all
  1276. Type: vcpu ioctl
  1277. Parameters: struct kvm_one_reg (in)
  1278. Returns: 0 on success, negative value on failure
  1279. struct kvm_one_reg {
  1280. __u64 id;
  1281. __u64 addr;
  1282. };
  1283. Using this ioctl, a single vcpu register can be set to a specific value
  1284. defined by user space with the passed in struct kvm_one_reg, where id
  1285. refers to the register identifier as described below and addr is a pointer
  1286. to a variable with the respective size. There can be architecture agnostic
  1287. and architecture specific registers. Each have their own range of operation
  1288. and their own constants and width. To keep track of the implemented
  1289. registers, find a list below:
  1290. Arch | Register | Width (bits)
  1291. | |
  1292. PPC | KVM_REG_PPC_HIOR | 64
  1293. PPC | KVM_REG_PPC_IAC1 | 64
  1294. PPC | KVM_REG_PPC_IAC2 | 64
  1295. PPC | KVM_REG_PPC_IAC3 | 64
  1296. PPC | KVM_REG_PPC_IAC4 | 64
  1297. PPC | KVM_REG_PPC_DAC1 | 64
  1298. PPC | KVM_REG_PPC_DAC2 | 64
  1299. PPC | KVM_REG_PPC_DABR | 64
  1300. PPC | KVM_REG_PPC_DSCR | 64
  1301. PPC | KVM_REG_PPC_PURR | 64
  1302. PPC | KVM_REG_PPC_SPURR | 64
  1303. PPC | KVM_REG_PPC_DAR | 64
  1304. PPC | KVM_REG_PPC_DSISR | 32
  1305. PPC | KVM_REG_PPC_AMR | 64
  1306. PPC | KVM_REG_PPC_UAMOR | 64
  1307. PPC | KVM_REG_PPC_MMCR0 | 64
  1308. PPC | KVM_REG_PPC_MMCR1 | 64
  1309. PPC | KVM_REG_PPC_MMCRA | 64
  1310. PPC | KVM_REG_PPC_PMC1 | 32
  1311. PPC | KVM_REG_PPC_PMC2 | 32
  1312. PPC | KVM_REG_PPC_PMC3 | 32
  1313. PPC | KVM_REG_PPC_PMC4 | 32
  1314. PPC | KVM_REG_PPC_PMC5 | 32
  1315. PPC | KVM_REG_PPC_PMC6 | 32
  1316. PPC | KVM_REG_PPC_PMC7 | 32
  1317. PPC | KVM_REG_PPC_PMC8 | 32
  1318. PPC | KVM_REG_PPC_FPR0 | 64
  1319. ...
  1320. PPC | KVM_REG_PPC_FPR31 | 64
  1321. PPC | KVM_REG_PPC_VR0 | 128
  1322. ...
  1323. PPC | KVM_REG_PPC_VR31 | 128
  1324. PPC | KVM_REG_PPC_VSR0 | 128
  1325. ...
  1326. PPC | KVM_REG_PPC_VSR31 | 128
  1327. PPC | KVM_REG_PPC_FPSCR | 64
  1328. PPC | KVM_REG_PPC_VSCR | 32
  1329. PPC | KVM_REG_PPC_VPA_ADDR | 64
  1330. PPC | KVM_REG_PPC_VPA_SLB | 128
  1331. PPC | KVM_REG_PPC_VPA_DTL | 128
  1332. PPC | KVM_REG_PPC_EPCR | 32
  1333. 4.69 KVM_GET_ONE_REG
  1334. Capability: KVM_CAP_ONE_REG
  1335. Architectures: all
  1336. Type: vcpu ioctl
  1337. Parameters: struct kvm_one_reg (in and out)
  1338. Returns: 0 on success, negative value on failure
  1339. This ioctl allows to receive the value of a single register implemented
  1340. in a vcpu. The register to read is indicated by the "id" field of the
  1341. kvm_one_reg struct passed in. On success, the register value can be found
  1342. at the memory location pointed to by "addr".
  1343. The list of registers accessible using this interface is identical to the
  1344. list in 4.68.
  1345. 4.70 KVM_KVMCLOCK_CTRL
  1346. Capability: KVM_CAP_KVMCLOCK_CTRL
  1347. Architectures: Any that implement pvclocks (currently x86 only)
  1348. Type: vcpu ioctl
  1349. Parameters: None
  1350. Returns: 0 on success, -1 on error
  1351. This signals to the host kernel that the specified guest is being paused by
  1352. userspace. The host will set a flag in the pvclock structure that is checked
  1353. from the soft lockup watchdog. The flag is part of the pvclock structure that
  1354. is shared between guest and host, specifically the second bit of the flags
  1355. field of the pvclock_vcpu_time_info structure. It will be set exclusively by
  1356. the host and read/cleared exclusively by the guest. The guest operation of
  1357. checking and clearing the flag must an atomic operation so
  1358. load-link/store-conditional, or equivalent must be used. There are two cases
  1359. where the guest will clear the flag: when the soft lockup watchdog timer resets
  1360. itself or when a soft lockup is detected. This ioctl can be called any time
  1361. after pausing the vcpu, but before it is resumed.
  1362. 4.71 KVM_SIGNAL_MSI
  1363. Capability: KVM_CAP_SIGNAL_MSI
  1364. Architectures: x86
  1365. Type: vm ioctl
  1366. Parameters: struct kvm_msi (in)
  1367. Returns: >0 on delivery, 0 if guest blocked the MSI, and -1 on error
  1368. Directly inject a MSI message. Only valid with in-kernel irqchip that handles
  1369. MSI messages.
  1370. struct kvm_msi {
  1371. __u32 address_lo;
  1372. __u32 address_hi;
  1373. __u32 data;
  1374. __u32 flags;
  1375. __u8 pad[16];
  1376. };
  1377. No flags are defined so far. The corresponding field must be 0.
  1378. 4.71 KVM_CREATE_PIT2
  1379. Capability: KVM_CAP_PIT2
  1380. Architectures: x86
  1381. Type: vm ioctl
  1382. Parameters: struct kvm_pit_config (in)
  1383. Returns: 0 on success, -1 on error
  1384. Creates an in-kernel device model for the i8254 PIT. This call is only valid
  1385. after enabling in-kernel irqchip support via KVM_CREATE_IRQCHIP. The following
  1386. parameters have to be passed:
  1387. struct kvm_pit_config {
  1388. __u32 flags;
  1389. __u32 pad[15];
  1390. };
  1391. Valid flags are:
  1392. #define KVM_PIT_SPEAKER_DUMMY 1 /* emulate speaker port stub */
  1393. PIT timer interrupts may use a per-VM kernel thread for injection. If it
  1394. exists, this thread will have a name of the following pattern:
  1395. kvm-pit/<owner-process-pid>
  1396. When running a guest with elevated priorities, the scheduling parameters of
  1397. this thread may have to be adjusted accordingly.
  1398. This IOCTL replaces the obsolete KVM_CREATE_PIT.
  1399. 4.72 KVM_GET_PIT2
  1400. Capability: KVM_CAP_PIT_STATE2
  1401. Architectures: x86
  1402. Type: vm ioctl
  1403. Parameters: struct kvm_pit_state2 (out)
  1404. Returns: 0 on success, -1 on error
  1405. Retrieves the state of the in-kernel PIT model. Only valid after
  1406. KVM_CREATE_PIT2. The state is returned in the following structure:
  1407. struct kvm_pit_state2 {
  1408. struct kvm_pit_channel_state channels[3];
  1409. __u32 flags;
  1410. __u32 reserved[9];
  1411. };
  1412. Valid flags are:
  1413. /* disable PIT in HPET legacy mode */
  1414. #define KVM_PIT_FLAGS_HPET_LEGACY 0x00000001
  1415. This IOCTL replaces the obsolete KVM_GET_PIT.
  1416. 4.73 KVM_SET_PIT2
  1417. Capability: KVM_CAP_PIT_STATE2
  1418. Architectures: x86
  1419. Type: vm ioctl
  1420. Parameters: struct kvm_pit_state2 (in)
  1421. Returns: 0 on success, -1 on error
  1422. Sets the state of the in-kernel PIT model. Only valid after KVM_CREATE_PIT2.
  1423. See KVM_GET_PIT2 for details on struct kvm_pit_state2.
  1424. This IOCTL replaces the obsolete KVM_SET_PIT.
  1425. 4.74 KVM_PPC_GET_SMMU_INFO
  1426. Capability: KVM_CAP_PPC_GET_SMMU_INFO
  1427. Architectures: powerpc
  1428. Type: vm ioctl
  1429. Parameters: None
  1430. Returns: 0 on success, -1 on error
  1431. This populates and returns a structure describing the features of
  1432. the "Server" class MMU emulation supported by KVM.
  1433. This can in turn be used by userspace to generate the appropariate
  1434. device-tree properties for the guest operating system.
  1435. The structure contains some global informations, followed by an
  1436. array of supported segment page sizes:
  1437. struct kvm_ppc_smmu_info {
  1438. __u64 flags;
  1439. __u32 slb_size;
  1440. __u32 pad;
  1441. struct kvm_ppc_one_seg_page_size sps[KVM_PPC_PAGE_SIZES_MAX_SZ];
  1442. };
  1443. The supported flags are:
  1444. - KVM_PPC_PAGE_SIZES_REAL:
  1445. When that flag is set, guest page sizes must "fit" the backing
  1446. store page sizes. When not set, any page size in the list can
  1447. be used regardless of how they are backed by userspace.
  1448. - KVM_PPC_1T_SEGMENTS
  1449. The emulated MMU supports 1T segments in addition to the
  1450. standard 256M ones.
  1451. The "slb_size" field indicates how many SLB entries are supported
  1452. The "sps" array contains 8 entries indicating the supported base
  1453. page sizes for a segment in increasing order. Each entry is defined
  1454. as follow:
  1455. struct kvm_ppc_one_seg_page_size {
  1456. __u32 page_shift; /* Base page shift of segment (or 0) */
  1457. __u32 slb_enc; /* SLB encoding for BookS */
  1458. struct kvm_ppc_one_page_size enc[KVM_PPC_PAGE_SIZES_MAX_SZ];
  1459. };
  1460. An entry with a "page_shift" of 0 is unused. Because the array is
  1461. organized in increasing order, a lookup can stop when encoutering
  1462. such an entry.
  1463. The "slb_enc" field provides the encoding to use in the SLB for the
  1464. page size. The bits are in positions such as the value can directly
  1465. be OR'ed into the "vsid" argument of the slbmte instruction.
  1466. The "enc" array is a list which for each of those segment base page
  1467. size provides the list of supported actual page sizes (which can be
  1468. only larger or equal to the base page size), along with the
  1469. corresponding encoding in the hash PTE. Similarily, the array is
  1470. 8 entries sorted by increasing sizes and an entry with a "0" shift
  1471. is an empty entry and a terminator:
  1472. struct kvm_ppc_one_page_size {
  1473. __u32 page_shift; /* Page shift (or 0) */
  1474. __u32 pte_enc; /* Encoding in the HPTE (>>12) */
  1475. };
  1476. The "pte_enc" field provides a value that can OR'ed into the hash
  1477. PTE's RPN field (ie, it needs to be shifted left by 12 to OR it
  1478. into the hash PTE second double word).
  1479. 4.75 KVM_IRQFD
  1480. Capability: KVM_CAP_IRQFD
  1481. Architectures: x86
  1482. Type: vm ioctl
  1483. Parameters: struct kvm_irqfd (in)
  1484. Returns: 0 on success, -1 on error
  1485. Allows setting an eventfd to directly trigger a guest interrupt.
  1486. kvm_irqfd.fd specifies the file descriptor to use as the eventfd and
  1487. kvm_irqfd.gsi specifies the irqchip pin toggled by this event. When
  1488. an event is tiggered on the eventfd, an interrupt is injected into
  1489. the guest using the specified gsi pin. The irqfd is removed using
  1490. the KVM_IRQFD_FLAG_DEASSIGN flag, specifying both kvm_irqfd.fd
  1491. and kvm_irqfd.gsi.
  1492. With KVM_CAP_IRQFD_RESAMPLE, KVM_IRQFD supports a de-assert and notify
  1493. mechanism allowing emulation of level-triggered, irqfd-based
  1494. interrupts. When KVM_IRQFD_FLAG_RESAMPLE is set the user must pass an
  1495. additional eventfd in the kvm_irqfd.resamplefd field. When operating
  1496. in resample mode, posting of an interrupt through kvm_irq.fd asserts
  1497. the specified gsi in the irqchip. When the irqchip is resampled, such
  1498. as from an EOI, the gsi is de-asserted and the user is notifed via
  1499. kvm_irqfd.resamplefd. It is the user's responsibility to re-queue
  1500. the interrupt if the device making use of it still requires service.
  1501. Note that closing the resamplefd is not sufficient to disable the
  1502. irqfd. The KVM_IRQFD_FLAG_RESAMPLE is only necessary on assignment
  1503. and need not be specified with KVM_IRQFD_FLAG_DEASSIGN.
  1504. 4.76 KVM_PPC_ALLOCATE_HTAB
  1505. Capability: KVM_CAP_PPC_ALLOC_HTAB
  1506. Architectures: powerpc
  1507. Type: vm ioctl
  1508. Parameters: Pointer to u32 containing hash table order (in/out)
  1509. Returns: 0 on success, -1 on error
  1510. This requests the host kernel to allocate an MMU hash table for a
  1511. guest using the PAPR paravirtualization interface. This only does
  1512. anything if the kernel is configured to use the Book 3S HV style of
  1513. virtualization. Otherwise the capability doesn't exist and the ioctl
  1514. returns an ENOTTY error. The rest of this description assumes Book 3S
  1515. HV.
  1516. There must be no vcpus running when this ioctl is called; if there
  1517. are, it will do nothing and return an EBUSY error.
  1518. The parameter is a pointer to a 32-bit unsigned integer variable
  1519. containing the order (log base 2) of the desired size of the hash
  1520. table, which must be between 18 and 46. On successful return from the
  1521. ioctl, it will have been updated with the order of the hash table that
  1522. was allocated.
  1523. If no hash table has been allocated when any vcpu is asked to run
  1524. (with the KVM_RUN ioctl), the host kernel will allocate a
  1525. default-sized hash table (16 MB).
  1526. If this ioctl is called when a hash table has already been allocated,
  1527. the kernel will clear out the existing hash table (zero all HPTEs) and
  1528. return the hash table order in the parameter. (If the guest is using
  1529. the virtualized real-mode area (VRMA) facility, the kernel will
  1530. re-create the VMRA HPTEs on the next KVM_RUN of any vcpu.)
  1531. 4.77 KVM_S390_INTERRUPT
  1532. Capability: basic
  1533. Architectures: s390
  1534. Type: vm ioctl, vcpu ioctl
  1535. Parameters: struct kvm_s390_interrupt (in)
  1536. Returns: 0 on success, -1 on error
  1537. Allows to inject an interrupt to the guest. Interrupts can be floating
  1538. (vm ioctl) or per cpu (vcpu ioctl), depending on the interrupt type.
  1539. Interrupt parameters are passed via kvm_s390_interrupt:
  1540. struct kvm_s390_interrupt {
  1541. __u32 type;
  1542. __u32 parm;
  1543. __u64 parm64;
  1544. };
  1545. type can be one of the following:
  1546. KVM_S390_SIGP_STOP (vcpu) - sigp restart
  1547. KVM_S390_PROGRAM_INT (vcpu) - program check; code in parm
  1548. KVM_S390_SIGP_SET_PREFIX (vcpu) - sigp set prefix; prefix address in parm
  1549. KVM_S390_RESTART (vcpu) - restart
  1550. KVM_S390_INT_VIRTIO (vm) - virtio external interrupt; external interrupt
  1551. parameters in parm and parm64
  1552. KVM_S390_INT_SERVICE (vm) - sclp external interrupt; sclp parameter in parm
  1553. KVM_S390_INT_EMERGENCY (vcpu) - sigp emergency; source cpu in parm
  1554. KVM_S390_INT_EXTERNAL_CALL (vcpu) - sigp external call; source cpu in parm
  1555. Note that the vcpu ioctl is asynchronous to vcpu execution.
  1556. 4.78 KVM_PPC_GET_HTAB_FD
  1557. Capability: KVM_CAP_PPC_HTAB_FD
  1558. Architectures: powerpc
  1559. Type: vm ioctl
  1560. Parameters: Pointer to struct kvm_get_htab_fd (in)
  1561. Returns: file descriptor number (>= 0) on success, -1 on error
  1562. This returns a file descriptor that can be used either to read out the
  1563. entries in the guest's hashed page table (HPT), or to write entries to
  1564. initialize the HPT. The returned fd can only be written to if the
  1565. KVM_GET_HTAB_WRITE bit is set in the flags field of the argument, and
  1566. can only be read if that bit is clear. The argument struct looks like
  1567. this:
  1568. /* For KVM_PPC_GET_HTAB_FD */
  1569. struct kvm_get_htab_fd {
  1570. __u64 flags;
  1571. __u64 start_index;
  1572. __u64 reserved[2];
  1573. };
  1574. /* Values for kvm_get_htab_fd.flags */
  1575. #define KVM_GET_HTAB_BOLTED_ONLY ((__u64)0x1)
  1576. #define KVM_GET_HTAB_WRITE ((__u64)0x2)
  1577. The `start_index' field gives the index in the HPT of the entry at
  1578. which to start reading. It is ignored when writing.
  1579. Reads on the fd will initially supply information about all
  1580. "interesting" HPT entries. Interesting entries are those with the
  1581. bolted bit set, if the KVM_GET_HTAB_BOLTED_ONLY bit is set, otherwise
  1582. all entries. When the end of the HPT is reached, the read() will
  1583. return. If read() is called again on the fd, it will start again from
  1584. the beginning of the HPT, but will only return HPT entries that have
  1585. changed since they were last read.
  1586. Data read or written is structured as a header (8 bytes) followed by a
  1587. series of valid HPT entries (16 bytes) each. The header indicates how
  1588. many valid HPT entries there are and how many invalid entries follow
  1589. the valid entries. The invalid entries are not represented explicitly
  1590. in the stream. The header format is:
  1591. struct kvm_get_htab_header {
  1592. __u32 index;
  1593. __u16 n_valid;
  1594. __u16 n_invalid;
  1595. };
  1596. Writes to the fd create HPT entries starting at the index given in the
  1597. header; first `n_valid' valid entries with contents from the data
  1598. written, then `n_invalid' invalid entries, invalidating any previously
  1599. valid entries found.
  1600. 5. The kvm_run structure
  1601. ------------------------
  1602. Application code obtains a pointer to the kvm_run structure by
  1603. mmap()ing a vcpu fd. From that point, application code can control
  1604. execution by changing fields in kvm_run prior to calling the KVM_RUN
  1605. ioctl, and obtain information about the reason KVM_RUN returned by
  1606. looking up structure members.
  1607. struct kvm_run {
  1608. /* in */
  1609. __u8 request_interrupt_window;
  1610. Request that KVM_RUN return when it becomes possible to inject external
  1611. interrupts into the guest. Useful in conjunction with KVM_INTERRUPT.
  1612. __u8 padding1[7];
  1613. /* out */
  1614. __u32 exit_reason;
  1615. When KVM_RUN has returned successfully (return value 0), this informs
  1616. application code why KVM_RUN has returned. Allowable values for this
  1617. field are detailed below.
  1618. __u8 ready_for_interrupt_injection;
  1619. If request_interrupt_window has been specified, this field indicates
  1620. an interrupt can be injected now with KVM_INTERRUPT.
  1621. __u8 if_flag;
  1622. The value of the current interrupt flag. Only valid if in-kernel
  1623. local APIC is not used.
  1624. __u8 padding2[2];
  1625. /* in (pre_kvm_run), out (post_kvm_run) */
  1626. __u64 cr8;
  1627. The value of the cr8 register. Only valid if in-kernel local APIC is
  1628. not used. Both input and output.
  1629. __u64 apic_base;
  1630. The value of the APIC BASE msr. Only valid if in-kernel local
  1631. APIC is not used. Both input and output.
  1632. union {
  1633. /* KVM_EXIT_UNKNOWN */
  1634. struct {
  1635. __u64 hardware_exit_reason;
  1636. } hw;
  1637. If exit_reason is KVM_EXIT_UNKNOWN, the vcpu has exited due to unknown
  1638. reasons. Further architecture-specific information is available in
  1639. hardware_exit_reason.
  1640. /* KVM_EXIT_FAIL_ENTRY */
  1641. struct {
  1642. __u64 hardware_entry_failure_reason;
  1643. } fail_entry;
  1644. If exit_reason is KVM_EXIT_FAIL_ENTRY, the vcpu could not be run due
  1645. to unknown reasons. Further architecture-specific information is
  1646. available in hardware_entry_failure_reason.
  1647. /* KVM_EXIT_EXCEPTION */
  1648. struct {
  1649. __u32 exception;
  1650. __u32 error_code;
  1651. } ex;
  1652. Unused.
  1653. /* KVM_EXIT_IO */
  1654. struct {
  1655. #define KVM_EXIT_IO_IN 0
  1656. #define KVM_EXIT_IO_OUT 1
  1657. __u8 direction;
  1658. __u8 size; /* bytes */
  1659. __u16 port;
  1660. __u32 count;
  1661. __u64 data_offset; /* relative to kvm_run start */
  1662. } io;
  1663. If exit_reason is KVM_EXIT_IO, then the vcpu has
  1664. executed a port I/O instruction which could not be satisfied by kvm.
  1665. data_offset describes where the data is located (KVM_EXIT_IO_OUT) or
  1666. where kvm expects application code to place the data for the next
  1667. KVM_RUN invocation (KVM_EXIT_IO_IN). Data format is a packed array.
  1668. struct {
  1669. struct kvm_debug_exit_arch arch;
  1670. } debug;
  1671. Unused.
  1672. /* KVM_EXIT_MMIO */
  1673. struct {
  1674. __u64 phys_addr;
  1675. __u8 data[8];
  1676. __u32 len;
  1677. __u8 is_write;
  1678. } mmio;
  1679. If exit_reason is KVM_EXIT_MMIO, then the vcpu has
  1680. executed a memory-mapped I/O instruction which could not be satisfied
  1681. by kvm. The 'data' member contains the written data if 'is_write' is
  1682. true, and should be filled by application code otherwise.
  1683. NOTE: For KVM_EXIT_IO, KVM_EXIT_MMIO, KVM_EXIT_OSI, KVM_EXIT_DCR
  1684. and KVM_EXIT_PAPR the corresponding
  1685. operations are complete (and guest state is consistent) only after userspace
  1686. has re-entered the kernel with KVM_RUN. The kernel side will first finish
  1687. incomplete operations and then check for pending signals. Userspace
  1688. can re-enter the guest with an unmasked signal pending to complete
  1689. pending operations.
  1690. /* KVM_EXIT_HYPERCALL */
  1691. struct {
  1692. __u64 nr;
  1693. __u64 args[6];
  1694. __u64 ret;
  1695. __u32 longmode;
  1696. __u32 pad;
  1697. } hypercall;
  1698. Unused. This was once used for 'hypercall to userspace'. To implement
  1699. such functionality, use KVM_EXIT_IO (x86) or KVM_EXIT_MMIO (all except s390).
  1700. Note KVM_EXIT_IO is significantly faster than KVM_EXIT_MMIO.
  1701. /* KVM_EXIT_TPR_ACCESS */
  1702. struct {
  1703. __u64 rip;
  1704. __u32 is_write;
  1705. __u32 pad;
  1706. } tpr_access;
  1707. To be documented (KVM_TPR_ACCESS_REPORTING).
  1708. /* KVM_EXIT_S390_SIEIC */
  1709. struct {
  1710. __u8 icptcode;
  1711. __u64 mask; /* psw upper half */
  1712. __u64 addr; /* psw lower half */
  1713. __u16 ipa;
  1714. __u32 ipb;
  1715. } s390_sieic;
  1716. s390 specific.
  1717. /* KVM_EXIT_S390_RESET */
  1718. #define KVM_S390_RESET_POR 1
  1719. #define KVM_S390_RESET_CLEAR 2
  1720. #define KVM_S390_RESET_SUBSYSTEM 4
  1721. #define KVM_S390_RESET_CPU_INIT 8
  1722. #define KVM_S390_RESET_IPL 16
  1723. __u64 s390_reset_flags;
  1724. s390 specific.
  1725. /* KVM_EXIT_S390_UCONTROL */
  1726. struct {
  1727. __u64 trans_exc_code;
  1728. __u32 pgm_code;
  1729. } s390_ucontrol;
  1730. s390 specific. A page fault has occurred for a user controlled virtual
  1731. machine (KVM_VM_S390_UNCONTROL) on it's host page table that cannot be
  1732. resolved by the kernel.
  1733. The program code and the translation exception code that were placed
  1734. in the cpu's lowcore are presented here as defined by the z Architecture
  1735. Principles of Operation Book in the Chapter for Dynamic Address Translation
  1736. (DAT)
  1737. /* KVM_EXIT_DCR */
  1738. struct {
  1739. __u32 dcrn;
  1740. __u32 data;
  1741. __u8 is_write;
  1742. } dcr;
  1743. powerpc specific.
  1744. /* KVM_EXIT_OSI */
  1745. struct {
  1746. __u64 gprs[32];
  1747. } osi;
  1748. MOL uses a special hypercall interface it calls 'OSI'. To enable it, we catch
  1749. hypercalls and exit with this exit struct that contains all the guest gprs.
  1750. If exit_reason is KVM_EXIT_OSI, then the vcpu has triggered such a hypercall.
  1751. Userspace can now handle the hypercall and when it's done modify the gprs as
  1752. necessary. Upon guest entry all guest GPRs will then be replaced by the values
  1753. in this struct.
  1754. /* KVM_EXIT_PAPR_HCALL */
  1755. struct {
  1756. __u64 nr;
  1757. __u64 ret;
  1758. __u64 args[9];
  1759. } papr_hcall;
  1760. This is used on 64-bit PowerPC when emulating a pSeries partition,
  1761. e.g. with the 'pseries' machine type in qemu. It occurs when the
  1762. guest does a hypercall using the 'sc 1' instruction. The 'nr' field
  1763. contains the hypercall number (from the guest R3), and 'args' contains
  1764. the arguments (from the guest R4 - R12). Userspace should put the
  1765. return code in 'ret' and any extra returned values in args[].
  1766. The possible hypercalls are defined in the Power Architecture Platform
  1767. Requirements (PAPR) document available from www.power.org (free
  1768. developer registration required to access it).
  1769. /* Fix the size of the union. */
  1770. char padding[256];
  1771. };
  1772. /*
  1773. * shared registers between kvm and userspace.
  1774. * kvm_valid_regs specifies the register classes set by the host
  1775. * kvm_dirty_regs specified the register classes dirtied by userspace
  1776. * struct kvm_sync_regs is architecture specific, as well as the
  1777. * bits for kvm_valid_regs and kvm_dirty_regs
  1778. */
  1779. __u64 kvm_valid_regs;
  1780. __u64 kvm_dirty_regs;
  1781. union {
  1782. struct kvm_sync_regs regs;
  1783. char padding[1024];
  1784. } s;
  1785. If KVM_CAP_SYNC_REGS is defined, these fields allow userspace to access
  1786. certain guest registers without having to call SET/GET_*REGS. Thus we can
  1787. avoid some system call overhead if userspace has to handle the exit.
  1788. Userspace can query the validity of the structure by checking
  1789. kvm_valid_regs for specific bits. These bits are architecture specific
  1790. and usually define the validity of a groups of registers. (e.g. one bit
  1791. for general purpose registers)
  1792. };
  1793. 6. Capabilities that can be enabled
  1794. -----------------------------------
  1795. There are certain capabilities that change the behavior of the virtual CPU when
  1796. enabled. To enable them, please see section 4.37. Below you can find a list of
  1797. capabilities and what their effect on the vCPU is when enabling them.
  1798. The following information is provided along with the description:
  1799. Architectures: which instruction set architectures provide this ioctl.
  1800. x86 includes both i386 and x86_64.
  1801. Parameters: what parameters are accepted by the capability.
  1802. Returns: the return value. General error numbers (EBADF, ENOMEM, EINVAL)
  1803. are not detailed, but errors with specific meanings are.
  1804. 6.1 KVM_CAP_PPC_OSI
  1805. Architectures: ppc
  1806. Parameters: none
  1807. Returns: 0 on success; -1 on error
  1808. This capability enables interception of OSI hypercalls that otherwise would
  1809. be treated as normal system calls to be injected into the guest. OSI hypercalls
  1810. were invented by Mac-on-Linux to have a standardized communication mechanism
  1811. between the guest and the host.
  1812. When this capability is enabled, KVM_EXIT_OSI can occur.
  1813. 6.2 KVM_CAP_PPC_PAPR
  1814. Architectures: ppc
  1815. Parameters: none
  1816. Returns: 0 on success; -1 on error
  1817. This capability enables interception of PAPR hypercalls. PAPR hypercalls are
  1818. done using the hypercall instruction "sc 1".
  1819. It also sets the guest privilege level to "supervisor" mode. Usually the guest
  1820. runs in "hypervisor" privilege mode with a few missing features.
  1821. In addition to the above, it changes the semantics of SDR1. In this mode, the
  1822. HTAB address part of SDR1 contains an HVA instead of a GPA, as PAPR keeps the
  1823. HTAB invisible to the guest.
  1824. When this capability is enabled, KVM_EXIT_PAPR_HCALL can occur.
  1825. 6.3 KVM_CAP_SW_TLB
  1826. Architectures: ppc
  1827. Parameters: args[0] is the address of a struct kvm_config_tlb
  1828. Returns: 0 on success; -1 on error
  1829. struct kvm_config_tlb {
  1830. __u64 params;
  1831. __u64 array;
  1832. __u32 mmu_type;
  1833. __u32 array_len;
  1834. };
  1835. Configures the virtual CPU's TLB array, establishing a shared memory area
  1836. between userspace and KVM. The "params" and "array" fields are userspace
  1837. addresses of mmu-type-specific data structures. The "array_len" field is an
  1838. safety mechanism, and should be set to the size in bytes of the memory that
  1839. userspace has reserved for the array. It must be at least the size dictated
  1840. by "mmu_type" and "params".
  1841. While KVM_RUN is active, the shared region is under control of KVM. Its
  1842. contents are undefined, and any modification by userspace results in
  1843. boundedly undefined behavior.
  1844. On return from KVM_RUN, the shared region will reflect the current state of
  1845. the guest's TLB. If userspace makes any changes, it must call KVM_DIRTY_TLB
  1846. to tell KVM which entries have been changed, prior to calling KVM_RUN again
  1847. on this vcpu.
  1848. For mmu types KVM_MMU_FSL_BOOKE_NOHV and KVM_MMU_FSL_BOOKE_HV:
  1849. - The "params" field is of type "struct kvm_book3e_206_tlb_params".
  1850. - The "array" field points to an array of type "struct
  1851. kvm_book3e_206_tlb_entry".
  1852. - The array consists of all entries in the first TLB, followed by all
  1853. entries in the second TLB.
  1854. - Within a TLB, entries are ordered first by increasing set number. Within a
  1855. set, entries are ordered by way (increasing ESEL).
  1856. - The hash for determining set number in TLB0 is: (MAS2 >> 12) & (num_sets - 1)
  1857. where "num_sets" is the tlb_sizes[] value divided by the tlb_ways[] value.
  1858. - The tsize field of mas1 shall be set to 4K on TLB0, even though the
  1859. hardware ignores this value for TLB0.