Print this page
6153 use NULL pagelock segop as a shorthand for ENOTSUP
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/vm/seg_kpm.c
+++ new/usr/src/uts/common/vm/seg_kpm.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License, Version 1.0 only
6 6 * (the "License"). You may not use this file except in compliance
7 7 * with the License.
8 8 *
9 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 10 * or http://www.opensolaris.org/os/licensing.
11 11 * See the License for the specific language governing permissions
12 12 * and limitations under the License.
13 13 *
14 14 * When distributing Covered Code, include this CDDL HEADER in each
15 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 16 * If applicable, add the following below this CDDL HEADER, with the
17 17 * fields enclosed by brackets "[]" replaced with your own identifying
18 18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 19 *
20 20 * CDDL HEADER END
21 21 */
22 22 /*
23 23 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
24 24 * Use is subject to license terms.
25 25 */
26 26
27 27 /*
28 28 * Kernel Physical Mapping (kpm) segment driver (segkpm).
29 29 *
30 30 * This driver delivers along with the hat_kpm* interfaces an alternative
31 31 * mechanism for kernel mappings within the 64-bit Solaris operating system,
32 32 * which allows the mapping of all physical memory into the kernel address
33 33 * space at once. This is feasible in 64 bit kernels, e.g. for Ultrasparc II
34 34 * and beyond processors, since the available VA range is much larger than
35 35 * possible physical memory. Momentarily all physical memory is supported,
36 36 * that is represented by the list of memory segments (memsegs).
37 37 *
38 38 * Segkpm mappings have also very low overhead and large pages are used
39 39 * (when possible) to minimize the TLB and TSB footprint. It is also
40 40 * extentable for other than Sparc architectures (e.g. AMD64). Main
41 41 * advantage is the avoidance of the TLB-shootdown X-calls, which are
42 42 * normally needed when a kernel (global) mapping has to be removed.
43 43 *
44 44 * First example of a kernel facility that uses the segkpm mapping scheme
45 45 * is seg_map, where it is used as an alternative to hat_memload().
46 46 * See also hat layer for more information about the hat_kpm* routines.
47 47 * The kpm facilty can be turned off at boot time (e.g. /etc/system).
48 48 */
49 49
50 50 #include <sys/types.h>
51 51 #include <sys/param.h>
52 52 #include <sys/sysmacros.h>
53 53 #include <sys/systm.h>
54 54 #include <sys/vnode.h>
55 55 #include <sys/cmn_err.h>
56 56 #include <sys/debug.h>
57 57 #include <sys/thread.h>
58 58 #include <sys/cpuvar.h>
59 59 #include <sys/bitmap.h>
60 60 #include <sys/atomic.h>
61 61 #include <sys/lgrp.h>
62 62
63 63 #include <vm/seg_kmem.h>
64 64 #include <vm/seg_kpm.h>
65 65 #include <vm/hat.h>
66 66 #include <vm/as.h>
67 67 #include <vm/seg.h>
68 68 #include <vm/page.h>
69 69
70 70 /*
71 71 * Global kpm controls.
72 72 * See also platform and mmu specific controls.
73 73 *
74 74 * kpm_enable -- global on/off switch for segkpm.
75 75 * . Set by default on 64bit platforms that have kpm support.
76 76 * . Will be disabled from platform layer if not supported.
77 77 * . Can be disabled via /etc/system.
78 78 *
79 79 * kpm_smallpages -- use only regular/system pagesize for kpm mappings.
80 80 * . Can be useful for critical debugging of kpm clients.
81 81 * . Set to zero by default for platforms that support kpm large pages.
82 82 * The use of kpm large pages reduces the footprint of kpm meta data
83 83 * and has all the other advantages of using large pages (e.g TLB
84 84 * miss reduction).
85 85 * . Set by default for platforms that don't support kpm large pages or
86 86 * where large pages cannot be used for other reasons (e.g. there are
87 87 * only few full associative TLB entries available for large pages).
88 88 *
89 89 * segmap_kpm -- separate on/off switch for segmap using segkpm:
90 90 * . Set by default.
91 91 * . Will be disabled when kpm_enable is zero.
92 92 * . Will be disabled when MAXBSIZE != PAGESIZE.
93 93 * . Can be disabled via /etc/system.
94 94 *
95 95 */
↓ open down ↓ |
95 lines elided |
↑ open up ↑ |
96 96 int kpm_enable = 1;
97 97 int kpm_smallpages = 0;
98 98 int segmap_kpm = 1;
99 99
100 100 /*
101 101 * Private seg op routines.
102 102 */
103 103 faultcode_t segkpm_fault(struct hat *hat, struct seg *seg, caddr_t addr,
104 104 size_t len, enum fault_type type, enum seg_rw rw);
105 105 static void segkpm_badop(void);
106 -static int segkpm_notsup(void);
107 106
108 107 #define SEGKPM_BADOP(t) (t(*)())segkpm_badop
109 -#define SEGKPM_NOTSUP (int(*)())segkpm_notsup
110 108
111 109 static struct seg_ops segkpm_ops = {
112 110 .dup = SEGKPM_BADOP(int),
113 111 .unmap = SEGKPM_BADOP(int),
114 112 .free = SEGKPM_BADOP(void),
115 113 .fault = segkpm_fault,
116 114 .faulta = SEGKPM_BADOP(int),
117 115 .setprot = SEGKPM_BADOP(int),
118 116 .checkprot = SEGKPM_BADOP(int),
119 117 .kluster = SEGKPM_BADOP(int),
120 118 .swapout = SEGKPM_BADOP(size_t),
121 119 .sync = SEGKPM_BADOP(int),
122 120 .incore = SEGKPM_BADOP(size_t),
123 121 .lockop = SEGKPM_BADOP(int),
124 122 .getprot = SEGKPM_BADOP(int),
125 123 .getoffset = SEGKPM_BADOP(u_offset_t),
126 124 .gettype = SEGKPM_BADOP(int),
127 125 .getvp = SEGKPM_BADOP(int),
128 126 .advise = SEGKPM_BADOP(int),
129 - .pagelock = SEGKPM_NOTSUP,
130 127 .setpagesize = SEGKPM_BADOP(int),
131 128 .getmemid = SEGKPM_BADOP(int),
132 129 .getpolicy = SEGKPM_BADOP(lgrp_mem_policy_info_t *),
133 130 };
134 131
135 132 /*
136 133 * kpm_pgsz and kpm_pgshft are set by platform layer.
137 134 */
138 135 size_t kpm_pgsz; /* kpm page size */
139 136 uint_t kpm_pgshft; /* kpm page shift */
140 137 u_offset_t kpm_pgoff; /* kpm page offset mask */
141 138 uint_t kpmp2pshft; /* kpm page to page shift */
142 139 pgcnt_t kpmpnpgs; /* how many pages per kpm page */
143 140
144 141
145 142 #ifdef SEGKPM_SUPPORT
146 143
147 144 int
148 145 segkpm_create(struct seg *seg, void *argsp)
149 146 {
150 147 struct segkpm_data *skd;
151 148 struct segkpm_crargs *b = (struct segkpm_crargs *)argsp;
152 149 ushort_t *p;
153 150 int i, j;
154 151
155 152 ASSERT(seg->s_as && RW_WRITE_HELD(&seg->s_as->a_lock));
156 153 ASSERT(btokpmp(seg->s_size) >= 1 &&
157 154 kpmpageoff((uintptr_t)seg->s_base) == 0 &&
158 155 kpmpageoff((uintptr_t)seg->s_base + seg->s_size) == 0);
159 156
160 157 skd = kmem_zalloc(sizeof (struct segkpm_data), KM_SLEEP);
161 158
162 159 seg->s_data = (void *)skd;
163 160 seg->s_ops = &segkpm_ops;
164 161 skd->skd_prot = b->prot;
165 162
166 163 /*
167 164 * (1) Segkpm virtual addresses are based on physical adresses.
168 165 * From this and in opposite to other segment drivers it is
169 166 * often required to allocate a page first to be able to
170 167 * calculate the final segkpm virtual address.
171 168 * (2) Page allocation is done by calling page_create_va(),
172 169 * one important input argument is a virtual address (also
173 170 * expressed by the "va" in the function name). This function
174 171 * is highly optimized to select the right page for an optimal
175 172 * processor and platform support (e.g. virtual addressed
176 173 * caches (VAC), physical addressed caches, NUMA).
177 174 *
178 175 * Because of (1) the approach is to generate a faked virtual
179 176 * address for calling page_create_va(). In order to exploit
180 177 * the abilities of (2), especially to utilize the cache
181 178 * hierarchy (3) and to avoid VAC alias conflicts (4) the
182 179 * selection has to be done carefully. For each virtual color
183 180 * a separate counter is provided (4). The count values are
184 181 * used for the utilization of all cache lines (3) and are
185 182 * corresponding to the cache bins.
186 183 */
187 184 skd->skd_nvcolors = b->nvcolors;
188 185
189 186 p = skd->skd_va_select =
190 187 kmem_zalloc(NCPU * b->nvcolors * sizeof (ushort_t), KM_SLEEP);
191 188
192 189 for (i = 0; i < NCPU; i++)
193 190 for (j = 0; j < b->nvcolors; j++, p++)
194 191 *p = j;
195 192
196 193 return (0);
197 194 }
198 195
199 196 /*
200 197 * This routine is called via a machine specific fault handling
201 198 * routine.
202 199 */
203 200 /* ARGSUSED */
204 201 faultcode_t
205 202 segkpm_fault(struct hat *hat, struct seg *seg, caddr_t addr, size_t len,
206 203 enum fault_type type, enum seg_rw rw)
207 204 {
208 205 ASSERT(seg->s_as && AS_LOCK_HELD(seg->s_as, &seg->s_as->a_lock));
209 206
210 207 switch (type) {
211 208 case F_INVAL:
212 209 return (hat_kpm_fault(hat, addr));
213 210 case F_SOFTLOCK:
214 211 case F_SOFTUNLOCK:
215 212 return (0);
216 213 default:
217 214 return (FC_NOSUPPORT);
218 215 }
219 216 /*NOTREACHED*/
220 217 }
221 218
222 219 #define addr_to_vcolor(addr, vcolors) \
223 220 ((int)(((uintptr_t)(addr) & ((vcolors << PAGESHIFT) - 1)) >> PAGESHIFT))
224 221
225 222 /*
226 223 * Create a virtual address that can be used for invocations of
227 224 * page_create_va. Goal is to utilize the cache hierarchy (round
228 225 * robin bins) and to select the right color for virtual indexed
229 226 * caches. It isn't exact since we also increment the bin counter
230 227 * when the caller uses VOP_GETPAGE and gets a hit in the page
231 228 * cache, but we keep the bins turning for cache distribution
232 229 * (see also segkpm_create block comment).
233 230 */
234 231 caddr_t
235 232 segkpm_create_va(u_offset_t off)
236 233 {
237 234 int vcolor;
238 235 ushort_t *p;
239 236 struct segkpm_data *skd = (struct segkpm_data *)segkpm->s_data;
240 237 int nvcolors = skd->skd_nvcolors;
241 238 caddr_t va;
242 239
243 240 vcolor = (nvcolors > 1) ? addr_to_vcolor(off, nvcolors) : 0;
244 241 p = &skd->skd_va_select[(CPU->cpu_id * nvcolors) + vcolor];
245 242 va = (caddr_t)ptob(*p);
246 243
247 244 atomic_add_16(p, nvcolors);
248 245
249 246 return (va);
250 247 }
251 248
252 249 /*
253 250 * Unload mapping if the instance has an active kpm mapping.
254 251 */
255 252 void
256 253 segkpm_mapout_validkpme(struct kpme *kpme)
257 254 {
258 255 caddr_t vaddr;
259 256 page_t *pp;
260 257
261 258 retry:
262 259 if ((pp = kpme->kpe_page) == NULL) {
263 260 return;
264 261 }
265 262
266 263 if (page_lock(pp, SE_SHARED, (kmutex_t *)NULL, P_RECLAIM) == 0)
267 264 goto retry;
268 265
269 266 /*
270 267 * Check if segkpm mapping is not unloaded in the meantime
271 268 */
272 269 if (kpme->kpe_page == NULL) {
273 270 page_unlock(pp);
274 271 return;
275 272 }
276 273
277 274 vaddr = hat_kpm_page2va(pp, 1);
278 275 hat_kpm_mapout(pp, kpme, vaddr);
279 276 page_unlock(pp);
280 277 }
281 278
282 279 static void
283 280 segkpm_badop()
284 281 {
285 282 panic("segkpm_badop");
286 283 }
287 284
288 285 #else /* SEGKPM_SUPPORT */
289 286
290 287 /* segkpm stubs */
291 288
292 289 /*ARGSUSED*/
293 290 int segkpm_create(struct seg *seg, void *argsp) { return (0); }
294 291
295 292 /* ARGSUSED */
296 293 faultcode_t
297 294 segkpm_fault(struct hat *hat, struct seg *seg, caddr_t addr, size_t len,
298 295 enum fault_type type, enum seg_rw rw)
299 296 {
300 297 return ((faultcode_t)0);
301 298 }
302 299
↓ open down ↓ |
163 lines elided |
↑ open up ↑ |
303 300 /* ARGSUSED */
304 301 caddr_t segkpm_create_va(u_offset_t off) { return (NULL); }
305 302
306 303 /* ARGSUSED */
307 304 void segkpm_mapout_validkpme(struct kpme *kpme) {}
308 305
309 306 static void
310 307 segkpm_badop() {}
311 308
312 309 #endif /* SEGKPM_SUPPORT */
313 -
314 -static int
315 -segkpm_notsup()
316 -{
317 - return (ENOTSUP);
318 -}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX