Skip to contentSkip to conversation

ARM dump-guest-memory support

PATCH In review Rabin Vincent 5 participants 26 messages Mar 24, 2013 – Apr 29, 2013 Kbuild

lore
Share & tools
lore
#0 lore raw

v2 cover ARM dump-guest-memory support

A second patchset to add dump-guest-memory support for ARM.

This version of the patchset addresses the following comments from the previous posting, and also adds some more patches to the core dump code (patch #4 and #6):

- memset prstatus to 0 in x86_64_write_elf64_note()
- handle big endian in dump_write_elf_note()
- Save CPSR in ARM prstatus
- set correct ELF endianness for ARM BE

Rabin Vincent (6):
dump: create writable files
dump: extract out note helper
dump: extract out get note size function
dump: fix up memory mapping dependencies / stub
target-arm: add dump-guest-memory support
dump: fix memory region handling

 Makefile.target          |    3 +-
 configure                |    2 +-
 dump.c                   |   88 ++++++++++++++++--
 include/exec/memory.h    |    7 ++
 include/sysemu/dump.h    |    6 ++
 memory.c                 |   12 +++
 memory_mapping-stub.c    |    5 --
 memory_mapping.c         |    6 +-
 target-arm/Makefile.objs |    2 +-
 target-arm/arch_dump.c   |   61 +++++++++++++
 target-i386/arch_dump.c  |  222 +++++++++++-----------------------------------
 11 files changed, 223 insertions(+), 191 deletions(-)
 create mode 100644 target-arm/arch_dump.c
Signature · 1 line
1.7.10.4
#1 lore raw

PATCH v2 1/6 dump: create writable files

The files dump-guest-memory are created as read-only even for the owner. This non-standard behaviour makes it annoying to deal with the dump files (eg. rm -f is needed to delete them or saving a new dump by overwriting the previous one is not possible). Change the code to generate files with write permissions set. If someone requires read-only files to be created, they can achieve it by setting umask.

---
 dump.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
dump.c +2 -1
index a25f509..8dd86b4 100644
@@ -841,7 +841,8 @@ void qmp_dump_guest_memory(bool paging, const char *file, bool has_begin,
 #endif
 
     if  (strstart(file, "file:", &p)) {
-        fd = qemu_open(p, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, S_IRUSR);
+        fd = qemu_open(p, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY,
+                       S_IRUSR | S_IWUSR);
         if (fd < 0) {
             error_set(errp, QERR_OPEN_FILE_FAILED, p);
             return;
Signature · 1 line
1.7.10.4
#2 lore raw

Re: [Qemu-devel] [PATCHv2 1/6] dump: create writable files

Il 24/03/2013 18:27, Rabin Vincent ha scritto:

Quoted 18 lines

The files dump-guest-memory are created as read-only even for the owner. This non-standard behaviour makes it annoying to deal with the dump files (eg. rm -f is needed to delete them or saving a new dump by overwriting the previous one is not possible). Change the code to generate files with write permissions set. If someone requires read-only files to be created, they can achieve it by setting umask.

---
 dump.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
dump.c +0 -0
index a25f509..8dd86b4 100644

dump.c void qmp_dump_guest_memory(bool paging, const char *file, bool has_begin, · line 848

Quoted 9 lines
dump.c +2 -1
@@ -841,7 +841,8 @@ void qmp_dump_guest_memory(bool paging, const char *file, bool has_begin,
 #endif
 
     if  (strstart(file, "file:", &p)) {
-        fd = qemu_open(p, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, S_IRUSR);
+        fd = qemu_open(p, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY,
+                       S_IRUSR | S_IWUSR);
         if (fd < 0) {
             error_set(errp, QERR_OPEN_FILE_FAILED, p);
             return;

Rabim, I think you should resend this patch separately. Cc [email protected] and [email protected], please.

Paolo

#3 lore raw

PATCH v2 2/6 dump: extract out note helper

In reply to Rabin Vincent

Make a common helper function out of the x86 code to add ELF notes.

---
 dump.c                  |   51 ++++++++++++
 include/sysemu/dump.h   |    4 +
 target-i386/arch_dump.c |  208 +++++++++++------------------------------------
 3 files changed, 104 insertions(+), 159 deletions(-)
dump.c +51 -0
index 8dd86b4..c5e009a 100644
@@ -465,6 +465,57 @@ static hwaddr get_offset(hwaddr phys_addr,
     return -1;
 }
 
+int dump_write_elf_note(int class, const char *name, uint32_t type,
+                        void *desc, size_t descsz,
+                        write_core_dump_function f, void *opaque)
+{
+    DumpState *s = opaque;
+    int endian = s->dump_info.d_endian;
+    Elf64_Nhdr *note64;
+    Elf32_Nhdr *note32;
+    void *note;
+    char *buf;
+    size_t note_size, name_size, note_head_size;
+    int ret;
+
+    name_size = strlen(name) + 1;
+
+    if (class == ELFCLASS32) {
+        note_head_size = sizeof(Elf32_Nhdr);
+    } else {
+        note_head_size = sizeof(Elf64_Nhdr);
+    }
+    note_size = ((note_head_size + 3) / 4 + (name_size + 3) / 4 +
+                (descsz + 3) / 4) * 4;
+    note = g_malloc(note_size);
+
+    memset(note, 0, note_size);
+    if (class == ELFCLASS32) {
+        note32 = note;
+        note32->n_namesz = cpu_convert_to_target32(name_size, endian);
+        note32->n_descsz = cpu_convert_to_target32(descsz, endian);
+        note32->n_type = cpu_convert_to_target32(type, endian);
+    } else {
+        note64 = note;
+        note64->n_namesz = cpu_convert_to_target64(name_size, endian);
+        note64->n_descsz = cpu_convert_to_target64(descsz, endian);
+        note64->n_type = cpu_convert_to_target64(type, endian);
+    }
+    buf = note;
+    buf += ((note_head_size + 3) / 4) * 4;
+    memcpy(buf, name, name_size);
+    buf += ((name_size + 3) / 4) * 4;
+    memcpy(buf, desc, descsz);
+
+    ret = f(note, note_size, opaque);
+    g_free(note);
+    if (ret < 0) {
+        return -1;
+    }
+
+    return 0;
+}
+
 static int write_elf_loads(DumpState *s)
 {
     hwaddr offset;
include/sysemu/dump.h +4 -0
index e25b7cf..b07816a 100644
@@ -32,4 +32,8 @@ int cpu_write_elf32_qemunote(write_core_dump_function f, CPUArchState *env,
 int cpu_get_dump_info(ArchDumpInfo *info);
 ssize_t cpu_get_note_size(int class, int machine, int nr_cpus);
 
+int dump_write_elf_note(int class, const char *name, uint32_t type, void *desc,
+                        size_t descsz, write_core_dump_function f,
+                        void *opaque);
+
 #endif
target-i386/arch_dump.c +49 -159

254 lines not on this page · raw message

Signature · 1 line
1.7.10.4
#4 lore raw

PATCH v2 3/6 dump: extract out get note size function

In reply to Rabin Vincent

Extract out the ELF note size function from i386 so we can use it from other targets.

---
 dump.c                  |   15 +++++++++++++++
 include/sysemu/dump.h   |    2 ++
 target-i386/arch_dump.c |   14 ++------------
 3 files changed, 19 insertions(+), 12 deletions(-)
dump.c +15 -0
index c5e009a..4b7d76c 100644
@@ -465,6 +465,21 @@ static hwaddr get_offset(hwaddr phys_addr,
     return -1;
 }
 
+size_t dump_get_note_size(int class, const char *name, size_t descsz)
+{
+    int name_size = strlen(name) + 1;
+    int note_head_size;
+
+    if (class == ELFCLASS32) {
+        note_head_size = sizeof(Elf32_Nhdr);
+    } else {
+        note_head_size = sizeof(Elf64_Nhdr);
+    }
+
+    return ((note_head_size + 3) / 4 + (name_size + 3) / 4
+            + (descsz + 3) / 4) * 4;
+}
+
 int dump_write_elf_note(int class, const char *name, uint32_t type,
                         void *desc, size_t descsz,
                         write_core_dump_function f, void *opaque)
include/sysemu/dump.h +2 -0
index b07816a..a06b149 100644
@@ -36,4 +36,6 @@ int dump_write_elf_note(int class, const char *name, uint32_t type, void *desc,
                         size_t descsz, write_core_dump_function f,
                         void *opaque);
 
+size_t dump_get_note_size(int class, const char *name, size_t descsz);
+
 #endif
target-i386/arch_dump.c +2 -12
index eea7f7f..49fa024 100644
@@ -307,18 +307,10 @@ int cpu_get_dump_info(ArchDumpInfo *info)
 
 ssize_t cpu_get_note_size(int class, int machine, int nr_cpus)
 {
-    int name_size = 5; /* "CORE" or "QEMU" */
     size_t elf_note_size = 0;
     size_t qemu_note_size = 0;
     int elf_desc_size = 0;
     int qemu_desc_size = 0;
-    int note_head_size;
-
-    if (class == ELFCLASS32) {
-        note_head_size = sizeof(Elf32_Nhdr);
-    } else {
-        note_head_size = sizeof(Elf64_Nhdr);
-    }
 
     if (machine == EM_386) {
         elf_desc_size = sizeof(x86_elf_prstatus);
@@ -330,10 +322,8 @@ ssize_t cpu_get_note_size(int class, int machine, int nr_cpus)
 #endif
     qemu_desc_size = sizeof(QEMUCPUState);
 
-    elf_note_size = ((note_head_size + 3) / 4 + (name_size + 3) / 4 +
-                     (elf_desc_size + 3) / 4) * 4;
-    qemu_note_size = ((note_head_size + 3) / 4 + (name_size + 3) / 4 +
-                      (qemu_desc_size + 3) / 4) * 4;
+    elf_note_size = dump_get_note_size(class, "CORE", elf_desc_size);
+    qemu_note_size = dump_get_note_size(class, "QEMU", qemu_desc_size);
 
     return (elf_note_size + qemu_note_size) * nr_cpus;
 }
Signature · 1 line
1.7.10.4
#5 lore raw

PATCH v2 4/6 dump: fix up memory mapping dependencies / stub

In reply to Rabin Vincent

dump.c won't build without the functions from memory_mapping.c (and memory_mapping-stub.c does not help there), so build memory_mapping.c when CONFIG_HAVE_CORE_DUMP is set.

dump.c:84: undefined reference to memory_mapping_list_free' dump.c:819: undefined reference to memory_mapping_list_init' dump.c:827: undefined reference to `memory_mapping_filter'

Allow memory_mapping-stub.c to instead be used for targets which do not set CONFIG_HAVE_GET_MEMORY_MAPPING.

---
 Makefile.target       |    3 +--
 memory_mapping-stub.c |    5 -----
 2 files changed, 1 insertion(+), 7 deletions(-)
Makefile.target +1 -2
index 2bd6d14..629f48a 100644
@@ -115,8 +115,7 @@ obj-$(CONFIG_FDT) += device_tree.o
 obj-$(CONFIG_KVM) += kvm-all.o
 obj-$(CONFIG_NO_KVM) += kvm-stub.o
 obj-y += memory.o savevm.o cputlb.o
-obj-$(CONFIG_HAVE_GET_MEMORY_MAPPING) += memory_mapping.o
-obj-$(CONFIG_HAVE_CORE_DUMP) += dump.o
+obj-$(CONFIG_HAVE_CORE_DUMP) += dump.o memory_mapping.o
 obj-$(CONFIG_NO_GET_MEMORY_MAPPING) += memory_mapping-stub.o
 obj-$(CONFIG_NO_CORE_DUMP) += dump-stub.o
 LIBS+=-lz
memory_mapping-stub.c +0 -5
index 24d5d67..6dd9e36 100644
@@ -15,11 +15,6 @@
 #include "exec/cpu-all.h"
 #include "sysemu/memory_mapping.h"
 
-int qemu_get_guest_memory_mapping(MemoryMappingList *list)
-{
-    return -2;
-}
-
 int cpu_get_memory_mapping(MemoryMappingList *list,
 					                                          CPUArchState *env)
 {
Signature · 1 line
1.7.10.4
#6 lore raw

Re: [Qemu-devel] [PATCHv2 4/6] dump: fix up memory mapping dependencies / stub

Il 24/03/2013 18:27, Rabin Vincent ha scritto:

Quoted 10 lines

dump.c won't build without the functions from memory_mapping.c (and memory_mapping-stub.c does not help there), so build memory_mapping.c when CONFIG_HAVE_CORE_DUMP is set.

dump.c:84: undefined reference to memory_mapping_list_free' dump.c:819: undefined reference to memory_mapping_list_init' dump.c:827: undefined reference to `memory_mapping_filter'

Allow memory_mapping-stub.c to instead be used for targets which do not set CONFIG_HAVE_GET_MEMORY_MAPPING.

The right fix is to add these to memory_mapping-stub.c.

Paolo

#7 lore raw

PATCH v2 5/6 target-arm: add dump-guest-memory support

In reply to Rabin Vincent

Enable support for the dump-guest-memory monitor command for ARM.

---
 configure                |    2 +-
 target-arm/Makefile.objs |    2 +-
 target-arm/arch_dump.c   |   61 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 63 insertions(+), 2 deletions(-)
 create mode 100644 target-arm/arch_dump.c
configure +1 -1
index 46a7594..f35786d 100755
@@ -4184,7 +4184,7 @@ if test "$target_softmmu" = "yes" ; then
   echo "CONFIG_SOFTMMU=y" >> $config_target_mak
   echo "LIBS+=$libs_softmmu $target_libs_softmmu" >> $config_target_mak
   case "$target_arch2" in
-    i386|x86_64)
+    arm|i386|x86_64)
       echo "CONFIG_HAVE_CORE_DUMP=y" >> $config_target_mak
   esac
 fi
target-arm/Makefile.objs +1 -1
index d89b57c..93baa12 100644
@@ -1,5 +1,5 @@
 obj-y += arm-semi.o
-obj-$(CONFIG_SOFTMMU) += machine.o
+obj-$(CONFIG_SOFTMMU) += machine.o arch_dump.o
 obj-$(CONFIG_KVM) += kvm.o
 obj-y += translate.o op_helper.o helper.o cpu.o
 obj-y += neon_helper.o iwmmxt_helper.o
target-arm/arch_dump.c new file +61 -0

61 lines not on this page · raw message

Signature · 1 line
1.7.10.4
#8 lore raw

Re: [Qemu-devel] [PATCHv2 5/6] target-arm: add dump-guest-memory support

Quoted 1 line · Rabin Vincent

Enable support for the dump-guest-memory monitor command for ARM.

Hi. I'm afraid I'm not really familiar with the dump-guest-memory command/implementation so I have some possibly dumb comments below:

Quoted 4 lines
target-arm/arch_dump.c new file +1 -0
@@ -0,0 +1,61 @@
+#include "cpu.h"

target-arm/arch_dump.c line 11

Quoted 10 lines
target-arm/arch_dump.c new file +10 -0
+#include "sysemu/dump.h"
+#include "elf.h"
+
+typedef struct {
+    char pad1[24];
+    uint32_t pid;
+    char pad2[44];
+    uint32_t regs[18];
+    char pad3[4];
+} arm_elf_prstatus;

Can you point me at the spec this struct corresponds to?

target-arm/arch_dump.c line 17

Quoted 6 lines
target-arm/arch_dump.c new file +6 -0
+
+int cpu_write_elf64_note(write_core_dump_function f, CPUArchState *env,
+                         int cpuid, void *opaque)
+{
+    return -1;
+}

Is there any documentation of the API we're implementing here? (why does it require us to provide 64 bit functions that are never used?)

Quoted 15 lines
target-arm/arch_dump.c new file +15 -0
+
+int cpu_write_elf32_note(write_core_dump_function f, CPUArchState *env,
+                         int cpuid, void *opaque)
+{
+    arm_elf_prstatus prstatus = {.pid = cpuid};
+
+    memcpy(&(prstatus.regs), env->regs, sizeof(env->regs));
+    prstatus.regs[16] = cpsr_read(env);
+
+    return dump_write_elf_note(ELFCLASS32, "CORE", NT_PRSTATUS,
+                               &prstatus, sizeof(prstatus),
+                               f, opaque);
+}
+
+int cpu_write_elf64_qemunote(write_core_dump_function f, CPUArchState *env,

target-arm/arch_dump.c line 42

Quoted 10 lines
target-arm/arch_dump.c new file +10 -0
+                             void *opaque)
+{
+    return -1;
+}
+
+int cpu_write_elf32_qemunote(write_core_dump_function f, CPUArchState *env,
+                             void *opaque)
+{
+    return 0;
+}

Why is it OK to implement this as a no-op? What could we be doing here that we don't do? What are the effects?

target-arm/arch_dump.c line 52

Quoted 10 lines
target-arm/arch_dump.c new file +10 -0
+
+int cpu_get_dump_info(ArchDumpInfo *info)
+{
+    info->d_machine = EM_ARM;
+#ifdef TARGET_WORDS_BIGENDIAN
+    info->d_endian = ELFDATA2MSB;
+#else
+    info->d_endian = ELFDATA2LSB;
+#endif
+    info->d_class = ELFCLASS32;

Most of this looks like it would be suitable for a default implementation that said "endian based on TARGET_WORDS_BIGENDIAN, machine is ELF_MACHINE, class based on TARGET_LONG_BITS".

Quoted 10 lines
target-arm/arch_dump.c new file +9 -1
+
+    return 0;
+}
+
+ssize_t cpu_get_note_size(int class, int machine, int nr_cpus)
+{
+    return nr_cpus * dump_get_note_size(ELFCLASS32, "CORE",
+                                        sizeof(arm_elf_prstatus));
+}
--
Quoted 2 lines

1.7.10.4

thanks
-- PMM

#9 lore raw

Re: [Qemu-devel] [PATCHv2 5/6] target-arm: add dump-guest-memory support

2013/3/24 Peter Maydell <[email protected]>:

Quoted 9 lines · Rabin Vincent
Quoted 8 lines
target-arm/arch_dump.c new file +5 -0
@@ -0,0 +1,61 @@
+#include "cpu.h"
+#include "sysemu/dump.h"
+#include "elf.h"
+
+typedef struct {
Quoted 8 lines

target-arm/arch_dump.c line 11

Quoted 6 lines
target-arm/arch_dump.c new file +6 -0
+    char pad1[24];
+    uint32_t pid;
+    char pad2[44];
+    uint32_t regs[18];
+    char pad3[4];
+} arm_elf_prstatus;

Can you point me at the spec this struct corresponds to?

This is elf_prstatus from the Linux kernel's include/uapi/linux/elfcore.h, with the regset begin ARM regs in this case.

I don't know if there's a spec. It doesn't sound like it from the comments in the kernel file: "This is mostly like the SVR4 structure, but more Linuxy, with things that Linux does not support and which gdb doesn't really use excluded."

The x86 implementation in target-i386/arch_dump.c uses the same elf_prstatus with the x86 regs.

Quoted 9 lines

target-arm/arch_dump.c line 17

Quoted 7 lines
target-arm/arch_dump.c new file +6 -0
+
+int cpu_write_elf64_note(write_core_dump_function f, CPUArchState *env,
+                         int cpuid, void *opaque)
+{
+    return -1;
+}

Is there any documentation of the API we're implementing here?

I coudn't find any documentation. It's only x86 that has the API implemented.

Quoted 2 lines

(why does it require us to provide 64 bit functions that are never used?)

I guess the API was made with x86 in mind. I will see if the requirement can be removed with some ifdefs in the dump.c file.

(come to think of it, I guess this ARM code will need to use ELFCLASS64
when we have physical memory > 4GiB (LPAE))

Quoted 8 lines

target-arm/arch_dump.c line 42

Quoted 5 lines
target-arm/arch_dump.c new file +5 -0
+int cpu_write_elf32_qemunote(write_core_dump_function f, CPUArchState *env,
+                             void *opaque)
+{
+    return 0;
+}

Why is it OK to implement this as a no-op? What could we be doing here that we don't do? What are the effects?

This is supposed to be used to add some additional information about the CPU state in an ELF note in a QEMU-specific structure, like the QEMUCPUState in target-i386/arm-state.c. It's only useful to implement this if someone sees a need to add any such information.

Quoted 15 lines

target-arm/arch_dump.c line 52

Quoted 11 lines
target-arm/arch_dump.c new file +10 -0
+
+int cpu_get_dump_info(ArchDumpInfo *info)
+{
+    info->d_machine = EM_ARM;
+#ifdef TARGET_WORDS_BIGENDIAN
+    info->d_endian = ELFDATA2MSB;
+#else
+    info->d_endian = ELFDATA2LSB;
+#endif
+    info->d_class = ELFCLASS32;

Most of this looks like it would be suitable for a default implementation that said "endian based on TARGET_WORDS_BIGENDIAN, machine is ELF_MACHINE, class based on TARGET_LONG_BITS".

I will see if this can be moved into the generic dump.c.

#10 lore raw

Re: [Qemu-devel] [PATCHv2 5/6] target-arm: add dump-guest-memory support

Quoted 2 lines · Rabin Vincent

2013/3/24 Peter Maydell <[email protected]>:

Quoted 1 line · Rabin Vincent

So I guess I should prefix this email by saying that quite a bit of it is really comments on the existing dump code rather than the ARM related support you're adding here. I appreciate that it's annoying to get asked to fix up a bunch of existing code just because you happened to be the next person to want to add use case 2 to it. So you should feel free to push back a bit if any of this seems too burdensome or unnecessary.

(I do think that the memory region stuff in the other patch does need fixing though, because (a) vexpress really does map RAM in two places in the physical address map and (b) we need to be careful about what we allow to be added to the memory API, so it remains coherent. So if you only fix up one thing it should be that.)

Quoted 17 lines
Quoted 8 lines
Quoted 8 lines
target-arm/arch_dump.c new file +5 -0
@@ -0,0 +1,61 @@
+#include "cpu.h"
+#include "sysemu/dump.h"
+#include "elf.h"
+
+typedef struct {
Quoted 8 lines

target-arm/arch_dump.c line 11

Quoted 6 lines
target-arm/arch_dump.c new file +6 -0
+    char pad1[24];
+    uint32_t pid;
+    char pad2[44];
+    uint32_t regs[18];
+    char pad3[4];
+} arm_elf_prstatus;

Can you point me at the spec this struct corresponds to?

Quoted 3 lines

This is elf_prstatus from the Linux kernel's include/uapi/linux/elfcore.h, with the regset begin ARM regs in this case.

They don't look very similar to me -- this one has a lot of pad fields the elf_prstatus doesn't. Also, if the kernel's struct is a standard one with a cpu-specific regset field, why isn't QEMU also using a standard struct with a cpu-specific regset field?

(it seems a bit bogus that we aren't saving the floating point registers too, but it looks like Linux doesn't do that either, so I guess there's nowhere in the core file for it.)

Quoted 18 lines

I don't know if there's a spec. It doesn't sound like it from the comments in the kernel file: "This is mostly like the SVR4 structure, but more Linuxy, with things that Linux does not support and which gdb doesn't really use excluded."

The x86 implementation in target-i386/arch_dump.c uses the same elf_prstatus with the x86 regs.

Quoted 9 lines

target-arm/arch_dump.c line 17

Quoted 7 lines
target-arm/arch_dump.c new file +6 -0
+
+int cpu_write_elf64_note(write_core_dump_function f, CPUArchState *env,
+                         int cpuid, void *opaque)
+{
+    return -1;
+}

Is there any documentation of the API we're implementing here?

Quoted 2 lines

I coudn't find any documentation. It's only x86 that has the API implemented.

It would be nice if somebody who understood it could add some doc comments to the header file.

Quoted 8 lines
Quoted 2 lines

(why does it require us to provide 64 bit functions that are never used?)

I guess the API was made with x86 in mind. I will see if the requirement can be removed with some ifdefs in the dump.c file.

(come to think of it, I guess this ARM code will need to use ELFCLASS64
when we have physical memory > 4GiB (LPAE))

It would be good to check whether that is correct -- mostly core files are for dumps of a virtual address space so I don't know whether gdb/etc would understand an ARM corefile which claimed ELFCLASS64. (I mean understand it as an AArch32 corefile rather than AArch64.)

Quoted 9 lines
Quoted 8 lines

target-arm/arch_dump.c line 42

Quoted 5 lines
target-arm/arch_dump.c new file +5 -0
+int cpu_write_elf32_qemunote(write_core_dump_function f, CPUArchState *env,
+                             void *opaque)
+{
+    return 0;
+}

Why is it OK to implement this as a no-op? What could we be doing here that we don't do? What are the effects?

Quoted 4 lines

This is supposed to be used to add some additional information about the CPU state in an ELF note in a QEMU-specific structure, like the QEMUCPUState in target-i386/arm-state.c. It's only useful to implement this if someone sees a need to add any such information.

OK.

Quoted 16 lines
Quoted 15 lines

target-arm/arch_dump.c line 52

Quoted 11 lines
target-arm/arch_dump.c new file +10 -0
+
+int cpu_get_dump_info(ArchDumpInfo *info)
+{
+    info->d_machine = EM_ARM;
+#ifdef TARGET_WORDS_BIGENDIAN
+    info->d_endian = ELFDATA2MSB;
+#else
+    info->d_endian = ELFDATA2LSB;
+#endif
+    info->d_class = ELFCLASS32;

Most of this looks like it would be suitable for a default implementation that said "endian based on TARGET_WORDS_BIGENDIAN, machine is ELF_MACHINE, class based on TARGET_LONG_BITS".

Quoted 1 line

I will see if this can be moved into the generic dump.c.

thanks
-- PMM

#11 lore raw

Re: [Qemu-devel] [PATCHv2 5/6] target-arm: add dump-guest-memory support

Il 24/03/2013 21:39, Peter Maydell ha scritto:

Quoted 11 lines
Quoted 6 lines
Quoted 6 lines

I guess the API was made with x86 in mind. I will see if the requirement can be removed with some ifdefs in the dump.c file.

(come to think of it, I guess this ARM code will need to use ELFCLASS64
when we have physical memory > 4GiB (LPAE))

It would be good to check whether that is correct -- mostly core files are for dumps of a virtual address space so I don't know whether gdb/etc would understand an ARM corefile which claimed ELFCLASS64. (I mean understand it as an AArch32 corefile rather than AArch64.)

Note that in this case we can choose between physical and virtual address space dumps.

Virtual address space is mostly useful with gdb; physical address space can be used for example with "crash", a post-mortem kernel debugger.

Paolo

#12 lore raw

Re: [Qemu-devel] [PATCHv2 5/6] target-arm: add dump-guest-memory support

Quoted 9 lines · Paolo Bonzini

Il 24/03/2013 21:39, Peter Maydell ha scritto:

Quoted 7 lines
Quoted 2 lines
Quoted 2 lines

(come to think of it, I guess this ARM code will need to use ELFCLASS64
when we have physical memory > 4GiB (LPAE))

It would be good to check whether that is correct -- mostly core files are for dumps of a virtual address space so I don't know whether gdb/etc would understand an ARM corefile which claimed ELFCLASS64. (I mean understand it as an AArch32 corefile rather than AArch64.)

Quoted 5 lines

Note that in this case we can choose between physical and virtual address space dumps.

Virtual address space is mostly useful with gdb; physical address space can be used for example with "crash", a post-mortem kernel debugger.

Yeah, my point was really that either way we should be checking how the kernel and these tools expect to handle an LPAE dump.

-- PMM

#13 lore raw

PATCH v2 6/6 dump: fix memory region handling

In reply to Rabin Vincent

RAMBlock.offset does not provide the physical address of the memory region. This is available in the MemoryRegion's address. The wrong usage leads to incorrect physical addreses in the ELF. Fix it.

---
 dump.c                |   19 +++++++++++--------
 include/exec/memory.h |    7 +++++++
 memory.c              |   12 ++++++++++++
 memory_mapping.c      |    6 ++++--
 4 files changed, 34 insertions(+), 10 deletions(-)
dump.c +11 -8
index 4b7d76c..4b0353a 100644
@@ -16,6 +16,7 @@
 #include "cpu.h"
 #include "exec/cpu-all.h"
 #include "exec/hwaddr.h"
+#include "exec/memory.h"
 #include "monitor/monitor.h"
 #include "sysemu/kvm.h"
 #include "sysemu/dump.h"
@@ -432,26 +433,28 @@ static hwaddr get_offset(hwaddr phys_addr,
     }
 
     QTAILQ_FOREACH(block, &ram_list.blocks, next) {
+        hwaddr baddr = memory_region_get_addr(block->mr);
+
         if (s->has_filter) {
-            if (block->offset >= s->begin + s->length ||
-                block->offset + block->length <= s->begin) {
+            if (baddr >= s->begin + s->length ||
+                baddr + block->length <= s->begin) {
                 /* This block is out of the range */
                 continue;
             }
 
-            if (s->begin <= block->offset) {
-                start = block->offset;
+            if (s->begin <= baddr) {
+                start = baddr;
             } else {
                 start = s->begin;
             }
 
-            size_in_block = block->length - (start - block->offset);
-            if (s->begin + s->length < block->offset + block->length) {
-                size_in_block -= block->offset + block->length -
+            size_in_block = block->length - (start - baddr);
+            if (s->begin + s->length < baddr + block->length) {
+                size_in_block -= baddr + block->length -
                                  (s->begin + s->length);
             }
         } else {
-            start = block->offset;
+            start = baddr;
             size_in_block = block->length;
         }
 
include/exec/memory.h +7 -0
index 2322732..9227190 100644
@@ -665,6 +665,13 @@ void memory_region_add_subregion_overlap(MemoryRegion *mr,
                                          unsigned priority);
 
 /**
+ * memory_region_get_addr: Get the address of a memory region
+ *
+ * @mr: the memory region
+ */
+hwaddr memory_region_get_addr(MemoryRegion *mr);
+
+/**
  * memory_region_get_ram_addr: Get the ram address associated with a memory
  *                             region
  *
memory.c +12 -0
index 92a2196..f90fd19 100644
@@ -1427,6 +1427,18 @@ void memory_region_set_alias_offset(MemoryRegion *mr, hwaddr offset)
     memory_region_transaction_commit();
 }
 
+hwaddr memory_region_get_addr(MemoryRegion *mr)
+{
+    hwaddr addr = 0;
+
+    while (mr) {
+	    addr += mr->addr;
+	    mr = mr->parent;
+    }
+
+    return addr;
+}
+
 ram_addr_t memory_region_get_ram_addr(MemoryRegion *mr)
 {
     return mr->ram_addr;
memory_mapping.c +4 -2
index ff45b3a..cf0751c 100644
@@ -13,6 +13,7 @@
 
 #include "cpu.h"
 #include "exec/cpu-all.h"
+#include "exec/memory.h"
 #include "sysemu/memory_mapping.h"
 
 static void memory_mapping_list_add_mapping_sorted(MemoryMappingList *list,
@@ -201,7 +202,7 @@ int qemu_get_guest_memory_mapping(MemoryMappingList *list)
      * address.
      */
     QTAILQ_FOREACH(block, &ram_list.blocks, next) {
-        offset = block->offset;
+        offset = memory_region_get_addr(block->mr);
         length = block->length;
         create_new_memory_mapping(list, offset, offset, length);
     }
@@ -214,7 +215,8 @@ void qemu_get_guest_simple_memory_mapping(MemoryMappingList *list)
     RAMBlock *block;
 
     QTAILQ_FOREACH(block, &ram_list.blocks, next) {
-        create_new_memory_mapping(list, block->offset, 0, block->length);
+        create_new_memory_mapping(list, memory_region_get_addr(block->mr),
+                                  0, block->length);
     }
 }
 
Signature · 1 line
1.7.10.4
#14 lore raw

Re: [Qemu-devel] [PATCHv2 6/6] dump: fix memory region handling

Quoted 6 lines · Rabin Vincent

/**
+ * memory_region_get_addr: Get the address of a memory region
+ *
+ * @mr: the memory region
+ */
+hwaddr memory_region_get_addr(MemoryRegion *mr);

I'm afraid this doesn't make sense. A MemoryRegion by itself has no "address" -- it could be mapped into several places in several different address maps or none at all.

-- PMM

#15 lore raw

Re: [Qemu-devel] [PATCHv2 6/6] dump: fix memory region handling

2013/3/24 Peter Maydell <[email protected]>:

Quoted 11 lines · Rabin Vincent
Quoted 6 lines

/**
+ * memory_region_get_addr: Get the address of a memory region
+ *
+ * @mr: the memory region
+ */
+hwaddr memory_region_get_addr(MemoryRegion *mr);

I'm afraid this doesn't make sense. A MemoryRegion by itself has no "address" -- it could be mapped into several places in several different address maps or none at all.

OK. Do you mean that such a function can be used internally to the dump code where it gets the MemoryRegion only from the RAMBlock.mr or do you mean the dump code also shouldn't be doing it that way?

If you mean the latter, could you please suggest an alternative way to handle this? The problem is that the dump code assumes that RAMBlock.offset provides the physical address, and this appears to not be the case. For example, with a dump generated from vexpress I get these Program Headers in the dump:

  Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align
  NOTE           0x0000f4 0x00000000 0x00000000 0x002a0 0x002a0     0
  LOAD           0x000394 0x00000000 0x00000000 0x8000000 0x8000000     0
  LOAD           0x8000394 0x00000000 0x08000000 0x4000000 0x4000000     0
  LOAD           0xc000394 0x00000000 0x0c000000 0x4000000 0x4000000     0
  LOAD           0x10000394 0x00000000 0x10000000 0x2000000 0x2000000     0
  LOAD           0x12000394 0x00000000 0x12000000 0x800000 0x800000     0

The physical addresses are completely wrong, and with the patch I get the right ones:

  Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align
  NOTE           0x0000f4 0x00000000 0x00000000 0x002a0 0x002a0     0
  LOAD           0x8000394 0x00000000 0x40000000 0x4000000 0x4000000     0
  LOAD           0xc000394 0x00000000 0x44000000 0x4000000 0x4000000     0
  LOAD           0x10000394 0x00000000 0x48000000 0x2000000 0x2000000     0
  LOAD           0x12000394 0x00000000 0x4c000000 0x800000 0x800000     0
  LOAD           0x000394 0x00000000 0x60000000 0x8000000 0x8000000     0

Thanks.

#16 lore raw

Re: [Qemu-devel] [PATCHv2 6/6] dump: fix memory region handling

Quoted 9 lines · Rabin Vincent

2013/3/24 Peter Maydell <[email protected]>:

Quoted 8 lines · Rabin Vincent
Quoted 6 lines

/**
+ * memory_region_get_addr: Get the address of a memory region
+ *
+ * @mr: the memory region
+ */
+hwaddr memory_region_get_addr(MemoryRegion *mr);

Quoted 7 lines
Quoted 3 lines

I'm afraid this doesn't make sense. A MemoryRegion by itself has no "address" -- it could be mapped into several places in several different address maps or none at all.

OK. Do you mean that such a function can be used internally to the dump code where it gets the MemoryRegion only from the RAMBlock.mr or do you mean the dump code also shouldn't be doing it that way?

I mean that the dump code is wrong if it's trying to ask "what is the address of this MemoryRegion (or RAMBlock)" at all. That question doesn't have a well defined single answer.

Quoted 4 lines

If you mean the latter, could you please suggest an alternative way to handle this? The problem is that the dump code assumes that RAMBlock.offset provides the physical address, and this appears to not be the case.

That is also wrong, both for the reason you state and also because ramblocks can be aliased into multiple physical addresses too. I suspect you need to change anything that's trying to iterate through memory with "for each block in ram_list" to instead actually iterate through the system address space and say "if this is RAM then...". For instance with the vexpress-a9 you presumably want a LOAD section for both physaddr 0 (the alias) and physaddr 0x60000000 (the usual address).

-- PMM

#17 lore raw
In reply to Rabin Vincent

Hi,

Am 24.03.2013 18:27, schrieb Rabin Vincent:

Quoted 10 lines

A second patchset to add dump-guest-memory support for ARM.

This version of the patchset addresses the following comments from the previous posting, and also adds some more patches to the core dump code (patch #4 and #6):

- memset prstatus to 0 in x86_64_write_elf64_note()
- handle big endian in dump_write_elf_note()
- Save CPSR in ARM prstatus
- set correct ELF endianness for ARM BE

This still does not address the architectural issue that I brought up. That would affect the equivalent s390x patch as well.

Regards,
Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#19 lore raw

Am 29.03.2013 09:36, schrieb Rabin Vincent:

Quoted 8 lines

2013/3/25 Andreas Färber <[email protected]>

Quoted 1 line

This still does not address the architectural issue that I brought up.

I guess you mean the CPUArchState stuff? AFAICS Wen Congyang (the author of the dump code) had some answers/questions for you:

http://lists.gnu.org/archive/html/qemu-devel/2012-07/msg00382.html
http://lists.gnu.org/archive/html/qemu-devel/2012-07/msg00384.html

Yes, that is what I'm referring to, and I don't see answers to my questions...

If as I understand we are talking about a property that depends solely on the target CPU then it should be implemented on CPUClass level (which is the one above ARMCPU, S390CPU etc.) and not require changes to configure at all. CPUArchState is by contrast a per-target type. qom/cpu.c would implement the dummy versions and in your case target-arm/cpu.c (in Jens' case target-s390x/cpu.c) should override that behavior by setting cc->whatever to a static function that actually implements the functionality. I would supply you with a patch for that myself, but I am rather busy with downstream ATM and Igor is poking me for x86 CPU review, so if either of you or Wen Congyang could fix that design flaw before making it worse I would appreciate that!

Regards,
Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#20 lore raw

RFC 1/1 make write_elf_xx functions part of CPUClass, use CPUState

Hi Andreas,

not sure if this is what you had in mind. Does it at least go into the right direction? It is pretty much untested and won't compile as is. I just wanted to get your opinion before putting more work into this.

This patch adds 4 write_elf_XX functions to the CPUClass which can be implemented by XXXCPUState, e.g. S390CPUstate.

Would it make sense to have paging_enabled/HAVE_MEMORY_MAPPING also as a property of the CPU object?

---
 dump.c                   | 28 +++++++++++++++++++++++----
 include/qom/cpu.h        | 49 ++++++++++++++++++++++++++++++++++++++++++++++++
 include/sysemu/dump.h    |  9 +--------
 qom/cpu.c                | 44 +++++++++++++++++++++++++++++++++++++++++++
 target-s390x/arch_dump.c | 25 ++++--------------------
 target-s390x/arch_dump.h | 14 ++++++++++++++
 target-s390x/cpu.c       |  6 ++++++
 7 files changed, 142 insertions(+), 33 deletions(-)
 create mode 100644 target-s390x/arch_dump.h
dump.c +24 -4
index 574c292..df49845 100644
@@ -272,13 +272,19 @@ static int write_elf64_notes(DumpState *s)
 {
     CPUArchState *env;
     CPUState *cpu;
+    CPUClass *cc;
     int ret;
     int id;
 
     for (env = first_cpu; env != NULL; env = env->next_cpu) {
         cpu = ENV_GET_CPU(env);
+        cc = CPU_GET_CLASS(cpu);
         id = cpu_index(cpu);
-        ret = cpu_write_elf64_note(fd_write_vmcore, env, id, s);
+        if (cc->write_elf64_note)
+            ret = cc->write_elf64_note(fd_write_vmcore, cpu, id, s);
+        else {
+            ret = 0;
+        }
         if (ret < 0) {
             dump_error(s, "dump: failed to write elf notes.\n");
             return -1;
@@ -286,7 +292,11 @@ static int write_elf64_notes(DumpState *s)
     }
 
     for (env = first_cpu; env != NULL; env = env->next_cpu) {
-        ret = cpu_write_elf64_qemunote(fd_write_vmcore, env, s);
+        if (cc->write_elf64_qemunote)
+            ret = cc->write_elf64_qemunote(fd_write_vmcore, cpu, s);
+        else {
+            ret = 0;
+        }
         if (ret < 0) {
             dump_error(s, "dump: failed to write CPU status.\n");
             return -1;
@@ -324,13 +334,19 @@ static int write_elf32_notes(DumpState *s)
 {
     CPUArchState *env;
     CPUState *cpu;
+    CPUClass *cc;
     int ret;
     int id;
 
     for (env = first_cpu; env != NULL; env = env->next_cpu) {
         cpu = ENV_GET_CPU(env);
+        cc = CPU_GET_CLASS(cpu);
         id = cpu_index(cpu);
-        ret = cpu_write_elf32_note(fd_write_vmcore, env, id, s);
+        if (cc->write_elf32_note) {
+            ret = cc->write_elf32_note(fd_write_vmcore, cpu, id, s);
+        } else {
+            ret = 0; 
+        }
         if (ret < 0) {
             dump_error(s, "dump: failed to write elf notes.\n");
             return -1;
@@ -338,7 +354,11 @@ static int write_elf32_notes(DumpState *s)
     }
 
     for (env = first_cpu; env != NULL; env = env->next_cpu) {
-        ret = cpu_write_elf32_qemunote(fd_write_vmcore, env, s);
+        if (cc->write_elf32_qemunote) {
+            ret = cc->write_elf32_qemunote(fd_write_vmcore, cpu, s);
+        } else {
+            ret = 0; 
+        }
         if (ret < 0) {
             dump_error(s, "dump: failed to write CPU status.\n");
             return -1;
include/qom/cpu.h +49 -0

67 lines not on this page · raw message

include/sysemu/dump.h +1 -8
index b03efd4..e5f9f7d 100644
@@ -16,6 +16,7 @@
 
 #include "qapi/error.h"
 #include "include/qapi/qmp/qerror.h"
+#include "qom/cpu.h"
 
 typedef struct ArchDumpInfo {
     int d_machine;  /* Architecture */
@@ -24,14 +25,6 @@ typedef struct ArchDumpInfo {
 } ArchDumpInfo;
 
 typedef int (*write_core_dump_function)(void *buf, size_t size, void *opaque);
-int cpu_write_elf64_note(write_core_dump_function f, CPUArchState *env,
-                                                  int cpuid, void *opaque);
-int cpu_write_elf32_note(write_core_dump_function f, CPUArchState *env,
-                                                  int cpuid, void *opaque);
-int cpu_write_elf64_qemunote(write_core_dump_function f, CPUArchState *env,
-                                                          void *opaque);
-int cpu_write_elf32_qemunote(write_core_dump_function f, CPUArchState *env,
-                                                          void *opaque);
 int cpu_get_dump_info(ArchDumpInfo *info);
 ssize_t cpu_get_note_size(int class, int machine, int nr_cpus);
 
qom/cpu.c +44 -0

50 lines not on this page · raw message

target-s390x/arch_dump.c +4 -21
index 18f2652..c594874 100644
@@ -13,6 +13,7 @@
 
 #include "cpu.h"
 #include "elf.h"
+#include "arch_dump.h"
 #include "exec/cpu-all.h"
 #include "sysemu/dump.h"
 #include "sysemu/kvm.h"
@@ -186,10 +187,11 @@ static int s390x_write_all_elf64_notes(const char *note_name, write_core_dump_fu
 }
 
 
-int cpu_write_elf64_note(write_core_dump_function f, CPUArchState *env,
+int s390_cpu_write_elf64_note(write_core_dump_function f, CPUState *cpu,
                          int cpuid, void *opaque)
 {
-    return s390x_write_all_elf64_notes("CORE", f, env, cpuid, opaque);
+    S390CPU *_cpu = S390_CPU(cpu);
+    return s390x_write_all_elf64_notes("CORE", f, &_cpu->env, cpuid, opaque);
 }
 
 int cpu_get_dump_info(ArchDumpInfo *info)
@@ -222,25 +224,6 @@ ssize_t cpu_get_note_size(int class, int machine, int nr_cpus)
 
 }
 
-int cpu_write_elf32_note(write_core_dump_function f, CPUArchState *env,
-                         int cpuid, void *opaque)
-{
-    return 0;
-}
-
-
-int cpu_write_elf64_qemunote(write_core_dump_function f, CPUArchState *env,
-                             void *opaque)
-{
-    return 0;
-}
-
-int cpu_write_elf32_qemunote(write_core_dump_function f, CPUArchState *env,
-                             void *opaque)
-{
-    return 0;
-}
-
 int arch_check_parameter(bool paging, bool has_filter, int64_t begin, int64_t length, 
                           Error **errp)
 {
target-s390x/arch_dump.h new file +14 -0
new file mode 100644
index 0000000..8ebc24e
@@ -0,0 +1,14 @@
+/*
+ * dump guest memory implementation 
+ *
+ * Copyright 2012 IBM Corp.
+ * Author(s): Jens Freimann <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or (at
+ * your option) any later version. See the COPYING file in the top-level
+ * directory.
+ */
+
+int s390_cpu_write_elf64_note(write_core_dump_function f, CPUState *cpu,
+                         int cpuid, void *opaque);
+
target-s390x/cpu.c +6 -0
index 14a9e9d..14b25d8 100644
@@ -27,6 +27,7 @@
 #include "qemu-common.h"
 #include "qemu/timer.h"
 #include "hw/hw.h"
+#include "arch_dump.h"
 #ifndef CONFIG_USER_ONLY
 #include "hw/s390x/sclp.h"
 #include "sysemu/arch_init.h"
@@ -231,6 +232,11 @@ static void s390_cpu_class_init(ObjectClass *oc, void *data)
     scc->parent_reset = cc->reset;
     cc->reset = s390_cpu_reset;
 
+    cc->write_elf64_note = s390_cpu_write_elf64_note;
+    cc->write_elf64_qemunote = NULL;
+    cc->write_elf32_note = NULL;
+    cc->write_elf32_qemunote = NULL;
+
     dc->vmsd = &vmstate_s390_cpu;
 }
 
Signature · 1 line
1.8.0.1
#21 lore raw

Re: [Qemu-devel] [RFC] make write_elf_xx functions part of CPUClass, use CPUState

Hi Jens,

Am 09.04.2013 14:09, schrieb Jens Freimann:

Quoted 8 lines

Hi Andreas,

not sure if this is what you had in mind. Does it at least go into the right direction? It is pretty much untested and won't compile as is. I just wanted to get your opinion before putting more work into this.

This patch adds 4 write_elf_XX functions to the CPUClass which can be implemented by XXXCPUState, e.g. S390CPUstate.

That is mostly like I expected it, comments inline.

Quoted 3 lines

Would it make sense to have paging_enabled/HAVE_MEMORY_MAPPING also as a property of the CPU object?

Hm, I don't think QOM properties make much sense for the internal restructuring - I'm not sure if we already have some indication whether this can be used from QMP for a given target? That would be the only use case for HAVE_MEMORY_MAPPING as QOM property that I could think of. for paging_enabled() I think the only users would be internal so this could be a QOM method/function just like the write_* functions.

Quoted 25 lines
---
 dump.c                   | 28 +++++++++++++++++++++++----
 include/qom/cpu.h        | 49 ++++++++++++++++++++++++++++++++++++++++++++++++
 include/sysemu/dump.h    |  9 +--------
 qom/cpu.c                | 44 +++++++++++++++++++++++++++++++++++++++++++
 target-s390x/arch_dump.c | 25 ++++--------------------
 target-s390x/arch_dump.h | 14 ++++++++++++++
 target-s390x/cpu.c       |  6 ++++++
 7 files changed, 142 insertions(+), 33 deletions(-)
 create mode 100644 target-s390x/arch_dump.h
dump.c +1 -0
index 574c292..df49845 100644
@@ -272,13 +272,19 @@ static int write_elf64_notes(DumpState *s)
 {
     CPUArchState *env;
     CPUState *cpu;
+    CPUClass *cc;
     int ret;
     int id;
 

dump.c static int write_elf64_notes(DumpState *s) · line 287

Quoted 10 lines
dump.c +6 -1
     for (env = first_cpu; env != NULL; env = env->next_cpu) {
         cpu = ENV_GET_CPU(env);
+        cc = CPU_GET_CLASS(cpu);
         id = cpu_index(cpu);
-        ret = cpu_write_elf64_note(fd_write_vmcore, env, id, s);
+        if (cc->write_elf64_note)
+            ret = cc->write_elf64_note(fd_write_vmcore, cpu, id, s);
+        else {
+            ret = 0;
+        }

Why are you changing the logic here?

dump.c static int write_elf64_notes(DumpState *s) · line 299

Quoted 13 lines
dump.c +5 -1
         if (ret < 0) {
             dump_error(s, "dump: failed to write elf notes.\n");
             return -1;
@@ -286,7 +292,11 @@ static int write_elf64_notes(DumpState *s)
     }
 
     for (env = first_cpu; env != NULL; env = env->next_cpu) {
-        ret = cpu_write_elf64_qemunote(fd_write_vmcore, env, s);
+        if (cc->write_elf64_qemunote)
+            ret = cc->write_elf64_qemunote(fd_write_vmcore, cpu, s);
+        else {
+            ret = 0;
+        }

Dito?

Quoted 11 lines
dump.c +1 -0
         if (ret < 0) {
             dump_error(s, "dump: failed to write CPU status.\n");
             return -1;
@@ -324,13 +334,19 @@ static int write_elf32_notes(DumpState *s)
 {
     CPUArchState *env;
     CPUState *cpu;
+    CPUClass *cc;
     int ret;
     int id;
 

dump.c static int write_elf32_notes(DumpState *s) · line 349

Quoted 10 lines
dump.c +6 -1
     for (env = first_cpu; env != NULL; env = env->next_cpu) {
         cpu = ENV_GET_CPU(env);
+        cc = CPU_GET_CLASS(cpu);
         id = cpu_index(cpu);
-        ret = cpu_write_elf32_note(fd_write_vmcore, env, id, s);
+        if (cc->write_elf32_note) {
+            ret = cc->write_elf32_note(fd_write_vmcore, cpu, id, s);
+        } else {
+            ret = 0; 
+        }

Dito?

dump.c static int write_elf32_notes(DumpState *s) · line 361

Quoted 13 lines
dump.c +5 -1
         if (ret < 0) {
             dump_error(s, "dump: failed to write elf notes.\n");
             return -1;
@@ -338,7 +354,11 @@ static int write_elf32_notes(DumpState *s)
     }
 
     for (env = first_cpu; env != NULL; env = env->next_cpu) {
-        ret = cpu_write_elf32_qemunote(fd_write_vmcore, env, s);
+        if (cc->write_elf32_qemunote) {
+            ret = cc->write_elf32_qemunote(fd_write_vmcore, cpu, s);
+        } else {
+            ret = 0; 
+        }

Dito?

include/qom/cpu.h line 27

Quoted 12 lines
dump.c +0 -0
         if (ret < 0) {
             dump_error(s, "dump: failed to write CPU status.\n");
             return -1;
include/qom/cpu.h +1 -0
index ab2657c..53199f1 100644
@@ -24,6 +24,8 @@
 #include "hw/qdev-core.h"
 #include "qemu/thread.h"
 
+typedef int (*write_core_dump_function)(void *buf, size_t size, void *opaque);

You're only copying it (which may lead to duplicate typedef warnings btw) but it would be nice to name it WriteCoreDump or so here.

Quoted 134 lines
include/qom/cpu.h +48 -0
+
 /**
  * SECTION:cpu
  * @section_id: QEMU-cpu
@@ -55,6 +57,14 @@ typedef struct CPUClass {
     ObjectClass *(*class_by_name)(const char *cpu_model);
 
     void (*reset)(CPUState *cpu);
+    int (*write_elf64_note)(write_core_dump_function f, CPUState *cpu,
+            int cpuid, void *opaque);
+    int (*write_elf64_qemunote)(write_core_dump_function f, CPUState *cpu,
+            void *opaque);
+    int (*write_elf32_note)(write_core_dump_function f, CPUState *cpu,
+            int cpuid, void *opaque);
+    int (*write_elf32_qemunote)(write_core_dump_function f, CPUState *cpu,
+            void *opaque);
 } CPUClass;
 
 struct KVMState;
@@ -116,6 +126,45 @@ struct CPUState {
     int cpu_index; /* used by alpha TCG */
 };
 
+/**
+ * cpu_write_elf64_note:
+ * @f: pointer to a function that writes memory to a file 
+ * @cpu: The CPU whose memory is to be dumped
+ * @cpuid: ID number of the CPU 
+ * @opaque: pointer to the CPUState struct
+ */
+int cpu_write_elf64_note(write_core_dump_function f, CPUState *cpu,
+        int cpuid, void *opaque);
+
+/**
+ * cpu_write_elf64_qemunote:
+ * @f: pointer to a function that writes memory to a file 
+ * @cpu: The CPU whose memory is to be dumped
+ * @cpuid: ID number of the CPU 
+ * @opaque: pointer to the CPUState struct
+ */
+int cpu_write_elf64_qemunote(write_core_dump_function f, CPUState *cpu,
+        void *opaque);
+
+/**
+ * cpu_write_elf32_note:
+ * @f: pointer to a function that writes memory to a file 
+ * @cpu: The CPU whose memory is to be dumped
+ * @cpuid: ID number of the CPU 
+ * @opaque: pointer to the CPUState struct
+ */
+int cpu_write_elf32_note(write_core_dump_function f, CPUState *cpu,
+        int cpuid, void *opaque);
+
+/**
+ * cpu_write_elf32_qemunote:
+ * @f: pointer to a function that writes memory to a file 
+ * @cpu: The CPU whose memory is to be dumped
+ * @cpuid: ID number of the CPU 
+ * @opaque: pointer to the CPUState struct
+ */
+int cpu_write_elf32_qemunote(write_core_dump_function f, CPUState *cpu,
+        void *opaque);
 
 /**
  * cpu_reset:
include/sysemu/dump.h +1 -8
index b03efd4..e5f9f7d 100644
@@ -16,6 +16,7 @@
 
 #include "qapi/error.h"
 #include "include/qapi/qmp/qerror.h"
+#include "qom/cpu.h"
 
 typedef struct ArchDumpInfo {
     int d_machine;  /* Architecture */
@@ -24,14 +25,6 @@ typedef struct ArchDumpInfo {
 } ArchDumpInfo;
 
 typedef int (*write_core_dump_function)(void *buf, size_t size, void *opaque);
-int cpu_write_elf64_note(write_core_dump_function f, CPUArchState *env,
-                                                  int cpuid, void *opaque);
-int cpu_write_elf32_note(write_core_dump_function f, CPUArchState *env,
-                                                  int cpuid, void *opaque);
-int cpu_write_elf64_qemunote(write_core_dump_function f, CPUArchState *env,
-                                                          void *opaque);
-int cpu_write_elf32_qemunote(write_core_dump_function f, CPUArchState *env,
-                                                          void *opaque);
 int cpu_get_dump_info(ArchDumpInfo *info);
 ssize_t cpu_get_note_size(int class, int machine, int nr_cpus);
 
qom/cpu.c +34 -0
index 0a2194d..e2822d0 100644
@@ -21,6 +21,50 @@
 #include "qom/cpu.h"
 #include "qemu-common.h"
 
+int cpu_write_elf32_qemunote(write_core_dump_function f, CPUState *cpu,
+        void *opaque)
+{
+    CPUClass *klass = CPU_GET_CLASS(cpu);
+
+    if (klass->write_elf32_qemunote != NULL) {
+        return (*klass->write_elf32_qemunote)(f, cpu, opaque);
+    }
+    return -1;
+}
+
+int cpu_write_elf32_note(write_core_dump_function f, CPUState *cpu,
+        int cpuid, void *opaque)
+{
+    CPUClass *klass = CPU_GET_CLASS(cpu);
+
+    if (klass->write_elf32_note != NULL) {
+        return (*klass->write_elf32_note)(f, cpu, cpuid, opaque);
+    }
+    return -1;
+}
+
+int cpu_write_elf64_qemunote(write_core_dump_function f, CPUState *cpu,
+        void *opaque)
+{
+    CPUClass *klass = CPU_GET_CLASS(cpu);
+
+    if (klass->write_elf64_note != NULL) {
+        return (*klass->write_elf64_qemunote)(f, cpu, opaque);
+    }
+    return -1;
+}
+
+int cpu_write_elf64_note(write_core_dump_function f, CPUState *cpu,

qom/cpu.c line 67

Quoted 10 lines
qom/cpu.c +10 -0
+        int cpuid, void *opaque)
+{
+    CPUClass *klass = CPU_GET_CLASS(cpu);
+
+    if (klass->write_elf64_note != NULL) {
+        return (*klass->write_elf64_note)(f, cpu, cpuid, opaque);
+    }
+    return -1;
+}
+

I would rather make these four totally trivial, passing through the return value always. See below.

Quoted 16 lines
qom/cpu.c +0 -0
 void cpu_reset(CPUState *cpu)
 {
     CPUClass *klass = CPU_GET_CLASS(cpu);
target-s390x/arch_dump.c +1 -0
index 18f2652..c594874 100644
@@ -13,6 +13,7 @@
 
 #include "cpu.h"
 #include "elf.h"
+#include "arch_dump.h"
 #include "exec/cpu-all.h"
 #include "sysemu/dump.h"
 #include "sysemu/kvm.h"

target-s390x/arch_dump.c static int s390x_write_all_elf64_notes(const char *note_name, write_core_dump_fu · line 193

Quoted 9 lines
target-s390x/arch_dump.c +2 -2
@@ -186,10 +187,11 @@ static int s390x_write_all_elf64_notes(const char *note_name, write_core_dump_fu
 }
 
 
-int cpu_write_elf64_note(write_core_dump_function f, CPUArchState *env,
+int s390_cpu_write_elf64_note(write_core_dump_function f, CPUState *cpu,
                          int cpuid, void *opaque)
 {
-    return s390x_write_all_elf64_notes("CORE", f, env, cpuid, opaque);
+    S390CPU *_cpu = S390_CPU(cpu);

To avoid this name conflict, please name the argument "cs" above, then this can be just "cpu".

Quoted 39 lines
target-s390x/arch_dump.c +1 -19
+    return s390x_write_all_elf64_notes("CORE", f, &_cpu->env, cpuid, opaque);
 }
 
 int cpu_get_dump_info(ArchDumpInfo *info)
@@ -222,25 +224,6 @@ ssize_t cpu_get_note_size(int class, int machine, int nr_cpus)
 
 }
 
-int cpu_write_elf32_note(write_core_dump_function f, CPUArchState *env,
-                         int cpuid, void *opaque)
-{
-    return 0;
-}
-
-
-int cpu_write_elf64_qemunote(write_core_dump_function f, CPUArchState *env,
-                             void *opaque)
-{
-    return 0;
-}
-
-int cpu_write_elf32_qemunote(write_core_dump_function f, CPUArchState *env,
-                             void *opaque)
-{
-    return 0;
-}
-
 int arch_check_parameter(bool paging, bool has_filter, int64_t begin, int64_t length, 
                           Error **errp)
 {
target-s390x/arch_dump.h new file +3 -0
new file mode 100644
index 0000000..8ebc24e
@@ -0,0 +1,14 @@
+/*
+ * dump guest memory implementation 
+ *

target-s390x/arch_dump.h line 13

Quoted 10 lines
target-s390x/arch_dump.h new file +10 -0
+ * Copyright 2012 IBM Corp.
+ * Author(s): Jens Freimann <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or (at
+ * your option) any later version. See the COPYING file in the top-level
+ * directory.
+ */
+
+int s390_cpu_write_elf64_note(write_core_dump_function f, CPUState *cpu,
+                         int cpuid, void *opaque);

Suggest to place this into cpu-qom.h if not much more gets added to it.

Quoted 14 lines
target-s390x/arch_dump.h new file +1 -0
+
target-s390x/cpu.c +1 -0
index 14a9e9d..14b25d8 100644
@@ -27,6 +27,7 @@
 #include "qemu-common.h"
 #include "qemu/timer.h"
 #include "hw/hw.h"
+#include "arch_dump.h"
 #ifndef CONFIG_USER_ONLY
 #include "hw/s390x/sclp.h"
 #include "sysemu/arch_init.h"

target-s390x/cpu.c static void s390_cpu_class_init(ObjectClass *oc, void *data) · line 238

Quoted 7 lines
target-s390x/cpu.c +4 -0
@@ -231,6 +232,11 @@ static void s390_cpu_class_init(ObjectClass *oc, void *data)
     scc->parent_reset = cc->reset;
     cc->reset = s390_cpu_reset;
 
+    cc->write_elf64_note = s390_cpu_write_elf64_note;
+    cc->write_elf64_qemunote = NULL;
+    cc->write_elf32_note = NULL;
+    cc->write_elf32_qemunote = NULL;

Suggest to avoid NULL functions by implementing dummy versions in qom/cpu.c, which return a value compatible with its call sites. Then s390x etc. only overwrite the functions whose functionality they wish to override, keeping the call sites (both wrappers and their callers) simpler.

cc->paging_enabled (or so) should also get overridden here.

And quite obviously this RFC is based on top of the s390x patch whereas I was hoping to insert this rework before, to simplify both arm and s390x patches.

Regards,
Andreas

Quoted 5 lines
target-s390x/cpu.c +1 -0
+
     dc->vmsd = &vmstate_s390_cpu;
 }
 
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#22 lore raw

cover qom: make cpu_write_elfXX_ functions part of CPUClass

Hi Andreas,

I have two patches to make dump-guest-memory related cpu_write_elfxx_note functions members of CPUClass and pass CPUstate as an argument instead of CPUArchState.

This is preparation for s390 patches which will follow on Monday.

Jens Freimann (2):
qom: Convert cpu_write_elfXX_note functions to CPUState
i386: use CPUClass->write_elf* functions

 dump-stub.c             | 28 ----------------------------
 dump.c                  |  8 ++++----
 include/qom/cpu.h       | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 include/sysemu/dump.h   |  9 ---------
 qom/cpu.c               | 32 ++++++++++++++++++++++++++++++++
 target-i386/arch_dump.c | 25 +++++++++++++------------
 target-i386/cpu-qom.h   |  9 +++++++++
 target-i386/cpu.c       |  7 +++++++
 8 files changed, 114 insertions(+), 53 deletions(-)
Signature · 1 line
1.7.12.4
#23 lore raw

PATCH 1/2 qom: Convert cpu_write_elfXX_note functions to CPUState

Convert cpu_write_elfXX_note functions to CPUClass methods and pass CPUState as argument

---
 dump-stub.c           | 28 ----------------------------
 dump.c                |  8 ++++----
 include/qom/cpu.h     | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 include/sysemu/dump.h |  8 --------
 qom/cpu.c             | 32 ++++++++++++++++++++++++++++++++
 5 files changed, 85 insertions(+), 40 deletions(-)
dump-stub.c +0 -28
index a9d0b3c..b3f42cb 100644
@@ -24,34 +24,6 @@ void qmp_dump_guest_memory(bool paging, const char *file, bool has_begin,
     error_set(errp, QERR_UNSUPPORTED);
 }
 
-int cpu_write_elf64_note(write_core_dump_function f,
-                                       CPUArchState *env, int cpuid,
-                                       void *opaque)
-{
-    return -1;
-}
-
-int cpu_write_elf32_note(write_core_dump_function f,
-                                       CPUArchState *env, int cpuid,
-                                       void *opaque)
-{
-    return -1;
-}
-
-int cpu_write_elf64_qemunote(write_core_dump_function f,
-                                           CPUArchState *env,
-                                           void *opaque)
-{
-    return -1;
-}
-
-int cpu_write_elf32_qemunote(write_core_dump_function f,
-                                           CPUArchState *env,
-                                           void *opaque)
-{
-    return -1;
-}
-
 int cpu_get_dump_info(ArchDumpInfo *info)
 {
     return -1;
dump.c +4 -4
index b34f143..c0d3da5 100644
@@ -282,7 +282,7 @@ static int write_elf64_notes(DumpState *s)
     for (env = first_cpu; env != NULL; env = env->next_cpu) {
         cpu = ENV_GET_CPU(env);
         id = cpu_index(cpu);
-        ret = cpu_write_elf64_note(fd_write_vmcore, env, id, s);
+        ret = cpu_write_elf64_note(fd_write_vmcore, cpu, id, s);
         if (ret < 0) {
             dump_error(s, "dump: failed to write elf notes.\n");
             return -1;
@@ -290,7 +290,7 @@ static int write_elf64_notes(DumpState *s)
     }
 
     for (env = first_cpu; env != NULL; env = env->next_cpu) {
-        ret = cpu_write_elf64_qemunote(fd_write_vmcore, env, s);
+        ret = cpu_write_elf64_qemunote(fd_write_vmcore, cpu, s);
         if (ret < 0) {
             dump_error(s, "dump: failed to write CPU status.\n");
             return -1;
@@ -334,7 +334,7 @@ static int write_elf32_notes(DumpState *s)
     for (env = first_cpu; env != NULL; env = env->next_cpu) {
         cpu = ENV_GET_CPU(env);
         id = cpu_index(cpu);
-        ret = cpu_write_elf32_note(fd_write_vmcore, env, id, s);
+        ret = cpu_write_elf32_note(fd_write_vmcore, cpu, id, s);
         if (ret < 0) {
             dump_error(s, "dump: failed to write elf notes.\n");
             return -1;
@@ -342,7 +342,7 @@ static int write_elf32_notes(DumpState *s)
     }
 
     for (env = first_cpu; env != NULL; env = env->next_cpu) {
-        ret = cpu_write_elf32_qemunote(fd_write_vmcore, env, s);
+        ret = cpu_write_elf32_qemunote(fd_write_vmcore, cpu, s);
         if (ret < 0) {
             dump_error(s, "dump: failed to write CPU status.\n");
             return -1;
include/qom/cpu.h +49 -0

67 lines not on this page · raw message

include/sysemu/dump.h +0 -8
index e25b7cf..75823e5 100644
@@ -21,14 +21,6 @@ typedef struct ArchDumpInfo {
 } ArchDumpInfo;
 
 typedef int (*write_core_dump_function)(void *buf, size_t size, void *opaque);
-int cpu_write_elf64_note(write_core_dump_function f, CPUArchState *env,
-                                                  int cpuid, void *opaque);
-int cpu_write_elf32_note(write_core_dump_function f, CPUArchState *env,
-                                                  int cpuid, void *opaque);
-int cpu_write_elf64_qemunote(write_core_dump_function f, CPUArchState *env,
-                                                          void *opaque);
-int cpu_write_elf32_qemunote(write_core_dump_function f, CPUArchState *env,
-                                                          void *opaque);
 int cpu_get_dump_info(ArchDumpInfo *info);
 ssize_t cpu_get_note_size(int class, int machine, int nr_cpus);
 
qom/cpu.c +32 -0
index e242dcb..aacc057 100644
@@ -26,6 +26,38 @@ void cpu_reset_interrupt(CPUState *cpu, int mask)
     cpu->interrupt_request &= ~mask;
 }
 
+int cpu_write_elf32_qemunote(WriteCoreDumpFunction f, CPUState *cpu,
+        void *opaque)
+{
+    CPUClass *klass = CPU_GET_CLASS(cpu);
+
+    return (*klass->write_elf32_qemunote)(f, cpu, opaque);
+}
+
+int cpu_write_elf32_note(WriteCoreDumpFunction f, CPUState *cpu,
+        int cpuid, void *opaque)
+{
+    CPUClass *klass = CPU_GET_CLASS(cpu);
+
+    return (*klass->write_elf32_note)(f, cpu, cpuid, opaque);
+}
+
+int cpu_write_elf64_qemunote(WriteCoreDumpFunction f, CPUState *cpu,
+        void *opaque)
+{
+    CPUClass *klass = CPU_GET_CLASS(cpu);
+
+    return (*klass->write_elf64_qemunote)(f, cpu, opaque);
+}
+
+int cpu_write_elf64_note(WriteCoreDumpFunction f, CPUState *cpu,
+        int cpuid, void *opaque)
+{
+    CPUClass *klass = CPU_GET_CLASS(cpu);
+
+    return (*klass->write_elf64_note)(f, cpu, cpuid, opaque);
+}
+
 void cpu_reset(CPUState *cpu)
 {
     CPUClass *klass = CPU_GET_CLASS(cpu);
Signature · 1 line
1.7.12.4
#24 lore raw

PATCH 2/2 i386: use CPUClass->write_elf* functions

In reply to Jens Freimann

Rework dump-guest-memory support to implement write_elfXX_note methods of CPUClass.

---
 include/sysemu/dump.h   |  1 -
 target-i386/arch_dump.c | 25 +++++++++++++------------
 target-i386/cpu-qom.h   |  9 +++++++++
 target-i386/cpu.c       |  7 +++++++
 4 files changed, 29 insertions(+), 13 deletions(-)
include/sysemu/dump.h +0 -1
index 75823e5..b8c770f 100644
@@ -20,7 +20,6 @@ typedef struct ArchDumpInfo {
     int d_class;    /* ELFCLASS32 or ELFCLASS64 */
 } ArchDumpInfo;
 
-typedef int (*write_core_dump_function)(void *buf, size_t size, void *opaque);
 int cpu_get_dump_info(ArchDumpInfo *info);
 ssize_t cpu_get_note_size(int class, int machine, int nr_cpus);
 
target-i386/arch_dump.c +13 -12
index 2cd2f7f..dfd23cd 100644
@@ -15,6 +15,7 @@
 #include "exec/cpu-all.h"
 #include "sysemu/dump.h"
 #include "elf.h"
+#include "qom/cpu.h"
 
 #ifdef TARGET_X86_64
 typedef struct {
@@ -34,7 +35,7 @@ typedef struct {
     char pad3[8];
 } x86_64_elf_prstatus;
 
-static int x86_64_write_elf64_note(write_core_dump_function f,
+static int x86_64_write_elf64_note(WriteCoreDumpFunction f,
                                    CPUArchState *env, int id,
                                    void *opaque)
 {
@@ -144,7 +145,7 @@ static void x86_fill_elf_prstatus(x86_elf_prstatus *prstatus, CPUArchState *env,
     prstatus->pid = id;
 }
 
-static int x86_write_elf64_note(write_core_dump_function f, CPUArchState *env,
+static int x86_write_elf64_note(WriteCoreDumpFunction f, CPUArchState *env,
                                 int id, void *opaque)
 {
     x86_elf_prstatus prstatus;
@@ -179,7 +180,7 @@ static int x86_write_elf64_note(write_core_dump_function f, CPUArchState *env,
     return 0;
 }
 
-int cpu_write_elf64_note(write_core_dump_function f, CPUArchState *env,
+int x86_cpu_write_elf64_note(WriteCoreDumpFunction f, CPUState *cpu,
                          int cpuid, void *opaque)
 {
     int ret;
@@ -187,10 +188,10 @@ int cpu_write_elf64_note(write_core_dump_function f, CPUArchState *env,
     bool lma = !!(first_cpu->hflags & HF_LMA_MASK);
 
     if (lma) {
-        ret = x86_64_write_elf64_note(f, env, cpuid, opaque);
+        ret = x86_64_write_elf64_note(f, cpu->env_ptr, cpuid, opaque);
     } else {
 #endif
-        ret = x86_write_elf64_note(f, env, cpuid, opaque);
+        ret = x86_write_elf64_note(f, cpu->env_ptr, cpuid, opaque);
 #ifdef TARGET_X86_64
     }
 #endif
@@ -198,7 +199,7 @@ int cpu_write_elf64_note(write_core_dump_function f, CPUArchState *env,
     return ret;
 }
 
-int cpu_write_elf32_note(write_core_dump_function f, CPUArchState *env,
+int x86_cpu_write_elf32_note(WriteCoreDumpFunction f, CPUState *cpu,
                          int cpuid, void *opaque)
 {
     x86_elf_prstatus prstatus;
@@ -208,7 +209,7 @@ int cpu_write_elf32_note(write_core_dump_function f, CPUArchState *env,
     const char *name = "CORE";
     int ret;
 
-    x86_fill_elf_prstatus(&prstatus, env, cpuid);
+    x86_fill_elf_prstatus(&prstatus, cpu->env_ptr, cpuid);
     descsz = sizeof(x86_elf_prstatus);
     note_size = ((sizeof(Elf32_Nhdr) + 3) / 4 + (name_size + 3) / 4 +
                 (descsz + 3) / 4) * 4;
@@ -317,7 +318,7 @@ static void qemu_get_cpustate(QEMUCPUState *s, CPUArchState *env)
     s->cr[4] = env->cr[4];
 }
 
-static inline int cpu_write_qemu_note(write_core_dump_function f,
+static inline int cpu_write_qemu_note(WriteCoreDumpFunction f,
                                       CPUArchState *env,
                                       void *opaque,
                                       int type)
@@ -370,16 +371,16 @@ static inline int cpu_write_qemu_note(write_core_dump_function f,
     return 0;
 }
 
-int cpu_write_elf64_qemunote(write_core_dump_function f, CPUArchState *env,
+int x86_cpu_write_elf64_qemunote(WriteCoreDumpFunction f, CPUState *cpu,
                              void *opaque)
 {
-    return cpu_write_qemu_note(f, env, opaque, 1);
+    return cpu_write_qemu_note(f, cpu->env_ptr, opaque, 1);
 }
 
-int cpu_write_elf32_qemunote(write_core_dump_function f, CPUArchState *env,
+int x86_cpu_write_elf32_qemunote(WriteCoreDumpFunction f, CPUState *cpu,
                              void *opaque)
 {
-    return cpu_write_qemu_note(f, env, opaque, 0);
+    return cpu_write_qemu_note(f, cpu->env_ptr, opaque, 0);
 }
 
 int cpu_get_dump_info(ArchDumpInfo *info)
target-i386/cpu-qom.h +9 -0
index 08f9eb6..d575b8b 100644
@@ -86,4 +86,13 @@ extern const struct VMStateDescription vmstate_x86_cpu;
  */
 void x86_cpu_do_interrupt(CPUState *cpu);
 
+int x86_cpu_write_elf64_note(WriteCoreDumpFunction f, CPUState *cpu,
+                         int cpuid, void *opaque);
+int x86_cpu_write_elf32_note(WriteCoreDumpFunction f, CPUState *cpu,
+                         int cpuid, void *opaque);
+int x86_cpu_write_elf64_qemunote(WriteCoreDumpFunction f, CPUState *cpu,
+                             void *opaque);
+int x86_cpu_write_elf32_qemunote(WriteCoreDumpFunction f, CPUState *cpu,
+                             void *opaque);
+
 #endif
target-i386/cpu.c +7 -0
index e2302d8..8e4e7a3 100644
@@ -30,6 +30,7 @@
 #include "qemu/config-file.h"
 #include "qapi/qmp/qerror.h"
 
+#include "cpu-qom.h"
 #include "qapi/visitor.h"
 #include "sysemu/arch_init.h"
 
@@ -2285,6 +2286,12 @@ static void x86_cpu_common_class_init(ObjectClass *oc, void *data)
     cc->reset = x86_cpu_reset;
 
     cc->do_interrupt = x86_cpu_do_interrupt;
+#ifndef CONFIG_USER_ONLY
+    cc->write_elf64_note = x86_cpu_write_elf64_note;
+    cc->write_elf64_qemunote = x86_cpu_write_elf64_qemunote;
+    cc->write_elf32_note = x86_cpu_write_elf32_note;
+    cc->write_elf32_qemunote = x86_cpu_write_elf32_qemunote;
+#endif
     cpu_class_set_vmsd(cc, &vmstate_x86_cpu);
 }
 
Signature · 1 line
1.7.12.4
#25 lore raw

Re: [Qemu-devel] [PATCH 0/2] qom: make cpu_write_elfXX_ functions part of CPUClass

In reply to Jens Freimann

Am 19.04.2013 16:45, schrieb Jens Freimann:

Quoted 11 lines

Hi Andreas,

I have two patches to make dump-guest-memory related cpu_write_elfxx_note functions members of CPUClass and pass CPUstate as an argument instead of CPUArchState.

This is preparation for s390 patches which will follow on Monday.

Jens Freimann (2):
qom: Convert cpu_write_elfXX_note functions to CPUState
i386: use CPUClass->write_elf* functions

Thanks, squashed and applied to qom-cpu (with changes below):
https://github.com/afaerber/qemu-cpu/commits/qom-cpu

* squashed both for bisectability
* fixed argument indentation
* s/klass/cc/g in qom/cpu.c; TODO: class_init still uses k
* dropped including cpu-qom.h in target-i386/cpu.c
* dropped including qom/cpu.h in target-i386/arch_dump.c
* retained stubs from dump-stub.c in qom/cpu.c
* target-i386: reserve "cpu" for X86CPU and avoid env_ptr usage

Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg