qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Alex Williamson <alex.williamson@redhat.com>
To: qemu-devel@nongnu.org, anthony@codemonkey.ws
Cc: jan.kiszka@siemens.com, alex.williamson@redhat.com,
	armbru@redhat.com, mst@redhat.com
Subject: [Qemu-devel] [PATCH v2 2/3] CPUPhysMemoryClient: Pass guest physical address not	region offset
Date: Tue, 03 May 2011 12:36:46 -0600	[thread overview]
Message-ID: <20110503183638.28430.11842.stgit@s20.home> (raw)
In-Reply-To: <20110503182039.28430.26530.stgit@s20.home>

When we're trying to get a newly registered phys memory client updated
with the current page mappings, we end up passing the region offset
(a ram_addr_t) as the start address rather than the actual guest
physical memory address (target_phys_addr_t).  If your guest has less
than 3.5G of memory, these are coincidentally the same thing.  If
there's more, the region offset for the memory above 4G starts over
at 0, so the set_memory client will overwrite it's lower memory entries.

Instead, keep track of the guest phsyical address as we're walking the
tables and pass that to the set_memory client.

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
---

 exec.c |   16 ++++++++++++----
 1 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/exec.c b/exec.c
index 8790ad8..bbd5c86 100644
--- a/exec.c
+++ b/exec.c
@@ -1741,8 +1741,14 @@ static int cpu_notify_migration_log(int enable)
     return 0;
 }
 
+/* The l1_phys_map provides the upper P_L1_BITs of the guest physical
+ * address.  Each intermediate table provides the next L2_BITs of guest
+ * physical address space.  The number of levels vary based on host and
+ * guest configuration, making it efficient to build the final guest
+ * physical address by seeding the L1 offset and shifting and adding in
+ * each L2 offset as we recurse through them. */
 static void phys_page_for_each_1(CPUPhysMemoryClient *client,
-                                 int level, void **lp)
+                                 int level, void **lp, target_phys_addr_t addr)
 {
     int i;
 
@@ -1751,16 +1757,18 @@ static void phys_page_for_each_1(CPUPhysMemoryClient *client,
     }
     if (level == 0) {
         PhysPageDesc *pd = *lp;
+        addr <<= L2_BITS + TARGET_PAGE_BITS;
         for (i = 0; i < L2_SIZE; ++i) {
             if (pd[i].phys_offset != IO_MEM_UNASSIGNED) {
-                client->set_memory(client, pd[i].region_offset,
+                client->set_memory(client, addr | i << TARGET_PAGE_BITS,
                                    TARGET_PAGE_SIZE, pd[i].phys_offset);
             }
         }
     } else {
         void **pp = *lp;
         for (i = 0; i < L2_SIZE; ++i) {
-            phys_page_for_each_1(client, level - 1, pp + i);
+            phys_page_for_each_1(client, level - 1, pp + i,
+                                 (addr << L2_BITS) | i);
         }
     }
 }
@@ -1770,7 +1778,7 @@ static void phys_page_for_each(CPUPhysMemoryClient *client)
     int i;
     for (i = 0; i < P_L1_SIZE; ++i) {
         phys_page_for_each_1(client, P_L1_SHIFT / L2_BITS - 1,
-                             l1_phys_map + i);
+                             l1_phys_map + i, i);
     }
 }
 

  parent reply	other threads:[~2011-05-03 18:36 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-03 18:36 [Qemu-devel] [PATCH v2 0/3] CPUPhysMemoryClient: Fixes and batching Alex Williamson
2011-05-03 18:36 ` [Qemu-devel] [PATCH v2 1/3] CPUPhysMemoryClient: Fix typo in phys memory client registration Alex Williamson
2011-05-03 18:36 ` Alex Williamson [this message]
2011-05-03 18:36 ` [Qemu-devel] [PATCH v2 3/3] CPUPhysMemoryClient: Batch contiguous addresses when playing catchup Alex Williamson
2011-05-05 13:21   ` Michael S. Tsirkin
2011-05-05 14:21     ` Alex Williamson
2011-05-05 14:30       ` Jes Sorensen
2011-05-05 15:18         ` Michael S. Tsirkin
2011-05-05 15:36           ` Jes Sorensen
2011-05-05 15:38             ` Michael S. Tsirkin
2011-05-05 15:40               ` Jes Sorensen
2011-05-05 15:41                 ` Michael S. Tsirkin
2011-05-05 15:21       ` Michael S. Tsirkin
2011-05-25  3:47         ` Alex Williamson
2011-05-25  6:08           ` Michael S. Tsirkin
2011-05-05 13:21 ` [Qemu-devel] [PATCH v2 0/3] CPUPhysMemoryClient: Fixes and batching Michael S. Tsirkin

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=20110503183638.28430.11842.stgit@s20.home \
    --to=alex.williamson@redhat.com \
    --cc=anthony@codemonkey.ws \
    --cc=armbru@redhat.com \
    --cc=jan.kiszka@siemens.com \
    --cc=mst@redhat.com \
    --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 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).