All of lore.kernel.org
 help / color / mirror / Atom feed
From: Rabin Vincent <rabin@rab.in>
To: qemu-devel@nongnu.org
Cc: Rabin Vincent <rabin@rab.in>
Subject: [Qemu-devel] [PATCHv2 6/6] dump: fix memory region handling
Date: Sun, 24 Mar 2013 18:27:21 +0100	[thread overview]
Message-ID: <1364146041-27041-7-git-send-email-rabin@rab.in> (raw)
In-Reply-To: <1364146041-27041-1-git-send-email-rabin@rab.in>

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.

Signed-off-by: Rabin Vincent <rabin@rab.in>
---
 dump.c                |   19 +++++++++++--------
 include/exec/memory.h |    7 +++++++
 memory.c              |   12 ++++++++++++
 memory_mapping.c      |    6 ++++--
 4 files changed, 34 insertions(+), 10 deletions(-)

diff --git a/dump.c b/dump.c
index 4b7d76c..4b0353a 100644
--- a/dump.c
+++ b/dump.c
@@ -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;
         }
 
diff --git a/include/exec/memory.h b/include/exec/memory.h
index 2322732..9227190 100644
--- a/include/exec/memory.h
+++ b/include/exec/memory.h
@@ -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
  *
diff --git a/memory.c b/memory.c
index 92a2196..f90fd19 100644
--- a/memory.c
+++ b/memory.c
@@ -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;
diff --git a/memory_mapping.c b/memory_mapping.c
index ff45b3a..cf0751c 100644
--- a/memory_mapping.c
+++ b/memory_mapping.c
@@ -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);
     }
 }
 
-- 
1.7.10.4

  parent reply	other threads:[~2013-03-24 17:27 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-24 17:27 [Qemu-devel] [PATCHv2 0/6] ARM dump-guest-memory support Rabin Vincent
2013-03-24 17:27 ` [Qemu-devel] [PATCHv2 1/6] dump: create writable files Rabin Vincent
2013-04-04  9:42   ` Paolo Bonzini
2013-03-24 17:27 ` [Qemu-devel] [PATCHv2 2/6] dump: extract out note helper Rabin Vincent
2013-03-24 17:27 ` [Qemu-devel] [PATCHv2 3/6] dump: extract out get note size function Rabin Vincent
2013-03-24 17:27 ` [Qemu-devel] [PATCHv2 4/6] dump: fix up memory mapping dependencies / stub Rabin Vincent
2013-04-04  9:43   ` Paolo Bonzini
2013-03-24 17:27 ` [Qemu-devel] [PATCHv2 5/6] target-arm: add dump-guest-memory support Rabin Vincent
2013-03-24 18:34   ` Peter Maydell
2013-03-24 19:26     ` Rabin Vincent
2013-03-24 20:39       ` Peter Maydell
2013-04-04  9:47         ` Paolo Bonzini
2013-04-04  9:49           ` Peter Maydell
2013-03-24 17:27 ` Rabin Vincent [this message]
2013-03-24 18:36   ` [Qemu-devel] [PATCHv2 6/6] dump: fix memory region handling Peter Maydell
2013-03-24 19:35     ` Rabin Vincent
2013-03-24 20:18       ` Peter Maydell
2013-03-25 11:49 ` [Qemu-devel] [PATCHv2 0/6] ARM dump-guest-memory support Andreas Färber
2013-03-29  8:36   ` Rabin Vincent
2013-04-04  8:52     ` Andreas Färber
2013-04-09 12:09       ` [Qemu-devel] [RFC] make write_elf_xx functions part of CPUClass, use CPUState Jens Freimann
2013-04-09 13:15         ` Andreas Färber
2013-04-19 14:45           ` [Qemu-devel] [PATCH 0/2] qom: make cpu_write_elfXX_ functions part of CPUClass Jens Freimann
2013-04-19 14:45             ` [Qemu-devel] [PATCH 1/2] qom: Convert cpu_write_elfXX_note functions to CPUState Jens Freimann
2013-04-19 14:45             ` [Qemu-devel] [PATCH 2/2] i386: use CPUClass->write_elf* functions Jens Freimann
2013-04-29 14:21             ` [Qemu-devel] [PATCH 0/2] qom: make cpu_write_elfXX_ functions part of CPUClass Andreas Färber

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1364146041-27041-7-git-send-email-rabin@rab.in \
    --to=rabin@rab.in \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.