From: Paolo Bonzini Date: Mon, 29 Jul 2013 12:27:39 +0000 (+0200) Subject: exec: fix writing to MMIO area with non-power-of-two length X-Git-Tag: qemu-xen-4.4.0-rc1~1^2~33 X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=9fab8e1fe15014a4bd147eeedd2491bcfbba4e59;p=qemu-upstream-4.4-testing.git exec: fix writing to MMIO area with non-power-of-two length 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 Tested-by: Oleksii Shevchuk Signed-off-by: Paolo Bonzini (cherry picked from commit 098178f2749a63fbbb1a626dcc7d939d5cb2bde7) Signed-off-by: Michael Roth --- diff --git a/exec.c b/exec.c index 3ca938121..394f7e2b1 100644 --- a/exec.c +++ b/exec.c @@ -1928,6 +1928,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; }