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 /* 2365908c77Syu, 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; 220*681d9761SEric Taylor if (strcmp(ddi_driver_name(VTOS(cvp)->s_dip), 221*681d9761SEric Taylor ZFS_DRIVER) == 0 && 222*681d9761SEric Taylor IS_SWAPVP(common_specvp(cvp))) 223*681d9761SEric Taylor error = EBUSY; 2247c478bd9Sstevel@tonic-gate } else { 2257c478bd9Sstevel@tonic-gate if (vn_matchopval(cvp, VOPNAME_DUMP, fs_nosys) || 2267c478bd9Sstevel@tonic-gate !IS_SWAPVP(cvp)) 2277c478bd9Sstevel@tonic-gate error = ENOTSUP; 2287c478bd9Sstevel@tonic-gate } 2297c478bd9Sstevel@tonic-gate } 2307c478bd9Sstevel@tonic-gate 2317c478bd9Sstevel@tonic-gate if (error == 0 && vattr.va_size < 2 * DUMP_LOGSIZE + DUMP_ERPTSIZE) 2327c478bd9Sstevel@tonic-gate error = ENOSPC; 2337c478bd9Sstevel@tonic-gate 2347c478bd9Sstevel@tonic-gate if (error || justchecking) { 235da6c28aaSamw (void) VOP_CLOSE(cvp, FREAD | FWRITE, 1, (offset_t)0, 236da6c28aaSamw kcred, NULL); 2377c478bd9Sstevel@tonic-gate return (error); 2387c478bd9Sstevel@tonic-gate } 2397c478bd9Sstevel@tonic-gate 2407c478bd9Sstevel@tonic-gate VN_HOLD(cvp); 2417c478bd9Sstevel@tonic-gate 2427c478bd9Sstevel@tonic-gate if (dumpvp != NULL) 2437c478bd9Sstevel@tonic-gate dumpfini(); /* unconfigure the old dump device */ 2447c478bd9Sstevel@tonic-gate 2457c478bd9Sstevel@tonic-gate dumpvp = cvp; 2467c478bd9Sstevel@tonic-gate dumpvp_size = vattr.va_size & -DUMP_OFFSET; 2477c478bd9Sstevel@tonic-gate dumppath = kmem_alloc(strlen(name) + 1, KM_SLEEP); 2487c478bd9Sstevel@tonic-gate (void) strcpy(dumppath, name); 2497c478bd9Sstevel@tonic-gate dump_iosize = 0; 2507c478bd9Sstevel@tonic-gate 2517c478bd9Sstevel@tonic-gate /* 2527c478bd9Sstevel@tonic-gate * If the dump device is a block device, attempt to open up the 2537c478bd9Sstevel@tonic-gate * corresponding character device and determine its maximum transfer 2547c478bd9Sstevel@tonic-gate * size. We use this information to potentially resize dumpbuf to a 2557c478bd9Sstevel@tonic-gate * larger and more optimal size for performing i/o to the dump device. 2567c478bd9Sstevel@tonic-gate */ 2577c478bd9Sstevel@tonic-gate if (cvp->v_type == VBLK && 2587c478bd9Sstevel@tonic-gate (cdev_vp = makespecvp(VTOS(cvp)->s_dev, VCHR)) != NULL) { 259da6c28aaSamw if (VOP_OPEN(&cdev_vp, FREAD | FWRITE, kcred, NULL) == 0) { 2607c478bd9Sstevel@tonic-gate size_t blk_size; 2617c478bd9Sstevel@tonic-gate struct dk_cinfo dki; 26265908c77Syu, larry liu - Sun Microsystems - Beijing China struct dk_minfo minf; 2637c478bd9Sstevel@tonic-gate 26465908c77Syu, larry liu - Sun Microsystems - Beijing China if (VOP_IOCTL(cdev_vp, DKIOCGMEDIAINFO, 26565908c77Syu, larry liu - Sun Microsystems - Beijing China (intptr_t)&minf, FKIOCTL, kcred, NULL, NULL) 26665908c77Syu, larry liu - Sun Microsystems - Beijing China == 0 && minf.dki_lbsize != 0) 26765908c77Syu, larry liu - Sun Microsystems - Beijing China blk_size = minf.dki_lbsize; 2687c478bd9Sstevel@tonic-gate else 2697c478bd9Sstevel@tonic-gate blk_size = DEV_BSIZE; 2707c478bd9Sstevel@tonic-gate 2717c478bd9Sstevel@tonic-gate if (VOP_IOCTL(cdev_vp, DKIOCINFO, (intptr_t)&dki, 272da6c28aaSamw FKIOCTL, kcred, NULL, NULL) == 0) { 2737c478bd9Sstevel@tonic-gate dump_iosize = dki.dki_maxtransfer * blk_size; 2747c478bd9Sstevel@tonic-gate dumpbuf_resize(); 2757c478bd9Sstevel@tonic-gate } 276e7cbe64fSgw25295 /* 277*681d9761SEric Taylor * If we are working with a zvol then dumpify it 278*681d9761SEric Taylor * if it's not being used as swap. 279e7cbe64fSgw25295 */ 280e7cbe64fSgw25295 if (strcmp(dki.dki_dname, ZVOL_DRIVER) == 0) { 281*681d9761SEric Taylor if (IS_SWAPVP(common_specvp(cvp))) 282*681d9761SEric Taylor error = EBUSY; 283*681d9761SEric Taylor else if ((error = VOP_IOCTL(cdev_vp, 284e7cbe64fSgw25295 DKIOCDUMPINIT, NULL, FKIOCTL, kcred, 285*681d9761SEric Taylor NULL, NULL)) != 0) 286e7cbe64fSgw25295 dumpfini(); 287e7cbe64fSgw25295 } 2887c478bd9Sstevel@tonic-gate 289da6c28aaSamw (void) VOP_CLOSE(cdev_vp, FREAD | FWRITE, 1, 0, 290da6c28aaSamw kcred, NULL); 2917c478bd9Sstevel@tonic-gate } 2927c478bd9Sstevel@tonic-gate 2937c478bd9Sstevel@tonic-gate VN_RELE(cdev_vp); 2947c478bd9Sstevel@tonic-gate } 2957c478bd9Sstevel@tonic-gate 2967c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "?dump on %s size %llu MB\n", name, dumpvp_size >> 20); 2977c478bd9Sstevel@tonic-gate 298e7cbe64fSgw25295 return (error); 2997c478bd9Sstevel@tonic-gate } 3007c478bd9Sstevel@tonic-gate 3017c478bd9Sstevel@tonic-gate void 3027c478bd9Sstevel@tonic-gate dumpfini(void) 3037c478bd9Sstevel@tonic-gate { 304e7cbe64fSgw25295 vattr_t vattr; 305e7cbe64fSgw25295 boolean_t is_zfs = B_FALSE; 306e7cbe64fSgw25295 vnode_t *cdev_vp; 3077c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&dump_lock)); 3087c478bd9Sstevel@tonic-gate 3097c478bd9Sstevel@tonic-gate kmem_free(dumppath, strlen(dumppath) + 1); 3107c478bd9Sstevel@tonic-gate 311e7cbe64fSgw25295 /* 312e7cbe64fSgw25295 * Determine if we are using zvols for our dump device 313e7cbe64fSgw25295 */ 314e7cbe64fSgw25295 vattr.va_mask = AT_RDEV; 315e7cbe64fSgw25295 if (VOP_GETATTR(dumpvp, &vattr, 0, kcred, NULL) == 0) { 316e7cbe64fSgw25295 is_zfs = (getmajor(vattr.va_rdev) == 317e7cbe64fSgw25295 ddi_name_to_major(ZFS_DRIVER)) ? B_TRUE : B_FALSE; 318e7cbe64fSgw25295 } 319e7cbe64fSgw25295 320e7cbe64fSgw25295 /* 321e7cbe64fSgw25295 * If we have a zvol dump device then we call into zfs so 322e7cbe64fSgw25295 * that it may have a chance to cleanup. 323e7cbe64fSgw25295 */ 324e7cbe64fSgw25295 if (is_zfs && 325e7cbe64fSgw25295 (cdev_vp = makespecvp(VTOS(dumpvp)->s_dev, VCHR)) != NULL) { 326e7cbe64fSgw25295 if (VOP_OPEN(&cdev_vp, FREAD | FWRITE, kcred, NULL) == 0) { 327e7cbe64fSgw25295 (void) VOP_IOCTL(cdev_vp, DKIOCDUMPFINI, NULL, FKIOCTL, 328e7cbe64fSgw25295 kcred, NULL, NULL); 329e7cbe64fSgw25295 (void) VOP_CLOSE(cdev_vp, FREAD | FWRITE, 1, 0, 330e7cbe64fSgw25295 kcred, NULL); 331e7cbe64fSgw25295 } 332e7cbe64fSgw25295 VN_RELE(cdev_vp); 333e7cbe64fSgw25295 } 334e7cbe64fSgw25295 335da6c28aaSamw (void) VOP_CLOSE(dumpvp, FREAD | FWRITE, 1, (offset_t)0, kcred, NULL); 3367c478bd9Sstevel@tonic-gate 3377c478bd9Sstevel@tonic-gate VN_RELE(dumpvp); 3387c478bd9Sstevel@tonic-gate 3397c478bd9Sstevel@tonic-gate dumpvp = NULL; 3407c478bd9Sstevel@tonic-gate dumpvp_size = 0; 3417c478bd9Sstevel@tonic-gate dumppath = NULL; 3427c478bd9Sstevel@tonic-gate } 3437c478bd9Sstevel@tonic-gate 3447c478bd9Sstevel@tonic-gate static pfn_t 3457c478bd9Sstevel@tonic-gate dump_bitnum_to_pfn(pgcnt_t bitnum) 3467c478bd9Sstevel@tonic-gate { 3477c478bd9Sstevel@tonic-gate struct memlist *mp; 3487c478bd9Sstevel@tonic-gate 3497c478bd9Sstevel@tonic-gate for (mp = phys_install; mp != NULL; mp = mp->next) { 3507c478bd9Sstevel@tonic-gate if (bitnum < (mp->size >> PAGESHIFT)) 3517c478bd9Sstevel@tonic-gate return ((mp->address >> PAGESHIFT) + bitnum); 3527c478bd9Sstevel@tonic-gate bitnum -= mp->size >> PAGESHIFT; 3537c478bd9Sstevel@tonic-gate } 3547c478bd9Sstevel@tonic-gate return (PFN_INVALID); 3557c478bd9Sstevel@tonic-gate } 3567c478bd9Sstevel@tonic-gate 3577c478bd9Sstevel@tonic-gate static pgcnt_t 3587c478bd9Sstevel@tonic-gate dump_pfn_to_bitnum(pfn_t pfn) 3597c478bd9Sstevel@tonic-gate { 3607c478bd9Sstevel@tonic-gate struct memlist *mp; 3617c478bd9Sstevel@tonic-gate pgcnt_t bitnum = 0; 3627c478bd9Sstevel@tonic-gate 3637c478bd9Sstevel@tonic-gate for (mp = phys_install; mp != NULL; mp = mp->next) { 3647c478bd9Sstevel@tonic-gate if (pfn >= (mp->address >> PAGESHIFT) && 3657c478bd9Sstevel@tonic-gate pfn < ((mp->address + mp->size) >> PAGESHIFT)) 3667c478bd9Sstevel@tonic-gate return (bitnum + pfn - (mp->address >> PAGESHIFT)); 3677c478bd9Sstevel@tonic-gate bitnum += mp->size >> PAGESHIFT; 3687c478bd9Sstevel@tonic-gate } 3697c478bd9Sstevel@tonic-gate return ((pgcnt_t)-1); 3707c478bd9Sstevel@tonic-gate } 3717c478bd9Sstevel@tonic-gate 3727c478bd9Sstevel@tonic-gate static offset_t 3737c478bd9Sstevel@tonic-gate dumpvp_flush(void) 3747c478bd9Sstevel@tonic-gate { 3757c478bd9Sstevel@tonic-gate size_t size = P2ROUNDUP(dumpbuf_cur - dumpbuf_start, PAGESIZE); 3767c478bd9Sstevel@tonic-gate int err; 3777c478bd9Sstevel@tonic-gate 3787c478bd9Sstevel@tonic-gate if (dumpvp_off + size > dumpvp_limit) { 3797c478bd9Sstevel@tonic-gate dump_ioerr = ENOSPC; 3807c478bd9Sstevel@tonic-gate } else if (size != 0) { 3817c478bd9Sstevel@tonic-gate if (panicstr) 3827c478bd9Sstevel@tonic-gate err = VOP_DUMP(dumpvp, dumpbuf_start, 383da6c28aaSamw lbtodb(dumpvp_off), btod(size), NULL); 3847c478bd9Sstevel@tonic-gate else 3857c478bd9Sstevel@tonic-gate err = vn_rdwr(UIO_WRITE, dumpvp, dumpbuf_start, size, 3867c478bd9Sstevel@tonic-gate dumpvp_off, UIO_SYSSPACE, 0, dumpvp_limit, 3877c478bd9Sstevel@tonic-gate kcred, 0); 3887c478bd9Sstevel@tonic-gate if (err && dump_ioerr == 0) 3897c478bd9Sstevel@tonic-gate dump_ioerr = err; 3907c478bd9Sstevel@tonic-gate } 3917c478bd9Sstevel@tonic-gate dumpvp_off += size; 3927c478bd9Sstevel@tonic-gate dumpbuf_cur = dumpbuf_start; 3937c478bd9Sstevel@tonic-gate dump_timeleft = dump_timeout; 3947c478bd9Sstevel@tonic-gate return (dumpvp_off); 3957c478bd9Sstevel@tonic-gate } 3967c478bd9Sstevel@tonic-gate 3977c478bd9Sstevel@tonic-gate void 3987c478bd9Sstevel@tonic-gate dumpvp_write(const void *va, size_t size) 3997c478bd9Sstevel@tonic-gate { 4007c478bd9Sstevel@tonic-gate while (size != 0) { 4017c478bd9Sstevel@tonic-gate size_t len = MIN(size, dumpbuf_end - dumpbuf_cur); 4027c478bd9Sstevel@tonic-gate if (len == 0) { 4037c478bd9Sstevel@tonic-gate (void) dumpvp_flush(); 4047c478bd9Sstevel@tonic-gate } else { 4057c478bd9Sstevel@tonic-gate bcopy(va, dumpbuf_cur, len); 4067c478bd9Sstevel@tonic-gate va = (char *)va + len; 4077c478bd9Sstevel@tonic-gate dumpbuf_cur += len; 4087c478bd9Sstevel@tonic-gate size -= len; 4097c478bd9Sstevel@tonic-gate } 4107c478bd9Sstevel@tonic-gate } 4117c478bd9Sstevel@tonic-gate } 4127c478bd9Sstevel@tonic-gate 4137c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 4147c478bd9Sstevel@tonic-gate static void 4157c478bd9Sstevel@tonic-gate dumpvp_ksyms_write(const void *src, void *dst, size_t size) 4167c478bd9Sstevel@tonic-gate { 4177c478bd9Sstevel@tonic-gate dumpvp_write(src, size); 4187c478bd9Sstevel@tonic-gate } 4197c478bd9Sstevel@tonic-gate 4207c478bd9Sstevel@tonic-gate /* 4217c478bd9Sstevel@tonic-gate * Mark 'pfn' in the bitmap and dump its translation table entry. 4227c478bd9Sstevel@tonic-gate */ 4237c478bd9Sstevel@tonic-gate void 4247c478bd9Sstevel@tonic-gate dump_addpage(struct as *as, void *va, pfn_t pfn) 4257c478bd9Sstevel@tonic-gate { 4267c478bd9Sstevel@tonic-gate mem_vtop_t mem_vtop; 4277c478bd9Sstevel@tonic-gate pgcnt_t bitnum; 4287c478bd9Sstevel@tonic-gate 4297c478bd9Sstevel@tonic-gate if ((bitnum = dump_pfn_to_bitnum(pfn)) != (pgcnt_t)-1) { 4307c478bd9Sstevel@tonic-gate if (!BT_TEST(dump_bitmap, bitnum)) { 4317c478bd9Sstevel@tonic-gate dumphdr->dump_npages++; 4327c478bd9Sstevel@tonic-gate BT_SET(dump_bitmap, bitnum); 4337c478bd9Sstevel@tonic-gate } 4347c478bd9Sstevel@tonic-gate dumphdr->dump_nvtop++; 4357c478bd9Sstevel@tonic-gate mem_vtop.m_as = as; 4367c478bd9Sstevel@tonic-gate mem_vtop.m_va = va; 4377c478bd9Sstevel@tonic-gate mem_vtop.m_pfn = pfn; 4387c478bd9Sstevel@tonic-gate dumpvp_write(&mem_vtop, sizeof (mem_vtop_t)); 4397c478bd9Sstevel@tonic-gate } 4407c478bd9Sstevel@tonic-gate dump_timeleft = dump_timeout; 4417c478bd9Sstevel@tonic-gate } 4427c478bd9Sstevel@tonic-gate 4437c478bd9Sstevel@tonic-gate /* 4447c478bd9Sstevel@tonic-gate * Mark 'pfn' in the bitmap 4457c478bd9Sstevel@tonic-gate */ 4467c478bd9Sstevel@tonic-gate void 4477c478bd9Sstevel@tonic-gate dump_page(pfn_t pfn) 4487c478bd9Sstevel@tonic-gate { 4497c478bd9Sstevel@tonic-gate pgcnt_t bitnum; 4507c478bd9Sstevel@tonic-gate 4517c478bd9Sstevel@tonic-gate if ((bitnum = dump_pfn_to_bitnum(pfn)) != (pgcnt_t)-1) { 4527c478bd9Sstevel@tonic-gate if (!BT_TEST(dump_bitmap, bitnum)) { 4537c478bd9Sstevel@tonic-gate dumphdr->dump_npages++; 4547c478bd9Sstevel@tonic-gate BT_SET(dump_bitmap, bitnum); 4557c478bd9Sstevel@tonic-gate } 4567c478bd9Sstevel@tonic-gate } 4577c478bd9Sstevel@tonic-gate dump_timeleft = dump_timeout; 4587c478bd9Sstevel@tonic-gate } 4597c478bd9Sstevel@tonic-gate 4607c478bd9Sstevel@tonic-gate /* 4617c478bd9Sstevel@tonic-gate * Dump the <as, va, pfn> information for a given address space. 4627c478bd9Sstevel@tonic-gate * SEGOP_DUMP() will call dump_addpage() for each page in the segment. 4637c478bd9Sstevel@tonic-gate */ 4647c478bd9Sstevel@tonic-gate static void 4657c478bd9Sstevel@tonic-gate dump_as(struct as *as) 4667c478bd9Sstevel@tonic-gate { 4677c478bd9Sstevel@tonic-gate struct seg *seg; 4687c478bd9Sstevel@tonic-gate 4697c478bd9Sstevel@tonic-gate AS_LOCK_ENTER(as, &as->a_lock, RW_READER); 4707c478bd9Sstevel@tonic-gate for (seg = AS_SEGFIRST(as); seg; seg = AS_SEGNEXT(as, seg)) { 4717c478bd9Sstevel@tonic-gate if (seg->s_as != as) 4727c478bd9Sstevel@tonic-gate break; 4737c478bd9Sstevel@tonic-gate if (seg->s_ops == NULL) 4747c478bd9Sstevel@tonic-gate continue; 4757c478bd9Sstevel@tonic-gate SEGOP_DUMP(seg); 4767c478bd9Sstevel@tonic-gate } 4777c478bd9Sstevel@tonic-gate AS_LOCK_EXIT(as, &as->a_lock); 4787c478bd9Sstevel@tonic-gate 4797c478bd9Sstevel@tonic-gate if (seg != NULL) 4807c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "invalid segment %p in address space %p", 4817c478bd9Sstevel@tonic-gate (void *)seg, (void *)as); 4827c478bd9Sstevel@tonic-gate } 4837c478bd9Sstevel@tonic-gate 4847c478bd9Sstevel@tonic-gate static int 4857c478bd9Sstevel@tonic-gate dump_process(pid_t pid) 4867c478bd9Sstevel@tonic-gate { 4877c478bd9Sstevel@tonic-gate proc_t *p = sprlock(pid); 4887c478bd9Sstevel@tonic-gate 4897c478bd9Sstevel@tonic-gate if (p == NULL) 4907c478bd9Sstevel@tonic-gate return (-1); 4917c478bd9Sstevel@tonic-gate if (p->p_as != &kas) { 4927c478bd9Sstevel@tonic-gate mutex_exit(&p->p_lock); 4937c478bd9Sstevel@tonic-gate dump_as(p->p_as); 4947c478bd9Sstevel@tonic-gate mutex_enter(&p->p_lock); 4957c478bd9Sstevel@tonic-gate } 4967c478bd9Sstevel@tonic-gate 4977c478bd9Sstevel@tonic-gate sprunlock(p); 4987c478bd9Sstevel@tonic-gate 4997c478bd9Sstevel@tonic-gate return (0); 5007c478bd9Sstevel@tonic-gate } 5017c478bd9Sstevel@tonic-gate 5027c478bd9Sstevel@tonic-gate void 5037c478bd9Sstevel@tonic-gate dump_ereports(void) 5047c478bd9Sstevel@tonic-gate { 5057c478bd9Sstevel@tonic-gate u_offset_t dumpvp_start; 5067c478bd9Sstevel@tonic-gate erpt_dump_t ed; 5077c478bd9Sstevel@tonic-gate 5087c478bd9Sstevel@tonic-gate if (dumpvp == NULL || dumphdr == NULL) 5097c478bd9Sstevel@tonic-gate return; 5107c478bd9Sstevel@tonic-gate 5117c478bd9Sstevel@tonic-gate dumpbuf_cur = dumpbuf_start; 5127c478bd9Sstevel@tonic-gate dumpvp_limit = dumpvp_size - (DUMP_OFFSET + DUMP_LOGSIZE); 5137c478bd9Sstevel@tonic-gate dumpvp_start = dumpvp_limit - DUMP_ERPTSIZE; 5147c478bd9Sstevel@tonic-gate dumpvp_off = dumpvp_start; 5157c478bd9Sstevel@tonic-gate 5167c478bd9Sstevel@tonic-gate fm_ereport_dump(); 5177c478bd9Sstevel@tonic-gate if (panicstr) 5187c478bd9Sstevel@tonic-gate errorq_dump(); 5197c478bd9Sstevel@tonic-gate 5207c478bd9Sstevel@tonic-gate bzero(&ed, sizeof (ed)); /* indicate end of ereports */ 5217c478bd9Sstevel@tonic-gate dumpvp_write(&ed, sizeof (ed)); 5227c478bd9Sstevel@tonic-gate (void) dumpvp_flush(); 5237c478bd9Sstevel@tonic-gate 5247c478bd9Sstevel@tonic-gate if (!panicstr) { 5257c478bd9Sstevel@tonic-gate (void) VOP_PUTPAGE(dumpvp, dumpvp_start, 5267c478bd9Sstevel@tonic-gate (size_t)(dumpvp_off - dumpvp_start), 527da6c28aaSamw B_INVAL | B_FORCE, kcred, NULL); 5287c478bd9Sstevel@tonic-gate } 5297c478bd9Sstevel@tonic-gate } 5307c478bd9Sstevel@tonic-gate 5317c478bd9Sstevel@tonic-gate void 5327c478bd9Sstevel@tonic-gate dump_messages(void) 5337c478bd9Sstevel@tonic-gate { 5347c478bd9Sstevel@tonic-gate log_dump_t ld; 5357c478bd9Sstevel@tonic-gate mblk_t *mctl, *mdata; 5367c478bd9Sstevel@tonic-gate queue_t *q, *qlast; 5377c478bd9Sstevel@tonic-gate u_offset_t dumpvp_start; 5387c478bd9Sstevel@tonic-gate 5397c478bd9Sstevel@tonic-gate if (dumpvp == NULL || dumphdr == NULL || log_consq == NULL) 5407c478bd9Sstevel@tonic-gate return; 5417c478bd9Sstevel@tonic-gate 5427c478bd9Sstevel@tonic-gate dumpbuf_cur = dumpbuf_start; 5437c478bd9Sstevel@tonic-gate dumpvp_limit = dumpvp_size - DUMP_OFFSET; 5447c478bd9Sstevel@tonic-gate dumpvp_start = dumpvp_limit - DUMP_LOGSIZE; 5457c478bd9Sstevel@tonic-gate dumpvp_off = dumpvp_start; 5467c478bd9Sstevel@tonic-gate 5477c478bd9Sstevel@tonic-gate qlast = NULL; 5487c478bd9Sstevel@tonic-gate do { 5497c478bd9Sstevel@tonic-gate for (q = log_consq; q->q_next != qlast; q = q->q_next) 5507c478bd9Sstevel@tonic-gate continue; 5517c478bd9Sstevel@tonic-gate for (mctl = q->q_first; mctl != NULL; mctl = mctl->b_next) { 5527c478bd9Sstevel@tonic-gate dump_timeleft = dump_timeout; 5537c478bd9Sstevel@tonic-gate mdata = mctl->b_cont; 5547c478bd9Sstevel@tonic-gate ld.ld_magic = LOG_MAGIC; 5557c478bd9Sstevel@tonic-gate ld.ld_msgsize = MBLKL(mctl->b_cont); 5567c478bd9Sstevel@tonic-gate ld.ld_csum = checksum32(mctl->b_rptr, MBLKL(mctl)); 5577c478bd9Sstevel@tonic-gate ld.ld_msum = checksum32(mdata->b_rptr, MBLKL(mdata)); 5587c478bd9Sstevel@tonic-gate dumpvp_write(&ld, sizeof (ld)); 5597c478bd9Sstevel@tonic-gate dumpvp_write(mctl->b_rptr, MBLKL(mctl)); 5607c478bd9Sstevel@tonic-gate dumpvp_write(mdata->b_rptr, MBLKL(mdata)); 5617c478bd9Sstevel@tonic-gate } 5627c478bd9Sstevel@tonic-gate } while ((qlast = q) != log_consq); 5637c478bd9Sstevel@tonic-gate 5647c478bd9Sstevel@tonic-gate ld.ld_magic = 0; /* indicate end of messages */ 5657c478bd9Sstevel@tonic-gate dumpvp_write(&ld, sizeof (ld)); 5667c478bd9Sstevel@tonic-gate (void) dumpvp_flush(); 5677c478bd9Sstevel@tonic-gate if (!panicstr) { 5687c478bd9Sstevel@tonic-gate (void) VOP_PUTPAGE(dumpvp, dumpvp_start, 5697c478bd9Sstevel@tonic-gate (size_t)(dumpvp_off - dumpvp_start), 570da6c28aaSamw B_INVAL | B_FORCE, kcred, NULL); 5717c478bd9Sstevel@tonic-gate } 5727c478bd9Sstevel@tonic-gate } 5737c478bd9Sstevel@tonic-gate 5747c478bd9Sstevel@tonic-gate static void 5757c478bd9Sstevel@tonic-gate dump_pagecopy(void *src, void *dst) 5767c478bd9Sstevel@tonic-gate { 5777c478bd9Sstevel@tonic-gate long *wsrc = (long *)src; 5787c478bd9Sstevel@tonic-gate long *wdst = (long *)dst; 5797c478bd9Sstevel@tonic-gate const ulong_t ncopies = PAGESIZE / sizeof (long); 5807c478bd9Sstevel@tonic-gate volatile int w = 0; 5817c478bd9Sstevel@tonic-gate volatile int ueoff = -1; 5827c478bd9Sstevel@tonic-gate on_trap_data_t otd; 5837c478bd9Sstevel@tonic-gate 5847c478bd9Sstevel@tonic-gate if (on_trap(&otd, OT_DATA_EC)) { 5857c478bd9Sstevel@tonic-gate if (ueoff == -1) { 5867c478bd9Sstevel@tonic-gate uint64_t pa; 5877c478bd9Sstevel@tonic-gate 5887c478bd9Sstevel@tonic-gate ueoff = w * sizeof (long); 5897c478bd9Sstevel@tonic-gate pa = ptob((uint64_t)hat_getpfnum(kas.a_hat, src)) 5907c478bd9Sstevel@tonic-gate + ueoff; 5917c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "memory error at PA 0x%08x.%08x", 5927c478bd9Sstevel@tonic-gate (uint32_t)(pa >> 32), (uint32_t)pa); 5937c478bd9Sstevel@tonic-gate } 5947c478bd9Sstevel@tonic-gate #ifdef _LP64 5957c478bd9Sstevel@tonic-gate wdst[w++] = 0xbadecc00badecc; 5967c478bd9Sstevel@tonic-gate #else 5977c478bd9Sstevel@tonic-gate wdst[w++] = 0xbadecc; 5987c478bd9Sstevel@tonic-gate #endif 5997c478bd9Sstevel@tonic-gate } 6007c478bd9Sstevel@tonic-gate while (w < ncopies) { 6017c478bd9Sstevel@tonic-gate wdst[w] = wsrc[w]; 6027c478bd9Sstevel@tonic-gate w++; 6037c478bd9Sstevel@tonic-gate } 6047c478bd9Sstevel@tonic-gate no_trap(); 6057c478bd9Sstevel@tonic-gate } 6067c478bd9Sstevel@tonic-gate 6077c478bd9Sstevel@tonic-gate /* 6087c478bd9Sstevel@tonic-gate * Dump the system. 6097c478bd9Sstevel@tonic-gate */ 6107c478bd9Sstevel@tonic-gate void 6117c478bd9Sstevel@tonic-gate dumpsys(void) 6127c478bd9Sstevel@tonic-gate { 6137c478bd9Sstevel@tonic-gate pfn_t pfn; 6147c478bd9Sstevel@tonic-gate pgcnt_t bitnum; 6157c478bd9Sstevel@tonic-gate int npages = 0; 6167c478bd9Sstevel@tonic-gate int percent_done = 0; 6177c478bd9Sstevel@tonic-gate uint32_t csize; 6187c478bd9Sstevel@tonic-gate u_offset_t total_csize = 0; 6197c478bd9Sstevel@tonic-gate int compress_ratio; 6207c478bd9Sstevel@tonic-gate proc_t *p; 6217c478bd9Sstevel@tonic-gate pid_t npids, pidx; 6227c478bd9Sstevel@tonic-gate char *content; 6237c478bd9Sstevel@tonic-gate 6247c478bd9Sstevel@tonic-gate if (dumpvp == NULL || dumphdr == NULL) { 6257c478bd9Sstevel@tonic-gate uprintf("skipping system dump - no dump device configured\n"); 6267c478bd9Sstevel@tonic-gate return; 6277c478bd9Sstevel@tonic-gate } 6287c478bd9Sstevel@tonic-gate dumpbuf_cur = dumpbuf_start; 6297c478bd9Sstevel@tonic-gate 6307c478bd9Sstevel@tonic-gate /* 6317c478bd9Sstevel@tonic-gate * Calculate the starting block for dump. If we're dumping on a 6327c478bd9Sstevel@tonic-gate * swap device, start 1/5 of the way in; otherwise, start at the 6337c478bd9Sstevel@tonic-gate * beginning. And never use the first page -- it may be a disk label. 6347c478bd9Sstevel@tonic-gate */ 6357c478bd9Sstevel@tonic-gate if (dumpvp->v_flag & VISSWAP) 6367c478bd9Sstevel@tonic-gate dumphdr->dump_start = P2ROUNDUP(dumpvp_size / 5, DUMP_OFFSET); 6377c478bd9Sstevel@tonic-gate else 6387c478bd9Sstevel@tonic-gate dumphdr->dump_start = DUMP_OFFSET; 6397c478bd9Sstevel@tonic-gate 6407c478bd9Sstevel@tonic-gate dumphdr->dump_flags = DF_VALID | DF_COMPLETE | DF_LIVE; 6417c478bd9Sstevel@tonic-gate dumphdr->dump_crashtime = gethrestime_sec(); 6427c478bd9Sstevel@tonic-gate dumphdr->dump_npages = 0; 6437c478bd9Sstevel@tonic-gate dumphdr->dump_nvtop = 0; 6447c478bd9Sstevel@tonic-gate bzero(dump_bitmap, BT_SIZEOFMAP(dump_bitmapsize)); 6457c478bd9Sstevel@tonic-gate dump_timeleft = dump_timeout; 6467c478bd9Sstevel@tonic-gate 6477c478bd9Sstevel@tonic-gate if (panicstr) { 6487c478bd9Sstevel@tonic-gate dumphdr->dump_flags &= ~DF_LIVE; 649da6c28aaSamw (void) VOP_DUMPCTL(dumpvp, DUMP_FREE, NULL, NULL); 650da6c28aaSamw (void) VOP_DUMPCTL(dumpvp, DUMP_ALLOC, NULL, NULL); 6517c478bd9Sstevel@tonic-gate (void) vsnprintf(dumphdr->dump_panicstring, DUMP_PANICSIZE, 6527c478bd9Sstevel@tonic-gate panicstr, panicargs); 6537c478bd9Sstevel@tonic-gate } 6547c478bd9Sstevel@tonic-gate 6557c478bd9Sstevel@tonic-gate if (dump_conflags & DUMP_ALL) 6567c478bd9Sstevel@tonic-gate content = "all"; 6577c478bd9Sstevel@tonic-gate else if (dump_conflags & DUMP_CURPROC) 6587c478bd9Sstevel@tonic-gate content = "kernel + curproc"; 6597c478bd9Sstevel@tonic-gate else 6607c478bd9Sstevel@tonic-gate content = "kernel"; 6617c478bd9Sstevel@tonic-gate uprintf("dumping to %s, offset %lld, content: %s\n", dumppath, 6627c478bd9Sstevel@tonic-gate dumphdr->dump_start, content); 6637c478bd9Sstevel@tonic-gate 6647c478bd9Sstevel@tonic-gate /* 6657c478bd9Sstevel@tonic-gate * Leave room for the message and ereport save areas and terminal dump 6667c478bd9Sstevel@tonic-gate * header. 6677c478bd9Sstevel@tonic-gate */ 6687c478bd9Sstevel@tonic-gate dumpvp_limit = dumpvp_size - DUMP_LOGSIZE - DUMP_OFFSET - DUMP_ERPTSIZE; 6697c478bd9Sstevel@tonic-gate 6707c478bd9Sstevel@tonic-gate /* 6717c478bd9Sstevel@tonic-gate * Write out the symbol table. It's no longer compressed, 6727c478bd9Sstevel@tonic-gate * so its 'size' and 'csize' are equal. 6737c478bd9Sstevel@tonic-gate */ 6747c478bd9Sstevel@tonic-gate dumpvp_off = dumphdr->dump_ksyms = dumphdr->dump_start + PAGESIZE; 6757c478bd9Sstevel@tonic-gate dumphdr->dump_ksyms_size = dumphdr->dump_ksyms_csize = 6767c478bd9Sstevel@tonic-gate ksyms_snapshot(dumpvp_ksyms_write, NULL, LONG_MAX); 6777c478bd9Sstevel@tonic-gate 6787c478bd9Sstevel@tonic-gate /* 6797c478bd9Sstevel@tonic-gate * Write out the translation map. 6807c478bd9Sstevel@tonic-gate */ 6817c478bd9Sstevel@tonic-gate dumphdr->dump_map = dumpvp_flush(); 6827c478bd9Sstevel@tonic-gate dump_as(&kas); 683ae115bc7Smrj dumphdr->dump_nvtop += dump_plat_addr(); 6847c478bd9Sstevel@tonic-gate 6857c478bd9Sstevel@tonic-gate /* 6867c478bd9Sstevel@tonic-gate * call into hat, which may have unmapped pages that also need to 6877c478bd9Sstevel@tonic-gate * be in the dump 6887c478bd9Sstevel@tonic-gate */ 6897c478bd9Sstevel@tonic-gate hat_dump(); 6907c478bd9Sstevel@tonic-gate 6917c478bd9Sstevel@tonic-gate if (dump_conflags & DUMP_ALL) { 6927c478bd9Sstevel@tonic-gate mutex_enter(&pidlock); 6937c478bd9Sstevel@tonic-gate 6947c478bd9Sstevel@tonic-gate for (npids = 0, p = practive; p != NULL; p = p->p_next) 6957c478bd9Sstevel@tonic-gate dump_pids[npids++] = p->p_pid; 6967c478bd9Sstevel@tonic-gate 6977c478bd9Sstevel@tonic-gate mutex_exit(&pidlock); 6987c478bd9Sstevel@tonic-gate 6997c478bd9Sstevel@tonic-gate for (pidx = 0; pidx < npids; pidx++) 7007c478bd9Sstevel@tonic-gate (void) dump_process(dump_pids[pidx]); 7017c478bd9Sstevel@tonic-gate 7027c478bd9Sstevel@tonic-gate for (bitnum = 0; bitnum < dump_bitmapsize; bitnum++) { 7037c478bd9Sstevel@tonic-gate dump_timeleft = dump_timeout; 7047c478bd9Sstevel@tonic-gate BT_SET(dump_bitmap, bitnum); 7057c478bd9Sstevel@tonic-gate } 7067c478bd9Sstevel@tonic-gate dumphdr->dump_npages = dump_bitmapsize; 7077c478bd9Sstevel@tonic-gate dumphdr->dump_flags |= DF_ALL; 7087c478bd9Sstevel@tonic-gate 7097c478bd9Sstevel@tonic-gate } else if (dump_conflags & DUMP_CURPROC) { 7107c478bd9Sstevel@tonic-gate /* 7117c478bd9Sstevel@tonic-gate * Determine which pid is to be dumped. If we're panicking, we 7127c478bd9Sstevel@tonic-gate * dump the process associated with panic_thread (if any). If 7137c478bd9Sstevel@tonic-gate * this is a live dump, we dump the process associated with 7147c478bd9Sstevel@tonic-gate * curthread. 7157c478bd9Sstevel@tonic-gate */ 7167c478bd9Sstevel@tonic-gate npids = 0; 7177c478bd9Sstevel@tonic-gate if (panicstr) { 7187c478bd9Sstevel@tonic-gate if (panic_thread != NULL && 7197c478bd9Sstevel@tonic-gate panic_thread->t_procp != NULL && 7207c478bd9Sstevel@tonic-gate panic_thread->t_procp != &p0) { 7217c478bd9Sstevel@tonic-gate dump_pids[npids++] = 7227c478bd9Sstevel@tonic-gate panic_thread->t_procp->p_pid; 7237c478bd9Sstevel@tonic-gate } 7247c478bd9Sstevel@tonic-gate } else { 7257c478bd9Sstevel@tonic-gate dump_pids[npids++] = curthread->t_procp->p_pid; 7267c478bd9Sstevel@tonic-gate } 7277c478bd9Sstevel@tonic-gate 7287c478bd9Sstevel@tonic-gate if (npids && dump_process(dump_pids[0]) == 0) 7297c478bd9Sstevel@tonic-gate dumphdr->dump_flags |= DF_CURPROC; 7307c478bd9Sstevel@tonic-gate else 7317c478bd9Sstevel@tonic-gate dumphdr->dump_flags |= DF_KERNEL; 7327c478bd9Sstevel@tonic-gate 7337c478bd9Sstevel@tonic-gate } else { 7347c478bd9Sstevel@tonic-gate dumphdr->dump_flags |= DF_KERNEL; 7357c478bd9Sstevel@tonic-gate } 7367c478bd9Sstevel@tonic-gate 7377c478bd9Sstevel@tonic-gate dumphdr->dump_hashmask = (1 << highbit(dumphdr->dump_nvtop - 1)) - 1; 7387c478bd9Sstevel@tonic-gate 7397c478bd9Sstevel@tonic-gate /* 7407c478bd9Sstevel@tonic-gate * Write out the pfn table. 7417c478bd9Sstevel@tonic-gate */ 7427c478bd9Sstevel@tonic-gate dumphdr->dump_pfn = dumpvp_flush(); 7437c478bd9Sstevel@tonic-gate for (bitnum = 0; bitnum < dump_bitmapsize; bitnum++) { 7447c478bd9Sstevel@tonic-gate dump_timeleft = dump_timeout; 7457c478bd9Sstevel@tonic-gate if (!BT_TEST(dump_bitmap, bitnum)) 7467c478bd9Sstevel@tonic-gate continue; 7477c478bd9Sstevel@tonic-gate pfn = dump_bitnum_to_pfn(bitnum); 7487c478bd9Sstevel@tonic-gate ASSERT(pfn != PFN_INVALID); 7497c478bd9Sstevel@tonic-gate dumpvp_write(&pfn, sizeof (pfn_t)); 7507c478bd9Sstevel@tonic-gate } 751ae115bc7Smrj dump_plat_pfn(); 7527c478bd9Sstevel@tonic-gate 7537c478bd9Sstevel@tonic-gate /* 7547c478bd9Sstevel@tonic-gate * Write out all the pages. 7557c478bd9Sstevel@tonic-gate */ 7567c478bd9Sstevel@tonic-gate dumphdr->dump_data = dumpvp_flush(); 7577c478bd9Sstevel@tonic-gate for (bitnum = 0; bitnum < dump_bitmapsize; bitnum++) { 7587c478bd9Sstevel@tonic-gate dump_timeleft = dump_timeout; 7597c478bd9Sstevel@tonic-gate if (!BT_TEST(dump_bitmap, bitnum)) 7607c478bd9Sstevel@tonic-gate continue; 7617c478bd9Sstevel@tonic-gate pfn = dump_bitnum_to_pfn(bitnum); 7627c478bd9Sstevel@tonic-gate ASSERT(pfn != PFN_INVALID); 7637c478bd9Sstevel@tonic-gate 7647c478bd9Sstevel@tonic-gate /* 7657c478bd9Sstevel@tonic-gate * Map in page frame 'pfn', scan it for UE's while copying 7667c478bd9Sstevel@tonic-gate * the data to dump_uebuf, unmap it, compress dump_uebuf into 7677c478bd9Sstevel@tonic-gate * dump_cbuf, and write out dump_cbuf. The UE check ensures 7687c478bd9Sstevel@tonic-gate * that we don't lose the whole dump because of a latent UE. 7697c478bd9Sstevel@tonic-gate */ 7707c478bd9Sstevel@tonic-gate hat_devload(kas.a_hat, dump_cmap, PAGESIZE, pfn, PROT_READ, 7717c478bd9Sstevel@tonic-gate HAT_LOAD_NOCONSIST); 7727c478bd9Sstevel@tonic-gate dump_pagecopy(dump_cmap, dump_uebuf); 7737c478bd9Sstevel@tonic-gate hat_unload(kas.a_hat, dump_cmap, PAGESIZE, HAT_UNLOAD); 7747c478bd9Sstevel@tonic-gate csize = (uint32_t)compress(dump_uebuf, dump_cbuf, PAGESIZE); 7757c478bd9Sstevel@tonic-gate dumpvp_write(&csize, sizeof (uint32_t)); 7767c478bd9Sstevel@tonic-gate dumpvp_write(dump_cbuf, csize); 7777c478bd9Sstevel@tonic-gate if (dump_ioerr) { 7787c478bd9Sstevel@tonic-gate dumphdr->dump_flags &= ~DF_COMPLETE; 7797c478bd9Sstevel@tonic-gate dumphdr->dump_npages = npages; 7807c478bd9Sstevel@tonic-gate break; 7817c478bd9Sstevel@tonic-gate } 7827c478bd9Sstevel@tonic-gate total_csize += csize; 7837c478bd9Sstevel@tonic-gate if (++npages * 100LL / dumphdr->dump_npages > percent_done) { 7847c478bd9Sstevel@tonic-gate uprintf("^\r%3d%% done", ++percent_done); 7857c478bd9Sstevel@tonic-gate if (!panicstr) 7867c478bd9Sstevel@tonic-gate delay(1); /* let the output be sent */ 7877c478bd9Sstevel@tonic-gate } 7887c478bd9Sstevel@tonic-gate } 789ae115bc7Smrj dumphdr->dump_npages += dump_plat_data(dump_cbuf); 7907c478bd9Sstevel@tonic-gate 7917c478bd9Sstevel@tonic-gate (void) dumpvp_flush(); 7927c478bd9Sstevel@tonic-gate 7937c478bd9Sstevel@tonic-gate /* 7947c478bd9Sstevel@tonic-gate * Write out the initial and terminal dump headers. 7957c478bd9Sstevel@tonic-gate */ 7967c478bd9Sstevel@tonic-gate dumpvp_off = dumphdr->dump_start; 7977c478bd9Sstevel@tonic-gate dumpvp_write(dumphdr, sizeof (dumphdr_t)); 7987c478bd9Sstevel@tonic-gate (void) dumpvp_flush(); 7997c478bd9Sstevel@tonic-gate 8007c478bd9Sstevel@tonic-gate dumpvp_limit = dumpvp_size; 8017c478bd9Sstevel@tonic-gate dumpvp_off = dumpvp_limit - DUMP_OFFSET; 8027c478bd9Sstevel@tonic-gate dumpvp_write(dumphdr, sizeof (dumphdr_t)); 8037c478bd9Sstevel@tonic-gate (void) dumpvp_flush(); 8047c478bd9Sstevel@tonic-gate 8057c478bd9Sstevel@tonic-gate compress_ratio = (int)(100LL * npages / (btopr(total_csize + 1))); 8067c478bd9Sstevel@tonic-gate 8077c478bd9Sstevel@tonic-gate uprintf("\r%3d%% done: %d pages dumped, compression ratio %d.%02d, ", 8087c478bd9Sstevel@tonic-gate percent_done, npages, compress_ratio / 100, compress_ratio % 100); 8097c478bd9Sstevel@tonic-gate 8107c478bd9Sstevel@tonic-gate if (dump_ioerr == 0) { 8117c478bd9Sstevel@tonic-gate uprintf("dump succeeded\n"); 8127c478bd9Sstevel@tonic-gate } else { 8137c478bd9Sstevel@tonic-gate uprintf("dump failed: error %d\n", dump_ioerr); 8147c478bd9Sstevel@tonic-gate if (panicstr && dumpfaildebug) 8157c478bd9Sstevel@tonic-gate debug_enter("dump failed"); 8167c478bd9Sstevel@tonic-gate } 8177c478bd9Sstevel@tonic-gate 8187c478bd9Sstevel@tonic-gate /* 8197c478bd9Sstevel@tonic-gate * Write out all undelivered messages. This has to be the *last* 8207c478bd9Sstevel@tonic-gate * thing we do because the dump process itself emits messages. 8217c478bd9Sstevel@tonic-gate */ 8227c478bd9Sstevel@tonic-gate if (panicstr) { 8237c478bd9Sstevel@tonic-gate dump_ereports(); 8247c478bd9Sstevel@tonic-gate dump_messages(); 8257c478bd9Sstevel@tonic-gate } 8267c478bd9Sstevel@tonic-gate 8277c478bd9Sstevel@tonic-gate delay(2 * hz); /* let people see the 'done' message */ 8287c478bd9Sstevel@tonic-gate dump_timeleft = 0; 8297c478bd9Sstevel@tonic-gate dump_ioerr = 0; 8307c478bd9Sstevel@tonic-gate } 8317c478bd9Sstevel@tonic-gate 8327c478bd9Sstevel@tonic-gate /* 8337c478bd9Sstevel@tonic-gate * This function is called whenever the memory size, as represented 8347c478bd9Sstevel@tonic-gate * by the phys_install list, changes. 8357c478bd9Sstevel@tonic-gate */ 8367c478bd9Sstevel@tonic-gate void 8377c478bd9Sstevel@tonic-gate dump_resize() 8387c478bd9Sstevel@tonic-gate { 8397c478bd9Sstevel@tonic-gate mutex_enter(&dump_lock); 8407c478bd9Sstevel@tonic-gate dumphdr_init(); 8417c478bd9Sstevel@tonic-gate dumpbuf_resize(); 8427c478bd9Sstevel@tonic-gate mutex_exit(&dump_lock); 8437c478bd9Sstevel@tonic-gate } 844e7cbe64fSgw25295 845e7cbe64fSgw25295 /* 846e7cbe64fSgw25295 * This function allows for dynamic resizing of a dump area. It assumes that 847e7cbe64fSgw25295 * the underlying device has update its appropriate size(9P). 848e7cbe64fSgw25295 */ 849e7cbe64fSgw25295 int 850e7cbe64fSgw25295 dumpvp_resize() 851e7cbe64fSgw25295 { 852e7cbe64fSgw25295 int error; 853e7cbe64fSgw25295 vattr_t vattr; 854e7cbe64fSgw25295 855e7cbe64fSgw25295 mutex_enter(&dump_lock); 856e7cbe64fSgw25295 vattr.va_mask = AT_SIZE; 857e7cbe64fSgw25295 if ((error = VOP_GETATTR(dumpvp, &vattr, 0, kcred, NULL)) != 0) { 858e7cbe64fSgw25295 mutex_exit(&dump_lock); 859e7cbe64fSgw25295 return (error); 860e7cbe64fSgw25295 } 861e7cbe64fSgw25295 862e7cbe64fSgw25295 if (error == 0 && vattr.va_size < 2 * DUMP_LOGSIZE + DUMP_ERPTSIZE) { 863e7cbe64fSgw25295 mutex_exit(&dump_lock); 864e7cbe64fSgw25295 return (ENOSPC); 865e7cbe64fSgw25295 } 866e7cbe64fSgw25295 867e7cbe64fSgw25295 dumpvp_size = vattr.va_size & -DUMP_OFFSET; 868e7cbe64fSgw25295 mutex_exit(&dump_lock); 869e7cbe64fSgw25295 return (0); 870e7cbe64fSgw25295 } 871