1 /*
   2  * CDDL HEADER START
   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved.
  23  * Copyright 2018 Nexenta Systems, Inc. All rights reserved.
  24  * Copyright (c) 2016 by Delphix. All rights reserved.
  25  */
  26 
  27 #ifndef _SYS_DUMPHDR_H
  28 #define _SYS_DUMPHDR_H
  29 
  30 #include <sys/types.h>
  31 #include <sys/param.h>
  32 #include <sys/utsname.h>
  33 #include <sys/log.h>
  34 
  35 #ifdef  __cplusplus
  36 extern "C" {
  37 #endif
  38 
  39 /*
  40  * The dump header describes the contents of a crash dump.  Two headers
  41  * are written out: one at the beginning of the dump, and the other at
  42  * the very end of the dump device.  The terminal header is at a known
  43  * location (end of device) so we can always find it.  The initial header
  44  * is redundant, but helps savecore(1M) determine whether the dump has been
  45  * overwritten by swap activity.  See dumpadm(1M) for dump configuration.
  46  */
  47 #define DUMP_MAGIC      0xdefec8edU             /* dump magic number */
  48 #define DUMP_VERSION    10                      /* version of this dumphdr */
  49 #define DUMP_WORDSIZE   (sizeof (long) * NBBY)  /* word size (32 or 64) */
  50 #define DUMP_PANICSIZE  200                     /* Max panic string copied */
  51 #define DUMP_COMPRESS_RATIO     2               /* conservative; usually 2.5+ */
  52 #define DUMP_OFFSET     65536                   /* pad at start/end of dev */
  53 #define DUMP_LOGSIZE    (2 * LOG_HIWAT)         /* /dev/log message save area */
  54 #define DUMP_ERPTSIZE   (P2ROUNDUP(     \
  55         (ERPT_DATA_SZ / 2) *            \
  56         (ERPT_EVCH_MAX +                \
  57         ERPT_MAX_ERRS * ERPT_HIWAT),    \
  58         DUMP_OFFSET))                           /* ereport save area */
  59 #define DUMP_SUMMARYSIZE (P2ROUNDUP(    \
  60         (STACK_BUF_SIZE +              \
  61         sizeof (summary_dump_t) + 1024), \
  62         DUMP_OFFSET))                           /* summary save area */
  63 
  64 typedef struct dumphdr {
  65         uint32_t dump_magic;            /* magic number */
  66         uint32_t dump_version;          /* version number */
  67         uint32_t dump_flags;            /* flags; see below */
  68         uint32_t dump_wordsize;         /* 32 or 64 */
  69         offset_t dump_start;            /* starting offset on dump device */
  70         offset_t dump_ksyms;            /* offset of compressed symbol table */
  71         offset_t dump_pfn;              /* offset of pfn table for all pages */
  72         offset_t dump_map;              /* offset of page translation map */
  73         offset_t dump_data;             /* offset of actual dump data */
  74         struct utsname dump_utsname;    /* copy of utsname structure */
  75         char    dump_platform[SYS_NMLN]; /* platform name (uname -i) */
  76         char    dump_panicstring[DUMP_PANICSIZE]; /* copy of panicstr */
  77         time_t  dump_crashtime;         /* time of crash */
  78         long    dump_pageshift;         /* log2(pagesize) */
  79         long    dump_pagesize;          /* pagesize */
  80         long    dump_hashmask;          /* page translation hash mask */
  81         long    dump_nvtop;             /* number of vtop table entries */
  82         pgcnt_t dump_npages;            /* number of data pages */
  83         size_t  dump_ksyms_size;        /* kernel symbol table size */
  84         size_t  dump_ksyms_csize;       /* compressed symbol table size */
  85         uint32_t dump_fm_panic;         /* initiated from fm subsystems */
  86         char    dump_uuid[36 + 1];      /* os image uuid */
  87 } dumphdr_t;
  88 
  89 /*
  90  * Values for dump_flags
  91  */
  92 #define DF_VALID        0x00000001      /* Dump is valid (savecore clears) */
  93 #define DF_COMPLETE     0x00000002      /* All pages present as configured */
  94 #define DF_LIVE         0x00000004      /* Dump was taken on a live system */
  95 #define DF_COMPRESSED   0x00000008      /* Dump is compressed */
  96 #define DF_KERNEL       0x00010000      /* Contains kernel pages only */
  97 #define DF_ALL          0x00020000      /* Contains all pages */
  98 #define DF_CURPROC      0x00040000      /* Contains kernel + cur proc pages */
  99 #define DF_CONTENT      0xffff0000      /* The set of all dump content flags */
 100 
 101 /*
 102  * Dump translation map hash table entry.
 103  */
 104 typedef struct dump_map {
 105         offset_t        dm_first;
 106         offset_t        dm_next;
 107         offset_t        dm_data;
 108         struct as       *dm_as;
 109         uintptr_t       dm_va;
 110 } dump_map_t;
 111 
 112 /*
 113  * Dump translation map hash function.
 114  */
 115 #define DUMP_HASH(dhp, as, va)  \
 116         ((((uintptr_t)(as) >> 3) + ((va) >> (dhp)->dump_pageshift)) & \
 117         (dhp)->dump_hashmask)
 118 
 119 /*
 120  * Encoding of the csize word used to provide meta information
 121  * between dumpsys and savecore.
 122  *
 123  *      tag     size
 124  *      1-4095  1..dump_maxcsize        stream block
 125  *      0       1..pagesize             one lzjb page
 126  *      0       0                       marks end of data
 127  */
 128 typedef uint32_t dumpcsize_t;
 129 
 130 #define DUMP_MAX_TAG            (0xfffU)
 131 #define DUMP_MAX_CSIZE          (0xfffffU)
 132 #define DUMP_SET_TAG(w, v)      (((w) & DUMP_MAX_CSIZE) | ((v) << 20))
 133 #define DUMP_GET_TAG(w)         (((w) >> 20) & DUMP_MAX_TAG)
 134 #define DUMP_SET_CSIZE(w, v)    \
 135         (((w) & (DUMP_MAX_TAG << 20)) | ((v) & DUMP_MAX_CSIZE))
 136 #define DUMP_GET_CSIZE(w)       ((w) & DUMP_MAX_CSIZE)
 137 
 138 typedef struct dumpstreamhdr {
 139         char            stream_magic[8];        /* "StrmHdr" */
 140         pgcnt_t         stream_pagenum;         /* starting pfn */
 141         pgcnt_t         stream_npages;          /* uncompressed size */
 142 } dumpstreamhdr_t;
 143 
 144 #define DUMP_STREAM_MAGIC       "StrmHdr"
 145 
 146 /* The number of helpers is limited by the number of stream tags. */
 147 #define DUMP_MAX_NHELPER        DUMP_MAX_TAG
 148 
 149 /*
 150  * The dump data header is placed after the dumphdr in the compressed
 151  * image. It is not needed after savecore runs and the data pages have
 152  * been decompressed.
 153  */
 154 typedef struct dumpdatahdr {
 155         uint32_t dump_datahdr_magic;    /* data header presence */
 156         uint32_t dump_datahdr_version;  /* data header version */
 157         uint64_t dump_data_csize;       /* compressed data size */
 158         uint32_t dump_maxcsize;         /* compressed data max block size */
 159         uint32_t dump_maxrange;         /* max number of pages per range */
 160         uint16_t dump_nstreams;         /* number of compression streams */
 161         uint16_t dump_clevel;           /* compression level (0-9) */
 162         uint32_t dump_metrics;          /* size of metrics data */
 163 } dumpdatahdr_t;
 164 
 165 #define DUMP_DATAHDR_MAGIC      ('d' << 24 | 'h' << 16 | 'd' << 8 | 'r')
 166 
 167 #define DUMP_DATAHDR_VERSION    1
 168 #define DUMP_CLEVEL_SERIAL      0       /* single-threaded lzjb compression */
 169 #define DUMP_CLEVEL_LZJB        1       /* parallel lzjb compression */
 170 
 171 #ifdef _KERNEL
 172 
 173 extern kmutex_t dump_lock;
 174 extern struct vnode *dumpvp;
 175 extern u_offset_t dumpvp_size;
 176 extern struct dumphdr *dumphdr;
 177 extern int dump_conflags;
 178 extern char *dumppath;
 179 
 180 extern int dump_timeout;
 181 extern int dump_timeleft;
 182 extern int dump_ioerr;
 183 
 184 extern int dumpinit(struct vnode *, char *, int);
 185 extern void dumpfini(void);
 186 extern void dump_resize(void);
 187 extern void dump_page(pfn_t);
 188 extern void dump_addpage(struct as *, void *, pfn_t);
 189 extern void dumpsys(void);
 190 extern void dumpsys_helper(void);
 191 extern void dumpsys_helper_nw(void);
 192 extern void dump_messages(void);
 193 extern void dump_ereports(void);
 194 extern void dumpvp_write(const void *, size_t);
 195 extern int dumpvp_resize(void);
 196 extern int dump_plat_addr(void);
 197 extern void dump_plat_pfn(void);
 198 extern int dump_plat_data(void *);
 199 extern int dump_set_uuid(const char *);
 200 extern const char *dump_get_uuid(void);
 201 
 202 /*
 203  * Pages may be stolen at dump time. Prevent the pages from ever being
 204  * allocated while dump is running.
 205  */
 206 #define IS_DUMP_PAGE(pp) (dump_check_used && dump_test_used((pp)->p_pagenum))
 207 
 208 extern int dump_test_used(pfn_t);
 209 extern int dump_check_used;
 210 
 211 #endif /* _KERNEL */
 212 
 213 #ifdef  __cplusplus
 214 }
 215 #endif
 216 
 217 #endif  /* _SYS_DUMPHDR_H */