qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Peter Maydell <peter.maydell@linaro.org>
To: qemu-devel@nongnu.org
Cc: Paul Brook <paul@codesourcery.com>, Avi Kivity <avi@redhat.com>,
	patches@linaro.org
Subject: [Qemu-devel] [PATCH] exec.c: Allow memory region start_addr and region_offset to vary in low bits
Date: Mon,  5 Dec 2011 11:01:37 +0000	[thread overview]
Message-ID: <1323082897-15249-1-git-send-email-peter.maydell@linaro.org> (raw)

Fix a long-standing deficiency of cpu_register_physical_memory_log()
where the start address and region offset had to have the same low
bits (otherwise the IO functions would be passed an incorrect address
offset). This was most likely to bite when registering memory regions
which started at a non-page-boundary.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
This is such a small change to correct this issue that I'm kind of
suspicious of it :-)

 exec.c |   11 ++++++-----
 1 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/exec.c b/exec.c
index 6b92198..7030cea 100644
--- a/exec.c
+++ b/exec.c
@@ -2655,10 +2655,7 @@ static subpage_t *subpage_init (target_phys_addr_t base, ram_addr_t *phys,
    For RAM, 'size' must be a multiple of the target page size.
    If (phys_offset & ~TARGET_PAGE_MASK) != 0, then it is an
    io memory page.  The address used when calling the IO function is
-   the offset from the start of the region, plus region_offset.  Both
-   start_addr and region_offset are rounded down to a page boundary
-   before calculating this offset.  This should not be a problem unless
-   the low bits of start_addr and region_offset differ.  */
+   the offset from the start of the region, plus region_offset. */
 void cpu_register_physical_memory_log(target_phys_addr_t start_addr,
                                          ram_addr_t size,
                                          ram_addr_t phys_offset,
@@ -2677,7 +2674,11 @@ void cpu_register_physical_memory_log(target_phys_addr_t start_addr,
     if (phys_offset == IO_MEM_UNASSIGNED) {
         region_offset = start_addr;
     }
-    region_offset &= TARGET_PAGE_MASK;
+    /* Adjust the region offset to account for the start_addr possibly
+     * not being page aligned, so we end up passing the IO functions
+     * the true offset from the start of the region.
+     */
+    region_offset -= (start_addr & ~TARGET_PAGE_MASK);
     size = (size + TARGET_PAGE_SIZE - 1) & TARGET_PAGE_MASK;
     end_addr = start_addr + (target_phys_addr_t)size;
 
-- 
1.7.1

             reply	other threads:[~2011-12-05 11:01 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-05 11:01 Peter Maydell [this message]
2011-12-05 13:40 ` [Qemu-devel] [PATCH] exec.c: Allow memory region start_addr and region_offset to vary in low bits Avi Kivity
2011-12-05 14:01   ` Peter Maydell
2011-12-05 14:14     ` Avi Kivity

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=1323082897-15249-1-git-send-email-peter.maydell@linaro.org \
    --to=peter.maydell@linaro.org \
    --cc=avi@redhat.com \
    --cc=patches@linaro.org \
    --cc=paul@codesourcery.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).