Now that all targets implement the get_dump_info sysemu op, we can replace the per-target cpu_get_dump_info() implementations (and its stub) with a single generic version in hw/core/cpu-system.c, taking the cpu as parameter, like other dump related sysemu ops wrappers.
We always check if there is at least one cpu available. For instance, machine null has no cpu present. Heterogeneous emulation is already handled by the check above which disable dump. Signed-off-by: Pierrick Bouvier <[email protected]> --- dump/dump.c | 6 +++--- hw/core/cpu-system.c | 9 +++++++++ include/hw/core/cpu.h | 11 +++++++++++ include/system/dump-arch.h | 3 --- stubs/dump.c | 6 ------ target/arm/arch_dump.c | 10 ---------- target/i386/arch_dump.c | 10 ---------- target/loongarch/arch_dump.c | 6 ------ target/ppc/arch_dump.c | 10 ---------- target/riscv/arch_dump.c | 10 ---------- target/s390x/arch_dump.c | 6 ------ 11 files changed, 23 insertions(+), 64 deletions(-) diff --git a/dump/dump.c b/dump/dump.c index 0ecff682dd4..60ecde02173 100644 --- a/dump/dump.c +++ b/dump/dump.c @@ -1793,7 +1793,6 @@ static void dump_init(DumpState *s, int fd, bool has_format, VMCoreInfoState *vmci = vmcoreinfo_find(); CPUState *cpu; int nr_cpus; - int ret; if (target_heterogeneous()) { error_setg(errp, @@ -1862,8 +1861,9 @@ static void dump_init(DumpState *s, int fd, bool has_format, * If the target architecture is not supported, cpu_get_dump_info() will * return -1. */ - ret = cpu_get_dump_info(&s->dump_info, &s->guest_phys_blocks); - if (ret < 0) { + if (!first_cpu || + cpu_get_dump_info(first_cpu, &s->dump_info, + &s->guest_phys_blocks) < 0) { error_setg(errp, "dumping guest memory is not supported on this target"); goto cleanup; diff --git a/hw/core/cpu-system.c b/hw/core/cpu-system.c index a64e8c2b687..499fad1c68a 100644 --- a/hw/core/cpu-system.c +++ b/hw/core/cpu-system.c @@ -130,6 +130,15 @@ int cpu_write_elf64_note(WriteCoreDumpFunction f, CPUState *cpu, return (*cpu->cc->sysemu_ops->write_elf64_note)(f, cpu, cpuid, opaque); } +int cpu_get_dump_info(const CPUState *cpu, ArchDumpInfo *info, + const GuestPhysBlockList *guest_phys_blocks) +{ + if (!cpu->cc->sysemu_ops->get_dump_info) { + return -1; + } + return cpu->cc->sysemu_ops->get_dump_info(cpu, info, guest_phys_blocks); +} + bool cpu_internal_is_big_endian(CPUState *cpu) { if (cpu->cc->sysemu_ops->internal_is_big_endian) { diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h index 456154df6f6..d80a6a4e752 100644 --- a/include/hw/core/cpu.h +++ b/include/hw/core/cpu.h @@ -701,6 +701,17 @@ int cpu_write_elf32_note(WriteCoreDumpFunction f, CPUState *cpu, int cpu_write_elf32_qemunote(WriteCoreDumpFunction f, CPUState *cpu, void *opaque); +/** + * cpu_get_dump_info: + * @cpu: The CPU whose dump information is to be obtained + * @info: Where to write endianness, class and architecture + * @guest_phys_blocks: guest physical memory blocks to be dumped + * + * Returns: 0 on success, -1 if guest memory can't be dumped. + */ +int cpu_get_dump_info(const CPUState *cpu, ArchDumpInfo *info, + const GuestPhysBlockList *guest_phys_blocks); + /** * cpu_memory_rw_debug: * @cpu: The CPU whose memory is to be accessed diff --git a/include/system/dump-arch.h b/include/system/dump-arch.h index 743916e46ca..b89e495661f 100644 --- a/include/system/dump-arch.h +++ b/include/system/dump-arch.h @@ -27,9 +27,6 @@ typedef struct ArchDumpInfo { void (*arch_cleanup_fn)(DumpState *s); } ArchDumpInfo; -struct GuestPhysBlockList; /* memory_mapping.h */ -int cpu_get_dump_info(ArchDumpInfo *info, - const struct GuestPhysBlockList *guest_phys_blocks); ssize_t cpu_get_note_size(int class, int machine, int nr_cpus); #endif diff --git a/stubs/dump.c b/stubs/dump.c index df7897b72b1..2ce3c5e274d 100644 --- a/stubs/dump.c +++ b/stubs/dump.c @@ -14,12 +14,6 @@ #include "qemu/osdep.h" #include "system/dump-arch.h" -int cpu_get_dump_info(ArchDumpInfo *info, - const struct GuestPhysBlockList *guest_phys_blocks) -{ - return -1; -} - ssize_t cpu_get_note_size(int class, int machine, int nr_cpus) { return -1; diff --git a/target/arm/arch_dump.c b/target/arm/arch_dump.c index 98eecf3d26d..181691b81c6 100644 --- a/target/arm/arch_dump.c +++ b/target/arm/arch_dump.c @@ -432,16 +432,6 @@ int arm_get_dump_info(const CPUState *cs, ArchDumpInfo *info, return 0; } -int cpu_get_dump_info(ArchDumpInfo *info, - const GuestPhysBlockList *guest_phys_blocks) -{ - if (first_cpu == NULL) { - return -1; - } - - return arm_get_dump_info(first_cpu, info, guest_phys_blocks); -} - ssize_t cpu_get_note_size(int class, int machine, int nr_cpus) { ARMCPU *cpu = ARM_CPU(first_cpu); diff --git a/target/i386/arch_dump.c b/target/i386/arch_dump.c index d5016c198cb..004a639030e 100644 --- a/target/i386/arch_dump.c +++ b/target/i386/arch_dump.c @@ -430,16 +430,6 @@ int x86_get_dump_info(const CPUState *cs, ArchDumpInfo *info, return 0; } -int cpu_get_dump_info(ArchDumpInfo *info, - const GuestPhysBlockList *guest_phys_blocks) -{ - if (first_cpu == NULL) { - return -1; - } - - return x86_get_dump_info(first_cpu, info, guest_phys_blocks); -} - ssize_t cpu_get_note_size(int class, int machine, int nr_cpus) { int name_size = 5; /* "CORE" or "QEMU" */ diff --git a/target/loongarch/arch_dump.c b/target/loongarch/arch_dump.c index e216e906414..5a0e1742242 100644 --- a/target/loongarch/arch_dump.c +++ b/target/loongarch/arch_dump.c @@ -152,12 +152,6 @@ int loongarch_get_dump_info(const CPUState *cs, ArchDumpInfo *info, return 0; } -int cpu_get_dump_info(ArchDumpInfo *info, - const GuestPhysBlockList *guest_phys_blocks) -{ - return loongarch_get_dump_info(first_cpu, info, guest_phys_blocks); -} - ssize_t cpu_get_note_size(int class, int machine, int nr_cpus) { size_t note_size = 0; diff --git a/target/ppc/arch_dump.c b/target/ppc/arch_dump.c index 7cb97082926..c70c2d0b125 100644 --- a/target/ppc/arch_dump.c +++ b/target/ppc/arch_dump.c @@ -252,16 +252,6 @@ int ppc_get_dump_info(const CPUState *cs, ArchDumpInfo *info, return 0; } -int cpu_get_dump_info(ArchDumpInfo *info, - const struct GuestPhysBlockList *guest_phys_blocks) -{ - if (first_cpu == NULL) { - return -1; - } - - return ppc_get_dump_info(first_cpu, info, guest_phys_blocks); -} - ssize_t cpu_get_note_size(int class, int machine, int nr_cpus) { int name_size = 8; /* "CORE" or "QEMU" rounded */ diff --git a/target/riscv/arch_dump.c b/target/riscv/arch_dump.c index 6562c32cfca..13aaa87202b 100644 --- a/target/riscv/arch_dump.c +++ b/target/riscv/arch_dump.c @@ -182,16 +182,6 @@ int riscv_get_dump_info(const CPUState *cs, ArchDumpInfo *info, return 0; } -int cpu_get_dump_info(ArchDumpInfo *info, - const GuestPhysBlockList *guest_phys_blocks) -{ - if (first_cpu == NULL) { - return -1; - } - - return riscv_get_dump_info(first_cpu, info, guest_phys_blocks); -} - ssize_t cpu_get_note_size(int class, int machine, int nr_cpus) { size_t note_size; diff --git a/target/s390x/arch_dump.c b/target/s390x/arch_dump.c index 9a92efd249a..4301cf400e4 100644 --- a/target/s390x/arch_dump.c +++ b/target/s390x/arch_dump.c @@ -469,12 +469,6 @@ int s390_get_dump_info(const CPUState *cs, ArchDumpInfo *info, return 0; } -int cpu_get_dump_info(ArchDumpInfo *info, - const struct GuestPhysBlockList *guest_phys_blocks) -{ - return s390_get_dump_info(first_cpu, info, guest_phys_blocks); -} - ssize_t cpu_get_note_size(int class, int machine, int nr_cpus) { int name_size = 8; /* "LINUX" or "CORE" + pad */ -- 2.43.0
