Skip to contentSkip to conversation

virtio: clear signalled_used_valid when switching from dataplane

PATCH In review Stefan Hajnoczi 4 participants 7 messages Aug 12, 2013 – Aug 13, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 virtio: clear signalled_used_valid when switching from dataplane

When the dataplane thread stops, its vring.c implementation synchronizes vring state back to virtio.c so we can continue emulating the virtio device.

This patch ensures that virtio.c's signalled_used_valid flag is reset so that we do not suppress guest notifications due to stale signalled_used values.

---
 hw/virtio/dataplane/vring.c | 1 +
 hw/virtio/virtio.c          | 5 +++++
 include/hw/virtio/virtio.h  | 1 +
 3 files changed, 7 insertions(+)
hw/virtio/dataplane/vring.c +1 -0
index 82cc151..351a343 100644
@@ -52,6 +52,7 @@ bool vring_setup(Vring *vring, VirtIODevice *vdev, int n)
 void vring_teardown(Vring *vring, VirtIODevice *vdev, int n)
 {
     virtio_queue_set_last_avail_idx(vdev, n, vring->last_avail_idx);
+    virtio_queue_invalidate_signalled_used(vdev, n);
 
     hostmem_finalize(&vring->hostmem);
 }
hw/virtio/virtio.c +5 -0
index 09f62c6..706bdf4 100644
@@ -1059,6 +1059,11 @@ void virtio_queue_set_last_avail_idx(VirtIODevice *vdev, int n, uint16_t idx)
     vdev->vq[n].last_avail_idx = idx;
 }
 
+void virtio_queue_invalidate_signalled_used(VirtIODevice *vdev, int n)
+{
+    vdev->vq[n].signalled_used_valid = false;
+}
+
 VirtQueue *virtio_get_queue(VirtIODevice *vdev, int n)
 {
     return vdev->vq + n;
include/hw/virtio/virtio.h +1 -0
index d7e9e0f..a90522d 100644
@@ -237,6 +237,7 @@ hwaddr virtio_queue_get_used_size(VirtIODevice *vdev, int n);
 hwaddr virtio_queue_get_ring_size(VirtIODevice *vdev, int n);
 uint16_t virtio_queue_get_last_avail_idx(VirtIODevice *vdev, int n);
 void virtio_queue_set_last_avail_idx(VirtIODevice *vdev, int n, uint16_t idx);
+void virtio_queue_invalidate_signalled_used(VirtIODevice *vdev, int n);
 VirtQueue *virtio_get_queue(VirtIODevice *vdev, int n);
 uint16_t virtio_get_queue_index(VirtQueue *vq);
 int virtio_queue_get_id(VirtQueue *vq);
Signature · 1 line
1.8.3.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Stefan Hajnoczi

When the dataplane thread stops, its vring.c implementation synchronizes vring state back to virtio.c so we can continue emulating the virtio device.

This patch ensures that virtio.c's signalled_used_valid flag is reset so that we do not suppress guest notifications due to stale signalled_used values.

Good point

and we also need this for vhost.c right?

Quoted 48 lines
---
 hw/virtio/dataplane/vring.c | 1 +
 hw/virtio/virtio.c          | 5 +++++
 include/hw/virtio/virtio.h  | 1 +
 3 files changed, 7 insertions(+)
hw/virtio/dataplane/vring.c +1 -0
index 82cc151..351a343 100644
@@ -52,6 +52,7 @@ bool vring_setup(Vring *vring, VirtIODevice *vdev, int n)
 void vring_teardown(Vring *vring, VirtIODevice *vdev, int n)
 {
     virtio_queue_set_last_avail_idx(vdev, n, vring->last_avail_idx);
+    virtio_queue_invalidate_signalled_used(vdev, n);
 
     hostmem_finalize(&vring->hostmem);
 }
hw/virtio/virtio.c +5 -0
index 09f62c6..706bdf4 100644
@@ -1059,6 +1059,11 @@ void virtio_queue_set_last_avail_idx(VirtIODevice *vdev, int n, uint16_t idx)
     vdev->vq[n].last_avail_idx = idx;
 }
 
