Commit b36a3fb229 for qemu.org
commit b36a3fb2299e1589ea75c8e40b64869819245bf3
Author: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>
Date: Wed Oct 21 11:12:36 2026 -0700
dump: reimplement cpu_get_dump_info using get_dump_info sysemu op
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.
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Link: https://lore.kernel.org/qemu-devel/20261021181244.867840-14-pierrick.bouvier@oss.qualcomm.com
Signed-off-by: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>
diff --git a/dump/dump.c b/dump/dump.c
index 0ecff682dd..60ecde0217 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 a64e8c2b68..d04c6a2e6e 100644
--- a/hw/core/cpu-system.c
+++ b/hw/core/cpu-system.c
@@ -130,6 +130,16 @@ 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;
+ }
+ cpu->cc->sysemu_ops->get_dump_info(cpu, info, guest_phys_blocks);
+ return 0;
+}
+
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 456154df6f..d80a6a4e75 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 7165a5bbd0..eccf61dc3e 100644
--- a/include/system/dump-arch.h
+++ b/include/system/dump-arch.h
@@ -27,9 +27,6 @@ struct ArchDumpInfo {
void (*arch_cleanup_fn)(DumpState *s);
};
-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 df7897b72b..2ce3c5e274 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 3ce6ba1d68..6a009ae1a6 100644
--- a/target/arm/arch_dump.c
+++ b/target/arm/arch_dump.c
@@ -430,17 +430,6 @@ void arm_get_dump_info(const CPUState *cs, ArchDumpInfo *info,
? ELFDATA2MSB : ELFDATA2LSB;
}
-int cpu_get_dump_info(ArchDumpInfo *info,
- const GuestPhysBlockList *guest_phys_blocks)
-{
- if (first_cpu == NULL) {
- return -1;
- }
-
- arm_get_dump_info(first_cpu, info, guest_phys_blocks);
- return 0;
-}
-
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 ed273708c6..edbe99d3f5 100644
--- a/target/i386/arch_dump.c
+++ b/target/i386/arch_dump.c
@@ -428,17 +428,6 @@ void x86_get_dump_info(const CPUState *cs, ArchDumpInfo *info,
}
}
-int cpu_get_dump_info(ArchDumpInfo *info,
- const GuestPhysBlockList *guest_phys_blocks)
-{
- if (first_cpu == NULL) {
- return -1;
- }
-
- x86_get_dump_info(first_cpu, info, guest_phys_blocks);
- return 0;
-}
-
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 0ab2df7fab..853a60d7b8 100644
--- a/target/loongarch/arch_dump.c
+++ b/target/loongarch/arch_dump.c
@@ -150,13 +150,6 @@ void loongarch_get_dump_info(const CPUState *cs, ArchDumpInfo *info,
info->d_class = ELFCLASS64;
}
-int cpu_get_dump_info(ArchDumpInfo *info,
- const GuestPhysBlockList *guest_phys_blocks)
-{
- loongarch_get_dump_info(first_cpu, info, guest_phys_blocks);
- return 0;
-}
-
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 2296a0c9e8..86e31c6546 100644
--- a/target/ppc/arch_dump.c
+++ b/target/ppc/arch_dump.c
@@ -250,17 +250,6 @@ void ppc_get_dump_info(const CPUState *cs, ArchDumpInfo *info,
}
}
-int cpu_get_dump_info(ArchDumpInfo *info,
- const struct GuestPhysBlockList *guest_phys_blocks)
-{
- if (first_cpu == NULL) {
- return -1;
- }
-
- ppc_get_dump_info(first_cpu, info, guest_phys_blocks);
- return 0;
-}
-
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 4c442a7831..578435941d 100644
--- a/target/riscv/arch_dump.c
+++ b/target/riscv/arch_dump.c
@@ -180,17 +180,6 @@ void riscv_get_dump_info(const CPUState *cs, ArchDumpInfo *info,
ELFDATA2MSB : ELFDATA2LSB;
}
-int cpu_get_dump_info(ArchDumpInfo *info,
- const GuestPhysBlockList *guest_phys_blocks)
-{
- if (first_cpu == NULL) {
- return -1;
- }
-
- riscv_get_dump_info(first_cpu, info, guest_phys_blocks);
- return 0;
-}
-
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 b26f0ffe14..15299dd7a2 100644
--- a/target/s390x/arch_dump.c
+++ b/target/s390x/arch_dump.c
@@ -468,13 +468,6 @@ void s390_get_dump_info(const CPUState *cs, ArchDumpInfo *info,
}
}
-int cpu_get_dump_info(ArchDumpInfo *info,
- const struct GuestPhysBlockList *guest_phys_blocks)
-{
- s390_get_dump_info(first_cpu, info, guest_phys_blocks);
- return 0;
-}
-
ssize_t cpu_get_note_size(int class, int machine, int nr_cpus)
{
int name_size = 8; /* "LINUX" or "CORE" + pad */