kvm_host.h 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540
  1. /*
  2. * Kernel-based Virtual Machine driver for Linux
  3. *
  4. * This header defines architecture specific interfaces, x86 version
  5. *
  6. * This work is licensed under the terms of the GNU GPL, version 2. See
  7. * the COPYING file in the top-level directory.
  8. *
  9. */
  10. #ifndef _ASM_X86_KVM_HOST_H
  11. #define _ASM_X86_KVM_HOST_H
  12. #include <linux/types.h>
  13. #include <linux/mm.h>
  14. #include <linux/mmu_notifier.h>
  15. #include <linux/tracepoint.h>
  16. #include <linux/cpumask.h>
  17. #include <linux/irq_work.h>
  18. #include <linux/irq.h>
  19. #include <linux/kvm.h>
  20. #include <linux/kvm_para.h>
  21. #include <linux/kvm_types.h>
  22. #include <linux/perf_event.h>
  23. #include <linux/pvclock_gtod.h>
  24. #include <linux/clocksource.h>
  25. #include <linux/irqbypass.h>
  26. #include <linux/hyperv.h>
  27. #include <asm/apic.h>
  28. #include <asm/pvclock-abi.h>
  29. #include <asm/desc.h>
  30. #include <asm/mtrr.h>
  31. #include <asm/msr-index.h>
  32. #include <asm/asm.h>
  33. #include <asm/kvm_page_track.h>
  34. #include <asm/hyperv-tlfs.h>
  35. #define KVM_MAX_VCPUS 288
  36. #define KVM_SOFT_MAX_VCPUS 240
  37. #define KVM_MAX_VCPU_ID 1023
  38. #define KVM_USER_MEM_SLOTS 509
  39. /* memory slots that are not exposed to userspace */
  40. #define KVM_PRIVATE_MEM_SLOTS 3
  41. #define KVM_MEM_SLOTS_NUM (KVM_USER_MEM_SLOTS + KVM_PRIVATE_MEM_SLOTS)
  42. #define KVM_HALT_POLL_NS_DEFAULT 200000
  43. #define KVM_IRQCHIP_NUM_PINS KVM_IOAPIC_NUM_PINS
  44. /* x86-specific vcpu->requests bit members */
  45. #define KVM_REQ_MIGRATE_TIMER KVM_ARCH_REQ(0)
  46. #define KVM_REQ_REPORT_TPR_ACCESS KVM_ARCH_REQ(1)
  47. #define KVM_REQ_TRIPLE_FAULT KVM_ARCH_REQ(2)
  48. #define KVM_REQ_MMU_SYNC KVM_ARCH_REQ(3)
  49. #define KVM_REQ_CLOCK_UPDATE KVM_ARCH_REQ(4)
  50. #define KVM_REQ_LOAD_CR3 KVM_ARCH_REQ(5)
  51. #define KVM_REQ_EVENT KVM_ARCH_REQ(6)
  52. #define KVM_REQ_APF_HALT KVM_ARCH_REQ(7)
  53. #define KVM_REQ_STEAL_UPDATE KVM_ARCH_REQ(8)
  54. #define KVM_REQ_NMI KVM_ARCH_REQ(9)
  55. #define KVM_REQ_PMU KVM_ARCH_REQ(10)
  56. #define KVM_REQ_PMI KVM_ARCH_REQ(11)
  57. #define KVM_REQ_SMI KVM_ARCH_REQ(12)
  58. #define KVM_REQ_MASTERCLOCK_UPDATE KVM_ARCH_REQ(13)
  59. #define KVM_REQ_MCLOCK_INPROGRESS \
  60. KVM_ARCH_REQ_FLAGS(14, KVM_REQUEST_WAIT | KVM_REQUEST_NO_WAKEUP)
  61. #define KVM_REQ_SCAN_IOAPIC \
  62. KVM_ARCH_REQ_FLAGS(15, KVM_REQUEST_WAIT | KVM_REQUEST_NO_WAKEUP)
  63. #define KVM_REQ_GLOBAL_CLOCK_UPDATE KVM_ARCH_REQ(16)
  64. #define KVM_REQ_APIC_PAGE_RELOAD \
  65. KVM_ARCH_REQ_FLAGS(17, KVM_REQUEST_WAIT | KVM_REQUEST_NO_WAKEUP)
  66. #define KVM_REQ_HV_CRASH KVM_ARCH_REQ(18)
  67. #define KVM_REQ_IOAPIC_EOI_EXIT KVM_ARCH_REQ(19)
  68. #define KVM_REQ_HV_RESET KVM_ARCH_REQ(20)
  69. #define KVM_REQ_HV_EXIT KVM_ARCH_REQ(21)
  70. #define KVM_REQ_HV_STIMER KVM_ARCH_REQ(22)
  71. #define KVM_REQ_LOAD_EOI_EXITMAP KVM_ARCH_REQ(23)
  72. #define KVM_REQ_GET_VMCS12_PAGES KVM_ARCH_REQ(24)
  73. #define CR0_RESERVED_BITS \
  74. (~(unsigned long)(X86_CR0_PE | X86_CR0_MP | X86_CR0_EM | X86_CR0_TS \
  75. | X86_CR0_ET | X86_CR0_NE | X86_CR0_WP | X86_CR0_AM \
  76. | X86_CR0_NW | X86_CR0_CD | X86_CR0_PG))
  77. #define CR4_RESERVED_BITS \
  78. (~(unsigned long)(X86_CR4_VME | X86_CR4_PVI | X86_CR4_TSD | X86_CR4_DE\
  79. | X86_CR4_PSE | X86_CR4_PAE | X86_CR4_MCE \
  80. | X86_CR4_PGE | X86_CR4_PCE | X86_CR4_OSFXSR | X86_CR4_PCIDE \
  81. | X86_CR4_OSXSAVE | X86_CR4_SMEP | X86_CR4_FSGSBASE \
  82. | X86_CR4_OSXMMEXCPT | X86_CR4_LA57 | X86_CR4_VMXE \
  83. | X86_CR4_SMAP | X86_CR4_PKE | X86_CR4_UMIP))
  84. #define CR8_RESERVED_BITS (~(unsigned long)X86_CR8_TPR)
  85. #define INVALID_PAGE (~(hpa_t)0)
  86. #define VALID_PAGE(x) ((x) != INVALID_PAGE)
  87. #define UNMAPPED_GVA (~(gpa_t)0)
  88. /* KVM Hugepage definitions for x86 */
  89. #define KVM_NR_PAGE_SIZES 3
  90. #define KVM_HPAGE_GFN_SHIFT(x) (((x) - 1) * 9)
  91. #define KVM_HPAGE_SHIFT(x) (PAGE_SHIFT + KVM_HPAGE_GFN_SHIFT(x))
  92. #define KVM_HPAGE_SIZE(x) (1UL << KVM_HPAGE_SHIFT(x))
  93. #define KVM_HPAGE_MASK(x) (~(KVM_HPAGE_SIZE(x) - 1))
  94. #define KVM_PAGES_PER_HPAGE(x) (KVM_HPAGE_SIZE(x) / PAGE_SIZE)
  95. static inline gfn_t gfn_to_index(gfn_t gfn, gfn_t base_gfn, int level)
  96. {
  97. /* KVM_HPAGE_GFN_SHIFT(PT_PAGE_TABLE_LEVEL) must be 0. */
  98. return (gfn >> KVM_HPAGE_GFN_SHIFT(level)) -
  99. (base_gfn >> KVM_HPAGE_GFN_SHIFT(level));
  100. }
  101. #define KVM_PERMILLE_MMU_PAGES 20
  102. #define KVM_MIN_ALLOC_MMU_PAGES 64
  103. #define KVM_MMU_HASH_SHIFT 12
  104. #define KVM_NUM_MMU_PAGES (1 << KVM_MMU_HASH_SHIFT)
  105. #define KVM_MIN_FREE_MMU_PAGES 5
  106. #define KVM_REFILL_PAGES 25
  107. #define KVM_MAX_CPUID_ENTRIES 80
  108. #define KVM_NR_FIXED_MTRR_REGION 88
  109. #define KVM_NR_VAR_MTRR 8
  110. #define ASYNC_PF_PER_VCPU 64
  111. enum kvm_reg {
  112. VCPU_REGS_RAX = 0,
  113. VCPU_REGS_RCX = 1,
  114. VCPU_REGS_RDX = 2,
  115. VCPU_REGS_RBX = 3,
  116. VCPU_REGS_RSP = 4,
  117. VCPU_REGS_RBP = 5,
  118. VCPU_REGS_RSI = 6,
  119. VCPU_REGS_RDI = 7,
  120. #ifdef CONFIG_X86_64
  121. VCPU_REGS_R8 = 8,
  122. VCPU_REGS_R9 = 9,
  123. VCPU_REGS_R10 = 10,
  124. VCPU_REGS_R11 = 11,
  125. VCPU_REGS_R12 = 12,
  126. VCPU_REGS_R13 = 13,
  127. VCPU_REGS_R14 = 14,
  128. VCPU_REGS_R15 = 15,
  129. #endif
  130. VCPU_REGS_RIP,
  131. NR_VCPU_REGS
  132. };
  133. enum kvm_reg_ex {
  134. VCPU_EXREG_PDPTR = NR_VCPU_REGS,
  135. VCPU_EXREG_CR3,
  136. VCPU_EXREG_RFLAGS,
  137. VCPU_EXREG_SEGMENTS,
  138. };
  139. enum {
  140. VCPU_SREG_ES,
  141. VCPU_SREG_CS,
  142. VCPU_SREG_SS,
  143. VCPU_SREG_DS,
  144. VCPU_SREG_FS,
  145. VCPU_SREG_GS,
  146. VCPU_SREG_TR,
  147. VCPU_SREG_LDTR,
  148. };
  149. #include <asm/kvm_emulate.h>
  150. #define KVM_NR_MEM_OBJS 40
  151. #define KVM_NR_DB_REGS 4
  152. #define DR6_BD (1 << 13)
  153. #define DR6_BS (1 << 14)
  154. #define DR6_BT (1 << 15)
  155. #define DR6_RTM (1 << 16)
  156. #define DR6_FIXED_1 0xfffe0ff0
  157. #define DR6_INIT 0xffff0ff0
  158. #define DR6_VOLATILE 0x0001e00f
  159. #define DR7_BP_EN_MASK 0x000000ff
  160. #define DR7_GE (1 << 9)
  161. #define DR7_GD (1 << 13)
  162. #define DR7_FIXED_1 0x00000400
  163. #define DR7_VOLATILE 0xffff2bff
  164. #define PFERR_PRESENT_BIT 0
  165. #define PFERR_WRITE_BIT 1
  166. #define PFERR_USER_BIT 2
  167. #define PFERR_RSVD_BIT 3
  168. #define PFERR_FETCH_BIT 4
  169. #define PFERR_PK_BIT 5
  170. #define PFERR_GUEST_FINAL_BIT 32
  171. #define PFERR_GUEST_PAGE_BIT 33
  172. #define PFERR_PRESENT_MASK (1U << PFERR_PRESENT_BIT)
  173. #define PFERR_WRITE_MASK (1U << PFERR_WRITE_BIT)
  174. #define PFERR_USER_MASK (1U << PFERR_USER_BIT)
  175. #define PFERR_RSVD_MASK (1U << PFERR_RSVD_BIT)
  176. #define PFERR_FETCH_MASK (1U << PFERR_FETCH_BIT)
  177. #define PFERR_PK_MASK (1U << PFERR_PK_BIT)
  178. #define PFERR_GUEST_FINAL_MASK (1ULL << PFERR_GUEST_FINAL_BIT)
  179. #define PFERR_GUEST_PAGE_MASK (1ULL << PFERR_GUEST_PAGE_BIT)
  180. #define PFERR_NESTED_GUEST_PAGE (PFERR_GUEST_PAGE_MASK | \
  181. PFERR_WRITE_MASK | \
  182. PFERR_PRESENT_MASK)
  183. /*
  184. * The mask used to denote special SPTEs, which can be either MMIO SPTEs or
  185. * Access Tracking SPTEs. We use bit 62 instead of bit 63 to avoid conflicting
  186. * with the SVE bit in EPT PTEs.
  187. */
  188. #define SPTE_SPECIAL_MASK (1ULL << 62)
  189. /* apic attention bits */
  190. #define KVM_APIC_CHECK_VAPIC 0
  191. /*
  192. * The following bit is set with PV-EOI, unset on EOI.
  193. * We detect PV-EOI changes by guest by comparing
  194. * this bit with PV-EOI in guest memory.
  195. * See the implementation in apic_update_pv_eoi.
  196. */
  197. #define KVM_APIC_PV_EOI_PENDING 1
  198. struct kvm_kernel_irq_routing_entry;
  199. /*
  200. * We don't want allocation failures within the mmu code, so we preallocate
  201. * enough memory for a single page fault in a cache.
  202. */
  203. struct kvm_mmu_memory_cache {
  204. int nobjs;
  205. void *objects[KVM_NR_MEM_OBJS];
  206. };
  207. /*
  208. * the pages used as guest page table on soft mmu are tracked by
  209. * kvm_memory_slot.arch.gfn_track which is 16 bits, so the role bits used
  210. * by indirect shadow page can not be more than 15 bits.
  211. *
  212. * Currently, we used 14 bits that are @level, @cr4_pae, @quadrant, @access,
  213. * @nxe, @cr0_wp, @smep_andnot_wp and @smap_andnot_wp.
  214. */
  215. union kvm_mmu_page_role {
  216. unsigned word;
  217. struct {
  218. unsigned level:4;
  219. unsigned cr4_pae:1;
  220. unsigned quadrant:2;
  221. unsigned direct:1;
  222. unsigned access:3;
  223. unsigned invalid:1;
  224. unsigned nxe:1;
  225. unsigned cr0_wp:1;
  226. unsigned smep_andnot_wp:1;
  227. unsigned smap_andnot_wp:1;
  228. unsigned ad_disabled:1;
  229. unsigned guest_mode:1;
  230. unsigned :6;
  231. /*
  232. * This is left at the top of the word so that
  233. * kvm_memslots_for_spte_role can extract it with a
  234. * simple shift. While there is room, give it a whole
  235. * byte so it is also faster to load it from memory.
  236. */
  237. unsigned smm:8;
  238. };
  239. };
  240. struct kvm_rmap_head {
  241. unsigned long val;
  242. };
  243. struct kvm_mmu_page {
  244. struct list_head link;
  245. struct hlist_node hash_link;
  246. /*
  247. * The following two entries are used to key the shadow page in the
  248. * hash table.
  249. */
  250. gfn_t gfn;
  251. union kvm_mmu_page_role role;
  252. u64 *spt;
  253. /* hold the gfn of each spte inside spt */
  254. gfn_t *gfns;
  255. bool unsync;
  256. int root_count; /* Currently serving as active root */
  257. unsigned int unsync_children;
  258. struct kvm_rmap_head parent_ptes; /* rmap pointers to parent sptes */
  259. /* The page is obsolete if mmu_valid_gen != kvm->arch.mmu_valid_gen. */
  260. unsigned long mmu_valid_gen;
  261. DECLARE_BITMAP(unsync_child_bitmap, 512);
  262. #ifdef CONFIG_X86_32
  263. /*
  264. * Used out of the mmu-lock to avoid reading spte values while an
  265. * update is in progress; see the comments in __get_spte_lockless().
  266. */
  267. int clear_spte_count;
  268. #endif
  269. /* Number of writes since the last time traversal visited this page. */
  270. atomic_t write_flooding_count;
  271. };
  272. struct kvm_pio_request {
  273. unsigned long linear_rip;
  274. unsigned long count;
  275. int in;
  276. int port;
  277. int size;
  278. };
  279. #define PT64_ROOT_MAX_LEVEL 5
  280. struct rsvd_bits_validate {
  281. u64 rsvd_bits_mask[2][PT64_ROOT_MAX_LEVEL];
  282. u64 bad_mt_xwr;
  283. };
  284. struct kvm_mmu_root_info {
  285. gpa_t cr3;
  286. hpa_t hpa;
  287. };
  288. #define KVM_MMU_ROOT_INFO_INVALID \
  289. ((struct kvm_mmu_root_info) { .cr3 = INVALID_PAGE, .hpa = INVALID_PAGE })
  290. #define KVM_MMU_NUM_PREV_ROOTS 3
  291. /*
  292. * x86 supports 4 paging modes (5-level 64-bit, 4-level 64-bit, 3-level 32-bit,
  293. * and 2-level 32-bit). The kvm_mmu structure abstracts the details of the
  294. * current mmu mode.
  295. */
  296. struct kvm_mmu {
  297. void (*set_cr3)(struct kvm_vcpu *vcpu, unsigned long root);
  298. unsigned long (*get_cr3)(struct kvm_vcpu *vcpu);
  299. u64 (*get_pdptr)(struct kvm_vcpu *vcpu, int index);
  300. int (*page_fault)(struct kvm_vcpu *vcpu, gva_t gva, u32 err,
  301. bool prefault);
  302. void (*inject_page_fault)(struct kvm_vcpu *vcpu,
  303. struct x86_exception *fault);
  304. gpa_t (*gva_to_gpa)(struct kvm_vcpu *vcpu, gva_t gva, u32 access,
  305. struct x86_exception *exception);
  306. gpa_t (*translate_gpa)(struct kvm_vcpu *vcpu, gpa_t gpa, u32 access,
  307. struct x86_exception *exception);
  308. int (*sync_page)(struct kvm_vcpu *vcpu,
  309. struct kvm_mmu_page *sp);
  310. void (*invlpg)(struct kvm_vcpu *vcpu, gva_t gva, hpa_t root_hpa);
  311. void (*update_pte)(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp,
  312. u64 *spte, const void *pte);
  313. hpa_t root_hpa;
  314. union kvm_mmu_page_role base_role;
  315. u8 root_level;
  316. u8 shadow_root_level;
  317. u8 ept_ad;
  318. bool direct_map;
  319. struct kvm_mmu_root_info prev_roots[KVM_MMU_NUM_PREV_ROOTS];
  320. /*
  321. * Bitmap; bit set = permission fault
  322. * Byte index: page fault error code [4:1]
  323. * Bit index: pte permissions in ACC_* format
  324. */
  325. u8 permissions[16];
  326. /*
  327. * The pkru_mask indicates if protection key checks are needed. It
  328. * consists of 16 domains indexed by page fault error code bits [4:1],
  329. * with PFEC.RSVD replaced by ACC_USER_MASK from the page tables.
  330. * Each domain has 2 bits which are ANDed with AD and WD from PKRU.
  331. */
  332. u32 pkru_mask;
  333. u64 *pae_root;
  334. u64 *lm_root;
  335. /*
  336. * check zero bits on shadow page table entries, these
  337. * bits include not only hardware reserved bits but also
  338. * the bits spte never used.
  339. */
  340. struct rsvd_bits_validate shadow_zero_check;
  341. struct rsvd_bits_validate guest_rsvd_check;
  342. /* Can have large pages at levels 2..last_nonleaf_level-1. */
  343. u8 last_nonleaf_level;
  344. bool nx;
  345. u64 pdptrs[4]; /* pae */
  346. };
  347. enum pmc_type {
  348. KVM_PMC_GP = 0,
  349. KVM_PMC_FIXED,
  350. };
  351. struct kvm_pmc {
  352. enum pmc_type type;
  353. u8 idx;
  354. u64 counter;
  355. u64 eventsel;
  356. struct perf_event *perf_event;
  357. struct kvm_vcpu *vcpu;
  358. };
  359. struct kvm_pmu {
  360. unsigned nr_arch_gp_counters;
  361. unsigned nr_arch_fixed_counters;
  362. unsigned available_event_types;
  363. u64 fixed_ctr_ctrl;
  364. u64 global_ctrl;
  365. u64 global_status;
  366. u64 global_ovf_ctrl;
  367. u64 counter_bitmask[2];
  368. u64 global_ctrl_mask;
  369. u64 reserved_bits;
  370. u8 version;
  371. struct kvm_pmc gp_counters[INTEL_PMC_MAX_GENERIC];
  372. struct kvm_pmc fixed_counters[INTEL_PMC_MAX_FIXED];
  373. struct irq_work irq_work;
  374. u64 reprogram_pmi;
  375. };
  376. struct kvm_pmu_ops;
  377. enum {
  378. KVM_DEBUGREG_BP_ENABLED = 1,
  379. KVM_DEBUGREG_WONT_EXIT = 2,
  380. KVM_DEBUGREG_RELOAD = 4,
  381. };
  382. struct kvm_mtrr_range {
  383. u64 base;
  384. u64 mask;
  385. struct list_head node;
  386. };
  387. struct kvm_mtrr {
  388. struct kvm_mtrr_range var_ranges[KVM_NR_VAR_MTRR];
  389. mtrr_type fixed_ranges[KVM_NR_FIXED_MTRR_REGION];
  390. u64 deftype;
  391. struct list_head head;
  392. };
  393. /* Hyper-V SynIC timer */
  394. struct kvm_vcpu_hv_stimer {
  395. struct hrtimer timer;
  396. int index;
  397. u64 config;
  398. u64 count;
  399. u64 exp_time;
  400. struct hv_message msg;
  401. bool msg_pending;
  402. };
  403. /* Hyper-V synthetic interrupt controller (SynIC)*/
  404. struct kvm_vcpu_hv_synic {
  405. u64 version;
  406. u64 control;
  407. u64 msg_page;
  408. u64 evt_page;
  409. atomic64_t sint[HV_SYNIC_SINT_COUNT];
  410. atomic_t sint_to_gsi[HV_SYNIC_SINT_COUNT];
  411. DECLARE_BITMAP(auto_eoi_bitmap, 256);
  412. DECLARE_BITMAP(vec_bitmap, 256);
  413. bool active;
  414. bool dont_zero_synic_pages;
  415. };
  416. /* Hyper-V per vcpu emulation context */
  417. struct kvm_vcpu_hv {
  418. u32 vp_index;
  419. u64 hv_vapic;
  420. s64 runtime_offset;
  421. struct kvm_vcpu_hv_synic synic;
  422. struct kvm_hyperv_exit exit;
  423. struct kvm_vcpu_hv_stimer stimer[HV_SYNIC_STIMER_COUNT];
  424. DECLARE_BITMAP(stimer_pending_bitmap, HV_SYNIC_STIMER_COUNT);
  425. cpumask_t tlb_lush;
  426. };
  427. struct kvm_vcpu_arch {
  428. /*
  429. * rip and regs accesses must go through
  430. * kvm_{register,rip}_{read,write} functions.
  431. */
  432. unsigned long regs[NR_VCPU_REGS];
  433. u32 regs_avail;
  434. u32 regs_dirty;
  435. unsigned long cr0;
  436. unsigned long cr0_guest_owned_bits;
  437. unsigned long cr2;
  438. unsigned long cr3;
  439. unsigned long cr4;
  440. unsigned long cr4_guest_owned_bits;
  441. unsigned long cr8;
  442. u32 pkru;
  443. u32 hflags;
  444. u64 efer;
  445. u64 apic_base;
  446. struct kvm_lapic *apic; /* kernel irqchip context */
  447. bool apicv_active;
  448. bool load_eoi_exitmap_pending;
  449. DECLARE_BITMAP(ioapic_handled_vectors, 256);
  450. unsigned long apic_attention;
  451. int32_t apic_arb_prio;
  452. int mp_state;
  453. u64 ia32_misc_enable_msr;
  454. u64 smbase;
  455. u64 smi_count;
  456. bool tpr_access_reporting;
  457. u64 ia32_xss;
  458. u64 microcode_version;
  459. u64 arch_capabilities;
  460. /*
  461. * Paging state of the vcpu
  462. *
  463. * If the vcpu runs in guest mode with two level paging this still saves
  464. * the paging mode of the l1 guest. This context is always used to
  465. * handle faults.
  466. */
  467. struct kvm_mmu mmu;
  468. /*
  469. * Paging state of an L2 guest (used for nested npt)
  470. *
  471. * This context will save all necessary information to walk page tables
  472. * of the an L2 guest. This context is only initialized for page table
  473. * walking and not for faulting since we never handle l2 page faults on
  474. * the host.
  475. */
  476. struct kvm_mmu nested_mmu;
  477. /*
  478. * Pointer to the mmu context currently used for
  479. * gva_to_gpa translations.
  480. */
  481. struct kvm_mmu *walk_mmu;
  482. struct kvm_mmu_memory_cache mmu_pte_list_desc_cache;
  483. struct kvm_mmu_memory_cache mmu_page_cache;
  484. struct kvm_mmu_memory_cache mmu_page_header_cache;
  485. /*
  486. * QEMU userspace and the guest each have their own FPU state.
  487. * In vcpu_run, we switch between the user and guest FPU contexts.
  488. * While running a VCPU, the VCPU thread will have the guest FPU
  489. * context.
  490. *
  491. * Note that while the PKRU state lives inside the fpu registers,
  492. * it is switched out separately at VMENTER and VMEXIT time. The
  493. * "guest_fpu" state here contains the guest FPU context, with the
  494. * host PRKU bits.
  495. */
  496. struct fpu user_fpu;
  497. struct fpu guest_fpu;
  498. u64 xcr0;
  499. u64 guest_supported_xcr0;
  500. u32 guest_xstate_size;
  501. struct kvm_pio_request pio;
  502. void *pio_data;
  503. u8 event_exit_inst_len;
  504. struct kvm_queued_exception {
  505. bool pending;
  506. bool injected;
  507. bool has_error_code;
  508. u8 nr;
  509. u32 error_code;
  510. u8 nested_apf;
  511. } exception;
  512. struct kvm_queued_interrupt {
  513. bool injected;
  514. bool soft;
  515. u8 nr;
  516. } interrupt;
  517. int halt_request; /* real mode on Intel only */
  518. int cpuid_nent;
  519. struct kvm_cpuid_entry2 cpuid_entries[KVM_MAX_CPUID_ENTRIES];
  520. int maxphyaddr;
  521. /* emulate context */
  522. struct x86_emulate_ctxt emulate_ctxt;
  523. bool emulate_regs_need_sync_to_vcpu;
  524. bool emulate_regs_need_sync_from_vcpu;
  525. int (*complete_userspace_io)(struct kvm_vcpu *vcpu);
  526. gpa_t time;
  527. struct pvclock_vcpu_time_info hv_clock;
  528. unsigned int hw_tsc_khz;
  529. struct gfn_to_hva_cache pv_time;
  530. bool pv_time_enabled;
  531. /* set guest stopped flag in pvclock flags field */
  532. bool pvclock_set_guest_stopped_request;
  533. struct {
  534. u64 msr_val;
  535. u64 last_steal;
  536. struct gfn_to_hva_cache stime;
  537. struct kvm_steal_time steal;
  538. } st;
  539. u64 tsc_offset;
  540. u64 last_guest_tsc;
  541. u64 last_host_tsc;
  542. u64 tsc_offset_adjustment;
  543. u64 this_tsc_nsec;
  544. u64 this_tsc_write;
  545. u64 this_tsc_generation;
  546. bool tsc_catchup;
  547. bool tsc_always_catchup;
  548. s8 virtual_tsc_shift;
  549. u32 virtual_tsc_mult;
  550. u32 virtual_tsc_khz;
  551. s64 ia32_tsc_adjust_msr;
  552. u64 tsc_scaling_ratio;
  553. atomic_t nmi_queued; /* unprocessed asynchronous NMIs */
  554. unsigned nmi_pending; /* NMI queued after currently running handler */
  555. bool nmi_injected; /* Trying to inject an NMI this entry */
  556. bool smi_pending; /* SMI queued after currently running handler */
  557. struct kvm_mtrr mtrr_state;
  558. u64 pat;
  559. unsigned switch_db_regs;
  560. unsigned long db[KVM_NR_DB_REGS];
  561. unsigned long dr6;
  562. unsigned long dr7;
  563. unsigned long eff_db[KVM_NR_DB_REGS];
  564. unsigned long guest_debug_dr7;
  565. u64 msr_platform_info;
  566. u64 msr_misc_features_enables;
  567. u64 mcg_cap;
  568. u64 mcg_status;
  569. u64 mcg_ctl;
  570. u64 mcg_ext_ctl;
  571. u64 *mce_banks;
  572. /* Cache MMIO info */
  573. u64 mmio_gva;
  574. unsigned access;
  575. gfn_t mmio_gfn;
  576. u64 mmio_gen;
  577. struct kvm_pmu pmu;
  578. /* used for guest single stepping over the given code position */
  579. unsigned long singlestep_rip;
  580. struct kvm_vcpu_hv hyperv;
  581. cpumask_var_t wbinvd_dirty_mask;
  582. unsigned long last_retry_eip;
  583. unsigned long last_retry_addr;
  584. struct {
  585. bool halted;
  586. gfn_t gfns[roundup_pow_of_two(ASYNC_PF_PER_VCPU)];
  587. struct gfn_to_hva_cache data;
  588. u64 msr_val;
  589. u32 id;
  590. bool send_user_only;
  591. u32 host_apf_reason;
  592. unsigned long nested_apf_token;
  593. bool delivery_as_pf_vmexit;
  594. } apf;
  595. /* OSVW MSRs (AMD only) */
  596. struct {
  597. u64 length;
  598. u64 status;
  599. } osvw;
  600. struct {
  601. u64 msr_val;
  602. struct gfn_to_hva_cache data;
  603. } pv_eoi;
  604. /*
  605. * Indicate whether the access faults on its page table in guest
  606. * which is set when fix page fault and used to detect unhandeable
  607. * instruction.
  608. */
  609. bool write_fault_to_shadow_pgtable;
  610. /* set at EPT violation at this point */
  611. unsigned long exit_qualification;
  612. /* pv related host specific info */
  613. struct {
  614. bool pv_unhalted;
  615. } pv;
  616. int pending_ioapic_eoi;
  617. int pending_external_vector;
  618. /* GPA available */
  619. bool gpa_available;
  620. gpa_t gpa_val;
  621. /* be preempted when it's in kernel-mode(cpl=0) */
  622. bool preempted_in_kernel;
  623. /* Flush the L1 Data cache for L1TF mitigation on VMENTER */
  624. bool l1tf_flush_l1d;
  625. };
  626. struct kvm_lpage_info {
  627. int disallow_lpage;
  628. };
  629. struct kvm_arch_memory_slot {
  630. struct kvm_rmap_head *rmap[KVM_NR_PAGE_SIZES];
  631. struct kvm_lpage_info *lpage_info[KVM_NR_PAGE_SIZES - 1];
  632. unsigned short *gfn_track[KVM_PAGE_TRACK_MAX];
  633. };
  634. /*
  635. * We use as the mode the number of bits allocated in the LDR for the
  636. * logical processor ID. It happens that these are all powers of two.
  637. * This makes it is very easy to detect cases where the APICs are
  638. * configured for multiple modes; in that case, we cannot use the map and
  639. * hence cannot use kvm_irq_delivery_to_apic_fast either.
  640. */
  641. #define KVM_APIC_MODE_XAPIC_CLUSTER 4
  642. #define KVM_APIC_MODE_XAPIC_FLAT 8
  643. #define KVM_APIC_MODE_X2APIC 16
  644. struct kvm_apic_map {
  645. struct rcu_head rcu;
  646. u8 mode;
  647. u32 max_apic_id;
  648. union {
  649. struct kvm_lapic *xapic_flat_map[8];
  650. struct kvm_lapic *xapic_cluster_map[16][4];
  651. };
  652. struct kvm_lapic *phys_map[];
  653. };
  654. /* Hyper-V emulation context */
  655. struct kvm_hv {
  656. struct mutex hv_lock;
  657. u64 hv_guest_os_id;
  658. u64 hv_hypercall;
  659. u64 hv_tsc_page;
  660. /* Hyper-v based guest crash (NT kernel bugcheck) parameters */
  661. u64 hv_crash_param[HV_X64_MSR_CRASH_PARAMS];
  662. u64 hv_crash_ctl;
  663. HV_REFERENCE_TSC_PAGE tsc_ref;
  664. struct idr conn_to_evt;
  665. u64 hv_reenlightenment_control;
  666. u64 hv_tsc_emulation_control;
  667. u64 hv_tsc_emulation_status;
  668. };
  669. enum kvm_irqchip_mode {
  670. KVM_IRQCHIP_NONE,
  671. KVM_IRQCHIP_KERNEL, /* created with KVM_CREATE_IRQCHIP */
  672. KVM_IRQCHIP_SPLIT, /* created with KVM_CAP_SPLIT_IRQCHIP */
  673. };
  674. struct kvm_arch {
  675. unsigned int n_used_mmu_pages;
  676. unsigned int n_requested_mmu_pages;
  677. unsigned int n_max_mmu_pages;
  678. unsigned int indirect_shadow_pages;
  679. unsigned long mmu_valid_gen;
  680. struct hlist_head mmu_page_hash[KVM_NUM_MMU_PAGES];
  681. /*
  682. * Hash table of struct kvm_mmu_page.
  683. */
  684. struct list_head active_mmu_pages;
  685. struct list_head zapped_obsolete_pages;
  686. struct kvm_page_track_notifier_node mmu_sp_tracker;
  687. struct kvm_page_track_notifier_head track_notifier_head;
  688. struct list_head assigned_dev_head;
  689. struct iommu_domain *iommu_domain;
  690. bool iommu_noncoherent;
  691. #define __KVM_HAVE_ARCH_NONCOHERENT_DMA
  692. atomic_t noncoherent_dma_count;
  693. #define __KVM_HAVE_ARCH_ASSIGNED_DEVICE
  694. atomic_t assigned_device_count;
  695. struct kvm_pic *vpic;
  696. struct kvm_ioapic *vioapic;
  697. struct kvm_pit *vpit;
  698. atomic_t vapics_in_nmi_mode;
  699. struct mutex apic_map_lock;
  700. struct kvm_apic_map *apic_map;
  701. bool apic_access_page_done;
  702. gpa_t wall_clock;
  703. bool mwait_in_guest;
  704. bool hlt_in_guest;
  705. bool pause_in_guest;
  706. unsigned long irq_sources_bitmap;
  707. s64 kvmclock_offset;
  708. raw_spinlock_t tsc_write_lock;
  709. u64 last_tsc_nsec;
  710. u64 last_tsc_write;
  711. u32 last_tsc_khz;
  712. u64 cur_tsc_nsec;
  713. u64 cur_tsc_write;
  714. u64 cur_tsc_offset;
  715. u64 cur_tsc_generation;
  716. int nr_vcpus_matched_tsc;
  717. spinlock_t pvclock_gtod_sync_lock;
  718. bool use_master_clock;
  719. u64 master_kernel_ns;
  720. u64 master_cycle_now;
  721. struct delayed_work kvmclock_update_work;
  722. struct delayed_work kvmclock_sync_work;
  723. struct kvm_xen_hvm_config xen_hvm_config;
  724. /* reads protected by irq_srcu, writes by irq_lock */
  725. struct hlist_head mask_notifier_list;
  726. struct kvm_hv hyperv;
  727. #ifdef CONFIG_KVM_MMU_AUDIT
  728. int audit_point;
  729. #endif
  730. bool backwards_tsc_observed;
  731. bool boot_vcpu_runs_old_kvmclock;
  732. u32 bsp_vcpu_id;
  733. u64 disabled_quirks;
  734. enum kvm_irqchip_mode irqchip_mode;
  735. u8 nr_reserved_ioapic_pins;
  736. bool disabled_lapic_found;
  737. bool x2apic_format;
  738. bool x2apic_broadcast_quirk_disabled;
  739. bool guest_can_read_msr_platform_info;
  740. };
  741. struct kvm_vm_stat {
  742. ulong mmu_shadow_zapped;
  743. ulong mmu_pte_write;
  744. ulong mmu_pte_updated;
  745. ulong mmu_pde_zapped;
  746. ulong mmu_flooded;
  747. ulong mmu_recycled;
  748. ulong mmu_cache_miss;
  749. ulong mmu_unsync;
  750. ulong remote_tlb_flush;
  751. ulong lpages;
  752. ulong max_mmu_page_hash_collisions;
  753. };
  754. struct kvm_vcpu_stat {
  755. u64 pf_fixed;
  756. u64 pf_guest;
  757. u64 tlb_flush;
  758. u64 invlpg;
  759. u64 exits;
  760. u64 io_exits;
  761. u64 mmio_exits;
  762. u64 signal_exits;
  763. u64 irq_window_exits;
  764. u64 nmi_window_exits;
  765. u64 l1d_flush;
  766. u64 halt_exits;
  767. u64 halt_successful_poll;
  768. u64 halt_attempted_poll;
  769. u64 halt_poll_invalid;
  770. u64 halt_wakeup;
  771. u64 request_irq_exits;
  772. u64 irq_exits;
  773. u64 host_state_reload;
  774. u64 fpu_reload;
  775. u64 insn_emulation;
  776. u64 insn_emulation_fail;
  777. u64 hypercalls;
  778. u64 irq_injections;
  779. u64 nmi_injections;
  780. u64 req_event;
  781. };
  782. struct x86_instruction_info;
  783. struct msr_data {
  784. bool host_initiated;
  785. u32 index;
  786. u64 data;
  787. };
  788. struct kvm_lapic_irq {
  789. u32 vector;
  790. u16 delivery_mode;
  791. u16 dest_mode;
  792. bool level;
  793. u16 trig_mode;
  794. u32 shorthand;
  795. u32 dest_id;
  796. bool msi_redir_hint;
  797. };
  798. struct kvm_x86_ops {
  799. int (*cpu_has_kvm_support)(void); /* __init */
  800. int (*disabled_by_bios)(void); /* __init */
  801. int (*hardware_enable)(void);
  802. void (*hardware_disable)(void);
  803. void (*check_processor_compatibility)(void *rtn);
  804. int (*hardware_setup)(void); /* __init */
  805. void (*hardware_unsetup)(void); /* __exit */
  806. bool (*cpu_has_accelerated_tpr)(void);
  807. bool (*has_emulated_msr)(int index);
  808. void (*cpuid_update)(struct kvm_vcpu *vcpu);
  809. struct kvm *(*vm_alloc)(void);
  810. void (*vm_free)(struct kvm *);
  811. int (*vm_init)(struct kvm *kvm);
  812. void (*vm_destroy)(struct kvm *kvm);
  813. /* Create, but do not attach this VCPU */
  814. struct kvm_vcpu *(*vcpu_create)(struct kvm *kvm, unsigned id);
  815. void (*vcpu_free)(struct kvm_vcpu *vcpu);
  816. void (*vcpu_reset)(struct kvm_vcpu *vcpu, bool init_event);
  817. void (*prepare_guest_switch)(struct kvm_vcpu *vcpu);
  818. void (*vcpu_load)(struct kvm_vcpu *vcpu, int cpu);
  819. void (*vcpu_put)(struct kvm_vcpu *vcpu);
  820. void (*update_bp_intercept)(struct kvm_vcpu *vcpu);
  821. int (*get_msr)(struct kvm_vcpu *vcpu, struct msr_data *msr);
  822. int (*set_msr)(struct kvm_vcpu *vcpu, struct msr_data *msr);
  823. u64 (*get_segment_base)(struct kvm_vcpu *vcpu, int seg);
  824. void (*get_segment)(struct kvm_vcpu *vcpu,
  825. struct kvm_segment *var, int seg);
  826. int (*get_cpl)(struct kvm_vcpu *vcpu);
  827. void (*set_segment)(struct kvm_vcpu *vcpu,
  828. struct kvm_segment *var, int seg);
  829. void (*get_cs_db_l_bits)(struct kvm_vcpu *vcpu, int *db, int *l);
  830. void (*decache_cr0_guest_bits)(struct kvm_vcpu *vcpu);
  831. void (*decache_cr3)(struct kvm_vcpu *vcpu);
  832. void (*decache_cr4_guest_bits)(struct kvm_vcpu *vcpu);
  833. void (*set_cr0)(struct kvm_vcpu *vcpu, unsigned long cr0);
  834. void (*set_cr3)(struct kvm_vcpu *vcpu, unsigned long cr3);
  835. int (*set_cr4)(struct kvm_vcpu *vcpu, unsigned long cr4);
  836. void (*set_efer)(struct kvm_vcpu *vcpu, u64 efer);
  837. void (*get_idt)(struct kvm_vcpu *vcpu, struct desc_ptr *dt);
  838. void (*set_idt)(struct kvm_vcpu *vcpu, struct desc_ptr *dt);
  839. void (*get_gdt)(struct kvm_vcpu *vcpu, struct desc_ptr *dt);
  840. void (*set_gdt)(struct kvm_vcpu *vcpu, struct desc_ptr *dt);
  841. u64 (*get_dr6)(struct kvm_vcpu *vcpu);
  842. void (*set_dr6)(struct kvm_vcpu *vcpu, unsigned long value);
  843. void (*sync_dirty_debug_regs)(struct kvm_vcpu *vcpu);
  844. void (*set_dr7)(struct kvm_vcpu *vcpu, unsigned long value);
  845. void (*cache_reg)(struct kvm_vcpu *vcpu, enum kvm_reg reg);
  846. unsigned long (*get_rflags)(struct kvm_vcpu *vcpu);
  847. void (*set_rflags)(struct kvm_vcpu *vcpu, unsigned long rflags);
  848. void (*tlb_flush)(struct kvm_vcpu *vcpu, bool invalidate_gpa);
  849. int (*tlb_remote_flush)(struct kvm *kvm);
  850. /*
  851. * Flush any TLB entries associated with the given GVA.
  852. * Does not need to flush GPA->HPA mappings.
  853. * Can potentially get non-canonical addresses through INVLPGs, which
  854. * the implementation may choose to ignore if appropriate.
  855. */
  856. void (*tlb_flush_gva)(struct kvm_vcpu *vcpu, gva_t addr);
  857. void (*run)(struct kvm_vcpu *vcpu);
  858. int (*handle_exit)(struct kvm_vcpu *vcpu);
  859. void (*skip_emulated_instruction)(struct kvm_vcpu *vcpu);
  860. void (*set_interrupt_shadow)(struct kvm_vcpu *vcpu, int mask);
  861. u32 (*get_interrupt_shadow)(struct kvm_vcpu *vcpu);
  862. void (*patch_hypercall)(struct kvm_vcpu *vcpu,
  863. unsigned char *hypercall_addr);
  864. void (*set_irq)(struct kvm_vcpu *vcpu);
  865. void (*set_nmi)(struct kvm_vcpu *vcpu);
  866. void (*queue_exception)(struct kvm_vcpu *vcpu);
  867. void (*cancel_injection)(struct kvm_vcpu *vcpu);
  868. int (*interrupt_allowed)(struct kvm_vcpu *vcpu);
  869. int (*nmi_allowed)(struct kvm_vcpu *vcpu);
  870. bool (*get_nmi_mask)(struct kvm_vcpu *vcpu);
  871. void (*set_nmi_mask)(struct kvm_vcpu *vcpu, bool masked);
  872. void (*enable_nmi_window)(struct kvm_vcpu *vcpu);
  873. void (*enable_irq_window)(struct kvm_vcpu *vcpu);
  874. void (*update_cr8_intercept)(struct kvm_vcpu *vcpu, int tpr, int irr);
  875. bool (*get_enable_apicv)(struct kvm_vcpu *vcpu);
  876. void (*refresh_apicv_exec_ctrl)(struct kvm_vcpu *vcpu);
  877. void (*hwapic_irr_update)(struct kvm_vcpu *vcpu, int max_irr);
  878. void (*hwapic_isr_update)(struct kvm_vcpu *vcpu, int isr);
  879. bool (*guest_apic_has_interrupt)(struct kvm_vcpu *vcpu);
  880. void (*load_eoi_exitmap)(struct kvm_vcpu *vcpu, u64 *eoi_exit_bitmap);
  881. void (*set_virtual_apic_mode)(struct kvm_vcpu *vcpu);
  882. void (*set_apic_access_page_addr)(struct kvm_vcpu *vcpu, hpa_t hpa);
  883. void (*deliver_posted_interrupt)(struct kvm_vcpu *vcpu, int vector);
  884. int (*sync_pir_to_irr)(struct kvm_vcpu *vcpu);
  885. int (*set_tss_addr)(struct kvm *kvm, unsigned int addr);
  886. int (*set_identity_map_addr)(struct kvm *kvm, u64 ident_addr);
  887. int (*get_tdp_level)(struct kvm_vcpu *vcpu);
  888. u64 (*get_mt_mask)(struct kvm_vcpu *vcpu, gfn_t gfn, bool is_mmio);
  889. int (*get_lpage_level)(void);
  890. bool (*rdtscp_supported)(void);
  891. bool (*invpcid_supported)(void);
  892. void (*set_tdp_cr3)(struct kvm_vcpu *vcpu, unsigned long cr3);
  893. void (*set_supported_cpuid)(u32 func, struct kvm_cpuid_entry2 *entry);
  894. bool (*has_wbinvd_exit)(void);
  895. u64 (*read_l1_tsc_offset)(struct kvm_vcpu *vcpu);
  896. /* Returns actual tsc_offset set in active VMCS */
  897. u64 (*write_l1_tsc_offset)(struct kvm_vcpu *vcpu, u64 offset);
  898. void (*get_exit_info)(struct kvm_vcpu *vcpu, u64 *info1, u64 *info2);
  899. int (*check_intercept)(struct kvm_vcpu *vcpu,
  900. struct x86_instruction_info *info,
  901. enum x86_intercept_stage stage);
  902. void (*handle_external_intr)(struct kvm_vcpu *vcpu);
  903. bool (*mpx_supported)(void);
  904. bool (*xsaves_supported)(void);
  905. bool (*umip_emulated)(void);
  906. int (*check_nested_events)(struct kvm_vcpu *vcpu, bool external_intr);
  907. void (*request_immediate_exit)(struct kvm_vcpu *vcpu);
  908. void (*sched_in)(struct kvm_vcpu *kvm, int cpu);
  909. /*
  910. * Arch-specific dirty logging hooks. These hooks are only supposed to
  911. * be valid if the specific arch has hardware-accelerated dirty logging
  912. * mechanism. Currently only for PML on VMX.
  913. *
  914. * - slot_enable_log_dirty:
  915. * called when enabling log dirty mode for the slot.
  916. * - slot_disable_log_dirty:
  917. * called when disabling log dirty mode for the slot.
  918. * also called when slot is created with log dirty disabled.
  919. * - flush_log_dirty:
  920. * called before reporting dirty_bitmap to userspace.
  921. * - enable_log_dirty_pt_masked:
  922. * called when reenabling log dirty for the GFNs in the mask after
  923. * corresponding bits are cleared in slot->dirty_bitmap.
  924. */
  925. void (*slot_enable_log_dirty)(struct kvm *kvm,
  926. struct kvm_memory_slot *slot);
  927. void (*slot_disable_log_dirty)(struct kvm *kvm,
  928. struct kvm_memory_slot *slot);
  929. void (*flush_log_dirty)(struct kvm *kvm);
  930. void (*enable_log_dirty_pt_masked)(struct kvm *kvm,
  931. struct kvm_memory_slot *slot,
  932. gfn_t offset, unsigned long mask);
  933. int (*write_log_dirty)(struct kvm_vcpu *vcpu);
  934. /* pmu operations of sub-arch */
  935. const struct kvm_pmu_ops *pmu_ops;
  936. /*
  937. * Architecture specific hooks for vCPU blocking due to
  938. * HLT instruction.
  939. * Returns for .pre_block():
  940. * - 0 means continue to block the vCPU.
  941. * - 1 means we cannot block the vCPU since some event
  942. * happens during this period, such as, 'ON' bit in
  943. * posted-interrupts descriptor is set.
  944. */
  945. int (*pre_block)(struct kvm_vcpu *vcpu);
  946. void (*post_block)(struct kvm_vcpu *vcpu);
  947. void (*vcpu_blocking)(struct kvm_vcpu *vcpu);
  948. void (*vcpu_unblocking)(struct kvm_vcpu *vcpu);
  949. int (*update_pi_irte)(struct kvm *kvm, unsigned int host_irq,
  950. uint32_t guest_irq, bool set);
  951. void (*apicv_post_state_restore)(struct kvm_vcpu *vcpu);
  952. bool (*dy_apicv_has_pending_interrupt)(struct kvm_vcpu *vcpu);
  953. int (*set_hv_timer)(struct kvm_vcpu *vcpu, u64 guest_deadline_tsc);
  954. void (*cancel_hv_timer)(struct kvm_vcpu *vcpu);
  955. void (*setup_mce)(struct kvm_vcpu *vcpu);
  956. int (*get_nested_state)(struct kvm_vcpu *vcpu,
  957. struct kvm_nested_state __user *user_kvm_nested_state,
  958. unsigned user_data_size);
  959. int (*set_nested_state)(struct kvm_vcpu *vcpu,
  960. struct kvm_nested_state __user *user_kvm_nested_state,
  961. struct kvm_nested_state *kvm_state);
  962. void (*get_vmcs12_pages)(struct kvm_vcpu *vcpu);
  963. int (*smi_allowed)(struct kvm_vcpu *vcpu);
  964. int (*pre_enter_smm)(struct kvm_vcpu *vcpu, char *smstate);
  965. int (*pre_leave_smm)(struct kvm_vcpu *vcpu, u64 smbase);
  966. int (*enable_smi_window)(struct kvm_vcpu *vcpu);
  967. int (*mem_enc_op)(struct kvm *kvm, void __user *argp);
  968. int (*mem_enc_reg_region)(struct kvm *kvm, struct kvm_enc_region *argp);
  969. int (*mem_enc_unreg_region)(struct kvm *kvm, struct kvm_enc_region *argp);
  970. int (*get_msr_feature)(struct kvm_msr_entry *entry);
  971. };
  972. struct kvm_arch_async_pf {
  973. u32 token;
  974. gfn_t gfn;
  975. unsigned long cr3;
  976. bool direct_map;
  977. };
  978. extern struct kvm_x86_ops *kvm_x86_ops;
  979. #define __KVM_HAVE_ARCH_VM_ALLOC
  980. static inline struct kvm *kvm_arch_alloc_vm(void)
  981. {
  982. return kvm_x86_ops->vm_alloc();
  983. }
  984. static inline void kvm_arch_free_vm(struct kvm *kvm)
  985. {
  986. return kvm_x86_ops->vm_free(kvm);
  987. }
  988. #define __KVM_HAVE_ARCH_FLUSH_REMOTE_TLB
  989. static inline int kvm_arch_flush_remote_tlb(struct kvm *kvm)
  990. {
  991. if (kvm_x86_ops->tlb_remote_flush &&
  992. !kvm_x86_ops->tlb_remote_flush(kvm))
  993. return 0;
  994. else
  995. return -ENOTSUPP;
  996. }
  997. int kvm_mmu_module_init(void);
  998. void kvm_mmu_module_exit(void);
  999. void kvm_mmu_destroy(struct kvm_vcpu *vcpu);
  1000. int kvm_mmu_create(struct kvm_vcpu *vcpu);
  1001. void kvm_mmu_setup(struct kvm_vcpu *vcpu);
  1002. void kvm_mmu_init_vm(struct kvm *kvm);
  1003. void kvm_mmu_uninit_vm(struct kvm *kvm);
  1004. void kvm_mmu_set_mask_ptes(u64 user_mask, u64 accessed_mask,
  1005. u64 dirty_mask, u64 nx_mask, u64 x_mask, u64 p_mask,
  1006. u64 acc_track_mask, u64 me_mask);
  1007. void kvm_mmu_reset_context(struct kvm_vcpu *vcpu);
  1008. void kvm_mmu_slot_remove_write_access(struct kvm *kvm,
  1009. struct kvm_memory_slot *memslot);
  1010. void kvm_mmu_zap_collapsible_sptes(struct kvm *kvm,
  1011. const struct kvm_memory_slot *memslot);
  1012. void kvm_mmu_slot_leaf_clear_dirty(struct kvm *kvm,
  1013. struct kvm_memory_slot *memslot);
  1014. void kvm_mmu_slot_largepage_remove_write_access(struct kvm *kvm,
  1015. struct kvm_memory_slot *memslot);
  1016. void kvm_mmu_slot_set_dirty(struct kvm *kvm,
  1017. struct kvm_memory_slot *memslot);
  1018. void kvm_mmu_clear_dirty_pt_masked(struct kvm *kvm,
  1019. struct kvm_memory_slot *slot,
  1020. gfn_t gfn_offset, unsigned long mask);
  1021. void kvm_mmu_zap_all(struct kvm *kvm);
  1022. void kvm_mmu_invalidate_mmio_sptes(struct kvm *kvm, u64 gen);
  1023. unsigned int kvm_mmu_calculate_mmu_pages(struct kvm *kvm);
  1024. void kvm_mmu_change_mmu_pages(struct kvm *kvm, unsigned int kvm_nr_mmu_pages);
  1025. int load_pdptrs(struct kvm_vcpu *vcpu, struct kvm_mmu *mmu, unsigned long cr3);
  1026. bool pdptrs_changed(struct kvm_vcpu *vcpu);
  1027. int emulator_write_phys(struct kvm_vcpu *vcpu, gpa_t gpa,
  1028. const void *val, int bytes);
  1029. struct kvm_irq_mask_notifier {
  1030. void (*func)(struct kvm_irq_mask_notifier *kimn, bool masked);
  1031. int irq;
  1032. struct hlist_node link;
  1033. };
  1034. void kvm_register_irq_mask_notifier(struct kvm *kvm, int irq,
  1035. struct kvm_irq_mask_notifier *kimn);
  1036. void kvm_unregister_irq_mask_notifier(struct kvm *kvm, int irq,
  1037. struct kvm_irq_mask_notifier *kimn);
  1038. void kvm_fire_mask_notifiers(struct kvm *kvm, unsigned irqchip, unsigned pin,
  1039. bool mask);
  1040. extern bool tdp_enabled;
  1041. u64 vcpu_tsc_khz(struct kvm_vcpu *vcpu);
  1042. /* control of guest tsc rate supported? */
  1043. extern bool kvm_has_tsc_control;
  1044. /* maximum supported tsc_khz for guests */
  1045. extern u32 kvm_max_guest_tsc_khz;
  1046. /* number of bits of the fractional part of the TSC scaling ratio */
  1047. extern u8 kvm_tsc_scaling_ratio_frac_bits;
  1048. /* maximum allowed value of TSC scaling ratio */
  1049. extern u64 kvm_max_tsc_scaling_ratio;
  1050. /* 1ull << kvm_tsc_scaling_ratio_frac_bits */
  1051. extern u64 kvm_default_tsc_scaling_ratio;
  1052. extern u64 kvm_mce_cap_supported;
  1053. enum emulation_result {
  1054. EMULATE_DONE, /* no further processing */
  1055. EMULATE_USER_EXIT, /* kvm_run ready for userspace exit */
  1056. EMULATE_FAIL, /* can't emulate this instruction */
  1057. };
  1058. #define EMULTYPE_NO_DECODE (1 << 0)
  1059. #define EMULTYPE_TRAP_UD (1 << 1)
  1060. #define EMULTYPE_SKIP (1 << 2)
  1061. #define EMULTYPE_ALLOW_RETRY (1 << 3)
  1062. #define EMULTYPE_NO_UD_ON_FAIL (1 << 4)
  1063. #define EMULTYPE_VMWARE (1 << 5)
  1064. int kvm_emulate_instruction(struct kvm_vcpu *vcpu, int emulation_type);
  1065. int kvm_emulate_instruction_from_buffer(struct kvm_vcpu *vcpu,
  1066. void *insn, int insn_len);
  1067. void kvm_enable_efer_bits(u64);
  1068. bool kvm_valid_efer(struct kvm_vcpu *vcpu, u64 efer);
  1069. int kvm_get_msr(struct kvm_vcpu *vcpu, struct msr_data *msr);
  1070. int kvm_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr);
  1071. struct x86_emulate_ctxt;
  1072. int kvm_fast_pio(struct kvm_vcpu *vcpu, int size, unsigned short port, int in);
  1073. int kvm_emulate_cpuid(struct kvm_vcpu *vcpu);
  1074. int kvm_emulate_halt(struct kvm_vcpu *vcpu);
  1075. int kvm_vcpu_halt(struct kvm_vcpu *vcpu);
  1076. int kvm_emulate_wbinvd(struct kvm_vcpu *vcpu);
  1077. void kvm_get_segment(struct kvm_vcpu *vcpu, struct kvm_segment *var, int seg);
  1078. int kvm_load_segment_descriptor(struct kvm_vcpu *vcpu, u16 selector, int seg);
  1079. void kvm_vcpu_deliver_sipi_vector(struct kvm_vcpu *vcpu, u8 vector);
  1080. int kvm_task_switch(struct kvm_vcpu *vcpu, u16 tss_selector, int idt_index,
  1081. int reason, bool has_error_code, u32 error_code);
  1082. int kvm_set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0);
  1083. int kvm_set_cr3(struct kvm_vcpu *vcpu, unsigned long cr3);
  1084. int kvm_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4);
  1085. int kvm_set_cr8(struct kvm_vcpu *vcpu, unsigned long cr8);
  1086. int kvm_set_dr(struct kvm_vcpu *vcpu, int dr, unsigned long val);
  1087. int kvm_get_dr(struct kvm_vcpu *vcpu, int dr, unsigned long *val);
  1088. unsigned long kvm_get_cr8(struct kvm_vcpu *vcpu);
  1089. void kvm_lmsw(struct kvm_vcpu *vcpu, unsigned long msw);
  1090. void kvm_get_cs_db_l_bits(struct kvm_vcpu *vcpu, int *db, int *l);
  1091. int kvm_set_xcr(struct kvm_vcpu *vcpu, u32 index, u64 xcr);
  1092. int kvm_get_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr);
  1093. int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr);
  1094. unsigned long kvm_get_rflags(struct kvm_vcpu *vcpu);
  1095. void kvm_set_rflags(struct kvm_vcpu *vcpu, unsigned long rflags);
  1096. bool kvm_rdpmc(struct kvm_vcpu *vcpu);
  1097. void kvm_queue_exception(struct kvm_vcpu *vcpu, unsigned nr);
  1098. void kvm_queue_exception_e(struct kvm_vcpu *vcpu, unsigned nr, u32 error_code);
  1099. void kvm_requeue_exception(struct kvm_vcpu *vcpu, unsigned nr);
  1100. void kvm_requeue_exception_e(struct kvm_vcpu *vcpu, unsigned nr, u32 error_code);
  1101. void kvm_inject_page_fault(struct kvm_vcpu *vcpu, struct x86_exception *fault);
  1102. int kvm_read_guest_page_mmu(struct kvm_vcpu *vcpu, struct kvm_mmu *mmu,
  1103. gfn_t gfn, void *data, int offset, int len,
  1104. u32 access);
  1105. bool kvm_require_cpl(struct kvm_vcpu *vcpu, int required_cpl);
  1106. bool kvm_require_dr(struct kvm_vcpu *vcpu, int dr);
  1107. static inline int __kvm_irq_line_state(unsigned long *irq_state,
  1108. int irq_source_id, int level)
  1109. {
  1110. /* Logical OR for level trig interrupt */
  1111. if (level)
  1112. __set_bit(irq_source_id, irq_state);
  1113. else
  1114. __clear_bit(irq_source_id, irq_state);
  1115. return !!(*irq_state);
  1116. }
  1117. #define KVM_MMU_ROOT_CURRENT BIT(0)
  1118. #define KVM_MMU_ROOT_PREVIOUS(i) BIT(1+i)
  1119. #define KVM_MMU_ROOTS_ALL (~0UL)
  1120. int kvm_pic_set_irq(struct kvm_pic *pic, int irq, int irq_source_id, int level);
  1121. void kvm_pic_clear_all(struct kvm_pic *pic, int irq_source_id);
  1122. void kvm_inject_nmi(struct kvm_vcpu *vcpu);
  1123. int kvm_mmu_unprotect_page(struct kvm *kvm, gfn_t gfn);
  1124. int kvm_mmu_unprotect_page_virt(struct kvm_vcpu *vcpu, gva_t gva);
  1125. void __kvm_mmu_free_some_pages(struct kvm_vcpu *vcpu);
  1126. int kvm_mmu_load(struct kvm_vcpu *vcpu);
  1127. void kvm_mmu_unload(struct kvm_vcpu *vcpu);
  1128. void kvm_mmu_sync_roots(struct kvm_vcpu *vcpu);
  1129. void kvm_mmu_free_roots(struct kvm_vcpu *vcpu, ulong roots_to_free);
  1130. gpa_t translate_nested_gpa(struct kvm_vcpu *vcpu, gpa_t gpa, u32 access,
  1131. struct x86_exception *exception);
  1132. gpa_t kvm_mmu_gva_to_gpa_read(struct kvm_vcpu *vcpu, gva_t gva,
  1133. struct x86_exception *exception);
  1134. gpa_t kvm_mmu_gva_to_gpa_fetch(struct kvm_vcpu *vcpu, gva_t gva,
  1135. struct x86_exception *exception);
  1136. gpa_t kvm_mmu_gva_to_gpa_write(struct kvm_vcpu *vcpu, gva_t gva,
  1137. struct x86_exception *exception);
  1138. gpa_t kvm_mmu_gva_to_gpa_system(struct kvm_vcpu *vcpu, gva_t gva,
  1139. struct x86_exception *exception);
  1140. void kvm_vcpu_deactivate_apicv(struct kvm_vcpu *vcpu);
  1141. int kvm_emulate_hypercall(struct kvm_vcpu *vcpu);
  1142. int kvm_mmu_page_fault(struct kvm_vcpu *vcpu, gva_t gva, u64 error_code,
  1143. void *insn, int insn_len);
  1144. void kvm_mmu_invlpg(struct kvm_vcpu *vcpu, gva_t gva);
  1145. void kvm_mmu_invpcid_gva(struct kvm_vcpu *vcpu, gva_t gva, unsigned long pcid);
  1146. void kvm_mmu_new_cr3(struct kvm_vcpu *vcpu, gpa_t new_cr3, bool skip_tlb_flush);
  1147. void kvm_enable_tdp(void);
  1148. void kvm_disable_tdp(void);
  1149. static inline gpa_t translate_gpa(struct kvm_vcpu *vcpu, gpa_t gpa, u32 access,
  1150. struct x86_exception *exception)
  1151. {
  1152. return gpa;
  1153. }
  1154. static inline struct kvm_mmu_page *page_header(hpa_t shadow_page)
  1155. {
  1156. struct page *page = pfn_to_page(shadow_page >> PAGE_SHIFT);
  1157. return (struct kvm_mmu_page *)page_private(page);
  1158. }
  1159. static inline u16 kvm_read_ldt(void)
  1160. {
  1161. u16 ldt;
  1162. asm("sldt %0" : "=g"(ldt));
  1163. return ldt;
  1164. }
  1165. static inline void kvm_load_ldt(u16 sel)
  1166. {
  1167. asm("lldt %0" : : "rm"(sel));
  1168. }
  1169. #ifdef CONFIG_X86_64
  1170. static inline unsigned long read_msr(unsigned long msr)
  1171. {
  1172. u64 value;
  1173. rdmsrl(msr, value);
  1174. return value;
  1175. }
  1176. #endif
  1177. static inline u32 get_rdx_init_val(void)
  1178. {
  1179. return 0x600; /* P6 family */
  1180. }
  1181. static inline void kvm_inject_gp(struct kvm_vcpu *vcpu, u32 error_code)
  1182. {
  1183. kvm_queue_exception_e(vcpu, GP_VECTOR, error_code);
  1184. }
  1185. #define TSS_IOPB_BASE_OFFSET 0x66
  1186. #define TSS_BASE_SIZE 0x68
  1187. #define TSS_IOPB_SIZE (65536 / 8)
  1188. #define TSS_REDIRECTION_SIZE (256 / 8)
  1189. #define RMODE_TSS_SIZE \
  1190. (TSS_BASE_SIZE + TSS_REDIRECTION_SIZE + TSS_IOPB_SIZE + 1)
  1191. enum {
  1192. TASK_SWITCH_CALL = 0,
  1193. TASK_SWITCH_IRET = 1,
  1194. TASK_SWITCH_JMP = 2,
  1195. TASK_SWITCH_GATE = 3,
  1196. };
  1197. #define HF_GIF_MASK (1 << 0)
  1198. #define HF_HIF_MASK (1 << 1)
  1199. #define HF_VINTR_MASK (1 << 2)
  1200. #define HF_NMI_MASK (1 << 3)
  1201. #define HF_IRET_MASK (1 << 4)
  1202. #define HF_GUEST_MASK (1 << 5) /* VCPU is in guest-mode */
  1203. #define HF_SMM_MASK (1 << 6)
  1204. #define HF_SMM_INSIDE_NMI_MASK (1 << 7)
  1205. #define __KVM_VCPU_MULTIPLE_ADDRESS_SPACE
  1206. #define KVM_ADDRESS_SPACE_NUM 2
  1207. #define kvm_arch_vcpu_memslots_id(vcpu) ((vcpu)->arch.hflags & HF_SMM_MASK ? 1 : 0)
  1208. #define kvm_memslots_for_spte_role(kvm, role) __kvm_memslots(kvm, (role).smm)
  1209. asmlinkage void __noreturn kvm_spurious_fault(void);
  1210. /*
  1211. * Hardware virtualization extension instructions may fault if a
  1212. * reboot turns off virtualization while processes are running.
  1213. * Usually after catching the fault we just panic; during reboot
  1214. * instead the instruction is ignored.
  1215. */
  1216. #define ____kvm_handle_fault_on_reboot(insn, cleanup_insn) \
  1217. "666: \n\t" \
  1218. insn "\n\t" \
  1219. "jmp 668f \n\t" \
  1220. "667: \n\t" \
  1221. "call kvm_spurious_fault \n\t" \
  1222. "668: \n\t" \
  1223. ".pushsection .fixup, \"ax\" \n\t" \
  1224. "700: \n\t" \
  1225. cleanup_insn "\n\t" \
  1226. "cmpb $0, kvm_rebooting\n\t" \
  1227. "je 667b \n\t" \
  1228. "jmp 668b \n\t" \
  1229. ".popsection \n\t" \
  1230. _ASM_EXTABLE(666b, 700b)
  1231. #define __kvm_handle_fault_on_reboot(insn) \
  1232. ____kvm_handle_fault_on_reboot(insn, "")
  1233. #define KVM_ARCH_WANT_MMU_NOTIFIER
  1234. int kvm_unmap_hva_range(struct kvm *kvm, unsigned long start, unsigned long end);
  1235. int kvm_age_hva(struct kvm *kvm, unsigned long start, unsigned long end);
  1236. int kvm_test_age_hva(struct kvm *kvm, unsigned long hva);
  1237. void kvm_set_spte_hva(struct kvm *kvm, unsigned long hva, pte_t pte);
  1238. int kvm_cpu_has_injectable_intr(struct kvm_vcpu *v);
  1239. int kvm_cpu_has_interrupt(struct kvm_vcpu *vcpu);
  1240. int kvm_arch_interrupt_allowed(struct kvm_vcpu *vcpu);
  1241. int kvm_cpu_get_interrupt(struct kvm_vcpu *v);
  1242. void kvm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event);
  1243. void kvm_vcpu_reload_apic_access_page(struct kvm_vcpu *vcpu);
  1244. int kvm_pv_send_ipi(struct kvm *kvm, unsigned long ipi_bitmap_low,
  1245. unsigned long ipi_bitmap_high, u32 min,
  1246. unsigned long icr, int op_64_bit);
  1247. u64 kvm_get_arch_capabilities(void);
  1248. void kvm_define_shared_msr(unsigned index, u32 msr);
  1249. int kvm_set_shared_msr(unsigned index, u64 val, u64 mask);
  1250. u64 kvm_scale_tsc(struct kvm_vcpu *vcpu, u64 tsc);
  1251. u64 kvm_read_l1_tsc(struct kvm_vcpu *vcpu, u64 host_tsc);
  1252. unsigned long kvm_get_linear_rip(struct kvm_vcpu *vcpu);
  1253. bool kvm_is_linear_rip(struct kvm_vcpu *vcpu, unsigned long linear_rip);
  1254. void kvm_make_mclock_inprogress_request(struct kvm *kvm);
  1255. void kvm_make_scan_ioapic_request(struct kvm *kvm);
  1256. void kvm_arch_async_page_not_present(struct kvm_vcpu *vcpu,
  1257. struct kvm_async_pf *work);
  1258. void kvm_arch_async_page_present(struct kvm_vcpu *vcpu,
  1259. struct kvm_async_pf *work);
  1260. void kvm_arch_async_page_ready(struct kvm_vcpu *vcpu,
  1261. struct kvm_async_pf *work);
  1262. bool kvm_arch_can_inject_async_page_present(struct kvm_vcpu *vcpu);
  1263. extern bool kvm_find_async_pf_gfn(struct kvm_vcpu *vcpu, gfn_t gfn);
  1264. int kvm_skip_emulated_instruction(struct kvm_vcpu *vcpu);
  1265. int kvm_complete_insn_gp(struct kvm_vcpu *vcpu, int err);
  1266. void __kvm_request_immediate_exit(struct kvm_vcpu *vcpu);
  1267. int kvm_is_in_guest(void);
  1268. int __x86_set_memory_region(struct kvm *kvm, int id, gpa_t gpa, u32 size);
  1269. int x86_set_memory_region(struct kvm *kvm, int id, gpa_t gpa, u32 size);
  1270. bool kvm_vcpu_is_reset_bsp(struct kvm_vcpu *vcpu);
  1271. bool kvm_vcpu_is_bsp(struct kvm_vcpu *vcpu);
  1272. bool kvm_intr_is_single_vcpu(struct kvm *kvm, struct kvm_lapic_irq *irq,
  1273. struct kvm_vcpu **dest_vcpu);
  1274. void kvm_set_msi_irq(struct kvm *kvm, struct kvm_kernel_irq_routing_entry *e,
  1275. struct kvm_lapic_irq *irq);
  1276. static inline void kvm_arch_vcpu_blocking(struct kvm_vcpu *vcpu)
  1277. {
  1278. if (kvm_x86_ops->vcpu_blocking)
  1279. kvm_x86_ops->vcpu_blocking(vcpu);
  1280. }
  1281. static inline void kvm_arch_vcpu_unblocking(struct kvm_vcpu *vcpu)
  1282. {
  1283. if (kvm_x86_ops->vcpu_unblocking)
  1284. kvm_x86_ops->vcpu_unblocking(vcpu);
  1285. }
  1286. static inline void kvm_arch_vcpu_block_finish(struct kvm_vcpu *vcpu) {}
  1287. static inline int kvm_cpu_get_apicid(int mps_cpu)
  1288. {
  1289. #ifdef CONFIG_X86_LOCAL_APIC
  1290. return default_cpu_present_to_apicid(mps_cpu);
  1291. #else
  1292. WARN_ON_ONCE(1);
  1293. return BAD_APICID;
  1294. #endif
  1295. }
  1296. #define put_smstate(type, buf, offset, val) \
  1297. *(type *)((buf) + (offset) - 0x7e00) = val
  1298. #endif /* _ASM_X86_KVM_HOST_H */