xref: /titanic_51/usr/src/uts/common/os/dumpsubr.c (revision a776e90690d98f629ab57f6493ff5949af9d65bd)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #pragma ident	"%Z%%M%	%I%	%E% SMI"
27 
28 #include <sys/types.h>
29 #include <sys/param.h>
30 #include <sys/systm.h>
31 #include <sys/vm.h>
32 #include <sys/proc.h>
33 #include <sys/file.h>
34 #include <sys/conf.h>
35 #include <sys/kmem.h>
36 #include <sys/mem.h>
37 #include <sys/mman.h>
38 #include <sys/vnode.h>
39 #include <sys/errno.h>
40 #include <sys/memlist.h>
41 #include <sys/dumphdr.h>
42 #include <sys/dumpadm.h>
43 #include <sys/ksyms.h>
44 #include <sys/compress.h>
45 #include <sys/stream.h>
46 #include <sys/strsun.h>
47 #include <sys/cmn_err.h>
48 #include <sys/bitmap.h>
49 #include <sys/modctl.h>
50 #include <sys/utsname.h>
51 #include <sys/systeminfo.h>
52 #include <sys/vmem.h>
53 #include <sys/log.h>
54 #include <sys/var.h>
55 #include <sys/debug.h>
56 #include <sys/sunddi.h>
57 #include <fs/fs_subr.h>
58 #include <sys/fs/snode.h>
59 #include <sys/ontrap.h>
60 #include <sys/panic.h>
61 #include <sys/dkio.h>
62 #include <sys/vtoc.h>
63 #include <sys/errorq.h>
64 #include <sys/fm/util.h>
65 
66 #include <vm/hat.h>
67 #include <vm/as.h>
68 #include <vm/page.h>
69 #include <vm/seg.h>
70 #include <vm/seg_kmem.h>
71 
72 kmutex_t	dump_lock;	/* lock for dump configuration */
73 dumphdr_t	*dumphdr;	/* dump header */
74 int		dump_conflags = DUMP_KERNEL; /* dump configuration flags */
75 vnode_t		*dumpvp;	/* dump device vnode pointer */
76 u_offset_t	dumpvp_size;	/* size of dump device, in bytes */
77 static u_offset_t dumpvp_limit;	/* maximum write offset */
78 char		*dumppath;	/* pathname of dump device */
79 int		dump_timeout = 120; /* timeout for dumping page during panic */
80 int		dump_timeleft;	/* portion of dump_timeout remaining */
81 int		dump_ioerr;	/* dump i/o error */
82 
83 #ifdef DEBUG
84 int		dumpfaildebug = 1;	/* enter debugger if dump fails */
85 #else
86 int		dumpfaildebug = 0;
87 #endif
88 
89 static ulong_t	*dump_bitmap;	/* bitmap for marking pages to dump */
90 static pgcnt_t	dump_bitmapsize; /* size of bitmap */
91 static pid_t	*dump_pids;	/* list of process IDs at dump time */
92 static offset_t	dumpvp_off;	/* current dump device offset */
93 static char	*dump_cmap;	/* VA for dump compression mapping */
94 static char	*dumpbuf_cur, *dumpbuf_start, *dumpbuf_end;
95 static char	*dump_cbuf;	/* compression buffer */
96 static char	*dump_uebuf;	/* memory error detection buffer */
97 static size_t	dumpbuf_size;	/* size of dumpbuf in bytes */
98 static size_t	dumpbuf_limit = 1UL << 23;	/* 8MB */
99 static size_t	dump_iosize;	/* device's best transfer size, if any */
100 static uint64_t	dumpbuf_thresh = 1ULL << 30;	/* 1GB */
101 static ulong_t	dumpbuf_mult = 8;
102 
103 /*
104  * The dump i/o buffer must be at least one page, at most xfer_size bytes, and
105  * should scale with physmem in between.  The transfer size passed in will
106  * either represent a global default (maxphys) or the best size for the device.
107  * Once the physical memory size exceeds dumpbuf_thresh (1GB by default), we
108  * increase the percentage of physical memory that dumpbuf can consume by a
109  * factor of dumpbuf_mult (8 by default) to improve large memory performance.
110  * The size of the dumpbuf i/o buffer is limited by dumpbuf_limit (8MB by
111  * default) because the dump performance saturates beyond a certain size.
112  */
113 static size_t
114 dumpbuf_iosize(size_t xfer_size)
115 {
116 	pgcnt_t scale = physmem;
117 	size_t iosize;
118 
119 	if (scale >= dumpbuf_thresh / PAGESIZE) {
120 		scale *= dumpbuf_mult; /* increase scaling factor */
121 		iosize = MIN(xfer_size, scale) & PAGEMASK;
122 		if (dumpbuf_limit && iosize > dumpbuf_limit)
123 			iosize = MAX(PAGESIZE, dumpbuf_limit & PAGEMASK);
124 	} else
125 		iosize = MAX(PAGESIZE, MIN(xfer_size, scale) & PAGEMASK);
126 
127 	return (iosize);
128 }
129 
130 static void
131 dumpbuf_resize(void)
132 {
133 	char *old_buf = dumpbuf_start;
134 	size_t old_size = dumpbuf_size;
135 	char *new_buf;
136 	size_t new_size;
137 
138 	ASSERT(MUTEX_HELD(&dump_lock));
139 
140 	if ((new_size = dumpbuf_iosize(MAX(dump_iosize, maxphys))) <= old_size)
141 		return; /* no need to reallocate buffer */
142 
143 	new_buf = kmem_alloc(new_size, KM_SLEEP);
144 	dumpbuf_size = new_size;
145 	dumpbuf_start = new_buf;
146 	dumpbuf_end = new_buf + new_size;
147 	kmem_free(old_buf, old_size);
148 }
149 
150 static void
151 dumphdr_init(void)
152 {
153 	pgcnt_t npages = 0;
154 
155 	ASSERT(MUTEX_HELD(&dump_lock));
156 
157 	if (dumphdr == NULL) {
158 		dumphdr = kmem_zalloc(sizeof (dumphdr_t), KM_SLEEP);
159 		dumphdr->dump_magic = DUMP_MAGIC;
160 		dumphdr->dump_version = DUMP_VERSION;
161 		dumphdr->dump_wordsize = DUMP_WORDSIZE;
162 		dumphdr->dump_pageshift = PAGESHIFT;
163 		dumphdr->dump_pagesize = PAGESIZE;
164 		dumphdr->dump_utsname = utsname;
165 		(void) strcpy(dumphdr->dump_platform, platform);
166 		dump_cmap = vmem_alloc(heap_arena, PAGESIZE, VM_SLEEP);
167 		dumpbuf_size = dumpbuf_iosize(maxphys);
168 		dumpbuf_start = kmem_alloc(dumpbuf_size, KM_SLEEP);
169 		dumpbuf_end = dumpbuf_start + dumpbuf_size;
170 		dump_cbuf = kmem_alloc(PAGESIZE, KM_SLEEP); /* compress buf */
171 		dump_uebuf = kmem_alloc(PAGESIZE, KM_SLEEP); /* UE buf */
172 		dump_pids = kmem_alloc(v.v_proc * sizeof (pid_t), KM_SLEEP);
173 	}
174 
175 	npages = num_phys_pages();
176 
177 	if (dump_bitmapsize != npages) {
178 		void *map = kmem_alloc(BT_SIZEOFMAP(npages), KM_SLEEP);
179 		kmem_free(dump_bitmap, BT_SIZEOFMAP(dump_bitmapsize));
180 		dump_bitmap = map;
181 		dump_bitmapsize = npages;
182 	}
183 }
184 
185 /*
186  * Establish a new dump device.
187  */
188 int
189 dumpinit(vnode_t *vp, char *name, int justchecking)
190 {
191 	vnode_t *cvp;
192 	vattr_t vattr;
193 	vnode_t *cdev_vp;
194 	int error = 0;
195 
196 	ASSERT(MUTEX_HELD(&dump_lock));
197 
198 	dumphdr_init();
199 
200 	cvp = common_specvp(vp);
201 	if (cvp == dumpvp)
202 		return (0);
203 
204 	/*
205 	 * Determine whether this is a plausible dump device.  We want either:
206 	 * (1) a real device that's not mounted and has a cb_dump routine, or
207 	 * (2) a swapfile on some filesystem that has a vop_dump routine.
208 	 */
209 	if ((error = VOP_OPEN(&cvp, FREAD | FWRITE, kcred, NULL)) != 0)
210 		return (error);
211 
212 	vattr.va_mask = AT_SIZE | AT_TYPE | AT_RDEV;
213 	if ((error = VOP_GETATTR(cvp, &vattr, 0, kcred, NULL)) == 0) {
214 		if (vattr.va_type == VBLK || vattr.va_type == VCHR) {
215 			if (devopsp[getmajor(vattr.va_rdev)]->
216 			    devo_cb_ops->cb_dump == nodev)
217 				error = ENOTSUP;
218 			else if (vfs_devismounted(vattr.va_rdev))
219 				error = EBUSY;
220 		} else {
221 			if (vn_matchopval(cvp, VOPNAME_DUMP, fs_nosys) ||
222 			    !IS_SWAPVP(cvp))
223 				error = ENOTSUP;
224 		}
225 	}
226 
227 	if (error == 0 && vattr.va_size < 2 * DUMP_LOGSIZE + DUMP_ERPTSIZE)
228 		error = ENOSPC;
229 
230 	if (error || justchecking) {
231 		(void) VOP_CLOSE(cvp, FREAD | FWRITE, 1, (offset_t)0,
232 		    kcred, NULL);
233 		return (error);
234 	}
235 
236 	VN_HOLD(cvp);
237 
238 	if (dumpvp != NULL)
239 		dumpfini();	/* unconfigure the old dump device */
240 
241 	dumpvp = cvp;
242 	dumpvp_size = vattr.va_size & -DUMP_OFFSET;
243 	dumppath = kmem_alloc(strlen(name) + 1, KM_SLEEP);
244 	(void) strcpy(dumppath, name);
245 	dump_iosize = 0;
246 
247 	/*
248 	 * If the dump device is a block device, attempt to open up the
249 	 * corresponding character device and determine its maximum transfer
250 	 * size.  We use this information to potentially resize dumpbuf to a
251 	 * larger and more optimal size for performing i/o to the dump device.
252 	 */
253 	if (cvp->v_type == VBLK &&
254 	    (cdev_vp = makespecvp(VTOS(cvp)->s_dev, VCHR)) != NULL) {
255 		if (VOP_OPEN(&cdev_vp, FREAD | FWRITE, kcred, NULL) == 0) {
256 			size_t blk_size;
257 			struct dk_cinfo dki;
258 			struct vtoc vtoc;
259 
260 			if (VOP_IOCTL(cdev_vp, DKIOCGVTOC, (intptr_t)&vtoc,
261 			    FKIOCTL, kcred, NULL, NULL) == 0 &&
262 			    vtoc.v_sectorsz != 0)
263 				blk_size = vtoc.v_sectorsz;
264 			else
265 				blk_size = DEV_BSIZE;
266 
267 			if (VOP_IOCTL(cdev_vp, DKIOCINFO, (intptr_t)&dki,
268 			    FKIOCTL, kcred, NULL, NULL) == 0) {
269 				dump_iosize = dki.dki_maxtransfer * blk_size;
270 				dumpbuf_resize();
271 			}
272 
273 			(void) VOP_CLOSE(cdev_vp, FREAD | FWRITE, 1, 0,
274 			    kcred, NULL);
275 		}
276 
277 		VN_RELE(cdev_vp);
278 	}
279 
280 	cmn_err(CE_CONT, "?dump on %s size %llu MB\n", name, dumpvp_size >> 20);
281 
282 	return (0);
283 }
284 
285 void
286 dumpfini(void)
287 {
288 	ASSERT(MUTEX_HELD(&dump_lock));
289 
290 	kmem_free(dumppath, strlen(dumppath) + 1);
291 
292 	(void) VOP_CLOSE(dumpvp, FREAD | FWRITE, 1, (offset_t)0, kcred, NULL);
293 
294 	VN_RELE(dumpvp);
295 
296 	dumpvp = NULL;
297 	dumpvp_size = 0;
298 	dumppath = NULL;
299 }
300 
301 static pfn_t
302 dump_bitnum_to_pfn(pgcnt_t bitnum)
303 {
304 	struct memlist *mp;
305 
306 	for (mp = phys_install; mp != NULL; mp = mp->next) {
307 		if (bitnum < (mp->size >> PAGESHIFT))
308 			return ((mp->address >> PAGESHIFT) + bitnum);
309 		bitnum -= mp->size >> PAGESHIFT;
310 	}
311 	return (PFN_INVALID);
312 }
313 
314 static pgcnt_t
315 dump_pfn_to_bitnum(pfn_t pfn)
316 {
317 	struct memlist *mp;
318 	pgcnt_t bitnum = 0;
319 
320 	for (mp = phys_install; mp != NULL; mp = mp->next) {
321 		if (pfn >= (mp->address >> PAGESHIFT) &&
322 		    pfn < ((mp->address + mp->size) >> PAGESHIFT))
323 			return (bitnum + pfn - (mp->address >> PAGESHIFT));
324 		bitnum += mp->size >> PAGESHIFT;
325 	}
326 	return ((pgcnt_t)-1);
327 }
328 
329 static offset_t
330 dumpvp_flush(void)
331 {
332 	size_t size = P2ROUNDUP(dumpbuf_cur - dumpbuf_start, PAGESIZE);
333 	int err;
334 
335 	if (dumpvp_off + size > dumpvp_limit) {
336 		dump_ioerr = ENOSPC;
337 	} else if (size != 0) {
338 		if (panicstr)
339 			err = VOP_DUMP(dumpvp, dumpbuf_start,
340 			    lbtodb(dumpvp_off), btod(size), NULL);
341 		else
342 			err = vn_rdwr(UIO_WRITE, dumpvp, dumpbuf_start, size,
343 			    dumpvp_off, UIO_SYSSPACE, 0, dumpvp_limit,
344 			    kcred, 0);
345 		if (err && dump_ioerr == 0)
346 			dump_ioerr = err;
347 	}
348 	dumpvp_off += size;
349 	dumpbuf_cur = dumpbuf_start;
350 	dump_timeleft = dump_timeout;
351 	return (dumpvp_off);
352 }
353 
354 void
355 dumpvp_write(const void *va, size_t size)
356 {
357 	while (size != 0) {
358 		size_t len = MIN(size, dumpbuf_end - dumpbuf_cur);
359 		if (len == 0) {
360 			(void) dumpvp_flush();
361 		} else {
362 			bcopy(va, dumpbuf_cur, len);
363 			va = (char *)va + len;
364 			dumpbuf_cur += len;
365 			size -= len;
366 		}
367 	}
368 }
369 
370 /*ARGSUSED*/
371 static void
372 dumpvp_ksyms_write(const void *src, void *dst, size_t size)
373 {
374 	dumpvp_write(src, size);
375 }
376 
377 /*
378  * Mark 'pfn' in the bitmap and dump its translation table entry.
379  */
380 void
381 dump_addpage(struct as *as, void *va, pfn_t pfn)
382 {
383 	mem_vtop_t mem_vtop;
384 	pgcnt_t bitnum;
385 
386 	if ((bitnum = dump_pfn_to_bitnum(pfn)) != (pgcnt_t)-1) {
387 		if (!BT_TEST(dump_bitmap, bitnum)) {
388 			dumphdr->dump_npages++;
389 			BT_SET(dump_bitmap, bitnum);
390 		}
391 		dumphdr->dump_nvtop++;
392 		mem_vtop.m_as = as;
393 		mem_vtop.m_va = va;
394 		mem_vtop.m_pfn = pfn;
395 		dumpvp_write(&mem_vtop, sizeof (mem_vtop_t));
396 	}
397 	dump_timeleft = dump_timeout;
398 }
399 
400 /*
401  * Mark 'pfn' in the bitmap
402  */
403 void
404 dump_page(pfn_t pfn)
405 {
406 	pgcnt_t bitnum;
407 
408 	if ((bitnum = dump_pfn_to_bitnum(pfn)) != (pgcnt_t)-1) {
409 		if (!BT_TEST(dump_bitmap, bitnum)) {
410 			dumphdr->dump_npages++;
411 			BT_SET(dump_bitmap, bitnum);
412 		}
413 	}
414 	dump_timeleft = dump_timeout;
415 }
416 
417 /*
418  * Dump the <as, va, pfn> information for a given address space.
419  * SEGOP_DUMP() will call dump_addpage() for each page in the segment.
420  */
421 static void
422 dump_as(struct as *as)
423 {
424 	struct seg *seg;
425 
426 	AS_LOCK_ENTER(as, &as->a_lock, RW_READER);
427 	for (seg = AS_SEGFIRST(as); seg; seg = AS_SEGNEXT(as, seg)) {
428 		if (seg->s_as != as)
429 			break;
430 		if (seg->s_ops == NULL)
431 			continue;
432 		SEGOP_DUMP(seg);
433 	}
434 	AS_LOCK_EXIT(as, &as->a_lock);
435 
436 	if (seg != NULL)
437 		cmn_err(CE_WARN, "invalid segment %p in address space %p",
438 		    (void *)seg, (void *)as);
439 }
440 
441 static int
442 dump_process(pid_t pid)
443 {
444 	proc_t *p = sprlock(pid);
445 
446 	if (p == NULL)
447 		return (-1);
448 	if (p->p_as != &kas) {
449 		mutex_exit(&p->p_lock);
450 		dump_as(p->p_as);
451 		mutex_enter(&p->p_lock);
452 	}
453 
454 	sprunlock(p);
455 
456 	return (0);
457 }
458 
459 void
460 dump_ereports(void)
461 {
462 	u_offset_t dumpvp_start;
463 	erpt_dump_t ed;
464 
465 	if (dumpvp == NULL || dumphdr == NULL)
466 		return;
467 
468 	dumpbuf_cur = dumpbuf_start;
469 	dumpvp_limit = dumpvp_size - (DUMP_OFFSET + DUMP_LOGSIZE);
470 	dumpvp_start = dumpvp_limit - DUMP_ERPTSIZE;
471 	dumpvp_off = dumpvp_start;
472 
473 	fm_ereport_dump();
474 	if (panicstr)
475 		errorq_dump();
476 
477 	bzero(&ed, sizeof (ed)); /* indicate end of ereports */
478 	dumpvp_write(&ed, sizeof (ed));
479 	(void) dumpvp_flush();
480 
481 	if (!panicstr) {
482 		(void) VOP_PUTPAGE(dumpvp, dumpvp_start,
483 		    (size_t)(dumpvp_off - dumpvp_start),
484 		    B_INVAL | B_FORCE, kcred, NULL);
485 	}
486 }
487 
488 void
489 dump_messages(void)
490 {
491 	log_dump_t ld;
492 	mblk_t *mctl, *mdata;
493 	queue_t *q, *qlast;
494 	u_offset_t dumpvp_start;
495 
496 	if (dumpvp == NULL || dumphdr == NULL || log_consq == NULL)
497 		return;
498 
499 	dumpbuf_cur = dumpbuf_start;
500 	dumpvp_limit = dumpvp_size - DUMP_OFFSET;
501 	dumpvp_start = dumpvp_limit - DUMP_LOGSIZE;
502 	dumpvp_off = dumpvp_start;
503 
504 	qlast = NULL;
505 	do {
506 		for (q = log_consq; q->q_next != qlast; q = q->q_next)
507 			continue;
508 		for (mctl = q->q_first; mctl != NULL; mctl = mctl->b_next) {
509 			dump_timeleft = dump_timeout;
510 			mdata = mctl->b_cont;
511 			ld.ld_magic = LOG_MAGIC;
512 			ld.ld_msgsize = MBLKL(mctl->b_cont);
513 			ld.ld_csum = checksum32(mctl->b_rptr, MBLKL(mctl));
514 			ld.ld_msum = checksum32(mdata->b_rptr, MBLKL(mdata));
515 			dumpvp_write(&ld, sizeof (ld));
516 			dumpvp_write(mctl->b_rptr, MBLKL(mctl));
517 			dumpvp_write(mdata->b_rptr, MBLKL(mdata));
518 		}
519 	} while ((qlast = q) != log_consq);
520 
521 	ld.ld_magic = 0;		/* indicate end of messages */
522 	dumpvp_write(&ld, sizeof (ld));
523 	(void) dumpvp_flush();
524 	if (!panicstr) {
525 		(void) VOP_PUTPAGE(dumpvp, dumpvp_start,
526 		    (size_t)(dumpvp_off - dumpvp_start),
527 		    B_INVAL | B_FORCE, kcred, NULL);
528 	}
529 }
530 
531 static void
532 dump_pagecopy(void *src, void *dst)
533 {
534 	long *wsrc = (long *)src;
535 	long *wdst = (long *)dst;
536 	const ulong_t ncopies = PAGESIZE / sizeof (long);
537 	volatile int w = 0;
538 	volatile int ueoff = -1;
539 	on_trap_data_t otd;
540 
541 	if (on_trap(&otd, OT_DATA_EC)) {
542 		if (ueoff == -1) {
543 			uint64_t pa;
544 
545 			ueoff = w * sizeof (long);
546 			pa = ptob((uint64_t)hat_getpfnum(kas.a_hat, src))
547 			    + ueoff;
548 			cmn_err(CE_WARN, "memory error at PA 0x%08x.%08x",
549 			    (uint32_t)(pa >> 32), (uint32_t)pa);
550 		}
551 #ifdef _LP64
552 		wdst[w++] = 0xbadecc00badecc;
553 #else
554 		wdst[w++] = 0xbadecc;
555 #endif
556 	}
557 	while (w < ncopies) {
558 		wdst[w] = wsrc[w];
559 		w++;
560 	}
561 	no_trap();
562 }
563 
564 /*
565  * Dump the system.
566  */
567 void
568 dumpsys(void)
569 {
570 	pfn_t pfn;
571 	pgcnt_t bitnum;
572 	int npages = 0;
573 	int percent_done = 0;
574 	uint32_t csize;
575 	u_offset_t total_csize = 0;
576 	int compress_ratio;
577 	proc_t *p;
578 	pid_t npids, pidx;
579 	char *content;
580 
581 	if (dumpvp == NULL || dumphdr == NULL) {
582 		uprintf("skipping system dump - no dump device configured\n");
583 		return;
584 	}
585 	dumpbuf_cur = dumpbuf_start;
586 
587 	/*
588 	 * Calculate the starting block for dump.  If we're dumping on a
589 	 * swap device, start 1/5 of the way in; otherwise, start at the
590 	 * beginning.  And never use the first page -- it may be a disk label.
591 	 */
592 	if (dumpvp->v_flag & VISSWAP)
593 		dumphdr->dump_start = P2ROUNDUP(dumpvp_size / 5, DUMP_OFFSET);
594 	else
595 		dumphdr->dump_start = DUMP_OFFSET;
596 
597 	dumphdr->dump_flags = DF_VALID | DF_COMPLETE | DF_LIVE;
598 	dumphdr->dump_crashtime = gethrestime_sec();
599 	dumphdr->dump_npages = 0;
600 	dumphdr->dump_nvtop = 0;
601 	bzero(dump_bitmap, BT_SIZEOFMAP(dump_bitmapsize));
602 	dump_timeleft = dump_timeout;
603 
604 	if (panicstr) {
605 		dumphdr->dump_flags &= ~DF_LIVE;
606 		(void) VOP_DUMPCTL(dumpvp, DUMP_FREE, NULL, NULL);
607 		(void) VOP_DUMPCTL(dumpvp, DUMP_ALLOC, NULL, NULL);
608 		(void) vsnprintf(dumphdr->dump_panicstring, DUMP_PANICSIZE,
609 		    panicstr, panicargs);
610 	}
611 
612 	if (dump_conflags & DUMP_ALL)
613 		content = "all";
614 	else if (dump_conflags & DUMP_CURPROC)
615 		content = "kernel + curproc";
616 	else
617 		content = "kernel";
618 	uprintf("dumping to %s, offset %lld, content: %s\n", dumppath,
619 	    dumphdr->dump_start, content);
620 
621 	/*
622 	 * Leave room for the message and ereport save areas and terminal dump
623 	 * header.
624 	 */
625 	dumpvp_limit = dumpvp_size - DUMP_LOGSIZE - DUMP_OFFSET - DUMP_ERPTSIZE;
626 
627 	/*
628 	 * Write out the symbol table.  It's no longer compressed,
629 	 * so its 'size' and 'csize' are equal.
630 	 */
631 	dumpvp_off = dumphdr->dump_ksyms = dumphdr->dump_start + PAGESIZE;
632 	dumphdr->dump_ksyms_size = dumphdr->dump_ksyms_csize =
633 	    ksyms_snapshot(dumpvp_ksyms_write, NULL, LONG_MAX);
634 
635 	/*
636 	 * Write out the translation map.
637 	 */
638 	dumphdr->dump_map = dumpvp_flush();
639 	dump_as(&kas);
640 	dumphdr->dump_nvtop += dump_plat_addr();
641 
642 	/*
643 	 * call into hat, which may have unmapped pages that also need to
644 	 * be in the dump
645 	 */
646 	hat_dump();
647 
648 	if (dump_conflags & DUMP_ALL) {
649 		mutex_enter(&pidlock);
650 
651 		for (npids = 0, p = practive; p != NULL; p = p->p_next)
652 			dump_pids[npids++] = p->p_pid;
653 
654 		mutex_exit(&pidlock);
655 
656 		for (pidx = 0; pidx < npids; pidx++)
657 			(void) dump_process(dump_pids[pidx]);
658 
659 		for (bitnum = 0; bitnum < dump_bitmapsize; bitnum++) {
660 			dump_timeleft = dump_timeout;
661 			BT_SET(dump_bitmap, bitnum);
662 		}
663 		dumphdr->dump_npages = dump_bitmapsize;
664 		dumphdr->dump_flags |= DF_ALL;
665 
666 	} else if (dump_conflags & DUMP_CURPROC) {
667 		/*
668 		 * Determine which pid is to be dumped.  If we're panicking, we
669 		 * dump the process associated with panic_thread (if any).  If
670 		 * this is a live dump, we dump the process associated with
671 		 * curthread.
672 		 */
673 		npids = 0;
674 		if (panicstr) {
675 			if (panic_thread != NULL &&
676 			    panic_thread->t_procp != NULL &&
677 			    panic_thread->t_procp != &p0) {
678 				dump_pids[npids++] =
679 				    panic_thread->t_procp->p_pid;
680 			}
681 		} else {
682 			dump_pids[npids++] = curthread->t_procp->p_pid;
683 		}
684 
685 		if (npids && dump_process(dump_pids[0]) == 0)
686 			dumphdr->dump_flags |= DF_CURPROC;
687 		else
688 			dumphdr->dump_flags |= DF_KERNEL;
689 
690 	} else {
691 		dumphdr->dump_flags |= DF_KERNEL;
692 	}
693 
694 	dumphdr->dump_hashmask = (1 << highbit(dumphdr->dump_nvtop - 1)) - 1;
695 
696 	/*
697 	 * Write out the pfn table.
698 	 */
699 	dumphdr->dump_pfn = dumpvp_flush();
700 	for (bitnum = 0; bitnum < dump_bitmapsize; bitnum++) {
701 		dump_timeleft = dump_timeout;
702 		if (!BT_TEST(dump_bitmap, bitnum))
703 			continue;
704 		pfn = dump_bitnum_to_pfn(bitnum);
705 		ASSERT(pfn != PFN_INVALID);
706 		dumpvp_write(&pfn, sizeof (pfn_t));
707 	}
708 	dump_plat_pfn();
709 
710 	/*
711 	 * Write out all the pages.
712 	 */
713 	dumphdr->dump_data = dumpvp_flush();
714 	for (bitnum = 0; bitnum < dump_bitmapsize; bitnum++) {
715 		dump_timeleft = dump_timeout;
716 		if (!BT_TEST(dump_bitmap, bitnum))
717 			continue;
718 		pfn = dump_bitnum_to_pfn(bitnum);
719 		ASSERT(pfn != PFN_INVALID);
720 
721 		/*
722 		 * Map in page frame 'pfn', scan it for UE's while copying
723 		 * the data to dump_uebuf, unmap it, compress dump_uebuf into
724 		 * dump_cbuf, and write out dump_cbuf.  The UE check ensures
725 		 * that we don't lose the whole dump because of a latent UE.
726 		 */
727 		hat_devload(kas.a_hat, dump_cmap, PAGESIZE, pfn, PROT_READ,
728 		    HAT_LOAD_NOCONSIST);
729 		dump_pagecopy(dump_cmap, dump_uebuf);
730 		hat_unload(kas.a_hat, dump_cmap, PAGESIZE, HAT_UNLOAD);
731 		csize = (uint32_t)compress(dump_uebuf, dump_cbuf, PAGESIZE);
732 		dumpvp_write(&csize, sizeof (uint32_t));
733 		dumpvp_write(dump_cbuf, csize);
734 		if (dump_ioerr) {
735 			dumphdr->dump_flags &= ~DF_COMPLETE;
736 			dumphdr->dump_npages = npages;
737 			break;
738 		}
739 		total_csize += csize;
740 		if (++npages * 100LL / dumphdr->dump_npages > percent_done) {
741 			uprintf("^\r%3d%% done", ++percent_done);
742 			if (!panicstr)
743 				delay(1);	/* let the output be sent */
744 		}
745 	}
746 	dumphdr->dump_npages += dump_plat_data(dump_cbuf);
747 
748 	(void) dumpvp_flush();
749 
750 	/*
751 	 * Write out the initial and terminal dump headers.
752 	 */
753 	dumpvp_off = dumphdr->dump_start;
754 	dumpvp_write(dumphdr, sizeof (dumphdr_t));
755 	(void) dumpvp_flush();
756 
757 	dumpvp_limit = dumpvp_size;
758 	dumpvp_off = dumpvp_limit - DUMP_OFFSET;
759 	dumpvp_write(dumphdr, sizeof (dumphdr_t));
760 	(void) dumpvp_flush();
761 
762 	compress_ratio = (int)(100LL * npages / (btopr(total_csize + 1)));
763 
764 	uprintf("\r%3d%% done: %d pages dumped, compression ratio %d.%02d, ",
765 	    percent_done, npages, compress_ratio / 100, compress_ratio % 100);
766 
767 	if (dump_ioerr == 0) {
768 		uprintf("dump succeeded\n");
769 	} else {
770 		uprintf("dump failed: error %d\n", dump_ioerr);
771 		if (panicstr && dumpfaildebug)
772 			debug_enter("dump failed");
773 	}
774 
775 	/*
776 	 * Write out all undelivered messages.  This has to be the *last*
777 	 * thing we do because the dump process itself emits messages.
778 	 */
779 	if (panicstr) {
780 		dump_ereports();
781 		dump_messages();
782 	}
783 
784 	delay(2 * hz);	/* let people see the 'done' message */
785 	dump_timeleft = 0;
786 	dump_ioerr = 0;
787 }
788 
789 /*
790  * This function is called whenever the memory size, as represented
791  * by the phys_install list, changes.
792  */
793 void
794 dump_resize()
795 {
796 	mutex_enter(&dump_lock);
797 	dumphdr_init();
798 	dumpbuf_resize();
799 	mutex_exit(&dump_lock);
800 }
801