17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5ae115bc7Smrj * Common Development and Distribution License (the "License"). 6ae115bc7Smrj * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 21342440ecSPrasad Singamsetty 227c478bd9Sstevel@tonic-gate /* 23*65908c77Syu, larry liu - Sun Microsystems - Beijing China * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate #include <sys/types.h> 287c478bd9Sstevel@tonic-gate #include <sys/param.h> 297c478bd9Sstevel@tonic-gate #include <sys/systm.h> 307c478bd9Sstevel@tonic-gate #include <sys/vm.h> 317c478bd9Sstevel@tonic-gate #include <sys/proc.h> 327c478bd9Sstevel@tonic-gate #include <sys/file.h> 337c478bd9Sstevel@tonic-gate #include <sys/conf.h> 347c478bd9Sstevel@tonic-gate #include <sys/kmem.h> 357c478bd9Sstevel@tonic-gate #include <sys/mem.h> 367c478bd9Sstevel@tonic-gate #include <sys/mman.h> 377c478bd9Sstevel@tonic-gate #include <sys/vnode.h> 387c478bd9Sstevel@tonic-gate #include <sys/errno.h> 397c478bd9Sstevel@tonic-gate #include <sys/memlist.h> 407c478bd9Sstevel@tonic-gate #include <sys/dumphdr.h> 417c478bd9Sstevel@tonic-gate #include <sys/dumpadm.h> 427c478bd9Sstevel@tonic-gate #include <sys/ksyms.h> 437c478bd9Sstevel@tonic-gate #include <sys/compress.h> 447c478bd9Sstevel@tonic-gate #include <sys/stream.h> 457c478bd9Sstevel@tonic-gate #include <sys/strsun.h> 467c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h> 477c478bd9Sstevel@tonic-gate #include <sys/bitmap.h> 487c478bd9Sstevel@tonic-gate #include <sys/modctl.h> 497c478bd9Sstevel@tonic-gate #include <sys/utsname.h> 507c478bd9Sstevel@tonic-gate #include <sys/systeminfo.h> 517c478bd9Sstevel@tonic-gate #include <sys/vmem.h> 527c478bd9Sstevel@tonic-gate #include <sys/log.h> 537c478bd9Sstevel@tonic-gate #include <sys/var.h> 547c478bd9Sstevel@tonic-gate #include <sys/debug.h> 557c478bd9Sstevel@tonic-gate #include <sys/sunddi.h> 567c478bd9Sstevel@tonic-gate #include <fs/fs_subr.h> 577c478bd9Sstevel@tonic-gate #include <sys/fs/snode.h> 587c478bd9Sstevel@tonic-gate #include <sys/ontrap.h> 597c478bd9Sstevel@tonic-gate #include <sys/panic.h> 607c478bd9Sstevel@tonic-gate #include <sys/dkio.h> 617c478bd9Sstevel@tonic-gate #include <sys/vtoc.h> 627c478bd9Sstevel@tonic-gate #include <sys/errorq.h> 637c478bd9Sstevel@tonic-gate #include <sys/fm/util.h> 64e7cbe64fSgw25295 #include <sys/fs/zfs.h> 657c478bd9Sstevel@tonic-gate 667c478bd9Sstevel@tonic-gate #include <vm/hat.h> 677c478bd9Sstevel@tonic-gate #include <vm/as.h> 687c478bd9Sstevel@tonic-gate #include <vm/page.h> 697c478bd9Sstevel@tonic-gate #include <vm/seg.h> 707c478bd9Sstevel@tonic-gate #include <vm/seg_kmem.h> 717c478bd9Sstevel@tonic-gate 727c478bd9Sstevel@tonic-gate kmutex_t dump_lock; /* lock for dump configuration */ 737c478bd9Sstevel@tonic-gate dumphdr_t *dumphdr; /* dump header */ 747c478bd9Sstevel@tonic-gate int dump_conflags = DUMP_KERNEL; /* dump configuration flags */ 757c478bd9Sstevel@tonic-gate vnode_t *dumpvp; /* dump device vnode pointer */ 767c478bd9Sstevel@tonic-gate u_offset_t dumpvp_size; /* size of dump device, in bytes */ 777c478bd9Sstevel@tonic-gate static u_offset_t dumpvp_limit; /* maximum write offset */ 787c478bd9Sstevel@tonic-gate char *dumppath; /* pathname of dump device */ 797c478bd9Sstevel@tonic-gate int dump_timeout = 120; /* timeout for dumping page during panic */ 807c478bd9Sstevel@tonic-gate int dump_timeleft; /* portion of dump_timeout remaining */ 81843e1988Sjohnlev int dump_ioerr; /* dump i/o error */ 827c478bd9Sstevel@tonic-gate 837c478bd9Sstevel@tonic-gate #ifdef DEBUG 847c478bd9Sstevel@tonic-gate int dumpfaildebug = 1; /* enter debugger if dump fails */ 857c478bd9Sstevel@tonic-gate #else 867c478bd9Sstevel@tonic-gate int dumpfaildebug = 0; 877c478bd9Sstevel@tonic-gate #endif 887c478bd9Sstevel@tonic-gate 897c478bd9Sstevel@tonic-gate static ulong_t *dump_bitmap; /* bitmap for marking pages to dump */ 907c478bd9Sstevel@tonic-gate static pgcnt_t dump_bitmapsize; /* size of bitmap */ 917c478bd9Sstevel@tonic-gate static pid_t *dump_pids; /* list of process IDs at dump time */ 927c478bd9Sstevel@tonic-gate static offset_t dumpvp_off; /* current dump device offset */ 937c478bd9Sstevel@tonic-gate static char *dump_cmap; /* VA for dump compression mapping */ 947c478bd9Sstevel@tonic-gate static char *dumpbuf_cur, *dumpbuf_start, *dumpbuf_end; 957c478bd9Sstevel@tonic-gate static char *dump_cbuf; /* compression buffer */ 967c478bd9Sstevel@tonic-gate static char *dump_uebuf; /* memory error detection buffer */ 977c478bd9Sstevel@tonic-gate static size_t dumpbuf_size; /* size of dumpbuf in bytes */ 987c478bd9Sstevel@tonic-gate static size_t dumpbuf_limit = 1UL << 23; /* 8MB */ 997c478bd9Sstevel@tonic-gate static size_t dump_iosize; /* device's best transfer size, if any */ 1007c478bd9Sstevel@tonic-gate static uint64_t dumpbuf_thresh = 1ULL << 30; /* 1GB */ 1017c478bd9Sstevel@tonic-gate static ulong_t dumpbuf_mult = 8; 1027c478bd9Sstevel@tonic-gate 1037c478bd9Sstevel@tonic-gate /* 1047c478bd9Sstevel@tonic-gate * The dump i/o buffer must be at least one page, at most xfer_size bytes, and 1057c478bd9Sstevel@tonic-gate * should scale with physmem in between. The transfer size passed in will 1067c478bd9Sstevel@tonic-gate * either represent a global default (maxphys) or the best size for the device. 1077c478bd9Sstevel@tonic-gate * Once the physical memory size exceeds dumpbuf_thresh (1GB by default), we 1087c478bd9Sstevel@tonic-gate * increase the percentage of physical memory that dumpbuf can consume by a 1097c478bd9Sstevel@tonic-gate * factor of dumpbuf_mult (8 by default) to improve large memory performance. 1107c478bd9Sstevel@tonic-gate * The size of the dumpbuf i/o buffer is limited by dumpbuf_limit (8MB by 1117c478bd9Sstevel@tonic-gate * default) because the dump performance saturates beyond a certain size. 1127c478bd9Sstevel@tonic-gate */ 1137c478bd9Sstevel@tonic-gate static size_t 1147c478bd9Sstevel@tonic-gate dumpbuf_iosize(size_t xfer_size) 1157c478bd9Sstevel@tonic-gate { 1167c478bd9Sstevel@tonic-gate pgcnt_t scale = physmem; 1177c478bd9Sstevel@tonic-gate size_t iosize; 1187c478bd9Sstevel@tonic-gate 1197c478bd9Sstevel@tonic-gate if (scale >= dumpbuf_thresh / PAGESIZE) { 1207c478bd9Sstevel@tonic-gate scale *= dumpbuf_mult; /* increase scaling factor */ 1217c478bd9Sstevel@tonic-gate iosize = MIN(xfer_size, scale) & PAGEMASK; 1227c478bd9Sstevel@tonic-gate if (dumpbuf_limit && iosize > dumpbuf_limit) 1237c478bd9Sstevel@tonic-gate iosize = MAX(PAGESIZE, dumpbuf_limit & PAGEMASK); 1247c478bd9Sstevel@tonic-gate } else 1257c478bd9Sstevel@tonic-gate iosize = MAX(PAGESIZE, MIN(xfer_size, scale) & PAGEMASK); 1267c478bd9Sstevel@tonic-gate 1277c478bd9Sstevel@tonic-gate return (iosize); 1287c478bd9Sstevel@tonic-gate } 1297c478bd9Sstevel@tonic-gate 1307c478bd9Sstevel@tonic-gate static void 1317c478bd9Sstevel@tonic-gate dumpbuf_resize(void) 1327c478bd9Sstevel@tonic-gate { 1337c478bd9Sstevel@tonic-gate char *old_buf = dumpbuf_start; 1347c478bd9Sstevel@tonic-gate size_t old_size = dumpbuf_size; 1357c478bd9Sstevel@tonic-gate char *new_buf; 1367c478bd9Sstevel@tonic-gate size_t new_size; 1377c478bd9Sstevel@tonic-gate 1387c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&dump_lock)); 1397c478bd9Sstevel@tonic-gate 1407c478bd9Sstevel@tonic-gate if ((new_size = dumpbuf_iosize(MAX(dump_iosize, maxphys))) <= old_size) 1417c478bd9Sstevel@tonic-gate return; /* no need to reallocate buffer */ 1427c478bd9Sstevel@tonic-gate 1437c478bd9Sstevel@tonic-gate new_buf = kmem_alloc(new_size, KM_SLEEP); 1447c478bd9Sstevel@tonic-gate dumpbuf_size = new_size; 1457c478bd9Sstevel@tonic-gate dumpbuf_start = new_buf; 1467c478bd9Sstevel@tonic-gate dumpbuf_end = new_buf + new_size; 1477c478bd9Sstevel@tonic-gate kmem_free(old_buf, old_size); 1487c478bd9Sstevel@tonic-gate } 1497c478bd9Sstevel@tonic-gate 1507c478bd9Sstevel@tonic-gate static void 1517c478bd9Sstevel@tonic-gate dumphdr_init(void) 1527c478bd9Sstevel@tonic-gate { 1537c478bd9Sstevel@tonic-gate pgcnt_t npages = 0; 1547c478bd9Sstevel@tonic-gate 1557c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&dump_lock)); 1567c478bd9Sstevel@tonic-gate 1577c478bd9Sstevel@tonic-gate if (dumphdr == NULL) { 1587c478bd9Sstevel@tonic-gate dumphdr = kmem_zalloc(sizeof (dumphdr_t), KM_SLEEP); 1597c478bd9Sstevel@tonic-gate dumphdr->dump_magic = DUMP_MAGIC; 1607c478bd9Sstevel@tonic-gate dumphdr->dump_version = DUMP_VERSION; 1617c478bd9Sstevel@tonic-gate dumphdr->dump_wordsize = DUMP_WORDSIZE; 1627c478bd9Sstevel@tonic-gate dumphdr->dump_pageshift = PAGESHIFT; 1637c478bd9Sstevel@tonic-gate dumphdr->dump_pagesize = PAGESIZE; 1647c478bd9Sstevel@tonic-gate dumphdr->dump_utsname = utsname; 1657c478bd9Sstevel@tonic-gate (void) strcpy(dumphdr->dump_platform, platform); 1667c478bd9Sstevel@tonic-gate dump_cmap = vmem_alloc(heap_arena, PAGESIZE, VM_SLEEP); 1677c478bd9Sstevel@tonic-gate dumpbuf_size = dumpbuf_iosize(maxphys); 1687c478bd9Sstevel@tonic-gate dumpbuf_start = kmem_alloc(dumpbuf_size, KM_SLEEP); 1697c478bd9Sstevel@tonic-gate dumpbuf_end = dumpbuf_start + dumpbuf_size; 1707c478bd9Sstevel@tonic-gate dump_cbuf = kmem_alloc(PAGESIZE, KM_SLEEP); /* compress buf */ 1717c478bd9Sstevel@tonic-gate dump_uebuf = kmem_alloc(PAGESIZE, KM_SLEEP); /* UE buf */ 1727c478bd9Sstevel@tonic-gate dump_pids = kmem_alloc(v.v_proc * sizeof (pid_t), KM_SLEEP); 1737c478bd9Sstevel@tonic-gate } 1747c478bd9Sstevel@tonic-gate 175843e1988Sjohnlev npages = num_phys_pages(); 1767c478bd9Sstevel@tonic-gate 1777c478bd9Sstevel@tonic-gate if (dump_bitmapsize != npages) { 1787c478bd9Sstevel@tonic-gate void *map = kmem_alloc(BT_SIZEOFMAP(npages), KM_SLEEP); 1797c478bd9Sstevel@tonic-gate kmem_free(dump_bitmap, BT_SIZEOFMAP(dump_bitmapsize)); 1807c478bd9Sstevel@tonic-gate dump_bitmap = map; 1817c478bd9Sstevel@tonic-gate dump_bitmapsize = npages; 1827c478bd9Sstevel@tonic-gate } 1837c478bd9Sstevel@tonic-gate } 1847c478bd9Sstevel@tonic-gate 1857c478bd9Sstevel@tonic-gate /* 1867c478bd9Sstevel@tonic-gate * Establish a new dump device. 1877c478bd9Sstevel@tonic-gate */ 1887c478bd9Sstevel@tonic-gate int 1897c478bd9Sstevel@tonic-gate dumpinit(vnode_t *vp, char *name, int justchecking) 1907c478bd9Sstevel@tonic-gate { 1917c478bd9Sstevel@tonic-gate vnode_t *cvp; 1927c478bd9Sstevel@tonic-gate vattr_t vattr; 1937c478bd9Sstevel@tonic-gate vnode_t *cdev_vp; 1947c478bd9Sstevel@tonic-gate int error = 0; 1957c478bd9Sstevel@tonic-gate 1967c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&dump_lock)); 1977c478bd9Sstevel@tonic-gate 1987c478bd9Sstevel@tonic-gate dumphdr_init(); 1997c478bd9Sstevel@tonic-gate 2007c478bd9Sstevel@tonic-gate cvp = common_specvp(vp); 2017c478bd9Sstevel@tonic-gate if (cvp == dumpvp) 2027c478bd9Sstevel@tonic-gate return (0); 2037c478bd9Sstevel@tonic-gate 2047c478bd9Sstevel@tonic-gate /* 2057c478bd9Sstevel@tonic-gate * Determine whether this is a plausible dump device. We want either: 2067c478bd9Sstevel@tonic-gate * (1) a real device that's not mounted and has a cb_dump routine, or 2077c478bd9Sstevel@tonic-gate * (2) a swapfile on some filesystem that has a vop_dump routine. 2087c478bd9Sstevel@tonic-gate */ 209da6c28aaSamw if ((error = VOP_OPEN(&cvp, FREAD | FWRITE, kcred, NULL)) != 0) 2107c478bd9Sstevel@tonic-gate return (error); 2117c478bd9Sstevel@tonic-gate 2127c478bd9Sstevel@tonic-gate vattr.va_mask = AT_SIZE | AT_TYPE | AT_RDEV; 213da6c28aaSamw if ((error = VOP_GETATTR(cvp, &vattr, 0, kcred, NULL)) == 0) { 2147c478bd9Sstevel@tonic-gate if (vattr.va_type == VBLK || vattr.va_type == VCHR) { 2157c478bd9Sstevel@tonic-gate if (devopsp[getmajor(vattr.va_rdev)]-> 2167c478bd9Sstevel@tonic-gate devo_cb_ops->cb_dump == nodev) 2177c478bd9Sstevel@tonic-gate error = ENOTSUP; 2187c478bd9Sstevel@tonic-gate else if (vfs_devismounted(vattr.va_rdev)) 2197c478bd9Sstevel@tonic-gate error = EBUSY; 2207c478bd9Sstevel@tonic-gate } else { 2217c478bd9Sstevel@tonic-gate if (vn_matchopval(cvp, VOPNAME_DUMP, fs_nosys) || 2227c478bd9Sstevel@tonic-gate !IS_SWAPVP(cvp)) 2237c478bd9Sstevel@tonic-gate error = ENOTSUP; 2247c478bd9Sstevel@tonic-gate } 2257c478bd9Sstevel@tonic-gate } 2267c478bd9Sstevel@tonic-gate 2277c478bd9Sstevel@tonic-gate if (error == 0 && vattr.va_size < 2 * DUMP_LOGSIZE + DUMP_ERPTSIZE) 2287c478bd9Sstevel@tonic-gate error = ENOSPC; 2297c478bd9Sstevel@tonic-gate 2307c478bd9Sstevel@tonic-gate if (error || justchecking) { 231da6c28aaSamw (void) VOP_CLOSE(cvp, FREAD | FWRITE, 1, (offset_t)0, 232da6c28aaSamw kcred, NULL); 2337c478bd9Sstevel@tonic-gate return (error); 2347c478bd9Sstevel@tonic-gate } 2357c478bd9Sstevel@tonic-gate 2367c478bd9Sstevel@tonic-gate VN_HOLD(cvp); 2377c478bd9Sstevel@tonic-gate 2387c478bd9Sstevel@tonic-gate if (dumpvp != NULL) 2397c478bd9Sstevel@tonic-gate dumpfini(); /* unconfigure the old dump device */ 2407c478bd9Sstevel@tonic-gate 2417c478bd9Sstevel@tonic-gate dumpvp = cvp; 2427c478bd9Sstevel@tonic-gate dumpvp_size = vattr.va_size & -DUMP_OFFSET; 2437c478bd9Sstevel@tonic-gate dumppath = kmem_alloc(strlen(name) + 1, KM_SLEEP); 2447c478bd9Sstevel@tonic-gate (void) strcpy(dumppath, name); 2457c478bd9Sstevel@tonic-gate dump_iosize = 0; 2467c478bd9Sstevel@tonic-gate 2477c478bd9Sstevel@tonic-gate /* 2487c478bd9Sstevel@tonic-gate * If the dump device is a block device, attempt to open up the 2497c478bd9Sstevel@tonic-gate * corresponding character device and determine its maximum transfer 2507c478bd9Sstevel@tonic-gate * size. We use this information to potentially resize dumpbuf to a 2517c478bd9Sstevel@tonic-gate * larger and more optimal size for performing i/o to the dump device. 2527c478bd9Sstevel@tonic-gate */ 2537c478bd9Sstevel@tonic-gate if (cvp->v_type == VBLK && 2547c478bd9Sstevel@tonic-gate (cdev_vp = makespecvp(VTOS(cvp)->s_dev, VCHR)) != NULL) { 255da6c28aaSamw if (VOP_OPEN(&cdev_vp, FREAD | FWRITE, kcred, NULL) == 0) { 2567c478bd9Sstevel@tonic-gate size_t blk_size; 2577c478bd9Sstevel@tonic-gate struct dk_cinfo dki; 258*65908c77Syu, larry liu - Sun Microsystems - Beijing China struct dk_minfo minf; 2597c478bd9Sstevel@tonic-gate 260*65908c77Syu, larry liu - Sun Microsystems - Beijing China if (VOP_IOCTL(cdev_vp, DKIOCGMEDIAINFO, 261*65908c77Syu, larry liu - Sun Microsystems - Beijing China (intptr_t)&minf, FKIOCTL, kcred, NULL, NULL) 262*65908c77Syu, larry liu - Sun Microsystems - Beijing China == 0 && minf.dki_lbsize != 0) 263*65908c77Syu, larry liu - Sun Microsystems - Beijing China blk_size = minf.dki_lbsize; 2647c478bd9Sstevel@tonic-gate else 2657c478bd9Sstevel@tonic-gate blk_size = DEV_BSIZE; 2667c478bd9Sstevel@tonic-gate 2677c478bd9Sstevel@tonic-gate if (VOP_IOCTL(cdev_vp, DKIOCINFO, (intptr_t)&dki, 268da6c28aaSamw FKIOCTL, kcred, NULL, NULL) == 0) { 2697c478bd9Sstevel@tonic-gate dump_iosize = dki.dki_maxtransfer * blk_size; 2707c478bd9Sstevel@tonic-gate dumpbuf_resize(); 2717c478bd9Sstevel@tonic-gate } 272e7cbe64fSgw25295 /* 273e7cbe64fSgw25295 * If we are working with a zvol then call into 274e7cbe64fSgw25295 * it to dumpify itself. 275e7cbe64fSgw25295 */ 276e7cbe64fSgw25295 if (strcmp(dki.dki_dname, ZVOL_DRIVER) == 0) { 277e7cbe64fSgw25295 if ((error = VOP_IOCTL(cdev_vp, 278e7cbe64fSgw25295 DKIOCDUMPINIT, NULL, FKIOCTL, kcred, 279e7cbe64fSgw25295 NULL, NULL)) != 0) { 280e7cbe64fSgw25295 dumpfini(); 281e7cbe64fSgw25295 } 282e7cbe64fSgw25295 } 2837c478bd9Sstevel@tonic-gate 284da6c28aaSamw (void) VOP_CLOSE(cdev_vp, FREAD | FWRITE, 1, 0, 285da6c28aaSamw kcred, NULL); 2867c478bd9Sstevel@tonic-gate } 2877c478bd9Sstevel@tonic-gate 2887c478bd9Sstevel@tonic-gate VN_RELE(cdev_vp); 2897c478bd9Sstevel@tonic-gate } 2907c478bd9Sstevel@tonic-gate 2917c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "?dump on %s size %llu MB\n", name, dumpvp_size >> 20); 2927c478bd9Sstevel@tonic-gate 293e7cbe64fSgw25295 return (error); 2947c478bd9Sstevel@tonic-gate } 2957c478bd9Sstevel@tonic-gate 2967c478bd9Sstevel@tonic-gate void 2977c478bd9Sstevel@tonic-gate dumpfini(void) 2987c478bd9Sstevel@tonic-gate { 299e7cbe64fSgw25295 vattr_t vattr; 300e7cbe64fSgw25295 boolean_t is_zfs = B_FALSE; 301e7cbe64fSgw25295 vnode_t *cdev_vp; 3027c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&dump_lock)); 3037c478bd9Sstevel@tonic-gate 3047c478bd9Sstevel@tonic-gate kmem_free(dumppath, strlen(dumppath) + 1); 3057c478bd9Sstevel@tonic-gate 306e7cbe64fSgw25295 /* 307e7cbe64fSgw25295 * Determine if we are using zvols for our dump device 308e7cbe64fSgw25295 */ 309e7cbe64fSgw25295 vattr.va_mask = AT_RDEV; 310e7cbe64fSgw25295 if (VOP_GETATTR(dumpvp, &vattr, 0, kcred, NULL) == 0) { 311e7cbe64fSgw25295 is_zfs = (getmajor(vattr.va_rdev) == 312e7cbe64fSgw25295 ddi_name_to_major(ZFS_DRIVER)) ? B_TRUE : B_FALSE; 313e7cbe64fSgw25295 } 314e7cbe64fSgw25295 315e7cbe64fSgw25295 /* 316e7cbe64fSgw25295 * If we have a zvol dump device then we call into zfs so 317e7cbe64fSgw25295 * that it may have a chance to cleanup. 318e7cbe64fSgw25295 */ 319e7cbe64fSgw25295 if (is_zfs && 320e7cbe64fSgw25295 (cdev_vp = makespecvp(VTOS(dumpvp)->s_dev, VCHR)) != NULL) { 321e7cbe64fSgw25295 if (VOP_OPEN(&cdev_vp, FREAD | FWRITE, kcred, NULL) == 0) { 322e7cbe64fSgw25295 (void) VOP_IOCTL(cdev_vp, DKIOCDUMPFINI, NULL, FKIOCTL, 323e7cbe64fSgw25295 kcred, NULL, NULL); 324e7cbe64fSgw25295 (void) VOP_CLOSE(cdev_vp, FREAD | FWRITE, 1, 0, 325e7cbe64fSgw25295 kcred, NULL); 326e7cbe64fSgw25295 } 327e7cbe64fSgw25295 VN_RELE(cdev_vp); 328e7cbe64fSgw25295 } 329e7cbe64fSgw25295 330da6c28aaSamw (void) VOP_CLOSE(dumpvp, FREAD | FWRITE, 1, (offset_t)0, kcred, NULL); 3317c478bd9Sstevel@tonic-gate 3327c478bd9Sstevel@tonic-gate VN_RELE(dumpvp); 3337c478bd9Sstevel@tonic-gate 3347c478bd9Sstevel@tonic-gate dumpvp = NULL; 3357c478bd9Sstevel@tonic-gate dumpvp_size = 0; 3367c478bd9Sstevel@tonic-gate dumppath = NULL; 3377c478bd9Sstevel@tonic-gate } 3387c478bd9Sstevel@tonic-gate 3397c478bd9Sstevel@tonic-gate static pfn_t 3407c478bd9Sstevel@tonic-gate dump_bitnum_to_pfn(pgcnt_t bitnum) 3417c478bd9Sstevel@tonic-gate { 3427c478bd9Sstevel@tonic-gate struct memlist *mp; 3437c478bd9Sstevel@tonic-gate 3447c478bd9Sstevel@tonic-gate for (mp = phys_install; mp != NULL; mp = mp->next) { 3457c478bd9Sstevel@tonic-gate if (bitnum < (mp->size >> PAGESHIFT)) 3467c478bd9Sstevel@tonic-gate return ((mp->address >> PAGESHIFT) + bitnum); 3477c478bd9Sstevel@tonic-gate bitnum -= mp->size >> PAGESHIFT; 3487c478bd9Sstevel@tonic-gate } 3497c478bd9Sstevel@tonic-gate return (PFN_INVALID); 3507c478bd9Sstevel@tonic-gate } 3517c478bd9Sstevel@tonic-gate 3527c478bd9Sstevel@tonic-gate static pgcnt_t 3537c478bd9Sstevel@tonic-gate dump_pfn_to_bitnum(pfn_t pfn) 3547c478bd9Sstevel@tonic-gate { 3557c478bd9Sstevel@tonic-gate struct memlist *mp; 3567c478bd9Sstevel@tonic-gate pgcnt_t bitnum = 0; 3577c478bd9Sstevel@tonic-gate 3587c478bd9Sstevel@tonic-gate for (mp = phys_install; mp != NULL; mp = mp->next) { 3597c478bd9Sstevel@tonic-gate if (pfn >= (mp->address >> PAGESHIFT) && 3607c478bd9Sstevel@tonic-gate pfn < ((mp->address + mp->size) >> PAGESHIFT)) 3617c478bd9Sstevel@tonic-gate return (bitnum + pfn - (mp->address >> PAGESHIFT)); 3627c478bd9Sstevel@tonic-gate bitnum += mp->size >> PAGESHIFT; 3637c478bd9Sstevel@tonic-gate } 3647c478bd9Sstevel@tonic-gate return ((pgcnt_t)-1); 3657c478bd9Sstevel@tonic-gate } 3667c478bd9Sstevel@tonic-gate 3677c478bd9Sstevel@tonic-gate static offset_t 3687c478bd9Sstevel@tonic-gate dumpvp_flush(void) 3697c478bd9Sstevel@tonic-gate { 3707c478bd9Sstevel@tonic-gate size_t size = P2ROUNDUP(dumpbuf_cur - dumpbuf_start, PAGESIZE); 3717c478bd9Sstevel@tonic-gate int err; 3727c478bd9Sstevel@tonic-gate 3737c478bd9Sstevel@tonic-gate if (dumpvp_off + size > dumpvp_limit) { 3747c478bd9Sstevel@tonic-gate dump_ioerr = ENOSPC; 3757c478bd9Sstevel@tonic-gate } else if (size != 0) { 3767c478bd9Sstevel@tonic-gate if (panicstr) 3777c478bd9Sstevel@tonic-gate err = VOP_DUMP(dumpvp, dumpbuf_start, 378da6c28aaSamw lbtodb(dumpvp_off), btod(size), NULL); 3797c478bd9Sstevel@tonic-gate else 3807c478bd9Sstevel@tonic-gate err = vn_rdwr(UIO_WRITE, dumpvp, dumpbuf_start, size, 3817c478bd9Sstevel@tonic-gate dumpvp_off, UIO_SYSSPACE, 0, dumpvp_limit, 3827c478bd9Sstevel@tonic-gate kcred, 0); 3837c478bd9Sstevel@tonic-gate if (err && dump_ioerr == 0) 3847c478bd9Sstevel@tonic-gate dump_ioerr = err; 3857c478bd9Sstevel@tonic-gate } 3867c478bd9Sstevel@tonic-gate dumpvp_off += size; 3877c478bd9Sstevel@tonic-gate dumpbuf_cur = dumpbuf_start; 3887c478bd9Sstevel@tonic-gate dump_timeleft = dump_timeout; 3897c478bd9Sstevel@tonic-gate return (dumpvp_off); 3907c478bd9Sstevel@tonic-gate } 3917c478bd9Sstevel@tonic-gate 3927c478bd9Sstevel@tonic-gate void 3937c478bd9Sstevel@tonic-gate dumpvp_write(const void *va, size_t size) 3947c478bd9Sstevel@tonic-gate { 3957c478bd9Sstevel@tonic-gate while (size != 0) { 3967c478bd9Sstevel@tonic-gate size_t len = MIN(size, dumpbuf_end - dumpbuf_cur); 3977c478bd9Sstevel@tonic-gate if (len == 0) { 3987c478bd9Sstevel@tonic-gate (void) dumpvp_flush(); 3997c478bd9Sstevel@tonic-gate } else { 4007c478bd9Sstevel@tonic-gate bcopy(va, dumpbuf_cur, len); 4017c478bd9Sstevel@tonic-gate va = (char *)va + len; 4027c478bd9Sstevel@tonic-gate dumpbuf_cur += len; 4037c478bd9Sstevel@tonic-gate size -= len; 4047c478bd9Sstevel@tonic-gate } 4057c478bd9Sstevel@tonic-gate } 4067c478bd9Sstevel@tonic-gate } 4077c478bd9Sstevel@tonic-gate 4087c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 4097c478bd9Sstevel@tonic-gate static void 4107c478bd9Sstevel@tonic-gate dumpvp_ksyms_write(const void *src, void *dst, size_t size) 4117c478bd9Sstevel@tonic-gate { 4127c478bd9Sstevel@tonic-gate dumpvp_write(src, size); 4137c478bd9Sstevel@tonic-gate } 4147c478bd9Sstevel@tonic-gate 4157c478bd9Sstevel@tonic-gate /* 4167c478bd9Sstevel@tonic-gate * Mark 'pfn' in the bitmap and dump its translation table entry. 4177c478bd9Sstevel@tonic-gate */ 4187c478bd9Sstevel@tonic-gate void 4197c478bd9Sstevel@tonic-gate dump_addpage(struct as *as, void *va, pfn_t pfn) 4207c478bd9Sstevel@tonic-gate { 4217c478bd9Sstevel@tonic-gate mem_vtop_t mem_vtop; 4227c478bd9Sstevel@tonic-gate pgcnt_t bitnum; 4237c478bd9Sstevel@tonic-gate 4247c478bd9Sstevel@tonic-gate if ((bitnum = dump_pfn_to_bitnum(pfn)) != (pgcnt_t)-1) { 4257c478bd9Sstevel@tonic-gate if (!BT_TEST(dump_bitmap, bitnum)) { 4267c478bd9Sstevel@tonic-gate dumphdr->dump_npages++; 4277c478bd9Sstevel@tonic-gate BT_SET(dump_bitmap, bitnum); 4287c478bd9Sstevel@tonic-gate } 4297c478bd9Sstevel@tonic-gate dumphdr->dump_nvtop++; 4307c478bd9Sstevel@tonic-gate mem_vtop.m_as = as; 4317c478bd9Sstevel@tonic-gate mem_vtop.m_va = va; 4327c478bd9Sstevel@tonic-gate mem_vtop.m_pfn = pfn; 4337c478bd9Sstevel@tonic-gate dumpvp_write(&mem_vtop, sizeof (mem_vtop_t)); 4347c478bd9Sstevel@tonic-gate } 4357c478bd9Sstevel@tonic-gate dump_timeleft = dump_timeout; 4367c478bd9Sstevel@tonic-gate } 4377c478bd9Sstevel@tonic-gate 4387c478bd9Sstevel@tonic-gate /* 4397c478bd9Sstevel@tonic-gate * Mark 'pfn' in the bitmap 4407c478bd9Sstevel@tonic-gate */ 4417c478bd9Sstevel@tonic-gate void 4427c478bd9Sstevel@tonic-gate dump_page(pfn_t pfn) 4437c478bd9Sstevel@tonic-gate { 4447c478bd9Sstevel@tonic-gate pgcnt_t bitnum; 4457c478bd9Sstevel@tonic-gate 4467c478bd9Sstevel@tonic-gate if ((bitnum = dump_pfn_to_bitnum(pfn)) != (pgcnt_t)-1) { 4477c478bd9Sstevel@tonic-gate if (!BT_TEST(dump_bitmap, bitnum)) { 4487c478bd9Sstevel@tonic-gate dumphdr->dump_npages++; 4497c478bd9Sstevel@tonic-gate BT_SET(dump_bitmap, bitnum); 4507c478bd9Sstevel@tonic-gate } 4517c478bd9Sstevel@tonic-gate } 4527c478bd9Sstevel@tonic-gate dump_timeleft = dump_timeout; 4537c478bd9Sstevel@tonic-gate } 4547c478bd9Sstevel@tonic-gate 4557c478bd9Sstevel@tonic-gate /* 4567c478bd9Sstevel@tonic-gate * Dump the <as, va, pfn> information for a given address space. 4577c478bd9Sstevel@tonic-gate * SEGOP_DUMP() will call dump_addpage() for each page in the segment. 4587c478bd9Sstevel@tonic-gate */ 4597c478bd9Sstevel@tonic-gate static void 4607c478bd9Sstevel@tonic-gate dump_as(struct as *as) 4617c478bd9Sstevel@tonic-gate { 4627c478bd9Sstevel@tonic-gate struct seg *seg; 4637c478bd9Sstevel@tonic-gate 4647c478bd9Sstevel@tonic-gate AS_LOCK_ENTER(as, &as->a_lock, RW_READER); 4657c478bd9Sstevel@tonic-gate for (seg = AS_SEGFIRST(as); seg; seg = AS_SEGNEXT(as, seg)) { 4667c478bd9Sstevel@tonic-gate if (seg->s_as != as) 4677c478bd9Sstevel@tonic-gate break; 4687c478bd9Sstevel@tonic-gate if (seg->s_ops == NULL) 4697c478bd9Sstevel@tonic-gate continue; 4707c478bd9Sstevel@tonic-gate SEGOP_DUMP(seg); 4717c478bd9Sstevel@tonic-gate } 4727c478bd9Sstevel@tonic-gate AS_LOCK_EXIT(as, &as->a_lock); 4737c478bd9Sstevel@tonic-gate 4747c478bd9Sstevel@tonic-gate if (seg != NULL) 4757c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "invalid segment %p in address space %p", 4767c478bd9Sstevel@tonic-gate (void *)seg, (void *)as); 4777c478bd9Sstevel@tonic-gate } 4787c478bd9Sstevel@tonic-gate 4797c478bd9Sstevel@tonic-gate static int 4807c478bd9Sstevel@tonic-gate dump_process(pid_t pid) 4817c478bd9Sstevel@tonic-gate { 4827c478bd9Sstevel@tonic-gate proc_t *p = sprlock(pid); 4837c478bd9Sstevel@tonic-gate 4847c478bd9Sstevel@tonic-gate if (p == NULL) 4857c478bd9Sstevel@tonic-gate return (-1); 4867c478bd9Sstevel@tonic-gate if (p->p_as != &kas) { 4877c478bd9Sstevel@tonic-gate mutex_exit(&p->p_lock); 4887c478bd9Sstevel@tonic-gate dump_as(p->p_as); 4897c478bd9Sstevel@tonic-gate mutex_enter(&p->p_lock); 4907c478bd9Sstevel@tonic-gate } 4917c478bd9Sstevel@tonic-gate 4927c478bd9Sstevel@tonic-gate sprunlock(p); 4937c478bd9Sstevel@tonic-gate 4947c478bd9Sstevel@tonic-gate return (0); 4957c478bd9Sstevel@tonic-gate } 4967c478bd9Sstevel@tonic-gate 4977c478bd9Sstevel@tonic-gate void 4987c478bd9Sstevel@tonic-gate dump_ereports(void) 4997c478bd9Sstevel@tonic-gate { 5007c478bd9Sstevel@tonic-gate u_offset_t dumpvp_start; 5017c478bd9Sstevel@tonic-gate erpt_dump_t ed; 5027c478bd9Sstevel@tonic-gate 5037c478bd9Sstevel@tonic-gate if (dumpvp == NULL || dumphdr == NULL) 5047c478bd9Sstevel@tonic-gate return; 5057c478bd9Sstevel@tonic-gate 5067c478bd9Sstevel@tonic-gate dumpbuf_cur = dumpbuf_start; 5077c478bd9Sstevel@tonic-gate dumpvp_limit = dumpvp_size - (DUMP_OFFSET + DUMP_LOGSIZE); 5087c478bd9Sstevel@tonic-gate dumpvp_start = dumpvp_limit - DUMP_ERPTSIZE; 5097c478bd9Sstevel@tonic-gate dumpvp_off = dumpvp_start; 5107c478bd9Sstevel@tonic-gate 5117c478bd9Sstevel@tonic-gate fm_ereport_dump(); 5127c478bd9Sstevel@tonic-gate if (panicstr) 5137c478bd9Sstevel@tonic-gate errorq_dump(); 5147c478bd9Sstevel@tonic-gate 5157c478bd9Sstevel@tonic-gate bzero(&ed, sizeof (ed)); /* indicate end of ereports */ 5167c478bd9Sstevel@tonic-gate dumpvp_write(&ed, sizeof (ed)); 5177c478bd9Sstevel@tonic-gate (void) dumpvp_flush(); 5187c478bd9Sstevel@tonic-gate 5197c478bd9Sstevel@tonic-gate if (!panicstr) { 5207c478bd9Sstevel@tonic-gate (void) VOP_PUTPAGE(dumpvp, dumpvp_start, 5217c478bd9Sstevel@tonic-gate (size_t)(dumpvp_off - dumpvp_start), 522da6c28aaSamw B_INVAL | B_FORCE, kcred, NULL); 5237c478bd9Sstevel@tonic-gate } 5247c478bd9Sstevel@tonic-gate } 5257c478bd9Sstevel@tonic-gate 5267c478bd9Sstevel@tonic-gate void 5277c478bd9Sstevel@tonic-gate dump_messages(void) 5287c478bd9Sstevel@tonic-gate { 5297c478bd9Sstevel@tonic-gate log_dump_t ld; 5307c478bd9Sstevel@tonic-gate mblk_t *mctl, *mdata; 5317c478bd9Sstevel@tonic-gate queue_t *q, *qlast; 5327c478bd9Sstevel@tonic-gate u_offset_t dumpvp_start; 5337c478bd9Sstevel@tonic-gate 5347c478bd9Sstevel@tonic-gate if (dumpvp == NULL || dumphdr == NULL || log_consq == NULL) 5357c478bd9Sstevel@tonic-gate return; 5367c478bd9Sstevel@tonic-gate 5377c478bd9Sstevel@tonic-gate dumpbuf_cur = dumpbuf_start; 5387c478bd9Sstevel@tonic-gate dumpvp_limit = dumpvp_size - DUMP_OFFSET; 5397c478bd9Sstevel@tonic-gate dumpvp_start = dumpvp_limit - DUMP_LOGSIZE; 5407c478bd9Sstevel@tonic-gate dumpvp_off = dumpvp_start; 5417c478bd9Sstevel@tonic-gate 5427c478bd9Sstevel@tonic-gate qlast = NULL; 5437c478bd9Sstevel@tonic-gate do { 5447c478bd9Sstevel@tonic-gate for (q = log_consq; q->q_next != qlast; q = q->q_next) 5457c478bd9Sstevel@tonic-gate continue; 5467c478bd9Sstevel@tonic-gate for (mctl = q->q_first; mctl != NULL; mctl = mctl->b_next) { 5477c478bd9Sstevel@tonic-gate dump_timeleft = dump_timeout; 5487c478bd9Sstevel@tonic-gate mdata = mctl->b_cont; 5497c478bd9Sstevel@tonic-gate ld.ld_magic = LOG_MAGIC; 5507c478bd9Sstevel@tonic-gate ld.ld_msgsize = MBLKL(mctl->b_cont); 5517c478bd9Sstevel@tonic-gate ld.ld_csum = checksum32(mctl->b_rptr, MBLKL(mctl)); 5527c478bd9Sstevel@tonic-gate ld.ld_msum = checksum32(mdata->b_rptr, MBLKL(mdata)); 5537c478bd9Sstevel@tonic-gate dumpvp_write(&ld, sizeof (ld)); 5547c478bd9Sstevel@tonic-gate dumpvp_write(mctl->b_rptr, MBLKL(mctl)); 5557c478bd9Sstevel@tonic-gate dumpvp_write(mdata->b_rptr, MBLKL(mdata)); 5567c478bd9Sstevel@tonic-gate } 5577c478bd9Sstevel@tonic-gate } while ((qlast = q) != log_consq); 5587c478bd9Sstevel@tonic-gate 5597c478bd9Sstevel@tonic-gate ld.ld_magic = 0; /* indicate end of messages */ 5607c478bd9Sstevel@tonic-gate dumpvp_write(&ld, sizeof (ld)); 5617c478bd9Sstevel@tonic-gate (void) dumpvp_flush(); 5627c478bd9Sstevel@tonic-gate if (!panicstr) { 5637c478bd9Sstevel@tonic-gate (void) VOP_PUTPAGE(dumpvp, dumpvp_start, 5647c478bd9Sstevel@tonic-gate (size_t)(dumpvp_off - dumpvp_start), 565da6c28aaSamw B_INVAL | B_FORCE, kcred, NULL); 5667c478bd9Sstevel@tonic-gate } 5677c478bd9Sstevel@tonic-gate } 5687c478bd9Sstevel@tonic-gate 5697c478bd9Sstevel@tonic-gate static void 5707c478bd9Sstevel@tonic-gate dump_pagecopy(void *src, void *dst) 5717c478bd9Sstevel@tonic-gate { 5727c478bd9Sstevel@tonic-gate long *wsrc = (long *)src; 5737c478bd9Sstevel@tonic-gate long *wdst = (long *)dst; 5747c478bd9Sstevel@tonic-gate const ulong_t ncopies = PAGESIZE / sizeof (long); 5757c478bd9Sstevel@tonic-gate volatile int w = 0; 5767c478bd9Sstevel@tonic-gate volatile int ueoff = -1; 5777c478bd9Sstevel@tonic-gate on_trap_data_t otd; 5787c478bd9Sstevel@tonic-gate 5797c478bd9Sstevel@tonic-gate if (on_trap(&otd, OT_DATA_EC)) { 5807c478bd9Sstevel@tonic-gate if (ueoff == -1) { 5817c478bd9Sstevel@tonic-gate uint64_t pa; 5827c478bd9Sstevel@tonic-gate 5837c478bd9Sstevel@tonic-gate ueoff = w * sizeof (long); 5847c478bd9Sstevel@tonic-gate pa = ptob((uint64_t)hat_getpfnum(kas.a_hat, src)) 5857c478bd9Sstevel@tonic-gate + ueoff; 5867c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "memory error at PA 0x%08x.%08x", 5877c478bd9Sstevel@tonic-gate (uint32_t)(pa >> 32), (uint32_t)pa); 5887c478bd9Sstevel@tonic-gate } 5897c478bd9Sstevel@tonic-gate #ifdef _LP64 5907c478bd9Sstevel@tonic-gate wdst[w++] = 0xbadecc00badecc; 5917c478bd9Sstevel@tonic-gate #else 5927c478bd9Sstevel@tonic-gate wdst[w++] = 0xbadecc; 5937c478bd9Sstevel@tonic-gate #endif 5947c478bd9Sstevel@tonic-gate } 5957c478bd9Sstevel@tonic-gate while (w < ncopies) { 5967c478bd9Sstevel@tonic-gate wdst[w] = wsrc[w]; 5977c478bd9Sstevel@tonic-gate w++; 5987c478bd9Sstevel@tonic-gate } 5997c478bd9Sstevel@tonic-gate no_trap(); 6007c478bd9Sstevel@tonic-gate } 6017c478bd9Sstevel@tonic-gate 6027c478bd9Sstevel@tonic-gate /* 6037c478bd9Sstevel@tonic-gate * Dump the system. 6047c478bd9Sstevel@tonic-gate */ 6057c478bd9Sstevel@tonic-gate void 6067c478bd9Sstevel@tonic-gate dumpsys(void) 6077c478bd9Sstevel@tonic-gate { 6087c478bd9Sstevel@tonic-gate pfn_t pfn; 6097c478bd9Sstevel@tonic-gate pgcnt_t bitnum; 6107c478bd9Sstevel@tonic-gate int npages = 0; 6117c478bd9Sstevel@tonic-gate int percent_done = 0; 6127c478bd9Sstevel@tonic-gate uint32_t csize; 6137c478bd9Sstevel@tonic-gate u_offset_t total_csize = 0; 6147c478bd9Sstevel@tonic-gate int compress_ratio; 6157c478bd9Sstevel@tonic-gate proc_t *p; 6167c478bd9Sstevel@tonic-gate pid_t npids, pidx; 6177c478bd9Sstevel@tonic-gate char *content; 6187c478bd9Sstevel@tonic-gate 6197c478bd9Sstevel@tonic-gate if (dumpvp == NULL || dumphdr == NULL) { 6207c478bd9Sstevel@tonic-gate uprintf("skipping system dump - no dump device configured\n"); 6217c478bd9Sstevel@tonic-gate return; 6227c478bd9Sstevel@tonic-gate } 6237c478bd9Sstevel@tonic-gate dumpbuf_cur = dumpbuf_start; 6247c478bd9Sstevel@tonic-gate 6257c478bd9Sstevel@tonic-gate /* 6267c478bd9Sstevel@tonic-gate * Calculate the starting block for dump. If we're dumping on a 6277c478bd9Sstevel@tonic-gate * swap device, start 1/5 of the way in; otherwise, start at the 6287c478bd9Sstevel@tonic-gate * beginning. And never use the first page -- it may be a disk label. 6297c478bd9Sstevel@tonic-gate */ 6307c478bd9Sstevel@tonic-gate if (dumpvp->v_flag & VISSWAP) 6317c478bd9Sstevel@tonic-gate dumphdr->dump_start = P2ROUNDUP(dumpvp_size / 5, DUMP_OFFSET); 6327c478bd9Sstevel@tonic-gate else 6337c478bd9Sstevel@tonic-gate dumphdr->dump_start = DUMP_OFFSET; 6347c478bd9Sstevel@tonic-gate 6357c478bd9Sstevel@tonic-gate dumphdr->dump_flags = DF_VALID | DF_COMPLETE | DF_LIVE; 6367c478bd9Sstevel@tonic-gate dumphdr->dump_crashtime = gethrestime_sec(); 6377c478bd9Sstevel@tonic-gate dumphdr->dump_npages = 0; 6387c478bd9Sstevel@tonic-gate dumphdr->dump_nvtop = 0; 6397c478bd9Sstevel@tonic-gate bzero(dump_bitmap, BT_SIZEOFMAP(dump_bitmapsize)); 6407c478bd9Sstevel@tonic-gate dump_timeleft = dump_timeout; 6417c478bd9Sstevel@tonic-gate 6427c478bd9Sstevel@tonic-gate if (panicstr) { 6437c478bd9Sstevel@tonic-gate dumphdr->dump_flags &= ~DF_LIVE; 644da6c28aaSamw (void) VOP_DUMPCTL(dumpvp, DUMP_FREE, NULL, NULL); 645da6c28aaSamw (void) VOP_DUMPCTL(dumpvp, DUMP_ALLOC, NULL, NULL); 6467c478bd9Sstevel@tonic-gate (void) vsnprintf(dumphdr->dump_panicstring, DUMP_PANICSIZE, 6477c478bd9Sstevel@tonic-gate panicstr, panicargs); 6487c478bd9Sstevel@tonic-gate } 6497c478bd9Sstevel@tonic-gate 6507c478bd9Sstevel@tonic-gate if (dump_conflags & DUMP_ALL) 6517c478bd9Sstevel@tonic-gate content = "all"; 6527c478bd9Sstevel@tonic-gate else if (dump_conflags & DUMP_CURPROC) 6537c478bd9Sstevel@tonic-gate content = "kernel + curproc"; 6547c478bd9Sstevel@tonic-gate else 6557c478bd9Sstevel@tonic-gate content = "kernel"; 6567c478bd9Sstevel@tonic-gate uprintf("dumping to %s, offset %lld, content: %s\n", dumppath, 6577c478bd9Sstevel@tonic-gate dumphdr->dump_start, content); 6587c478bd9Sstevel@tonic-gate 6597c478bd9Sstevel@tonic-gate /* 6607c478bd9Sstevel@tonic-gate * Leave room for the message and ereport save areas and terminal dump 6617c478bd9Sstevel@tonic-gate * header. 6627c478bd9Sstevel@tonic-gate */ 6637c478bd9Sstevel@tonic-gate dumpvp_limit = dumpvp_size - DUMP_LOGSIZE - DUMP_OFFSET - DUMP_ERPTSIZE; 6647c478bd9Sstevel@tonic-gate 6657c478bd9Sstevel@tonic-gate /* 6667c478bd9Sstevel@tonic-gate * Write out the symbol table. It's no longer compressed, 6677c478bd9Sstevel@tonic-gate * so its 'size' and 'csize' are equal. 6687c478bd9Sstevel@tonic-gate */ 6697c478bd9Sstevel@tonic-gate dumpvp_off = dumphdr->dump_ksyms = dumphdr->dump_start + PAGESIZE; 6707c478bd9Sstevel@tonic-gate dumphdr->dump_ksyms_size = dumphdr->dump_ksyms_csize = 6717c478bd9Sstevel@tonic-gate ksyms_snapshot(dumpvp_ksyms_write, NULL, LONG_MAX); 6727c478bd9Sstevel@tonic-gate 6737c478bd9Sstevel@tonic-gate /* 6747c478bd9Sstevel@tonic-gate * Write out the translation map. 6757c478bd9Sstevel@tonic-gate */ 6767c478bd9Sstevel@tonic-gate dumphdr->dump_map = dumpvp_flush(); 6777c478bd9Sstevel@tonic-gate dump_as(&kas); 678ae115bc7Smrj dumphdr->dump_nvtop += dump_plat_addr(); 6797c478bd9Sstevel@tonic-gate 6807c478bd9Sstevel@tonic-gate /* 6817c478bd9Sstevel@tonic-gate * call into hat, which may have unmapped pages that also need to 6827c478bd9Sstevel@tonic-gate * be in the dump 6837c478bd9Sstevel@tonic-gate */ 6847c478bd9Sstevel@tonic-gate hat_dump(); 6857c478bd9Sstevel@tonic-gate 6867c478bd9Sstevel@tonic-gate if (dump_conflags & DUMP_ALL) { 6877c478bd9Sstevel@tonic-gate mutex_enter(&pidlock); 6887c478bd9Sstevel@tonic-gate 6897c478bd9Sstevel@tonic-gate for (npids = 0, p = practive; p != NULL; p = p->p_next) 6907c478bd9Sstevel@tonic-gate dump_pids[npids++] = p->p_pid; 6917c478bd9Sstevel@tonic-gate 6927c478bd9Sstevel@tonic-gate mutex_exit(&pidlock); 6937c478bd9Sstevel@tonic-gate 6947c478bd9Sstevel@tonic-gate for (pidx = 0; pidx < npids; pidx++) 6957c478bd9Sstevel@tonic-gate (void) dump_process(dump_pids[pidx]); 6967c478bd9Sstevel@tonic-gate 6977c478bd9Sstevel@tonic-gate for (bitnum = 0; bitnum < dump_bitmapsize; bitnum++) { 6987c478bd9Sstevel@tonic-gate dump_timeleft = dump_timeout; 6997c478bd9Sstevel@tonic-gate BT_SET(dump_bitmap, bitnum); 7007c478bd9Sstevel@tonic-gate } 7017c478bd9Sstevel@tonic-gate dumphdr->dump_npages = dump_bitmapsize; 7027c478bd9Sstevel@tonic-gate dumphdr->dump_flags |= DF_ALL; 7037c478bd9Sstevel@tonic-gate 7047c478bd9Sstevel@tonic-gate } else if (dump_conflags & DUMP_CURPROC) { 7057c478bd9Sstevel@tonic-gate /* 7067c478bd9Sstevel@tonic-gate * Determine which pid is to be dumped. If we're panicking, we 7077c478bd9Sstevel@tonic-gate * dump the process associated with panic_thread (if any). If 7087c478bd9Sstevel@tonic-gate * this is a live dump, we dump the process associated with 7097c478bd9Sstevel@tonic-gate * curthread. 7107c478bd9Sstevel@tonic-gate */ 7117c478bd9Sstevel@tonic-gate npids = 0; 7127c478bd9Sstevel@tonic-gate if (panicstr) { 7137c478bd9Sstevel@tonic-gate if (panic_thread != NULL && 7147c478bd9Sstevel@tonic-gate panic_thread->t_procp != NULL && 7157c478bd9Sstevel@tonic-gate panic_thread->t_procp != &p0) { 7167c478bd9Sstevel@tonic-gate dump_pids[npids++] = 7177c478bd9Sstevel@tonic-gate panic_thread->t_procp->p_pid; 7187c478bd9Sstevel@tonic-gate } 7197c478bd9Sstevel@tonic-gate } else { 7207c478bd9Sstevel@tonic-gate dump_pids[npids++] = curthread->t_procp->p_pid; 7217c478bd9Sstevel@tonic-gate } 7227c478bd9Sstevel@tonic-gate 7237c478bd9Sstevel@tonic-gate if (npids && dump_process(dump_pids[0]) == 0) 7247c478bd9Sstevel@tonic-gate dumphdr->dump_flags |= DF_CURPROC; 7257c478bd9Sstevel@tonic-gate else 7267c478bd9Sstevel@tonic-gate dumphdr->dump_flags |= DF_KERNEL; 7277c478bd9Sstevel@tonic-gate 7287c478bd9Sstevel@tonic-gate } else { 7297c478bd9Sstevel@tonic-gate dumphdr->dump_flags |= DF_KERNEL; 7307c478bd9Sstevel@tonic-gate } 7317c478bd9Sstevel@tonic-gate 7327c478bd9Sstevel@tonic-gate dumphdr->dump_hashmask = (1 << highbit(dumphdr->dump_nvtop - 1)) - 1; 7337c478bd9Sstevel@tonic-gate 7347c478bd9Sstevel@tonic-gate /* 7357c478bd9Sstevel@tonic-gate * Write out the pfn table. 7367c478bd9Sstevel@tonic-gate */ 7377c478bd9Sstevel@tonic-gate dumphdr->dump_pfn = dumpvp_flush(); 7387c478bd9Sstevel@tonic-gate for (bitnum = 0; bitnum < dump_bitmapsize; bitnum++) { 7397c478bd9Sstevel@tonic-gate dump_timeleft = dump_timeout; 7407c478bd9Sstevel@tonic-gate if (!BT_TEST(dump_bitmap, bitnum)) 7417c478bd9Sstevel@tonic-gate continue; 7427c478bd9Sstevel@tonic-gate pfn = dump_bitnum_to_pfn(bitnum); 7437c478bd9Sstevel@tonic-gate ASSERT(pfn != PFN_INVALID); 7447c478bd9Sstevel@tonic-gate dumpvp_write(&pfn, sizeof (pfn_t)); 7457c478bd9Sstevel@tonic-gate } 746ae115bc7Smrj dump_plat_pfn(); 7477c478bd9Sstevel@tonic-gate 7487c478bd9Sstevel@tonic-gate /* 7497c478bd9Sstevel@tonic-gate * Write out all the pages. 7507c478bd9Sstevel@tonic-gate */ 7517c478bd9Sstevel@tonic-gate dumphdr->dump_data = dumpvp_flush(); 7527c478bd9Sstevel@tonic-gate for (bitnum = 0; bitnum < dump_bitmapsize; bitnum++) { 7537c478bd9Sstevel@tonic-gate dump_timeleft = dump_timeout; 7547c478bd9Sstevel@tonic-gate if (!BT_TEST(dump_bitmap, bitnum)) 7557c478bd9Sstevel@tonic-gate continue; 7567c478bd9Sstevel@tonic-gate pfn = dump_bitnum_to_pfn(bitnum); 7577c478bd9Sstevel@tonic-gate ASSERT(pfn != PFN_INVALID); 7587c478bd9Sstevel@tonic-gate 7597c478bd9Sstevel@tonic-gate /* 7607c478bd9Sstevel@tonic-gate * Map in page frame 'pfn', scan it for UE's while copying 7617c478bd9Sstevel@tonic-gate * the data to dump_uebuf, unmap it, compress dump_uebuf into 7627c478bd9Sstevel@tonic-gate * dump_cbuf, and write out dump_cbuf. The UE check ensures 7637c478bd9Sstevel@tonic-gate * that we don't lose the whole dump because of a latent UE. 7647c478bd9Sstevel@tonic-gate */ 7657c478bd9Sstevel@tonic-gate hat_devload(kas.a_hat, dump_cmap, PAGESIZE, pfn, PROT_READ, 7667c478bd9Sstevel@tonic-gate HAT_LOAD_NOCONSIST); 7677c478bd9Sstevel@tonic-gate dump_pagecopy(dump_cmap, dump_uebuf); 7687c478bd9Sstevel@tonic-gate hat_unload(kas.a_hat, dump_cmap, PAGESIZE, HAT_UNLOAD); 7697c478bd9Sstevel@tonic-gate csize = (uint32_t)compress(dump_uebuf, dump_cbuf, PAGESIZE); 7707c478bd9Sstevel@tonic-gate dumpvp_write(&csize, sizeof (uint32_t)); 7717c478bd9Sstevel@tonic-gate dumpvp_write(dump_cbuf, csize); 7727c478bd9Sstevel@tonic-gate if (dump_ioerr) { 7737c478bd9Sstevel@tonic-gate dumphdr->dump_flags &= ~DF_COMPLETE; 7747c478bd9Sstevel@tonic-gate dumphdr->dump_npages = npages; 7757c478bd9Sstevel@tonic-gate break; 7767c478bd9Sstevel@tonic-gate } 7777c478bd9Sstevel@tonic-gate total_csize += csize; 7787c478bd9Sstevel@tonic-gate if (++npages * 100LL / dumphdr->dump_npages > percent_done) { 7797c478bd9Sstevel@tonic-gate uprintf("^\r%3d%% done", ++percent_done); 7807c478bd9Sstevel@tonic-gate if (!panicstr) 7817c478bd9Sstevel@tonic-gate delay(1); /* let the output be sent */ 7827c478bd9Sstevel@tonic-gate } 7837c478bd9Sstevel@tonic-gate } 784ae115bc7Smrj dumphdr->dump_npages += dump_plat_data(dump_cbuf); 7857c478bd9Sstevel@tonic-gate 7867c478bd9Sstevel@tonic-gate (void) dumpvp_flush(); 7877c478bd9Sstevel@tonic-gate 7887c478bd9Sstevel@tonic-gate /* 7897c478bd9Sstevel@tonic-gate * Write out the initial and terminal dump headers. 7907c478bd9Sstevel@tonic-gate */ 7917c478bd9Sstevel@tonic-gate dumpvp_off = dumphdr->dump_start; 7927c478bd9Sstevel@tonic-gate dumpvp_write(dumphdr, sizeof (dumphdr_t)); 7937c478bd9Sstevel@tonic-gate (void) dumpvp_flush(); 7947c478bd9Sstevel@tonic-gate 7957c478bd9Sstevel@tonic-gate dumpvp_limit = dumpvp_size; 7967c478bd9Sstevel@tonic-gate dumpvp_off = dumpvp_limit - DUMP_OFFSET; 7977c478bd9Sstevel@tonic-gate dumpvp_write(dumphdr, sizeof (dumphdr_t)); 7987c478bd9Sstevel@tonic-gate (void) dumpvp_flush(); 7997c478bd9Sstevel@tonic-gate 8007c478bd9Sstevel@tonic-gate compress_ratio = (int)(100LL * npages / (btopr(total_csize + 1))); 8017c478bd9Sstevel@tonic-gate 8027c478bd9Sstevel@tonic-gate uprintf("\r%3d%% done: %d pages dumped, compression ratio %d.%02d, ", 8037c478bd9Sstevel@tonic-gate percent_done, npages, compress_ratio / 100, compress_ratio % 100); 8047c478bd9Sstevel@tonic-gate 8057c478bd9Sstevel@tonic-gate if (dump_ioerr == 0) { 8067c478bd9Sstevel@tonic-gate uprintf("dump succeeded\n"); 8077c478bd9Sstevel@tonic-gate } else { 8087c478bd9Sstevel@tonic-gate uprintf("dump failed: error %d\n", dump_ioerr); 8097c478bd9Sstevel@tonic-gate if (panicstr && dumpfaildebug) 8107c478bd9Sstevel@tonic-gate debug_enter("dump failed"); 8117c478bd9Sstevel@tonic-gate } 8127c478bd9Sstevel@tonic-gate 8137c478bd9Sstevel@tonic-gate /* 8147c478bd9Sstevel@tonic-gate * Write out all undelivered messages. This has to be the *last* 8157c478bd9Sstevel@tonic-gate * thing we do because the dump process itself emits messages. 8167c478bd9Sstevel@tonic-gate */ 8177c478bd9Sstevel@tonic-gate if (panicstr) { 8187c478bd9Sstevel@tonic-gate dump_ereports(); 8197c478bd9Sstevel@tonic-gate dump_messages(); 8207c478bd9Sstevel@tonic-gate } 8217c478bd9Sstevel@tonic-gate 8227c478bd9Sstevel@tonic-gate delay(2 * hz); /* let people see the 'done' message */ 8237c478bd9Sstevel@tonic-gate dump_timeleft = 0; 8247c478bd9Sstevel@tonic-gate dump_ioerr = 0; 8257c478bd9Sstevel@tonic-gate } 8267c478bd9Sstevel@tonic-gate 8277c478bd9Sstevel@tonic-gate /* 8287c478bd9Sstevel@tonic-gate * This function is called whenever the memory size, as represented 8297c478bd9Sstevel@tonic-gate * by the phys_install list, changes. 8307c478bd9Sstevel@tonic-gate */ 8317c478bd9Sstevel@tonic-gate void 8327c478bd9Sstevel@tonic-gate dump_resize() 8337c478bd9Sstevel@tonic-gate { 8347c478bd9Sstevel@tonic-gate mutex_enter(&dump_lock); 8357c478bd9Sstevel@tonic-gate dumphdr_init(); 8367c478bd9Sstevel@tonic-gate dumpbuf_resize(); 8377c478bd9Sstevel@tonic-gate mutex_exit(&dump_lock); 8387c478bd9Sstevel@tonic-gate } 839e7cbe64fSgw25295 840e7cbe64fSgw25295 /* 841e7cbe64fSgw25295 * This function allows for dynamic resizing of a dump area. It assumes that 842e7cbe64fSgw25295 * the underlying device has update its appropriate size(9P). 843e7cbe64fSgw25295 */ 844e7cbe64fSgw25295 int 845e7cbe64fSgw25295 dumpvp_resize() 846e7cbe64fSgw25295 { 847e7cbe64fSgw25295 int error; 848e7cbe64fSgw25295 vattr_t vattr; 849e7cbe64fSgw25295 850e7cbe64fSgw25295 mutex_enter(&dump_lock); 851e7cbe64fSgw25295 vattr.va_mask = AT_SIZE; 852e7cbe64fSgw25295 if ((error = VOP_GETATTR(dumpvp, &vattr, 0, kcred, NULL)) != 0) { 853e7cbe64fSgw25295 mutex_exit(&dump_lock); 854e7cbe64fSgw25295 return (error); 855e7cbe64fSgw25295 } 856e7cbe64fSgw25295 857e7cbe64fSgw25295 if (error == 0 && vattr.va_size < 2 * DUMP_LOGSIZE + DUMP_ERPTSIZE) { 858e7cbe64fSgw25295 mutex_exit(&dump_lock); 859e7cbe64fSgw25295 return (ENOSPC); 860e7cbe64fSgw25295 } 861e7cbe64fSgw25295 862e7cbe64fSgw25295 dumpvp_size = vattr.va_size & -DUMP_OFFSET; 863e7cbe64fSgw25295 mutex_exit(&dump_lock); 864e7cbe64fSgw25295 return (0); 865e7cbe64fSgw25295 } 866