diff options
| author | Dan Cross <cross@oxidecomputer.com> | 2021-05-20 11:42:55 +0000 |
|---|---|---|
| committer | Robert Mustacchi <rm@fingolfin.org> | 2021-05-31 19:20:34 -0700 |
| commit | cf409e3f26ef8db450f46ba9760eb9734f603ae0 (patch) | |
| tree | 3e1ce27d3b4d52eb9d758aa221ad6f57f63a0682 | |
| parent | 3a9318192067bc7735a0a8b261c598c7d4129177 (diff) | |
| download | illumos-joyent-cf409e3f26ef8db450f46ba9760eb9734f603ae0.tar.gz | |
13825 consolidate vm-related headers for bhyve
Reviewed by: Patrick Mooney <pmooney@pfmooney.com>
Reviewed by: Yuri Pankov <ypankov@tintri.com>
Reviewed by: Andy Fiddaman <andy@omnios.org>
Approved by: Robert Mustacchi <rm@fingolfin.org>
27 files changed, 264 insertions, 466 deletions
diff --git a/usr/src/compat/bhyve/vm/vm.h b/usr/src/compat/bhyve/vm/vm.h deleted file mode 100644 index f5bb7b6eb8..0000000000 --- a/usr/src/compat/bhyve/vm/vm.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * This file and its contents are supplied under the terms of the - * Common Development and Distribution License ("CDDL"), version 1.0. - * You may only use this file in accordance with the terms of version - * 1.0 of the CDDL. - * - * A full copy of the text of the CDDL should have accompanied this - * source. A copy of the CDDL is also available via the Internet at - * http://www.illumos.org/license/CDDL. - */ - -/* - * Copyright 2014 Pluribus Networks Inc. - * Copyright 2017 Joyent, Inc. - */ - -#ifndef _FREEBSD_VM_VM_H_ -#define _FREEBSD_VM_VM_H_ - -#include <machine/vm.h> -#include <sys/mman.h> - -typedef u_char vm_prot_t; - -/* - * Even though the FreeBSD VM_PROT defines happen to match illumos, this - * references the native values directly so there's no risk of breakage. - */ -#define VM_PROT_NONE ((vm_prot_t) 0x00) -#define VM_PROT_READ ((vm_prot_t) PROT_READ) -#define VM_PROT_WRITE ((vm_prot_t) PROT_WRITE) -#define VM_PROT_EXECUTE ((vm_prot_t) PROT_EXEC) - -#define VM_PROT_ALL (VM_PROT_READ|VM_PROT_WRITE|VM_PROT_EXECUTE) -#define VM_PROT_RW (VM_PROT_READ|VM_PROT_WRITE) - -struct vm_page; -typedef struct vm_page *vm_page_t; - -enum obj_type { OBJT_DEFAULT, OBJT_SWAP, OBJT_VNODE, OBJT_DEVICE, OBJT_PHYS, - OBJT_DEAD, OBJT_SG, OBJT_MGTDEVICE }; -typedef u_char objtype_t; - -union vm_map_object; -typedef union vm_map_object vm_map_object_t; - -struct vm_map_entry; -typedef struct vm_map_entry *vm_map_entry_t; - -struct vm_map; -typedef struct vm_map *vm_map_t; - -struct vm_object; -typedef struct vm_object *vm_object_t; - -/* - * <sys/promif.h> contains a troublesome preprocessor define for BYTE. - * Do this ugly workaround to avoid it. - */ -#define _SYS_PROMIF_H -#include <vm/hat_i86.h> -#undef _SYS_PROMIF_H - -#endif /* _FREEBSD_VM_VM_H_ */ diff --git a/usr/src/uts/i86pc/io/vmm/amd/amdvi_hw.c b/usr/src/uts/i86pc/io/vmm/amd/amdvi_hw.c index 869b692100..c7b43b85ef 100644 --- a/usr/src/uts/i86pc/io/vmm/amd/amdvi_hw.c +++ b/usr/src/uts/i86pc/io/vmm/amd/amdvi_hw.c @@ -40,9 +40,6 @@ __FBSDID("$FreeBSD$"); #include <sys/smp.h> #include <sys/sysctl.h> -#include <vm/vm.h> -#include <vm/pmap.h> - #include <dev/pci/pcivar.h> #include <dev/pci/pcireg.h> diff --git a/usr/src/uts/i86pc/io/vmm/amd/ivrs_drv.c b/usr/src/uts/i86pc/io/vmm/amd/ivrs_drv.c index 3eb9fda2e3..4c26b61f5c 100644 --- a/usr/src/uts/i86pc/io/vmm/amd/ivrs_drv.c +++ b/usr/src/uts/i86pc/io/vmm/amd/ivrs_drv.c @@ -39,9 +39,6 @@ __FBSDID("$FreeBSD$"); #include <machine/vmparam.h> -#include <vm/vm.h> -#include <vm/pmap.h> - #include <contrib/dev/acpica/include/acpi.h> #include <contrib/dev/acpica/include/accommon.h> #include <dev/acpica/acpivar.h> diff --git a/usr/src/uts/i86pc/io/vmm/amd/npt.c b/usr/src/uts/i86pc/io/vmm/amd/npt.c index d532b7b6ec..6fc6825242 100644 --- a/usr/src/uts/i86pc/io/vmm/amd/npt.c +++ b/usr/src/uts/i86pc/io/vmm/amd/npt.c @@ -34,9 +34,7 @@ __FBSDID("$FreeBSD$"); #include <sys/systm.h> #include <sys/sysctl.h> -#include <vm/vm.h> -#include <vm/pmap.h> -#include <vm/vm_extern.h> +#include <sys/vmm_vm.h> #include "npt.h" diff --git a/usr/src/uts/i86pc/io/vmm/amd/svm.c b/usr/src/uts/i86pc/io/vmm/amd/svm.c index 7071a5ad7f..5b1ad7dba3 100644 --- a/usr/src/uts/i86pc/io/vmm/amd/svm.c +++ b/usr/src/uts/i86pc/io/vmm/amd/svm.c @@ -55,9 +55,6 @@ __FBSDID("$FreeBSD$"); #include <sys/x86_archext.h> #include <sys/trap.h> -#include <vm/vm.h> -#include <vm/pmap.h> - #include <machine/cpufunc.h> #include <machine/psl.h> #include <machine/md_var.h> @@ -67,6 +64,7 @@ __FBSDID("$FreeBSD$"); #include <machine/vmm.h> #include <machine/vmm_dev.h> #include <sys/vmm_instruction_emul.h> +#include <sys/vmm_vm.h> #include "vmm_lapic.h" #include "vmm_stat.h" @@ -667,11 +665,11 @@ npf_fault_type(uint64_t exitinfo1) { if (exitinfo1 & VMCB_NPF_INFO1_W) - return (VM_PROT_WRITE); + return (PROT_WRITE); else if (exitinfo1 & VMCB_NPF_INFO1_ID) - return (VM_PROT_EXECUTE); + return (PROT_EXEC); else - return (VM_PROT_READ); + return (PROT_READ); } static bool diff --git a/usr/src/uts/i86pc/io/vmm/intel/ept.c b/usr/src/uts/i86pc/io/vmm/intel/ept.c index 35e29bcfcc..49b01ebd36 100644 --- a/usr/src/uts/i86pc/io/vmm/intel/ept.c +++ b/usr/src/uts/i86pc/io/vmm/intel/ept.c @@ -51,11 +51,9 @@ __FBSDID("$FreeBSD$"); #include <sys/sysctl.h> #include <sys/hma.h> -#include <vm/vm.h> -#include <vm/pmap.h> -#include <vm/vm_extern.h> - +#include <machine/specialreg.h> #include <machine/vmm.h> +#include <sys/vmm_vm.h> #include "ept.h" diff --git a/usr/src/uts/i86pc/io/vmm/intel/offsets.in b/usr/src/uts/i86pc/io/vmm/intel/offsets.in index ca7f967f3b..d456693573 100644 --- a/usr/src/uts/i86pc/io/vmm/intel/offsets.in +++ b/usr/src/uts/i86pc/io/vmm/intel/offsets.in @@ -21,9 +21,9 @@ #include <machine/pmap.h> #include <machine/vmm.h> +#include <sys/vmm_vm.h> #include "intel/vmx.h" -#include "vm/vm_glue.h" vmxctx guest_rdi VMXCTX_GUEST_RDI diff --git a/usr/src/uts/i86pc/io/vmm/intel/vmcs.c b/usr/src/uts/i86pc/io/vmm/intel/vmcs.c index 36318b1b49..7fabba79f7 100644 --- a/usr/src/uts/i86pc/io/vmm/intel/vmcs.c +++ b/usr/src/uts/i86pc/io/vmm/intel/vmcs.c @@ -48,8 +48,7 @@ __FBSDID("$FreeBSD$"); #include <sys/param.h> #include <sys/systm.h> -#include <vm/vm.h> - +#include <machine/specialreg.h> #include <machine/vmm.h> #include "vmx.h" diff --git a/usr/src/uts/i86pc/io/vmm/intel/vmx.c b/usr/src/uts/i86pc/io/vmm/intel/vmx.c index 4f4c32ac69..c716c02a34 100644 --- a/usr/src/uts/i86pc/io/vmm/intel/vmx.c +++ b/usr/src/uts/i86pc/io/vmm/intel/vmx.c @@ -61,9 +61,6 @@ __FBSDID("$FreeBSD$"); #include <sys/hma.h> #include <sys/trap.h> -#include <vm/vm.h> -#include <vm/pmap.h> - #include <machine/psl.h> #include <machine/cpufunc.h> #include <machine/md_var.h> @@ -72,6 +69,7 @@ __FBSDID("$FreeBSD$"); #include <machine/smp.h> #include <machine/specialreg.h> #include <machine/vmparam.h> +#include <sys/vmm_vm.h> #include <machine/vmm.h> #include <machine/vmm_dev.h> @@ -1806,11 +1804,11 @@ ept_fault_type(uint64_t ept_qual) int fault_type; if (ept_qual & EPT_VIOLATION_DATA_WRITE) - fault_type = VM_PROT_WRITE; + fault_type = PROT_WRITE; else if (ept_qual & EPT_VIOLATION_INST_FETCH) - fault_type = VM_PROT_EXECUTE; + fault_type = PROT_EXEC; else - fault_type = VM_PROT_READ; + fault_type = PROT_READ; return (fault_type); } diff --git a/usr/src/uts/i86pc/io/vmm/intel/vtd.c b/usr/src/uts/i86pc/io/vmm/intel/vtd.c index e75764acf3..8784c94b48 100644 --- a/usr/src/uts/i86pc/io/vmm/intel/vtd.c +++ b/usr/src/uts/i86pc/io/vmm/intel/vtd.c @@ -36,12 +36,11 @@ __FBSDID("$FreeBSD$"); #include <sys/systm.h> #include <sys/malloc.h> -#include <vm/vm.h> -#include <vm/pmap.h> - #include <dev/pci/pcireg.h> #include <machine/vmparam.h> +#include <sys/vmm_vm.h> + #include <contrib/dev/acpica/include/acpi.h> #include <sys/sunndi.h> diff --git a/usr/src/uts/i86pc/io/vmm/sys/vmm_impl.h b/usr/src/uts/i86pc/io/vmm/sys/vmm_impl.h index 7240679efe..606be4bbae 100644 --- a/usr/src/uts/i86pc/io/vmm/sys/vmm_impl.h +++ b/usr/src/uts/i86pc/io/vmm/sys/vmm_impl.h @@ -35,7 +35,6 @@ * available by mmap(2)ing the vmm handle at a specific offset. These offsets * begin just above the maximum allow guest physical address. */ -#include <vm/vm_param.h> #define VM_DEVMEM_START (VM_MAXUSER_ADDRESS + 1) struct vmm_devmem_entry { diff --git a/usr/src/uts/i86pc/io/vmm/sys/vmm_vm.h b/usr/src/uts/i86pc/io/vmm/sys/vmm_vm.h new file mode 100644 index 0000000000..e9ffbadcb2 --- /dev/null +++ b/usr/src/uts/i86pc/io/vmm/sys/vmm_vm.h @@ -0,0 +1,207 @@ +/* + * This file and its contents are supplied under the terms of the + * Common Development and Distribution License ("CDDL"), version 1.0. + * You may only use this file in accordance with the terms of version + * 1.0 of the CDDL. + * + * A full copy of the text of the CDDL should have accompanied this + * source. A copy of the CDDL is also available via the Internet at + * http://www.illumos.org/license/CDDL. + */ +/* This file is dual-licensed; see usr/src/contrib/bhyve/LICENSE */ + +/* + * Copyright 2019 Joyent, Inc. + * Copyright 2021 Oxide Computer Company + */ + +#ifndef _VMM_VM_H +#define _VMM_VM_H + +#include <sys/list.h> +#include <sys/types.h> +#include <vm/hat_pte.h> +#include <machine/pmap.h> + +/* + * vm_map_wire and vm_map_unwire option flags + */ +#define VM_MAP_WIRE_SYSTEM 0 /* wiring in a kernel map */ +#define VM_MAP_WIRE_USER 1 /* wiring in a user map */ + +#define VM_MAP_WIRE_NOHOLES 0 /* region must not have holes */ +#define VM_MAP_WIRE_HOLESOK 2 /* region may have holes */ + +#define VM_MAP_WIRE_WRITE 4 /* Validate writable. */ + +/* + * The following "find_space" options are supported by vm_map_find(). + * + * For VMFS_ALIGNED_SPACE, the desired alignment is specified to + * the macro argument as log base 2 of the desired alignment. + */ +#define VMFS_NO_SPACE 0 /* don't find; use the given range */ +#define VMFS_ANY_SPACE 1 /* find range with any alignment */ +#define VMFS_OPTIMAL_SPACE 2 /* find range with optimal alignment */ +#define VMFS_SUPER_SPACE 3 /* find superpage-aligned range */ +#define VMFS_ALIGNED_SPACE(x) ((x) << 8) /* find range with fixed alignment */ + +/* + * vm_fault option flags + */ +#define VM_FAULT_NORMAL 0 /* Nothing special */ +#define VM_FAULT_WIRE 1 /* Wire the mapped page */ +#define VM_FAULT_DIRTY 2 /* Dirty the page; use w/PROT_COPY */ + +/* + * The VM_MAXUSER_ADDRESS determines the upper size limit of a vmspace. + * This value is sized well below the host userlimit, halving the + * available space below the VA hole to avoid Intel EPT limits and + * leave room available in the usable VA range for other mmap tricks. + */ +#define VM_MAXUSER_ADDRESS 0x00003ffffffffffful + +/* + * Type definitions used in the hypervisor. + */ +typedef uchar_t vm_prot_t; + +/* New type declarations. */ +struct vm; +struct vmspace; +struct pmap; + +struct vm_object; +typedef struct vm_object *vm_object_t; + +struct vmm_pt_ops; + +struct vm_page; +typedef struct vm_page *vm_page_t; + +enum obj_type { OBJT_DEFAULT, OBJT_SWAP, OBJT_VNODE, OBJT_DEVICE, OBJT_PHYS, + OBJT_DEAD, OBJT_SG, OBJT_MGTDEVICE }; +typedef uchar_t objtype_t; + +union vm_map_object; +typedef union vm_map_object vm_map_object_t; + +struct vm_map_entry; +typedef struct vm_map_entry *vm_map_entry_t; + +struct vm_map; +typedef struct vm_map *vm_map_t; + +pmap_t vmspace_pmap(struct vmspace *); + +int vm_map_find(vm_map_t, vm_object_t, vm_ooffset_t, vm_offset_t *, vm_size_t, + vm_offset_t, int, vm_prot_t, vm_prot_t, int); +int vm_map_remove(vm_map_t, vm_offset_t, vm_offset_t); +int vm_map_wire(vm_map_t map, vm_offset_t start, vm_offset_t end, int flags); + +long vmspace_resident_count(struct vmspace *vmspace); + +void pmap_invalidate_cache(void); +void pmap_get_mapping(pmap_t pmap, vm_offset_t va, uint64_t *ptr, int *num); +int pmap_emulate_accessed_dirty(pmap_t pmap, vm_offset_t va, int ftype); +long pmap_wired_count(pmap_t pmap); + +struct vm_map { + struct vmspace *vmm_space; +}; + +struct pmap { + void *pm_pml4; + cpuset_t pm_active; + long pm_eptgen; + + /* Implementation private */ + enum pmap_type pm_type; + struct vmm_pt_ops *pm_ops; + void *pm_impl; +}; + +struct vmspace { + struct vm_map vm_map; + + /* Implementation private */ + kmutex_t vms_lock; + boolean_t vms_map_changing; + struct pmap vms_pmap; + uintptr_t vms_size; /* fixed after creation */ + + list_t vms_maplist; +}; + +typedef pfn_t (*vm_pager_fn_t)(vm_object_t, uintptr_t, pfn_t *, uint_t *); + +struct vm_object { + uint_t vmo_refcnt; /* manipulated with atomic ops */ + + /* This group of fields are fixed at creation time */ + objtype_t vmo_type; + size_t vmo_size; + vm_pager_fn_t vmo_pager; + void *vmo_data; + + kmutex_t vmo_lock; /* protects fields below */ + vm_memattr_t vmo_attr; +}; + +struct vm_page { + kmutex_t vmp_lock; + pfn_t vmp_pfn; + struct vm_object *vmp_obj_held; +}; + +/* illumos-specific functions for setup and operation */ +int vm_segmap_obj(vm_object_t, off_t, size_t, struct as *, caddr_t *, uint_t, + uint_t, uint_t); +int vm_segmap_space(struct vmspace *, off_t, struct as *, caddr_t *, off_t, + uint_t, uint_t, uint_t); +void *vmspace_find_kva(struct vmspace *, uintptr_t, size_t); +void vmm_arena_init(void); +void vmm_arena_fini(void); + +struct vmm_pt_ops { + void * (*vpo_init)(uint64_t *); + void (*vpo_free)(void *); + uint64_t (*vpo_wired_cnt)(void *); + int (*vpo_is_wired)(void *, uint64_t, uint_t *); + int (*vpo_map)(void *, uint64_t, pfn_t, uint_t, uint_t, uint8_t); + uint64_t (*vpo_unmap)(void *, uint64_t, uint64_t); +}; + +extern struct vmm_pt_ops ept_ops; +extern struct vmm_pt_ops rvi_ops; + +typedef int (*pmap_pinit_t)(struct pmap *pmap); + +struct vmspace *vmspace_alloc(vm_offset_t, vm_offset_t, pmap_pinit_t); +void vmspace_free(struct vmspace *); + +int vm_fault(vm_map_t, vm_offset_t, vm_prot_t, int); +int vm_fault_quick_hold_pages(vm_map_t map, vm_offset_t addr, vm_size_t len, + vm_prot_t prot, vm_page_t *ma, int max_count); +void vmm_arena_fini(void); + + +struct vm_object *vm_object_allocate(objtype_t, vm_pindex_t); +void vm_object_deallocate(vm_object_t); +void vm_object_reference(vm_object_t); +int vm_object_set_memattr(vm_object_t, vm_memattr_t); +void vm_object_clear(vm_object_t); + +#define VM_OBJECT_WLOCK(vmo) mutex_enter(&(vmo)->vmo_lock) +#define VM_OBJECT_WUNLOCK(vmo) mutex_exit(&(vmo)->vmo_lock) + +#define PQ_ACTIVE 1 + +void vm_page_unwire(vm_page_t, uint8_t); + +#define VM_PAGE_TO_PHYS(page) (mmu_ptob((uintptr_t)((page)->vmp_pfn))) + +vm_object_t vm_pager_allocate(objtype_t, void *, vm_ooffset_t, vm_prot_t, + vm_ooffset_t, void *); + +#endif /* _VMM_VM_H */ diff --git a/usr/src/uts/i86pc/io/vmm/vm/pmap.h b/usr/src/uts/i86pc/io/vmm/vm/pmap.h deleted file mode 100644 index 680f24f171..0000000000 --- a/usr/src/uts/i86pc/io/vmm/vm/pmap.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * This file and its contents are supplied under the terms of the - * Common Development and Distribution License ("CDDL"), version 1.0. - * You may only use this file in accordance with the terms of version - * 1.0 of the CDDL. - * - * A full copy of the text of the CDDL should have accompanied this - * source. A copy of the CDDL is also available via the Internet at - * http://www.illumos.org/license/CDDL. - */ -/* This file is dual-licensed; see usr/src/contrib/bhyve/LICENSE */ - -/* - * Copyright 2017 Joyent, Inc. - */ - -#ifndef _PMAP_VM_ -#define _PMAP_VM_ - -#include <machine/pmap.h> -#include "vm_glue.h" - -void pmap_invalidate_cache(void); -void pmap_get_mapping(pmap_t pmap, vm_offset_t va, uint64_t *ptr, int *num); -int pmap_emulate_accessed_dirty(pmap_t pmap, vm_offset_t va, int ftype); -long pmap_wired_count(pmap_t pmap); - -#endif /* _PMAP_VM_ */ diff --git a/usr/src/uts/i86pc/io/vmm/vm/vm_extern.h b/usr/src/uts/i86pc/io/vmm/vm/vm_extern.h deleted file mode 100644 index fcd44ab1be..0000000000 --- a/usr/src/uts/i86pc/io/vmm/vm/vm_extern.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * This file and its contents are supplied under the terms of the - * Common Development and Distribution License ("CDDL"), version 1.0. - * You may only use this file in accordance with the terms of version - * 1.0 of the CDDL. - * - * A full copy of the text of the CDDL should have accompanied this - * source. A copy of the CDDL is also available via the Internet at - * http://www.illumos.org/license/CDDL. - */ -/* This file is dual-licensed; see usr/src/contrib/bhyve/LICENSE */ - -/* - * Copyright 2017 Joyent, Inc. - */ - -#ifndef _VM_EXTERN_H_ -#define _VM_EXTERN_H_ - -#include <sys/types.h> -#include <vm/vm.h> - -struct vmspace; -struct pmap; - -typedef int (*pmap_pinit_t)(struct pmap *pmap); - -struct vmspace *vmspace_alloc(vm_offset_t, vm_offset_t, pmap_pinit_t); -void vmspace_free(struct vmspace *); - -int vm_fault(vm_map_t, vm_offset_t, vm_prot_t, int); -int vm_fault_quick_hold_pages(vm_map_t map, vm_offset_t addr, vm_size_t len, - vm_prot_t prot, vm_page_t *ma, int max_count); - - -#endif /* _VM_EXTERN_H_ */ diff --git a/usr/src/uts/i86pc/io/vmm/vm/vm_glue.h b/usr/src/uts/i86pc/io/vmm/vm/vm_glue.h deleted file mode 100644 index 436b8e9691..0000000000 --- a/usr/src/uts/i86pc/io/vmm/vm/vm_glue.h +++ /dev/null @@ -1,101 +0,0 @@ -/* - * This file and its contents are supplied under the terms of the - * Common Development and Distribution License ("CDDL"), version 1.0. - * You may only use this file in accordance with the terms of version - * 1.0 of the CDDL. - * - * A full copy of the text of the CDDL should have accompanied this - * source. A copy of the CDDL is also available via the Internet at - * http://www.illumos.org/license/CDDL. - */ -/* This file is dual-licensed; see usr/src/contrib/bhyve/LICENSE */ - -/* - * Copyright 2019 Joyent, Inc. - * Copyright 2020 Oxide Computer Company - */ - -#ifndef _VM_GLUE_ -#define _VM_GLUE_ - -#include <vm/pmap.h> -#include <vm/vm.h> -#include <sys/cpuvar.h> - -struct vmspace; -struct vm_map; -struct pmap; -struct vm_object; -struct vmm_pt_ops; - -struct vm_map { - struct vmspace *vmm_space; -}; - -struct pmap { - void *pm_pml4; - cpuset_t pm_active; - long pm_eptgen; - - /* Implementation private */ - enum pmap_type pm_type; - struct vmm_pt_ops *pm_ops; - void *pm_impl; -}; - -struct vmspace { - struct vm_map vm_map; - - /* Implementation private */ - kmutex_t vms_lock; - boolean_t vms_map_changing; - struct pmap vms_pmap; - uintptr_t vms_size; /* fixed after creation */ - - list_t vms_maplist; -}; - -typedef pfn_t (*vm_pager_fn_t)(vm_object_t, uintptr_t, pfn_t *, uint_t *); - -struct vm_object { - uint_t vmo_refcnt; /* manipulated with atomic ops */ - - /* This group of fields are fixed at creation time */ - objtype_t vmo_type; - size_t vmo_size; - vm_pager_fn_t vmo_pager; - void *vmo_data; - - kmutex_t vmo_lock; /* protects fields below */ - vm_memattr_t vmo_attr; -}; - -struct vm_page { - kmutex_t vmp_lock; - pfn_t vmp_pfn; - struct vm_object *vmp_obj_held; -}; - -/* Illumos-specific functions for setup and operation */ -int vm_segmap_obj(vm_object_t, off_t, size_t, struct as *, caddr_t *, uint_t, - uint_t, uint_t); -int vm_segmap_space(struct vmspace *, off_t, struct as *, caddr_t *, off_t, - uint_t, uint_t, uint_t); -void *vmspace_find_kva(struct vmspace *, uintptr_t, size_t); -void vmm_arena_init(void); -void vmm_arena_fini(void); - -struct vmm_pt_ops { - void * (*vpo_init)(uint64_t *); - void (*vpo_free)(void *); - uint64_t (*vpo_wired_cnt)(void *); - int (*vpo_is_wired)(void *, uint64_t, uint_t *); - int (*vpo_map)(void *, uint64_t, pfn_t, uint_t, uint_t, uint8_t); - uint64_t (*vpo_unmap)(void *, uint64_t, uint64_t); -}; - -extern struct vmm_pt_ops ept_ops; -extern struct vmm_pt_ops rvi_ops; - - -#endif /* _VM_GLUE_ */ diff --git a/usr/src/uts/i86pc/io/vmm/vm/vm_map.h b/usr/src/uts/i86pc/io/vmm/vm/vm_map.h deleted file mode 100644 index 5e57c0b37d..0000000000 --- a/usr/src/uts/i86pc/io/vmm/vm/vm_map.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * This file and its contents are supplied under the terms of the - * Common Development and Distribution License ("CDDL"), version 1.0. - * You may only use this file in accordance with the terms of version - * 1.0 of the CDDL. - * - * A full copy of the text of the CDDL should have accompanied this - * source. A copy of the CDDL is also available via the Internet at - * http://www.illumos.org/license/CDDL. - */ -/* This file is dual-licensed; see usr/src/contrib/bhyve/LICENSE */ - -/* - * Copyright 2017 Joyent, Inc. - */ - -#ifndef _VM_MAP_ -#define _VM_MAP_ - -#include "vm_glue.h" - -/* - * vm_map_wire and vm_map_unwire option flags - */ -#define VM_MAP_WIRE_SYSTEM 0 /* wiring in a kernel map */ -#define VM_MAP_WIRE_USER 1 /* wiring in a user map */ - -#define VM_MAP_WIRE_NOHOLES 0 /* region must not have holes */ -#define VM_MAP_WIRE_HOLESOK 2 /* region may have holes */ - -#define VM_MAP_WIRE_WRITE 4 /* Validate writable. */ - -/* - * The following "find_space" options are supported by vm_map_find(). - * - * For VMFS_ALIGNED_SPACE, the desired alignment is specified to - * the macro argument as log base 2 of the desired alignment. - */ -#define VMFS_NO_SPACE 0 /* don't find; use the given range */ -#define VMFS_ANY_SPACE 1 /* find range with any alignment */ -#define VMFS_OPTIMAL_SPACE 2 /* find range with optimal alignment */ -#define VMFS_SUPER_SPACE 3 /* find superpage-aligned range */ -#define VMFS_ALIGNED_SPACE(x) ((x) << 8) /* find range with fixed alignment */ - -/* - * vm_fault option flags - */ -#define VM_FAULT_NORMAL 0 /* Nothing special */ -#define VM_FAULT_WIRE 1 /* Wire the mapped page */ -#define VM_FAULT_DIRTY 2 /* Dirty the page; use w/VM_PROT_COPY */ - - - -pmap_t vmspace_pmap(struct vmspace *); - -int vm_map_find(vm_map_t, vm_object_t, vm_ooffset_t, vm_offset_t *, vm_size_t, - vm_offset_t, int, vm_prot_t, vm_prot_t, int); -int vm_map_remove(vm_map_t, vm_offset_t, vm_offset_t); -int vm_map_wire(vm_map_t map, vm_offset_t start, vm_offset_t end, int flags); - -long vmspace_resident_count(struct vmspace *vmspace); - - -#endif /* _VM_MAP_ */ diff --git a/usr/src/uts/i86pc/io/vmm/vm/vm_object.h b/usr/src/uts/i86pc/io/vmm/vm/vm_object.h deleted file mode 100644 index c2f6391cd1..0000000000 --- a/usr/src/uts/i86pc/io/vmm/vm/vm_object.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * This file and its contents are supplied under the terms of the - * Common Development and Distribution License ("CDDL"), version 1.0. - * You may only use this file in accordance with the terms of version - * 1.0 of the CDDL. - * - * A full copy of the text of the CDDL should have accompanied this - * source. A copy of the CDDL is also available via the Internet at - * http://www.illumos.org/license/CDDL. - */ -/* This file is dual-licensed; see usr/src/contrib/bhyve/LICENSE */ - -/* - * Copyright 2017 Joyent, Inc. - */ - -#ifndef _VM_OBJECT_ -#define _VM_OBJECT_ - -#include "vm_glue.h" - -vm_object_t vm_object_allocate(objtype_t, vm_pindex_t); -void vm_object_deallocate(vm_object_t); -void vm_object_reference(vm_object_t); -int vm_object_set_memattr(vm_object_t, vm_memattr_t); -void vm_object_clear(vm_object_t); - - -#define VM_OBJECT_WLOCK(vmo) mutex_enter(&(vmo)->vmo_lock) -#define VM_OBJECT_WUNLOCK(vmo) mutex_exit(&(vmo)->vmo_lock) - -#endif /* _VM_OBJECT_ */ diff --git a/usr/src/uts/i86pc/io/vmm/vm/vm_page.h b/usr/src/uts/i86pc/io/vmm/vm/vm_page.h deleted file mode 100644 index d344c8f188..0000000000 --- a/usr/src/uts/i86pc/io/vmm/vm/vm_page.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * This file and its contents are supplied under the terms of the - * Common Development and Distribution License ("CDDL"), version 1.0. - * You may only use this file in accordance with the terms of version - * 1.0 of the CDDL. - * - * A full copy of the text of the CDDL should have accompanied this - * source. A copy of the CDDL is also available via the Internet at - * http://www.illumos.org/license/CDDL. - */ -/* This file is dual-licensed; see usr/src/contrib/bhyve/LICENSE */ - -/* - * Copyright 2017 Joyent, Inc. - */ - - -#ifndef _VM_PAGE_ -#define _VM_PAGE_ - -#include "vm_glue.h" - -#define PQ_ACTIVE 1 - -void vm_page_unwire(vm_page_t, uint8_t); - -#define VM_PAGE_TO_PHYS(page) (mmu_ptob((uintptr_t)((page)->vmp_pfn))) - -#endif /* _VM_PAGE_ */ diff --git a/usr/src/uts/i86pc/io/vmm/vm/vm_pager.h b/usr/src/uts/i86pc/io/vmm/vm/vm_pager.h deleted file mode 100644 index b4c84a9411..0000000000 --- a/usr/src/uts/i86pc/io/vmm/vm/vm_pager.h +++ /dev/null @@ -1,24 +0,0 @@ -/* - * This file and its contents are supplied under the terms of the - * Common Development and Distribution License ("CDDL"), version 1.0. - * You may only use this file in accordance with the terms of version - * 1.0 of the CDDL. - * - * A full copy of the text of the CDDL should have accompanied this - * source. A copy of the CDDL is also available via the Internet at - * http://www.illumos.org/license/CDDL. - */ -/* This file is dual-licensed; see usr/src/contrib/bhyve/LICENSE */ - -/* - * Copyright 2017 Joyent, Inc. - */ - -#ifndef _VM_PAGER_ -#define _VM_PAGER_ - -vm_object_t vm_pager_allocate(objtype_t, void *, vm_ooffset_t, vm_prot_t, - vm_ooffset_t, void *); - - -#endif /* _VM_PAGER_ */ diff --git a/usr/src/uts/i86pc/io/vmm/vmm.c b/usr/src/uts/i86pc/io/vmm/vmm.c index d9807579b4..959636c20f 100644 --- a/usr/src/uts/i86pc/io/vmm/vmm.c +++ b/usr/src/uts/i86pc/io/vmm/vmm.c @@ -61,23 +61,18 @@ __FBSDID("$FreeBSD$"); #include <sys/smp.h> #include <sys/systm.h> -#include <vm/vm.h> -#include <vm/vm_object.h> -#include <vm/vm_map.h> -#include <vm/vm_page.h> -#include <vm/pmap.h> -#include <vm/vm_extern.h> -#include <vm/vm_param.h> - #include <machine/pcb.h> #include <machine/smp.h> #include <machine/md_var.h> #include <x86/psl.h> #include <x86/apicreg.h> +#include <machine/specialreg.h> #include <machine/vmm.h> #include <machine/vmm_dev.h> +#include <machine/vmparam.h> #include <sys/vmm_instruction_emul.h> +#include <sys/vmm_vm.h> #include "vmm_ioport.h" #include "vmm_ktr.h" @@ -811,7 +806,7 @@ vm_mmap_memseg(struct vm *vm, vm_paddr_t gpa, int segid, vm_ooffset_t first, vm_ooffset_t last; int i, error; - if (prot == 0 || (prot & ~(VM_PROT_ALL)) != 0) + if (prot == 0 || (prot & ~(PROT_ALL)) != 0) return (EINVAL); if (flags & ~VM_MEMMAP_F_WIRED) @@ -845,7 +840,7 @@ vm_mmap_memseg(struct vm *vm, vm_paddr_t gpa, int segid, vm_ooffset_t first, error = vm_map_find(&vm->vmspace->vm_map, seg->object, first, &gpa, len, 0, VMFS_NO_SPACE, prot, prot, 0); - if (error != KERN_SUCCESS) + if (error != 0) return (EFAULT); vm_object_reference(seg->object); @@ -853,10 +848,9 @@ vm_mmap_memseg(struct vm *vm, vm_paddr_t gpa, int segid, vm_ooffset_t first, if ((flags & VM_MEMMAP_F_WIRED) != 0) { error = vm_map_wire(&vm->vmspace->vm_map, gpa, gpa + len, VM_MAP_WIRE_USER | VM_MAP_WIRE_NOHOLES); - if (error != KERN_SUCCESS) { + if (error != 0) { vm_map_remove(&vm->vmspace->vm_map, gpa, gpa + len); - return (error == KERN_RESOURCE_SHORTAGE ? ENOMEM : - EFAULT); + return (EFAULT); } } @@ -931,7 +925,7 @@ vm_free_memmap(struct vm *vm, int ident) if (mm->len) { error = vm_map_remove(&vm->vmspace->vm_map, mm->gpa, mm->gpa + mm->len); - KASSERT(error == KERN_SUCCESS, ("%s: vm_map_remove error %d", + KASSERT(error == 0, ("%s: vm_map_remove error %d", __func__, error)); bzero(mm, sizeof (struct mem_map)); } @@ -1003,7 +997,7 @@ vm_iommu_modify(struct vm *vm, bool map) gpa = mm->gpa; while (gpa < mm->gpa + mm->len) { - vp = vm_gpa_hold(vm, -1, gpa, PAGE_SIZE, VM_PROT_WRITE, + vp = vm_gpa_hold(vm, -1, gpa, PAGE_SIZE, PROT_WRITE, &cookie); KASSERT(vp != NULL, ("vm(%s) could not map gpa %lx", vm_name(vm), gpa)); @@ -1502,16 +1496,16 @@ vm_handle_paging(struct vm *vm, int vcpuid) __func__, vme->inst_length)); ftype = vme->u.paging.fault_type; - KASSERT(ftype == VM_PROT_READ || - ftype == VM_PROT_WRITE || ftype == VM_PROT_EXECUTE, + KASSERT(ftype == PROT_READ || + ftype == PROT_WRITE || ftype == PROT_EXEC, ("vm_handle_paging: invalid fault_type %d", ftype)); - if (ftype == VM_PROT_READ || ftype == VM_PROT_WRITE) { + if (ftype == PROT_READ || ftype == PROT_WRITE) { rv = pmap_emulate_accessed_dirty(vmspace_pmap(vm->vmspace), vme->u.paging.gpa, ftype); if (rv == 0) { VCPU_CTR2(vm, vcpuid, "%s bit emulation for gpa %lx", - ftype == VM_PROT_READ ? "accessed" : "dirty", + ftype == PROT_READ ? "accessed" : "dirty", vme->u.paging.gpa); goto done; } @@ -1523,7 +1517,7 @@ vm_handle_paging(struct vm *vm, int vcpuid) VCPU_CTR3(vm, vcpuid, "vm_handle_paging rv = %d, gpa = %lx, " "ftype = %d", rv, vme->u.paging.gpa, ftype); - if (rv != KERN_SUCCESS) + if (rv != 0) return (EFAULT); done: return (0); diff --git a/usr/src/uts/i86pc/io/vmm/vmm_instruction_emul.c b/usr/src/uts/i86pc/io/vmm/vmm_instruction_emul.c index b0501a60ad..ea0b0ae379 100644 --- a/usr/src/uts/i86pc/io/vmm/vmm_instruction_emul.c +++ b/usr/src/uts/i86pc/io/vmm/vmm_instruction_emul.c @@ -51,12 +51,10 @@ __FBSDID("$FreeBSD$"); #include <sys/systm.h> #include <sys/proc.h> -#include <vm/vm.h> -#include <vm/pmap.h> - #include <machine/vmparam.h> #include <machine/vmm.h> #include <sys/vmm_kernel.h> +#include <sys/vmm_vm.h> #include <sys/vmm_instruction_emul.h> #include <x86/psl.h> @@ -2724,13 +2722,13 @@ pf_error_code(int usermode, int prot, int rsvd, uint64_t pte) if (pte & PG_V) error_code |= PGEX_P; - if (prot & VM_PROT_WRITE) + if (prot & PROT_WRITE) error_code |= PGEX_W; if (usermode) error_code |= PGEX_U; if (rsvd) error_code |= PGEX_RSV; - if (prot & VM_PROT_EXECUTE) + if (prot & PROT_EXEC) error_code |= PGEX_I; return (error_code); @@ -2751,7 +2749,9 @@ ptp_hold(struct vm *vm, int vcpu, vm_paddr_t ptpphys, size_t len, void **cookie) void *ptr; ptp_release(cookie); - ptr = vm_gpa_hold(vm, vcpu, ptpphys, len, VM_PROT_RW, cookie); + ptr = vm_gpa_hold(vm, vcpu, ptpphys, len, PROT_READ | PROT_WRITE, + cookie); + return (ptr); } @@ -2769,7 +2769,7 @@ _vm_gla2gpa(struct vm *vm, int vcpuid, struct vm_guest_paging *paging, *guest_fault = 0; usermode = (paging->cpl == 3 ? 1 : 0); - writable = prot & VM_PROT_WRITE; + writable = prot & PROT_WRITE; cookie = NULL; retval = 0; restart: diff --git a/usr/src/uts/i86pc/io/vmm/vmm_mem.c b/usr/src/uts/i86pc/io/vmm/vmm_mem.c index 26862397a1..4ffe5bf509 100644 --- a/usr/src/uts/i86pc/io/vmm/vmm_mem.c +++ b/usr/src/uts/i86pc/io/vmm/vmm_mem.c @@ -34,19 +34,14 @@ __FBSDID("$FreeBSD$"); #include <sys/param.h> #include <sys/systm.h> #include <sys/malloc.h> +#include <sys/mman.h> #include <sys/sglist.h> #include <sys/lock.h> #include <sys/rwlock.h> -#include <vm/vm.h> -#include <vm/vm_param.h> -#include <vm/pmap.h> -#include <vm/vm_map.h> -#include <vm/vm_object.h> -#include <vm/vm_page.h> -#include <vm/vm_pager.h> - #include <machine/md_var.h> +#include <machine/vm.h> +#include <sys/vmm_vm.h> #include "vmm_mem.h" @@ -69,7 +64,8 @@ vmm_mmio_alloc(struct vmspace *vmspace, vm_paddr_t gpa, size_t len, error = sglist_append_phys(sg, hpa, len); KASSERT(error == 0, ("error %d appending physaddr to sglist", error)); - obj = vm_pager_allocate(OBJT_SG, sg, len, VM_PROT_RW, 0, NULL); + const int prot = PROT_READ | PROT_WRITE; + obj = vm_pager_allocate(OBJT_SG, sg, len, prot, 0, NULL); if (obj != NULL) { /* * VT-x ignores the MTRR settings when figuring out the @@ -81,13 +77,13 @@ vmm_mmio_alloc(struct vmspace *vmspace, vm_paddr_t gpa, size_t len, VM_OBJECT_WLOCK(obj); error = vm_object_set_memattr(obj, VM_MEMATTR_UNCACHEABLE); VM_OBJECT_WUNLOCK(obj); - if (error != KERN_SUCCESS) { + if (error != 0) { panic("vmm_mmio_alloc: vm_object_set_memattr error %d", error); } error = vm_map_find(&vmspace->vm_map, obj, 0, &gpa, len, 0, - VMFS_NO_SPACE, VM_PROT_RW, VM_PROT_RW, 0); - if (error != KERN_SUCCESS) { + VMFS_NO_SPACE, prot, prot, 0); + if (error != 0) { vm_object_deallocate(obj); obj = NULL; } diff --git a/usr/src/uts/i86pc/io/vmm/vmm_sol_dev.c b/usr/src/uts/i86pc/io/vmm/vmm_sol_dev.c index 4508087980..d5f4b3883b 100644 --- a/usr/src/uts/i86pc/io/vmm/vmm_sol_dev.c +++ b/usr/src/uts/i86pc/io/vmm/vmm_sol_dev.c @@ -44,8 +44,8 @@ #include <sys/vmm_dev.h> #include <sys/vmm_impl.h> #include <sys/vmm_drv.h> +#include <sys/vmm_vm.h> -#include <vm/vm.h> #include <vm/seg_dev.h> #include "io/ppt.h" @@ -57,7 +57,6 @@ #include "vmm_lapic.h" #include "vmm_stat.h" #include "vmm_util.h" -#include "vm/vm_glue.h" /* * Locking details: @@ -1184,10 +1183,6 @@ vmmdev_do_ioctl(vmm_softc_t *sc, int cmd, intptr_t arg, int md, case VM_GLA2GPA: { struct vm_gla2gpa gg; - CTASSERT(PROT_READ == VM_PROT_READ); - CTASSERT(PROT_WRITE == VM_PROT_WRITE); - CTASSERT(PROT_EXEC == VM_PROT_EXECUTE); - if (ddi_copyin(datap, &gg, sizeof (gg), md)) { error = EFAULT; break; @@ -1204,10 +1199,6 @@ vmmdev_do_ioctl(vmm_softc_t *sc, int cmd, intptr_t arg, int md, case VM_GLA2GPA_NOFAULT: { struct vm_gla2gpa gg; - CTASSERT(PROT_READ == VM_PROT_READ); - CTASSERT(PROT_WRITE == VM_PROT_WRITE); - CTASSERT(PROT_EXEC == VM_PROT_EXECUTE); - if (ddi_copyin(datap, &gg, sizeof (gg), md)) { error = EFAULT; break; diff --git a/usr/src/uts/i86pc/io/vmm/vmm_sol_ept.c b/usr/src/uts/i86pc/io/vmm/vmm_sol_ept.c index 01403642b4..b43a6cac1d 100644 --- a/usr/src/uts/i86pc/io/vmm/vmm_sol_ept.c +++ b/usr/src/uts/i86pc/io/vmm/vmm_sol_ept.c @@ -12,15 +12,17 @@ /* * Copyright 2019 Joyent, Inc. + * Copyright 2021 Oxide Computer Company */ #include <sys/types.h> #include <sys/param.h> #include <sys/kmem.h> #include <sys/machsystm.h> +#include <sys/mman.h> #include <sys/gipt.h> -#include <vm/vm_glue.h> +#include <sys/vmm_vm.h> struct ept_map { diff --git a/usr/src/uts/i86pc/io/vmm/vmm_sol_glue.c b/usr/src/uts/i86pc/io/vmm/vmm_sol_glue.c index 7968f461f7..afd686f197 100644 --- a/usr/src/uts/i86pc/io/vmm/vmm_sol_glue.c +++ b/usr/src/uts/i86pc/io/vmm/vmm_sol_glue.c @@ -63,6 +63,7 @@ #include <machine/pmap.h> #include <machine/specialreg.h> #include <machine/vmm.h> +#include <machine/vmparam.h> #include <sys/vmm_impl.h> #include <sys/kernel.h> diff --git a/usr/src/uts/i86pc/io/vmm/vmm_sol_rvi.c b/usr/src/uts/i86pc/io/vmm/vmm_sol_rvi.c index 4a2ce5b3f7..f82ea64994 100644 --- a/usr/src/uts/i86pc/io/vmm/vmm_sol_rvi.c +++ b/usr/src/uts/i86pc/io/vmm/vmm_sol_rvi.c @@ -12,17 +12,19 @@ /* * Copyright 2019 Joyent, Inc. + * Copyright 2021 Oxide Computer Company */ #include <sys/types.h> #include <sys/param.h> #include <sys/kmem.h> #include <sys/machsystm.h> +#include <sys/mach_mmu.h> +#include <sys/mman.h> #include <sys/x86_archext.h> #include <sys/gipt.h> -#include <vm/vm_glue.h> - +#include <sys/vmm_vm.h> struct rvi_map { gipt_map_t rm_gipt; diff --git a/usr/src/uts/i86pc/io/vmm/vmm_sol_vm.c b/usr/src/uts/i86pc/io/vmm/vmm_sol_vm.c index a280c1d255..04fbb94c83 100644 --- a/usr/src/uts/i86pc/io/vmm/vmm_sol_vm.c +++ b/usr/src/uts/i86pc/io/vmm/vmm_sol_vm.c @@ -12,7 +12,7 @@ /* * Copyright 2019 Joyent, Inc. - * Copyright 2020 Oxide Computer Company + * Copyright 2021 Oxide Computer Company * Copyright 2021 OmniOS Community Edition (OmniOSce) Association. */ @@ -29,13 +29,13 @@ #include <sys/malloc.h> #include <sys/x86_archext.h> #include <vm/as.h> +#include <vm/hat_i86.h> #include <vm/seg_vn.h> #include <vm/seg_kmem.h> #include <vm/seg_vmm.h> -#include <vm/vm_extern.h> -#include <vm/vm_map.h> -#include "vm/vm_glue.h" +#include <machine/vm.h> +#include <sys/vmm_vm.h> #define PMAP_TO_VMMAP(pm) ((vm_map_t) \ ((caddr_t)(pm) - offsetof(struct vmspace, vms_pmap))) |
