Skip to contentSkip to conversation

exec: fix writing to MMIO area with non-power-of-two length

PATCH In review Paolo Bonzini 2 participants 4 messages Jul 29, 2013 – Aug 30, 2013

lore
Share & tools
lore
#0 lore raw

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
index c4f2894..e122c81 100644
@@ -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
#1 lore raw
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_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 +0 -0
index c4f2894..e122c81 100644

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

#2 lore raw

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_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(+)
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
index c4f2894..e122c81 100644
@@ -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?

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

#3 lore raw

[Qemu-devel] PING Re: [PATCH for-1.6] exec: fix writing to MMIO area with non-power-of-two length

In reply to Paolo Bonzini

Il 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_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 +0 -0
index c4f2894..e122c81 100644

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