kvm_host.h 44 KB

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