xref: /openbmc/qemu/include/sysemu/dump.h (revision 520e210c)
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-misc.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     uint16_t phdr_num;
158     uint32_t sh_info;
159     bool have_section;
160     bool resume;
161     bool detached;
162     ssize_t note_size;
163     hwaddr memory_offset;
164     int fd;
165 
166     GuestPhysBlock *next_block;
167     ram_addr_t start;
168     bool has_filter;
169     int64_t begin;
170     int64_t length;
171 
172     uint8_t *note_buf;          /* buffer for notes */
173     size_t note_buf_offset;     /* the writing place in note_buf */
174     uint32_t nr_cpus;           /* number of guest's cpu */
175     uint64_t max_mapnr;         /* the biggest guest's phys-mem's number */
176     size_t len_dump_bitmap;     /* the size of the place used to store
177                                    dump_bitmap in vmcore */
178     off_t offset_dump_bitmap;   /* offset of dump_bitmap part in vmcore */
179     off_t offset_page;          /* offset of page part in vmcore */
180     size_t num_dumpable;        /* number of page that can be dumped */
181     uint32_t flag_compress;     /* indicate the compression format */
182     DumpStatus status;          /* current dump status */
183 
184     bool has_format;              /* whether format is provided */
185     DumpGuestMemoryFormat format; /* valid only if has_format == true */
186     QemuThread dump_thread;       /* thread for detached dump */
187 
188     int64_t total_size;          /* total memory size (in bytes) to
189                                   * be dumped. When filter is
190                                   * enabled, this will only count
191                                   * those to be written. */
192     int64_t written_size;        /* written memory size (in bytes),
193                                   * this could be used to calculate
194                                   * how much work we have
195                                   * finished. */
196     uint8_t *guest_note;         /* ELF note content */
197     size_t guest_note_size;
198 } DumpState;
199 
200 uint16_t cpu_to_dump16(DumpState *s, uint16_t val);
201 uint32_t cpu_to_dump32(DumpState *s, uint32_t val);
202 uint64_t cpu_to_dump64(DumpState *s, uint64_t val);
203 #endif
204