xref: /openbmc/qemu/include/sysemu/dump.h (revision 8466405e)
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     bool resume;
158     bool detached;
159     hwaddr memory_offset;
160     int fd;
161 
162     /*
163      * Dump filter area variables
164      *
165      * A filtered dump only contains the guest memory designated by
166      * the start address and length variables defined below.
167      *
168      * If length is 0, no filtering is applied.
169      */
170     int64_t filter_area_begin;  /* Start address of partial guest memory area */
171     int64_t filter_area_length; /* Length of partial guest memory area */
172 
173     /* Elf dump related data */
174     uint32_t phdr_num;
175     uint32_t shdr_num;
176     ssize_t note_size;
177     hwaddr shdr_offset;
178     hwaddr phdr_offset;
179     hwaddr section_offset;
180     hwaddr note_offset;
181 
182     void *elf_section_hdrs;     /* Pointer to section header buffer */
183     void *elf_section_data;     /* Pointer to section data buffer */
184     uint64_t elf_section_data_size; /* Size of section data */
185     GArray *string_table_buf;   /* String table data buffer */
186 
187     uint8_t *note_buf;          /* buffer for notes */
188     size_t note_buf_offset;     /* the writing place in note_buf */
189     uint32_t nr_cpus;           /* number of guest's cpu */
190     uint64_t max_mapnr;         /* the biggest guest's phys-mem's number */
191     size_t len_dump_bitmap;     /* the size of the place used to store
192                                    dump_bitmap in vmcore */
193     off_t offset_dump_bitmap;   /* offset of dump_bitmap part in vmcore */
194     off_t offset_page;          /* offset of page part in vmcore */
195     size_t num_dumpable;        /* number of page that can be dumped */
196     uint32_t flag_compress;     /* indicate the compression format */
197     DumpStatus status;          /* current dump status */
198 
199     bool has_format;              /* whether format is provided */
200     DumpGuestMemoryFormat format; /* valid only if has_format == true */
201     QemuThread dump_thread;       /* thread for detached dump */
202 
203     int64_t total_size;          /* total memory size (in bytes) to
204                                   * be dumped. When filter is
205                                   * enabled, this will only count
206                                   * those to be written. */
207     int64_t written_size;        /* written memory size (in bytes),
208                                   * this could be used to calculate
209                                   * how much work we have
210                                   * finished. */
211     uint8_t *guest_note;         /* ELF note content */
212     size_t guest_note_size;
213 } DumpState;
214 
215 uint16_t cpu_to_dump16(DumpState *s, uint16_t val);
216 uint32_t cpu_to_dump32(DumpState *s, uint32_t val);
217 uint64_t cpu_to_dump64(DumpState *s, uint64_t val);
218 
219 int64_t dump_filtered_memblock_size(GuestPhysBlock *block, int64_t filter_area_start,
220                                     int64_t filter_area_length);
221 int64_t dump_filtered_memblock_start(GuestPhysBlock *block, int64_t filter_area_start,
222                                      int64_t filter_area_length);
223 #endif
224