Skip to contentSkip to conversation

Fix off-by-one in dirty bitmap functions

PATCH Applied Avi Kivity 2 participants 2 messages Jan 29, 2012

lore
Share & tools
lore

Avi Kivity

author
#0 lore raw

PATCH 1/1 Fix off-by-one in dirty bitmap functions

---
 exec-obsolete.h |   10 ++++++----
 1 files changed, 6 insertions(+), 4 deletions(-)
exec-obsolete.h +6 -4
index 03cf35e..d2749d3 100644
@@ -83,9 +83,10 @@ static inline void cpu_physical_memory_set_dirty_range(ram_addr_t start,
     uint8_t *p;
     ram_addr_t addr, end;
 
-    end = start + length;
+    end = TARGET_PAGE_ALIGN(start + length);
+    start &= TARGET_PAGE_MASK;
     p = ram_list.phys_dirty + (start >> TARGET_PAGE_BITS);
-    for (addr = start; addr <= end; addr += TARGET_PAGE_SIZE) {
+    for (addr = start; addr < end; addr += TARGET_PAGE_SIZE) {
         *p++ |= dirty_flags;
     }
 }
@@ -98,10 +99,11 @@ static inline void cpu_physical_memory_mask_dirty_range(ram_addr_t start,
     uint8_t *p;
     ram_addr_t addr, end;
 
-    end = start + length;
+    end = TARGET_PAGE_ALIGN(start + length);
+    start &= TARGET_PAGE_MASK;
     mask = ~dirty_flags;
     p = ram_list.phys_dirty + (start >> TARGET_PAGE_BITS);
-    for (addr = start; addr <= end; addr += TARGET_PAGE_SIZE) {
+    for (addr = start; addr < end; addr += TARGET_PAGE_SIZE) {
         *p++ &= mask;
     }
 }
Signature · 1 line
1.7.7.1
Applied
#1 lore raw

Thanks, applied.

Quoted 40 lines · Avi Kivity

---
 exec-obsolete.h |   10 ++++++----

 1 files changed, 6 insertions(+), 4 deletions(-)
exec-obsolete.h +6 -5
index 03cf35e..d2749d3 100644
@@ -83,9 +83,10 @@ static inline void cpu_physical_memory_set_dirty_range(ram_addr_t start,
     uint8_t *p;
     ram_addr_t addr, end;
 
-    end = start + length;
+    end = TARGET_PAGE_ALIGN(start + length);
+    start &= TARGET_PAGE_MASK;
     p = ram_list.phys_dirty + (start >> TARGET_PAGE_BITS);
-    for (addr = start; addr <= end; addr += TARGET_PAGE_SIZE) {
+    for (addr = start; addr < end; addr += TARGET_PAGE_SIZE) {
         *p++ |= dirty_flags;
     }
  }
@@ -98,10 +99,11 @@ static inline void cpu_physical_memory_mask_dirty_range(ram_addr_t start,
     uint8_t *p;
     ram_addr_t addr, end;
 
-    end = start + length;
+    end = TARGET_PAGE_ALIGN(start + length);
+    start &= TARGET_PAGE_MASK;
     mask = ~dirty_flags;
     p = ram_list.phys_dirty + (start >> TARGET_PAGE_BITS);
-    for (addr = start; addr <= end; addr += TARGET_PAGE_SIZE) {
+    for (addr = start; addr < end; addr += TARGET_PAGE_SIZE) {
         *p++ &= mask;
     }
  }
--

1.7.7.1