xref: /openbmc/qemu/include/sysemu/dump.h (revision 113d8f4e)
19c17d615SPaolo Bonzini /*
29c17d615SPaolo Bonzini  * QEMU dump
39c17d615SPaolo Bonzini  *
49c17d615SPaolo Bonzini  * Copyright Fujitsu, Corp. 2011, 2012
59c17d615SPaolo Bonzini  *
69c17d615SPaolo Bonzini  * Authors:
79c17d615SPaolo Bonzini  *     Wen Congyang <wency@cn.fujitsu.com>
89c17d615SPaolo Bonzini  *
99c17d615SPaolo Bonzini  * This work is licensed under the terms of the GNU GPL, version 2 or later.
109c17d615SPaolo Bonzini  * See the COPYING file in the top-level directory.
119c17d615SPaolo Bonzini  *
129c17d615SPaolo Bonzini  */
139c17d615SPaolo Bonzini 
149c17d615SPaolo Bonzini #ifndef DUMP_H
159c17d615SPaolo Bonzini #define DUMP_H
169c17d615SPaolo Bonzini 
17d06b747bSMarkus Armbruster #include "qapi/qapi-types-dump.h"
189af23989SMarkus Armbruster 
19fda05387Sqiaonuohan #define MAKEDUMPFILE_SIGNATURE      "makedumpfile"
20fda05387Sqiaonuohan #define MAX_SIZE_MDF_HEADER         (4096) /* max size of makedumpfile_header */
21fda05387Sqiaonuohan #define TYPE_FLAT_HEADER            (1)    /* type of flattened format */
22fda05387Sqiaonuohan #define VERSION_FLAT_HEADER         (1)    /* version of flattened format */
23fda05387Sqiaonuohan #define END_FLAG_FLAT_HEADER        (-1)
24fda05387Sqiaonuohan 
258161befdSAndrew Jones #ifndef ARCH_PFN_OFFSET
267aad248dSqiaonuohan #define ARCH_PFN_OFFSET             (0)
278161befdSAndrew Jones #endif
287aad248dSqiaonuohan 
29298f1168Sqiaonuohan /*
30298f1168Sqiaonuohan  * flag for compressed format
31298f1168Sqiaonuohan  */
32298f1168Sqiaonuohan #define DUMP_DH_COMPRESSED_ZLIB     (0x1)
33298f1168Sqiaonuohan #define DUMP_DH_COMPRESSED_LZO      (0x2)
34298f1168Sqiaonuohan #define DUMP_DH_COMPRESSED_SNAPPY   (0x4)
35298f1168Sqiaonuohan 
36298f1168Sqiaonuohan #define KDUMP_SIGNATURE             "KDUMP   "
37298f1168Sqiaonuohan #define SIG_LEN                     (sizeof(KDUMP_SIGNATURE) - 1)
38298f1168Sqiaonuohan #define DUMP_LEVEL                  (1)
39298f1168Sqiaonuohan #define DISKDUMP_HEADER_BLOCKS      (1)
40298f1168Sqiaonuohan 
41acb0ef58SBharata B Rao #include "sysemu/dump-arch.h"
42acb0ef58SBharata B Rao #include "sysemu/memory_mapping.h"
439c17d615SPaolo Bonzini 
44fda05387Sqiaonuohan typedef struct QEMU_PACKED MakedumpfileHeader {
45fda05387Sqiaonuohan     char signature[16];     /* = "makedumpfile" */
46fda05387Sqiaonuohan     int64_t type;
47fda05387Sqiaonuohan     int64_t version;
48fda05387Sqiaonuohan } MakedumpfileHeader;
49fda05387Sqiaonuohan 
50fda05387Sqiaonuohan typedef struct QEMU_PACKED MakedumpfileDataHeader {
51fda05387Sqiaonuohan     int64_t offset;
52fda05387Sqiaonuohan     int64_t buf_size;
53fda05387Sqiaonuohan } MakedumpfileDataHeader;
54fda05387Sqiaonuohan 
55298f1168Sqiaonuohan typedef struct QEMU_PACKED NewUtsname {
56298f1168Sqiaonuohan     char sysname[65];
57298f1168Sqiaonuohan     char nodename[65];
58298f1168Sqiaonuohan     char release[65];
59298f1168Sqiaonuohan     char version[65];
60298f1168Sqiaonuohan     char machine[65];
61298f1168Sqiaonuohan     char domainname[65];
62298f1168Sqiaonuohan } NewUtsname;
63298f1168Sqiaonuohan 
64298f1168Sqiaonuohan typedef struct QEMU_PACKED DiskDumpHeader32 {
65298f1168Sqiaonuohan     char signature[SIG_LEN];        /* = "KDUMP   " */
66298f1168Sqiaonuohan     uint32_t header_version;        /* Dump header version */
67298f1168Sqiaonuohan     NewUtsname utsname;             /* copy of system_utsname */
68298f1168Sqiaonuohan     char timestamp[10];             /* Time stamp */
69298f1168Sqiaonuohan     uint32_t status;                /* Above flags */
70298f1168Sqiaonuohan     uint32_t block_size;            /* Size of a block in byte */
71298f1168Sqiaonuohan     uint32_t sub_hdr_size;          /* Size of arch dependent header in block */
72298f1168Sqiaonuohan     uint32_t bitmap_blocks;         /* Size of Memory bitmap in block */
73298f1168Sqiaonuohan     uint32_t max_mapnr;             /* = max_mapnr ,
74298f1168Sqiaonuohan                                        obsoleted in header_version 6 */
75298f1168Sqiaonuohan     uint32_t total_ram_blocks;      /* Number of blocks should be written */
76298f1168Sqiaonuohan     uint32_t device_blocks;         /* Number of total blocks in dump device */
77298f1168Sqiaonuohan     uint32_t written_blocks;        /* Number of written blocks */
78298f1168Sqiaonuohan     uint32_t current_cpu;           /* CPU# which handles dump */
79298f1168Sqiaonuohan     uint32_t nr_cpus;               /* Number of CPUs */
80298f1168Sqiaonuohan } DiskDumpHeader32;
81298f1168Sqiaonuohan 
82298f1168Sqiaonuohan typedef struct QEMU_PACKED DiskDumpHeader64 {
83298f1168Sqiaonuohan     char signature[SIG_LEN];        /* = "KDUMP   " */
84298f1168Sqiaonuohan     uint32_t header_version;        /* Dump header version */
85298f1168Sqiaonuohan     NewUtsname utsname;             /* copy of system_utsname */
86298f1168Sqiaonuohan     char timestamp[22];             /* Time stamp */
87298f1168Sqiaonuohan     uint32_t status;                /* Above flags */
88298f1168Sqiaonuohan     uint32_t block_size;            /* Size of a block in byte */
89298f1168Sqiaonuohan     uint32_t sub_hdr_size;          /* Size of arch dependent header in block */
90298f1168Sqiaonuohan     uint32_t bitmap_blocks;         /* Size of Memory bitmap in block */
91298f1168Sqiaonuohan     uint32_t max_mapnr;             /* = max_mapnr,
92298f1168Sqiaonuohan                                        obsoleted in header_version 6 */
93298f1168Sqiaonuohan     uint32_t total_ram_blocks;      /* Number of blocks should be written */
94298f1168Sqiaonuohan     uint32_t device_blocks;         /* Number of total blocks in dump device */
95298f1168Sqiaonuohan     uint32_t written_blocks;        /* Number of written blocks */
96298f1168Sqiaonuohan     uint32_t current_cpu;           /* CPU# which handles dump */
97298f1168Sqiaonuohan     uint32_t nr_cpus;               /* Number of CPUs */
98298f1168Sqiaonuohan } DiskDumpHeader64;
99298f1168Sqiaonuohan 
100298f1168Sqiaonuohan typedef struct QEMU_PACKED KdumpSubHeader32 {
101298f1168Sqiaonuohan     uint32_t phys_base;
102298f1168Sqiaonuohan     uint32_t dump_level;            /* header_version 1 and later */
103298f1168Sqiaonuohan     uint32_t split;                 /* header_version 2 and later */
104298f1168Sqiaonuohan     uint32_t start_pfn;             /* header_version 2 and later,
105298f1168Sqiaonuohan                                        obsoleted in header_version 6 */
106298f1168Sqiaonuohan     uint32_t end_pfn;               /* header_version 2 and later,
107298f1168Sqiaonuohan                                        obsoleted in header_version 6 */
108298f1168Sqiaonuohan     uint64_t offset_vmcoreinfo;     /* header_version 3 and later */
109298f1168Sqiaonuohan     uint32_t size_vmcoreinfo;       /* header_version 3 and later */
110298f1168Sqiaonuohan     uint64_t offset_note;           /* header_version 4 and later */
111298f1168Sqiaonuohan     uint32_t note_size;             /* header_version 4 and later */
112298f1168Sqiaonuohan     uint64_t offset_eraseinfo;      /* header_version 5 and later */
113298f1168Sqiaonuohan     uint32_t size_eraseinfo;        /* header_version 5 and later */
114298f1168Sqiaonuohan     uint64_t start_pfn_64;          /* header_version 6 and later */
115298f1168Sqiaonuohan     uint64_t end_pfn_64;            /* header_version 6 and later */
116298f1168Sqiaonuohan     uint64_t max_mapnr_64;          /* header_version 6 and later */
117298f1168Sqiaonuohan } KdumpSubHeader32;
118298f1168Sqiaonuohan 
119298f1168Sqiaonuohan typedef struct QEMU_PACKED KdumpSubHeader64 {
120298f1168Sqiaonuohan     uint64_t phys_base;
121298f1168Sqiaonuohan     uint32_t dump_level;            /* header_version 1 and later */
122298f1168Sqiaonuohan     uint32_t split;                 /* header_version 2 and later */
123298f1168Sqiaonuohan     uint64_t start_pfn;             /* header_version 2 and later,
124298f1168Sqiaonuohan                                        obsoleted in header_version 6 */
125298f1168Sqiaonuohan     uint64_t end_pfn;               /* header_version 2 and later,
126298f1168Sqiaonuohan                                        obsoleted in header_version 6 */
127298f1168Sqiaonuohan     uint64_t offset_vmcoreinfo;     /* header_version 3 and later */
128298f1168Sqiaonuohan     uint64_t size_vmcoreinfo;       /* header_version 3 and later */
129298f1168Sqiaonuohan     uint64_t offset_note;           /* header_version 4 and later */
130298f1168Sqiaonuohan     uint64_t note_size;             /* header_version 4 and later */
131298f1168Sqiaonuohan     uint64_t offset_eraseinfo;      /* header_version 5 and later */
132298f1168Sqiaonuohan     uint64_t size_eraseinfo;        /* header_version 5 and later */
133298f1168Sqiaonuohan     uint64_t start_pfn_64;          /* header_version 6 and later */
134298f1168Sqiaonuohan     uint64_t end_pfn_64;            /* header_version 6 and later */
135298f1168Sqiaonuohan     uint64_t max_mapnr_64;          /* header_version 6 and later */
136298f1168Sqiaonuohan } KdumpSubHeader64;
137298f1168Sqiaonuohan 
13864cfba6aSqiaonuohan typedef struct DataCache {
13964cfba6aSqiaonuohan     int fd;             /* fd of the file where to write the cached data */
14064cfba6aSqiaonuohan     uint8_t *buf;       /* buffer for cached data */
14164cfba6aSqiaonuohan     size_t buf_size;    /* size of the buf */
14264cfba6aSqiaonuohan     size_t data_size;   /* size of cached data in buf */
14364cfba6aSqiaonuohan     off_t offset;       /* offset of the file */
14464cfba6aSqiaonuohan } DataCache;
14564cfba6aSqiaonuohan 
146d12f57ecSqiaonuohan typedef struct QEMU_PACKED PageDescriptor {
147d12f57ecSqiaonuohan     uint64_t offset;                /* the offset of the page data*/
148d12f57ecSqiaonuohan     uint32_t size;                  /* the size of this dump page */
149d12f57ecSqiaonuohan     uint32_t flags;                 /* flags */
150d12f57ecSqiaonuohan     uint64_t page_flags;            /* page flags */
151d12f57ecSqiaonuohan } PageDescriptor;
152d12f57ecSqiaonuohan 
153acb0ef58SBharata B Rao typedef struct DumpState {
154acb0ef58SBharata B Rao     GuestPhysBlockList guest_phys_blocks;
155acb0ef58SBharata B Rao     ArchDumpInfo dump_info;
156acb0ef58SBharata B Rao     MemoryMappingList list;
157acb0ef58SBharata B Rao     bool resume;
1586796b400SFam Zheng     bool detached;
159acb0ef58SBharata B Rao     hwaddr memory_offset;
160acb0ef58SBharata B Rao     int fd;
1619c17d615SPaolo Bonzini 
162dddf725fSJanosch Frank     /*
163dddf725fSJanosch Frank      * Dump filter area variables
164dddf725fSJanosch Frank      *
165dddf725fSJanosch Frank      * A filtered dump only contains the guest memory designated by
166dddf725fSJanosch Frank      * the start address and length variables defined below.
167dddf725fSJanosch Frank      *
168dddf725fSJanosch Frank      * If length is 0, no filtering is applied.
169dddf725fSJanosch Frank      */
170dddf725fSJanosch Frank     int64_t filter_area_begin;  /* Start address of partial guest memory area */
171dddf725fSJanosch Frank     int64_t filter_area_length; /* Length of partial guest memory area */
172acb0ef58SBharata B Rao 
1738384b73cSJanosch Frank     /* Elf dump related data */
1748384b73cSJanosch Frank     uint32_t phdr_num;
1758384b73cSJanosch Frank     uint32_t shdr_num;
1768384b73cSJanosch Frank     ssize_t note_size;
1778384b73cSJanosch Frank     hwaddr shdr_offset;
1788384b73cSJanosch Frank     hwaddr phdr_offset;
1798384b73cSJanosch Frank     hwaddr section_offset;
1808384b73cSJanosch Frank     hwaddr note_offset;
1818384b73cSJanosch Frank 
182e41ed29bSJanosch Frank     void *elf_section_hdrs;     /* Pointer to section header buffer */
1839b72224fSJanosch Frank     void *elf_section_data;     /* Pointer to section data buffer */
1849b72224fSJanosch Frank     uint64_t elf_section_data_size; /* Size of section data */
1859b72224fSJanosch Frank     GArray *string_table_buf;   /* String table data buffer */
186e41ed29bSJanosch Frank 
187acb0ef58SBharata B Rao     uint8_t *note_buf;          /* buffer for notes */
188acb0ef58SBharata B Rao     size_t note_buf_offset;     /* the writing place in note_buf */
189acb0ef58SBharata B Rao     uint32_t nr_cpus;           /* number of guest's cpu */
190acb0ef58SBharata B Rao     uint64_t max_mapnr;         /* the biggest guest's phys-mem's number */
191acb0ef58SBharata B Rao     size_t len_dump_bitmap;     /* the size of the place used to store
192acb0ef58SBharata B Rao                                    dump_bitmap in vmcore */
193acb0ef58SBharata B Rao     off_t offset_dump_bitmap;   /* offset of dump_bitmap part in vmcore */
194acb0ef58SBharata B Rao     off_t offset_page;          /* offset of page part in vmcore */
195acb0ef58SBharata B Rao     size_t num_dumpable;        /* number of page that can be dumped */
196acb0ef58SBharata B Rao     uint32_t flag_compress;     /* indicate the compression format */
197baf28f57SPeter Xu     DumpStatus status;          /* current dump status */
198ca1fc8c9SPeter Xu 
199ca1fc8c9SPeter Xu     bool has_format;              /* whether format is provided */
200ca1fc8c9SPeter Xu     DumpGuestMemoryFormat format; /* valid only if has_format == true */
2011fbeff72SPeter Xu     QemuThread dump_thread;       /* thread for detached dump */
2022264c2c9SPeter Xu 
2032264c2c9SPeter Xu     int64_t total_size;          /* total memory size (in bytes) to
2042264c2c9SPeter Xu                                   * be dumped. When filter is
2052264c2c9SPeter Xu                                   * enabled, this will only count
2062264c2c9SPeter Xu                                   * those to be written. */
2072264c2c9SPeter Xu     int64_t written_size;        /* written memory size (in bytes),
2082264c2c9SPeter Xu                                   * this could be used to calculate
2092264c2c9SPeter Xu                                   * how much work we have
2102264c2c9SPeter Xu                                   * finished. */
211903ef734SMarc-André Lureau     uint8_t *guest_note;         /* ELF note content */
212903ef734SMarc-André Lureau     size_t guest_note_size;
213acb0ef58SBharata B Rao } DumpState;
214acb0ef58SBharata B Rao 
215acb0ef58SBharata B Rao uint16_t cpu_to_dump16(DumpState *s, uint16_t val);
216acb0ef58SBharata B Rao uint32_t cpu_to_dump32(DumpState *s, uint32_t val);
217acb0ef58SBharata B Rao uint64_t cpu_to_dump64(DumpState *s, uint64_t val);
218*113d8f4eSJanosch Frank 
219*113d8f4eSJanosch Frank int64_t dump_filtered_memblock_size(GuestPhysBlock *block, int64_t filter_area_start,
220*113d8f4eSJanosch Frank                                     int64_t filter_area_length);
221*113d8f4eSJanosch Frank int64_t dump_filtered_memblock_start(GuestPhysBlock *block, int64_t filter_area_start,
222*113d8f4eSJanosch Frank                                      int64_t filter_area_length);
2239c17d615SPaolo Bonzini #endif
224