qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH/RFC 0/3 v2] s390 dump guest memory support
@ 2013-03-28 16:35 Jens Freimann
  2013-03-28 16:35 ` [Qemu-devel] [PATCH 1/3] s390: dump-guest-memory implementation Jens Freimann
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Jens Freimann @ 2013-03-28 16:35 UTC (permalink / raw)
  To: Alexander Graf
  Cc: Ekaterina Tumanova, qemu-devel, Rabin Vincent,
	Christian Borntraeger, Jens Freimann, Cornelia Huck,
	Andreas Färber

Hi Alex,

this is code for dump guest memory support.

About Patch 3/3:
In order to be able to have CONFIG_HAVE_GET_MEMORY_MAPPING=n
we moved the memory mapping code which is needed for both =y
and =n to a new file memory_mapping_common.c. We still have memory_mapping
support turned on in patch 1 but it is resolved in patch 3.

Ekaterina Tumanova (3):
  s390: dump-guest-memory implementation
  s390: Added check for unsupported parameters of dump-guest-memory
  s390: Split dump-guest-memory memory mapping code, drop
    CONFIG_HAVE_GET_MEMORY_MAPPING for s390

 Makefile.target                    |   2 +-
 configure                          |   4 +-
 dump.c                             |  12 +-
 include/elf.h                      |   6 +
 include/qapi/qmp/qerror.h          |   3 +
 include/sysemu/dump.h              |   6 +
 include/sysemu/memory_mapping.h    |  15 ++-
 memory_mapping-stub.c              |  14 +-
 memory_mapping.c                   |  87 +------------
 memory_mapping_common.c            | 103 +++++++++++++++
 target-i386/arch_dump.c            |   6 +
 target-s390x/Makefile.objs         |   2 +-
 target-s390x/arch_dump.c           | 254 +++++++++++++++++++++++++++++++++++++
 target-s390x/arch_memory_mapping.c |  26 ++++
 14 files changed, 434 insertions(+), 106 deletions(-)
 create mode 100644 memory_mapping_common.c
 create mode 100644 target-s390x/arch_dump.c
 create mode 100644 target-s390x/arch_memory_mapping.c

-- 
1.7.12.4

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Qemu-devel] [PATCH 1/3] s390: dump-guest-memory implementation
  2013-03-28 16:35 [Qemu-devel] [PATCH/RFC 0/3 v2] s390 dump guest memory support Jens Freimann
@ 2013-03-28 16:35 ` Jens Freimann
  2013-03-28 16:35 ` [Qemu-devel] [PATCH 2/3] s390: Added check for unsupported parameters of dump-guest-memory Jens Freimann
  2013-03-28 16:36 ` [Qemu-devel] [PATCH 3/3] s390: Split dump-guest-memory memory mapping code Jens Freimann
  2 siblings, 0 replies; 5+ messages in thread
From: Jens Freimann @ 2013-03-28 16:35 UTC (permalink / raw)
  To: Alexander Graf
  Cc: Ekaterina Tumanova, qemu-devel, Rabin Vincent,
	Christian Borntraeger, Jens Freimann, Cornelia Huck,
	Andreas Färber

From: Ekaterina Tumanova <tumanova@linux.vnet.ibm.com>

dump-guest-memory QEMU monitor command didn't work for s390 architecture.
The result of the command is supposed to be ELF format crash-readable
dump.
In order to implement this, the arch-specific part of dump-guest-memory
was added:
target-s390x/arch_dump.c contains the whole set of function for writing
Elf note sections of all types for s390x.
arch_memory_mapping.c is created to make the patch compile and run. 

Signed-off-by: Ekaterina Tumanova <tumanova@linux.vnet.ibm.com>
Signed-off-by: Jens Freimann <jfrei@linux.vnet.ibm.com>
---
 configure                          |   4 +-
 include/elf.h                      |   6 +
 target-s390x/Makefile.objs         |   2 +-
 target-s390x/arch_dump.c           | 243 +++++++++++++++++++++++++++++++++++++
 target-s390x/arch_memory_mapping.c |  26 ++++
 5 files changed, 278 insertions(+), 3 deletions(-)
 create mode 100644 target-s390x/arch_dump.c
 create mode 100644 target-s390x/arch_memory_mapping.c

diff --git a/configure b/configure
index f2af714..c082917 100755
--- a/configure
+++ b/configure
@@ -4178,7 +4178,7 @@ case "$target_arch2" in
     fi
 esac
 case "$target_arch2" in
-  i386|x86_64)
+  i386|x86_64|s390x)
     echo "CONFIG_HAVE_GET_MEMORY_MAPPING=y" >> $config_target_mak
 esac
 if test "$target_bigendian" = "yes" ; then
@@ -4188,7 +4188,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)
+    i386|x86_64|s390x)
       echo "CONFIG_HAVE_CORE_DUMP=y" >> $config_target_mak
   esac
 fi
