api.txt 66 KB

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