virtio: clear signalled_used_valid when switching from dataplane
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
@@ -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
@@ -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
@@ -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
Quoted 10 lines · Stefan Hajnoczi
When the dataplane thread stops, its
vring.cimplementation synchronizes vring state back tovirtio.cso we can continue emulating the virtio device.This patch ensures that virtio.c's
signalled_used_validflag is reset so that we do not suppress guest notifications due to stalesignalled_usedvalues.Suggested-by Kevin Wolf <[email protected]>Signed-off-by Stefan Hajnoczi <[email protected]>
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@@ -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@@ -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@@ -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
Am 12.08.2013 um 11:08 hat Stefan Hajnoczi geschrieben:
Quoted 10 lines
When the dataplane thread stops, its
vring.cimplementation synchronizes vring state back tovirtio.cso we can continue emulating the virtio device.This patch ensures that virtio.c's
signalled_used_validflag is reset so that we do not suppress guest notifications due to stalesignalled_usedvalues.Suggested-by Kevin Wolf <[email protected]>Signed-off-by Stefan Hajnoczi <[email protected]>
Quoted 9 lines · Michael S. Tsirkin
Quoted 8 lines · Stefan Hajnoczi
When the dataplane thread stops, its
vring.cimplementation synchronizes vring state back tovirtio.cso we can continue emulating the virtio device.This patch ensures that virtio.c's
signalled_used_validflag is reset so that we do not suppress guest notifications due to stalesignalled_usedvalues.
Quoted 8 lines
Quoted 2 lines
Suggested-by Kevin Wolf <[email protected]>Signed-off-by Stefan Hajnoczi <[email protected]>Good point
Reviewed-by Michael S. Tsirkin <[email protected]>and we also need this for
vhost.cright?
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 17 lines · Stefan Hajnoczi
Quoted 16 lines · Michael S. Tsirkin
Quoted 10 lines · Stefan Hajnoczi
When the dataplane thread stops, its
vring.cimplementation synchronizes vring state back tovirtio.cso we can continue emulating the virtio device.This patch ensures that virtio.c's
signalled_used_validflag is reset so that we do not suppress guest notifications due to stalesignalled_usedvalues.Suggested-by Kevin Wolf <[email protected]>Signed-off-by Stefan Hajnoczi <[email protected]>Good point
Reviewed-by Michael S. Tsirkin <[email protected]>
Quoted 8 lines
Quoted 1 line
and we also need this for
vhost.cright?I think vhost is not affected by this because
virtio.cclears thesignalled_used_validflag when the device is reset. Sincevhost_netdoes 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.
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.cimplementation synchronizes vring state back tovirtio.cso we can continue emulating the virtio device.This patch ensures that virtio.c's
signalled_used_validflag is reset so that we do not suppress guest notifications due to stalesignalled_usedvalues.Suggested-by Kevin Wolf <[email protected]>Signed-off-by Stefan Hajnoczi <[email protected]>Good point
Reviewed-by Michael S. Tsirkin <[email protected]>and we also need this for
vhost.cright?
Quoted 8 lines
Quoted 6 lines
I think vhost is not affected by this because
virtio.cclears thesignalled_used_validflag when the device is reset. Sincevhost_netdoes 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
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.cimplementation synchronizes vring state back tovirtio.cso we can continue emulating the virtio device.This patch ensures that virtio.c's
signalled_used_validflag is reset so that we do not suppress guest notifications due to stalesignalled_usedvalues.Quoted 8 lines
Quoted 2 lines
Suggested-by Kevin Wolf <[email protected]>Signed-off-by Stefan Hajnoczi <[email protected]>Good point
Reviewed-by Michael S. Tsirkin <[email protected]>and we also need this for
vhost.cright?I think vhost is not affected by this because
virtio.cclears thesignalled_used_validflag when the device is reset. Sincevhost_netdoes 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