Print this page
seg_inherit_notsup is redundant since segop_inherit checks for NULL properly
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 */
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_dump(struct seg *);
↓ open down ↓ |
105 lines elided |
↑ open up ↑ |
106 106 static int segkpm_pagelock(struct seg *seg, caddr_t addr, size_t len,
107 107 struct page ***page, enum lock_type type,
108 108 enum seg_rw rw);
109 109 static int segkpm_capable(struct seg *, segcapability_t);
110 110
111 111 static struct seg_ops segkpm_ops = {
112 112 .fault = segkpm_fault,
113 113 .dump = segkpm_dump,
114 114 .pagelock = segkpm_pagelock,
115 115 .capable = segkpm_capable,
116 - .inherit = seg_inherit_notsup,
117 116 //#ifndef SEGKPM_SUPPORT
118 117 #if 0
119 118 #error FIXME: define nop
120 119 .dup = nop,
121 120 .unmap = nop,
122 121 .free = nop,
123 122 .faulta = nop,
124 123 .setprot = nop,
125 124 .checkprot = nop,
126 125 .kluster = nop,
127 126 .sync = nop,
128 127 .incore = nop,
129 128 .lockop = nop,
130 129 .getprot = nop,
131 130 .getoffset = nop,
132 131 .gettype = nop,
133 132 .getvp = nop,
134 133 .advise = nop,
135 134 .setpagesize = nop,
136 135 .getmemid = nop,
137 136 .getpolicy = nop,
138 137 #endif
139 138 };
140 139
141 140 /*
142 141 * kpm_pgsz and kpm_pgshft are set by platform layer.
143 142 */
144 143 size_t kpm_pgsz; /* kpm page size */
145 144 uint_t kpm_pgshft; /* kpm page shift */
146 145 u_offset_t kpm_pgoff; /* kpm page offset mask */
147 146 uint_t kpmp2pshft; /* kpm page to page shift */
148 147 pgcnt_t kpmpnpgs; /* how many pages per kpm page */
149 148
150 149
151 150 #ifdef SEGKPM_SUPPORT
152 151
153 152 int
154 153 segkpm_create(struct seg *seg, void *argsp)
155 154 {
156 155 struct segkpm_data *skd;
157 156 struct segkpm_crargs *b = (struct segkpm_crargs *)argsp;
158 157 ushort_t *p;
159 158 int i, j;
160 159
161 160 ASSERT(seg->s_as && RW_WRITE_HELD(&seg->s_as->a_lock));
162 161 ASSERT(btokpmp(seg->s_size) >= 1 &&
163 162 kpmpageoff((uintptr_t)seg->s_base) == 0 &&
164 163 kpmpageoff((uintptr_t)seg->s_base + seg->s_size) == 0);
165 164
166 165 skd = kmem_zalloc(sizeof (struct segkpm_data), KM_SLEEP);
167 166
168 167 seg->s_data = (void *)skd;
169 168 seg->s_ops = &segkpm_ops;
170 169 skd->skd_prot = b->prot;
171 170
172 171 /*
173 172 * (1) Segkpm virtual addresses are based on physical adresses.
174 173 * From this and in opposite to other segment drivers it is
175 174 * often required to allocate a page first to be able to
176 175 * calculate the final segkpm virtual address.
177 176 * (2) Page allocation is done by calling page_create_va(),
178 177 * one important input argument is a virtual address (also
179 178 * expressed by the "va" in the function name). This function
180 179 * is highly optimized to select the right page for an optimal
181 180 * processor and platform support (e.g. virtual addressed
182 181 * caches (VAC), physical addressed caches, NUMA).
183 182 *
184 183 * Because of (1) the approach is to generate a faked virtual
185 184 * address for calling page_create_va(). In order to exploit
186 185 * the abilities of (2), especially to utilize the cache
187 186 * hierarchy (3) and to avoid VAC alias conflicts (4) the
188 187 * selection has to be done carefully. For each virtual color
189 188 * a separate counter is provided (4). The count values are
190 189 * used for the utilization of all cache lines (3) and are
191 190 * corresponding to the cache bins.
192 191 */
193 192 skd->skd_nvcolors = b->nvcolors;
194 193
195 194 p = skd->skd_va_select =
196 195 kmem_zalloc(NCPU * b->nvcolors * sizeof (ushort_t), KM_SLEEP);
197 196
198 197 for (i = 0; i < NCPU; i++)
199 198 for (j = 0; j < b->nvcolors; j++, p++)
200 199 *p = j;
201 200
202 201 return (0);
203 202 }
204 203
205 204 /*
206 205 * This routine is called via a machine specific fault handling
207 206 * routine.
208 207 */
209 208 /* ARGSUSED */
210 209 faultcode_t
211 210 segkpm_fault(struct hat *hat, struct seg *seg, caddr_t addr, size_t len,
212 211 enum fault_type type, enum seg_rw rw)
213 212 {
214 213 ASSERT(seg->s_as && AS_LOCK_HELD(seg->s_as, &seg->s_as->a_lock));
215 214
216 215 switch (type) {
217 216 case F_INVAL:
218 217 return (hat_kpm_fault(hat, addr));
219 218 case F_SOFTLOCK:
220 219 case F_SOFTUNLOCK:
221 220 return (0);
222 221 default:
223 222 return (FC_NOSUPPORT);
224 223 }
225 224 /*NOTREACHED*/
226 225 }
227 226
228 227 #define addr_to_vcolor(addr, vcolors) \
229 228 ((int)(((uintptr_t)(addr) & ((vcolors << PAGESHIFT) - 1)) >> PAGESHIFT))
230 229
231 230 /*
232 231 * Create a virtual address that can be used for invocations of
233 232 * page_create_va. Goal is to utilize the cache hierarchy (round
234 233 * robin bins) and to select the right color for virtual indexed
235 234 * caches. It isn't exact since we also increment the bin counter
236 235 * when the caller uses VOP_GETPAGE and gets a hit in the page
237 236 * cache, but we keep the bins turning for cache distribution
238 237 * (see also segkpm_create block comment).
239 238 */
240 239 caddr_t
241 240 segkpm_create_va(u_offset_t off)
242 241 {
243 242 int vcolor;
244 243 ushort_t *p;
245 244 struct segkpm_data *skd = (struct segkpm_data *)segkpm->s_data;
246 245 int nvcolors = skd->skd_nvcolors;
247 246 caddr_t va;
248 247
249 248 vcolor = (nvcolors > 1) ? addr_to_vcolor(off, nvcolors) : 0;
250 249 p = &skd->skd_va_select[(CPU->cpu_id * nvcolors) + vcolor];
251 250 va = (caddr_t)ptob(*p);
252 251
253 252 atomic_add_16(p, nvcolors);
254 253
255 254 return (va);
256 255 }
257 256
258 257 /*
259 258 * Unload mapping if the instance has an active kpm mapping.
260 259 */
261 260 void
262 261 segkpm_mapout_validkpme(struct kpme *kpme)
263 262 {
264 263 caddr_t vaddr;
265 264 page_t *pp;
266 265
267 266 retry:
268 267 if ((pp = kpme->kpe_page) == NULL) {
269 268 return;
270 269 }
271 270
272 271 if (page_lock(pp, SE_SHARED, (kmutex_t *)NULL, P_RECLAIM) == 0)
273 272 goto retry;
274 273
275 274 /*
276 275 * Check if segkpm mapping is not unloaded in the meantime
277 276 */
278 277 if (kpme->kpe_page == NULL) {
279 278 page_unlock(pp);
280 279 return;
281 280 }
282 281
283 282 vaddr = hat_kpm_page2va(pp, 1);
284 283 hat_kpm_mapout(pp, kpme, vaddr);
285 284 page_unlock(pp);
286 285 }
287 286
288 287 #else /* SEGKPM_SUPPORT */
289 288
290 289 /* segkpm stubs */
291 290
292 291 /*ARGSUSED*/
293 292 int segkpm_create(struct seg *seg, void *argsp)
294 293 {
295 294 return (0);
296 295 }
297 296
298 297 /* ARGSUSED */
299 298 faultcode_t
300 299 segkpm_fault(struct hat *hat, struct seg *seg, caddr_t addr, size_t len,
301 300 enum fault_type type, enum seg_rw rw)
302 301 {
303 302 return (0);
304 303 }
305 304
306 305 /* ARGSUSED */
307 306 caddr_t segkpm_create_va(u_offset_t off)
308 307 {
309 308 return (NULL);
310 309 }
311 310
312 311 /* ARGSUSED */
313 312 void segkpm_mapout_validkpme(struct kpme *kpme)
314 313 {
315 314 }
316 315
317 316 #endif /* SEGKPM_SUPPORT */
318 317
319 318 /* ARGSUSED */
320 319 static int
321 320 segkpm_pagelock(struct seg *seg, caddr_t addr, size_t len,
322 321 struct page ***page, enum lock_type type, enum seg_rw rw)
323 322 {
324 323 return (ENOTSUP);
325 324 }
326 325
327 326 /*
328 327 * segkpm pages are not dumped, so we just return
329 328 */
330 329 /*ARGSUSED*/
331 330 static void
332 331 segkpm_dump(struct seg *seg)
333 332 {
334 333 }
335 334
336 335 /*
337 336 * We claim to have no special capabilities.
338 337 */
339 338 /*ARGSUSED*/
340 339 static int
341 340 segkpm_capable(struct seg *seg, segcapability_t capability)
342 341 {
343 342 return (0);
344 343 }
↓ open down ↓ |
218 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX