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