1 /*
2 * Copyright (c) 2016 Apple Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28
29 #include <sys/sysctl.h>
30
31 extern kern_return_t test_pmap_enter_disconnect(unsigned int);
32 extern kern_return_t test_pmap_compress_remove(unsigned int);
33 extern kern_return_t test_pmap_exec_remove(unsigned int);
34 extern kern_return_t test_pmap_nesting(unsigned int);
35 extern kern_return_t test_pmap_iommu_disconnect(void);
36 extern kern_return_t test_pmap_extended(void);
37 extern void test_pmap_call_overhead(unsigned int);
38 extern uint64_t test_pmap_page_protect_overhead(unsigned int, unsigned int);
39 #if CONFIG_SPTM
40 extern kern_return_t test_pmap_huge_pv_list(unsigned int, unsigned int);
41 #endif
42
43 static int
sysctl_test_pmap_enter_disconnect(__unused struct sysctl_oid * oidp,__unused void * arg1,__unused int arg2,struct sysctl_req * req)44 sysctl_test_pmap_enter_disconnect(__unused struct sysctl_oid *oidp, __unused void *arg1, __unused int arg2, struct sysctl_req *req)
45 {
46 unsigned int num_loops;
47 int error, changed;
48 error = sysctl_io_number(req, 0, sizeof(num_loops), &num_loops, &changed);
49 if (error || !changed) {
50 return error;
51 }
52 return test_pmap_enter_disconnect(num_loops);
53 }
54
55 SYSCTL_PROC(_kern, OID_AUTO, pmap_enter_disconnect_test,
56 CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_LOCKED,
57 0, 0, sysctl_test_pmap_enter_disconnect, "I", "");
58
59 static int
sysctl_test_pmap_compress_remove(__unused struct sysctl_oid * oidp,__unused void * arg1,__unused int arg2,struct sysctl_req * req)60 sysctl_test_pmap_compress_remove(__unused struct sysctl_oid *oidp, __unused void *arg1, __unused int arg2, struct sysctl_req *req)
61 {
62 unsigned int num_loops;
63 int error, changed;
64 error = sysctl_io_number(req, 0, sizeof(num_loops), &num_loops, &changed);
65 if (error || !changed) {
66 return error;
67 }
68 return test_pmap_compress_remove(num_loops);
69 }
70
71 SYSCTL_PROC(_kern, OID_AUTO, pmap_compress_remove_test,
72 CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_LOCKED,
73 0, 0, sysctl_test_pmap_compress_remove, "I", "");
74
75 static int
sysctl_test_pmap_exec_remove(__unused struct sysctl_oid * oidp,__unused void * arg1,__unused int arg2,struct sysctl_req * req)76 sysctl_test_pmap_exec_remove(__unused struct sysctl_oid *oidp, __unused void *arg1, __unused int arg2, struct sysctl_req *req)
77 {
78 unsigned int num_loops;
79 int error, changed;
80 error = sysctl_io_number(req, 0, sizeof(num_loops), &num_loops, &changed);
81 if (error || !changed) {
82 return error;
83 }
84 return test_pmap_exec_remove(num_loops);
85 }
86
87 SYSCTL_PROC(_kern, OID_AUTO, pmap_exec_remove_test,
88 CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_LOCKED,
89 0, 0, sysctl_test_pmap_exec_remove, "I", "");
90
91 static int
sysctl_test_pmap_nesting(__unused struct sysctl_oid * oidp,__unused void * arg1,__unused int arg2,struct sysctl_req * req)92 sysctl_test_pmap_nesting(__unused struct sysctl_oid *oidp, __unused void *arg1, __unused int arg2, struct sysctl_req *req)
93 {
94 unsigned int num_loops;
95 int error, changed;
96 error = sysctl_io_number(req, 0, sizeof(num_loops), &num_loops, &changed);
97 if (error || !changed) {
98 return error;
99 }
100 return test_pmap_nesting(num_loops);
101 }
102 SYSCTL_PROC(_kern, OID_AUTO, pmap_nesting_test,
103 CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_LOCKED,
104 0, 0, sysctl_test_pmap_nesting, "I", "");
105
106 static int
sysctl_test_pmap_iommu_disconnect(__unused struct sysctl_oid * oidp,__unused void * arg1,__unused int arg2,struct sysctl_req * req)107 sysctl_test_pmap_iommu_disconnect(__unused struct sysctl_oid *oidp, __unused void *arg1, __unused int arg2, struct sysctl_req *req)
108 {
109 unsigned int run = 0;
110 int error, changed;
111 error = sysctl_io_number(req, 0, sizeof(run), &run, &changed);
112 if (error || !changed) {
113 return error;
114 }
115 return test_pmap_iommu_disconnect();
116 }
117
118 SYSCTL_PROC(_kern, OID_AUTO, pmap_iommu_disconnect_test,
119 CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_LOCKED,
120 0, 0, sysctl_test_pmap_iommu_disconnect, "I", "");
121
122 static int
sysctl_test_pmap_extended(__unused struct sysctl_oid * oidp,__unused void * arg1,__unused int arg2,struct sysctl_req * req)123 sysctl_test_pmap_extended(__unused struct sysctl_oid *oidp, __unused void *arg1, __unused int arg2, struct sysctl_req *req)
124 {
125 unsigned int run = 0;
126 int error, changed;
127 error = sysctl_io_number(req, 0, sizeof(run), &run, &changed);
128 if (error || !changed) {
129 return error;
130 }
131 return test_pmap_extended();
132 }
133
134 SYSCTL_PROC(_kern, OID_AUTO, pmap_extended_test,
135 CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_LOCKED,
136 0, 0, sysctl_test_pmap_extended, "I", "");
137
138 static int
sysctl_test_pmap_call_overhead(__unused struct sysctl_oid * oidp,__unused void * arg1,__unused int arg2,struct sysctl_req * req)139 sysctl_test_pmap_call_overhead(__unused struct sysctl_oid *oidp, __unused void *arg1, __unused int arg2, struct sysctl_req *req)
140 {
141 unsigned int num_loops;
142 int error, changed;
143 error = sysctl_io_number(req, 0, sizeof(num_loops), &num_loops, &changed);
144 if (error || !changed) {
145 return error;
146 }
147 test_pmap_call_overhead(num_loops);
148 return 0;
149 }
150
151 SYSCTL_PROC(_kern, OID_AUTO, pmap_call_overhead_test,
152 CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_LOCKED,
153 0, 0, sysctl_test_pmap_call_overhead, "I", "");
154
155 static int
sysctl_test_pmap_page_protect_overhead(__unused struct sysctl_oid * oidp,__unused void * arg1,__unused int arg2,struct sysctl_req * req)156 sysctl_test_pmap_page_protect_overhead(__unused struct sysctl_oid *oidp, __unused void *arg1, __unused int arg2, struct sysctl_req *req)
157 {
158 struct {
159 unsigned int num_loops;
160 unsigned int num_aliases;
161 } ppo_in;
162
163 int error;
164 uint64_t duration;
165
166 error = SYSCTL_IN(req, &ppo_in, sizeof(ppo_in));
167 if (error) {
168 return error;
169 }
170
171 duration = test_pmap_page_protect_overhead(ppo_in.num_loops, ppo_in.num_aliases);
172 error = SYSCTL_OUT(req, &duration, sizeof(duration));
173 return error;
174 }
175
176 SYSCTL_PROC(_kern, OID_AUTO, pmap_page_protect_overhead_test,
177 CTLTYPE_OPAQUE | CTLFLAG_RW | CTLFLAG_LOCKED, 0, 0, sysctl_test_pmap_page_protect_overhead, "-", "");
178
179 #if CONFIG_SPTM
180
181 static int
sysctl_test_pmap_huge_pv_list(__unused struct sysctl_oid * oidp,__unused void * arg1,__unused int arg2,struct sysctl_req * req)182 sysctl_test_pmap_huge_pv_list(__unused struct sysctl_oid *oidp, __unused void *arg1, __unused int arg2, struct sysctl_req *req)
183 {
184 struct {
185 unsigned int num_loops;
186 unsigned int num_mappings;
187 } hugepv_in;
188
189 int error = SYSCTL_IN(req, &hugepv_in, sizeof(hugepv_in));
190 if (error) {
191 return error;
192 }
193 return test_pmap_huge_pv_list(hugepv_in.num_loops, hugepv_in.num_mappings);
194 }
195
196 SYSCTL_PROC(_kern, OID_AUTO, pmap_huge_pv_list_test,
197 CTLTYPE_OPAQUE | CTLFLAG_RW | CTLFLAG_LOCKED, 0, 0, sysctl_test_pmap_huge_pv_list, "-", "");
198
199 #endif
200