Skip to contentSkip to conversation

memory: Fix start offset for bitmap log_clear hook

PATCH In review Matt Borgerson 3 participants 4 messages Feb 18, 2020 – Mar 2, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 memory: Fix start offset for bitmap log_clear hook

Currently only the final page offset is being passed to the log_clear hook via memory_region_clear_dirty_bitmap after it is used as an iterator in cpu_physical_memory_test_and_clear_dirty. This patch corrects the start address and size of the region.

---
 exec.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
exec.c +5 -4
index 8e9cc3b47c..f0f7d0be49 100644
@@ -1314,7 +1314,7 @@ bool cpu_physical_memory_test_and_clear_dirty(ram_addr_t start,
                                               unsigned client)
 {
     DirtyMemoryBlocks *blocks;
-    unsigned long end, page;
+    unsigned long end, page, start_page;
     bool dirty = false;
     RAMBlock *ramblock;
     uint64_t mr_offset, mr_size;
@@ -1324,7 +1324,8 @@ bool cpu_physical_memory_test_and_clear_dirty(ram_addr_t start,
     }
 
     end = TARGET_PAGE_ALIGN(start + length) >> TARGET_PAGE_BITS;
-    page = start >> TARGET_PAGE_BITS;
+    start_page = start >> TARGET_PAGE_BITS;
+    page = start_page;
 
     WITH_RCU_READ_LOCK_GUARD() {
         blocks = atomic_rcu_read(&ram_list.dirty_memory[client]);
@@ -1344,8 +1345,8 @@ bool cpu_physical_memory_test_and_clear_dirty(ram_addr_t start,
             page += num;
         }
 
-        mr_offset = (ram_addr_t)(page << TARGET_PAGE_BITS) - ramblock->offset;
-        mr_size = (end - page) << TARGET_PAGE_BITS;
+        mr_offset = (ram_addr_t)(start_page << TARGET_PAGE_BITS) - ramblock->offset;
+        mr_size = (end - start_page) << TARGET_PAGE_BITS;
         memory_region_clear_dirty_bitmap(ramblock->mr, mr_offset, mr_size);
     }
 
Signature · 1 line
2.17.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Matt Borgerson

Currently only the final page offset is being passed to the log_clear hook via memory_region_clear_dirty_bitmap after it is used as an iterator in cpu_physical_memory_test_and_clear_dirty. This patch corrects the start address and size of the region.

Looks correct, thanks!

Signature · 1 line
Peter Xu
#2 lore raw

[ ping ]

Hi Paolo, would you mind taking a quick look at this patch for memory.c to consider
it for merge? This resolves an issue with dirty bits not being cleared as expected.

Here's the Patchwork link: http://patchwork.ozlabs.org/patch/1240121/

Thanks for your time!

Matt

Quoted 16 lines · Peter Xu
Quoted 6 lines · Matt Borgerson

Currently only the final page offset is being passed to the log_clear hook via memory_region_clear_dirty_bitmap after it is used as an iterator in cpu_physical_memory_test_and_clear_dirty. This patch corrects the start address and size of the region.

Looks correct, thanks!

--
Peter Xu

#3 lore raw
Quoted 10 lines · Matt Borgerson

[ ping ]

Hi Paolo, would you mind taking a quick look at this patch for memory.c to consider
it for merge? This resolves an issue with dirty bits not being cleared as expected.

Here's the Patchwork link: http://patchwork.ozlabs.org/patch/1240121/

Thanks for your time!

Yes, I queued it now.

Thanks!

Paolo