+void virtio_queue_invalidate_signalled_used(VirtIODevice *vdev, int n)
+{
+    vdev->vq[n].signalled_used_valid = false;
+}
+
 VirtQueue *virtio_get_queue(VirtIODevice *vdev, int n)
 {
     return vdev->vq + n;
include/hw/virtio/virtio.h +1 -0
index d7e9e0f..a90522d 100644
@@ -237,6 +237,7 @@ hwaddr virtio_queue_get_used_size(VirtIODevice *vdev, int n);
 hwaddr virtio_queue_get_ring_size(VirtIODevice *vdev, int n);
 uint16_t virtio_queue_get_last_avail_idx(VirtIODevice *vdev, int n);
 void virtio_queue_set_last_avail_idx(VirtIODevice *vdev, int n, uint16_t idx);
+void virtio_queue_invalidate_signalled_used(VirtIODevice *vdev, int n);
 VirtQueue *virtio_get_queue(VirtIODevice *vdev, int n);
 uint16_t virtio_get_queue_index(VirtQueue *vq);
 int virtio_queue_get_id(VirtQueue *vq);
Signature · 1 line
1.8.3.1
Reviewed-by on v1 1/1
#6 lore raw
In reply to Stefan Hajnoczi

Am 12.08.2013 um 11:08 hat Stefan Hajnoczi geschrieben:

Quoted 10 lines

When the dataplane thread stops, its vring.c implementation synchronizes vring state back to virtio.c so we can continue emulating the virtio device.

This patch ensures that virtio.c's signalled_used_valid flag is reset so that we do not suppress guest notifications due to stale signalled_used values.

#2 lore raw
In reply to Michael S. Tsirkin
Quoted 9 lines · Michael S. Tsirkin
Quoted 8 lines · Stefan Hajnoczi

When the dataplane thread stops, its vring.c implementation synchronizes vring state back to virtio.c so we can continue emulating the virtio device.

This patch ensures that virtio.c's signalled_used_valid flag is reset so that we do not suppress guest notifications due to stale signalled_used values.

Quoted 8 lines
Quoted 2 lines

Good point

and we also need this for vhost.c right?

I think vhost is not affected by this because virtio.c clears the signalled_used_valid flag when the device is reset. Since vhost_net does not transition back and forth between userspace virtio and vhost (without a device reset), there is no need to reset the flag.

Stefan

#3 lore raw
Quoted 17 lines · Stefan Hajnoczi
Quoted 16 lines · Michael S. Tsirkin
Quoted 10 lines · Stefan Hajnoczi

When the dataplane thread stops, its vring.c implementation synchronizes vring state back to virtio.c so we can continue emulating the virtio device.

This patch ensures that virtio.c's signalled_used_valid flag is reset so that we do not suppress guest notifications due to stale signalled_used values.

Good point

Quoted 8 lines
Quoted 1 line

and we also need this for vhost.c right?

I think vhost is not affected by this because virtio.c clears the signalled_used_valid flag when the device is reset. Since vhost_net does not transition back and forth between userspace virtio and vhost (without a device reset), there is no need to reset the flag.

Stefan

Yes it does transition on vm stop/start.

#4 lore raw
Quoted 20 lines · Michael S. Tsirkin
Quoted 19 lines · Stefan Hajnoczi
Quoted 17 lines · Michael S. Tsirkin
Quoted 10 lines · Stefan Hajnoczi

When the dataplane thread stops, its vring.c implementation synchronizes vring state back to virtio.c so we can continue emulating the virtio device.

This patch ensures that virtio.c's signalled_used_valid flag is reset so that we do not suppress guest notifications due to stale signalled_used values.

Good point

and we also need this for vhost.c right?

Quoted 8 lines
Quoted 6 lines

I think vhost is not affected by this because virtio.c clears the signalled_used_valid flag when the device is reset. Since vhost_net does not transition back and forth between userspace virtio and vhost (without a device reset), there is no need to reset the flag.

Stefan

Yes it does transition on vm stop/start.

I see. Come to think of it maybe dataplane could use virtio.c's vm change state handler instead of registering its own. Anyway, thanks for pointing this out.

Stefan

#5 lore raw
Quoted 28 lines · Stefan Hajnoczi
Quoted 27 lines · Michael S. Tsirkin
Quoted 25 lines · Stefan Hajnoczi
Quoted 9 lines · Michael S. Tsirkin
Quoted 8 lines · Stefan Hajnoczi

When the dataplane thread stops, its vring.c implementation synchronizes vring state back to virtio.c so we can continue emulating the virtio device.

This patch ensures that virtio.c's signalled_used_valid flag is reset so that we do not suppress guest notifications due to stale signalled_used values.

Quoted 8 lines
Quoted 2 lines

Good point

and we also need this for vhost.c right?

I think vhost is not affected by this because virtio.c clears the signalled_used_valid flag when the device is reset. Since vhost_net does not transition back and forth between userspace virtio and vhost (without a device reset), there is no need to reset the flag.

Stefan

Quoted 7 lines
Quoted 1 line

Yes it does transition on vm stop/start.

I see. Come to think of it maybe dataplane could use virtio.c's vm change state handler instead of registering its own. Anyway, thanks for pointing this out.

Stefan

It probably should esp if you have a handler for virtio status:
this is the only way to guarantee they are called in a sane order.

Signature · 1 line
MST