exec: fix writing to MMIO area with non-power-of-two length
authorPaolo Bonzini <pbonzini@redhat.com>
Mon, 29 Jul 2013 12:27:39 +0000 (14:27 +0200)
committerSeokYeon Hwang <syeon.hwang@samsung.com>
Tue, 29 Oct 2013 02:17:44 +0000 (11:17 +0900)
The problem is introduced by commit 2332616 (exec: Support 64-bit
operations in address_space_rw, 2013-07-08).  Before that commit,
memory_access_size would only return 1/2/4.

Since alignment is already handled above, reduce l to the largest
power of two that is smaller than l.

Cc: qemu-stable@nongnu.org
Reported-by: Oleksii Shevchuk <alxchk@gmail.com>
Tested-by: Oleksii Shevchuk <alxchk@gmail.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
(cherry picked from commit 098178f2749a63fbbb1a626dcc7d939d5cb2bde7)

Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
exec.c

diff --git a/exec.c b/exec.c
index 8d415905d52dc7e12844ae0931753b11557a65ec..0245f4e30343b4f32ed751e876283068bb21dc7c 100644 (file)
--- a/exec.c
+++ b/exec.c
@@ -1944,6 +1944,9 @@ static int memory_access_size(MemoryRegion *mr, unsigned l, hwaddr addr)
     if (l > access_size_max) {
         l = access_size_max;
     }
+    if (l & (l - 1)) {
+        l = 1 << (qemu_fls(l) - 1);
+    }
 
     return l;
 }