exec: fix writing to MMIO area with non-power-of-two length
PATCH 1/1 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.
--- exec.c | 3 +++ 1 file changed, 3 insertions(+)
exec.c +3 -0
@@ -1925,6 +1925,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; }
Signature · 1 line
1.8.1.4
Quoted 19 lines · Paolo Bonzini
The problem is introduced by commit 2332616 (exec: Support 64-bit operations in
address_space_rw, 2013-07-08). Before that commit,memory_access_sizewould only return 1/2/4.Since alignment is already handled above, reduce l to the largest power of two that is smaller than l.
Reported-by Oleksii Shevchuk <[email protected]>Tested-by Oleksii Shevchuk <[email protected]>Signed-off-by Paolo Bonzini <[email protected]>--- exec.c | 3 +++ 1 file changed, 3 insertions(+)exec.c +0
-0
exec.c static int memory_access_size(MemoryRegion *mr, unsigned l, hwaddr addr) · line 1930
Quoted 6 lines
exec.c +3
-0@@ -1925,6 +1925,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 ); + }
Is this a hot enough code path that we care about going via the not-inline qemu_fls() rather than calling clz32() directly? (probably not, I guess.) Alternatively, we seem to have a pow2floor() function...
-- PMM
Il 29/07/2013 14:41, Peter Maydell ha scritto:
Quoted 15 lines · Paolo Bonzini
Quoted 14 lines
The problem is introduced by commit 2332616 (exec: Support 64-bit operations in
address_space_rw, 2013-07-08). Before that commit,memory_access_sizewould only return 1/2/4.Since alignment is already handled above, reduce l to the largest power of two that is smaller than l.
Reported-by Oleksii Shevchuk <[email protected]>Tested-by Oleksii Shevchuk <[email protected]>Signed-off-by Paolo Bonzini <[email protected]>--- exec.c | 3 +++ 1 file changed, 3 insertions(+)
Quoted 14 lines
exec.c static int memory_access_size(MemoryRegion *mr, unsigned l, hwaddr addr) · line 1930
Quoted 11 lines
exec.c +3
-0@@ -1925,6 +1925,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 ); + }Is this a hot enough code path that we care about going via the not-inline
qemu_fls()rather than callingclz32()directly?
It is not that hot because of the "if".
Quoted 2 lines
(probably not, I guess.) Alternatively, we seem to have a
pow2floor()function...
Yeah, pow2floor is also nice. There's still a lot of opportunity for unification...
Paolo
[Qemu-devel] PING Re: [PATCH for-1.6] exec: fix writing to MMIO area with non-power-of-two length
In reply to Paolo BonziniIl 29/07/2013 14:28, Paolo Bonzini ha scritto:
Quoted 20 lines
The problem is introduced by commit 2332616 (exec: Support 64-bit operations in
address_space_rw, 2013-07-08). Before that commit,memory_access_sizewould only return 1/2/4.Since alignment is already handled above, reduce l to the largest power of two that is smaller than l.
Reported-by Oleksii Shevchuk <[email protected]>Tested-by Oleksii Shevchuk <[email protected]>Signed-off-by Paolo Bonzini <[email protected]>--- exec.c | 3 +++ 1 file changed, 3 insertions(+)exec.c +0
-0
exec.c static int memory_access_size(MemoryRegion *mr, unsigned l, hwaddr addr) · line 1933
Quoted 9 lines
exec.c +3
-0@@ -1925,6 +1925,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; }
Ping, and adding qemu-stable.
Paolo