Skip to contentSkip to conversation

virtio/vhost: reset dev->log after syncing

PATCH In review Felipe Franciosi 4 participants 6 messages Sep 20, 2017 – Sep 25, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 virtio/vhost: reset dev->log after syncing

vhost_log_put() is called to decomission the dirty log between qemu and a vhost device when stopping the device. Such a call can happen from migration_completion().

Present code sets dev->log_size to zero too early in vhost_log_put(), causing the sync check to always return false. As a consequence, the last pass on the dirty bitmap never happens at the end of migration.

If a vhost device was busy (writing to guest memory) until the last moments before vhost_virtqueue_stop(), this error will result in guest memory corruption (at least) following migrations.

---
 hw/virtio/vhost.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
hw/virtio/vhost.c +3 -2
index 5fd69f0..ddc42f0 100644
@@ -375,8 +375,6 @@ static void vhost_log_put(struct vhost_dev *dev, bool sync)
     if (!log) {
         return;
     }
-    dev->log = NULL;
-    dev->log_size = 0;
 
     --log->refcnt;
     if (log->refcnt == 0) {
@@ -396,6 +394,9 @@ static void vhost_log_put(struct vhost_dev *dev, bool sync)
 
         g_free(log);
     }
+
+    dev->log = NULL;
+    dev->log_size = 0;
 }
 
 static bool vhost_dev_log_is_shared(struct vhost_dev *dev)
Signature · 1 line
1.7.1
#1 lore raw

Hi

----- Original Message -----

Quoted 22 lines

vhost_log_put() is called to decomission the dirty log between qemu and a vhost device when stopping the device. Such a call can happen from migration_completion().

Present code sets dev->log_size to zero too early in vhost_log_put(), causing the sync check to always return false. As a consequence, the last pass on the dirty bitmap never happens at the end of migration.

If a vhost device was busy (writing to guest memory) until the last moments before vhost_virtqueue_stop(), this error will result in guest memory corruption (at least) following migrations.

---
 hw/virtio/vhost.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
hw/virtio/vhost.c +0 -0
index 5fd69f0..ddc42f0 100644

hw/virtio/vhost.c static void vhost_log_put(struct vhost_dev *dev, bool · line 379

Quoted 7 lines
hw/virtio/vhost.c +0 -2
@@ -375,8 +375,6 @@ static void vhost_log_put(struct vhost_dev *dev, bool
 sync)
     if (!log) {
         return;
     }
-    dev->log = NULL;
-    dev->log_size = 0;
 

Good catch. This reminds me of another patch, but I can't find it.

What if we replace dev->log_size with log->size below?

(and I don't see a clear reason why dev->log_size would be different from "log ? log->size : 0", am I missing something?)

Quoted 18 lines
hw/virtio/vhost.c +0 -0
     --log->refcnt;
     if (log->refcnt == 0) {
hw/virtio/vhost.c +3 -0
@@ -396,6 +394,9 @@ static void vhost_log_put(struct vhost_dev *dev, bool
 sync)
 
         g_free(log);
     }
+
+    dev->log = NULL;
+    dev->log_size = 0;
 
 }

static bool vhost_dev_log_is_shared(struct vhost_dev *dev)
--
1.7.1

#2 lore raw

Heya,

Quoted 22 lines · Marc-André Lureau

Hi

----- Original Message -----

Quoted 17 lines

vhost_log_put() is called to decomission the dirty log between qemu and a vhost device when stopping the device. Such a call can happen from migration_completion().

Present code sets dev->log_size to zero too early in vhost_log_put(), causing the sync check to always return false. As a consequence, the last pass on the dirty bitmap never happens at the end of migration.

If a vhost device was busy (writing to guest memory) until the last moments before vhost_virtqueue_stop(), this error will result in guest memory corruption (at least) following migrations.

---
hw/virtio/vhost.c | 5 +++--

1 files changed, 3 insertions(+), 2 deletions(-)
Quoted 15 lines

hw/virtio/vhost.c static void vhost_log_put(struct vhost_dev *dev, bool · line 379

Quoted 12 lines
hw/virtio/vhost.c +0 -2
index 5fd69f0..ddc42f0 100644
@@ -375,8 +375,6 @@ static void vhost_log_put(struct vhost_dev *dev, bool
 sync)
    if (!log) {
        return;
    }
-    dev->log = NULL;
-    dev->log_size = 0;
 

Good catch. This reminds me of another patch, but I can't find it.

I actually ran into this error when testing migration with a vhost-user-scsi backed controller and a request that completes while quiescing on a VRING_GET_BASE. Took me a while to figure out why the bitmap wasn't being honoured by Qemu. :(

Quoted 4 lines

What if we replace dev->log_size with log->size below?

(and I don't see a clear reason why dev->log_size would be different from "log ? log->size : 0", am I missing something?)

I can see that vhost_dev_log_resize() changes dev->log_size without necessarily changing dev->log_size. Having said that, it seems like the latter gets correctly updated during vhost_log_get() which happens on the same function.

In any case, I feel like any further improvement to the function should be discussed and done in a separate commit.

Cheers,
Felipe

Quoted 20 lines
Quoted 19 lines
hw/virtio/vhost.c +0 -0
    --log->refcnt;
    if (log->refcnt == 0) {
hw/virtio/vhost.c +3 -0
@@ -396,6 +394,9 @@ static void vhost_log_put(struct vhost_dev *dev, bool
 sync)
 
        g_free(log);
    }
+
+    dev->log = NULL;
+    dev->log_size = 0;
 
 }

static bool vhost_dev_log_is_shared(struct vhost_dev *dev) --
1.7.1

Acked-by on v1 1/1
#3 lore raw
In reply to Felipe Franciosi
Quoted 31 lines · Felipe Franciosi

vhost_log_put() is called to decomission the dirty log between qemu and a vhost device when stopping the device. Such a call can happen from migration_completion().

Present code sets dev->log_size to zero too early in vhost_log_put(), causing the sync check to always return false. As a consequence, the last pass on the dirty bitmap never happens at the end of migration.

If a vhost device was busy (writing to guest memory) until the last moments before vhost_virtqueue_stop(), this error will result in guest memory corruption (at least) following migrations.

---
  hw/virtio/vhost.c |    5 +++--
  1 files changed, 3 insertions(+), 2 deletions(-)
hw/virtio/vhost.c +0 -2
index 5fd69f0..ddc42f0 100644
@@ -375,8 +375,6 @@ static void vhost_log_put(struct vhost_dev *dev, bool sync)
      if (!log) {
          return;
      }
-    dev->log = NULL;
-    dev->log_size = 0;
 
      --log->refcnt;
      if (log->refcnt == 0) {

hw/virtio/vhost.c static void vhost_log_put(struct vhost_dev *dev, bool sync) · line 402

Quoted 9 lines
hw/virtio/vhost.c +3 -0
@@ -396,6 +394,9 @@ static void vhost_log_put(struct vhost_dev *dev, bool sync)
 
          g_free(log);
      }
+
+    dev->log = NULL;
+    dev->log_size = 0;
  }
 
  static bool vhost_dev_log_is_shared(struct vhost_dev *dev)

Thanks

Reviewed-by on v1 1/1
#4 lore raw
In reply to Felipe Franciosi

----- Original Message -----

Quoted 8 lines

vhost_log_put() is called to decomission the dirty log between qemu and a vhost device when stopping the device. Such a call can happen from migration_completion().

Present code sets dev->log_size to zero too early in vhost_log_put(), causing the sync check to always return false. As a consequence, the last pass on the dirty bitmap never happens at the end of migration.

Quoted 5 lines

If a vhost device was busy (writing to guest memory) until the last moments before vhost_virtqueue_stop(), this error will result in guest memory corruption (at least) following migrations.

Quoted 33 lines
---
 hw/virtio/vhost.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
hw/virtio/vhost.c +0 -2
index 5fd69f0..ddc42f0 100644
@@ -375,8 +375,6 @@ static void vhost_log_put(struct vhost_dev *dev, bool
 sync)
     if (!log) {
         return;
     }
-    dev->log = NULL;
-    dev->log_size = 0;
 
     --log->refcnt;
     if (log->refcnt == 0) {
hw/virtio/vhost.c +3 -0
@@ -396,6 +394,9 @@ static void vhost_log_put(struct vhost_dev *dev, bool
 sync)
 
         g_free(log);
     }
+
+    dev->log = NULL;
+    dev->log_size = 0;
 }
 

static bool vhost_dev_log_is_shared(struct vhost_dev *dev)
--
1.7.1

#5 lore raw
In reply to Felipe Franciosi

Quoting Felipe Franciosi (2017-09-20 13:53:06)

Quoted 8 lines

vhost_log_put() is called to decomission the dirty log between qemu and a vhost device when stopping the device. Such a call can happen from migration_completion().

Present code sets dev->log_size to zero too early in vhost_log_put(), causing the sync check to always return false. As a consequence, the last pass on the dirty bitmap never happens at the end of migration.

Quoted 5 lines

If a vhost device was busy (writing to guest memory) until the last moments before vhost_virtqueue_stop(), this error will result in guest memory corruption (at least) following migrations.

FYI: this patch has been tagged for stable 2.10.1, but is not yet upstream. Patch freeze for 2.10.1 is September 27th.

Quoted 31 lines
---
 hw/virtio/vhost.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
hw/virtio/vhost.c +3 -2
index 5fd69f0..ddc42f0 100644
@@ -375,8 +375,6 @@ static void vhost_log_put(struct vhost_dev *dev, bool sync)
     if (!log) {
         return;
     }
-    dev->log = NULL;
-    dev->log_size = 0;
 
     --log->refcnt;
     if (log->refcnt == 0) {
@@ -396,6 +394,9 @@ static void vhost_log_put(struct vhost_dev *dev, bool sync)
 
         g_free(log);
     }
+
+    dev->log = NULL;
+    dev->log_size = 0;
 }
 
 static bool vhost_dev_log_is_shared(struct vhost_dev *dev)
Signature · 1 line
1.7.1