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