dump: Make most of it target agnostic (build once)
v6 cover dump: Make most of it target agnostic (build once)
All series reviewed.
Since v5:
- reword one commit description (Thomas)
- drop CONFIG_SOFTMMU, unify softmmu_ss (Richard)
Since v4:
- more unused headers removed
- KISS, use a bit of #ifdef'ry to avoid a stub file
Thanks to Richard help, we can now build dump.o once for all targets, keeping win_dump.o for x86* targets.
Philippe Mathieu-Daudé (5):
dump: Replace tswapN() -> cpu_to_dumpN()
dump: Replace TARGET_PAGE_SIZE -> qemu_target_page_size()
dump: Clean included headers
dump: Simplify compiling win_dump.o by introducing
win_dump_available()
dump: Add create_win_dump() stub for non-x86 targets
dump/dump-hmp-cmds.c | 2 +- dump/dump.c | 35 +++++++++++++---------------------- dump/meson.build | 6 ++---- dump/win_dump.c | 38 ++++++++++++++++++++++++++++---------- dump/win_dump.h | 5 ++++- 5 files changed, 48 insertions(+), 38 deletions(-)
Signature · 1 line
2.38.1
PATCH v6 1/5 dump: Replace tswapN() -> cpu_to_dumpN()
All uses of tswap in that file are wrong, and should be using cpu_to_dumpN, which correctly tests the endianness of the output.
--- dump/dump.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
dump/dump.c +4 -4
@@ -907,13 +907,13 @@ static void get_note_sizes(DumpState *s, const void *note,if (dump_is_64bit (s)) {const Elf64_Nhdr *hdr = note; note_head_sz =sizeof (Elf64_Nhdr); - name_sz =tswap64 (hdr->n_namesz); - desc_sz =tswap64 (hdr->n_descsz); + name_sz =cpu_to_dump64 (s, hdr->n_namesz); + desc_sz =cpu_to_dump64 (s, hdr->n_descsz); }else {const Elf32_Nhdr *hdr = note; note_head_sz =sizeof (Elf32_Nhdr); - name_sz =tswap32 (hdr->n_namesz); - desc_sz =tswap32 (hdr->n_descsz); + name_sz =cpu_to_dump32 (s, hdr->n_namesz); + desc_sz =cpu_to_dump32 (s, hdr->n_descsz); }if (note_head_size) {
Signature · 1 line
2.38.1
PATCH v6 2/5 dump: Replace TARGET_PAGE_SIZE -> qemu_target_page_size()
In reply to Philippe Mathieu-DaudéTARGET_PAGE_SIZE is target specific. In preparation of making dump.c target-agnostic, replace the compile-time TARGET_PAGE_SIZE definition by runtime qemu_target_page_size().
--- dump/dump.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
dump/dump.c +2 -1
@@ -15,6 +15,7 @@#include "qemu/cutils.h" #include "elf.h" #include "exec/hwaddr.h" +#include "exec/target_page.h" #include "monitor/monitor.h" #include "sysemu/kvm.h" #include "sysemu/dump.h"
@@ -1860,7 +1861,7 @@ static void dump_init(DumpState *s, int fd, bool has_format, }if (!s->dump_info.page_size) { - s->dump_info.page_size =TARGET_PAGE_SIZE ; + s->dump_info.page_size =qemu_target_page_size (); } s->note_size = cpu_get_note_size(s->dump_info.d_class,
Signature · 1 line
2.38.1
PATCH v6 3/5 dump: Clean included headers
In reply to Philippe Mathieu-Daudé"qemu/win_dump_defs.h" is only required by win_dump.c, but win_dump.h requires "sysemu/dump.h" which declares the DumpState type. Remove various unused headers.
--- dump/dump-hmp-cmds.c | 2 +- dump/dump.c | 6 ++---- dump/win_dump.c | 15 +++++---------- dump/win_dump.h | 2 +- 4 files changed, 9 insertions(+), 16 deletions(-)
dump/dump-hmp-cmds.c +1 -1
@@ -1,5 +1,5 @@/* -* Human Monitor Interface commands +* Windows crashdump (Human Monitor Interface commands) * * This work is licensed under the terms of the GNU GPL, version 2 or later. * See the COPYING file in the top-level directory.
dump/dump.c +2 -4
@@ -14,22 +14,20 @@#include "qemu/osdep.h" #include "qemu/cutils.h" #include "elf.h" -#include "exec/hwaddr.h" +#include "qemu/bswap.h" #include "exec/target_page.h" #include "monitor/monitor.h" -#include "sysemu/kvm.h" #include "sysemu/dump.h" -#include "sysemu/memory_mapping.h" #include "sysemu/runstate.h" #include "sysemu/cpus.h" #include "qapi/error.h" #include "qapi/qapi-commands-dump.h" #include "qapi/qapi-events-dump.h" #include "qapi/qmp/qerror.h" -#include "qemu/error-report.h" #include "qemu/main-loop.h" #include "hw/misc/vmcoreinfo.h" #include "migration/blocker.h" +#include "hw/core/cpu.h" #ifdef TARGET_X86_64 #include "win_dump.h"
dump/win_dump.c +5 -10
@@ -1,5 +1,5 @@/* -* Windows crashdump +* Windows crashdump (target specific implementations) * * Copyright (c) 2018 Virtuozzo International GmbH *
@@ -9,19 +9,14 @@*/ #include "qemu/osdep.h" -#include "qemu/cutils.h" -#include "elf.h" -#include "exec/hwaddr.h" -#include "monitor/monitor.h" -#include "sysemu/kvm.h" #include "sysemu/dump.h" -#include "sysemu/memory_mapping.h" -#include "sysemu/cpus.h" #include "qapi/error.h" #include "qapi/qmp/qerror.h" -#include "qemu/error-report.h" -#include "hw/misc/vmcoreinfo.h" +#include "exec/cpu-defs.h" +#include "hw/core/cpu.h" +#include "qemu/win_dump_defs.h" #include "win_dump.h" +#include "cpu.h" static size_t win_dump_ptr_size (bool x64) {
dump/win_dump.h +1 -1
@@ -11,7 +11,7 @@#ifndef WIN_DUMP_H #define WIN_DUMP_H -#include "qemu/win_dump_defs.h" +#include "sysemu/dump.h" void create_win_dump (DumpState *s,Error **errp);
Signature · 1 line
2.38.1
PATCH v6 4/5 dump: Simplify compiling win_dump.o by introducing win_dump_available()
In reply to Philippe Mathieu-DaudéTo make dump.c less target dependent, move the TARGET_X86_64 #ifdef'ry from dump.c to win_dump.c (introducing a win_dump_available() method there). By doing so we can build win_dump.c on any target, and simplify the meson rule.
--- dump/dump.c | 16 +++++----------- dump/meson.build | 2 +- dump/win_dump.c | 18 ++++++++++++++++++ dump/win_dump.h | 3 +++ 4 files changed, 27 insertions(+), 12 deletions(-)
dump/dump.c +5 -11
@@ -28,10 +28,7 @@#include "hw/misc/vmcoreinfo.h" #include "migration/blocker.h" #include "hw/core/cpu.h" - -#ifdef TARGET_X86_64 #include "win_dump.h" -#endif #include <zlib.h> #ifdef CONFIG_LZO
@@ -2126,12 +2123,10 @@ void qmp_dump_guest_memory(bool paging, const char *file, }#endif -#ifndef TARGET_X86_64 -if (has_format && format ==DUMP_GUEST_MEMORY_FORMAT_WIN_DMP ) { -error_setg (errp,"Windows dump is only available for x86-64" ); +if (has_format && format ==DUMP_GUEST_MEMORY_FORMAT_WIN_DMP + && !win_dump_available (errp)) {return ; } -#endif #if !defined(WIN32 )if (strstart (file,"fd:" , &p)) {
@@ -2213,10 +2208,9 @@ DumpGuestMemoryCapability *qmp_query_dump_guest_memory_capability(Error **errp)QAPI_LIST_APPEND (tail,DUMP_GUEST_MEMORY_FORMAT_KDUMP_SNAPPY );#endif -/* Windows dump is available only if target is x86_64 */ -#ifdef TARGET_X86_64 -QAPI_LIST_APPEND (tail,DUMP_GUEST_MEMORY_FORMAT_WIN_DMP ); -#endif +if (win_dump_available (NULL )) { +QAPI_LIST_APPEND (tail,DUMP_GUEST_MEMORY_FORMAT_WIN_DMP ); + }return cap; }
dump/meson.build +1 -1
@@ -1,4 +1,4 @@ softmmu_ss.add(files('dump-hmp-cmds.c')) specific_ss.add(when: 'CONFIG_SOFTMMU', if_true: [files('dump.c'), snappy, lzo]) -specific_ss.add(when: ['CONFIG_SOFTMMU', 'TARGET_X86_64'], if_true: files('win_dump.c')) +specific_ss.add(when: 'CONFIG_SOFTMMU', if_true: files('win_dump.c'))
dump/win_dump.c +18 -0
@@ -18,6 +18,13 @@#include "win_dump.h" #include "cpu.h" +#if defined(TARGET_X86_64 ) + +bool win_dump_available (Error **errp) +{ +return true; +} +static size_t win_dump_ptr_size (bool x64) {return x64 ?sizeof (uint64_t ) :sizeof (uint32_t );
@@ -470,3 +477,14 @@ out_cr3: return; } + +#else /* !TARGET_X86_64 */ + +bool win_dump_available (Error **errp) +{ +error_setg (errp,"Windows dump is only available for x86-64" ); + +return false; +} + +#endif
dump/win_dump.h +3 -0
@@ -13,6 +13,9 @@#include "sysemu/dump.h" +/* Check Windows dump availability for the current target */ +bool win_dump_available (Error **errp); +void create_win_dump (DumpState *s,Error **errp);#endif /* WIN_DUMP_H */
Signature · 1 line
2.38.1
PATCH v6 5/5 dump: Add create_win_dump() stub for non-x86 targets
In reply to Philippe Mathieu-DaudéImplement the non-x86 create_win_dump(). We can remove the last TARGET_X86_64 #ifdef'ry in dump.c, which thus becomes target-independent. Update meson accordingly.
--- dump/dump.c | 2 -- dump/meson.build | 4 +--- dump/win_dump.c | 5 +++++ 3 files changed, 6 insertions(+), 5 deletions(-)
dump/dump.c +0 -2
@@ -2018,9 +2018,7 @@ static void dump_process(DumpState *s, Error **errp)DumpQueryResult *result =NULL ;if (s->has_format && s->format ==DUMP_GUEST_MEMORY_FORMAT_WIN_DMP ) { -#ifdef TARGET_X86_64 create_win_dump (s, errp); -#endif }else if (s->has_format && s->format !=DUMP_GUEST_MEMORY_FORMAT_ELF ) {create_kdump_vmcore (s, errp); }else {
dump/meson.build +1 -3
@@ -1,4 +1,2 @@ -softmmu_ss.add(files('dump-hmp-cmds.c')) - -specific_ss.add(when: 'CONFIG_SOFTMMU', if_true: [files('dump.c'), snappy, lzo]) +softmmu_ss.add([files('dump.c', 'dump-hmp-cmds.c'), snappy, lzo]) specific_ss.add(when: 'CONFIG_SOFTMMU', if_true: files('win_dump.c'))
dump/win_dump.c +5 -0
@@ -487,4 +487,9 @@ bool win_dump_available(Error **errp) return false; } +void create_win_dump (DumpState *s,Error **errp) +{ +win_dump_available (errp); +} +#endif
Signature · 1 line
2.38.1
Quoted 21 lines · Philippe Mathieu-Daudé
All series reviewed.
Since v5:
- reword one commit description (Thomas)
- dropCONFIG_SOFTMMU, unifysoftmmu_ss(Richard)Since v4:
- more unused headers removed
- KISS, use a bit of #ifdef'ry to avoid a stub fileThanks to Richard help, we can now build dump.o once for all targets, keeping win_dump.o for x86* targets.
Philippe Mathieu-Daudé (5):
dump: ReplacetswapN()->cpu_to_dumpN()
dump: ReplaceTARGET_PAGE_SIZE->qemu_target_page_size()
dump: Clean included headers
dump: Simplify compiling win_dump.o by introducing
win_dump_available()
dump: Addcreate_win_dump()stub for non-x86 targets
Quoted 8 lines
dump/dump-hmp-cmds.c | 2 +- dump/dump.c | 35 +++++++++++++---------------------- dump/meson.build | 6 ++---- dump/win_dump.c | 38 ++++++++++++++++++++++++++++---------- dump/win_dump.h | 5 ++++- 5 files changed, 48 insertions(+), 38 deletions(-)
Quoted 10 lines · Marc-André Lureau
Philippe Mathieu-Daudé (5):
dump: ReplacetswapN()->cpu_to_dumpN()
dump: ReplaceTARGET_PAGE_SIZE->qemu_target_page_size()
dump: Clean included headers
dump: Simplify compiling win_dump.o by introducingwin_dump_available()
dump: Addcreate_win_dump()stub for non-x86 targetsReviewed-by Marc-André Lureau <[email protected] <mailto:[email protected]>>
Thanks, I'm going to queue this series with various qdev cleanups.