Print this page
Revert "OS-8005 bhyve memory pressure needs to target ARC better (#354)"
This reverts commit a6033573eedd94118d2b9e65f45deca0bf4b42f7.
| Split |
Close |
| Expand all |
| Collapse all |
--- old/usr/src/uts/i86pc/io/vmm/sys/vmm_kernel.h
+++ new/usr/src/uts/i86pc/io/vmm/sys/vmm_kernel.h
1 1 /*-
2 2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3 3 *
4 4 * Copyright (c) 2011 NetApp, Inc.
5 5 * All rights reserved.
6 6 *
7 7 * Redistribution and use in source and binary forms, with or without
8 8 * modification, are permitted provided that the following conditions
9 9 * are met:
10 10 * 1. Redistributions of source code must retain the above copyright
11 11 * notice, this list of conditions and the following disclaimer.
12 12 * 2. Redistributions in binary form must reproduce the above copyright
13 13 * notice, this list of conditions and the following disclaimer in the
14 14 * documentation and/or other materials provided with the distribution.
15 15 *
16 16 * THIS SOFTWARE IS PROVIDED BY NETAPP, INC ``AS IS'' AND
17 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 19 * ARE DISCLAIMED. IN NO EVENT SHALL NETAPP, INC OR CONTRIBUTORS BE LIABLE
20 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 26 * SUCH DAMAGE.
27 27 *
28 28 * $FreeBSD$
29 29 */
30 30 /*
31 31 * This file and its contents are supplied under the terms of the
32 32 * Common Development and Distribution License ("CDDL"), version 1.0.
33 33 * You may only use this file in accordance with the terms of version
34 34 * 1.0 of the CDDL.
35 35 *
36 36 * A full copy of the text of the CDDL should have accompanied this
37 37 * source. A copy of the CDDL is also available via the Internet at
38 38 * http://www.illumos.org/license/CDDL.
39 39 *
40 40 * Copyright 2015 Pluribus Networks Inc.
41 41 * Copyright 2019 Joyent, Inc.
42 42 * Copyright 2021 Oxide Computer Company
43 43 * Copyright 2021 OmniOS Community Edition (OmniOSce) Association.
44 44 */
45 45
46 46 #ifndef _VMM_KERNEL_H_
47 47 #define _VMM_KERNEL_H_
48 48
49 49 #include <sys/sdt.h>
50 50 #include <x86/segments.h>
51 51
52 52 SDT_PROVIDER_DECLARE(vmm);
53 53
54 54 struct vm;
55 55 struct vm_exception;
56 56 struct seg_desc;
57 57 struct vm_exit;
58 58 struct vie;
59 59 struct vm_run;
60 60 struct vhpet;
61 61 struct vioapic;
62 62 struct vlapic;
63 63 struct vmspace;
64 64 struct vm_object;
65 65 struct vm_guest_paging;
66 66 struct pmap;
67 67
68 68 typedef int (*vmm_init_func_t)(int ipinum);
69 69 typedef int (*vmm_cleanup_func_t)(void);
70 70 typedef void (*vmm_resume_func_t)(void);
71 71 typedef void * (*vmi_init_func_t)(struct vm *vm, struct pmap *pmap);
72 72 typedef int (*vmi_run_func_t)(void *vmi, int vcpu, uint64_t rip,
73 73 struct pmap *pmap);
74 74 typedef void (*vmi_cleanup_func_t)(void *vmi);
75 75 typedef int (*vmi_get_register_t)(void *vmi, int vcpu, int num,
76 76 uint64_t *retval);
77 77 typedef int (*vmi_set_register_t)(void *vmi, int vcpu, int num,
78 78 uint64_t val);
79 79 typedef int (*vmi_get_desc_t)(void *vmi, int vcpu, int num,
80 80 struct seg_desc *desc);
81 81 typedef int (*vmi_set_desc_t)(void *vmi, int vcpu, int num,
82 82 const struct seg_desc *desc);
83 83 typedef int (*vmi_get_cap_t)(void *vmi, int vcpu, int num, int *retval);
84 84 typedef int (*vmi_set_cap_t)(void *vmi, int vcpu, int num, int val);
85 85 typedef struct vmspace *(*vmi_vmspace_alloc)(vm_offset_t min, vm_offset_t max);
86 86 typedef void (*vmi_vmspace_free)(struct vmspace *vmspace);
87 87 typedef struct vlapic *(*vmi_vlapic_init)(void *vmi, int vcpu);
88 88 typedef void (*vmi_vlapic_cleanup)(void *vmi, struct vlapic *vlapic);
89 89 typedef void (*vmi_savectx)(void *vmi, int vcpu);
90 90 typedef void (*vmi_restorectx)(void *vmi, int vcpu);
91 91
92 92 struct vmm_ops {
93 93 vmm_init_func_t init; /* module wide initialization */
94 94 vmm_cleanup_func_t cleanup;
95 95 vmm_resume_func_t resume;
96 96
97 97 vmi_init_func_t vminit; /* vm-specific initialization */
98 98 vmi_run_func_t vmrun;
99 99 vmi_cleanup_func_t vmcleanup;
100 100 vmi_get_register_t vmgetreg;
101 101 vmi_set_register_t vmsetreg;
102 102 vmi_get_desc_t vmgetdesc;
103 103 vmi_set_desc_t vmsetdesc;
104 104 vmi_get_cap_t vmgetcap;
105 105 vmi_set_cap_t vmsetcap;
106 106 vmi_vmspace_alloc vmspace_alloc;
107 107 vmi_vmspace_free vmspace_free;
108 108 vmi_vlapic_init vlapic_init;
109 109 vmi_vlapic_cleanup vlapic_cleanup;
110 110
111 111 vmi_savectx vmsavectx;
112 112 vmi_restorectx vmrestorectx;
113 113 };
114 114
115 115 extern struct vmm_ops vmm_ops_intel;
116 116 extern struct vmm_ops vmm_ops_amd;
117 117
118 118 int vm_create(const char *name, struct vm **retvm);
119 119 void vm_destroy(struct vm *vm);
120 120 int vm_reinit(struct vm *vm);
121 121 const char *vm_name(struct vm *vm);
122 122 uint16_t vm_get_maxcpus(struct vm *vm);
123 123 void vm_get_topology(struct vm *vm, uint16_t *sockets, uint16_t *cores,
124 124 uint16_t *threads, uint16_t *maxcpus);
125 125 int vm_set_topology(struct vm *vm, uint16_t sockets, uint16_t cores,
126 126 uint16_t threads, uint16_t maxcpus);
127 127
128 128 /*
129 129 * APIs that modify the guest memory map require all vcpus to be frozen.
130 130 */
131 131 int vm_mmap_memseg(struct vm *vm, vm_paddr_t gpa, int segid, vm_ooffset_t off,
132 132 size_t len, int prot, int flags);
133 133 int vm_munmap_memseg(struct vm *vm, vm_paddr_t gpa, size_t len);
134 134 int vm_alloc_memseg(struct vm *vm, int ident, size_t len, bool sysmem);
135 135 void vm_free_memseg(struct vm *vm, int ident);
136 136 int vm_map_mmio(struct vm *vm, vm_paddr_t gpa, size_t len, vm_paddr_t hpa);
137 137 int vm_unmap_mmio(struct vm *vm, vm_paddr_t gpa, size_t len);
138 138 int vm_assign_pptdev(struct vm *vm, int pptfd);
139 139 int vm_unassign_pptdev(struct vm *vm, int pptfd);
140 140
141 141 /*
142 142 * APIs that inspect the guest memory map require only a *single* vcpu to
143 143 * be frozen. This acts like a read lock on the guest memory map since any
144 144 * modification requires *all* vcpus to be frozen.
145 145 */
146 146 int vm_mmap_getnext(struct vm *vm, vm_paddr_t *gpa, int *segid,
147 147 vm_ooffset_t *segoff, size_t *len, int *prot, int *flags);
148 148 int vm_get_memseg(struct vm *vm, int ident, size_t *len, bool *sysmem,
149 149 struct vm_object **objptr);
150 150 vm_paddr_t vmm_sysmem_maxaddr(struct vm *vm);
151 151 void *vm_gpa_hold(struct vm *, int vcpuid, vm_paddr_t gpa, size_t len,
152 152 int prot, void **cookie);
153 153 void vm_gpa_release(void *cookie);
154 154 bool vm_mem_allocated(struct vm *vm, int vcpuid, vm_paddr_t gpa);
155 155
156 156 int vm_get_register(struct vm *vm, int vcpu, int reg, uint64_t *retval);
157 157 int vm_set_register(struct vm *vm, int vcpu, int reg, uint64_t val);
158 158 int vm_get_seg_desc(struct vm *vm, int vcpu, int reg,
159 159 struct seg_desc *ret_desc);
160 160 int vm_set_seg_desc(struct vm *vm, int vcpu, int reg,
161 161 const struct seg_desc *desc);
162 162 int vm_get_run_state(struct vm *vm, int vcpuid, uint32_t *state,
163 163 uint8_t *sipi_vec);
164 164 int vm_set_run_state(struct vm *vm, int vcpuid, uint32_t state,
165 165 uint8_t sipi_vec);
166 166 int vm_run(struct vm *vm, int vcpuid, const struct vm_entry *);
167 167 int vm_suspend(struct vm *vm, enum vm_suspend_how how);
168 168 int vm_inject_nmi(struct vm *vm, int vcpu);
169 169 int vm_nmi_pending(struct vm *vm, int vcpuid);
170 170 void vm_nmi_clear(struct vm *vm, int vcpuid);
171 171 int vm_inject_extint(struct vm *vm, int vcpu);
172 172 int vm_extint_pending(struct vm *vm, int vcpuid);
173 173 void vm_extint_clear(struct vm *vm, int vcpuid);
174 174 int vm_inject_init(struct vm *vm, int vcpuid);
175 175 int vm_inject_sipi(struct vm *vm, int vcpuid, uint8_t vec);
176 176 struct vlapic *vm_lapic(struct vm *vm, int cpu);
177 177 struct vioapic *vm_ioapic(struct vm *vm);
178 178 struct vhpet *vm_hpet(struct vm *vm);
179 179 int vm_get_capability(struct vm *vm, int vcpu, int type, int *val);
180 180 int vm_set_capability(struct vm *vm, int vcpu, int type, int val);
181 181 int vm_get_x2apic_state(struct vm *vm, int vcpu, enum x2apic_state *state);
182 182 int vm_set_x2apic_state(struct vm *vm, int vcpu, enum x2apic_state state);
183 183 int vm_apicid2vcpuid(struct vm *vm, int apicid);
184 184 int vm_activate_cpu(struct vm *vm, int vcpu);
185 185 int vm_suspend_cpu(struct vm *vm, int vcpu);
186 186 int vm_resume_cpu(struct vm *vm, int vcpu);
187 187 struct vm_exit *vm_exitinfo(struct vm *vm, int vcpuid);
188 188 struct vie *vm_vie_ctx(struct vm *vm, int vcpuid);
|
↓ open down ↓ |
188 lines elided |
↑ open up ↑ |
189 189 void vm_exit_suspended(struct vm *vm, int vcpuid, uint64_t rip);
190 190 void vm_exit_debug(struct vm *vm, int vcpuid, uint64_t rip);
191 191 void vm_exit_astpending(struct vm *vm, int vcpuid, uint64_t rip);
192 192 void vm_exit_reqidle(struct vm *vm, int vcpuid, uint64_t rip);
193 193 void vm_exit_run_state(struct vm *vm, int vcpuid, uint64_t rip);
194 194 int vm_service_mmio_read(struct vm *vm, int cpuid, uint64_t gpa, uint64_t *rval,
195 195 int rsize);
196 196 int vm_service_mmio_write(struct vm *vm, int cpuid, uint64_t gpa, uint64_t wval,
197 197 int wsize);
198 198
199 -int vm_arc_resv(struct vm *vm, size_t);
200 -
201 199 #ifdef _SYS__CPUSET_H_
202 200 cpuset_t vm_active_cpus(struct vm *vm);
203 201 cpuset_t vm_debug_cpus(struct vm *vm);
204 202 cpuset_t vm_suspended_cpus(struct vm *vm);
205 203 #endif /* _SYS__CPUSET_H_ */
206 204
207 205 bool vcpu_entry_bailout_checks(struct vm *vm, int vcpuid, uint64_t rip);
208 206 bool vcpu_run_state_pending(struct vm *vm, int vcpuid);
209 207 int vcpu_arch_reset(struct vm *vm, int vcpuid, bool init_only);
210 208
211 209 /*
212 210 * Return true if device indicated by bus/slot/func is supposed to be a
213 211 * pci passthrough device.
214 212 *
215 213 * Return false otherwise.
216 214 */
217 215 bool vmm_is_pptdev(int bus, int slot, int func);
218 216
219 217 void *vm_iommu_domain(struct vm *vm);
220 218
221 219 enum vcpu_state {
222 220 VCPU_IDLE,
223 221 VCPU_FROZEN,
224 222 VCPU_RUNNING,
225 223 VCPU_SLEEPING,
226 224 };
227 225
228 226 int vcpu_set_state(struct vm *vm, int vcpu, enum vcpu_state state,
229 227 bool from_idle);
230 228 enum vcpu_state vcpu_get_state(struct vm *vm, int vcpu, int *hostcpu);
231 229 void vcpu_block_run(struct vm *, int);
232 230 void vcpu_unblock_run(struct vm *, int);
233 231
234 232 uint64_t vcpu_tsc_offset(struct vm *vm, int vcpuid, bool phys_adj);
235 233
236 234 static __inline int
237 235 vcpu_is_running(struct vm *vm, int vcpu, int *hostcpu)
238 236 {
239 237 return (vcpu_get_state(vm, vcpu, hostcpu) == VCPU_RUNNING);
240 238 }
241 239
242 240 #ifdef _SYS_THREAD_H
243 241 static __inline int
244 242 vcpu_should_yield(struct vm *vm, int vcpu)
245 243 {
246 244
247 245 if (curthread->t_astflag)
248 246 return (1);
249 247 else if (CPU->cpu_runrun)
250 248 return (1);
251 249 else
252 250 return (0);
253 251 }
254 252 #endif /* _SYS_THREAD_H */
255 253
256 254 typedef enum vcpu_notify {
257 255 VCPU_NOTIFY_NONE,
258 256 VCPU_NOTIFY_APIC, /* Posted intr notification (if possible) */
259 257 VCPU_NOTIFY_EXIT, /* IPI to cause VM exit */
260 258 } vcpu_notify_t;
261 259
262 260 void *vcpu_stats(struct vm *vm, int vcpu);
263 261 void vcpu_notify_event(struct vm *vm, int vcpuid);
264 262 void vcpu_notify_event_type(struct vm *vm, int vcpuid, vcpu_notify_t);
265 263 struct vmspace *vm_get_vmspace(struct vm *vm);
266 264 struct vatpic *vm_atpic(struct vm *vm);
267 265 struct vatpit *vm_atpit(struct vm *vm);
268 266 struct vpmtmr *vm_pmtmr(struct vm *vm);
269 267 struct vrtc *vm_rtc(struct vm *vm);
270 268
271 269 /*
272 270 * Inject exception 'vector' into the guest vcpu. This function returns 0 on
273 271 * success and non-zero on failure.
274 272 *
275 273 * Wrapper functions like 'vm_inject_gp()' should be preferred to calling
276 274 * this function directly because they enforce the trap-like or fault-like
277 275 * behavior of an exception.
278 276 *
279 277 * This function should only be called in the context of the thread that is
280 278 * executing this vcpu.
281 279 */
282 280 int vm_inject_exception(struct vm *vm, int vcpuid, int vector, int err_valid,
283 281 uint32_t errcode, int restart_instruction);
284 282
285 283 /*
286 284 * This function is called after a VM-exit that occurred during exception or
287 285 * interrupt delivery through the IDT. The format of 'intinfo' is described
288 286 * in Figure 15-1, "EXITINTINFO for All Intercepts", APM, Vol 2.
289 287 *
290 288 * If a VM-exit handler completes the event delivery successfully then it
291 289 * should call vm_exit_intinfo() to extinguish the pending event. For e.g.,
292 290 * if the task switch emulation is triggered via a task gate then it should
293 291 * call this function with 'intinfo=0' to indicate that the external event
294 292 * is not pending anymore.
295 293 *
296 294 * Return value is 0 on success and non-zero on failure.
297 295 */
298 296 int vm_exit_intinfo(struct vm *vm, int vcpuid, uint64_t intinfo);
299 297
300 298 /*
301 299 * This function is called before every VM-entry to retrieve a pending
302 300 * event that should be injected into the guest. This function combines
303 301 * nested events into a double or triple fault.
304 302 *
305 303 * Returns 0 if there are no events that need to be injected into the guest
306 304 * and non-zero otherwise.
307 305 */
308 306 int vm_entry_intinfo(struct vm *vm, int vcpuid, uint64_t *info);
309 307
310 308 int vm_get_intinfo(struct vm *vm, int vcpuid, uint64_t *info1, uint64_t *info2);
311 309
312 310 enum vm_reg_name vm_segment_name(int seg_encoding);
313 311
314 312 struct vm_copyinfo {
315 313 uint64_t gpa;
316 314 size_t len;
317 315 void *hva;
318 316 void *cookie;
319 317 };
320 318
321 319 /*
322 320 * Set up 'copyinfo[]' to copy to/from guest linear address space starting
323 321 * at 'gla' and 'len' bytes long. The 'prot' should be set to PROT_READ for
324 322 * a copyin or PROT_WRITE for a copyout.
325 323 *
326 324 * retval is_fault Interpretation
327 325 * 0 0 Success
328 326 * 0 1 An exception was injected into the guest
329 327 * EFAULT N/A Unrecoverable error
330 328 *
331 329 * The 'copyinfo[]' can be passed to 'vm_copyin()' or 'vm_copyout()' only if
332 330 * the return value is 0. The 'copyinfo[]' resources should be freed by calling
333 331 * 'vm_copy_teardown()' after the copy is done.
334 332 */
335 333 int vm_copy_setup(struct vm *vm, int vcpuid, struct vm_guest_paging *paging,
336 334 uint64_t gla, size_t len, int prot, struct vm_copyinfo *copyinfo,
337 335 int num_copyinfo, int *is_fault);
338 336 void vm_copy_teardown(struct vm *vm, int vcpuid, struct vm_copyinfo *copyinfo,
339 337 int num_copyinfo);
340 338 void vm_copyin(struct vm *vm, int vcpuid, struct vm_copyinfo *copyinfo,
341 339 void *kaddr, size_t len);
342 340 void vm_copyout(struct vm *vm, int vcpuid, const void *kaddr,
343 341 struct vm_copyinfo *copyinfo, size_t len);
344 342
345 343 int vcpu_trace_exceptions(struct vm *vm, int vcpuid);
346 344
347 345 /* APIs to inject faults into the guest */
348 346 void vm_inject_fault(struct vm *vm, int vcpuid, int vector, int errcode_valid,
349 347 int errcode);
350 348
351 349 void vm_inject_ud(struct vm *vm, int vcpuid);
352 350 void vm_inject_gp(struct vm *vm, int vcpuid);
353 351 void vm_inject_ac(struct vm *vm, int vcpuid, int errcode);
354 352 void vm_inject_ss(struct vm *vm, int vcpuid, int errcode);
355 353 void vm_inject_pf(struct vm *vm, int vcpuid, int errcode, uint64_t cr2);
356 354
357 355 /*
358 356 * Both SVM and VMX have complex logic for injecting events such as exceptions
359 357 * or interrupts into the guest. Within those two backends, the progress of
360 358 * event injection is tracked by event_inject_state, hopefully making it easier
361 359 * to reason about.
362 360 */
363 361 enum event_inject_state {
364 362 EIS_CAN_INJECT = 0, /* exception/interrupt can be injected */
365 363 EIS_EV_EXISTING = 1, /* blocked by existing event */
366 364 EIS_EV_INJECTED = 2, /* blocked by injected event */
367 365 EIS_GI_BLOCK = 3, /* blocked by guest interruptability */
368 366
369 367 /*
370 368 * Flag to request an immediate exit from VM context after event
371 369 * injection in order to perform more processing
372 370 */
373 371 EIS_REQ_EXIT = (1 << 15),
374 372 };
375 373
376 374 void vmm_sol_glue_init(void);
377 375 void vmm_sol_glue_cleanup(void);
378 376
379 377 int vmm_mod_load(void);
380 378 int vmm_mod_unload(void);
381 379
382 380 void vmm_call_trap(uint64_t);
383 381
384 382 /*
385 383 * Because of tangled headers, this is not exposed directly via the vmm_drv
386 384 * interface, but rather mirrored as vmm_drv_iop_cb_t in vmm_drv.h.
387 385 */
388 386 typedef int (*ioport_handler_t)(void *, bool, uint16_t, uint8_t, uint32_t *);
389 387
390 388 int vm_ioport_access(struct vm *vm, int vcpuid, bool in, uint16_t port,
391 389 uint8_t bytes, uint32_t *val);
392 390
393 391 int vm_ioport_attach(struct vm *vm, uint16_t port, ioport_handler_t func,
394 392 void *arg, void **cookie);
395 393 int vm_ioport_detach(struct vm *vm, void **cookie, ioport_handler_t *old_func,
396 394 void **old_arg);
397 395
398 396 int vm_ioport_hook(struct vm *, uint16_t, ioport_handler_t, void *, void **);
399 397 void vm_ioport_unhook(struct vm *, void **);
400 398
401 399 enum vcpu_ustate {
402 400 VU_INIT = 0, /* initialized but has not yet attempted to run */
403 401 VU_RUN, /* running in guest context */
404 402 VU_IDLE, /* idle (HLTed, wait-for-SIPI, etc) */
405 403 VU_EMU_KERN, /* emulation performed in-kernel */
406 404 VU_EMU_USER, /* emulation performed in userspace */
407 405 VU_SCHED, /* off-cpu for interrupt, preempt, lock contention */
408 406 VU_MAX
409 407 };
410 408
411 409 void vcpu_ustate_change(struct vm *, int, enum vcpu_ustate);
412 410
413 411 typedef struct vmm_kstats {
414 412 kstat_named_t vk_name;
415 413 } vmm_kstats_t;
416 414
417 415 typedef struct vmm_vcpu_kstats {
418 416 kstat_named_t vvk_vcpu;
419 417 kstat_named_t vvk_time_init;
420 418 kstat_named_t vvk_time_run;
421 419 kstat_named_t vvk_time_idle;
422 420 kstat_named_t vvk_time_emu_kern;
423 421 kstat_named_t vvk_time_emu_user;
424 422 kstat_named_t vvk_time_sched;
425 423 } vmm_vcpu_kstats_t;
426 424
427 425 #define VMM_KSTAT_CLASS "misc"
428 426
429 427 int vmm_kstat_update_vcpu(struct kstat *, int);
430 428
431 429 #endif /* _VMM_KERNEL_H_ */
|
↓ open down ↓ |
221 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX