Print this page
6151 use NULL setpagesize segop as a shorthand for ENOTSUP
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/sparc/v9/vm/seg_nf.c
+++ new/usr/src/uts/sparc/v9/vm/seg_nf.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 (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
23 23 * Use is subject to license terms.
24 24 */
25 25
26 26 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
27 27 /* All Rights Reserved */
28 28
29 29 /*
30 30 * Portions of this source code were derived from Berkeley 4.3 BSD
31 31 * under license from the Regents of the University of California.
32 32 */
33 33
34 34 /*
35 35 * VM - segment for non-faulting loads.
36 36 */
37 37
38 38 #include <sys/types.h>
39 39 #include <sys/t_lock.h>
40 40 #include <sys/param.h>
41 41 #include <sys/mman.h>
42 42 #include <sys/errno.h>
43 43 #include <sys/kmem.h>
44 44 #include <sys/cmn_err.h>
45 45 #include <sys/vnode.h>
46 46 #include <sys/proc.h>
47 47 #include <sys/conf.h>
48 48 #include <sys/debug.h>
49 49 #include <sys/archsystm.h>
50 50 #include <sys/lgrp.h>
51 51
52 52 #include <vm/page.h>
53 53 #include <vm/hat.h>
54 54 #include <vm/as.h>
55 55 #include <vm/seg.h>
56 56 #include <vm/vpage.h>
57 57
58 58 /*
59 59 * Private seg op routines.
60 60 */
61 61 static int segnf_dup(struct seg *seg, struct seg *newseg);
62 62 static int segnf_unmap(struct seg *seg, caddr_t addr, size_t len);
63 63 static void segnf_free(struct seg *seg);
64 64 static faultcode_t segnf_nomap(void);
65 65 static int segnf_setprot(struct seg *seg, caddr_t addr,
66 66 size_t len, uint_t prot);
67 67 static int segnf_checkprot(struct seg *seg, caddr_t addr,
68 68 size_t len, uint_t prot);
↓ open down ↓ |
68 lines elided |
↑ open up ↑ |
69 69 static void segnf_badop(void);
70 70 static int segnf_nop(void);
71 71 static int segnf_getprot(struct seg *seg, caddr_t addr,
72 72 size_t len, uint_t *protv);
73 73 static u_offset_t segnf_getoffset(struct seg *seg, caddr_t addr);
74 74 static int segnf_gettype(struct seg *seg, caddr_t addr);
75 75 static int segnf_getvp(struct seg *seg, caddr_t addr, struct vnode **vpp);
76 76 static void segnf_dump(struct seg *seg);
77 77 static int segnf_pagelock(struct seg *seg, caddr_t addr, size_t len,
78 78 struct page ***ppp, enum lock_type type, enum seg_rw rw);
79 -static int segnf_setpagesize(struct seg *seg, caddr_t addr, size_t len,
80 - uint_t szc);
81 79
82 80
83 81 struct seg_ops segnf_ops = {
84 82 .dup = segnf_dup,
85 83 .unmap = segnf_unmap,
86 84 .free = segnf_free,
87 85 .fault = (faultcode_t (*)(struct hat *, struct seg *, caddr_t,
88 86 size_t, enum fault_type, enum seg_rw))segnf_nomap,
89 87 .faulta = (faultcode_t (*)(struct seg *, caddr_t)) segnf_nomap,
90 88 .setprot = segnf_setprot,
91 89 .checkprot = segnf_checkprot,
92 90 .kluster = (int (*)())segnf_badop,
93 91 .sync = (int (*)(struct seg *, caddr_t, size_t, int, uint_t))
94 92 segnf_nop,
95 93 .incore = (size_t (*)(struct seg *, caddr_t, size_t, char *))
96 94 segnf_nop,
↓ open down ↓ |
6 lines elided |
↑ open up ↑ |
97 95 .lockop = (int (*)(struct seg *, caddr_t, size_t, int, int,
98 96 ulong_t *, size_t))segnf_nop,
99 97 .getprot = segnf_getprot,
100 98 .getoffset = segnf_getoffset,
101 99 .gettype = segnf_gettype,
102 100 .getvp = segnf_getvp,
103 101 .advise = (int (*)(struct seg *, caddr_t, size_t, uint_t))
104 102 segnf_nop,
105 103 .dump = segnf_dump,
106 104 .pagelock = segnf_pagelock,
107 - .setpagesize = segnf_setpagesize,
108 105 };
109 106
110 107 /*
111 108 * vnode and page for the page of zeros we use for the nf mappings.
112 109 */
113 110 static kmutex_t segnf_lock;
114 111 static struct vnode nfvp;
115 112 static struct page **nfpp;
116 113
117 114 #define addr_to_vcolor(addr) \
118 115 (shm_alignment) ? \
119 116 ((int)(((uintptr_t)(addr) & (shm_alignment - 1)) >> PAGESHIFT)) : 0
120 117
121 118 /*
122 119 * We try to limit the number of Non-fault segments created.
123 120 * Non fault segments are created to optimize sparc V9 code which uses
124 121 * the sparc nonfaulting load ASI (ASI_PRIMARY_NOFAULT).
125 122 *
126 123 * There are several reasons why creating too many non-fault segments
127 124 * could cause problems.
128 125 *
129 126 * First, excessive allocation of kernel resources for the seg
130 127 * structures and the HAT data to map the zero pages.
131 128 *
132 129 * Secondly, creating nofault segments actually uses up user virtual
133 130 * address space. This makes it unavailable for subsequent mmap(0, ...)
134 131 * calls which use as_gap() to find empty va regions. Creation of too
135 132 * many nofault segments could thus interfere with the ability of the
136 133 * runtime linker to load a shared object.
137 134 */
138 135 #define MAXSEGFORNF (10000)
139 136 #define MAXNFSEARCH (5)
140 137
141 138
142 139 /*
143 140 * Must be called from startup()
144 141 */
145 142 void
146 143 segnf_init()
147 144 {
148 145 mutex_init(&segnf_lock, NULL, MUTEX_DEFAULT, NULL);
149 146 }
150 147
151 148
152 149 /*
153 150 * Create a no-fault segment.
154 151 *
155 152 * The no-fault segment is not technically necessary, as the code in
156 153 * nfload() in trap.c will emulate the SPARC instruction and load
157 154 * a value of zero in the destination register.
158 155 *
159 156 * However, this code tries to put a page of zero's at the nofault address
160 157 * so that subsequent non-faulting loads to the same page will not
161 158 * trap with a tlb miss.
162 159 *
163 160 * In order to help limit the number of segments we merge adjacent nofault
164 161 * segments into a single segment. If we get a large number of segments
165 162 * we'll also try to delete a random other nf segment.
166 163 */
167 164 /* ARGSUSED */
168 165 int
169 166 segnf_create(struct seg *seg, void *argsp)
170 167 {
171 168 uint_t prot;
172 169 pgcnt_t vacpgs;
173 170 u_offset_t off = 0;
174 171 caddr_t vaddr = NULL;
175 172 int i, color;
176 173 struct seg *s1;
177 174 struct seg *s2;
178 175 size_t size;
179 176 struct as *as = seg->s_as;
180 177
181 178 ASSERT(as && AS_WRITE_HELD(as, &as->a_lock));
182 179
183 180 /*
184 181 * Need a page per virtual color or just 1 if no vac.
185 182 */
186 183 mutex_enter(&segnf_lock);
187 184 if (nfpp == NULL) {
188 185 struct seg kseg;
189 186
190 187 vacpgs = 1;
191 188 if (shm_alignment > PAGESIZE) {
192 189 vacpgs = shm_alignment >> PAGESHIFT;
193 190 }
194 191
195 192 nfpp = kmem_alloc(sizeof (*nfpp) * vacpgs, KM_SLEEP);
196 193
197 194 kseg.s_as = &kas;
198 195 for (i = 0; i < vacpgs; i++, off += PAGESIZE,
199 196 vaddr += PAGESIZE) {
200 197 nfpp[i] = page_create_va(&nfvp, off, PAGESIZE,
201 198 PG_WAIT | PG_NORELOC, &kseg, vaddr);
202 199 page_io_unlock(nfpp[i]);
203 200 page_downgrade(nfpp[i]);
204 201 pagezero(nfpp[i], 0, PAGESIZE);
205 202 }
206 203 }
207 204 mutex_exit(&segnf_lock);
208 205
209 206 hat_map(as->a_hat, seg->s_base, seg->s_size, HAT_MAP);
210 207
211 208 /*
212 209 * s_data can't be NULL because of ASSERTS in the common vm code.
213 210 */
214 211 seg->s_ops = &segnf_ops;
215 212 seg->s_data = seg;
216 213 seg->s_flags |= S_PURGE;
217 214
218 215 mutex_enter(&as->a_contents);
219 216 as->a_flags |= AS_NEEDSPURGE;
220 217 mutex_exit(&as->a_contents);
221 218
222 219 prot = PROT_READ;
223 220 color = addr_to_vcolor(seg->s_base);
224 221 if (as != &kas)
225 222 prot |= PROT_USER;
226 223 hat_memload(as->a_hat, seg->s_base, nfpp[color],
227 224 prot | HAT_NOFAULT, HAT_LOAD);
228 225
229 226 /*
230 227 * At this point see if we can concatenate a segment to
231 228 * a non-fault segment immediately before and/or after it.
232 229 */
233 230 if ((s1 = AS_SEGPREV(as, seg)) != NULL &&
234 231 s1->s_ops == &segnf_ops &&
235 232 s1->s_base + s1->s_size == seg->s_base) {
236 233 size = s1->s_size;
237 234 seg_free(s1);
238 235 seg->s_base -= size;
239 236 seg->s_size += size;
240 237 }
241 238
242 239 if ((s2 = AS_SEGNEXT(as, seg)) != NULL &&
243 240 s2->s_ops == &segnf_ops &&
244 241 seg->s_base + seg->s_size == s2->s_base) {
245 242 size = s2->s_size;
246 243 seg_free(s2);
247 244 seg->s_size += size;
248 245 }
249 246
250 247 /*
251 248 * if we already have a lot of segments, try to delete some other
252 249 * nofault segment to reduce the probability of uncontrolled segment
253 250 * creation.
254 251 *
255 252 * the code looks around quickly (no more than MAXNFSEARCH segments
256 253 * each way) for another NF segment and then deletes it.
257 254 */
258 255 if (avl_numnodes(&as->a_segtree) > MAXSEGFORNF) {
259 256 size = 0;
260 257 s2 = NULL;
261 258 s1 = AS_SEGPREV(as, seg);
262 259 while (size++ < MAXNFSEARCH && s1 != NULL) {
263 260 if (s1->s_ops == &segnf_ops)
264 261 s2 = s1;
265 262 s1 = AS_SEGPREV(s1->s_as, seg);
266 263 }
267 264 if (s2 == NULL) {
268 265 s1 = AS_SEGNEXT(as, seg);
269 266 while (size-- > 0 && s1 != NULL) {
270 267 if (s1->s_ops == &segnf_ops)
271 268 s2 = s1;
272 269 s1 = AS_SEGNEXT(as, seg);
273 270 }
274 271 }
275 272 if (s2 != NULL)
276 273 seg_unmap(s2);
277 274 }
278 275
279 276 return (0);
280 277 }
281 278
282 279 /*
283 280 * Never really need "No fault" segments, so they aren't dup'd.
284 281 */
285 282 /* ARGSUSED */
286 283 static int
287 284 segnf_dup(struct seg *seg, struct seg *newseg)
288 285 {
289 286 panic("segnf_dup");
290 287 return (0);
291 288 }
292 289
293 290 /*
294 291 * Split a segment at addr for length len.
295 292 */
296 293 static int
297 294 segnf_unmap(struct seg *seg, caddr_t addr, size_t len)
298 295 {
299 296 ASSERT(seg->s_as && AS_WRITE_HELD(seg->s_as, &seg->s_as->a_lock));
300 297
301 298 /*
302 299 * Check for bad sizes.
303 300 */
304 301 if (addr < seg->s_base || addr + len > seg->s_base + seg->s_size ||
305 302 (len & PAGEOFFSET) || ((uintptr_t)addr & PAGEOFFSET)) {
306 303 cmn_err(CE_PANIC, "segnf_unmap: bad unmap size");
307 304 }
308 305
309 306 /*
310 307 * Unload any hardware translations in the range to be taken out.
311 308 */
312 309 hat_unload(seg->s_as->a_hat, addr, len, HAT_UNLOAD_UNMAP);
313 310
314 311 if (addr == seg->s_base && len == seg->s_size) {
315 312 /*
316 313 * Freeing entire segment.
317 314 */
318 315 seg_free(seg);
319 316 } else if (addr == seg->s_base) {
320 317 /*
321 318 * Freeing the beginning of the segment.
322 319 */
323 320 seg->s_base += len;
324 321 seg->s_size -= len;
325 322 } else if (addr + len == seg->s_base + seg->s_size) {
326 323 /*
327 324 * Freeing the end of the segment.
328 325 */
329 326 seg->s_size -= len;
330 327 } else {
331 328 /*
332 329 * The section to go is in the middle of the segment, so we
333 330 * have to cut it into two segments. We shrink the existing
334 331 * "seg" at the low end, and create "nseg" for the high end.
335 332 */
336 333 caddr_t nbase = addr + len;
337 334 size_t nsize = (seg->s_base + seg->s_size) - nbase;
338 335 struct seg *nseg;
339 336
340 337 /*
341 338 * Trim down "seg" before trying to stick "nseg" into the as.
342 339 */
343 340 seg->s_size = addr - seg->s_base;
344 341 nseg = seg_alloc(seg->s_as, nbase, nsize);
345 342 if (nseg == NULL)
346 343 cmn_err(CE_PANIC, "segnf_unmap: seg_alloc failed");
347 344
348 345 /*
349 346 * s_data can't be NULL because of ASSERTs in common VM code.
350 347 */
351 348 nseg->s_ops = seg->s_ops;
352 349 nseg->s_data = nseg;
353 350 nseg->s_flags |= S_PURGE;
354 351 mutex_enter(&seg->s_as->a_contents);
355 352 seg->s_as->a_flags |= AS_NEEDSPURGE;
356 353 mutex_exit(&seg->s_as->a_contents);
357 354 }
358 355
359 356 return (0);
360 357 }
361 358
362 359 /*
363 360 * Free a segment.
364 361 */
365 362 static void
366 363 segnf_free(struct seg *seg)
367 364 {
368 365 ASSERT(seg->s_as && AS_WRITE_HELD(seg->s_as, &seg->s_as->a_lock));
369 366 }
370 367
371 368 /*
372 369 * No faults allowed on segnf.
373 370 */
374 371 static faultcode_t
375 372 segnf_nomap(void)
376 373 {
377 374 return (FC_NOMAP);
378 375 }
379 376
380 377 /* ARGSUSED */
381 378 static int
382 379 segnf_setprot(struct seg *seg, caddr_t addr, size_t len, uint_t prot)
383 380 {
384 381 ASSERT(seg->s_as && AS_LOCK_HELD(seg->s_as, &seg->s_as->a_lock));
385 382 return (EACCES);
386 383 }
387 384
388 385 /* ARGSUSED */
389 386 static int
390 387 segnf_checkprot(struct seg *seg, caddr_t addr, size_t len, uint_t prot)
391 388 {
392 389 uint_t sprot;
393 390 ASSERT(seg->s_as && AS_LOCK_HELD(seg->s_as, &seg->s_as->a_lock));
394 391
395 392 sprot = seg->s_as == &kas ? PROT_READ : PROT_READ|PROT_USER;
396 393 return ((prot & sprot) == prot ? 0 : EACCES);
397 394 }
398 395
399 396 static void
400 397 segnf_badop(void)
401 398 {
402 399 panic("segnf_badop");
403 400 /*NOTREACHED*/
404 401 }
405 402
406 403 static int
407 404 segnf_nop(void)
408 405 {
409 406 return (0);
410 407 }
411 408
412 409 static int
413 410 segnf_getprot(struct seg *seg, caddr_t addr, size_t len, uint_t *protv)
414 411 {
415 412 size_t pgno = seg_page(seg, addr + len) - seg_page(seg, addr) + 1;
416 413 size_t p;
417 414 ASSERT(seg->s_as && AS_LOCK_HELD(seg->s_as, &seg->s_as->a_lock));
418 415
419 416 for (p = 0; p < pgno; ++p)
420 417 protv[p] = PROT_READ;
421 418 return (0);
422 419 }
423 420
424 421 /* ARGSUSED */
425 422 static u_offset_t
426 423 segnf_getoffset(struct seg *seg, caddr_t addr)
427 424 {
428 425 ASSERT(seg->s_as && AS_LOCK_HELD(seg->s_as, &seg->s_as->a_lock));
429 426
430 427 return ((u_offset_t)0);
431 428 }
432 429
433 430 /* ARGSUSED */
434 431 static int
435 432 segnf_gettype(struct seg *seg, caddr_t addr)
436 433 {
437 434 ASSERT(seg->s_as && AS_LOCK_HELD(seg->s_as, &seg->s_as->a_lock));
438 435
439 436 return (MAP_SHARED);
440 437 }
441 438
442 439 /* ARGSUSED */
443 440 static int
444 441 segnf_getvp(struct seg *seg, caddr_t addr, struct vnode **vpp)
445 442 {
446 443 ASSERT(seg->s_as && AS_LOCK_HELD(seg->s_as, &seg->s_as->a_lock));
447 444
448 445 *vpp = &nfvp;
449 446 return (0);
450 447 }
451 448
452 449 /*
453 450 * segnf pages are not dumped, so we just return
↓ open down ↓ |
336 lines elided |
↑ open up ↑ |
454 451 */
455 452 /* ARGSUSED */
456 453 static void
457 454 segnf_dump(struct seg *seg)
458 455 {}
459 456
460 457 /*ARGSUSED*/
461 458 static int
462 459 segnf_pagelock(struct seg *seg, caddr_t addr, size_t len,
463 460 struct page ***ppp, enum lock_type type, enum seg_rw rw)
464 -{
465 - return (ENOTSUP);
466 -}
467 -
468 -/*ARGSUSED*/
469 -static int
470 -segnf_setpagesize(struct seg *seg, caddr_t addr, size_t len,
471 - uint_t szc)
472 461 {
473 462 return (ENOTSUP);
474 463 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX