Skip to contentSkip to conversation

vhost: fix dirty page handling

PATCH In review Michael S. Tsirkin 3 participants 3 messages Mar 16, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vhost: fix dirty page handling

vhost was passing a physical address to cpu_physical_memory_set_dirty, which is wrong: we need to translate to ram address first.

Note: this lead to crashes during migration, so the patch is needed on the stable branch too.

---
 hw/vhost.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
hw/vhost.c +3 -1
index aaa34e4..97a1299 100644
@@ -49,8 +49,10 @@ static void vhost_dev_sync_region(struct vhost_dev *dev,
         log = __sync_fetch_and_and(from, 0);
         while ((bit = sizeof(log) > sizeof(int) ?
                 ffsll(log) : ffs(log))) {
+            ram_addr_t ram_addr;
             bit -= 1;
-            cpu_physical_memory_set_dirty(addr + bit * VHOST_LOG_PAGE);
+            ram_addr = cpu_get_physical_page_desc(addr + bit * VHOST_LOG_PAGE);
+            cpu_physical_memory_set_dirty(ram_addr);
             log &= ~(0x1ull << bit);
         }
         addr += VHOST_LOG_CHUNK;
Signature · 1 line
1.7.3.2.91.g446ac
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Michael S. Tsirkin

vhost was passing a physical address to cpu_physical_memory_set_dirty, which is wrong: we need to translate to ram address first.

Note: this lead to crashes during migration, so the patch is needed on the stable branch too.

We have been having strange migration corruptions for some time, this can explain what was going on.

Quoted 10 lines
---
 hw/vhost.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
hw/vhost.c +0 -0
index aaa34e4..97a1299 100644
@@ -49,8 +49,10 @@ static void vhost_dev_sync_region(struct vhost_dev *dev,
         log = __sync_fetch_and_and(from, 0);

hw/vhost.c static void vhost_dev_sync_region(struct vhost_dev *dev, · line 58

Quoted 10 lines
hw/vhost.c +3 -1
         while ((bit = sizeof(log) > sizeof(int) ?
                 ffsll(log) : ffs(log))) {
+            ram_addr_t ram_addr;
             bit -= 1;
-            cpu_physical_memory_set_dirty(addr + bit * VHOST_LOG_PAGE);
+            ram_addr = cpu_get_physical_page_desc(addr + bit * VHOST_LOG_PAGE);
+            cpu_physical_memory_set_dirty(ram_addr);
             log &= ~(0x1ull << bit);
         }
         addr += VHOST_LOG_CHUNK;

<#secure method=pgpmime mode=sign>

Reviewed-by on v1 1/1
#2 lore raw
In reply to Michael S. Tsirkin
Quoted 18 lines · Michael S. Tsirkin

vhost was passing a physical address to cpu_physical_memory_set_dirty, which is wrong: we need to translate to ram address first.

Note: this lead to crashes during migration, so the patch is needed on the stable branch too.

---
 hw/vhost.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
hw/vhost.c +0 -0
index aaa34e4..97a1299 100644
@@ -49,8 +49,10 @@ static void vhost_dev_sync_region(struct vhost_dev *dev,
         log = __sync_fetch_and_and(from, 0);

hw/vhost.c static void vhost_dev_sync_region(struct vhost_dev *dev, · line 58

Quoted 10 lines
hw/vhost.c +3 -1
         while ((bit = sizeof(log) > sizeof(int) ?
                 ffsll(log) : ffs(log))) {
+            ram_addr_t ram_addr;
             bit -= 1;
-            cpu_physical_memory_set_dirty(addr + bit * VHOST_LOG_PAGE);
+            ram_addr = cpu_get_physical_page_desc(addr + bit * VHOST_LOG_PAGE);
+            cpu_physical_memory_set_dirty(ram_addr);
             log &= ~(0x1ull << bit);
         }
         addr += VHOST_LOG_CHUNK;