xref: /titanic_41/usr/src/uts/common/sys/dumphdr.h (revision c523716a48d6b0db35a7fb7d5f677687f18a448f)
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	10			/* 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 #define	DUMP_SUMMARYSIZE (P2ROUNDUP(    \
58 	(STACK_BUF_SIZE +	       \
59 	sizeof (summary_dump_t) + 1024), \
60 	DUMP_OFFSET))				/* summary save area */
61 
62 typedef struct dumphdr {
63 	uint32_t dump_magic;		/* magic number */
64 	uint32_t dump_version;		/* version number */
65 	uint32_t dump_flags;		/* flags; see below */
66 	uint32_t dump_wordsize;		/* 32 or 64 */
67 	offset_t dump_start;		/* starting offset on dump device */
68 	offset_t dump_ksyms;		/* offset of compressed symbol table */
69 	offset_t dump_pfn;		/* offset of pfn table for all pages */
70 	offset_t dump_map;		/* offset of page translation map */
71 	offset_t dump_data;		/* offset of actual dump data */
72 	struct utsname dump_utsname;	/* copy of utsname structure */
73 	char	dump_platform[SYS_NMLN]; /* platform name (uname -i) */
74 	char	dump_panicstring[DUMP_PANICSIZE]; /* copy of panicstr */
75 	time_t	dump_crashtime;		/* time of crash */
76 	long	dump_pageshift;		/* log2(pagesize) */
77 	long	dump_pagesize;		/* pagesize */
78 	long	dump_hashmask;		/* page translation hash mask */
79 	long	dump_nvtop;		/* number of vtop table entries */
80 	pgcnt_t	dump_npages;		/* number of data pages */
81 	size_t	dump_ksyms_size;	/* kernel symbol table size */
82 	size_t	dump_ksyms_csize;	/* compressed symbol table size */
83 	uint32_t dump_fm_panic;		/* initiated from fm subsystems */
84 	char	dump_uuid[36 + 1];	/* os image uuid */
85 } dumphdr_t;
86 
87 /*
88  * Values for dump_flags
89  */
90 #define	DF_VALID	0x00000001	/* Dump is valid (savecore clears) */
91 #define	DF_COMPLETE	0x00000002	/* All pages present as configured */
92 #define	DF_LIVE		0x00000004	/* Dump was taken on a live system */
93 #define	DF_COMPRESSED	0x00000008	/* Dump is compressed */
94 #define	DF_KERNEL	0x00010000	/* Contains kernel pages only */
95 #define	DF_ALL		0x00020000	/* Contains all pages */
96 #define	DF_CURPROC	0x00040000	/* Contains kernel + cur proc pages */
97 #define	DF_CONTENT	0xffff0000	/* The set of all dump content flags */
98 
99 /*
100  * Dump translation map hash table entry.
101  */
102 typedef struct dump_map {
103 	offset_t	dm_first;
104 	offset_t	dm_next;
105 	offset_t	dm_data;
106 	struct as	*dm_as;
107 	uintptr_t	dm_va;
108 } dump_map_t;
109 
110 /*
111  * Dump translation map hash function.
112  */
113 #define	DUMP_HASH(dhp, as, va)	\
114 	((((uintptr_t)(as) >> 3) + ((va) >> (dhp)->dump_pageshift)) & \
115 	(dhp)->dump_hashmask)
116 
117 /*
118  * Encoding of the csize word used to provide meta information
119  * between dumpsys and savecore.
120  *
121  *	tag	size
122  *	1-4095	1..dump_maxcsize	stream block
123  *	0	1..pagesize		one lzjb page
124  *	0	0			marks end of data
125  */
126 typedef uint32_t dumpcsize_t;
127 
128 #define	DUMP_MAX_TAG		(0xfffU)
129 #define	DUMP_MAX_CSIZE		(0xfffffU)
130 #define	DUMP_SET_TAG(w, v)	(((w) & DUMP_MAX_CSIZE) | ((v) << 20))
131 #define	DUMP_GET_TAG(w)		(((w) >> 20) & DUMP_MAX_TAG)
132 #define	DUMP_SET_CSIZE(w, v)	\
133 	(((w) & (DUMP_MAX_TAG << 20)) | ((v) & DUMP_MAX_CSIZE))
134 #define	DUMP_GET_CSIZE(w)	((w) & DUMP_MAX_CSIZE)
135 
136 typedef struct dumpstreamhdr {
137 	char		stream_magic[8];	/* "StrmHdr" */
138 	pgcnt_t		stream_pagenum;		/* starting pfn */
139 	pgcnt_t		stream_npages;		/* uncompressed size */
140 } dumpstreamhdr_t;
141 
142 #define	DUMP_STREAM_MAGIC	"StrmHdr"
143 
144 /* The number of helpers is limited by the number of stream tags. */
145 #define	DUMP_MAX_NHELPER	DUMP_MAX_TAG
146 
147 /*
148  * The dump data header is placed after the dumphdr in the compressed
149  * image. It is not needed after savecore runs and the data pages have
150  * been decompressed.
151  */
152 typedef struct dumpdatahdr {
153 	uint32_t dump_datahdr_magic;	/* data header presence */
154 	uint32_t dump_datahdr_version;	/* data header version */
155 	uint64_t dump_data_csize;	/* compressed data size */
156 	uint32_t dump_maxcsize;		/* compressed data max block size */
157 	uint32_t dump_maxrange;		/* max number of pages per range */
158 	uint16_t dump_nstreams;		/* number of compression streams */
159 	uint16_t dump_clevel;		/* compression level (0-9) */
160 	uint32_t dump_metrics;		/* size of metrics data */
161 } dumpdatahdr_t;
162 
163 #define	DUMP_DATAHDR_MAGIC	('d' << 24 | 'h' << 16 | 'd' << 8 | 'r')
164 
165 #define	DUMP_DATAHDR_VERSION	1
166 #define	DUMP_CLEVEL_LZJB	1	/* parallel lzjb compression */
167 #define	DUMP_CLEVEL_BZIP2	2	/* parallel bzip2 level 1 */
168 
169 #ifdef _KERNEL
170 
171 extern kmutex_t dump_lock;
172 extern struct vnode *dumpvp;
173 extern u_offset_t dumpvp_size;
174 extern struct dumphdr *dumphdr;
175 extern int dump_conflags;
176 extern char *dumppath;
177 
178 extern int dump_timeout;
179 extern int dump_timeleft;
180 extern int dump_ioerr;
181 extern int sync_timeout;
182 extern int sync_timeleft;
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  * Define a CPU count threshold that determines when to employ
204  * bzip2. This value is defined per-platform.
205  */
206 extern uint_t dump_plat_mincpu_default;
207 
208 #define	DUMP_PLAT_SUN4U_MINCPU		0
209 #define	DUMP_PLAT_SUN4U_OPL_MINCPU	0
210 #define	DUMP_PLAT_SUN4V_MINCPU		0
211 #define	DUMP_PLAT_X86_64_MINCPU		0
212 #define	DUMP_PLAT_X86_32_MINCPU		0
213 
214 /*
215  * Override the per-platform default by setting this variable with
216  * /etc/system.  The value 0 disables parallelism, and the old format
217  * dump is produced.
218  */
219 extern uint_t dump_plat_mincpu;
220 
221 /*
222  * Pages may be stolen at dump time. Prevent the pages from ever being
223  * allocated while dump is running.
224  */
225 #define	IS_DUMP_PAGE(pp) (dump_check_used && dump_test_used((pp)->p_pagenum))
226 
227 extern int dump_test_used(pfn_t);
228 extern int dump_check_used;
229 
230 #endif /* _KERNEL */
231 
232 #ifdef	__cplusplus
233 }
234 #endif
235 
236 #endif	/* _SYS_DUMPHDR_H */
237