xref: /openbmc/qemu/include/sysemu/dump.h (revision 701bff24)
1 /*
2  * QEMU dump
3  *
4  * Copyright Fujitsu, Corp. 2011, 2012
5  *
6  * Authors:
7  *     Wen Congyang <wency@cn.fujitsu.com>
8  *
9  * This work is licensed under the terms of the GNU GPL, version 2 or later.
10  * See the COPYING file in the top-level directory.
11  *
12  */
13 
14 #ifndef DUMP_H
15 #define DUMP_H
16 
17 #include "qapi/qapi-types-dump.h"
18 
19 #define MAKEDUMPFILE_SIGNATURE      "makedumpfile"
20 #define MAX_SIZE_MDF_HEADER         (4096) /* max size of makedumpfile_header */
21 #define TYPE_FLAT_HEADER            (1)    /* type of flattened format */
22 #define VERSION_FLAT_HEADER         (1)    /* version of flattened format */
23 #define END_FLAG_FLAT_HEADER        (-1)
24 
25 #ifndef ARCH_PFN_OFFSET
26 #define ARCH_PFN_OFFSET             (0)
27 #endif
28 
29 /*
30  * flag for compressed format
31  */
32 #define DUMP_DH_COMPRESSED_ZLIB     (0x1)
33 #define DUMP_DH_COMPRESSED_LZO      (0x2)
34 #define DUMP_DH_COMPRESSED_SNAPPY   (0x4)
35 
36 #define KDUMP_SIGNATURE             "KDUMP   "
37 #define SIG_LEN                     (sizeof(KDUMP_SIGNATURE) - 1)
38 #define DUMP_LEVEL                  (1)
39 #define DISKDUMP_HEADER_BLOCKS      (1)
40 
41 #include "sysemu/dump-arch.h"
42 #include "sysemu/memory_mapping.h"
43 
44 typedef struct QEMU_PACKED MakedumpfileHeader {
45     char signature[16];     /* = "makedumpfile" */
46     int64_t type;
47     int64_t version;
48 } MakedumpfileHeader;
49 
50 typedef struct QEMU_PACKED MakedumpfileDataHeader {
51     int64_t offset;
52     int64_t buf_size;
53 } MakedumpfileDataHeader;
54 
55 typedef struct QEMU_PACKED NewUtsname {
56     char sysname[65];
57     char nodename[65];
58     char release[65];
59     char version[65];
60     char machine[65];
61     char domainname[65];
62 } NewUtsname;
63 
64 typedef struct QEMU_PACKED DiskDumpHeader32 {
65     char signature[SIG_LEN];        /* = "KDUMP   " */
66     uint32_t header_version;        /* Dump header version */
67     NewUtsname utsname;             /* copy of system_utsname */
68     char timestamp[10];             /* Time stamp */
69     uint32_t status;                /* Above flags */
70     uint32_t block_size;            /* Size of a block in byte */
71     uint32_t sub_hdr_size;          /* Size of arch dependent header in block */
72     uint32_t bitmap_blocks;         /* Size of Memory bitmap in block */
73     uint32_t max_mapnr;             /* = max_mapnr ,
74                                        obsoleted in header_version 6 */
75     uint32_t total_ram_blocks;      /* Number of blocks should be written */
76     uint32_t device_blocks;         /* Number of total blocks in dump device */
77     uint32_t written_blocks;        /* Number of written blocks */
78     uint32_t current_cpu;           /* CPU# which handles dump */
79     uint32_t nr_cpus;               /* Number of CPUs */
80 } DiskDumpHeader32;
81 
82 typedef struct QEMU_PACKED DiskDumpHeader64 {
83     char signature[SIG_LEN];        /* = "KDUMP   " */
84     uint32_t header_version;        /* Dump header version */
85     NewUtsname utsname;             /* copy of system_utsname */
86     char timestamp[22];             /* Time stamp */
87     uint32_t status;                /* Above flags */
88     uint32_t block_size;            /* Size of a block in byte */
89     uint32_t sub_hdr_size;          /* Size of arch dependent header in block */
90     uint32_t bitmap_blocks;         /* Size of Memory bitmap in block */
91     uint32_t max_mapnr;             /* = max_mapnr,
92                                        obsoleted in header_version 6 */
93     uint32_t total_ram_blocks;      /* Number of blocks should be written */
94     uint32_t device_blocks;         /* Number of total blocks in dump device */
95     uint32_t written_blocks;        /* Number of written blocks */
96     uint32_t current_cpu;           /* CPU# which handles dump */
97     uint32_t nr_cpus;               /* Number of CPUs */
98 } DiskDumpHeader64;
99 
100 typedef struct QEMU_PACKED KdumpSubHeader32 {
101     uint32_t phys_base;
102     uint32_t dump_level;            /* header_version 1 and later */
103     uint32_t split;                 /* header_version 2 and later */
104     uint32_t start_pfn;             /* header_version 2 and later,
105                                        obsoleted in header_version 6 */
106     uint32_t end_pfn;               /* header_version 2 and later,
107                                        obsoleted in header_version 6 */
108     uint64_t offset_vmcoreinfo;     /* header_version 3 and later */
109     uint32_t size_vmcoreinfo;       /* header_version 3 and later */
110     uint64_t offset_note;           /* header_version 4 and later */
111     uint32_t note_size;             /* header_version 4 and later */
112     uint64_t offset_eraseinfo;      /* header_version 5 and later */
113     uint32_t size_eraseinfo;        /* header_version 5 and later */
114     uint64_t start_pfn_64;          /* header_version 6 and later */
115     uint64_t end_pfn_64;            /* header_version 6 and later */
116     uint64_t max_mapnr_64;          /* header_version 6 and later */
117 } KdumpSubHeader32;
118 
119 typedef struct QEMU_PACKED KdumpSubHeader64 {
120     uint64_t phys_base;
121     uint32_t dump_level;            /* header_version 1 and later */
122     uint32_t split;                 /* header_version 2 and later */
123     uint64_t start_pfn;             /* header_version 2 and later,
124                                        obsoleted in header_version 6 */
125     uint64_t end_pfn;               /* header_version 2 and later,
126                                        obsoleted in header_version 6 */
127     uint64_t offset_vmcoreinfo;     /* header_version 3 and later */
128     uint64_t size_vmcoreinfo;       /* header_version 3 and later */
129     uint64_t offset_note;           /* header_version 4 and later */
130     uint64_t note_size;             /* header_version 4 and later */
131     uint64_t offset_eraseinfo;      /* header_version 5 and later */
132     uint64_t size_eraseinfo;        /* header_version 5 and later */
133     uint64_t start_pfn_64;          /* header_version 6 and later */
134     uint64_t end_pfn_64;            /* header_version 6 and later */
135     uint64_t max_mapnr_64;          /* header_version 6 and later */
136 } KdumpSubHeader64;
137 
138 typedef struct DataCache {
139     int fd;             /* fd of the file where to write the cached data */
140     uint8_t *buf;       /* buffer for cached data */
141     size_t buf_size;    /* size of the buf */
142     size_t data_size;   /* size of cached data in buf */
143     off_t offset;       /* offset of the file */
144 } DataCache;
145 
146 typedef struct QEMU_PACKED PageDescriptor {
147     uint64_t offset;                /* the offset of the page data*/
148     uint32_t size;                  /* the size of this dump page */
149     uint32_t flags;                 /* flags */
150     uint64_t page_flags;            /* page flags */
151 } PageDescriptor;
152 
153 typedef struct DumpState {
154     GuestPhysBlockList guest_phys_blocks;
155     ArchDumpInfo dump_info;
156     MemoryMappingList list;
157     uint32_t phdr_num;
158     uint32_t shdr_num;
159     bool resume;
160     bool detached;
161     ssize_t note_size;
162     hwaddr shdr_offset;
163     hwaddr phdr_offset;
164     hwaddr section_offset;
165     hwaddr note_offset;
166     hwaddr memory_offset;
167     int fd;
168 
169     /*
170      * Dump filter area variables
171      *
172      * A filtered dump only contains the guest memory designated by
173      * the start address and length variables defined below.
174      *
175      * If length is 0, no filtering is applied.
176      */
177     int64_t filter_area_begin;  /* Start address of partial guest memory area */
178     int64_t filter_area_length; /* Length of partial guest memory area */
179 
180     uint8_t *note_buf;          /* buffer for notes */
181     size_t note_buf_offset;     /* the writing place in note_buf */
182     uint32_t nr_cpus;           /* number of guest's cpu */
183     uint64_t max_mapnr;         /* the biggest guest's phys-mem's number */
184     size_t len_dump_bitmap;     /* the size of the place used to store
185                                    dump_bitmap in vmcore */
186     off_t offset_dump_bitmap;   /* offset of dump_bitmap part in vmcore */
187     off_t offset_page;          /* offset of page part in vmcore */
188     size_t num_dumpable;        /* number of page that can be dumped */
189     uint32_t flag_compress;     /* indicate the compression format */
190     DumpStatus status;          /* current dump status */
191 
192     bool has_format;              /* whether format is provided */
193     DumpGuestMemoryFormat format; /* valid only if has_format == true */
194     QemuThread dump_thread;       /* thread for detached dump */
195 
196     int64_t total_size;          /* total memory size (in bytes) to
197                                   * be dumped. When filter is
198                                   * enabled, this will only count
199                                   * those to be written. */
200     int64_t written_size;        /* written memory size (in bytes),
201                                   * this could be used to calculate
202                                   * how much work we have
203                                   * finished. */
204     uint8_t *guest_note;         /* ELF note content */
205     size_t guest_note_size;
206 } DumpState;
207 
208 uint16_t cpu_to_dump16(DumpState *s, uint16_t val);
209 uint32_t cpu_to_dump32(DumpState *s, uint32_t val);
210 uint64_t cpu_to_dump64(DumpState *s, uint64_t val);
211 #endif
212