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