Commit 8b415dcd762607379cf0a69c9dd25940da1d174e

Authored by Geoff Levand
Committed by Gleb Natapov
1 parent e3ba45b804

KVM: Move kvm_rebooting declaration out of x86

The variable kvm_rebooting is a common kvm variable, so move its
declaration from arch/x86/include/asm/kvm_host.h to
include/asm/kvm_host.h.

Fixes this sparse warning when building on arm64:

  virt/kvm/kvm_main.c:warning: symbol 'kvm_rebooting' was not declared. Should it be static?

Signed-off-by: Geoff Levand <geoff@infradead.org>
Signed-off-by: Gleb Natapov <gleb@redhat.com>

Showing 2 changed files with 2 additions and 1 deletions Inline Diff

arch/x86/include/asm/kvm_host.h
1 /* 1 /*
2 * Kernel-based Virtual Machine driver for Linux 2 * Kernel-based Virtual Machine driver for Linux
3 * 3 *
4 * This header defines architecture specific interfaces, x86 version 4 * This header defines architecture specific interfaces, x86 version
5 * 5 *
6 * This work is licensed under the terms of the GNU GPL, version 2. See 6 * This work is licensed under the terms of the GNU GPL, version 2. See
7 * the COPYING file in the top-level directory. 7 * the COPYING file in the top-level directory.
8 * 8 *
9 */ 9 */
10 10
11 #ifndef _ASM_X86_KVM_HOST_H 11 #ifndef _ASM_X86_KVM_HOST_H
12 #define _ASM_X86_KVM_HOST_H 12 #define _ASM_X86_KVM_HOST_H
13 13
14 #include <linux/types.h> 14 #include <linux/types.h>
15 #include <linux/mm.h> 15 #include <linux/mm.h>
16 #include <linux/mmu_notifier.h> 16 #include <linux/mmu_notifier.h>
17 #include <linux/tracepoint.h> 17 #include <linux/tracepoint.h>
18 #include <linux/cpumask.h> 18 #include <linux/cpumask.h>
19 #include <linux/irq_work.h> 19 #include <linux/irq_work.h>
20 20
21 #include <linux/kvm.h> 21 #include <linux/kvm.h>
22 #include <linux/kvm_para.h> 22 #include <linux/kvm_para.h>
23 #include <linux/kvm_types.h> 23 #include <linux/kvm_types.h>
24 #include <linux/perf_event.h> 24 #include <linux/perf_event.h>
25 #include <linux/pvclock_gtod.h> 25 #include <linux/pvclock_gtod.h>
26 #include <linux/clocksource.h> 26 #include <linux/clocksource.h>
27 27
28 #include <asm/pvclock-abi.h> 28 #include <asm/pvclock-abi.h>
29 #include <asm/desc.h> 29 #include <asm/desc.h>
30 #include <asm/mtrr.h> 30 #include <asm/mtrr.h>
31 #include <asm/msr-index.h> 31 #include <asm/msr-index.h>
32 #include <asm/asm.h> 32 #include <asm/asm.h>
33 33
34 #define KVM_MAX_VCPUS 254 34 #define KVM_MAX_VCPUS 254
35 #define KVM_SOFT_MAX_VCPUS 160 35 #define KVM_SOFT_MAX_VCPUS 160
36 #define KVM_USER_MEM_SLOTS 125 36 #define KVM_USER_MEM_SLOTS 125
37 /* memory slots that are not exposed to userspace */ 37 /* memory slots that are not exposed to userspace */
38 #define KVM_PRIVATE_MEM_SLOTS 3 38 #define KVM_PRIVATE_MEM_SLOTS 3
39 #define KVM_MEM_SLOTS_NUM (KVM_USER_MEM_SLOTS + KVM_PRIVATE_MEM_SLOTS) 39 #define KVM_MEM_SLOTS_NUM (KVM_USER_MEM_SLOTS + KVM_PRIVATE_MEM_SLOTS)
40 40
41 #define KVM_MMIO_SIZE 16 41 #define KVM_MMIO_SIZE 16
42 42
43 #define KVM_PIO_PAGE_OFFSET 1 43 #define KVM_PIO_PAGE_OFFSET 1
44 #define KVM_COALESCED_MMIO_PAGE_OFFSET 2 44 #define KVM_COALESCED_MMIO_PAGE_OFFSET 2
45 45
46 #define CR0_RESERVED_BITS \ 46 #define CR0_RESERVED_BITS \
47 (~(unsigned long)(X86_CR0_PE | X86_CR0_MP | X86_CR0_EM | X86_CR0_TS \ 47 (~(unsigned long)(X86_CR0_PE | X86_CR0_MP | X86_CR0_EM | X86_CR0_TS \
48 | X86_CR0_ET | X86_CR0_NE | X86_CR0_WP | X86_CR0_AM \ 48 | X86_CR0_ET | X86_CR0_NE | X86_CR0_WP | X86_CR0_AM \
49 | X86_CR0_NW | X86_CR0_CD | X86_CR0_PG)) 49 | X86_CR0_NW | X86_CR0_CD | X86_CR0_PG))
50 50
51 #define CR3_PAE_RESERVED_BITS ((X86_CR3_PWT | X86_CR3_PCD) - 1) 51 #define CR3_PAE_RESERVED_BITS ((X86_CR3_PWT | X86_CR3_PCD) - 1)
52 #define CR3_NONPAE_RESERVED_BITS ((PAGE_SIZE-1) & ~(X86_CR3_PWT | X86_CR3_PCD)) 52 #define CR3_NONPAE_RESERVED_BITS ((PAGE_SIZE-1) & ~(X86_CR3_PWT | X86_CR3_PCD))
53 #define CR3_PCID_ENABLED_RESERVED_BITS 0xFFFFFF0000000000ULL 53 #define CR3_PCID_ENABLED_RESERVED_BITS 0xFFFFFF0000000000ULL
54 #define CR3_L_MODE_RESERVED_BITS (CR3_NONPAE_RESERVED_BITS | \ 54 #define CR3_L_MODE_RESERVED_BITS (CR3_NONPAE_RESERVED_BITS | \
55 0xFFFFFF0000000000ULL) 55 0xFFFFFF0000000000ULL)
56 #define CR4_RESERVED_BITS \ 56 #define CR4_RESERVED_BITS \
57 (~(unsigned long)(X86_CR4_VME | X86_CR4_PVI | X86_CR4_TSD | X86_CR4_DE\ 57 (~(unsigned long)(X86_CR4_VME | X86_CR4_PVI | X86_CR4_TSD | X86_CR4_DE\
58 | X86_CR4_PSE | X86_CR4_PAE | X86_CR4_MCE \ 58 | X86_CR4_PSE | X86_CR4_PAE | X86_CR4_MCE \
59 | X86_CR4_PGE | X86_CR4_PCE | X86_CR4_OSFXSR | X86_CR4_PCIDE \ 59 | X86_CR4_PGE | X86_CR4_PCE | X86_CR4_OSFXSR | X86_CR4_PCIDE \
60 | X86_CR4_OSXSAVE | X86_CR4_SMEP | X86_CR4_RDWRGSFS \ 60 | X86_CR4_OSXSAVE | X86_CR4_SMEP | X86_CR4_RDWRGSFS \
61 | X86_CR4_OSXMMEXCPT | X86_CR4_VMXE)) 61 | X86_CR4_OSXMMEXCPT | X86_CR4_VMXE))
62 62
63 #define CR8_RESERVED_BITS (~(unsigned long)X86_CR8_TPR) 63 #define CR8_RESERVED_BITS (~(unsigned long)X86_CR8_TPR)
64 64
65 65
66 66
67 #define INVALID_PAGE (~(hpa_t)0) 67 #define INVALID_PAGE (~(hpa_t)0)
68 #define VALID_PAGE(x) ((x) != INVALID_PAGE) 68 #define VALID_PAGE(x) ((x) != INVALID_PAGE)
69 69
70 #define UNMAPPED_GVA (~(gpa_t)0) 70 #define UNMAPPED_GVA (~(gpa_t)0)
71 71
72 /* KVM Hugepage definitions for x86 */ 72 /* KVM Hugepage definitions for x86 */
73 #define KVM_NR_PAGE_SIZES 3 73 #define KVM_NR_PAGE_SIZES 3
74 #define KVM_HPAGE_GFN_SHIFT(x) (((x) - 1) * 9) 74 #define KVM_HPAGE_GFN_SHIFT(x) (((x) - 1) * 9)
75 #define KVM_HPAGE_SHIFT(x) (PAGE_SHIFT + KVM_HPAGE_GFN_SHIFT(x)) 75 #define KVM_HPAGE_SHIFT(x) (PAGE_SHIFT + KVM_HPAGE_GFN_SHIFT(x))
76 #define KVM_HPAGE_SIZE(x) (1UL << KVM_HPAGE_SHIFT(x)) 76 #define KVM_HPAGE_SIZE(x) (1UL << KVM_HPAGE_SHIFT(x))
77 #define KVM_HPAGE_MASK(x) (~(KVM_HPAGE_SIZE(x) - 1)) 77 #define KVM_HPAGE_MASK(x) (~(KVM_HPAGE_SIZE(x) - 1))
78 #define KVM_PAGES_PER_HPAGE(x) (KVM_HPAGE_SIZE(x) / PAGE_SIZE) 78 #define KVM_PAGES_PER_HPAGE(x) (KVM_HPAGE_SIZE(x) / PAGE_SIZE)
79 79
80 #define SELECTOR_TI_MASK (1 << 2) 80 #define SELECTOR_TI_MASK (1 << 2)
81 #define SELECTOR_RPL_MASK 0x03 81 #define SELECTOR_RPL_MASK 0x03
82 82
83 #define IOPL_SHIFT 12 83 #define IOPL_SHIFT 12
84 84
85 #define KVM_PERMILLE_MMU_PAGES 20 85 #define KVM_PERMILLE_MMU_PAGES 20
86 #define KVM_MIN_ALLOC_MMU_PAGES 64 86 #define KVM_MIN_ALLOC_MMU_PAGES 64
87 #define KVM_MMU_HASH_SHIFT 10 87 #define KVM_MMU_HASH_SHIFT 10
88 #define KVM_NUM_MMU_PAGES (1 << KVM_MMU_HASH_SHIFT) 88 #define KVM_NUM_MMU_PAGES (1 << KVM_MMU_HASH_SHIFT)
89 #define KVM_MIN_FREE_MMU_PAGES 5 89 #define KVM_MIN_FREE_MMU_PAGES 5
90 #define KVM_REFILL_PAGES 25 90 #define KVM_REFILL_PAGES 25
91 #define KVM_MAX_CPUID_ENTRIES 80 91 #define KVM_MAX_CPUID_ENTRIES 80
92 #define KVM_NR_FIXED_MTRR_REGION 88 92 #define KVM_NR_FIXED_MTRR_REGION 88
93 #define KVM_NR_VAR_MTRR 8 93 #define KVM_NR_VAR_MTRR 8
94 94
95 #define ASYNC_PF_PER_VCPU 64 95 #define ASYNC_PF_PER_VCPU 64
96 96
97 struct kvm_vcpu; 97 struct kvm_vcpu;
98 struct kvm; 98 struct kvm;
99 struct kvm_async_pf; 99 struct kvm_async_pf;
100 100
101 enum kvm_reg { 101 enum kvm_reg {
102 VCPU_REGS_RAX = 0, 102 VCPU_REGS_RAX = 0,
103 VCPU_REGS_RCX = 1, 103 VCPU_REGS_RCX = 1,
104 VCPU_REGS_RDX = 2, 104 VCPU_REGS_RDX = 2,
105 VCPU_REGS_RBX = 3, 105 VCPU_REGS_RBX = 3,
106 VCPU_REGS_RSP = 4, 106 VCPU_REGS_RSP = 4,
107 VCPU_REGS_RBP = 5, 107 VCPU_REGS_RBP = 5,
108 VCPU_REGS_RSI = 6, 108 VCPU_REGS_RSI = 6,
109 VCPU_REGS_RDI = 7, 109 VCPU_REGS_RDI = 7,
110 #ifdef CONFIG_X86_64 110 #ifdef CONFIG_X86_64
111 VCPU_REGS_R8 = 8, 111 VCPU_REGS_R8 = 8,
112 VCPU_REGS_R9 = 9, 112 VCPU_REGS_R9 = 9,
113 VCPU_REGS_R10 = 10, 113 VCPU_REGS_R10 = 10,
114 VCPU_REGS_R11 = 11, 114 VCPU_REGS_R11 = 11,
115 VCPU_REGS_R12 = 12, 115 VCPU_REGS_R12 = 12,
116 VCPU_REGS_R13 = 13, 116 VCPU_REGS_R13 = 13,
117 VCPU_REGS_R14 = 14, 117 VCPU_REGS_R14 = 14,
118 VCPU_REGS_R15 = 15, 118 VCPU_REGS_R15 = 15,
119 #endif 119 #endif
120 VCPU_REGS_RIP, 120 VCPU_REGS_RIP,
121 NR_VCPU_REGS 121 NR_VCPU_REGS
122 }; 122 };
123 123
124 enum kvm_reg_ex { 124 enum kvm_reg_ex {
125 VCPU_EXREG_PDPTR = NR_VCPU_REGS, 125 VCPU_EXREG_PDPTR = NR_VCPU_REGS,
126 VCPU_EXREG_CR3, 126 VCPU_EXREG_CR3,
127 VCPU_EXREG_RFLAGS, 127 VCPU_EXREG_RFLAGS,
128 VCPU_EXREG_CPL, 128 VCPU_EXREG_CPL,
129 VCPU_EXREG_SEGMENTS, 129 VCPU_EXREG_SEGMENTS,
130 }; 130 };
131 131
132 enum { 132 enum {
133 VCPU_SREG_ES, 133 VCPU_SREG_ES,
134 VCPU_SREG_CS, 134 VCPU_SREG_CS,
135 VCPU_SREG_SS, 135 VCPU_SREG_SS,
136 VCPU_SREG_DS, 136 VCPU_SREG_DS,
137 VCPU_SREG_FS, 137 VCPU_SREG_FS,
138 VCPU_SREG_GS, 138 VCPU_SREG_GS,
139 VCPU_SREG_TR, 139 VCPU_SREG_TR,
140 VCPU_SREG_LDTR, 140 VCPU_SREG_LDTR,
141 }; 141 };
142 142
143 #include <asm/kvm_emulate.h> 143 #include <asm/kvm_emulate.h>
144 144
145 #define KVM_NR_MEM_OBJS 40 145 #define KVM_NR_MEM_OBJS 40
146 146
147 #define KVM_NR_DB_REGS 4 147 #define KVM_NR_DB_REGS 4
148 148
149 #define DR6_BD (1 << 13) 149 #define DR6_BD (1 << 13)
150 #define DR6_BS (1 << 14) 150 #define DR6_BS (1 << 14)
151 #define DR6_FIXED_1 0xffff0ff0 151 #define DR6_FIXED_1 0xffff0ff0
152 #define DR6_VOLATILE 0x0000e00f 152 #define DR6_VOLATILE 0x0000e00f
153 153
154 #define DR7_BP_EN_MASK 0x000000ff 154 #define DR7_BP_EN_MASK 0x000000ff
155 #define DR7_GE (1 << 9) 155 #define DR7_GE (1 << 9)
156 #define DR7_GD (1 << 13) 156 #define DR7_GD (1 << 13)
157 #define DR7_FIXED_1 0x00000400 157 #define DR7_FIXED_1 0x00000400
158 #define DR7_VOLATILE 0xffff23ff 158 #define DR7_VOLATILE 0xffff23ff
159 159
160 /* apic attention bits */ 160 /* apic attention bits */
161 #define KVM_APIC_CHECK_VAPIC 0 161 #define KVM_APIC_CHECK_VAPIC 0
162 /* 162 /*
163 * The following bit is set with PV-EOI, unset on EOI. 163 * The following bit is set with PV-EOI, unset on EOI.
164 * We detect PV-EOI changes by guest by comparing 164 * We detect PV-EOI changes by guest by comparing
165 * this bit with PV-EOI in guest memory. 165 * this bit with PV-EOI in guest memory.
166 * See the implementation in apic_update_pv_eoi. 166 * See the implementation in apic_update_pv_eoi.
167 */ 167 */
168 #define KVM_APIC_PV_EOI_PENDING 1 168 #define KVM_APIC_PV_EOI_PENDING 1
169 169
170 /* 170 /*
171 * We don't want allocation failures within the mmu code, so we preallocate 171 * We don't want allocation failures within the mmu code, so we preallocate
172 * enough memory for a single page fault in a cache. 172 * enough memory for a single page fault in a cache.
173 */ 173 */
174 struct kvm_mmu_memory_cache { 174 struct kvm_mmu_memory_cache {
175 int nobjs; 175 int nobjs;
176 void *objects[KVM_NR_MEM_OBJS]; 176 void *objects[KVM_NR_MEM_OBJS];
177 }; 177 };
178 178
179 /* 179 /*
180 * kvm_mmu_page_role, below, is defined as: 180 * kvm_mmu_page_role, below, is defined as:
181 * 181 *
182 * bits 0:3 - total guest paging levels (2-4, or zero for real mode) 182 * bits 0:3 - total guest paging levels (2-4, or zero for real mode)
183 * bits 4:7 - page table level for this shadow (1-4) 183 * bits 4:7 - page table level for this shadow (1-4)
184 * bits 8:9 - page table quadrant for 2-level guests 184 * bits 8:9 - page table quadrant for 2-level guests
185 * bit 16 - direct mapping of virtual to physical mapping at gfn 185 * bit 16 - direct mapping of virtual to physical mapping at gfn
186 * used for real mode and two-dimensional paging 186 * used for real mode and two-dimensional paging
187 * bits 17:19 - common access permissions for all ptes in this shadow page 187 * bits 17:19 - common access permissions for all ptes in this shadow page
188 */ 188 */
189 union kvm_mmu_page_role { 189 union kvm_mmu_page_role {
190 unsigned word; 190 unsigned word;
191 struct { 191 struct {
192 unsigned level:4; 192 unsigned level:4;
193 unsigned cr4_pae:1; 193 unsigned cr4_pae:1;
194 unsigned quadrant:2; 194 unsigned quadrant:2;
195 unsigned pad_for_nice_hex_output:6; 195 unsigned pad_for_nice_hex_output:6;
196 unsigned direct:1; 196 unsigned direct:1;
197 unsigned access:3; 197 unsigned access:3;
198 unsigned invalid:1; 198 unsigned invalid:1;
199 unsigned nxe:1; 199 unsigned nxe:1;
200 unsigned cr0_wp:1; 200 unsigned cr0_wp:1;
201 unsigned smep_andnot_wp:1; 201 unsigned smep_andnot_wp:1;
202 }; 202 };
203 }; 203 };
204 204
205 struct kvm_mmu_page { 205 struct kvm_mmu_page {
206 struct list_head link; 206 struct list_head link;
207 struct hlist_node hash_link; 207 struct hlist_node hash_link;
208 208
209 /* 209 /*
210 * The following two entries are used to key the shadow page in the 210 * The following two entries are used to key the shadow page in the
211 * hash table. 211 * hash table.
212 */ 212 */
213 gfn_t gfn; 213 gfn_t gfn;
214 union kvm_mmu_page_role role; 214 union kvm_mmu_page_role role;
215 215
216 u64 *spt; 216 u64 *spt;
217 /* hold the gfn of each spte inside spt */ 217 /* hold the gfn of each spte inside spt */
218 gfn_t *gfns; 218 gfn_t *gfns;
219 bool unsync; 219 bool unsync;
220 int root_count; /* Currently serving as active root */ 220 int root_count; /* Currently serving as active root */
221 unsigned int unsync_children; 221 unsigned int unsync_children;
222 unsigned long parent_ptes; /* Reverse mapping for parent_pte */ 222 unsigned long parent_ptes; /* Reverse mapping for parent_pte */
223 DECLARE_BITMAP(unsync_child_bitmap, 512); 223 DECLARE_BITMAP(unsync_child_bitmap, 512);
224 224
225 #ifdef CONFIG_X86_32 225 #ifdef CONFIG_X86_32
226 int clear_spte_count; 226 int clear_spte_count;
227 #endif 227 #endif
228 228
229 int write_flooding_count; 229 int write_flooding_count;
230 bool mmio_cached; 230 bool mmio_cached;
231 }; 231 };
232 232
233 struct kvm_pio_request { 233 struct kvm_pio_request {
234 unsigned long count; 234 unsigned long count;
235 int in; 235 int in;
236 int port; 236 int port;
237 int size; 237 int size;
238 }; 238 };
239 239
240 /* 240 /*
241 * x86 supports 3 paging modes (4-level 64-bit, 3-level 64-bit, and 2-level 241 * x86 supports 3 paging modes (4-level 64-bit, 3-level 64-bit, and 2-level
242 * 32-bit). The kvm_mmu structure abstracts the details of the current mmu 242 * 32-bit). The kvm_mmu structure abstracts the details of the current mmu
243 * mode. 243 * mode.
244 */ 244 */
245 struct kvm_mmu { 245 struct kvm_mmu {
246 void (*new_cr3)(struct kvm_vcpu *vcpu); 246 void (*new_cr3)(struct kvm_vcpu *vcpu);
247 void (*set_cr3)(struct kvm_vcpu *vcpu, unsigned long root); 247 void (*set_cr3)(struct kvm_vcpu *vcpu, unsigned long root);
248 unsigned long (*get_cr3)(struct kvm_vcpu *vcpu); 248 unsigned long (*get_cr3)(struct kvm_vcpu *vcpu);
249 u64 (*get_pdptr)(struct kvm_vcpu *vcpu, int index); 249 u64 (*get_pdptr)(struct kvm_vcpu *vcpu, int index);
250 int (*page_fault)(struct kvm_vcpu *vcpu, gva_t gva, u32 err, 250 int (*page_fault)(struct kvm_vcpu *vcpu, gva_t gva, u32 err,
251 bool prefault); 251 bool prefault);
252 void (*inject_page_fault)(struct kvm_vcpu *vcpu, 252 void (*inject_page_fault)(struct kvm_vcpu *vcpu,
253 struct x86_exception *fault); 253 struct x86_exception *fault);
254 void (*free)(struct kvm_vcpu *vcpu); 254 void (*free)(struct kvm_vcpu *vcpu);
255 gpa_t (*gva_to_gpa)(struct kvm_vcpu *vcpu, gva_t gva, u32 access, 255 gpa_t (*gva_to_gpa)(struct kvm_vcpu *vcpu, gva_t gva, u32 access,
256 struct x86_exception *exception); 256 struct x86_exception *exception);
257 gpa_t (*translate_gpa)(struct kvm_vcpu *vcpu, gpa_t gpa, u32 access); 257 gpa_t (*translate_gpa)(struct kvm_vcpu *vcpu, gpa_t gpa, u32 access);
258 int (*sync_page)(struct kvm_vcpu *vcpu, 258 int (*sync_page)(struct kvm_vcpu *vcpu,
259 struct kvm_mmu_page *sp); 259 struct kvm_mmu_page *sp);
260 void (*invlpg)(struct kvm_vcpu *vcpu, gva_t gva); 260 void (*invlpg)(struct kvm_vcpu *vcpu, gva_t gva);
261 void (*update_pte)(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp, 261 void (*update_pte)(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp,
262 u64 *spte, const void *pte); 262 u64 *spte, const void *pte);
263 hpa_t root_hpa; 263 hpa_t root_hpa;
264 int root_level; 264 int root_level;
265 int shadow_root_level; 265 int shadow_root_level;
266 union kvm_mmu_page_role base_role; 266 union kvm_mmu_page_role base_role;
267 bool direct_map; 267 bool direct_map;
268 268
269 /* 269 /*
270 * Bitmap; bit set = permission fault 270 * Bitmap; bit set = permission fault
271 * Byte index: page fault error code [4:1] 271 * Byte index: page fault error code [4:1]
272 * Bit index: pte permissions in ACC_* format 272 * Bit index: pte permissions in ACC_* format
273 */ 273 */
274 u8 permissions[16]; 274 u8 permissions[16];
275 275
276 u64 *pae_root; 276 u64 *pae_root;
277 u64 *lm_root; 277 u64 *lm_root;
278 u64 rsvd_bits_mask[2][4]; 278 u64 rsvd_bits_mask[2][4];
279 279
280 /* 280 /*
281 * Bitmap: bit set = last pte in walk 281 * Bitmap: bit set = last pte in walk
282 * index[0:1]: level (zero-based) 282 * index[0:1]: level (zero-based)
283 * index[2]: pte.ps 283 * index[2]: pte.ps
284 */ 284 */
285 u8 last_pte_bitmap; 285 u8 last_pte_bitmap;
286 286
287 bool nx; 287 bool nx;
288 288
289 u64 pdptrs[4]; /* pae */ 289 u64 pdptrs[4]; /* pae */
290 }; 290 };
291 291
292 enum pmc_type { 292 enum pmc_type {
293 KVM_PMC_GP = 0, 293 KVM_PMC_GP = 0,
294 KVM_PMC_FIXED, 294 KVM_PMC_FIXED,
295 }; 295 };
296 296
297 struct kvm_pmc { 297 struct kvm_pmc {
298 enum pmc_type type; 298 enum pmc_type type;
299 u8 idx; 299 u8 idx;
300 u64 counter; 300 u64 counter;
301 u64 eventsel; 301 u64 eventsel;
302 struct perf_event *perf_event; 302 struct perf_event *perf_event;
303 struct kvm_vcpu *vcpu; 303 struct kvm_vcpu *vcpu;
304 }; 304 };
305 305
306 struct kvm_pmu { 306 struct kvm_pmu {
307 unsigned nr_arch_gp_counters; 307 unsigned nr_arch_gp_counters;
308 unsigned nr_arch_fixed_counters; 308 unsigned nr_arch_fixed_counters;
309 unsigned available_event_types; 309 unsigned available_event_types;
310 u64 fixed_ctr_ctrl; 310 u64 fixed_ctr_ctrl;
311 u64 global_ctrl; 311 u64 global_ctrl;
312 u64 global_status; 312 u64 global_status;
313 u64 global_ovf_ctrl; 313 u64 global_ovf_ctrl;
314 u64 counter_bitmask[2]; 314 u64 counter_bitmask[2];
315 u64 global_ctrl_mask; 315 u64 global_ctrl_mask;
316 u8 version; 316 u8 version;
317 struct kvm_pmc gp_counters[INTEL_PMC_MAX_GENERIC]; 317 struct kvm_pmc gp_counters[INTEL_PMC_MAX_GENERIC];
318 struct kvm_pmc fixed_counters[INTEL_PMC_MAX_FIXED]; 318 struct kvm_pmc fixed_counters[INTEL_PMC_MAX_FIXED];
319 struct irq_work irq_work; 319 struct irq_work irq_work;
320 u64 reprogram_pmi; 320 u64 reprogram_pmi;
321 }; 321 };
322 322
323 struct kvm_vcpu_arch { 323 struct kvm_vcpu_arch {
324 /* 324 /*
325 * rip and regs accesses must go through 325 * rip and regs accesses must go through
326 * kvm_{register,rip}_{read,write} functions. 326 * kvm_{register,rip}_{read,write} functions.
327 */ 327 */
328 unsigned long regs[NR_VCPU_REGS]; 328 unsigned long regs[NR_VCPU_REGS];
329 u32 regs_avail; 329 u32 regs_avail;
330 u32 regs_dirty; 330 u32 regs_dirty;
331 331
332 unsigned long cr0; 332 unsigned long cr0;
333 unsigned long cr0_guest_owned_bits; 333 unsigned long cr0_guest_owned_bits;
334 unsigned long cr2; 334 unsigned long cr2;
335 unsigned long cr3; 335 unsigned long cr3;
336 unsigned long cr4; 336 unsigned long cr4;
337 unsigned long cr4_guest_owned_bits; 337 unsigned long cr4_guest_owned_bits;
338 unsigned long cr8; 338 unsigned long cr8;
339 u32 hflags; 339 u32 hflags;
340 u64 efer; 340 u64 efer;
341 u64 apic_base; 341 u64 apic_base;
342 struct kvm_lapic *apic; /* kernel irqchip context */ 342 struct kvm_lapic *apic; /* kernel irqchip context */
343 unsigned long apic_attention; 343 unsigned long apic_attention;
344 int32_t apic_arb_prio; 344 int32_t apic_arb_prio;
345 int mp_state; 345 int mp_state;
346 u64 ia32_misc_enable_msr; 346 u64 ia32_misc_enable_msr;
347 bool tpr_access_reporting; 347 bool tpr_access_reporting;
348 348
349 /* 349 /*
350 * Paging state of the vcpu 350 * Paging state of the vcpu
351 * 351 *
352 * If the vcpu runs in guest mode with two level paging this still saves 352 * If the vcpu runs in guest mode with two level paging this still saves
353 * the paging mode of the l1 guest. This context is always used to 353 * the paging mode of the l1 guest. This context is always used to
354 * handle faults. 354 * handle faults.
355 */ 355 */
356 struct kvm_mmu mmu; 356 struct kvm_mmu mmu;
357 357
358 /* 358 /*
359 * Paging state of an L2 guest (used for nested npt) 359 * Paging state of an L2 guest (used for nested npt)
360 * 360 *
361 * This context will save all necessary information to walk page tables 361 * This context will save all necessary information to walk page tables
362 * of the an L2 guest. This context is only initialized for page table 362 * of the an L2 guest. This context is only initialized for page table
363 * walking and not for faulting since we never handle l2 page faults on 363 * walking and not for faulting since we never handle l2 page faults on
364 * the host. 364 * the host.
365 */ 365 */
366 struct kvm_mmu nested_mmu; 366 struct kvm_mmu nested_mmu;
367 367
368 /* 368 /*
369 * Pointer to the mmu context currently used for 369 * Pointer to the mmu context currently used for
370 * gva_to_gpa translations. 370 * gva_to_gpa translations.
371 */ 371 */
372 struct kvm_mmu *walk_mmu; 372 struct kvm_mmu *walk_mmu;
373 373
374 struct kvm_mmu_memory_cache mmu_pte_list_desc_cache; 374 struct kvm_mmu_memory_cache mmu_pte_list_desc_cache;
375 struct kvm_mmu_memory_cache mmu_page_cache; 375 struct kvm_mmu_memory_cache mmu_page_cache;
376 struct kvm_mmu_memory_cache mmu_page_header_cache; 376 struct kvm_mmu_memory_cache mmu_page_header_cache;
377 377
378 struct fpu guest_fpu; 378 struct fpu guest_fpu;
379 u64 xcr0; 379 u64 xcr0;
380 380
381 struct kvm_pio_request pio; 381 struct kvm_pio_request pio;
382 void *pio_data; 382 void *pio_data;
383 383
384 u8 event_exit_inst_len; 384 u8 event_exit_inst_len;
385 385
386 struct kvm_queued_exception { 386 struct kvm_queued_exception {
387 bool pending; 387 bool pending;
388 bool has_error_code; 388 bool has_error_code;
389 bool reinject; 389 bool reinject;
390 u8 nr; 390 u8 nr;
391 u32 error_code; 391 u32 error_code;
392 } exception; 392 } exception;
393 393
394 struct kvm_queued_interrupt { 394 struct kvm_queued_interrupt {
395 bool pending; 395 bool pending;
396 bool soft; 396 bool soft;
397 u8 nr; 397 u8 nr;
398 } interrupt; 398 } interrupt;
399 399
400 int halt_request; /* real mode on Intel only */ 400 int halt_request; /* real mode on Intel only */
401 401
402 int cpuid_nent; 402 int cpuid_nent;
403 struct kvm_cpuid_entry2 cpuid_entries[KVM_MAX_CPUID_ENTRIES]; 403 struct kvm_cpuid_entry2 cpuid_entries[KVM_MAX_CPUID_ENTRIES];
404 /* emulate context */ 404 /* emulate context */
405 405
406 struct x86_emulate_ctxt emulate_ctxt; 406 struct x86_emulate_ctxt emulate_ctxt;
407 bool emulate_regs_need_sync_to_vcpu; 407 bool emulate_regs_need_sync_to_vcpu;
408 bool emulate_regs_need_sync_from_vcpu; 408 bool emulate_regs_need_sync_from_vcpu;
409 int (*complete_userspace_io)(struct kvm_vcpu *vcpu); 409 int (*complete_userspace_io)(struct kvm_vcpu *vcpu);
410 410
411 gpa_t time; 411 gpa_t time;
412 struct pvclock_vcpu_time_info hv_clock; 412 struct pvclock_vcpu_time_info hv_clock;
413 unsigned int hw_tsc_khz; 413 unsigned int hw_tsc_khz;
414 struct gfn_to_hva_cache pv_time; 414 struct gfn_to_hva_cache pv_time;
415 bool pv_time_enabled; 415 bool pv_time_enabled;
416 /* set guest stopped flag in pvclock flags field */ 416 /* set guest stopped flag in pvclock flags field */
417 bool pvclock_set_guest_stopped_request; 417 bool pvclock_set_guest_stopped_request;
418 418
419 struct { 419 struct {
420 u64 msr_val; 420 u64 msr_val;
421 u64 last_steal; 421 u64 last_steal;
422 u64 accum_steal; 422 u64 accum_steal;
423 struct gfn_to_hva_cache stime; 423 struct gfn_to_hva_cache stime;
424 struct kvm_steal_time steal; 424 struct kvm_steal_time steal;
425 } st; 425 } st;
426 426
427 u64 last_guest_tsc; 427 u64 last_guest_tsc;
428 u64 last_kernel_ns; 428 u64 last_kernel_ns;
429 u64 last_host_tsc; 429 u64 last_host_tsc;
430 u64 tsc_offset_adjustment; 430 u64 tsc_offset_adjustment;
431 u64 this_tsc_nsec; 431 u64 this_tsc_nsec;
432 u64 this_tsc_write; 432 u64 this_tsc_write;
433 u8 this_tsc_generation; 433 u8 this_tsc_generation;
434 bool tsc_catchup; 434 bool tsc_catchup;
435 bool tsc_always_catchup; 435 bool tsc_always_catchup;
436 s8 virtual_tsc_shift; 436 s8 virtual_tsc_shift;
437 u32 virtual_tsc_mult; 437 u32 virtual_tsc_mult;
438 u32 virtual_tsc_khz; 438 u32 virtual_tsc_khz;
439 s64 ia32_tsc_adjust_msr; 439 s64 ia32_tsc_adjust_msr;
440 440
441 atomic_t nmi_queued; /* unprocessed asynchronous NMIs */ 441 atomic_t nmi_queued; /* unprocessed asynchronous NMIs */
442 unsigned nmi_pending; /* NMI queued after currently running handler */ 442 unsigned nmi_pending; /* NMI queued after currently running handler */
443 bool nmi_injected; /* Trying to inject an NMI this entry */ 443 bool nmi_injected; /* Trying to inject an NMI this entry */
444 444
445 struct mtrr_state_type mtrr_state; 445 struct mtrr_state_type mtrr_state;
446 u32 pat; 446 u32 pat;
447 447
448 int switch_db_regs; 448 int switch_db_regs;
449 unsigned long db[KVM_NR_DB_REGS]; 449 unsigned long db[KVM_NR_DB_REGS];
450 unsigned long dr6; 450 unsigned long dr6;
451 unsigned long dr7; 451 unsigned long dr7;
452 unsigned long eff_db[KVM_NR_DB_REGS]; 452 unsigned long eff_db[KVM_NR_DB_REGS];
453 unsigned long guest_debug_dr7; 453 unsigned long guest_debug_dr7;
454 454
455 u64 mcg_cap; 455 u64 mcg_cap;
456 u64 mcg_status; 456 u64 mcg_status;
457 u64 mcg_ctl; 457 u64 mcg_ctl;
458 u64 *mce_banks; 458 u64 *mce_banks;
459 459
460 /* Cache MMIO info */ 460 /* Cache MMIO info */
461 u64 mmio_gva; 461 u64 mmio_gva;
462 unsigned access; 462 unsigned access;
463 gfn_t mmio_gfn; 463 gfn_t mmio_gfn;
464 464
465 struct kvm_pmu pmu; 465 struct kvm_pmu pmu;
466 466
467 /* used for guest single stepping over the given code position */ 467 /* used for guest single stepping over the given code position */
468 unsigned long singlestep_rip; 468 unsigned long singlestep_rip;
469 469
470 /* fields used by HYPER-V emulation */ 470 /* fields used by HYPER-V emulation */
471 u64 hv_vapic; 471 u64 hv_vapic;
472 472
473 cpumask_var_t wbinvd_dirty_mask; 473 cpumask_var_t wbinvd_dirty_mask;
474 474
475 unsigned long last_retry_eip; 475 unsigned long last_retry_eip;
476 unsigned long last_retry_addr; 476 unsigned long last_retry_addr;
477 477
478 struct { 478 struct {
479 bool halted; 479 bool halted;
480 gfn_t gfns[roundup_pow_of_two(ASYNC_PF_PER_VCPU)]; 480 gfn_t gfns[roundup_pow_of_two(ASYNC_PF_PER_VCPU)];
481 struct gfn_to_hva_cache data; 481 struct gfn_to_hva_cache data;
482 u64 msr_val; 482 u64 msr_val;
483 u32 id; 483 u32 id;
484 bool send_user_only; 484 bool send_user_only;
485 } apf; 485 } apf;
486 486
487 /* OSVW MSRs (AMD only) */ 487 /* OSVW MSRs (AMD only) */
488 struct { 488 struct {
489 u64 length; 489 u64 length;
490 u64 status; 490 u64 status;
491 } osvw; 491 } osvw;
492 492
493 struct { 493 struct {
494 u64 msr_val; 494 u64 msr_val;
495 struct gfn_to_hva_cache data; 495 struct gfn_to_hva_cache data;
496 } pv_eoi; 496 } pv_eoi;
497 497
498 /* 498 /*
499 * Indicate whether the access faults on its page table in guest 499 * Indicate whether the access faults on its page table in guest
500 * which is set when fix page fault and used to detect unhandeable 500 * which is set when fix page fault and used to detect unhandeable
501 * instruction. 501 * instruction.
502 */ 502 */
503 bool write_fault_to_shadow_pgtable; 503 bool write_fault_to_shadow_pgtable;
504 }; 504 };
505 505
506 struct kvm_lpage_info { 506 struct kvm_lpage_info {
507 int write_count; 507 int write_count;
508 }; 508 };
509 509
510 struct kvm_arch_memory_slot { 510 struct kvm_arch_memory_slot {
511 unsigned long *rmap[KVM_NR_PAGE_SIZES]; 511 unsigned long *rmap[KVM_NR_PAGE_SIZES];
512 struct kvm_lpage_info *lpage_info[KVM_NR_PAGE_SIZES - 1]; 512 struct kvm_lpage_info *lpage_info[KVM_NR_PAGE_SIZES - 1];
513 }; 513 };
514 514
515 struct kvm_apic_map { 515 struct kvm_apic_map {
516 struct rcu_head rcu; 516 struct rcu_head rcu;
517 u8 ldr_bits; 517 u8 ldr_bits;
518 /* fields bellow are used to decode ldr values in different modes */ 518 /* fields bellow are used to decode ldr values in different modes */
519 u32 cid_shift, cid_mask, lid_mask; 519 u32 cid_shift, cid_mask, lid_mask;
520 struct kvm_lapic *phys_map[256]; 520 struct kvm_lapic *phys_map[256];
521 /* first index is cluster id second is cpu id in a cluster */ 521 /* first index is cluster id second is cpu id in a cluster */
522 struct kvm_lapic *logical_map[16][16]; 522 struct kvm_lapic *logical_map[16][16];
523 }; 523 };
524 524
525 struct kvm_arch { 525 struct kvm_arch {
526 unsigned int n_used_mmu_pages; 526 unsigned int n_used_mmu_pages;
527 unsigned int n_requested_mmu_pages; 527 unsigned int n_requested_mmu_pages;
528 unsigned int n_max_mmu_pages; 528 unsigned int n_max_mmu_pages;
529 unsigned int indirect_shadow_pages; 529 unsigned int indirect_shadow_pages;
530 struct hlist_head mmu_page_hash[KVM_NUM_MMU_PAGES]; 530 struct hlist_head mmu_page_hash[KVM_NUM_MMU_PAGES];
531 /* 531 /*
532 * Hash table of struct kvm_mmu_page. 532 * Hash table of struct kvm_mmu_page.
533 */ 533 */
534 struct list_head active_mmu_pages; 534 struct list_head active_mmu_pages;
535 struct list_head assigned_dev_head; 535 struct list_head assigned_dev_head;
536 struct iommu_domain *iommu_domain; 536 struct iommu_domain *iommu_domain;
537 int iommu_flags; 537 int iommu_flags;
538 struct kvm_pic *vpic; 538 struct kvm_pic *vpic;
539 struct kvm_ioapic *vioapic; 539 struct kvm_ioapic *vioapic;
540 struct kvm_pit *vpit; 540 struct kvm_pit *vpit;
541 int vapics_in_nmi_mode; 541 int vapics_in_nmi_mode;
542 struct mutex apic_map_lock; 542 struct mutex apic_map_lock;
543 struct kvm_apic_map *apic_map; 543 struct kvm_apic_map *apic_map;
544 544
545 unsigned int tss_addr; 545 unsigned int tss_addr;
546 struct page *apic_access_page; 546 struct page *apic_access_page;
547 547
548 gpa_t wall_clock; 548 gpa_t wall_clock;
549 549
550 struct page *ept_identity_pagetable; 550 struct page *ept_identity_pagetable;
551 bool ept_identity_pagetable_done; 551 bool ept_identity_pagetable_done;
552 gpa_t ept_identity_map_addr; 552 gpa_t ept_identity_map_addr;
553 553
554 unsigned long irq_sources_bitmap; 554 unsigned long irq_sources_bitmap;
555 s64 kvmclock_offset; 555 s64 kvmclock_offset;
556 raw_spinlock_t tsc_write_lock; 556 raw_spinlock_t tsc_write_lock;
557 u64 last_tsc_nsec; 557 u64 last_tsc_nsec;
558 u64 last_tsc_write; 558 u64 last_tsc_write;
559 u32 last_tsc_khz; 559 u32 last_tsc_khz;
560 u64 cur_tsc_nsec; 560 u64 cur_tsc_nsec;
561 u64 cur_tsc_write; 561 u64 cur_tsc_write;
562 u64 cur_tsc_offset; 562 u64 cur_tsc_offset;
563 u8 cur_tsc_generation; 563 u8 cur_tsc_generation;
564 int nr_vcpus_matched_tsc; 564 int nr_vcpus_matched_tsc;
565 565
566 spinlock_t pvclock_gtod_sync_lock; 566 spinlock_t pvclock_gtod_sync_lock;
567 bool use_master_clock; 567 bool use_master_clock;
568 u64 master_kernel_ns; 568 u64 master_kernel_ns;
569 cycle_t master_cycle_now; 569 cycle_t master_cycle_now;
570 570
571 struct kvm_xen_hvm_config xen_hvm_config; 571 struct kvm_xen_hvm_config xen_hvm_config;
572 572
573 /* fields used by HYPER-V emulation */ 573 /* fields used by HYPER-V emulation */
574 u64 hv_guest_os_id; 574 u64 hv_guest_os_id;
575 u64 hv_hypercall; 575 u64 hv_hypercall;
576 576
577 #ifdef CONFIG_KVM_MMU_AUDIT 577 #ifdef CONFIG_KVM_MMU_AUDIT
578 int audit_point; 578 int audit_point;
579 #endif 579 #endif
580 }; 580 };
581 581
582 struct kvm_vm_stat { 582 struct kvm_vm_stat {
583 u32 mmu_shadow_zapped; 583 u32 mmu_shadow_zapped;
584 u32 mmu_pte_write; 584 u32 mmu_pte_write;
585 u32 mmu_pte_updated; 585 u32 mmu_pte_updated;
586 u32 mmu_pde_zapped; 586 u32 mmu_pde_zapped;
587 u32 mmu_flooded; 587 u32 mmu_flooded;
588 u32 mmu_recycled; 588 u32 mmu_recycled;
589 u32 mmu_cache_miss; 589 u32 mmu_cache_miss;
590 u32 mmu_unsync; 590 u32 mmu_unsync;
591 u32 remote_tlb_flush; 591 u32 remote_tlb_flush;
592 u32 lpages; 592 u32 lpages;
593 }; 593 };
594 594
595 struct kvm_vcpu_stat { 595 struct kvm_vcpu_stat {
596 u32 pf_fixed; 596 u32 pf_fixed;
597 u32 pf_guest; 597 u32 pf_guest;
598 u32 tlb_flush; 598 u32 tlb_flush;
599 u32 invlpg; 599 u32 invlpg;
600 600
601 u32 exits; 601 u32 exits;
602 u32 io_exits; 602 u32 io_exits;
603 u32 mmio_exits; 603 u32 mmio_exits;
604 u32 signal_exits; 604 u32 signal_exits;
605 u32 irq_window_exits; 605 u32 irq_window_exits;
606 u32 nmi_window_exits; 606 u32 nmi_window_exits;
607 u32 halt_exits; 607 u32 halt_exits;
608 u32 halt_wakeup; 608 u32 halt_wakeup;
609 u32 request_irq_exits; 609 u32 request_irq_exits;
610 u32 irq_exits; 610 u32 irq_exits;
611 u32 host_state_reload; 611 u32 host_state_reload;
612 u32 efer_reload; 612 u32 efer_reload;
613 u32 fpu_reload; 613 u32 fpu_reload;
614 u32 insn_emulation; 614 u32 insn_emulation;
615 u32 insn_emulation_fail; 615 u32 insn_emulation_fail;
616 u32 hypercalls; 616 u32 hypercalls;
617 u32 irq_injections; 617 u32 irq_injections;
618 u32 nmi_injections; 618 u32 nmi_injections;
619 }; 619 };
620 620
621 struct x86_instruction_info; 621 struct x86_instruction_info;
622 622
623 struct msr_data { 623 struct msr_data {
624 bool host_initiated; 624 bool host_initiated;
625 u32 index; 625 u32 index;
626 u64 data; 626 u64 data;
627 }; 627 };
628 628
629 struct kvm_x86_ops { 629 struct kvm_x86_ops {
630 int (*cpu_has_kvm_support)(void); /* __init */ 630 int (*cpu_has_kvm_support)(void); /* __init */
631 int (*disabled_by_bios)(void); /* __init */ 631 int (*disabled_by_bios)(void); /* __init */
632 int (*hardware_enable)(void *dummy); 632 int (*hardware_enable)(void *dummy);
633 void (*hardware_disable)(void *dummy); 633 void (*hardware_disable)(void *dummy);
634 void (*check_processor_compatibility)(void *rtn); 634 void (*check_processor_compatibility)(void *rtn);
635 int (*hardware_setup)(void); /* __init */ 635 int (*hardware_setup)(void); /* __init */
636 void (*hardware_unsetup)(void); /* __exit */ 636 void (*hardware_unsetup)(void); /* __exit */
637 bool (*cpu_has_accelerated_tpr)(void); 637 bool (*cpu_has_accelerated_tpr)(void);
638 void (*cpuid_update)(struct kvm_vcpu *vcpu); 638 void (*cpuid_update)(struct kvm_vcpu *vcpu);
639 639
640 /* Create, but do not attach this VCPU */ 640 /* Create, but do not attach this VCPU */
641 struct kvm_vcpu *(*vcpu_create)(struct kvm *kvm, unsigned id); 641 struct kvm_vcpu *(*vcpu_create)(struct kvm *kvm, unsigned id);
642 void (*vcpu_free)(struct kvm_vcpu *vcpu); 642 void (*vcpu_free)(struct kvm_vcpu *vcpu);
643 void (*vcpu_reset)(struct kvm_vcpu *vcpu); 643 void (*vcpu_reset)(struct kvm_vcpu *vcpu);
644 644
645 void (*prepare_guest_switch)(struct kvm_vcpu *vcpu); 645 void (*prepare_guest_switch)(struct kvm_vcpu *vcpu);
646 void (*vcpu_load)(struct kvm_vcpu *vcpu, int cpu); 646 void (*vcpu_load)(struct kvm_vcpu *vcpu, int cpu);
647 void (*vcpu_put)(struct kvm_vcpu *vcpu); 647 void (*vcpu_put)(struct kvm_vcpu *vcpu);
648 648
649 void (*update_db_bp_intercept)(struct kvm_vcpu *vcpu); 649 void (*update_db_bp_intercept)(struct kvm_vcpu *vcpu);
650 int (*get_msr)(struct kvm_vcpu *vcpu, u32 msr_index, u64 *pdata); 650 int (*get_msr)(struct kvm_vcpu *vcpu, u32 msr_index, u64 *pdata);
651 int (*set_msr)(struct kvm_vcpu *vcpu, struct msr_data *msr); 651 int (*set_msr)(struct kvm_vcpu *vcpu, struct msr_data *msr);
652 u64 (*get_segment_base)(struct kvm_vcpu *vcpu, int seg); 652 u64 (*get_segment_base)(struct kvm_vcpu *vcpu, int seg);
653 void (*get_segment)(struct kvm_vcpu *vcpu, 653 void (*get_segment)(struct kvm_vcpu *vcpu,
654 struct kvm_segment *var, int seg); 654 struct kvm_segment *var, int seg);
655 int (*get_cpl)(struct kvm_vcpu *vcpu); 655 int (*get_cpl)(struct kvm_vcpu *vcpu);
656 void (*set_segment)(struct kvm_vcpu *vcpu, 656 void (*set_segment)(struct kvm_vcpu *vcpu,
657 struct kvm_segment *var, int seg); 657 struct kvm_segment *var, int seg);
658 void (*get_cs_db_l_bits)(struct kvm_vcpu *vcpu, int *db, int *l); 658 void (*get_cs_db_l_bits)(struct kvm_vcpu *vcpu, int *db, int *l);
659 void (*decache_cr0_guest_bits)(struct kvm_vcpu *vcpu); 659 void (*decache_cr0_guest_bits)(struct kvm_vcpu *vcpu);
660 void (*decache_cr3)(struct kvm_vcpu *vcpu); 660 void (*decache_cr3)(struct kvm_vcpu *vcpu);
661 void (*decache_cr4_guest_bits)(struct kvm_vcpu *vcpu); 661 void (*decache_cr4_guest_bits)(struct kvm_vcpu *vcpu);
662 void (*set_cr0)(struct kvm_vcpu *vcpu, unsigned long cr0); 662 void (*set_cr0)(struct kvm_vcpu *vcpu, unsigned long cr0);
663 void (*set_cr3)(struct kvm_vcpu *vcpu, unsigned long cr3); 663 void (*set_cr3)(struct kvm_vcpu *vcpu, unsigned long cr3);
664 int (*set_cr4)(struct kvm_vcpu *vcpu, unsigned long cr4); 664 int (*set_cr4)(struct kvm_vcpu *vcpu, unsigned long cr4);
665 void (*set_efer)(struct kvm_vcpu *vcpu, u64 efer); 665 void (*set_efer)(struct kvm_vcpu *vcpu, u64 efer);
666 void (*get_idt)(struct kvm_vcpu *vcpu, struct desc_ptr *dt); 666 void (*get_idt)(struct kvm_vcpu *vcpu, struct desc_ptr *dt);
667 void (*set_idt)(struct kvm_vcpu *vcpu, struct desc_ptr *dt); 667 void (*set_idt)(struct kvm_vcpu *vcpu, struct desc_ptr *dt);
668 void (*get_gdt)(struct kvm_vcpu *vcpu, struct desc_ptr *dt); 668 void (*get_gdt)(struct kvm_vcpu *vcpu, struct desc_ptr *dt);
669 void (*set_gdt)(struct kvm_vcpu *vcpu, struct desc_ptr *dt); 669 void (*set_gdt)(struct kvm_vcpu *vcpu, struct desc_ptr *dt);
670 void (*set_dr7)(struct kvm_vcpu *vcpu, unsigned long value); 670 void (*set_dr7)(struct kvm_vcpu *vcpu, unsigned long value);
671 void (*cache_reg)(struct kvm_vcpu *vcpu, enum kvm_reg reg); 671 void (*cache_reg)(struct kvm_vcpu *vcpu, enum kvm_reg reg);
672 unsigned long (*get_rflags)(struct kvm_vcpu *vcpu); 672 unsigned long (*get_rflags)(struct kvm_vcpu *vcpu);
673 void (*set_rflags)(struct kvm_vcpu *vcpu, unsigned long rflags); 673 void (*set_rflags)(struct kvm_vcpu *vcpu, unsigned long rflags);
674 void (*fpu_activate)(struct kvm_vcpu *vcpu); 674 void (*fpu_activate)(struct kvm_vcpu *vcpu);
675 void (*fpu_deactivate)(struct kvm_vcpu *vcpu); 675 void (*fpu_deactivate)(struct kvm_vcpu *vcpu);
676 676
677 void (*tlb_flush)(struct kvm_vcpu *vcpu); 677 void (*tlb_flush)(struct kvm_vcpu *vcpu);
678 678
679 void (*run)(struct kvm_vcpu *vcpu); 679 void (*run)(struct kvm_vcpu *vcpu);
680 int (*handle_exit)(struct kvm_vcpu *vcpu); 680 int (*handle_exit)(struct kvm_vcpu *vcpu);
681 void (*skip_emulated_instruction)(struct kvm_vcpu *vcpu); 681 void (*skip_emulated_instruction)(struct kvm_vcpu *vcpu);
682 void (*set_interrupt_shadow)(struct kvm_vcpu *vcpu, int mask); 682 void (*set_interrupt_shadow)(struct kvm_vcpu *vcpu, int mask);
683 u32 (*get_interrupt_shadow)(struct kvm_vcpu *vcpu, int mask); 683 u32 (*get_interrupt_shadow)(struct kvm_vcpu *vcpu, int mask);
684 void (*patch_hypercall)(struct kvm_vcpu *vcpu, 684 void (*patch_hypercall)(struct kvm_vcpu *vcpu,
685 unsigned char *hypercall_addr); 685 unsigned char *hypercall_addr);
686 void (*set_irq)(struct kvm_vcpu *vcpu); 686 void (*set_irq)(struct kvm_vcpu *vcpu);
687 void (*set_nmi)(struct kvm_vcpu *vcpu); 687 void (*set_nmi)(struct kvm_vcpu *vcpu);
688 void (*queue_exception)(struct kvm_vcpu *vcpu, unsigned nr, 688 void (*queue_exception)(struct kvm_vcpu *vcpu, unsigned nr,
689 bool has_error_code, u32 error_code, 689 bool has_error_code, u32 error_code,
690 bool reinject); 690 bool reinject);
691 void (*cancel_injection)(struct kvm_vcpu *vcpu); 691 void (*cancel_injection)(struct kvm_vcpu *vcpu);
692 int (*interrupt_allowed)(struct kvm_vcpu *vcpu); 692 int (*interrupt_allowed)(struct kvm_vcpu *vcpu);
693 int (*nmi_allowed)(struct kvm_vcpu *vcpu); 693 int (*nmi_allowed)(struct kvm_vcpu *vcpu);
694 bool (*get_nmi_mask)(struct kvm_vcpu *vcpu); 694 bool (*get_nmi_mask)(struct kvm_vcpu *vcpu);
695 void (*set_nmi_mask)(struct kvm_vcpu *vcpu, bool masked); 695 void (*set_nmi_mask)(struct kvm_vcpu *vcpu, bool masked);
696 void (*enable_nmi_window)(struct kvm_vcpu *vcpu); 696 void (*enable_nmi_window)(struct kvm_vcpu *vcpu);
697 void (*enable_irq_window)(struct kvm_vcpu *vcpu); 697 void (*enable_irq_window)(struct kvm_vcpu *vcpu);
698 void (*update_cr8_intercept)(struct kvm_vcpu *vcpu, int tpr, int irr); 698 void (*update_cr8_intercept)(struct kvm_vcpu *vcpu, int tpr, int irr);
699 int (*vm_has_apicv)(struct kvm *kvm); 699 int (*vm_has_apicv)(struct kvm *kvm);
700 void (*hwapic_irr_update)(struct kvm_vcpu *vcpu, int max_irr); 700 void (*hwapic_irr_update)(struct kvm_vcpu *vcpu, int max_irr);
701 void (*hwapic_isr_update)(struct kvm *kvm, int isr); 701 void (*hwapic_isr_update)(struct kvm *kvm, int isr);
702 void (*load_eoi_exitmap)(struct kvm_vcpu *vcpu, u64 *eoi_exit_bitmap); 702 void (*load_eoi_exitmap)(struct kvm_vcpu *vcpu, u64 *eoi_exit_bitmap);
703 void (*set_virtual_x2apic_mode)(struct kvm_vcpu *vcpu, bool set); 703 void (*set_virtual_x2apic_mode)(struct kvm_vcpu *vcpu, bool set);
704 int (*set_tss_addr)(struct kvm *kvm, unsigned int addr); 704 int (*set_tss_addr)(struct kvm *kvm, unsigned int addr);
705 int (*get_tdp_level)(void); 705 int (*get_tdp_level)(void);
706 u64 (*get_mt_mask)(struct kvm_vcpu *vcpu, gfn_t gfn, bool is_mmio); 706 u64 (*get_mt_mask)(struct kvm_vcpu *vcpu, gfn_t gfn, bool is_mmio);
707 int (*get_lpage_level)(void); 707 int (*get_lpage_level)(void);
708 bool (*rdtscp_supported)(void); 708 bool (*rdtscp_supported)(void);
709 bool (*invpcid_supported)(void); 709 bool (*invpcid_supported)(void);
710 void (*adjust_tsc_offset)(struct kvm_vcpu *vcpu, s64 adjustment, bool host); 710 void (*adjust_tsc_offset)(struct kvm_vcpu *vcpu, s64 adjustment, bool host);
711 711
712 void (*set_tdp_cr3)(struct kvm_vcpu *vcpu, unsigned long cr3); 712 void (*set_tdp_cr3)(struct kvm_vcpu *vcpu, unsigned long cr3);
713 713
714 void (*set_supported_cpuid)(u32 func, struct kvm_cpuid_entry2 *entry); 714 void (*set_supported_cpuid)(u32 func, struct kvm_cpuid_entry2 *entry);
715 715
716 bool (*has_wbinvd_exit)(void); 716 bool (*has_wbinvd_exit)(void);
717 717
718 void (*set_tsc_khz)(struct kvm_vcpu *vcpu, u32 user_tsc_khz, bool scale); 718 void (*set_tsc_khz)(struct kvm_vcpu *vcpu, u32 user_tsc_khz, bool scale);
719 u64 (*read_tsc_offset)(struct kvm_vcpu *vcpu); 719 u64 (*read_tsc_offset)(struct kvm_vcpu *vcpu);
720 void (*write_tsc_offset)(struct kvm_vcpu *vcpu, u64 offset); 720 void (*write_tsc_offset)(struct kvm_vcpu *vcpu, u64 offset);
721 721
722 u64 (*compute_tsc_offset)(struct kvm_vcpu *vcpu, u64 target_tsc); 722 u64 (*compute_tsc_offset)(struct kvm_vcpu *vcpu, u64 target_tsc);
723 u64 (*read_l1_tsc)(struct kvm_vcpu *vcpu, u64 host_tsc); 723 u64 (*read_l1_tsc)(struct kvm_vcpu *vcpu, u64 host_tsc);
724 724
725 void (*get_exit_info)(struct kvm_vcpu *vcpu, u64 *info1, u64 *info2); 725 void (*get_exit_info)(struct kvm_vcpu *vcpu, u64 *info1, u64 *info2);
726 726
727 int (*check_intercept)(struct kvm_vcpu *vcpu, 727 int (*check_intercept)(struct kvm_vcpu *vcpu,
728 struct x86_instruction_info *info, 728 struct x86_instruction_info *info,
729 enum x86_intercept_stage stage); 729 enum x86_intercept_stage stage);
730 }; 730 };
731 731
732 struct kvm_arch_async_pf { 732 struct kvm_arch_async_pf {
733 u32 token; 733 u32 token;
734 gfn_t gfn; 734 gfn_t gfn;
735 unsigned long cr3; 735 unsigned long cr3;
736 bool direct_map; 736 bool direct_map;
737 }; 737 };
738 738
739 extern struct kvm_x86_ops *kvm_x86_ops; 739 extern struct kvm_x86_ops *kvm_x86_ops;
740 740
741 static inline void adjust_tsc_offset_guest(struct kvm_vcpu *vcpu, 741 static inline void adjust_tsc_offset_guest(struct kvm_vcpu *vcpu,
742 s64 adjustment) 742 s64 adjustment)
743 { 743 {
744 kvm_x86_ops->adjust_tsc_offset(vcpu, adjustment, false); 744 kvm_x86_ops->adjust_tsc_offset(vcpu, adjustment, false);
745 } 745 }
746 746
747 static inline void adjust_tsc_offset_host(struct kvm_vcpu *vcpu, s64 adjustment) 747 static inline void adjust_tsc_offset_host(struct kvm_vcpu *vcpu, s64 adjustment)
748 { 748 {
749 kvm_x86_ops->adjust_tsc_offset(vcpu, adjustment, true); 749 kvm_x86_ops->adjust_tsc_offset(vcpu, adjustment, true);
750 } 750 }
751 751
752 int kvm_mmu_module_init(void); 752 int kvm_mmu_module_init(void);
753 void kvm_mmu_module_exit(void); 753 void kvm_mmu_module_exit(void);
754 754
755 void kvm_mmu_destroy(struct kvm_vcpu *vcpu); 755 void kvm_mmu_destroy(struct kvm_vcpu *vcpu);
756 int kvm_mmu_create(struct kvm_vcpu *vcpu); 756 int kvm_mmu_create(struct kvm_vcpu *vcpu);
757 int kvm_mmu_setup(struct kvm_vcpu *vcpu); 757 int kvm_mmu_setup(struct kvm_vcpu *vcpu);
758 void kvm_mmu_set_mask_ptes(u64 user_mask, u64 accessed_mask, 758 void kvm_mmu_set_mask_ptes(u64 user_mask, u64 accessed_mask,
759 u64 dirty_mask, u64 nx_mask, u64 x_mask); 759 u64 dirty_mask, u64 nx_mask, u64 x_mask);
760 760
761 int kvm_mmu_reset_context(struct kvm_vcpu *vcpu); 761 int kvm_mmu_reset_context(struct kvm_vcpu *vcpu);
762 void kvm_mmu_slot_remove_write_access(struct kvm *kvm, int slot); 762 void kvm_mmu_slot_remove_write_access(struct kvm *kvm, int slot);
763 void kvm_mmu_write_protect_pt_masked(struct kvm *kvm, 763 void kvm_mmu_write_protect_pt_masked(struct kvm *kvm,
764 struct kvm_memory_slot *slot, 764 struct kvm_memory_slot *slot,
765 gfn_t gfn_offset, unsigned long mask); 765 gfn_t gfn_offset, unsigned long mask);
766 void kvm_mmu_zap_all(struct kvm *kvm); 766 void kvm_mmu_zap_all(struct kvm *kvm);
767 void kvm_mmu_zap_mmio_sptes(struct kvm *kvm); 767 void kvm_mmu_zap_mmio_sptes(struct kvm *kvm);
768 unsigned int kvm_mmu_calculate_mmu_pages(struct kvm *kvm); 768 unsigned int kvm_mmu_calculate_mmu_pages(struct kvm *kvm);
769 void kvm_mmu_change_mmu_pages(struct kvm *kvm, unsigned int kvm_nr_mmu_pages); 769 void kvm_mmu_change_mmu_pages(struct kvm *kvm, unsigned int kvm_nr_mmu_pages);
770 770
771 int load_pdptrs(struct kvm_vcpu *vcpu, struct kvm_mmu *mmu, unsigned long cr3); 771 int load_pdptrs(struct kvm_vcpu *vcpu, struct kvm_mmu *mmu, unsigned long cr3);
772 772
773 int emulator_write_phys(struct kvm_vcpu *vcpu, gpa_t gpa, 773 int emulator_write_phys(struct kvm_vcpu *vcpu, gpa_t gpa,
774 const void *val, int bytes); 774 const void *val, int bytes);
775 u8 kvm_get_guest_memory_type(struct kvm_vcpu *vcpu, gfn_t gfn); 775 u8 kvm_get_guest_memory_type(struct kvm_vcpu *vcpu, gfn_t gfn);
776 776
777 extern bool tdp_enabled; 777 extern bool tdp_enabled;
778 778
779 u64 vcpu_tsc_khz(struct kvm_vcpu *vcpu); 779 u64 vcpu_tsc_khz(struct kvm_vcpu *vcpu);
780 780
781 /* control of guest tsc rate supported? */ 781 /* control of guest tsc rate supported? */
782 extern bool kvm_has_tsc_control; 782 extern bool kvm_has_tsc_control;
783 /* minimum supported tsc_khz for guests */ 783 /* minimum supported tsc_khz for guests */
784 extern u32 kvm_min_guest_tsc_khz; 784 extern u32 kvm_min_guest_tsc_khz;
785 /* maximum supported tsc_khz for guests */ 785 /* maximum supported tsc_khz for guests */
786 extern u32 kvm_max_guest_tsc_khz; 786 extern u32 kvm_max_guest_tsc_khz;
787 787
788 enum emulation_result { 788 enum emulation_result {
789 EMULATE_DONE, /* no further processing */ 789 EMULATE_DONE, /* no further processing */
790 EMULATE_DO_MMIO, /* kvm_run filled with mmio request */ 790 EMULATE_DO_MMIO, /* kvm_run filled with mmio request */
791 EMULATE_FAIL, /* can't emulate this instruction */ 791 EMULATE_FAIL, /* can't emulate this instruction */
792 }; 792 };
793 793
794 #define EMULTYPE_NO_DECODE (1 << 0) 794 #define EMULTYPE_NO_DECODE (1 << 0)
795 #define EMULTYPE_TRAP_UD (1 << 1) 795 #define EMULTYPE_TRAP_UD (1 << 1)
796 #define EMULTYPE_SKIP (1 << 2) 796 #define EMULTYPE_SKIP (1 << 2)
797 #define EMULTYPE_RETRY (1 << 3) 797 #define EMULTYPE_RETRY (1 << 3)
798 int x86_emulate_instruction(struct kvm_vcpu *vcpu, unsigned long cr2, 798 int x86_emulate_instruction(struct kvm_vcpu *vcpu, unsigned long cr2,
799 int emulation_type, void *insn, int insn_len); 799 int emulation_type, void *insn, int insn_len);
800 800
801 static inline int emulate_instruction(struct kvm_vcpu *vcpu, 801 static inline int emulate_instruction(struct kvm_vcpu *vcpu,
802 int emulation_type) 802 int emulation_type)
803 { 803 {
804 return x86_emulate_instruction(vcpu, 0, emulation_type, NULL, 0); 804 return x86_emulate_instruction(vcpu, 0, emulation_type, NULL, 0);
805 } 805 }
806 806
807 void kvm_enable_efer_bits(u64); 807 void kvm_enable_efer_bits(u64);
808 int kvm_get_msr(struct kvm_vcpu *vcpu, u32 msr_index, u64 *data); 808 int kvm_get_msr(struct kvm_vcpu *vcpu, u32 msr_index, u64 *data);
809 int kvm_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr); 809 int kvm_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr);
810 810
811 struct x86_emulate_ctxt; 811 struct x86_emulate_ctxt;
812 812
813 int kvm_fast_pio_out(struct kvm_vcpu *vcpu, int size, unsigned short port); 813 int kvm_fast_pio_out(struct kvm_vcpu *vcpu, int size, unsigned short port);
814 void kvm_emulate_cpuid(struct kvm_vcpu *vcpu); 814 void kvm_emulate_cpuid(struct kvm_vcpu *vcpu);
815 int kvm_emulate_halt(struct kvm_vcpu *vcpu); 815 int kvm_emulate_halt(struct kvm_vcpu *vcpu);
816 int kvm_emulate_wbinvd(struct kvm_vcpu *vcpu); 816 int kvm_emulate_wbinvd(struct kvm_vcpu *vcpu);
817 817
818 void kvm_get_segment(struct kvm_vcpu *vcpu, struct kvm_segment *var, int seg); 818 void kvm_get_segment(struct kvm_vcpu *vcpu, struct kvm_segment *var, int seg);
819 int kvm_load_segment_descriptor(struct kvm_vcpu *vcpu, u16 selector, int seg); 819 int kvm_load_segment_descriptor(struct kvm_vcpu *vcpu, u16 selector, int seg);
820 void kvm_vcpu_deliver_sipi_vector(struct kvm_vcpu *vcpu, unsigned int vector); 820 void kvm_vcpu_deliver_sipi_vector(struct kvm_vcpu *vcpu, unsigned int vector);
821 821
822 int kvm_task_switch(struct kvm_vcpu *vcpu, u16 tss_selector, int idt_index, 822 int kvm_task_switch(struct kvm_vcpu *vcpu, u16 tss_selector, int idt_index,
823 int reason, bool has_error_code, u32 error_code); 823 int reason, bool has_error_code, u32 error_code);
824 824
825 int kvm_set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0); 825 int kvm_set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0);
826 int kvm_set_cr3(struct kvm_vcpu *vcpu, unsigned long cr3); 826 int kvm_set_cr3(struct kvm_vcpu *vcpu, unsigned long cr3);
827 int kvm_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4); 827 int kvm_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4);
828 int kvm_set_cr8(struct kvm_vcpu *vcpu, unsigned long cr8); 828 int kvm_set_cr8(struct kvm_vcpu *vcpu, unsigned long cr8);
829 int kvm_set_dr(struct kvm_vcpu *vcpu, int dr, unsigned long val); 829 int kvm_set_dr(struct kvm_vcpu *vcpu, int dr, unsigned long val);
830 int kvm_get_dr(struct kvm_vcpu *vcpu, int dr, unsigned long *val); 830 int kvm_get_dr(struct kvm_vcpu *vcpu, int dr, unsigned long *val);
831 unsigned long kvm_get_cr8(struct kvm_vcpu *vcpu); 831 unsigned long kvm_get_cr8(struct kvm_vcpu *vcpu);
832 void kvm_lmsw(struct kvm_vcpu *vcpu, unsigned long msw); 832 void kvm_lmsw(struct kvm_vcpu *vcpu, unsigned long msw);
833 void kvm_get_cs_db_l_bits(struct kvm_vcpu *vcpu, int *db, int *l); 833 void kvm_get_cs_db_l_bits(struct kvm_vcpu *vcpu, int *db, int *l);
834 int kvm_set_xcr(struct kvm_vcpu *vcpu, u32 index, u64 xcr); 834 int kvm_set_xcr(struct kvm_vcpu *vcpu, u32 index, u64 xcr);
835 835
836 int kvm_get_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata); 836 int kvm_get_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata);
837 int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr); 837 int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr);
838 838
839 unsigned long kvm_get_rflags(struct kvm_vcpu *vcpu); 839 unsigned long kvm_get_rflags(struct kvm_vcpu *vcpu);
840 void kvm_set_rflags(struct kvm_vcpu *vcpu, unsigned long rflags); 840 void kvm_set_rflags(struct kvm_vcpu *vcpu, unsigned long rflags);
841 bool kvm_rdpmc(struct kvm_vcpu *vcpu); 841 bool kvm_rdpmc(struct kvm_vcpu *vcpu);
842 842
843 void kvm_queue_exception(struct kvm_vcpu *vcpu, unsigned nr); 843 void kvm_queue_exception(struct kvm_vcpu *vcpu, unsigned nr);
844 void kvm_queue_exception_e(struct kvm_vcpu *vcpu, unsigned nr, u32 error_code); 844 void kvm_queue_exception_e(struct kvm_vcpu *vcpu, unsigned nr, u32 error_code);
845 void kvm_requeue_exception(struct kvm_vcpu *vcpu, unsigned nr); 845 void kvm_requeue_exception(struct kvm_vcpu *vcpu, unsigned nr);
846 void kvm_requeue_exception_e(struct kvm_vcpu *vcpu, unsigned nr, u32 error_code); 846 void kvm_requeue_exception_e(struct kvm_vcpu *vcpu, unsigned nr, u32 error_code);
847 void kvm_inject_page_fault(struct kvm_vcpu *vcpu, struct x86_exception *fault); 847 void kvm_inject_page_fault(struct kvm_vcpu *vcpu, struct x86_exception *fault);
848 int kvm_read_guest_page_mmu(struct kvm_vcpu *vcpu, struct kvm_mmu *mmu, 848 int kvm_read_guest_page_mmu(struct kvm_vcpu *vcpu, struct kvm_mmu *mmu,
849 gfn_t gfn, void *data, int offset, int len, 849 gfn_t gfn, void *data, int offset, int len,
850 u32 access); 850 u32 access);
851 void kvm_propagate_fault(struct kvm_vcpu *vcpu, struct x86_exception *fault); 851 void kvm_propagate_fault(struct kvm_vcpu *vcpu, struct x86_exception *fault);
852 bool kvm_require_cpl(struct kvm_vcpu *vcpu, int required_cpl); 852 bool kvm_require_cpl(struct kvm_vcpu *vcpu, int required_cpl);
853 853
854 static inline int __kvm_irq_line_state(unsigned long *irq_state, 854 static inline int __kvm_irq_line_state(unsigned long *irq_state,
855 int irq_source_id, int level) 855 int irq_source_id, int level)
856 { 856 {
857 /* Logical OR for level trig interrupt */ 857 /* Logical OR for level trig interrupt */
858 if (level) 858 if (level)
859 __set_bit(irq_source_id, irq_state); 859 __set_bit(irq_source_id, irq_state);
860 else 860 else
861 __clear_bit(irq_source_id, irq_state); 861 __clear_bit(irq_source_id, irq_state);
862 862
863 return !!(*irq_state); 863 return !!(*irq_state);
864 } 864 }
865 865
866 int kvm_pic_set_irq(struct kvm_pic *pic, int irq, int irq_source_id, int level); 866 int kvm_pic_set_irq(struct kvm_pic *pic, int irq, int irq_source_id, int level);
867 void kvm_pic_clear_all(struct kvm_pic *pic, int irq_source_id); 867 void kvm_pic_clear_all(struct kvm_pic *pic, int irq_source_id);
868 868
869 void kvm_inject_nmi(struct kvm_vcpu *vcpu); 869 void kvm_inject_nmi(struct kvm_vcpu *vcpu);
870 870
871 int fx_init(struct kvm_vcpu *vcpu); 871 int fx_init(struct kvm_vcpu *vcpu);
872 872
873 void kvm_mmu_flush_tlb(struct kvm_vcpu *vcpu); 873 void kvm_mmu_flush_tlb(struct kvm_vcpu *vcpu);
874 void kvm_mmu_pte_write(struct kvm_vcpu *vcpu, gpa_t gpa, 874 void kvm_mmu_pte_write(struct kvm_vcpu *vcpu, gpa_t gpa,
875 const u8 *new, int bytes); 875 const u8 *new, int bytes);
876 int kvm_mmu_unprotect_page(struct kvm *kvm, gfn_t gfn); 876 int kvm_mmu_unprotect_page(struct kvm *kvm, gfn_t gfn);
877 int kvm_mmu_unprotect_page_virt(struct kvm_vcpu *vcpu, gva_t gva); 877 int kvm_mmu_unprotect_page_virt(struct kvm_vcpu *vcpu, gva_t gva);
878 void __kvm_mmu_free_some_pages(struct kvm_vcpu *vcpu); 878 void __kvm_mmu_free_some_pages(struct kvm_vcpu *vcpu);
879 int kvm_mmu_load(struct kvm_vcpu *vcpu); 879 int kvm_mmu_load(struct kvm_vcpu *vcpu);
880 void kvm_mmu_unload(struct kvm_vcpu *vcpu); 880 void kvm_mmu_unload(struct kvm_vcpu *vcpu);
881 void kvm_mmu_sync_roots(struct kvm_vcpu *vcpu); 881 void kvm_mmu_sync_roots(struct kvm_vcpu *vcpu);
882 gpa_t translate_nested_gpa(struct kvm_vcpu *vcpu, gpa_t gpa, u32 access); 882 gpa_t translate_nested_gpa(struct kvm_vcpu *vcpu, gpa_t gpa, u32 access);
883 gpa_t kvm_mmu_gva_to_gpa_read(struct kvm_vcpu *vcpu, gva_t gva, 883 gpa_t kvm_mmu_gva_to_gpa_read(struct kvm_vcpu *vcpu, gva_t gva,
884 struct x86_exception *exception); 884 struct x86_exception *exception);
885 gpa_t kvm_mmu_gva_to_gpa_fetch(struct kvm_vcpu *vcpu, gva_t gva, 885 gpa_t kvm_mmu_gva_to_gpa_fetch(struct kvm_vcpu *vcpu, gva_t gva,
886 struct x86_exception *exception); 886 struct x86_exception *exception);
887 gpa_t kvm_mmu_gva_to_gpa_write(struct kvm_vcpu *vcpu, gva_t gva, 887 gpa_t kvm_mmu_gva_to_gpa_write(struct kvm_vcpu *vcpu, gva_t gva,
888 struct x86_exception *exception); 888 struct x86_exception *exception);
889 gpa_t kvm_mmu_gva_to_gpa_system(struct kvm_vcpu *vcpu, gva_t gva, 889 gpa_t kvm_mmu_gva_to_gpa_system(struct kvm_vcpu *vcpu, gva_t gva,
890 struct x86_exception *exception); 890 struct x86_exception *exception);
891 891
892 int kvm_emulate_hypercall(struct kvm_vcpu *vcpu); 892 int kvm_emulate_hypercall(struct kvm_vcpu *vcpu);
893 893
894 int kvm_mmu_page_fault(struct kvm_vcpu *vcpu, gva_t gva, u32 error_code, 894 int kvm_mmu_page_fault(struct kvm_vcpu *vcpu, gva_t gva, u32 error_code,
895 void *insn, int insn_len); 895 void *insn, int insn_len);
896 void kvm_mmu_invlpg(struct kvm_vcpu *vcpu, gva_t gva); 896 void kvm_mmu_invlpg(struct kvm_vcpu *vcpu, gva_t gva);
897 897
898 void kvm_enable_tdp(void); 898 void kvm_enable_tdp(void);
899 void kvm_disable_tdp(void); 899 void kvm_disable_tdp(void);
900 900
901 int complete_pio(struct kvm_vcpu *vcpu); 901 int complete_pio(struct kvm_vcpu *vcpu);
902 bool kvm_check_iopl(struct kvm_vcpu *vcpu); 902 bool kvm_check_iopl(struct kvm_vcpu *vcpu);
903 903
904 static inline gpa_t translate_gpa(struct kvm_vcpu *vcpu, gpa_t gpa, u32 access) 904 static inline gpa_t translate_gpa(struct kvm_vcpu *vcpu, gpa_t gpa, u32 access)
905 { 905 {
906 return gpa; 906 return gpa;
907 } 907 }
908 908
909 static inline struct kvm_mmu_page *page_header(hpa_t shadow_page) 909 static inline struct kvm_mmu_page *page_header(hpa_t shadow_page)
910 { 910 {
911 struct page *page = pfn_to_page(shadow_page >> PAGE_SHIFT); 911 struct page *page = pfn_to_page(shadow_page >> PAGE_SHIFT);
912 912
913 return (struct kvm_mmu_page *)page_private(page); 913 return (struct kvm_mmu_page *)page_private(page);
914 } 914 }
915 915
916 static inline u16 kvm_read_ldt(void) 916 static inline u16 kvm_read_ldt(void)
917 { 917 {
918 u16 ldt; 918 u16 ldt;
919 asm("sldt %0" : "=g"(ldt)); 919 asm("sldt %0" : "=g"(ldt));
920 return ldt; 920 return ldt;
921 } 921 }
922 922
923 static inline void kvm_load_ldt(u16 sel) 923 static inline void kvm_load_ldt(u16 sel)
924 { 924 {
925 asm("lldt %0" : : "rm"(sel)); 925 asm("lldt %0" : : "rm"(sel));
926 } 926 }
927 927
928 #ifdef CONFIG_X86_64 928 #ifdef CONFIG_X86_64
929 static inline unsigned long read_msr(unsigned long msr) 929 static inline unsigned long read_msr(unsigned long msr)
930 { 930 {
931 u64 value; 931 u64 value;
932 932
933 rdmsrl(msr, value); 933 rdmsrl(msr, value);
934 return value; 934 return value;
935 } 935 }
936 #endif 936 #endif
937 937
938 static inline u32 get_rdx_init_val(void) 938 static inline u32 get_rdx_init_val(void)
939 { 939 {
940 return 0x600; /* P6 family */ 940 return 0x600; /* P6 family */
941 } 941 }
942 942
943 static inline void kvm_inject_gp(struct kvm_vcpu *vcpu, u32 error_code) 943 static inline void kvm_inject_gp(struct kvm_vcpu *vcpu, u32 error_code)
944 { 944 {
945 kvm_queue_exception_e(vcpu, GP_VECTOR, error_code); 945 kvm_queue_exception_e(vcpu, GP_VECTOR, error_code);
946 } 946 }
947 947
948 #define TSS_IOPB_BASE_OFFSET 0x66 948 #define TSS_IOPB_BASE_OFFSET 0x66
949 #define TSS_BASE_SIZE 0x68 949 #define TSS_BASE_SIZE 0x68
950 #define TSS_IOPB_SIZE (65536 / 8) 950 #define TSS_IOPB_SIZE (65536 / 8)
951 #define TSS_REDIRECTION_SIZE (256 / 8) 951 #define TSS_REDIRECTION_SIZE (256 / 8)
952 #define RMODE_TSS_SIZE \ 952 #define RMODE_TSS_SIZE \
953 (TSS_BASE_SIZE + TSS_REDIRECTION_SIZE + TSS_IOPB_SIZE + 1) 953 (TSS_BASE_SIZE + TSS_REDIRECTION_SIZE + TSS_IOPB_SIZE + 1)
954 954
955 enum { 955 enum {
956 TASK_SWITCH_CALL = 0, 956 TASK_SWITCH_CALL = 0,
957 TASK_SWITCH_IRET = 1, 957 TASK_SWITCH_IRET = 1,
958 TASK_SWITCH_JMP = 2, 958 TASK_SWITCH_JMP = 2,
959 TASK_SWITCH_GATE = 3, 959 TASK_SWITCH_GATE = 3,
960 }; 960 };
961 961
962 #define HF_GIF_MASK (1 << 0) 962 #define HF_GIF_MASK (1 << 0)
963 #define HF_HIF_MASK (1 << 1) 963 #define HF_HIF_MASK (1 << 1)
964 #define HF_VINTR_MASK (1 << 2) 964 #define HF_VINTR_MASK (1 << 2)
965 #define HF_NMI_MASK (1 << 3) 965 #define HF_NMI_MASK (1 << 3)
966 #define HF_IRET_MASK (1 << 4) 966 #define HF_IRET_MASK (1 << 4)
967 #define HF_GUEST_MASK (1 << 5) /* VCPU is in guest-mode */ 967 #define HF_GUEST_MASK (1 << 5) /* VCPU is in guest-mode */
968 968
969 /* 969 /*
970 * Hardware virtualization extension instructions may fault if a 970 * Hardware virtualization extension instructions may fault if a
971 * reboot turns off virtualization while processes are running. 971 * reboot turns off virtualization while processes are running.
972 * Trap the fault and ignore the instruction if that happens. 972 * Trap the fault and ignore the instruction if that happens.
973 */ 973 */
974 asmlinkage void kvm_spurious_fault(void); 974 asmlinkage void kvm_spurious_fault(void);
975 extern bool kvm_rebooting;
976 975
977 #define ____kvm_handle_fault_on_reboot(insn, cleanup_insn) \ 976 #define ____kvm_handle_fault_on_reboot(insn, cleanup_insn) \
978 "666: " insn "\n\t" \ 977 "666: " insn "\n\t" \
979 "668: \n\t" \ 978 "668: \n\t" \
980 ".pushsection .fixup, \"ax\" \n" \ 979 ".pushsection .fixup, \"ax\" \n" \
981 "667: \n\t" \ 980 "667: \n\t" \
982 cleanup_insn "\n\t" \ 981 cleanup_insn "\n\t" \
983 "cmpb $0, kvm_rebooting \n\t" \ 982 "cmpb $0, kvm_rebooting \n\t" \
984 "jne 668b \n\t" \ 983 "jne 668b \n\t" \
985 __ASM_SIZE(push) " $666b \n\t" \ 984 __ASM_SIZE(push) " $666b \n\t" \
986 "call kvm_spurious_fault \n\t" \ 985 "call kvm_spurious_fault \n\t" \
987 ".popsection \n\t" \ 986 ".popsection \n\t" \
988 _ASM_EXTABLE(666b, 667b) 987 _ASM_EXTABLE(666b, 667b)
989 988
990 #define __kvm_handle_fault_on_reboot(insn) \ 989 #define __kvm_handle_fault_on_reboot(insn) \
991 ____kvm_handle_fault_on_reboot(insn, "") 990 ____kvm_handle_fault_on_reboot(insn, "")
992 991
993 #define KVM_ARCH_WANT_MMU_NOTIFIER 992 #define KVM_ARCH_WANT_MMU_NOTIFIER
994 int kvm_unmap_hva(struct kvm *kvm, unsigned long hva); 993 int kvm_unmap_hva(struct kvm *kvm, unsigned long hva);
995 int kvm_unmap_hva_range(struct kvm *kvm, unsigned long start, unsigned long end); 994 int kvm_unmap_hva_range(struct kvm *kvm, unsigned long start, unsigned long end);
996 int kvm_age_hva(struct kvm *kvm, unsigned long hva); 995 int kvm_age_hva(struct kvm *kvm, unsigned long hva);
997 int kvm_test_age_hva(struct kvm *kvm, unsigned long hva); 996 int kvm_test_age_hva(struct kvm *kvm, unsigned long hva);
998 void kvm_set_spte_hva(struct kvm *kvm, unsigned long hva, pte_t pte); 997 void kvm_set_spte_hva(struct kvm *kvm, unsigned long hva, pte_t pte);
999 int cpuid_maxphyaddr(struct kvm_vcpu *vcpu); 998 int cpuid_maxphyaddr(struct kvm_vcpu *vcpu);
1000 int kvm_cpu_has_injectable_intr(struct kvm_vcpu *v); 999 int kvm_cpu_has_injectable_intr(struct kvm_vcpu *v);
1001 int kvm_cpu_has_interrupt(struct kvm_vcpu *vcpu); 1000 int kvm_cpu_has_interrupt(struct kvm_vcpu *vcpu);
1002 int kvm_arch_interrupt_allowed(struct kvm_vcpu *vcpu); 1001 int kvm_arch_interrupt_allowed(struct kvm_vcpu *vcpu);
1003 int kvm_cpu_get_interrupt(struct kvm_vcpu *v); 1002 int kvm_cpu_get_interrupt(struct kvm_vcpu *v);
1004 void kvm_vcpu_reset(struct kvm_vcpu *vcpu); 1003 void kvm_vcpu_reset(struct kvm_vcpu *vcpu);
1005 1004
1006 void kvm_define_shared_msr(unsigned index, u32 msr); 1005 void kvm_define_shared_msr(unsigned index, u32 msr);
1007 void kvm_set_shared_msr(unsigned index, u64 val, u64 mask); 1006 void kvm_set_shared_msr(unsigned index, u64 val, u64 mask);
1008 1007
1009 bool kvm_is_linear_rip(struct kvm_vcpu *vcpu, unsigned long linear_rip); 1008 bool kvm_is_linear_rip(struct kvm_vcpu *vcpu, unsigned long linear_rip);
1010 1009
1011 void kvm_arch_async_page_not_present(struct kvm_vcpu *vcpu, 1010 void kvm_arch_async_page_not_present(struct kvm_vcpu *vcpu,
1012 struct kvm_async_pf *work); 1011 struct kvm_async_pf *work);
1013 void kvm_arch_async_page_present(struct kvm_vcpu *vcpu, 1012 void kvm_arch_async_page_present(struct kvm_vcpu *vcpu,
1014 struct kvm_async_pf *work); 1013 struct kvm_async_pf *work);
1015 void kvm_arch_async_page_ready(struct kvm_vcpu *vcpu, 1014 void kvm_arch_async_page_ready(struct kvm_vcpu *vcpu,
1016 struct kvm_async_pf *work); 1015 struct kvm_async_pf *work);
1017 bool kvm_arch_can_inject_async_page_present(struct kvm_vcpu *vcpu); 1016 bool kvm_arch_can_inject_async_page_present(struct kvm_vcpu *vcpu);
1018 extern bool kvm_find_async_pf_gfn(struct kvm_vcpu *vcpu, gfn_t gfn); 1017 extern bool kvm_find_async_pf_gfn(struct kvm_vcpu *vcpu, gfn_t gfn);
1019 1018
1020 void kvm_complete_insn_gp(struct kvm_vcpu *vcpu, int err); 1019 void kvm_complete_insn_gp(struct kvm_vcpu *vcpu, int err);
1021 1020
1022 int kvm_is_in_guest(void); 1021 int kvm_is_in_guest(void);
1023 1022
1024 void kvm_pmu_init(struct kvm_vcpu *vcpu); 1023 void kvm_pmu_init(struct kvm_vcpu *vcpu);
1025 void kvm_pmu_destroy(struct kvm_vcpu *vcpu); 1024 void kvm_pmu_destroy(struct kvm_vcpu *vcpu);
1026 void kvm_pmu_reset(struct kvm_vcpu *vcpu); 1025 void kvm_pmu_reset(struct kvm_vcpu *vcpu);
1027 void kvm_pmu_cpuid_update(struct kvm_vcpu *vcpu); 1026 void kvm_pmu_cpuid_update(struct kvm_vcpu *vcpu);
1028 bool kvm_pmu_msr(struct kvm_vcpu *vcpu, u32 msr); 1027 bool kvm_pmu_msr(struct kvm_vcpu *vcpu, u32 msr);
1029 int kvm_pmu_get_msr(struct kvm_vcpu *vcpu, u32 msr, u64 *data); 1028 int kvm_pmu_get_msr(struct kvm_vcpu *vcpu, u32 msr, u64 *data);
1030 int kvm_pmu_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info); 1029 int kvm_pmu_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info);
1031 int kvm_pmu_read_pmc(struct kvm_vcpu *vcpu, unsigned pmc, u64 *data); 1030 int kvm_pmu_read_pmc(struct kvm_vcpu *vcpu, unsigned pmc, u64 *data);
1032 void kvm_handle_pmu_event(struct kvm_vcpu *vcpu); 1031 void kvm_handle_pmu_event(struct kvm_vcpu *vcpu);
1033 void kvm_deliver_pmi(struct kvm_vcpu *vcpu); 1032 void kvm_deliver_pmi(struct kvm_vcpu *vcpu);
1034 1033
1035 #endif /* _ASM_X86_KVM_HOST_H */ 1034 #endif /* _ASM_X86_KVM_HOST_H */
1036 1035
include/linux/kvm_host.h
1 #ifndef __KVM_HOST_H 1 #ifndef __KVM_HOST_H
2 #define __KVM_HOST_H 2 #define __KVM_HOST_H
3 3
4 #if IS_ENABLED(CONFIG_KVM) 4 #if IS_ENABLED(CONFIG_KVM)
5 5
6 /* 6 /*
7 * This work is licensed under the terms of the GNU GPL, version 2. See 7 * This work is licensed under the terms of the GNU GPL, version 2. See
8 * the COPYING file in the top-level directory. 8 * the COPYING file in the top-level directory.
9 */ 9 */
10 10
11 #include <linux/types.h> 11 #include <linux/types.h>
12 #include <linux/hardirq.h> 12 #include <linux/hardirq.h>
13 #include <linux/list.h> 13 #include <linux/list.h>
14 #include <linux/mutex.h> 14 #include <linux/mutex.h>
15 #include <linux/spinlock.h> 15 #include <linux/spinlock.h>
16 #include <linux/signal.h> 16 #include <linux/signal.h>
17 #include <linux/sched.h> 17 #include <linux/sched.h>
18 #include <linux/bug.h> 18 #include <linux/bug.h>
19 #include <linux/mm.h> 19 #include <linux/mm.h>
20 #include <linux/mmu_notifier.h> 20 #include <linux/mmu_notifier.h>
21 #include <linux/preempt.h> 21 #include <linux/preempt.h>
22 #include <linux/msi.h> 22 #include <linux/msi.h>
23 #include <linux/slab.h> 23 #include <linux/slab.h>
24 #include <linux/rcupdate.h> 24 #include <linux/rcupdate.h>
25 #include <linux/ratelimit.h> 25 #include <linux/ratelimit.h>
26 #include <linux/err.h> 26 #include <linux/err.h>
27 #include <linux/irqflags.h> 27 #include <linux/irqflags.h>
28 #include <asm/signal.h> 28 #include <asm/signal.h>
29 29
30 #include <linux/kvm.h> 30 #include <linux/kvm.h>
31 #include <linux/kvm_para.h> 31 #include <linux/kvm_para.h>
32 32
33 #include <linux/kvm_types.h> 33 #include <linux/kvm_types.h>
34 34
35 #include <asm/kvm_host.h> 35 #include <asm/kvm_host.h>
36 36
37 #ifndef KVM_MMIO_SIZE 37 #ifndef KVM_MMIO_SIZE
38 #define KVM_MMIO_SIZE 8 38 #define KVM_MMIO_SIZE 8
39 #endif 39 #endif
40 40
41 /* 41 /*
42 * The bit 16 ~ bit 31 of kvm_memory_region::flags are internally used 42 * The bit 16 ~ bit 31 of kvm_memory_region::flags are internally used
43 * in kvm, other bits are visible for userspace which are defined in 43 * in kvm, other bits are visible for userspace which are defined in
44 * include/linux/kvm_h. 44 * include/linux/kvm_h.
45 */ 45 */
46 #define KVM_MEMSLOT_INVALID (1UL << 16) 46 #define KVM_MEMSLOT_INVALID (1UL << 16)
47 47
48 /* Two fragments for cross MMIO pages. */ 48 /* Two fragments for cross MMIO pages. */
49 #define KVM_MAX_MMIO_FRAGMENTS 2 49 #define KVM_MAX_MMIO_FRAGMENTS 2
50 50
51 /* 51 /*
52 * For the normal pfn, the highest 12 bits should be zero, 52 * For the normal pfn, the highest 12 bits should be zero,
53 * so we can mask bit 62 ~ bit 52 to indicate the error pfn, 53 * so we can mask bit 62 ~ bit 52 to indicate the error pfn,
54 * mask bit 63 to indicate the noslot pfn. 54 * mask bit 63 to indicate the noslot pfn.
55 */ 55 */
56 #define KVM_PFN_ERR_MASK (0x7ffULL << 52) 56 #define KVM_PFN_ERR_MASK (0x7ffULL << 52)
57 #define KVM_PFN_ERR_NOSLOT_MASK (0xfffULL << 52) 57 #define KVM_PFN_ERR_NOSLOT_MASK (0xfffULL << 52)
58 #define KVM_PFN_NOSLOT (0x1ULL << 63) 58 #define KVM_PFN_NOSLOT (0x1ULL << 63)
59 59
60 #define KVM_PFN_ERR_FAULT (KVM_PFN_ERR_MASK) 60 #define KVM_PFN_ERR_FAULT (KVM_PFN_ERR_MASK)
61 #define KVM_PFN_ERR_HWPOISON (KVM_PFN_ERR_MASK + 1) 61 #define KVM_PFN_ERR_HWPOISON (KVM_PFN_ERR_MASK + 1)
62 #define KVM_PFN_ERR_RO_FAULT (KVM_PFN_ERR_MASK + 2) 62 #define KVM_PFN_ERR_RO_FAULT (KVM_PFN_ERR_MASK + 2)
63 63
64 /* 64 /*
65 * error pfns indicate that the gfn is in slot but faild to 65 * error pfns indicate that the gfn is in slot but faild to
66 * translate it to pfn on host. 66 * translate it to pfn on host.
67 */ 67 */
68 static inline bool is_error_pfn(pfn_t pfn) 68 static inline bool is_error_pfn(pfn_t pfn)
69 { 69 {
70 return !!(pfn & KVM_PFN_ERR_MASK); 70 return !!(pfn & KVM_PFN_ERR_MASK);
71 } 71 }
72 72
73 /* 73 /*
74 * error_noslot pfns indicate that the gfn can not be 74 * error_noslot pfns indicate that the gfn can not be
75 * translated to pfn - it is not in slot or failed to 75 * translated to pfn - it is not in slot or failed to
76 * translate it to pfn. 76 * translate it to pfn.
77 */ 77 */
78 static inline bool is_error_noslot_pfn(pfn_t pfn) 78 static inline bool is_error_noslot_pfn(pfn_t pfn)
79 { 79 {
80 return !!(pfn & KVM_PFN_ERR_NOSLOT_MASK); 80 return !!(pfn & KVM_PFN_ERR_NOSLOT_MASK);
81 } 81 }
82 82
83 /* noslot pfn indicates that the gfn is not in slot. */ 83 /* noslot pfn indicates that the gfn is not in slot. */
84 static inline bool is_noslot_pfn(pfn_t pfn) 84 static inline bool is_noslot_pfn(pfn_t pfn)
85 { 85 {
86 return pfn == KVM_PFN_NOSLOT; 86 return pfn == KVM_PFN_NOSLOT;
87 } 87 }
88 88
89 #define KVM_HVA_ERR_BAD (PAGE_OFFSET) 89 #define KVM_HVA_ERR_BAD (PAGE_OFFSET)
90 #define KVM_HVA_ERR_RO_BAD (PAGE_OFFSET + PAGE_SIZE) 90 #define KVM_HVA_ERR_RO_BAD (PAGE_OFFSET + PAGE_SIZE)
91 91
92 static inline bool kvm_is_error_hva(unsigned long addr) 92 static inline bool kvm_is_error_hva(unsigned long addr)
93 { 93 {
94 return addr >= PAGE_OFFSET; 94 return addr >= PAGE_OFFSET;
95 } 95 }
96 96
97 #define KVM_ERR_PTR_BAD_PAGE (ERR_PTR(-ENOENT)) 97 #define KVM_ERR_PTR_BAD_PAGE (ERR_PTR(-ENOENT))
98 98
99 static inline bool is_error_page(struct page *page) 99 static inline bool is_error_page(struct page *page)
100 { 100 {
101 return IS_ERR(page); 101 return IS_ERR(page);
102 } 102 }
103 103
104 /* 104 /*
105 * vcpu->requests bit members 105 * vcpu->requests bit members
106 */ 106 */
107 #define KVM_REQ_TLB_FLUSH 0 107 #define KVM_REQ_TLB_FLUSH 0
108 #define KVM_REQ_MIGRATE_TIMER 1 108 #define KVM_REQ_MIGRATE_TIMER 1
109 #define KVM_REQ_REPORT_TPR_ACCESS 2 109 #define KVM_REQ_REPORT_TPR_ACCESS 2
110 #define KVM_REQ_MMU_RELOAD 3 110 #define KVM_REQ_MMU_RELOAD 3
111 #define KVM_REQ_TRIPLE_FAULT 4 111 #define KVM_REQ_TRIPLE_FAULT 4
112 #define KVM_REQ_PENDING_TIMER 5 112 #define KVM_REQ_PENDING_TIMER 5
113 #define KVM_REQ_UNHALT 6 113 #define KVM_REQ_UNHALT 6
114 #define KVM_REQ_MMU_SYNC 7 114 #define KVM_REQ_MMU_SYNC 7
115 #define KVM_REQ_CLOCK_UPDATE 8 115 #define KVM_REQ_CLOCK_UPDATE 8
116 #define KVM_REQ_KICK 9 116 #define KVM_REQ_KICK 9
117 #define KVM_REQ_DEACTIVATE_FPU 10 117 #define KVM_REQ_DEACTIVATE_FPU 10
118 #define KVM_REQ_EVENT 11 118 #define KVM_REQ_EVENT 11
119 #define KVM_REQ_APF_HALT 12 119 #define KVM_REQ_APF_HALT 12
120 #define KVM_REQ_STEAL_UPDATE 13 120 #define KVM_REQ_STEAL_UPDATE 13
121 #define KVM_REQ_NMI 14 121 #define KVM_REQ_NMI 14
122 #define KVM_REQ_IMMEDIATE_EXIT 15 122 #define KVM_REQ_IMMEDIATE_EXIT 15
123 #define KVM_REQ_PMU 16 123 #define KVM_REQ_PMU 16
124 #define KVM_REQ_PMI 17 124 #define KVM_REQ_PMI 17
125 #define KVM_REQ_WATCHDOG 18 125 #define KVM_REQ_WATCHDOG 18
126 #define KVM_REQ_MASTERCLOCK_UPDATE 19 126 #define KVM_REQ_MASTERCLOCK_UPDATE 19
127 #define KVM_REQ_MCLOCK_INPROGRESS 20 127 #define KVM_REQ_MCLOCK_INPROGRESS 20
128 #define KVM_REQ_EPR_EXIT 21 128 #define KVM_REQ_EPR_EXIT 21
129 #define KVM_REQ_EOIBITMAP 22 129 #define KVM_REQ_EOIBITMAP 22
130 130
131 #define KVM_USERSPACE_IRQ_SOURCE_ID 0 131 #define KVM_USERSPACE_IRQ_SOURCE_ID 0
132 #define KVM_IRQFD_RESAMPLE_IRQ_SOURCE_ID 1 132 #define KVM_IRQFD_RESAMPLE_IRQ_SOURCE_ID 1
133 133
134 struct kvm; 134 struct kvm;
135 struct kvm_vcpu; 135 struct kvm_vcpu;
136 extern struct kmem_cache *kvm_vcpu_cache; 136 extern struct kmem_cache *kvm_vcpu_cache;
137 137
138 extern raw_spinlock_t kvm_lock; 138 extern raw_spinlock_t kvm_lock;
139 extern struct list_head vm_list; 139 extern struct list_head vm_list;
140 140
141 struct kvm_io_range { 141 struct kvm_io_range {
142 gpa_t addr; 142 gpa_t addr;
143 int len; 143 int len;
144 struct kvm_io_device *dev; 144 struct kvm_io_device *dev;
145 }; 145 };
146 146
147 #define NR_IOBUS_DEVS 1000 147 #define NR_IOBUS_DEVS 1000
148 148
149 struct kvm_io_bus { 149 struct kvm_io_bus {
150 int dev_count; 150 int dev_count;
151 struct kvm_io_range range[]; 151 struct kvm_io_range range[];
152 }; 152 };
153 153
154 enum kvm_bus { 154 enum kvm_bus {
155 KVM_MMIO_BUS, 155 KVM_MMIO_BUS,
156 KVM_PIO_BUS, 156 KVM_PIO_BUS,
157 KVM_VIRTIO_CCW_NOTIFY_BUS, 157 KVM_VIRTIO_CCW_NOTIFY_BUS,
158 KVM_NR_BUSES 158 KVM_NR_BUSES
159 }; 159 };
160 160
161 int kvm_io_bus_write(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr, 161 int kvm_io_bus_write(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr,
162 int len, const void *val); 162 int len, const void *val);
163 int kvm_io_bus_read(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr, int len, 163 int kvm_io_bus_read(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr, int len,
164 void *val); 164 void *val);
165 int kvm_io_bus_register_dev(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr, 165 int kvm_io_bus_register_dev(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr,
166 int len, struct kvm_io_device *dev); 166 int len, struct kvm_io_device *dev);
167 int kvm_io_bus_unregister_dev(struct kvm *kvm, enum kvm_bus bus_idx, 167 int kvm_io_bus_unregister_dev(struct kvm *kvm, enum kvm_bus bus_idx,
168 struct kvm_io_device *dev); 168 struct kvm_io_device *dev);
169 169
170 #ifdef CONFIG_KVM_ASYNC_PF 170 #ifdef CONFIG_KVM_ASYNC_PF
171 struct kvm_async_pf { 171 struct kvm_async_pf {
172 struct work_struct work; 172 struct work_struct work;
173 struct list_head link; 173 struct list_head link;
174 struct list_head queue; 174 struct list_head queue;
175 struct kvm_vcpu *vcpu; 175 struct kvm_vcpu *vcpu;
176 struct mm_struct *mm; 176 struct mm_struct *mm;
177 gva_t gva; 177 gva_t gva;
178 unsigned long addr; 178 unsigned long addr;
179 struct kvm_arch_async_pf arch; 179 struct kvm_arch_async_pf arch;
180 struct page *page; 180 struct page *page;
181 bool done; 181 bool done;
182 }; 182 };
183 183
184 void kvm_clear_async_pf_completion_queue(struct kvm_vcpu *vcpu); 184 void kvm_clear_async_pf_completion_queue(struct kvm_vcpu *vcpu);
185 void kvm_check_async_pf_completion(struct kvm_vcpu *vcpu); 185 void kvm_check_async_pf_completion(struct kvm_vcpu *vcpu);
186 int kvm_setup_async_pf(struct kvm_vcpu *vcpu, gva_t gva, gfn_t gfn, 186 int kvm_setup_async_pf(struct kvm_vcpu *vcpu, gva_t gva, gfn_t gfn,
187 struct kvm_arch_async_pf *arch); 187 struct kvm_arch_async_pf *arch);
188 int kvm_async_pf_wakeup_all(struct kvm_vcpu *vcpu); 188 int kvm_async_pf_wakeup_all(struct kvm_vcpu *vcpu);
189 #endif 189 #endif
190 190
191 enum { 191 enum {
192 OUTSIDE_GUEST_MODE, 192 OUTSIDE_GUEST_MODE,
193 IN_GUEST_MODE, 193 IN_GUEST_MODE,
194 EXITING_GUEST_MODE, 194 EXITING_GUEST_MODE,
195 READING_SHADOW_PAGE_TABLES, 195 READING_SHADOW_PAGE_TABLES,
196 }; 196 };
197 197
198 /* 198 /*
199 * Sometimes a large or cross-page mmio needs to be broken up into separate 199 * Sometimes a large or cross-page mmio needs to be broken up into separate
200 * exits for userspace servicing. 200 * exits for userspace servicing.
201 */ 201 */
202 struct kvm_mmio_fragment { 202 struct kvm_mmio_fragment {
203 gpa_t gpa; 203 gpa_t gpa;
204 void *data; 204 void *data;
205 unsigned len; 205 unsigned len;
206 }; 206 };
207 207
208 struct kvm_vcpu { 208 struct kvm_vcpu {
209 struct kvm *kvm; 209 struct kvm *kvm;
210 #ifdef CONFIG_PREEMPT_NOTIFIERS 210 #ifdef CONFIG_PREEMPT_NOTIFIERS
211 struct preempt_notifier preempt_notifier; 211 struct preempt_notifier preempt_notifier;
212 #endif 212 #endif
213 int cpu; 213 int cpu;
214 int vcpu_id; 214 int vcpu_id;
215 int srcu_idx; 215 int srcu_idx;
216 int mode; 216 int mode;
217 unsigned long requests; 217 unsigned long requests;
218 unsigned long guest_debug; 218 unsigned long guest_debug;
219 219
220 struct mutex mutex; 220 struct mutex mutex;
221 struct kvm_run *run; 221 struct kvm_run *run;
222 222
223 int fpu_active; 223 int fpu_active;
224 int guest_fpu_loaded, guest_xcr0_loaded; 224 int guest_fpu_loaded, guest_xcr0_loaded;
225 wait_queue_head_t wq; 225 wait_queue_head_t wq;
226 struct pid *pid; 226 struct pid *pid;
227 int sigset_active; 227 int sigset_active;
228 sigset_t sigset; 228 sigset_t sigset;
229 struct kvm_vcpu_stat stat; 229 struct kvm_vcpu_stat stat;
230 230
231 #ifdef CONFIG_HAS_IOMEM 231 #ifdef CONFIG_HAS_IOMEM
232 int mmio_needed; 232 int mmio_needed;
233 int mmio_read_completed; 233 int mmio_read_completed;
234 int mmio_is_write; 234 int mmio_is_write;
235 int mmio_cur_fragment; 235 int mmio_cur_fragment;
236 int mmio_nr_fragments; 236 int mmio_nr_fragments;
237 struct kvm_mmio_fragment mmio_fragments[KVM_MAX_MMIO_FRAGMENTS]; 237 struct kvm_mmio_fragment mmio_fragments[KVM_MAX_MMIO_FRAGMENTS];
238 #endif 238 #endif
239 239
240 #ifdef CONFIG_KVM_ASYNC_PF 240 #ifdef CONFIG_KVM_ASYNC_PF
241 struct { 241 struct {
242 u32 queued; 242 u32 queued;
243 struct list_head queue; 243 struct list_head queue;
244 struct list_head done; 244 struct list_head done;
245 spinlock_t lock; 245 spinlock_t lock;
246 } async_pf; 246 } async_pf;
247 #endif 247 #endif
248 248
249 #ifdef CONFIG_HAVE_KVM_CPU_RELAX_INTERCEPT 249 #ifdef CONFIG_HAVE_KVM_CPU_RELAX_INTERCEPT
250 /* 250 /*
251 * Cpu relax intercept or pause loop exit optimization 251 * Cpu relax intercept or pause loop exit optimization
252 * in_spin_loop: set when a vcpu does a pause loop exit 252 * in_spin_loop: set when a vcpu does a pause loop exit
253 * or cpu relax intercepted. 253 * or cpu relax intercepted.
254 * dy_eligible: indicates whether vcpu is eligible for directed yield. 254 * dy_eligible: indicates whether vcpu is eligible for directed yield.
255 */ 255 */
256 struct { 256 struct {
257 bool in_spin_loop; 257 bool in_spin_loop;
258 bool dy_eligible; 258 bool dy_eligible;
259 } spin_loop; 259 } spin_loop;
260 #endif 260 #endif
261 bool preempted; 261 bool preempted;
262 struct kvm_vcpu_arch arch; 262 struct kvm_vcpu_arch arch;
263 }; 263 };
264 264
265 static inline int kvm_vcpu_exiting_guest_mode(struct kvm_vcpu *vcpu) 265 static inline int kvm_vcpu_exiting_guest_mode(struct kvm_vcpu *vcpu)
266 { 266 {
267 return cmpxchg(&vcpu->mode, IN_GUEST_MODE, EXITING_GUEST_MODE); 267 return cmpxchg(&vcpu->mode, IN_GUEST_MODE, EXITING_GUEST_MODE);
268 } 268 }
269 269
270 /* 270 /*
271 * Some of the bitops functions do not support too long bitmaps. 271 * Some of the bitops functions do not support too long bitmaps.
272 * This number must be determined not to exceed such limits. 272 * This number must be determined not to exceed such limits.
273 */ 273 */
274 #define KVM_MEM_MAX_NR_PAGES ((1UL << 31) - 1) 274 #define KVM_MEM_MAX_NR_PAGES ((1UL << 31) - 1)
275 275
276 struct kvm_memory_slot { 276 struct kvm_memory_slot {
277 gfn_t base_gfn; 277 gfn_t base_gfn;
278 unsigned long npages; 278 unsigned long npages;
279 unsigned long *dirty_bitmap; 279 unsigned long *dirty_bitmap;
280 struct kvm_arch_memory_slot arch; 280 struct kvm_arch_memory_slot arch;
281 unsigned long userspace_addr; 281 unsigned long userspace_addr;
282 u32 flags; 282 u32 flags;
283 short id; 283 short id;
284 }; 284 };
285 285
286 static inline unsigned long kvm_dirty_bitmap_bytes(struct kvm_memory_slot *memslot) 286 static inline unsigned long kvm_dirty_bitmap_bytes(struct kvm_memory_slot *memslot)
287 { 287 {
288 return ALIGN(memslot->npages, BITS_PER_LONG) / 8; 288 return ALIGN(memslot->npages, BITS_PER_LONG) / 8;
289 } 289 }
290 290
291 struct kvm_kernel_irq_routing_entry { 291 struct kvm_kernel_irq_routing_entry {
292 u32 gsi; 292 u32 gsi;
293 u32 type; 293 u32 type;
294 int (*set)(struct kvm_kernel_irq_routing_entry *e, 294 int (*set)(struct kvm_kernel_irq_routing_entry *e,
295 struct kvm *kvm, int irq_source_id, int level); 295 struct kvm *kvm, int irq_source_id, int level);
296 union { 296 union {
297 struct { 297 struct {
298 unsigned irqchip; 298 unsigned irqchip;
299 unsigned pin; 299 unsigned pin;
300 } irqchip; 300 } irqchip;
301 struct msi_msg msi; 301 struct msi_msg msi;
302 }; 302 };
303 struct hlist_node link; 303 struct hlist_node link;
304 }; 304 };
305 305
306 #ifdef __KVM_HAVE_IOAPIC 306 #ifdef __KVM_HAVE_IOAPIC
307 307
308 struct kvm_irq_routing_table { 308 struct kvm_irq_routing_table {
309 int chip[KVM_NR_IRQCHIPS][KVM_IOAPIC_NUM_PINS]; 309 int chip[KVM_NR_IRQCHIPS][KVM_IOAPIC_NUM_PINS];
310 struct kvm_kernel_irq_routing_entry *rt_entries; 310 struct kvm_kernel_irq_routing_entry *rt_entries;
311 u32 nr_rt_entries; 311 u32 nr_rt_entries;
312 /* 312 /*
313 * Array indexed by gsi. Each entry contains list of irq chips 313 * Array indexed by gsi. Each entry contains list of irq chips
314 * the gsi is connected to. 314 * the gsi is connected to.
315 */ 315 */
316 struct hlist_head map[0]; 316 struct hlist_head map[0];
317 }; 317 };
318 318
319 #else 319 #else
320 320
321 struct kvm_irq_routing_table {}; 321 struct kvm_irq_routing_table {};
322 322
323 #endif 323 #endif
324 324
325 #ifndef KVM_PRIVATE_MEM_SLOTS 325 #ifndef KVM_PRIVATE_MEM_SLOTS
326 #define KVM_PRIVATE_MEM_SLOTS 0 326 #define KVM_PRIVATE_MEM_SLOTS 0
327 #endif 327 #endif
328 328
329 #ifndef KVM_MEM_SLOTS_NUM 329 #ifndef KVM_MEM_SLOTS_NUM
330 #define KVM_MEM_SLOTS_NUM (KVM_USER_MEM_SLOTS + KVM_PRIVATE_MEM_SLOTS) 330 #define KVM_MEM_SLOTS_NUM (KVM_USER_MEM_SLOTS + KVM_PRIVATE_MEM_SLOTS)
331 #endif 331 #endif
332 332
333 /* 333 /*
334 * Note: 334 * Note:
335 * memslots are not sorted by id anymore, please use id_to_memslot() 335 * memslots are not sorted by id anymore, please use id_to_memslot()
336 * to get the memslot by its id. 336 * to get the memslot by its id.
337 */ 337 */
338 struct kvm_memslots { 338 struct kvm_memslots {
339 u64 generation; 339 u64 generation;
340 struct kvm_memory_slot memslots[KVM_MEM_SLOTS_NUM]; 340 struct kvm_memory_slot memslots[KVM_MEM_SLOTS_NUM];
341 /* The mapping table from slot id to the index in memslots[]. */ 341 /* The mapping table from slot id to the index in memslots[]. */
342 short id_to_index[KVM_MEM_SLOTS_NUM]; 342 short id_to_index[KVM_MEM_SLOTS_NUM];
343 }; 343 };
344 344
345 struct kvm { 345 struct kvm {
346 spinlock_t mmu_lock; 346 spinlock_t mmu_lock;
347 struct mutex slots_lock; 347 struct mutex slots_lock;
348 struct mm_struct *mm; /* userspace tied to this vm */ 348 struct mm_struct *mm; /* userspace tied to this vm */
349 struct kvm_memslots *memslots; 349 struct kvm_memslots *memslots;
350 struct srcu_struct srcu; 350 struct srcu_struct srcu;
351 #ifdef CONFIG_KVM_APIC_ARCHITECTURE 351 #ifdef CONFIG_KVM_APIC_ARCHITECTURE
352 u32 bsp_vcpu_id; 352 u32 bsp_vcpu_id;
353 #endif 353 #endif
354 struct kvm_vcpu *vcpus[KVM_MAX_VCPUS]; 354 struct kvm_vcpu *vcpus[KVM_MAX_VCPUS];
355 atomic_t online_vcpus; 355 atomic_t online_vcpus;
356 int last_boosted_vcpu; 356 int last_boosted_vcpu;
357 struct list_head vm_list; 357 struct list_head vm_list;
358 struct mutex lock; 358 struct mutex lock;
359 struct kvm_io_bus *buses[KVM_NR_BUSES]; 359 struct kvm_io_bus *buses[KVM_NR_BUSES];
360 #ifdef CONFIG_HAVE_KVM_EVENTFD 360 #ifdef CONFIG_HAVE_KVM_EVENTFD
361 struct { 361 struct {
362 spinlock_t lock; 362 spinlock_t lock;
363 struct list_head items; 363 struct list_head items;
364 struct list_head resampler_list; 364 struct list_head resampler_list;
365 struct mutex resampler_lock; 365 struct mutex resampler_lock;
366 } irqfds; 366 } irqfds;
367 struct list_head ioeventfds; 367 struct list_head ioeventfds;
368 #endif 368 #endif
369 struct kvm_vm_stat stat; 369 struct kvm_vm_stat stat;
370 struct kvm_arch arch; 370 struct kvm_arch arch;
371 atomic_t users_count; 371 atomic_t users_count;
372 #ifdef KVM_COALESCED_MMIO_PAGE_OFFSET 372 #ifdef KVM_COALESCED_MMIO_PAGE_OFFSET
373 struct kvm_coalesced_mmio_ring *coalesced_mmio_ring; 373 struct kvm_coalesced_mmio_ring *coalesced_mmio_ring;
374 spinlock_t ring_lock; 374 spinlock_t ring_lock;
375 struct list_head coalesced_zones; 375 struct list_head coalesced_zones;
376 #endif 376 #endif
377 377
378 struct mutex irq_lock; 378 struct mutex irq_lock;
379 #ifdef CONFIG_HAVE_KVM_IRQCHIP 379 #ifdef CONFIG_HAVE_KVM_IRQCHIP
380 /* 380 /*
381 * Update side is protected by irq_lock and, 381 * Update side is protected by irq_lock and,
382 * if configured, irqfds.lock. 382 * if configured, irqfds.lock.
383 */ 383 */
384 struct kvm_irq_routing_table __rcu *irq_routing; 384 struct kvm_irq_routing_table __rcu *irq_routing;
385 struct hlist_head mask_notifier_list; 385 struct hlist_head mask_notifier_list;
386 struct hlist_head irq_ack_notifier_list; 386 struct hlist_head irq_ack_notifier_list;
387 #endif 387 #endif
388 388
389 #if defined(CONFIG_MMU_NOTIFIER) && defined(KVM_ARCH_WANT_MMU_NOTIFIER) 389 #if defined(CONFIG_MMU_NOTIFIER) && defined(KVM_ARCH_WANT_MMU_NOTIFIER)
390 struct mmu_notifier mmu_notifier; 390 struct mmu_notifier mmu_notifier;
391 unsigned long mmu_notifier_seq; 391 unsigned long mmu_notifier_seq;
392 long mmu_notifier_count; 392 long mmu_notifier_count;
393 #endif 393 #endif
394 long tlbs_dirty; 394 long tlbs_dirty;
395 }; 395 };
396 396
397 #define kvm_err(fmt, ...) \ 397 #define kvm_err(fmt, ...) \
398 pr_err("kvm [%i]: " fmt, task_pid_nr(current), ## __VA_ARGS__) 398 pr_err("kvm [%i]: " fmt, task_pid_nr(current), ## __VA_ARGS__)
399 #define kvm_info(fmt, ...) \ 399 #define kvm_info(fmt, ...) \
400 pr_info("kvm [%i]: " fmt, task_pid_nr(current), ## __VA_ARGS__) 400 pr_info("kvm [%i]: " fmt, task_pid_nr(current), ## __VA_ARGS__)
401 #define kvm_debug(fmt, ...) \ 401 #define kvm_debug(fmt, ...) \
402 pr_debug("kvm [%i]: " fmt, task_pid_nr(current), ## __VA_ARGS__) 402 pr_debug("kvm [%i]: " fmt, task_pid_nr(current), ## __VA_ARGS__)
403 #define kvm_pr_unimpl(fmt, ...) \ 403 #define kvm_pr_unimpl(fmt, ...) \
404 pr_err_ratelimited("kvm [%i]: " fmt, \ 404 pr_err_ratelimited("kvm [%i]: " fmt, \
405 task_tgid_nr(current), ## __VA_ARGS__) 405 task_tgid_nr(current), ## __VA_ARGS__)
406 406
407 /* The guest did something we don't support. */ 407 /* The guest did something we don't support. */
408 #define vcpu_unimpl(vcpu, fmt, ...) \ 408 #define vcpu_unimpl(vcpu, fmt, ...) \
409 kvm_pr_unimpl("vcpu%i " fmt, (vcpu)->vcpu_id, ## __VA_ARGS__) 409 kvm_pr_unimpl("vcpu%i " fmt, (vcpu)->vcpu_id, ## __VA_ARGS__)
410 410
411 static inline struct kvm_vcpu *kvm_get_vcpu(struct kvm *kvm, int i) 411 static inline struct kvm_vcpu *kvm_get_vcpu(struct kvm *kvm, int i)
412 { 412 {
413 smp_rmb(); 413 smp_rmb();
414 return kvm->vcpus[i]; 414 return kvm->vcpus[i];
415 } 415 }
416 416
417 #define kvm_for_each_vcpu(idx, vcpup, kvm) \ 417 #define kvm_for_each_vcpu(idx, vcpup, kvm) \
418 for (idx = 0; \ 418 for (idx = 0; \
419 idx < atomic_read(&kvm->online_vcpus) && \ 419 idx < atomic_read(&kvm->online_vcpus) && \
420 (vcpup = kvm_get_vcpu(kvm, idx)) != NULL; \ 420 (vcpup = kvm_get_vcpu(kvm, idx)) != NULL; \
421 idx++) 421 idx++)
422 422
423 #define kvm_for_each_memslot(memslot, slots) \ 423 #define kvm_for_each_memslot(memslot, slots) \
424 for (memslot = &slots->memslots[0]; \ 424 for (memslot = &slots->memslots[0]; \
425 memslot < slots->memslots + KVM_MEM_SLOTS_NUM && memslot->npages;\ 425 memslot < slots->memslots + KVM_MEM_SLOTS_NUM && memslot->npages;\
426 memslot++) 426 memslot++)
427 427
428 int kvm_vcpu_init(struct kvm_vcpu *vcpu, struct kvm *kvm, unsigned id); 428 int kvm_vcpu_init(struct kvm_vcpu *vcpu, struct kvm *kvm, unsigned id);
429 void kvm_vcpu_uninit(struct kvm_vcpu *vcpu); 429 void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
430 430
431 int __must_check vcpu_load(struct kvm_vcpu *vcpu); 431 int __must_check vcpu_load(struct kvm_vcpu *vcpu);
432 void vcpu_put(struct kvm_vcpu *vcpu); 432 void vcpu_put(struct kvm_vcpu *vcpu);
433 433
434 #ifdef __KVM_HAVE_IOAPIC 434 #ifdef __KVM_HAVE_IOAPIC
435 int kvm_irqfd_init(void); 435 int kvm_irqfd_init(void);
436 void kvm_irqfd_exit(void); 436 void kvm_irqfd_exit(void);
437 #else 437 #else
438 static inline int kvm_irqfd_init(void) 438 static inline int kvm_irqfd_init(void)
439 { 439 {
440 return 0; 440 return 0;
441 } 441 }
442 442
443 static inline void kvm_irqfd_exit(void) 443 static inline void kvm_irqfd_exit(void)
444 { 444 {
445 } 445 }
446 #endif 446 #endif
447 int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align, 447 int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
448 struct module *module); 448 struct module *module);
449 void kvm_exit(void); 449 void kvm_exit(void);
450 450
451 void kvm_get_kvm(struct kvm *kvm); 451 void kvm_get_kvm(struct kvm *kvm);
452 void kvm_put_kvm(struct kvm *kvm); 452 void kvm_put_kvm(struct kvm *kvm);
453 void update_memslots(struct kvm_memslots *slots, struct kvm_memory_slot *new, 453 void update_memslots(struct kvm_memslots *slots, struct kvm_memory_slot *new,
454 u64 last_generation); 454 u64 last_generation);
455 455
456 static inline struct kvm_memslots *kvm_memslots(struct kvm *kvm) 456 static inline struct kvm_memslots *kvm_memslots(struct kvm *kvm)
457 { 457 {
458 return rcu_dereference_check(kvm->memslots, 458 return rcu_dereference_check(kvm->memslots,
459 srcu_read_lock_held(&kvm->srcu) 459 srcu_read_lock_held(&kvm->srcu)
460 || lockdep_is_held(&kvm->slots_lock)); 460 || lockdep_is_held(&kvm->slots_lock));
461 } 461 }
462 462
463 static inline struct kvm_memory_slot * 463 static inline struct kvm_memory_slot *
464 id_to_memslot(struct kvm_memslots *slots, int id) 464 id_to_memslot(struct kvm_memslots *slots, int id)
465 { 465 {
466 int index = slots->id_to_index[id]; 466 int index = slots->id_to_index[id];
467 struct kvm_memory_slot *slot; 467 struct kvm_memory_slot *slot;
468 468
469 slot = &slots->memslots[index]; 469 slot = &slots->memslots[index];
470 470
471 WARN_ON(slot->id != id); 471 WARN_ON(slot->id != id);
472 return slot; 472 return slot;
473 } 473 }
474 474
475 /* 475 /*
476 * KVM_SET_USER_MEMORY_REGION ioctl allows the following operations: 476 * KVM_SET_USER_MEMORY_REGION ioctl allows the following operations:
477 * - create a new memory slot 477 * - create a new memory slot
478 * - delete an existing memory slot 478 * - delete an existing memory slot
479 * - modify an existing memory slot 479 * - modify an existing memory slot
480 * -- move it in the guest physical memory space 480 * -- move it in the guest physical memory space
481 * -- just change its flags 481 * -- just change its flags
482 * 482 *
483 * Since flags can be changed by some of these operations, the following 483 * Since flags can be changed by some of these operations, the following
484 * differentiation is the best we can do for __kvm_set_memory_region(): 484 * differentiation is the best we can do for __kvm_set_memory_region():
485 */ 485 */
486 enum kvm_mr_change { 486 enum kvm_mr_change {
487 KVM_MR_CREATE, 487 KVM_MR_CREATE,
488 KVM_MR_DELETE, 488 KVM_MR_DELETE,
489 KVM_MR_MOVE, 489 KVM_MR_MOVE,
490 KVM_MR_FLAGS_ONLY, 490 KVM_MR_FLAGS_ONLY,
491 }; 491 };
492 492
493 int kvm_set_memory_region(struct kvm *kvm, 493 int kvm_set_memory_region(struct kvm *kvm,
494 struct kvm_userspace_memory_region *mem); 494 struct kvm_userspace_memory_region *mem);
495 int __kvm_set_memory_region(struct kvm *kvm, 495 int __kvm_set_memory_region(struct kvm *kvm,
496 struct kvm_userspace_memory_region *mem); 496 struct kvm_userspace_memory_region *mem);
497 void kvm_arch_free_memslot(struct kvm_memory_slot *free, 497 void kvm_arch_free_memslot(struct kvm_memory_slot *free,
498 struct kvm_memory_slot *dont); 498 struct kvm_memory_slot *dont);
499 int kvm_arch_create_memslot(struct kvm_memory_slot *slot, unsigned long npages); 499 int kvm_arch_create_memslot(struct kvm_memory_slot *slot, unsigned long npages);
500 int kvm_arch_prepare_memory_region(struct kvm *kvm, 500 int kvm_arch_prepare_memory_region(struct kvm *kvm,
501 struct kvm_memory_slot *memslot, 501 struct kvm_memory_slot *memslot,
502 struct kvm_userspace_memory_region *mem, 502 struct kvm_userspace_memory_region *mem,
503 enum kvm_mr_change change); 503 enum kvm_mr_change change);
504 void kvm_arch_commit_memory_region(struct kvm *kvm, 504 void kvm_arch_commit_memory_region(struct kvm *kvm,
505 struct kvm_userspace_memory_region *mem, 505 struct kvm_userspace_memory_region *mem,
506 const struct kvm_memory_slot *old, 506 const struct kvm_memory_slot *old,
507 enum kvm_mr_change change); 507 enum kvm_mr_change change);
508 bool kvm_largepages_enabled(void); 508 bool kvm_largepages_enabled(void);
509 void kvm_disable_largepages(void); 509 void kvm_disable_largepages(void);
510 /* flush all memory translations */ 510 /* flush all memory translations */
511 void kvm_arch_flush_shadow_all(struct kvm *kvm); 511 void kvm_arch_flush_shadow_all(struct kvm *kvm);
512 /* flush memory translations pointing to 'slot' */ 512 /* flush memory translations pointing to 'slot' */
513 void kvm_arch_flush_shadow_memslot(struct kvm *kvm, 513 void kvm_arch_flush_shadow_memslot(struct kvm *kvm,
514 struct kvm_memory_slot *slot); 514 struct kvm_memory_slot *slot);
515 515
516 int gfn_to_page_many_atomic(struct kvm *kvm, gfn_t gfn, struct page **pages, 516 int gfn_to_page_many_atomic(struct kvm *kvm, gfn_t gfn, struct page **pages,
517 int nr_pages); 517 int nr_pages);
518 518
519 struct page *gfn_to_page(struct kvm *kvm, gfn_t gfn); 519 struct page *gfn_to_page(struct kvm *kvm, gfn_t gfn);
520 unsigned long gfn_to_hva(struct kvm *kvm, gfn_t gfn); 520 unsigned long gfn_to_hva(struct kvm *kvm, gfn_t gfn);
521 unsigned long gfn_to_hva_memslot(struct kvm_memory_slot *slot, gfn_t gfn); 521 unsigned long gfn_to_hva_memslot(struct kvm_memory_slot *slot, gfn_t gfn);
522 void kvm_release_page_clean(struct page *page); 522 void kvm_release_page_clean(struct page *page);
523 void kvm_release_page_dirty(struct page *page); 523 void kvm_release_page_dirty(struct page *page);
524 void kvm_set_page_dirty(struct page *page); 524 void kvm_set_page_dirty(struct page *page);
525 void kvm_set_page_accessed(struct page *page); 525 void kvm_set_page_accessed(struct page *page);
526 526
527 pfn_t gfn_to_pfn_atomic(struct kvm *kvm, gfn_t gfn); 527 pfn_t gfn_to_pfn_atomic(struct kvm *kvm, gfn_t gfn);
528 pfn_t gfn_to_pfn_async(struct kvm *kvm, gfn_t gfn, bool *async, 528 pfn_t gfn_to_pfn_async(struct kvm *kvm, gfn_t gfn, bool *async,
529 bool write_fault, bool *writable); 529 bool write_fault, bool *writable);
530 pfn_t gfn_to_pfn(struct kvm *kvm, gfn_t gfn); 530 pfn_t gfn_to_pfn(struct kvm *kvm, gfn_t gfn);
531 pfn_t gfn_to_pfn_prot(struct kvm *kvm, gfn_t gfn, bool write_fault, 531 pfn_t gfn_to_pfn_prot(struct kvm *kvm, gfn_t gfn, bool write_fault,
532 bool *writable); 532 bool *writable);
533 pfn_t gfn_to_pfn_memslot(struct kvm_memory_slot *slot, gfn_t gfn); 533 pfn_t gfn_to_pfn_memslot(struct kvm_memory_slot *slot, gfn_t gfn);
534 pfn_t gfn_to_pfn_memslot_atomic(struct kvm_memory_slot *slot, gfn_t gfn); 534 pfn_t gfn_to_pfn_memslot_atomic(struct kvm_memory_slot *slot, gfn_t gfn);
535 535
536 void kvm_release_pfn_dirty(pfn_t pfn); 536 void kvm_release_pfn_dirty(pfn_t pfn);
537 void kvm_release_pfn_clean(pfn_t pfn); 537 void kvm_release_pfn_clean(pfn_t pfn);
538 void kvm_set_pfn_dirty(pfn_t pfn); 538 void kvm_set_pfn_dirty(pfn_t pfn);
539 void kvm_set_pfn_accessed(pfn_t pfn); 539 void kvm_set_pfn_accessed(pfn_t pfn);
540 void kvm_get_pfn(pfn_t pfn); 540 void kvm_get_pfn(pfn_t pfn);
541 541
542 int kvm_read_guest_page(struct kvm *kvm, gfn_t gfn, void *data, int offset, 542 int kvm_read_guest_page(struct kvm *kvm, gfn_t gfn, void *data, int offset,
543 int len); 543 int len);
544 int kvm_read_guest_atomic(struct kvm *kvm, gpa_t gpa, void *data, 544 int kvm_read_guest_atomic(struct kvm *kvm, gpa_t gpa, void *data,
545 unsigned long len); 545 unsigned long len);
546 int kvm_read_guest(struct kvm *kvm, gpa_t gpa, void *data, unsigned long len); 546 int kvm_read_guest(struct kvm *kvm, gpa_t gpa, void *data, unsigned long len);
547 int kvm_read_guest_cached(struct kvm *kvm, struct gfn_to_hva_cache *ghc, 547 int kvm_read_guest_cached(struct kvm *kvm, struct gfn_to_hva_cache *ghc,
548 void *data, unsigned long len); 548 void *data, unsigned long len);
549 int kvm_write_guest_page(struct kvm *kvm, gfn_t gfn, const void *data, 549 int kvm_write_guest_page(struct kvm *kvm, gfn_t gfn, const void *data,
550 int offset, int len); 550 int offset, int len);
551 int kvm_write_guest(struct kvm *kvm, gpa_t gpa, const void *data, 551 int kvm_write_guest(struct kvm *kvm, gpa_t gpa, const void *data,
552 unsigned long len); 552 unsigned long len);
553 int kvm_write_guest_cached(struct kvm *kvm, struct gfn_to_hva_cache *ghc, 553 int kvm_write_guest_cached(struct kvm *kvm, struct gfn_to_hva_cache *ghc,
554 void *data, unsigned long len); 554 void *data, unsigned long len);
555 int kvm_gfn_to_hva_cache_init(struct kvm *kvm, struct gfn_to_hva_cache *ghc, 555 int kvm_gfn_to_hva_cache_init(struct kvm *kvm, struct gfn_to_hva_cache *ghc,
556 gpa_t gpa); 556 gpa_t gpa);
557 int kvm_clear_guest_page(struct kvm *kvm, gfn_t gfn, int offset, int len); 557 int kvm_clear_guest_page(struct kvm *kvm, gfn_t gfn, int offset, int len);
558 int kvm_clear_guest(struct kvm *kvm, gpa_t gpa, unsigned long len); 558 int kvm_clear_guest(struct kvm *kvm, gpa_t gpa, unsigned long len);
559 struct kvm_memory_slot *gfn_to_memslot(struct kvm *kvm, gfn_t gfn); 559 struct kvm_memory_slot *gfn_to_memslot(struct kvm *kvm, gfn_t gfn);
560 int kvm_is_visible_gfn(struct kvm *kvm, gfn_t gfn); 560 int kvm_is_visible_gfn(struct kvm *kvm, gfn_t gfn);
561 unsigned long kvm_host_page_size(struct kvm *kvm, gfn_t gfn); 561 unsigned long kvm_host_page_size(struct kvm *kvm, gfn_t gfn);
562 void mark_page_dirty(struct kvm *kvm, gfn_t gfn); 562 void mark_page_dirty(struct kvm *kvm, gfn_t gfn);
563 void mark_page_dirty_in_slot(struct kvm *kvm, struct kvm_memory_slot *memslot, 563 void mark_page_dirty_in_slot(struct kvm *kvm, struct kvm_memory_slot *memslot,
564 gfn_t gfn); 564 gfn_t gfn);
565 565
566 void kvm_vcpu_block(struct kvm_vcpu *vcpu); 566 void kvm_vcpu_block(struct kvm_vcpu *vcpu);
567 void kvm_vcpu_kick(struct kvm_vcpu *vcpu); 567 void kvm_vcpu_kick(struct kvm_vcpu *vcpu);
568 bool kvm_vcpu_yield_to(struct kvm_vcpu *target); 568 bool kvm_vcpu_yield_to(struct kvm_vcpu *target);
569 void kvm_vcpu_on_spin(struct kvm_vcpu *vcpu); 569 void kvm_vcpu_on_spin(struct kvm_vcpu *vcpu);
570 void kvm_resched(struct kvm_vcpu *vcpu); 570 void kvm_resched(struct kvm_vcpu *vcpu);
571 void kvm_load_guest_fpu(struct kvm_vcpu *vcpu); 571 void kvm_load_guest_fpu(struct kvm_vcpu *vcpu);
572 void kvm_put_guest_fpu(struct kvm_vcpu *vcpu); 572 void kvm_put_guest_fpu(struct kvm_vcpu *vcpu);
573 573
574 void kvm_flush_remote_tlbs(struct kvm *kvm); 574 void kvm_flush_remote_tlbs(struct kvm *kvm);
575 void kvm_reload_remote_mmus(struct kvm *kvm); 575 void kvm_reload_remote_mmus(struct kvm *kvm);
576 void kvm_make_mclock_inprogress_request(struct kvm *kvm); 576 void kvm_make_mclock_inprogress_request(struct kvm *kvm);
577 void kvm_make_update_eoibitmap_request(struct kvm *kvm); 577 void kvm_make_update_eoibitmap_request(struct kvm *kvm);
578 578
579 long kvm_arch_dev_ioctl(struct file *filp, 579 long kvm_arch_dev_ioctl(struct file *filp,
580 unsigned int ioctl, unsigned long arg); 580 unsigned int ioctl, unsigned long arg);
581 long kvm_arch_vcpu_ioctl(struct file *filp, 581 long kvm_arch_vcpu_ioctl(struct file *filp,
582 unsigned int ioctl, unsigned long arg); 582 unsigned int ioctl, unsigned long arg);
583 int kvm_arch_vcpu_fault(struct kvm_vcpu *vcpu, struct vm_fault *vmf); 583 int kvm_arch_vcpu_fault(struct kvm_vcpu *vcpu, struct vm_fault *vmf);
584 584
585 int kvm_dev_ioctl_check_extension(long ext); 585 int kvm_dev_ioctl_check_extension(long ext);
586 586
587 int kvm_get_dirty_log(struct kvm *kvm, 587 int kvm_get_dirty_log(struct kvm *kvm,
588 struct kvm_dirty_log *log, int *is_dirty); 588 struct kvm_dirty_log *log, int *is_dirty);
589 int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm, 589 int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm,
590 struct kvm_dirty_log *log); 590 struct kvm_dirty_log *log);
591 591
592 int kvm_vm_ioctl_set_memory_region(struct kvm *kvm, 592 int kvm_vm_ioctl_set_memory_region(struct kvm *kvm,
593 struct kvm_userspace_memory_region *mem); 593 struct kvm_userspace_memory_region *mem);
594 int kvm_vm_ioctl_irq_line(struct kvm *kvm, struct kvm_irq_level *irq_level); 594 int kvm_vm_ioctl_irq_line(struct kvm *kvm, struct kvm_irq_level *irq_level);
595 long kvm_arch_vm_ioctl(struct file *filp, 595 long kvm_arch_vm_ioctl(struct file *filp,
596 unsigned int ioctl, unsigned long arg); 596 unsigned int ioctl, unsigned long arg);
597 597
598 int kvm_arch_vcpu_ioctl_get_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu); 598 int kvm_arch_vcpu_ioctl_get_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu);
599 int kvm_arch_vcpu_ioctl_set_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu); 599 int kvm_arch_vcpu_ioctl_set_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu);
600 600
601 int kvm_arch_vcpu_ioctl_translate(struct kvm_vcpu *vcpu, 601 int kvm_arch_vcpu_ioctl_translate(struct kvm_vcpu *vcpu,
602 struct kvm_translation *tr); 602 struct kvm_translation *tr);
603 603
604 int kvm_arch_vcpu_ioctl_get_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs); 604 int kvm_arch_vcpu_ioctl_get_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs);
605 int kvm_arch_vcpu_ioctl_set_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs); 605 int kvm_arch_vcpu_ioctl_set_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs);
606 int kvm_arch_vcpu_ioctl_get_sregs(struct kvm_vcpu *vcpu, 606 int kvm_arch_vcpu_ioctl_get_sregs(struct kvm_vcpu *vcpu,
607 struct kvm_sregs *sregs); 607 struct kvm_sregs *sregs);
608 int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu, 608 int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu,
609 struct kvm_sregs *sregs); 609 struct kvm_sregs *sregs);
610 int kvm_arch_vcpu_ioctl_get_mpstate(struct kvm_vcpu *vcpu, 610 int kvm_arch_vcpu_ioctl_get_mpstate(struct kvm_vcpu *vcpu,
611 struct kvm_mp_state *mp_state); 611 struct kvm_mp_state *mp_state);
612 int kvm_arch_vcpu_ioctl_set_mpstate(struct kvm_vcpu *vcpu, 612 int kvm_arch_vcpu_ioctl_set_mpstate(struct kvm_vcpu *vcpu,
613 struct kvm_mp_state *mp_state); 613 struct kvm_mp_state *mp_state);
614 int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu, 614 int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
615 struct kvm_guest_debug *dbg); 615 struct kvm_guest_debug *dbg);
616 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run); 616 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
617 617
618 int kvm_arch_init(void *opaque); 618 int kvm_arch_init(void *opaque);
619 void kvm_arch_exit(void); 619 void kvm_arch_exit(void);
620 620
621 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu); 621 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
622 void kvm_arch_vcpu_uninit(struct kvm_vcpu *vcpu); 622 void kvm_arch_vcpu_uninit(struct kvm_vcpu *vcpu);
623 623
624 void kvm_arch_vcpu_free(struct kvm_vcpu *vcpu); 624 void kvm_arch_vcpu_free(struct kvm_vcpu *vcpu);
625 void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu); 625 void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu);
626 void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu); 626 void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu);
627 struct kvm_vcpu *kvm_arch_vcpu_create(struct kvm *kvm, unsigned int id); 627 struct kvm_vcpu *kvm_arch_vcpu_create(struct kvm *kvm, unsigned int id);
628 int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu); 628 int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu);
629 int kvm_arch_vcpu_postcreate(struct kvm_vcpu *vcpu); 629 int kvm_arch_vcpu_postcreate(struct kvm_vcpu *vcpu);
630 void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu); 630 void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu);
631 631
632 int kvm_arch_hardware_enable(void *garbage); 632 int kvm_arch_hardware_enable(void *garbage);
633 void kvm_arch_hardware_disable(void *garbage); 633 void kvm_arch_hardware_disable(void *garbage);
634 int kvm_arch_hardware_setup(void); 634 int kvm_arch_hardware_setup(void);
635 void kvm_arch_hardware_unsetup(void); 635 void kvm_arch_hardware_unsetup(void);
636 void kvm_arch_check_processor_compat(void *rtn); 636 void kvm_arch_check_processor_compat(void *rtn);
637 int kvm_arch_vcpu_runnable(struct kvm_vcpu *vcpu); 637 int kvm_arch_vcpu_runnable(struct kvm_vcpu *vcpu);
638 int kvm_arch_vcpu_should_kick(struct kvm_vcpu *vcpu); 638 int kvm_arch_vcpu_should_kick(struct kvm_vcpu *vcpu);
639 639
640 void kvm_free_physmem(struct kvm *kvm); 640 void kvm_free_physmem(struct kvm *kvm);
641 641
642 void *kvm_kvzalloc(unsigned long size); 642 void *kvm_kvzalloc(unsigned long size);
643 void kvm_kvfree(const void *addr); 643 void kvm_kvfree(const void *addr);
644 644
645 #ifndef __KVM_HAVE_ARCH_VM_ALLOC 645 #ifndef __KVM_HAVE_ARCH_VM_ALLOC
646 static inline struct kvm *kvm_arch_alloc_vm(void) 646 static inline struct kvm *kvm_arch_alloc_vm(void)
647 { 647 {
648 return kzalloc(sizeof(struct kvm), GFP_KERNEL); 648 return kzalloc(sizeof(struct kvm), GFP_KERNEL);
649 } 649 }
650 650
651 static inline void kvm_arch_free_vm(struct kvm *kvm) 651 static inline void kvm_arch_free_vm(struct kvm *kvm)
652 { 652 {
653 kfree(kvm); 653 kfree(kvm);
654 } 654 }
655 #endif 655 #endif
656 656
657 static inline wait_queue_head_t *kvm_arch_vcpu_wq(struct kvm_vcpu *vcpu) 657 static inline wait_queue_head_t *kvm_arch_vcpu_wq(struct kvm_vcpu *vcpu)
658 { 658 {
659 #ifdef __KVM_HAVE_ARCH_WQP 659 #ifdef __KVM_HAVE_ARCH_WQP
660 return vcpu->arch.wqp; 660 return vcpu->arch.wqp;
661 #else 661 #else
662 return &vcpu->wq; 662 return &vcpu->wq;
663 #endif 663 #endif
664 } 664 }
665 665
666 int kvm_arch_init_vm(struct kvm *kvm, unsigned long type); 666 int kvm_arch_init_vm(struct kvm *kvm, unsigned long type);
667 void kvm_arch_destroy_vm(struct kvm *kvm); 667 void kvm_arch_destroy_vm(struct kvm *kvm);
668 void kvm_free_all_assigned_devices(struct kvm *kvm); 668 void kvm_free_all_assigned_devices(struct kvm *kvm);
669 void kvm_arch_sync_events(struct kvm *kvm); 669 void kvm_arch_sync_events(struct kvm *kvm);
670 670
671 int kvm_cpu_has_pending_timer(struct kvm_vcpu *vcpu); 671 int kvm_cpu_has_pending_timer(struct kvm_vcpu *vcpu);
672 void kvm_vcpu_kick(struct kvm_vcpu *vcpu); 672 void kvm_vcpu_kick(struct kvm_vcpu *vcpu);
673 673
674 bool kvm_is_mmio_pfn(pfn_t pfn); 674 bool kvm_is_mmio_pfn(pfn_t pfn);
675 675
676 struct kvm_irq_ack_notifier { 676 struct kvm_irq_ack_notifier {
677 struct hlist_node link; 677 struct hlist_node link;
678 unsigned gsi; 678 unsigned gsi;
679 void (*irq_acked)(struct kvm_irq_ack_notifier *kian); 679 void (*irq_acked)(struct kvm_irq_ack_notifier *kian);
680 }; 680 };
681 681
682 struct kvm_assigned_dev_kernel { 682 struct kvm_assigned_dev_kernel {
683 struct kvm_irq_ack_notifier ack_notifier; 683 struct kvm_irq_ack_notifier ack_notifier;
684 struct list_head list; 684 struct list_head list;
685 int assigned_dev_id; 685 int assigned_dev_id;
686 int host_segnr; 686 int host_segnr;
687 int host_busnr; 687 int host_busnr;
688 int host_devfn; 688 int host_devfn;
689 unsigned int entries_nr; 689 unsigned int entries_nr;
690 int host_irq; 690 int host_irq;
691 bool host_irq_disabled; 691 bool host_irq_disabled;
692 bool pci_2_3; 692 bool pci_2_3;
693 struct msix_entry *host_msix_entries; 693 struct msix_entry *host_msix_entries;
694 int guest_irq; 694 int guest_irq;
695 struct msix_entry *guest_msix_entries; 695 struct msix_entry *guest_msix_entries;
696 unsigned long irq_requested_type; 696 unsigned long irq_requested_type;
697 int irq_source_id; 697 int irq_source_id;
698 int flags; 698 int flags;
699 struct pci_dev *dev; 699 struct pci_dev *dev;
700 struct kvm *kvm; 700 struct kvm *kvm;
701 spinlock_t intx_lock; 701 spinlock_t intx_lock;
702 spinlock_t intx_mask_lock; 702 spinlock_t intx_mask_lock;
703 char irq_name[32]; 703 char irq_name[32];
704 struct pci_saved_state *pci_saved_state; 704 struct pci_saved_state *pci_saved_state;
705 }; 705 };
706 706
707 struct kvm_irq_mask_notifier { 707 struct kvm_irq_mask_notifier {
708 void (*func)(struct kvm_irq_mask_notifier *kimn, bool masked); 708 void (*func)(struct kvm_irq_mask_notifier *kimn, bool masked);
709 int irq; 709 int irq;
710 struct hlist_node link; 710 struct hlist_node link;
711 }; 711 };
712 712
713 void kvm_register_irq_mask_notifier(struct kvm *kvm, int irq, 713 void kvm_register_irq_mask_notifier(struct kvm *kvm, int irq,
714 struct kvm_irq_mask_notifier *kimn); 714 struct kvm_irq_mask_notifier *kimn);
715 void kvm_unregister_irq_mask_notifier(struct kvm *kvm, int irq, 715 void kvm_unregister_irq_mask_notifier(struct kvm *kvm, int irq,
716 struct kvm_irq_mask_notifier *kimn); 716 struct kvm_irq_mask_notifier *kimn);
717 void kvm_fire_mask_notifiers(struct kvm *kvm, unsigned irqchip, unsigned pin, 717 void kvm_fire_mask_notifiers(struct kvm *kvm, unsigned irqchip, unsigned pin,
718 bool mask); 718 bool mask);
719 719
720 #ifdef __KVM_HAVE_IOAPIC 720 #ifdef __KVM_HAVE_IOAPIC
721 void kvm_get_intr_delivery_bitmask(struct kvm_ioapic *ioapic, 721 void kvm_get_intr_delivery_bitmask(struct kvm_ioapic *ioapic,
722 union kvm_ioapic_redirect_entry *entry, 722 union kvm_ioapic_redirect_entry *entry,
723 unsigned long *deliver_bitmask); 723 unsigned long *deliver_bitmask);
724 #endif 724 #endif
725 int kvm_set_irq(struct kvm *kvm, int irq_source_id, u32 irq, int level); 725 int kvm_set_irq(struct kvm *kvm, int irq_source_id, u32 irq, int level);
726 int kvm_set_irq_inatomic(struct kvm *kvm, int irq_source_id, u32 irq, int level); 726 int kvm_set_irq_inatomic(struct kvm *kvm, int irq_source_id, u32 irq, int level);
727 int kvm_set_msi(struct kvm_kernel_irq_routing_entry *irq_entry, struct kvm *kvm, 727 int kvm_set_msi(struct kvm_kernel_irq_routing_entry *irq_entry, struct kvm *kvm,
728 int irq_source_id, int level); 728 int irq_source_id, int level);
729 bool kvm_irq_has_notifier(struct kvm *kvm, unsigned irqchip, unsigned pin); 729 bool kvm_irq_has_notifier(struct kvm *kvm, unsigned irqchip, unsigned pin);
730 void kvm_notify_acked_irq(struct kvm *kvm, unsigned irqchip, unsigned pin); 730 void kvm_notify_acked_irq(struct kvm *kvm, unsigned irqchip, unsigned pin);
731 void kvm_register_irq_ack_notifier(struct kvm *kvm, 731 void kvm_register_irq_ack_notifier(struct kvm *kvm,
732 struct kvm_irq_ack_notifier *kian); 732 struct kvm_irq_ack_notifier *kian);
733 void kvm_unregister_irq_ack_notifier(struct kvm *kvm, 733 void kvm_unregister_irq_ack_notifier(struct kvm *kvm,
734 struct kvm_irq_ack_notifier *kian); 734 struct kvm_irq_ack_notifier *kian);
735 int kvm_request_irq_source_id(struct kvm *kvm); 735 int kvm_request_irq_source_id(struct kvm *kvm);
736 void kvm_free_irq_source_id(struct kvm *kvm, int irq_source_id); 736 void kvm_free_irq_source_id(struct kvm *kvm, int irq_source_id);
737 737
738 /* For vcpu->arch.iommu_flags */ 738 /* For vcpu->arch.iommu_flags */
739 #define KVM_IOMMU_CACHE_COHERENCY 0x1 739 #define KVM_IOMMU_CACHE_COHERENCY 0x1
740 740
741 #ifdef CONFIG_IOMMU_API 741 #ifdef CONFIG_IOMMU_API
742 int kvm_iommu_map_pages(struct kvm *kvm, struct kvm_memory_slot *slot); 742 int kvm_iommu_map_pages(struct kvm *kvm, struct kvm_memory_slot *slot);
743 void kvm_iommu_unmap_pages(struct kvm *kvm, struct kvm_memory_slot *slot); 743 void kvm_iommu_unmap_pages(struct kvm *kvm, struct kvm_memory_slot *slot);
744 int kvm_iommu_map_guest(struct kvm *kvm); 744 int kvm_iommu_map_guest(struct kvm *kvm);
745 int kvm_iommu_unmap_guest(struct kvm *kvm); 745 int kvm_iommu_unmap_guest(struct kvm *kvm);
746 int kvm_assign_device(struct kvm *kvm, 746 int kvm_assign_device(struct kvm *kvm,
747 struct kvm_assigned_dev_kernel *assigned_dev); 747 struct kvm_assigned_dev_kernel *assigned_dev);
748 int kvm_deassign_device(struct kvm *kvm, 748 int kvm_deassign_device(struct kvm *kvm,
749 struct kvm_assigned_dev_kernel *assigned_dev); 749 struct kvm_assigned_dev_kernel *assigned_dev);
750 #else /* CONFIG_IOMMU_API */ 750 #else /* CONFIG_IOMMU_API */
751 static inline int kvm_iommu_map_pages(struct kvm *kvm, 751 static inline int kvm_iommu_map_pages(struct kvm *kvm,
752 struct kvm_memory_slot *slot) 752 struct kvm_memory_slot *slot)
753 { 753 {
754 return 0; 754 return 0;
755 } 755 }
756 756
757 static inline void kvm_iommu_unmap_pages(struct kvm *kvm, 757 static inline void kvm_iommu_unmap_pages(struct kvm *kvm,
758 struct kvm_memory_slot *slot) 758 struct kvm_memory_slot *slot)
759 { 759 {
760 } 760 }
761 761
762 static inline int kvm_iommu_map_guest(struct kvm *kvm) 762 static inline int kvm_iommu_map_guest(struct kvm *kvm)
763 { 763 {
764 return -ENODEV; 764 return -ENODEV;
765 } 765 }
766 766
767 static inline int kvm_iommu_unmap_guest(struct kvm *kvm) 767 static inline int kvm_iommu_unmap_guest(struct kvm *kvm)
768 { 768 {
769 return 0; 769 return 0;
770 } 770 }
771 771
772 static inline int kvm_assign_device(struct kvm *kvm, 772 static inline int kvm_assign_device(struct kvm *kvm,
773 struct kvm_assigned_dev_kernel *assigned_dev) 773 struct kvm_assigned_dev_kernel *assigned_dev)
774 { 774 {
775 return 0; 775 return 0;
776 } 776 }
777 777
778 static inline int kvm_deassign_device(struct kvm *kvm, 778 static inline int kvm_deassign_device(struct kvm *kvm,
779 struct kvm_assigned_dev_kernel *assigned_dev) 779 struct kvm_assigned_dev_kernel *assigned_dev)
780 { 780 {
781 return 0; 781 return 0;
782 } 782 }
783 #endif /* CONFIG_IOMMU_API */ 783 #endif /* CONFIG_IOMMU_API */
784 784
785 static inline void __guest_enter(void) 785 static inline void __guest_enter(void)
786 { 786 {
787 /* 787 /*
788 * This is running in ioctl context so we can avoid 788 * This is running in ioctl context so we can avoid
789 * the call to vtime_account() with its unnecessary idle check. 789 * the call to vtime_account() with its unnecessary idle check.
790 */ 790 */
791 vtime_account_system(current); 791 vtime_account_system(current);
792 current->flags |= PF_VCPU; 792 current->flags |= PF_VCPU;
793 } 793 }
794 794
795 static inline void __guest_exit(void) 795 static inline void __guest_exit(void)
796 { 796 {
797 /* 797 /*
798 * This is running in ioctl context so we can avoid 798 * This is running in ioctl context so we can avoid
799 * the call to vtime_account() with its unnecessary idle check. 799 * the call to vtime_account() with its unnecessary idle check.
800 */ 800 */
801 vtime_account_system(current); 801 vtime_account_system(current);
802 current->flags &= ~PF_VCPU; 802 current->flags &= ~PF_VCPU;
803 } 803 }
804 804
805 #ifdef CONFIG_CONTEXT_TRACKING 805 #ifdef CONFIG_CONTEXT_TRACKING
806 extern void guest_enter(void); 806 extern void guest_enter(void);
807 extern void guest_exit(void); 807 extern void guest_exit(void);
808 808
809 #else /* !CONFIG_CONTEXT_TRACKING */ 809 #else /* !CONFIG_CONTEXT_TRACKING */
810 static inline void guest_enter(void) 810 static inline void guest_enter(void)
811 { 811 {
812 __guest_enter(); 812 __guest_enter();
813 } 813 }
814 814
815 static inline void guest_exit(void) 815 static inline void guest_exit(void)
816 { 816 {
817 __guest_exit(); 817 __guest_exit();
818 } 818 }
819 #endif /* !CONFIG_CONTEXT_TRACKING */ 819 #endif /* !CONFIG_CONTEXT_TRACKING */
820 820
821 static inline void kvm_guest_enter(void) 821 static inline void kvm_guest_enter(void)
822 { 822 {
823 unsigned long flags; 823 unsigned long flags;
824 824
825 BUG_ON(preemptible()); 825 BUG_ON(preemptible());
826 826
827 local_irq_save(flags); 827 local_irq_save(flags);
828 guest_enter(); 828 guest_enter();
829 local_irq_restore(flags); 829 local_irq_restore(flags);
830 830
831 /* KVM does not hold any references to rcu protected data when it 831 /* KVM does not hold any references to rcu protected data when it
832 * switches CPU into a guest mode. In fact switching to a guest mode 832 * switches CPU into a guest mode. In fact switching to a guest mode
833 * is very similar to exiting to userspase from rcu point of view. In 833 * is very similar to exiting to userspase from rcu point of view. In
834 * addition CPU may stay in a guest mode for quite a long time (up to 834 * addition CPU may stay in a guest mode for quite a long time (up to
835 * one time slice). Lets treat guest mode as quiescent state, just like 835 * one time slice). Lets treat guest mode as quiescent state, just like
836 * we do with user-mode execution. 836 * we do with user-mode execution.
837 */ 837 */
838 rcu_virt_note_context_switch(smp_processor_id()); 838 rcu_virt_note_context_switch(smp_processor_id());
839 } 839 }
840 840
841 static inline void kvm_guest_exit(void) 841 static inline void kvm_guest_exit(void)
842 { 842 {
843 unsigned long flags; 843 unsigned long flags;
844 844
845 local_irq_save(flags); 845 local_irq_save(flags);
846 guest_exit(); 846 guest_exit();
847 local_irq_restore(flags); 847 local_irq_restore(flags);
848 } 848 }
849 849
850 /* 850 /*
851 * search_memslots() and __gfn_to_memslot() are here because they are 851 * search_memslots() and __gfn_to_memslot() are here because they are
852 * used in non-modular code in arch/powerpc/kvm/book3s_hv_rm_mmu.c. 852 * used in non-modular code in arch/powerpc/kvm/book3s_hv_rm_mmu.c.
853 * gfn_to_memslot() itself isn't here as an inline because that would 853 * gfn_to_memslot() itself isn't here as an inline because that would
854 * bloat other code too much. 854 * bloat other code too much.
855 */ 855 */
856 static inline struct kvm_memory_slot * 856 static inline struct kvm_memory_slot *
857 search_memslots(struct kvm_memslots *slots, gfn_t gfn) 857 search_memslots(struct kvm_memslots *slots, gfn_t gfn)
858 { 858 {
859 struct kvm_memory_slot *memslot; 859 struct kvm_memory_slot *memslot;
860 860
861 kvm_for_each_memslot(memslot, slots) 861 kvm_for_each_memslot(memslot, slots)
862 if (gfn >= memslot->base_gfn && 862 if (gfn >= memslot->base_gfn &&
863 gfn < memslot->base_gfn + memslot->npages) 863 gfn < memslot->base_gfn + memslot->npages)
864 return memslot; 864 return memslot;
865 865
866 return NULL; 866 return NULL;
867 } 867 }
868 868
869 static inline struct kvm_memory_slot * 869 static inline struct kvm_memory_slot *
870 __gfn_to_memslot(struct kvm_memslots *slots, gfn_t gfn) 870 __gfn_to_memslot(struct kvm_memslots *slots, gfn_t gfn)
871 { 871 {
872 return search_memslots(slots, gfn); 872 return search_memslots(slots, gfn);
873 } 873 }
874 874
875 static inline unsigned long 875 static inline unsigned long
876 __gfn_to_hva_memslot(struct kvm_memory_slot *slot, gfn_t gfn) 876 __gfn_to_hva_memslot(struct kvm_memory_slot *slot, gfn_t gfn)
877 { 877 {
878 return slot->userspace_addr + (gfn - slot->base_gfn) * PAGE_SIZE; 878 return slot->userspace_addr + (gfn - slot->base_gfn) * PAGE_SIZE;
879 } 879 }
880 880
881 static inline int memslot_id(struct kvm *kvm, gfn_t gfn) 881 static inline int memslot_id(struct kvm *kvm, gfn_t gfn)
882 { 882 {
883 return gfn_to_memslot(kvm, gfn)->id; 883 return gfn_to_memslot(kvm, gfn)->id;
884 } 884 }
885 885
886 static inline gfn_t gfn_to_index(gfn_t gfn, gfn_t base_gfn, int level) 886 static inline gfn_t gfn_to_index(gfn_t gfn, gfn_t base_gfn, int level)
887 { 887 {
888 /* KVM_HPAGE_GFN_SHIFT(PT_PAGE_TABLE_LEVEL) must be 0. */ 888 /* KVM_HPAGE_GFN_SHIFT(PT_PAGE_TABLE_LEVEL) must be 0. */
889 return (gfn >> KVM_HPAGE_GFN_SHIFT(level)) - 889 return (gfn >> KVM_HPAGE_GFN_SHIFT(level)) -
890 (base_gfn >> KVM_HPAGE_GFN_SHIFT(level)); 890 (base_gfn >> KVM_HPAGE_GFN_SHIFT(level));
891 } 891 }
892 892
893 static inline gfn_t 893 static inline gfn_t
894 hva_to_gfn_memslot(unsigned long hva, struct kvm_memory_slot *slot) 894 hva_to_gfn_memslot(unsigned long hva, struct kvm_memory_slot *slot)
895 { 895 {
896 gfn_t gfn_offset = (hva - slot->userspace_addr) >> PAGE_SHIFT; 896 gfn_t gfn_offset = (hva - slot->userspace_addr) >> PAGE_SHIFT;
897 897
898 return slot->base_gfn + gfn_offset; 898 return slot->base_gfn + gfn_offset;
899 } 899 }
900 900
901 static inline gpa_t gfn_to_gpa(gfn_t gfn) 901 static inline gpa_t gfn_to_gpa(gfn_t gfn)
902 { 902 {
903 return (gpa_t)gfn << PAGE_SHIFT; 903 return (gpa_t)gfn << PAGE_SHIFT;
904 } 904 }
905 905
906 static inline gfn_t gpa_to_gfn(gpa_t gpa) 906 static inline gfn_t gpa_to_gfn(gpa_t gpa)
907 { 907 {
908 return (gfn_t)(gpa >> PAGE_SHIFT); 908 return (gfn_t)(gpa >> PAGE_SHIFT);
909 } 909 }
910 910
911 static inline hpa_t pfn_to_hpa(pfn_t pfn) 911 static inline hpa_t pfn_to_hpa(pfn_t pfn)
912 { 912 {
913 return (hpa_t)pfn << PAGE_SHIFT; 913 return (hpa_t)pfn << PAGE_SHIFT;
914 } 914 }
915 915
916 static inline void kvm_migrate_timers(struct kvm_vcpu *vcpu) 916 static inline void kvm_migrate_timers(struct kvm_vcpu *vcpu)
917 { 917 {
918 set_bit(KVM_REQ_MIGRATE_TIMER, &vcpu->requests); 918 set_bit(KVM_REQ_MIGRATE_TIMER, &vcpu->requests);
919 } 919 }
920 920
921 enum kvm_stat_kind { 921 enum kvm_stat_kind {
922 KVM_STAT_VM, 922 KVM_STAT_VM,
923 KVM_STAT_VCPU, 923 KVM_STAT_VCPU,
924 }; 924 };
925 925
926 struct kvm_stats_debugfs_item { 926 struct kvm_stats_debugfs_item {
927 const char *name; 927 const char *name;
928 int offset; 928 int offset;
929 enum kvm_stat_kind kind; 929 enum kvm_stat_kind kind;
930 struct dentry *dentry; 930 struct dentry *dentry;
931 }; 931 };
932 extern struct kvm_stats_debugfs_item debugfs_entries[]; 932 extern struct kvm_stats_debugfs_item debugfs_entries[];
933 extern struct dentry *kvm_debugfs_dir; 933 extern struct dentry *kvm_debugfs_dir;
934 934
935 #if defined(CONFIG_MMU_NOTIFIER) && defined(KVM_ARCH_WANT_MMU_NOTIFIER) 935 #if defined(CONFIG_MMU_NOTIFIER) && defined(KVM_ARCH_WANT_MMU_NOTIFIER)
936 static inline int mmu_notifier_retry(struct kvm *kvm, unsigned long mmu_seq) 936 static inline int mmu_notifier_retry(struct kvm *kvm, unsigned long mmu_seq)
937 { 937 {
938 if (unlikely(kvm->mmu_notifier_count)) 938 if (unlikely(kvm->mmu_notifier_count))
939 return 1; 939 return 1;
940 /* 940 /*
941 * Ensure the read of mmu_notifier_count happens before the read 941 * Ensure the read of mmu_notifier_count happens before the read
942 * of mmu_notifier_seq. This interacts with the smp_wmb() in 942 * of mmu_notifier_seq. This interacts with the smp_wmb() in
943 * mmu_notifier_invalidate_range_end to make sure that the caller 943 * mmu_notifier_invalidate_range_end to make sure that the caller
944 * either sees the old (non-zero) value of mmu_notifier_count or 944 * either sees the old (non-zero) value of mmu_notifier_count or
945 * the new (incremented) value of mmu_notifier_seq. 945 * the new (incremented) value of mmu_notifier_seq.
946 * PowerPC Book3s HV KVM calls this under a per-page lock 946 * PowerPC Book3s HV KVM calls this under a per-page lock
947 * rather than under kvm->mmu_lock, for scalability, so 947 * rather than under kvm->mmu_lock, for scalability, so
948 * can't rely on kvm->mmu_lock to keep things ordered. 948 * can't rely on kvm->mmu_lock to keep things ordered.
949 */ 949 */
950 smp_rmb(); 950 smp_rmb();
951 if (kvm->mmu_notifier_seq != mmu_seq) 951 if (kvm->mmu_notifier_seq != mmu_seq)
952 return 1; 952 return 1;
953 return 0; 953 return 0;
954 } 954 }
955 #endif 955 #endif
956 956
957 #ifdef KVM_CAP_IRQ_ROUTING 957 #ifdef KVM_CAP_IRQ_ROUTING
958 958
959 #define KVM_MAX_IRQ_ROUTES 1024 959 #define KVM_MAX_IRQ_ROUTES 1024
960 960
961 int kvm_setup_default_irq_routing(struct kvm *kvm); 961 int kvm_setup_default_irq_routing(struct kvm *kvm);
962 int kvm_set_irq_routing(struct kvm *kvm, 962 int kvm_set_irq_routing(struct kvm *kvm,
963 const struct kvm_irq_routing_entry *entries, 963 const struct kvm_irq_routing_entry *entries,
964 unsigned nr, 964 unsigned nr,
965 unsigned flags); 965 unsigned flags);
966 void kvm_free_irq_routing(struct kvm *kvm); 966 void kvm_free_irq_routing(struct kvm *kvm);
967 967
968 int kvm_send_userspace_msi(struct kvm *kvm, struct kvm_msi *msi); 968 int kvm_send_userspace_msi(struct kvm *kvm, struct kvm_msi *msi);
969 969
970 #else 970 #else
971 971
972 static inline void kvm_free_irq_routing(struct kvm *kvm) {} 972 static inline void kvm_free_irq_routing(struct kvm *kvm) {}
973 973
974 #endif 974 #endif
975 975
976 #ifdef CONFIG_HAVE_KVM_EVENTFD 976 #ifdef CONFIG_HAVE_KVM_EVENTFD
977 977
978 void kvm_eventfd_init(struct kvm *kvm); 978 void kvm_eventfd_init(struct kvm *kvm);
979 int kvm_ioeventfd(struct kvm *kvm, struct kvm_ioeventfd *args); 979 int kvm_ioeventfd(struct kvm *kvm, struct kvm_ioeventfd *args);
980 980
981 #ifdef CONFIG_HAVE_KVM_IRQCHIP 981 #ifdef CONFIG_HAVE_KVM_IRQCHIP
982 int kvm_irqfd(struct kvm *kvm, struct kvm_irqfd *args); 982 int kvm_irqfd(struct kvm *kvm, struct kvm_irqfd *args);
983 void kvm_irqfd_release(struct kvm *kvm); 983 void kvm_irqfd_release(struct kvm *kvm);
984 void kvm_irq_routing_update(struct kvm *, struct kvm_irq_routing_table *); 984 void kvm_irq_routing_update(struct kvm *, struct kvm_irq_routing_table *);
985 #else 985 #else
986 static inline int kvm_irqfd(struct kvm *kvm, struct kvm_irqfd *args) 986 static inline int kvm_irqfd(struct kvm *kvm, struct kvm_irqfd *args)
987 { 987 {
988 return -EINVAL; 988 return -EINVAL;
989 } 989 }
990 990
991 static inline void kvm_irqfd_release(struct kvm *kvm) {} 991 static inline void kvm_irqfd_release(struct kvm *kvm) {}
992 #endif 992 #endif
993 993
994 #else 994 #else
995 995
996 static inline void kvm_eventfd_init(struct kvm *kvm) {} 996 static inline void kvm_eventfd_init(struct kvm *kvm) {}
997 997
998 static inline int kvm_irqfd(struct kvm *kvm, struct kvm_irqfd *args) 998 static inline int kvm_irqfd(struct kvm *kvm, struct kvm_irqfd *args)
999 { 999 {
1000 return -EINVAL; 1000 return -EINVAL;
1001 } 1001 }
1002 1002
1003 static inline void kvm_irqfd_release(struct kvm *kvm) {} 1003 static inline void kvm_irqfd_release(struct kvm *kvm) {}
1004 1004
1005 #ifdef CONFIG_HAVE_KVM_IRQCHIP 1005 #ifdef CONFIG_HAVE_KVM_IRQCHIP
1006 static inline void kvm_irq_routing_update(struct kvm *kvm, 1006 static inline void kvm_irq_routing_update(struct kvm *kvm,
1007 struct kvm_irq_routing_table *irq_rt) 1007 struct kvm_irq_routing_table *irq_rt)
1008 { 1008 {
1009 rcu_assign_pointer(kvm->irq_routing, irq_rt); 1009 rcu_assign_pointer(kvm->irq_routing, irq_rt);
1010 } 1010 }
1011 #endif 1011 #endif
1012 1012
1013 static inline int kvm_ioeventfd(struct kvm *kvm, struct kvm_ioeventfd *args) 1013 static inline int kvm_ioeventfd(struct kvm *kvm, struct kvm_ioeventfd *args)
1014 { 1014 {
1015 return -ENOSYS; 1015 return -ENOSYS;
1016 } 1016 }
1017 1017
1018 #endif /* CONFIG_HAVE_KVM_EVENTFD */ 1018 #endif /* CONFIG_HAVE_KVM_EVENTFD */
1019 1019
1020 #ifdef CONFIG_KVM_APIC_ARCHITECTURE 1020 #ifdef CONFIG_KVM_APIC_ARCHITECTURE
1021 static inline bool kvm_vcpu_is_bsp(struct kvm_vcpu *vcpu) 1021 static inline bool kvm_vcpu_is_bsp(struct kvm_vcpu *vcpu)
1022 { 1022 {
1023 return vcpu->kvm->bsp_vcpu_id == vcpu->vcpu_id; 1023 return vcpu->kvm->bsp_vcpu_id == vcpu->vcpu_id;
1024 } 1024 }
1025 1025
1026 bool kvm_vcpu_compatible(struct kvm_vcpu *vcpu); 1026 bool kvm_vcpu_compatible(struct kvm_vcpu *vcpu);
1027 1027
1028 #else 1028 #else
1029 1029
1030 static inline bool kvm_vcpu_compatible(struct kvm_vcpu *vcpu) { return true; } 1030 static inline bool kvm_vcpu_compatible(struct kvm_vcpu *vcpu) { return true; }
1031 1031
1032 #endif 1032 #endif
1033 1033
1034 #ifdef __KVM_HAVE_DEVICE_ASSIGNMENT 1034 #ifdef __KVM_HAVE_DEVICE_ASSIGNMENT
1035 1035
1036 long kvm_vm_ioctl_assigned_device(struct kvm *kvm, unsigned ioctl, 1036 long kvm_vm_ioctl_assigned_device(struct kvm *kvm, unsigned ioctl,
1037 unsigned long arg); 1037 unsigned long arg);
1038 1038
1039 #else 1039 #else
1040 1040
1041 static inline long kvm_vm_ioctl_assigned_device(struct kvm *kvm, unsigned ioctl, 1041 static inline long kvm_vm_ioctl_assigned_device(struct kvm *kvm, unsigned ioctl,
1042 unsigned long arg) 1042 unsigned long arg)
1043 { 1043 {
1044 return -ENOTTY; 1044 return -ENOTTY;
1045 } 1045 }
1046 1046
1047 #endif 1047 #endif
1048 1048
1049 static inline void kvm_make_request(int req, struct kvm_vcpu *vcpu) 1049 static inline void kvm_make_request(int req, struct kvm_vcpu *vcpu)
1050 { 1050 {
1051 set_bit(req, &vcpu->requests); 1051 set_bit(req, &vcpu->requests);
1052 } 1052 }
1053 1053
1054 static inline bool kvm_check_request(int req, struct kvm_vcpu *vcpu) 1054 static inline bool kvm_check_request(int req, struct kvm_vcpu *vcpu)
1055 { 1055 {
1056 if (test_bit(req, &vcpu->requests)) { 1056 if (test_bit(req, &vcpu->requests)) {
1057 clear_bit(req, &vcpu->requests); 1057 clear_bit(req, &vcpu->requests);
1058 return true; 1058 return true;
1059 } else { 1059 } else {
1060 return false; 1060 return false;
1061 } 1061 }
1062 } 1062 }
1063 1063
1064 extern bool kvm_rebooting;
1065
1064 #ifdef CONFIG_HAVE_KVM_CPU_RELAX_INTERCEPT 1066 #ifdef CONFIG_HAVE_KVM_CPU_RELAX_INTERCEPT
1065 1067
1066 static inline void kvm_vcpu_set_in_spin_loop(struct kvm_vcpu *vcpu, bool val) 1068 static inline void kvm_vcpu_set_in_spin_loop(struct kvm_vcpu *vcpu, bool val)
1067 { 1069 {
1068 vcpu->spin_loop.in_spin_loop = val; 1070 vcpu->spin_loop.in_spin_loop = val;
1069 } 1071 }
1070 static inline void kvm_vcpu_set_dy_eligible(struct kvm_vcpu *vcpu, bool val) 1072 static inline void kvm_vcpu_set_dy_eligible(struct kvm_vcpu *vcpu, bool val)
1071 { 1073 {
1072 vcpu->spin_loop.dy_eligible = val; 1074 vcpu->spin_loop.dy_eligible = val;
1073 } 1075 }
1074 1076
1075 #else /* !CONFIG_HAVE_KVM_CPU_RELAX_INTERCEPT */ 1077 #else /* !CONFIG_HAVE_KVM_CPU_RELAX_INTERCEPT */
1076 1078
1077 static inline void kvm_vcpu_set_in_spin_loop(struct kvm_vcpu *vcpu, bool val) 1079 static inline void kvm_vcpu_set_in_spin_loop(struct kvm_vcpu *vcpu, bool val)
1078 { 1080 {
1079 } 1081 }
1080 1082
1081 static inline void kvm_vcpu_set_dy_eligible(struct kvm_vcpu *vcpu, bool val) 1083 static inline void kvm_vcpu_set_dy_eligible(struct kvm_vcpu *vcpu, bool val)
1082 { 1084 {
1083 } 1085 }
1084 1086
1085 static inline bool kvm_vcpu_eligible_for_directed_yield(struct kvm_vcpu *vcpu) 1087 static inline bool kvm_vcpu_eligible_for_directed_yield(struct kvm_vcpu *vcpu)
1086 { 1088 {
1087 return true; 1089 return true;
1088 } 1090 }
1089 1091
1090 #endif /* CONFIG_HAVE_KVM_CPU_RELAX_INTERCEPT */ 1092 #endif /* CONFIG_HAVE_KVM_CPU_RELAX_INTERCEPT */
1091 #else 1093 #else
1092 static inline void __guest_enter(void) { return; } 1094 static inline void __guest_enter(void) { return; }
1093 static inline void __guest_exit(void) { return; } 1095 static inline void __guest_exit(void) { return; }
1094 #endif /* IS_ENABLED(CONFIG_KVM) */ 1096 #endif /* IS_ENABLED(CONFIG_KVM) */
1095 #endif 1097 #endif
1096 1098