api.txt 78 KB

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