xref: /illumos-gate/usr/src/uts/intel/io/vmm/sys/vmm_impl.h (revision fc910014e8a32a65612105835a10995f2c13d942)
1 /*
2  * This file and its contents are supplied under the terms of the
3  * Common Development and Distribution License ("CDDL"), version 1.0.
4  * You may only use this file in accordance with the terms of version
5  * 1.0 of the CDDL.
6  *
7  * A full copy of the text of the CDDL should have accompanied this
8  * source.  A copy of the CDDL is also available via the Internet at
9  * http://www.illumos.org/license/CDDL.
10  */
11 /* This file is dual-licensed; see usr/src/contrib/bhyve/LICENSE */
12 
13 /*
14  * Copyright 2014 Pluribus Networks Inc.
15  * Copyright 2019 Joyent, Inc.
16  * Copyright 2022 Oxide Computer Company
17  */
18 
19 #ifndef _VMM_IMPL_H_
20 #define	_VMM_IMPL_H_
21 
22 #include <sys/mutex.h>
23 #include <sys/queue.h>
24 #include <sys/varargs.h>
25 #include <sys/zone.h>
26 #include <sys/kstat.h>
27 #include <sys/vmm.h>
28 
29 #ifdef	_KERNEL
30 
31 #define	VMM_CTL_MINOR	0
32 
33 /*
34  * Rather than creating whole character devices for devmem mappings, they are
35  * available by mmap(2)ing the vmm handle at a specific offset.  These offsets
36  * begin just above the maximum allow guest physical address.
37  */
38 #define	VM_DEVMEM_START	(VM_MAXUSER_ADDRESS + 1)
39 
40 struct vmm_devmem_entry {
41 	list_node_t	vde_node;
42 	int		vde_segid;
43 	char		vde_name[VM_MAX_SEG_NAMELEN];
44 	size_t		vde_len;
45 	off_t		vde_off;
46 };
47 typedef struct vmm_devmem_entry vmm_devmem_entry_t;
48 
49 typedef struct vmm_zsd vmm_zsd_t;
50 
51 enum vmm_softc_state {
52 	VMM_HELD	= 1,	/* external driver(s) possess hold on the VM */
53 	VMM_BLOCK_HOOK	= 2,	/* mem hook install temporarily blocked */
54 	VMM_DESTROY	= 4,	/* VM destruction initiated */
55 	VMM_IS_OPEN	= 8,	/* VM device is open */
56 	VMM_AUTODESTROY	= 16,	/* auto-destroy instance on close */
57 };
58 
59 struct vmm_softc {
60 	list_node_t	vmm_node;
61 	struct vm	*vmm_vm;
62 	minor_t		vmm_minor;
63 	char		vmm_name[VM_MAX_NAMELEN];
64 	list_t		vmm_devmem_list;
65 
66 	kcondvar_t	vmm_cv;
67 	list_t		vmm_holds;
68 	uint_t		vmm_flags;
69 	uint_t		vmm_destroy_waiters;
70 
71 	kmutex_t	vmm_lease_lock;
72 	list_t		vmm_lease_list;
73 	uint_t		vmm_lease_blocker;
74 	kcondvar_t	vmm_lease_cv;
75 	krwlock_t	vmm_rwlock;
76 
77 	/* For zone specific data */
78 	list_node_t	vmm_zsd_linkage;
79 	zone_t		*vmm_zone;
80 	vmm_zsd_t	*vmm_zsd;
81 
82 	kstat_t		*vmm_kstat_vm;
83 	kstat_t		*vmm_kstat_vcpu[VM_MAXCPU];
84 };
85 typedef struct vmm_softc vmm_softc_t;
86 
87 void vmm_zsd_init(void);
88 void vmm_zsd_fini(void);
89 int vmm_zsd_add_vm(vmm_softc_t *sc);
90 void vmm_zsd_rem_vm(vmm_softc_t *sc);
91 void vmm_zone_vm_destroy(vmm_softc_t *);
92 
93 #define	VMM_MODULE_NAME	"vmm"
94 
95 #endif /* _KERNEL */
96 
97 #endif	/* _VMM_IMPL_H_ */
98