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