diff --git a/include/elf.h b/include/elf.h
index a21ea53..ba4b3a7 100644
--- a/include/elf.h
+++ b/include/elf.h
@@ -1219,11 +1219,17 @@ typedef struct elf64_shdr {
 
 /* Notes used in ET_CORE */
 #define NT_PRSTATUS	1
+#define NT_FPREGSET     2
 #define NT_PRFPREG	2
 #define NT_PRPSINFO	3
 #define NT_TASKSTRUCT	4
 #define NT_AUXV		6
 #define NT_PRXFPREG     0x46e62b7f      /* copied from gdb5.1/include/elf/common.h */
+#define NT_S390_PREFIX  0x305           /* s390 prefix register */
+#define NT_S390_CTRS    0x304           /* s390 control registers */
+#define NT_S390_TODPREG 0x303           /* s390 TOD programmable register */
+#define NT_S390_TODCMP  0x302           /* s390 TOD clock comparator register */
+#define NT_S390_TIMER   0x301           /* s390 timer register */
 
 
 /* Note header in a PT_NOTE section */
diff --git a/target-s390x/Makefile.objs b/target-s390x/Makefile.objs
index 4e63417..82c79c4 100644
--- a/target-s390x/Makefile.objs
+++ b/target-s390x/Makefile.objs
@@ -1,4 +1,4 @@
 obj-y += translate.o helper.o cpu.o interrupt.o
 obj-y += int_helper.o fpu_helper.o cc_helper.o mem_helper.o misc_helper.o
-obj-$(CONFIG_SOFTMMU) += ioinst.o
+obj-$(CONFIG_SOFTMMU) += ioinst.o arch_dump.o arch_memory_mapping.o
 obj-$(CONFIG_KVM) += kvm.o
diff --git a/target-s390x/arch_dump.c b/target-s390x/arch_dump.c
new file mode 100644
index 0000000..d8fa158
--- /dev/null
+++ b/target-s390x/arch_dump.c
@@ -0,0 +1,243 @@
+/*
+ * writing ELF notes for s390x arch
+ *
+ *  
+ * Copyright IBM Corp. 2012
+ *
+ *     Ekaterina Tumanova <tumanova@linux.vnet.ibm.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ *
+ */
+
+#include "cpu.h"
+#include "elf.h"
+#include "exec/cpu-all.h"
+#include "sysemu/dump.h"
+#include "sysemu/kvm.h"
+
+
+struct s390x_user_regs_struct {
+    uint64_t        psw[2];
+    uint64_t        gprs[16];
+    uint32_t        acrs[16];
+} QEMU_PACKED;
+
+typedef struct s390x_user_regs_struct s390x_user_regs;
+
+struct s390x_elf_prstatus_struct {
+    uint8_t pad1[32];
+    uint32_t pid;
+    uint8_t pad2[76];
+    s390x_user_regs regs;
+    uint8_t pad3[16];
+} QEMU_PACKED;
+
+typedef struct s390x_elf_prstatus_struct s390x_elf_prstatus;
+
+struct s390x_elf_fpregset_struct {
+        uint32_t        fpc;
+        uint32_t        pad;
+        uint64_t        fprs[16];
+} QEMU_PACKED;
+
+typedef struct s390x_elf_fpregset_struct s390x_elf_fpregset;
+
+    typedef struct note_struct {
+        Elf64_Nhdr hdr;
+        char name[5];
+        char pad3[3];
+	union {
+            s390x_elf_prstatus prstatus;
+            s390x_elf_fpregset fpregset;
+            uint32_t prefix;
+            uint64_t timer;
+            uint64_t todcmp;
+            uint32_t todpreg;
+            uint64_t ctrs[16];
+        } contents;
+    } QEMU_PACKED note_t;
+
+static int s390x_write_elf64_prstatus(note_t *note, CPUArchState *env)
+{
+    int i;
+    s390x_user_regs *regs;
+
+    note->hdr.n_type = cpu_to_be32(NT_PRSTATUS);
+
+    regs = &(note->contents.prstatus.regs);
+    regs->psw[0] =  cpu_to_be32(env->psw.mask);
+    regs->psw[1] =  cpu_to_be32(env->psw.addr);
+    for (i = 0; i <= 15; i++) {
+        regs->acrs[i] = cpu_to_be32(env->aregs[i]);
+        regs->gprs[i] = cpu_to_be32(env->regs[i]);
+    }
+
+    return 0;
+}
+
+static int s390x_write_elf64_fpregset(note_t *note, CPUArchState *env)
+{
+    int i;
+
+    note->hdr.n_type = cpu_to_be32(NT_FPREGSET);
+
+    note->contents.fpregset.fpc = cpu_to_be32(env->fpc);
+    for (i = 0; i <= 15; i++) {
+        note->contents.fpregset.fprs[i] =  cpu_to_be64(env->fregs[i].ll);
+    }
+
+    return 0;
+}
+
+
+static int s390x_write_elf64_timer(note_t *note, CPUArchState *env)
+{
+    note->hdr.n_type = cpu_to_be32(NT_S390_TIMER);
+
+    note->contents.timer = cpu_to_be64((uint64_t)(env->cputm));
+
+    return 0;
+}
+
+static int s390x_write_elf64_todcmp(note_t *note, CPUArchState *env)
+{
+    note->hdr.n_type = cpu_to_be32(NT_S390_TODCMP);
+
+    note->contents.todcmp = cpu_to_be64((uint64_t)(env->ckc));
+
+    return 0;
+}
+
+static int s390x_write_elf64_todpreg(note_t *note, CPUArchState *env)
+{
+    note->hdr.n_type = cpu_to_be32(NT_S390_TODPREG);
+
+    note->contents.todpreg = cpu_to_be32((uint32_t)(env->todpr));
+
+    return 0;
+}
+
+static int s390x_write_elf64_ctrs(note_t *note, CPUArchState *env)
+{
+    int i;
+
+    note->hdr.n_type = cpu_to_be32(NT_S390_CTRS);
+
+    for (i = 0; i <= 15; i++) {
+        note->contents.ctrs[i] =  cpu_to_be32(env->cregs[i]);
+    }
+
+    return 0;
+}
+
+static int s390x_write_elf64_prefix(note_t *note, CPUArchState *env)
+{
+    note->hdr.n_type = cpu_to_be32(NT_S390_PREFIX);
+
+    note->contents.prefix = cpu_to_be32((uint32_t)(env->psa));
+
+    return 0;
+}
+
+
+struct note_func_desc_struct {
+    int contents_size;
+    int (*note_contents_func)(note_t *note, CPUArchState *env);
+} note_func[] = {
+                   { sizeof(((note_t *)0)->contents.prstatus), s390x_write_elf64_prstatus },
+                   { sizeof(((note_t *)0)->contents.prefix),   s390x_write_elf64_prefix },
+                   { sizeof(((note_t *)0)->contents.fpregset), s390x_write_elf64_fpregset },
+                   { sizeof(((note_t *)0)->contents.ctrs),     s390x_write_elf64_ctrs },
+                   { sizeof(((note_t *)0)->contents.timer),    s390x_write_elf64_timer },
+                   { sizeof(((note_t *)0)->contents.todcmp),   s390x_write_elf64_todcmp },
+                   { sizeof(((note_t *)0)->contents.todpreg),  s390x_write_elf64_todpreg },
+
+                   { 0, NULL}
+                 };
+
+
+static int s390x_write_all_elf64_notes(const char *note_name, write_core_dump_function f,
+                                   CPUArchState *env, int id,
+                                   void *opaque)
+{
+    note_t note;
+    struct note_func_desc_struct *nf;
+    int note_size;
+    int ret = -1;
+
+    for (nf = note_func; nf->note_contents_func; nf++) {
+        note.hdr.n_namesz = cpu_to_be32(sizeof(note.name));
+        note.hdr.n_descsz = cpu_to_be32(nf->contents_size);
+        strncpy(note.name, note_name, sizeof(note.name));
+        ret = (*nf->note_contents_func)(&note, env);
+
+        note_size = cpu_to_be32(sizeof(note) - sizeof(note.contents) + nf->contents_size);
+        ret = f(&note, note_size, opaque);
+
+        if (ret < 0) {
+            return -1;
+        }
+
+    }
+
+    return 0;
+}
+
+
+int cpu_write_elf64_note(write_core_dump_function f, CPUArchState *env,
+                         int cpuid, void *opaque)
+{
+    return s390x_write_all_elf64_notes("CORE", f, env, cpuid, opaque);
+}
+
+int cpu_get_dump_info(ArchDumpInfo *info)
+{
+    info->d_machine = EM_S390;
+    info->d_endian = ELFDATA2MSB;
+    info->d_class = ELFCLASS64;
+
+    return 0;
+}
+
+ssize_t cpu_get_note_size(int class, int machine, int nr_cpus)
+{
+    int name_size = 8; /* "CORE" or "QEMU" rounded*/
+    size_t elf_note_size = 0;
+    int note_head_size;
+    struct note_func_desc_struct *nf;
+
+    assert (class == ELFCLASS64);
+    note_head_size = sizeof(Elf64_Nhdr);
+
+    assert (machine == EM_S390);
+
+    for (nf = note_func; nf->note_contents_func; nf++) {
+         elf_note_size = elf_note_size + note_head_size + name_size + nf->contents_size;
+
+    }
+
+    return (elf_note_size) * 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;
+}
+
diff --git a/target-s390x/arch_memory_mapping.c b/target-s390x/arch_memory_mapping.c
new file mode 100644
index 0000000..3dad3b9
--- /dev/null
+++ b/target-s390x/arch_memory_mapping.c
@@ -0,0 +1,26 @@
+/*
+ * s390x memory mapping
+ *
+ * Copyright IBM Corp. 2012
+ *
+ * Authors:
+ *     Ekaterina Tumanova <tumanova@linux.vnet.ibm.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ *
+ */
+
+#include "cpu.h"
+#include "exec/cpu-all.h"
+#include "sysemu/memory_mapping.h"
+
+int cpu_get_memory_mapping(MemoryMappingList *list, CPUArchState *env)
+{
+    return 0;
+}
+
+bool cpu_paging_enabled(CPUArchState *env)
+{
+    return false;
+}
-- 
1.7.12.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [Qemu-devel] [PATCH 2/3] s390: Added check for unsupported parameters of dump-guest-memory
  2013-03-28 16:35 [Qemu-devel] [PATCH/RFC 0/3 v2] s390 dump guest memory support Jens Freimann
  2013-03-28 16:35 ` [Qemu-devel] [PATCH 1/3] s390: dump-guest-memory implementation Jens Freimann
@ 2013-03-28 16:35 ` Jens Freimann
  2013-03-28 16:36 ` [Qemu-devel] [PATCH 3/3] s390: Split dump-guest-memory memory mapping code Jens Freimann
  2 siblings, 0 replies; 5+ messages in thread
From: Jens Freimann @ 2013-03-28 16:35 UTC (permalink / raw)
  To: Alexander Graf
  Cc: Ekaterina Tumanova, Ekaterina Tumanova, qemu-devel, Rabin Vincent,
	Christian Borntraeger, Jens Freimann, Cornelia Huck,
	Andreas Färber

From: Ekaterina Tumanova <tumanova_ek@ru.ibm.com>

Check for the 'begin' and 'length' parameters of dump-guest-memory monitor
command (not supported for s390) was placed into arch specific function:
arch_check_parameter.  The stub of this function is added to target-i386
directory for compatibility reasons.

Signed-Off-By: Ekaterina Tumanova <tumanova@linux.vnet.ibm.com>
Signed-off-by: Jens Freimann <jfrei@linux.vnet.ibm.com>
---
 dump.c                    |  4 ++++
 include/qapi/qmp/qerror.h |  3 +++
 include/sysemu/dump.h     |  6 ++++++
 target-i386/arch_dump.c   |  6 ++++++
 target-s390x/arch_dump.c  | 11 +++++++++++
 5 files changed, 30 insertions(+)

diff --git a/dump.c b/dump.c
index a25f509..fd1d0f6 100644
--- a/dump.c
+++ b/dump.c
@@ -822,6 +822,10 @@ void qmp_dump_guest_memory(bool paging, const char *file, bool has_begin,
     DumpState *s;
     int ret;
 
+    if (arch_check_parameter(paging, has_begin, begin, length, errp) < 0) {
+       return; 
+    }
+
     if (has_begin && !has_length) {
         error_set(errp, QERR_MISSING_PARAMETER, "length");
         return;
diff --git a/include/qapi/qmp/qerror.h b/include/qapi/qmp/qerror.h
index 6c0a18d..58b7f7a 100644
--- a/include/qapi/qmp/qerror.h
+++ b/include/qapi/qmp/qerror.h
@@ -249,4 +249,7 @@ void assert_no_error(Error *err);
 #define QERR_SOCKET_CREATE_FAILED \
     ERROR_CLASS_GENERIC_ERROR, "Failed to create socket"
 
+#define QERR_UNSUPPORTED_COMMAND_OPTION \
+    ERROR_CLASS_GENERIC_ERROR, "Option(s) %s of %s command not supported for %s"
+
 #endif /* QERROR_H */
diff --git a/include/sysemu/dump.h b/include/sysemu/dump.h
index e25b7cf..b03efd4 100644
--- a/include/sysemu/dump.h
+++ b/include/sysemu/dump.h
@@ -14,6 +14,9 @@
 #ifndef DUMP_H
 #define DUMP_H
 
+#include "qapi/error.h"
+#include "include/qapi/qmp/qerror.h"
+
 typedef struct ArchDumpInfo {
     int d_machine;  /* Architecture */
     int d_endian;   /* ELFDATA2LSB or ELFDATA2MSB */
@@ -32,4 +35,7 @@ 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 arch_check_parameter(bool paging, bool has_filter, int64_t begin, int64_t length,
+                         Error **errp);
+
 #endif
diff --git a/target-i386/arch_dump.c b/target-i386/arch_dump.c
index 2cd2f7f..959a5f7 100644
--- a/target-i386/arch_dump.c
+++ b/target-i386/arch_dump.c
@@ -447,3 +447,9 @@ ssize_t cpu_get_note_size(int class, int machine, int nr_cpus)
 
     return (elf_note_size + qemu_note_size) * nr_cpus;
 }
+
+int arch_check_parameter(bool paging, bool has_filter, int64_t begin, int64_t length,
+                          Error **errp)
+{
+    return 0;
+}
diff --git a/target-s390x/arch_dump.c b/target-s390x/arch_dump.c
index d8fa158..18f2652 100644
--- a/target-s390x/arch_dump.c
+++ b/target-s390x/arch_dump.c
@@ -241,3 +241,14 @@ int cpu_write_elf32_qemunote(write_core_dump_function f, CPUArchState *env,
     return 0;
 }
 
+int arch_check_parameter(bool paging, bool has_filter, int64_t begin, int64_t length, 
+                          Error **errp)
+{
+    if (has_filter) {
+        error_set(errp, QERR_UNSUPPORTED_COMMAND_OPTION, "begin and length", 
+                  "dump-guest-memory", "s390");
+        return -2;
+    }
+    return 0;
+}
+
-- 
1.7.12.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [Qemu-devel] [PATCH 3/3] s390: Split dump-guest-memory memory mapping code
  2013-03-28 16:35 [Qemu-devel] [PATCH/RFC 0/3 v2] s390 dump guest memory support Jens Freimann
  2013-03-28 16:35 ` [Qemu-devel] [PATCH 1/3] s390: dump-guest-memory implementation Jens Freimann
  2013-03-28 16:35 ` [Qemu-devel] [PATCH 2/3] s390: Added check for unsupported parameters of dump-guest-memory Jens Freimann
@ 2013-03-28 16:36 ` Jens Freimann
  2013-04-04  7:43   ` Christian Borntraeger
  2 siblings, 1 reply; 5+ messages in thread
From: Jens Freimann @ 2013-03-28 16:36 UTC (permalink / raw)
  To: Alexander Graf
  Cc: Ekaterina Tumanova, Ekaterina Tumanova, qemu-devel, Rabin Vincent,
	Christian Borntraeger, Jens Freimann, Cornelia Huck,
	Andreas Färber

From: Ekaterina Tumanova <tumanova_ek@ru.ibm.com>

Split dump-guest-memory memory mapping code and drop CONFIG_HAVE_GET_MEMORY_MAPPING
for s390.

Part of the code from the memory_mapping.c was moved to separate
memory_mapping_common.c file: memory-mapping functions, which dump code needs in
both paths(CONFIG_HAVE_GET_MEMORY_MAPPING=y and CONFIG_HAVE_GET_MEMORY_MAPPING=n).
These functions will be built the same time dump.o module is built (based on
CONFIG_HAVE_CORE_DUMP statement).  Functions, which are left in memory_mapping.c
are mapping ON specific, they will not be build if no
CONFIG_HAVE_GET_MEMORY_MAPPING was specified for target architecture.
In case when CONFIG_HAVE_GET_MEMORY_MAPPING is not specified, but paging is
requested via command line ("-p" option), the memory_mapping-stub.c will issue
an error.

Signed-Off-By: Ekaterina Tumanova <tumanova@linux.vnet.ibm.com>
Signed-off-by: Jens Freimann <jfrei@linux.vnet.ibm.com>
---
 Makefile.target                 |   2 +-
 dump.c                          |   8 +++-
 include/sysemu/memory_mapping.h |  15 +++++-
 memory_mapping-stub.c           |  14 +-----
 memory_mapping.c                |  87 +--------------------------------
 memory_mapping_common.c         | 103 ++++++++++++++++++++++++++++++++++++++++
 6 files changed, 126 insertions(+), 103 deletions(-)
 create mode 100644 memory_mapping_common.c

diff --git a/Makefile.target b/Makefile.target
index 2bd6d14..f4eadc7 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -116,7 +116,7 @@ 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_common.o
 obj-$(CONFIG_NO_GET_MEMORY_MAPPING) += memory_mapping-stub.o
 obj-$(CONFIG_NO_CORE_DUMP) += dump-stub.o
 LIBS+=-lz
diff --git a/dump.c b/dump.c
index fd1d0f6..574c292 100644
--- a/dump.c
+++ b/dump.c
@@ -752,9 +752,13 @@ static int dump_init(DumpState *s, int fd, bool paging, bool has_filter,
     /* get memory mapping */
     memory_mapping_list_init(&s->list);
     if (paging) {
-        qemu_get_guest_memory_mapping(&s->list);
+        qemu_get_guest_memory_mapping(&s->list, errp);
     } else {
-        qemu_get_guest_simple_memory_mapping(&s->list);
+        qemu_get_guest_simple_memory_mapping(&s->list, errp);
+    }
+
+    if (ret < 0) {
+        goto cleanup;
     }
 
     if (s->has_filter) {
diff --git a/include/sysemu/memory_mapping.h b/include/sysemu/memory_mapping.h
index 1256125..b7e7471 100644
--- a/include/sysemu/memory_mapping.h
+++ b/include/sysemu/memory_mapping.h
@@ -15,6 +15,8 @@
 #define MEMORY_MAPPING_H
 
 #include "qemu/queue.h"
+#include "qapi/error.h"
+#include "include/qapi/qmp/qerror.h"
 
 /* The physical and virtual address in the memory mapping are contiguous. */
 typedef struct MemoryMapping {
@@ -38,6 +40,15 @@ bool cpu_paging_enabled(CPUArchState *env);
  * memory mapping's list. The region's virtual address starts with virt_addr,
  * and is contiguous. The list is sorted by phys_addr.
  */
+
+void memory_mapping_list_add_mapping_sorted(MemoryMappingList *list,
+                                            MemoryMapping *mapping);
+
+void create_new_memory_mapping(MemoryMappingList *list,
+                               hwaddr phys_addr,
+                               hwaddr virt_addr,
+                               ram_addr_t length);
+
 void memory_mapping_list_add_merge_sorted(MemoryMappingList *list,
                                           hwaddr phys_addr,
                                           hwaddr virt_addr,
@@ -53,10 +64,10 @@ void memory_mapping_list_init(MemoryMappingList *list);
  *   -1: failed
  *   -2: unsupported
  */
-int qemu_get_guest_memory_mapping(MemoryMappingList *list);
+int qemu_get_guest_memory_mapping(MemoryMappingList *list, Error **errp);
 
 /* get guest's memory mapping without do paging(virtual address is 0). */
-void qemu_get_guest_simple_memory_mapping(MemoryMappingList *list);
+void qemu_get_guest_simple_memory_mapping(MemoryMappingList *list, Error **errp);
 
 void memory_mapping_filter(MemoryMappingList *list, int64_t begin,
                            int64_t length);
diff --git a/memory_mapping-stub.c b/memory_mapping-stub.c
index 24d5d67..fea489c 100644
--- a/memory_mapping-stub.c
+++ b/memory_mapping-stub.c
@@ -15,19 +15,9 @@
 #include "exec/cpu-all.h"
 #include "sysemu/memory_mapping.h"
 
-int qemu_get_guest_memory_mapping(MemoryMappingList *list)
+int qemu_get_guest_memory_mapping(MemoryMappingList *list, Error **errp)
 {
+    error_set(errp, QERR_UNSUPPORTED_COMMAND_OPTION, "paging", "dump-guest-memory", "current architecture");
     return -2;
 }
 
-int cpu_get_memory_mapping(MemoryMappingList *list,
-					                                          CPUArchState *env)
-{
-    return -1;
-}
-
-bool cpu_paging_enabled(CPUArchState *env)
-{
-    return true;
-}
-
diff --git a/memory_mapping.c b/memory_mapping.c
index ff45b3a..0d4c15b 100644
--- a/memory_mapping.c
+++ b/memory_mapping.c
@@ -15,36 +15,6 @@
 #include "exec/cpu-all.h"
 #include "sysemu/memory_mapping.h"
 
-static void memory_mapping_list_add_mapping_sorted(MemoryMappingList *list,
-                                                   MemoryMapping *mapping)
-{
-    MemoryMapping *p;
-
-    QTAILQ_FOREACH(p, &list->head, next) {
-        if (p->phys_addr >= mapping->phys_addr) {
-            QTAILQ_INSERT_BEFORE(p, mapping, next);
-            return;
-        }
-    }
-    QTAILQ_INSERT_TAIL(&list->head, mapping, next);
-}
-
-static void create_new_memory_mapping(MemoryMappingList *list,
-                                      hwaddr phys_addr,
-                                      hwaddr virt_addr,
-                                      ram_addr_t length)
-{
-    MemoryMapping *memory_mapping;
-
-    memory_mapping = g_malloc(sizeof(MemoryMapping));
-    memory_mapping->phys_addr = phys_addr;
-    memory_mapping->virt_addr = virt_addr;
-    memory_mapping->length = length;
-    list->last_mapping = memory_mapping;
-    list->num++;
-    memory_mapping_list_add_mapping_sorted(list, memory_mapping);
-}
-
 static inline bool mapping_contiguous(MemoryMapping *map,
                                       hwaddr phys_addr,
                                       hwaddr virt_addr)
@@ -145,26 +115,6 @@ void memory_mapping_list_add_merge_sorted(MemoryMappingList *list,
     create_new_memory_mapping(list, phys_addr, virt_addr, length);
 }
 
-void memory_mapping_list_free(MemoryMappingList *list)
-{
-    MemoryMapping *p, *q;
-
-    QTAILQ_FOREACH_SAFE(p, &list->head, next, q) {
-        QTAILQ_REMOVE(&list->head, p, next);
-        g_free(p);
-    }
-
-    list->num = 0;
-    list->last_mapping = NULL;
-}
-
-void memory_mapping_list_init(MemoryMappingList *list)
-{
-    list->num = 0;
-    list->last_mapping = NULL;
-    QTAILQ_INIT(&list->head);
-}
-
 static CPUArchState *find_paging_enabled_cpu(CPUArchState *start_cpu)
 {
     CPUArchState *env;
@@ -178,7 +128,7 @@ static CPUArchState *find_paging_enabled_cpu(CPUArchState *start_cpu)
     return NULL;
 }
 
-int qemu_get_guest_memory_mapping(MemoryMappingList *list)
+int qemu_get_guest_memory_mapping(MemoryMappingList *list, Error **errp)
 {
     CPUArchState *env, *first_paging_enabled_cpu;
     RAMBlock *block;
@@ -209,38 +159,3 @@ int qemu_get_guest_memory_mapping(MemoryMappingList *list)
     return 0;
 }
 
-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);
-    }
-}
-
-void memory_mapping_filter(MemoryMappingList *list, int64_t begin,
-                           int64_t length)
-{
-    MemoryMapping *cur, *next;
-
-    QTAILQ_FOREACH_SAFE(cur, &list->head, next, next) {
-        if (cur->phys_addr >= begin + length ||
-            cur->phys_addr + cur->length <= begin) {
-            QTAILQ_REMOVE(&list->head, cur, next);
-            list->num--;
-            continue;
-        }
-
-        if (cur->phys_addr < begin) {
-            cur->length -= begin - cur->phys_addr;
-            if (cur->virt_addr) {
-                cur->virt_addr += begin - cur->phys_addr;
-            }
-            cur->phys_addr = begin;
-        }
-
-        if (cur->phys_addr + cur->length > begin + length) {
-            cur->length -= cur->phys_addr + cur->length - begin - length;
-        }
-    }
-}
diff --git a/memory_mapping_common.c b/memory_mapping_common.c
new file mode 100644
index 0000000..faae044
--- /dev/null
+++ b/memory_mapping_common.c
@@ -0,0 +1,103 @@
+/*
+ * QEMU memory mapping
+ *
+ * Copyright Fujitsu, Corp. 2011, 2012
+ *
+ * Authors:
+ *     Wen Congyang <wency@cn.fujitsu.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ *
+ */
+
+#include "cpu.h"
+#include "exec/cpu-all.h"
+#include "sysemu/memory_mapping.h"
+
+void memory_mapping_list_add_mapping_sorted(MemoryMappingList *list,
+                                            MemoryMapping *mapping)
+{
+    MemoryMapping *p;
+
+    QTAILQ_FOREACH(p, &list->head, next) {
+        if (p->phys_addr >= mapping->phys_addr) {
+            QTAILQ_INSERT_BEFORE(p, mapping, next);
+            return;
+        }
+    }
+    QTAILQ_INSERT_TAIL(&list->head, mapping, next);
+}
+
+void create_new_memory_mapping(MemoryMappingList *list,
+                               hwaddr phys_addr,
+                               hwaddr virt_addr,
+                               ram_addr_t length)
+{
+    MemoryMapping *memory_mapping;
+
+    memory_mapping = g_malloc(sizeof(MemoryMapping));
+    memory_mapping->phys_addr = phys_addr;
+    memory_mapping->virt_addr = virt_addr;
+    memory_mapping->length = length;
+    list->last_mapping = memory_mapping;
+    list->num++;
+    memory_mapping_list_add_mapping_sorted(list, memory_mapping);
+}
+
+
+void memory_mapping_list_free(MemoryMappingList *list)
+{
+    MemoryMapping *p, *q;
+
+    QTAILQ_FOREACH_SAFE(p, &list->head, next, q) {
+        QTAILQ_REMOVE(&list->head, p, next);
+        g_free(p);
+    }
+
+    list->num = 0;
+    list->last_mapping = NULL;
+}
+
+void memory_mapping_list_init(MemoryMappingList *list)
+{
+    list->num = 0;
+    list->last_mapping = NULL;
+    QTAILQ_INIT(&list->head);
+}
+
+void qemu_get_guest_simple_memory_mapping(MemoryMappingList *list, Error **errp)
+{
+    RAMBlock *block;
+
+    QTAILQ_FOREACH(block, &ram_list.blocks, next) {
+        create_new_memory_mapping(list, block->offset, 0, block->length);
+    }
+}
+
+void memory_mapping_filter(MemoryMappingList *list, int64_t begin,
+                           int64_t length)
+{
+    MemoryMapping *cur, *next;
+
+    QTAILQ_FOREACH_SAFE(cur, &list->head, next, next) {
+        if (cur->phys_addr >= begin + length ||
+            cur->phys_addr + cur->length <= begin) {
+            QTAILQ_REMOVE(&list->head, cur, next);
+            list->num--;
+            continue;
+        }
+
+        if (cur->phys_addr < begin) {
+            cur->length -= begin - cur->phys_addr;
+            if (cur->virt_addr) {
+                cur->virt_addr += begin - cur->phys_addr;
+            }
+            cur->phys_addr = begin;
+        }
+
+        if (cur->phys_addr + cur->length > begin + length) {
+            cur->length -= cur->phys_addr + cur->length - begin - length;
+        }
+    }
+}
-- 
1.7.12.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH 3/3] s390: Split dump-guest-memory memory mapping code
  2013-03-28 16:36 ` [Qemu-devel] [PATCH 3/3] s390: Split dump-guest-memory memory mapping code Jens Freimann
@ 2013-04-04  7:43   ` Christian Borntraeger
  0 siblings, 0 replies; 5+ messages in thread
From: Christian Borntraeger @ 2013-04-04  7:43 UTC (permalink / raw)
  To: Jens Freimann
  Cc: Ekaterina Tumanova, qemu-devel, Alexander Graf, Rabin Vincent,
	Ekaterina Tumanova, Cornelia Huck, Andreas Färber

CC Wen Congyang <wency@cn.fujitsu.com>


On 28/03/13 17:36, Jens Freimann wrote:
> From: Ekaterina Tumanova <tumanova_ek@ru.ibm.com>
> 
> Split dump-guest-memory memory mapping code and drop CONFIG_HAVE_GET_MEMORY_MAPPING
> for s390.

Jens, 
"drop CONFIG_HAVE_GET_MEMORY_MAPPING" seems like a leftover from our internal git which
had an earlier version that implemented a dummy memory mapping for s390.

So please re-do the patch description.

Wording-wise something like 
"Split out dump-guest-memory memory mapping code to allow dumping without memory mapping"
might be better

> 
> Part of the code from the memory_mapping.c was moved to separate
> memory_mapping_common.c file: memory-mapping functions, which dump code needs in
> both paths(CONFIG_HAVE_GET_MEMORY_MAPPING=y and CONFIG_HAVE_GET_MEMORY_MAPPING=n).
> These functions will be built the same time dump.o module is built (based on
> CONFIG_HAVE_CORE_DUMP statement).  Functions, which are left in memory_mapping.c
> are mapping ON specific, they will not be build if no
> CONFIG_HAVE_GET_MEMORY_MAPPING was specified for target architecture.
> In case when CONFIG_HAVE_GET_MEMORY_MAPPING is not specified, but paging is
> requested via command line ("-p" option), the memory_mapping-stub.c will issue
> an error.
> 
> Signed-Off-By: Ekaterina Tumanova <tumanova@linux.vnet.ibm.com>
> Signed-off-by: Jens Freimann <jfrei@linux.vnet.ibm.com>
> ---
>  Makefile.target                 |   2 +-
>  dump.c                          |   8 +++-
>  include/sysemu/memory_mapping.h |  15 +++++-
>  memory_mapping-stub.c           |  14 +-----
>  memory_mapping.c                |  87 +--------------------------------
>  memory_mapping_common.c         | 103 ++++++++++++++++++++++++++++++++++++++++
>  6 files changed, 126 insertions(+), 103 deletions(-)
>  create mode 100644 memory_mapping_common.c
> 
> diff --git a/Makefile.target b/Makefile.target
> index 2bd6d14..f4eadc7 100644
> --- a/Makefile.target
> +++ b/Makefile.target
> @@ -116,7 +116,7 @@ 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_common.o
>  obj-$(CONFIG_NO_GET_MEMORY_MAPPING) += memory_mapping-stub.o
>  obj-$(CONFIG_NO_CORE_DUMP) += dump-stub.o
>  LIBS+=-lz
> diff --git a/dump.c b/dump.c
> index fd1d0f6..574c292 100644
> --- a/dump.c
> +++ b/dump.c
> @@ -752,9 +752,13 @@ static int dump_init(DumpState *s, int fd, bool paging, bool has_filter,
>      /* get memory mapping */
>      memory_mapping_list_init(&s->list);
>      if (paging) {
> -        qemu_get_guest_memory_mapping(&s->list);
> +        qemu_get_guest_memory_mapping(&s->list, errp);
>      } else {
> -        qemu_get_guest_simple_memory_mapping(&s->list);
> +        qemu_get_guest_simple_memory_mapping(&s->list, errp);
> +    }
> +
> +    if (ret < 0) {
> +        goto cleanup;
>      }
> 
>      if (s->has_filter) {
> diff --git a/include/sysemu/memory_mapping.h b/include/sysemu/memory_mapping.h
> index 1256125..b7e7471 100644
> --- a/include/sysemu/memory_mapping.h
> +++ b/include/sysemu/memory_mapping.h
> @@ -15,6 +15,8 @@
>  #define MEMORY_MAPPING_H
> 
>  #include "qemu/queue.h"
> +#include "qapi/error.h"
> +#include "include/qapi/qmp/qerror.h"
> 
>  /* The physical and virtual address in the memory mapping are contiguous. */
>  typedef struct MemoryMapping {
> @@ -38,6 +40,15 @@ bool cpu_paging_enabled(CPUArchState *env);
>   * memory mapping's list. The region's virtual address starts with virt_addr,
>   * and is contiguous. The list is sorted by phys_addr.
>   */
> +
> +void memory_mapping_list_add_mapping_sorted(MemoryMappingList *list,
> +                                            MemoryMapping *mapping);
> +
> +void create_new_memory_mapping(MemoryMappingList *list,
> +                               hwaddr phys_addr,
> +                               hwaddr virt_addr,
> +                               ram_addr_t length);
> +
>  void memory_mapping_list_add_merge_sorted(MemoryMappingList *list,
>                                            hwaddr phys_addr,
>                                            hwaddr virt_addr,
> @@ -53,10 +64,10 @@ void memory_mapping_list_init(MemoryMappingList *list);
>   *   -1: failed
>   *   -2: unsupported
>   */
> -int qemu_get_guest_memory_mapping(MemoryMappingList *list);
> +int qemu_get_guest_memory_mapping(MemoryMappingList *list, Error **errp);
> 
>  /* get guest's memory mapping without do paging(virtual address is 0). */
> -void qemu_get_guest_simple_memory_mapping(MemoryMappingList *list);
> +void qemu_get_guest_simple_memory_mapping(MemoryMappingList *list, Error **errp);
> 
>  void memory_mapping_filter(MemoryMappingList *list, int64_t begin,
>                             int64_t length);
> diff --git a/memory_mapping-stub.c b/memory_mapping-stub.c
> index 24d5d67..fea489c 100644
> --- a/memory_mapping-stub.c
> +++ b/memory_mapping-stub.c
> @@ -15,19 +15,9 @@
>  #include "exec/cpu-all.h"
>  #include "sysemu/memory_mapping.h"
> 
> -int qemu_get_guest_memory_mapping(MemoryMappingList *list)
> +int qemu_get_guest_memory_mapping(MemoryMappingList *list, Error **errp)
>  {
> +    error_set(errp, QERR_UNSUPPORTED_COMMAND_OPTION, "paging", "dump-guest-memory", "current architecture");
>      return -2;
>  }
> 
> -int cpu_get_memory_mapping(MemoryMappingList *list,
> -					                                          CPUArchState *env)
> -{
> -    return -1;
> -}
> -
> -bool cpu_paging_enabled(CPUArchState *env)
> -{
> -    return true;
> -}
> -
> diff --git a/memory_mapping.c b/memory_mapping.c
> index ff45b3a..0d4c15b 100644
> --- a/memory_mapping.c
> +++ b/memory_mapping.c
> @@ -15,36 +15,6 @@
>  #include "exec/cpu-all.h"
>  #include "sysemu/memory_mapping.h"
> 
> -static void memory_mapping_list_add_mapping_sorted(MemoryMappingList *list,
> -                                                   MemoryMapping *mapping)
> -{
> -    MemoryMapping *p;
> -
> -    QTAILQ_FOREACH(p, &list->head, next) {
> -        if (p->phys_addr >= mapping->phys_addr) {
> -            QTAILQ_INSERT_BEFORE(p, mapping, next);
> -            return;
> -        }
> -    }
> -    QTAILQ_INSERT_TAIL(&list->head, mapping, next);
> -}
> -
> -static void create_new_memory_mapping(MemoryMappingList *list,
> -                                      hwaddr phys_addr,
> -                                      hwaddr virt_addr,
> -                                      ram_addr_t length)
> -{
> -    MemoryMapping *memory_mapping;
> -
> -    memory_mapping = g_malloc(sizeof(MemoryMapping));
> -    memory_mapping->phys_addr = phys_addr;
> -    memory_mapping->virt_addr = virt_addr;
> -    memory_mapping->length = length;
> -    list->last_mapping = memory_mapping;
> -    list->num++;
> -    memory_mapping_list_add_mapping_sorted(list, memory_mapping);
> -}
> -
>  static inline bool mapping_contiguous(MemoryMapping *map,
>                                        hwaddr phys_addr,
>                                        hwaddr virt_addr)
> @@ -145,26 +115,6 @@ void memory_mapping_list_add_merge_sorted(MemoryMappingList *list,
>      create_new_memory_mapping(list, phys_addr, virt_addr, length);
>  }
> 
> -void memory_mapping_list_free(MemoryMappingList *list)
> -{
> -    MemoryMapping *p, *q;
> -
> -    QTAILQ_FOREACH_SAFE(p, &list->head, next, q) {
> -        QTAILQ_REMOVE(&list->head, p, next);
> -        g_free(p);
> -    }
> -
> -    list->num = 0;
> -    list->last_mapping = NULL;
> -}
> -
> -void memory_mapping_list_init(MemoryMappingList *list)
> -{
> -    list->num = 0;
> -    list->last_mapping = NULL;
> -    QTAILQ_INIT(&list->head);
> -}
> -
>  static CPUArchState *find_paging_enabled_cpu(CPUArchState *start_cpu)
>  {
>      CPUArchState *env;
> @@ -178,7 +128,7 @@ static CPUArchState *find_paging_enabled_cpu(CPUArchState *start_cpu)
>      return NULL;
>  }
> 
> -int qemu_get_guest_memory_mapping(MemoryMappingList *list)
> +int qemu_get_guest_memory_mapping(MemoryMappingList *list, Error **errp)
>  {
>      CPUArchState *env, *first_paging_enabled_cpu;
>      RAMBlock *block;
> @@ -209,38 +159,3 @@ int qemu_get_guest_memory_mapping(MemoryMappingList *list)
>      return 0;
>  }
> 
> -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);
> -    }
> -}
> -
> -void memory_mapping_filter(MemoryMappingList *list, int64_t begin,
> -                           int64_t length)
> -{
> -    MemoryMapping *cur, *next;
> -
> -    QTAILQ_FOREACH_SAFE(cur, &list->head, next, next) {
> -        if (cur->phys_addr >= begin + length ||
> -            cur->phys_addr + cur->length <= begin) {
> -            QTAILQ_REMOVE(&list->head, cur, next);
> -            list->num--;
> -            continue;
> -        }
> -
> -        if (cur->phys_addr < begin) {
> -            cur->length -= begin - cur->phys_addr;
> -            if (cur->virt_addr) {
> -                cur->virt_addr += begin - cur->phys_addr;
> -            }
> -            cur->phys_addr = begin;
> -        }
> -
> -        if (cur->phys_addr + cur->length > begin + length) {
> -            cur->length -= cur->phys_addr + cur->length - begin - length;
> -        }
> -    }
> -}
> diff --git a/memory_mapping_common.c b/memory_mapping_common.c
> new file mode 100644
> index 0000000..faae044
> --- /dev/null
> +++ b/memory_mapping_common.c
> @@ -0,0 +1,103 @@
> +/*
> + * QEMU memory mapping
> + *
> + * Copyright Fujitsu, Corp. 2011, 2012
> + *
> + * Authors:
> + *     Wen Congyang <wency@cn.fujitsu.com>
> + *
> + * This work is licensed under the terms of the GNU GPL, version 2 or later.
> + * See the COPYING file in the top-level directory.
> + *
> + */
> +
> +#include "cpu.h"
> +#include "exec/cpu-all.h"
> +#include "sysemu/memory_mapping.h"
> +
> +void memory_mapping_list_add_mapping_sorted(MemoryMappingList *list,
> +                                            MemoryMapping *mapping)
> +{
> +    MemoryMapping *p;
> +
> +    QTAILQ_FOREACH(p, &list->head, next) {
> +        if (p->phys_addr >= mapping->phys_addr) {
> +            QTAILQ_INSERT_BEFORE(p, mapping, next);
> +            return;
> +        }
> +    }
> +    QTAILQ_INSERT_TAIL(&list->head, mapping, next);
> +}
> +
> +void create_new_memory_mapping(MemoryMappingList *list,
> +                               hwaddr phys_addr,
> +                               hwaddr virt_addr,
> +                               ram_addr_t length)
> +{
> +    MemoryMapping *memory_mapping;
> +
> +    memory_mapping = g_malloc(sizeof(MemoryMapping));
> +    memory_mapping->phys_addr = phys_addr;
> +    memory_mapping->virt_addr = virt_addr;
> +    memory_mapping->length = length;
> +    list->last_mapping = memory_mapping;
> +    list->num++;
> +    memory_mapping_list_add_mapping_sorted(list, memory_mapping);
> +}
> +
> +
> +void memory_mapping_list_free(MemoryMappingList *list)
> +{
> +    MemoryMapping *p, *q;
> +
> +    QTAILQ_FOREACH_SAFE(p, &list->head, next, q) {
> +        QTAILQ_REMOVE(&list->head, p, next);
> +        g_free(p);
> +    }
> +
> +    list->num = 0;
> +    list->last_mapping = NULL;
> +}
> +
> +void memory_mapping_list_init(MemoryMappingList *list)
> +{
> +    list->num = 0;
> +    list->last_mapping = NULL;
> +    QTAILQ_INIT(&list->head);
> +}
> +
> +void qemu_get_guest_simple_memory_mapping(MemoryMappingList *list, Error **errp)
> +{
> +    RAMBlock *block;
> +
> +    QTAILQ_FOREACH(block, &ram_list.blocks, next) {
> +        create_new_memory_mapping(list, block->offset, 0, block->length);
> +    }
> +}
> +
> +void memory_mapping_filter(MemoryMappingList *list, int64_t begin,
> +                           int64_t length)
> +{
> +    MemoryMapping *cur, *next;
> +
> +    QTAILQ_FOREACH_SAFE(cur, &list->head, next, next) {
> +        if (cur->phys_addr >= begin + length ||
> +            cur->phys_addr + cur->length <= begin) {
> +            QTAILQ_REMOVE(&list->head, cur, next);
> +            list->num--;
> +            continue;
> +        }
> +
> +        if (cur->phys_addr < begin) {
> +            cur->length -= begin - cur->phys_addr;
> +            if (cur->virt_addr) {
> +                cur->virt_addr += begin - cur->phys_addr;
> +            }
> +            cur->phys_addr = begin;
> +        }
> +
> +        if (cur->phys_addr + cur->length > begin + length) {
> +            cur->length -= cur->phys_addr + cur->length - begin - length;
> +        }
> +    }
> +}
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2013-04-04  7:44 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-03-28 16:35 [Qemu-devel] [PATCH/RFC 0/3 v2] s390 dump guest memory support Jens Freimann
2013-03-28 16:35 ` [Qemu-devel] [PATCH 1/3] s390: dump-guest-memory implementation Jens Freimann
2013-03-28 16:35 ` [Qemu-devel] [PATCH 2/3] s390: Added check for unsupported parameters of dump-guest-memory Jens Freimann
2013-03-28 16:36 ` [Qemu-devel] [PATCH 3/3] s390: Split dump-guest-memory memory mapping code Jens Freimann
2013-04-04  7:43   ` Christian Borntraeger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).