virtio: detach VirtQueueElements freed by reset
cover virtio: detach VirtQueueElements freed by reset
virtio-blk and virtio-serial need to free VirtQueueElements during device reset. Simply calling g_free(elem) is not enough because the scatter-gather list should be unmapped and vq->inuse must be decremented.
These patches address the issue. I am not including a patch that changes vq->inuse = 0 to assert(!vq->inuse) in virtio_reset() yet because virtio-9p, virtio-gpu, and virtio-net have code paths that do not decrement vq->inuse.
Stefan Hajnoczi (3):
virtio: add virtio_detach_element()
virtio-blk: add missing virtio_detach_element() call
virtio-serial: add missing virtio_detach_element() call
hw/block/virtio-blk.c | 1 + hw/char/virtio-serial-bus.c | 14 ++++++++++++++ hw/virtio/virtio.c | 27 +++++++++++++++++++++++++-- include/hw/virtio/virtio.h | 2 ++ 4 files changed, 42 insertions(+), 2 deletions(-)
Signature · 1 line
2.7.4
PATCH 1/3 virtio: add virtio_detach_element()
During device reset or similar situations a VirtQueueElement needs to be freed without pushing it onto the used ring or rewinding the virtqueue. Extract a new function to do this.
Later patches add virtio_detach_element() calls to existing device so that scatter-gather lists are unmapped and vq->inuse goes back to zero during device reset. Currently some devices don't bother and simply call g_free(elem) which is not a clean way to throw away a VirtQueueElement.
--- hw/virtio/virtio.c | 27 +++++++++++++++++++++++++-- include/hw/virtio/virtio.h | 2 ++ 2 files changed, 27 insertions(+), 2 deletions(-)
hw/virtio/virtio.c +25 -2
@@ -264,12 +264,35 @@ static void virtqueue_unmap_sg(VirtQueue *vq, const VirtQueueElement *elem, 0, elem->out_sg[i].iov_len); } +/* virtqueue_detach_element: +* @vq: The #VirtQueue +* @elem: The #VirtQueueElement +* @len: number of bytes written +* +* Detach the element from the virtqueue. This function is suitable for device +* reset or other situations where a #VirtQueueElement is simply freed and will +* not be pushed or discarded. +*/ +void virtqueue_detach_element (VirtQueue *vq,const VirtQueueElement *elem, +unsigned int len) +{ + vq->inuse--; +virtqueue_unmap_sg (vq, elem, len); +} + +/* virtqueue_discard: +* @vq: The #VirtQueue +* @elem: The #VirtQueueElement +* @len: number of bytes written +* +* Pretend the most recent element wasn't popped from the virtqueue. The next +* call to virtqueue_pop() will refetch the element. +*/ void virtqueue_discard (VirtQueue *vq,const VirtQueueElement *elem,unsigned int len) { vq->last_avail_idx--; - vq->inuse--; -virtqueue_unmap_sg (vq, elem, len); +virtqueue_detach_element (vq, elem, len); }/* virtqueue_rewind:
include/hw/virtio/virtio.h +2 -0
@@ -152,6 +152,8 @@ void *virtqueue_alloc_element(size_t sz, unsigned out_num, unsigned in_num);void virtqueue_push (VirtQueue *vq,const VirtQueueElement *elem,unsigned int len);void virtqueue_flush (VirtQueue *vq,unsigned int count); +void virtqueue_detach_element (VirtQueue *vq,const VirtQueueElement *elem, +unsigned int len);void virtqueue_discard (VirtQueue *vq,const VirtQueueElement *elem,unsigned int len);bool virtqueue_rewind (VirtQueue *vq,unsigned int num);
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH 1/3] virtio: add virtio_detach_element()
Quoted 4 lines · On Mon, 19 Sep 2016 14:28:03 +0100 Stefan Hajnoczi <[email protected]> wrote:
During device reset or similar situations a VirtQueueElement needs to be freed without pushing it onto the used ring or rewinding the virtqueue. Extract a new function to do this.
Quoted 8 lines
Later patches add
virtio_detach_element()calls to existing device so that scatter-gather lists are unmapped andvq->inusegoes back to zero during device reset. Currently some devices don't bother and simply callg_free(elem)which is not a clean way to throw away a VirtQueueElement.Signed-off-by Stefan Hajnoczi <[email protected]>---
FWIW
Quoted 59 lines
hw/virtio/virtio.c | 27 +++++++++++++++++++++++++-- include/hw/virtio/virtio.h | 2 ++ 2 files changed, 27 insertions(+), 2 deletions(-)hw/virtio/virtio.c +25
-2@@ -264,12 +264,35 @@ static void virtqueue_unmap_sg(VirtQueue *vq, const VirtQueueElement *elem, 0, elem->out_sg[i].iov_len); } +/* virtqueue_detach_element: +* @vq: The #VirtQueue +* @elem: The #VirtQueueElement +* @len: number of bytes written +* +* Detach the element from the virtqueue. This function is suitable for device +* reset or other situations where a #VirtQueueElement is simply freed and will +* not be pushed or discarded. +*/ +void virtqueue_detach_element (VirtQueue *vq,const VirtQueueElement *elem, +unsigned int len) +{ + vq->inuse--; +virtqueue_unmap_sg (vq, elem, len); +} + +/* virtqueue_discard: +* @vq: The #VirtQueue +* @elem: The #VirtQueueElement +* @len: number of bytes written +* +* Pretend the most recent element wasn't popped from the virtqueue. The next +* call to virtqueue_pop() will refetch the element. +*/ void virtqueue_discard (VirtQueue *vq,const VirtQueueElement *elem,unsigned int len) { vq->last_avail_idx--; - vq->inuse--; -virtqueue_unmap_sg (vq, elem, len); +virtqueue_detach_element (vq, elem, len); }/* virtqueue_rewind: include/hw/virtio/virtio.h +2
-0@@ -152,6 +152,8 @@ void *virtqueue_alloc_element(size_t sz, unsigned out_num, unsigned in_num);void virtqueue_push (VirtQueue *vq,const VirtQueueElement *elem,unsigned int len);void virtqueue_flush (VirtQueue *vq,unsigned int count); +void virtqueue_detach_element (VirtQueue *vq,const VirtQueueElement *elem, +unsigned int len);void virtqueue_discard (VirtQueue *vq,const VirtQueueElement *elem,unsigned int len);bool virtqueue_rewind (VirtQueue *vq,unsigned int num);
Re: [Qemu-devel] [PATCH 1/3] virtio: add virtio_detach_element()
In reply to Stefan HajnocziQuoted 45 lines · Stefan Hajnoczi
During device reset or similar situations a VirtQueueElement needs to be freed without pushing it onto the used ring or rewinding the virtqueue. Extract a new function to do this.
Later patches add
virtio_detach_element()calls to existing device so that scatter-gather lists are unmapped andvq->inusegoes back to zero during device reset. Currently some devices don't bother and simply callg_free(elem)which is not a clean way to throw away a VirtQueueElement.Signed-off-by Stefan Hajnoczi <[email protected]>--- hw/virtio/virtio.c | 27 +++++++++++++++++++++++++-- include/hw/virtio/virtio.h | 2 ++ 2 files changed, 27 insertions(+), 2 deletions(-)hw/virtio/virtio.c +21
-0@@ -264,12 +264,35 @@ static void virtqueue_unmap_sg(VirtQueue *vq, const VirtQueueElement *elem, 0, elem->out_sg[i].iov_len); } +/* virtqueue_detach_element: +* @vq: The #VirtQueue +* @elem: The #VirtQueueElement +* @len: number of bytes written +* +* Detach the element from the virtqueue. This function is suitable for device +* reset or other situations where a #VirtQueueElement is simply freed and will +* not be pushed or discarded. +*/ +void virtqueue_detach_element (VirtQueue *vq,const VirtQueueElement *elem, +unsigned int len) +{ + vq->inuse--; +virtqueue_unmap_sg (vq, elem, len); +} + +/* virtqueue_discard: +* @vq: The #VirtQueue +* @elem: The #VirtQueueElement +* @len: number of bytes written +*
hw/virtio/virtio.c static void virtqueue_unmap_sg(VirtQueue *vq, const VirtQueueElement *elem, · line 295
Quoted 10 lines
hw/virtio/virtio.c +4
-2+* Pretend the most recent element wasn't popped from the virtqueue. The next +* call to virtqueue_pop() will refetch the element. +*/ void virtqueue_discard (VirtQueue *vq,const VirtQueueElement *elem,unsigned int len) { vq->last_avail_idx--; - vq->inuse--; -virtqueue_unmap_sg (vq, elem, len); +virtqueue_detach_element (vq, elem, len);
Random comment, not directly related to this change. Would it be worth adding an assert to this function that elem->index and vq->last_avail_idx match? In other words, enforce the "most recent" qualifier mentioned in the comment. As more virtqueue_* functions are added and the complexity goes up, it is easy to get confused. Also, I think that naming this function virtqueue_unpop instead of virtqueue_discard would help.
Quoted 17 lines
hw/virtio/virtio.c +0
-0}/* virtqueue_rewind: include/hw/virtio/virtio.h +2
-1@@ -152,6 +152,8 @@ void *virtqueue_alloc_element(size_t sz, unsigned out_num, unsigned in_num);void virtqueue_push (VirtQueue *vq,const VirtQueueElement *elem,unsigned int len);void virtqueue_flush (VirtQueue *vq,unsigned int count); +void virtqueue_detach_element (VirtQueue *vq,const VirtQueueElement *elem, +unsigned int len);void virtqueue_discard (VirtQueue *vq,const VirtQueueElement *elem,unsigned int len);bool virtqueue_rewind (VirtQueue *vq,unsigned int num); --
Quoted 2 lines
2.7.4
Thanks!
Ladi
Re: [Qemu-devel] [PATCH 1/3] virtio: add virtio_detach_element()
Quoted 17 lines · Ladi Prosek
Quoted 12 lines · Stefan Hajnoczi
During device res> > +/*
virtqueue_discard:
+ * @vq: The #VirtQueue
+ * @elem: The #VirtQueueElement
+ * @len: number of bytes written
+ *
+ * Pretend the most recent element wasn't popped from the virtqueue. The next
+ * call tovirtqueue_pop()will refetch the element.
+ */
void virtqueue_discard(VirtQueue *vq, const VirtQueueElement *elem,
unsigned int len){ vq->last_avail_idx--;hw/virtio/virtio.c static void virtqueue_unmap_sg(VirtQueue *vq, const VirtQueueElement *elem, · line 295
Quoted 3 lines
hw/virtio/virtio.c +1
-2- vq->inuse--; -virtqueue_unmap_sg (vq, elem, len); +virtqueue_detach_element (vq, elem, len);
Quoted 7 lines
Random comment, not directly related to this change. Would it be worth adding an assert to this function that
elem->indexandvq->last_avail_idxmatch? In other words, enforce the "most recent" qualifier mentioned in the comment. As more virtqueue_* functions are added and the complexity goes up, it is easy to get confused. Also, I think that naming this functionvirtqueue_unpopinstead ofvirtqueue_discardwould help.
elem->index is a descriptor ring index. vq->last_avail_idx is an index into the available ring. They are different but your suggestion makes sense in general.
We shouldn't read from vring memory again for an assertion so deferencing the available ring isn't possible (because we cannot rely on vring memory contents after processing the request). One way to implement the assertion is to put VirtQueueElements on a linked list (vq->inuse_elems) but that probably needs live migration support.
I agree that renaming to unpop makes the semantics clearer.
Would you like to submit a patch for either or both?
Re: [Qemu-devel] [PATCH 1/3] virtio: add virtio_detach_element()
Quoted 26 lines · Stefan Hajnoczi
Quoted 17 lines · Ladi Prosek
Quoted 12 lines · Stefan Hajnoczi
During device res> > +/*
virtqueue_discard:
+ * @vq: The #VirtQueue
+ * @elem: The #VirtQueueElement
+ * @len: number of bytes written
+ *
+ * Pretend the most recent element wasn't popped from the virtqueue. The next
+ * call tovirtqueue_pop()will refetch the element.
+ */
void virtqueue_discard(VirtQueue *vq, const VirtQueueElement *elem,
unsigned int len){ vq->last_avail_idx--;hw/virtio/virtio.c static void virtqueue_unmap_sg(VirtQueue *vq, const VirtQueueElement *elem, · line 295
Quoted 3 lines
hw/virtio/virtio.c +1
-2- vq->inuse--; -virtqueue_unmap_sg (vq, elem, len); +virtqueue_detach_element (vq, elem, len);Quoted 7 lines
Random comment, not directly related to this change. Would it be worth adding an assert to this function that
elem->indexandvq->last_avail_idxmatch? In other words, enforce the "most recent" qualifier mentioned in the comment. As more virtqueue_* functions are added and the complexity goes up, it is easy to get confused. Also, I think that naming this functionvirtqueue_unpopinstead ofvirtqueue_discardwould help.
Quoted 3 lines
elem->indexis a descriptor ring index.vq->last_avail_idxis an index into the available ring. They are different but your suggestion makes sense in general.
Oh, right, I didn't mean they would be identical but something like this:
g_assert(elem->index == virtqueue_get_head(vq, vq->last_avail_idx));
Quoted 3 lines
We shouldn't read from vring memory again for an assertion so deferencing the available ring isn't possible (because we cannot rely on vring memory contents after processing the request).
Not sure I follow, shouldn't available ring memory at that index still be the same? Basically I'd like to assert that the next virtqueue_pop would return the same element.
Quoted 7 lines
One way to
implement the assertion is to put VirtQueueElements on a linked list (vq->inuse_elems) but that probably needs live migration support.I agree that renaming to unpop makes the semantics clearer.
Would you like to submit a patch for either or both?
Yes, I'll do both.
Re: [Qemu-devel] [PATCH 1/3] virtio: add virtio_detach_element()
Quoted 35 lines · Ladi Prosek
Quoted 26 lines · Stefan Hajnoczi
Quoted 17 lines · Ladi Prosek
Quoted 12 lines · Stefan Hajnoczi
During device res> > +/*
virtqueue_discard:
+ * @vq: The #VirtQueue
+ * @elem: The #VirtQueueElement
+ * @len: number of bytes written
+ *
+ * Pretend the most recent element wasn't popped from the virtqueue. The next
+ * call tovirtqueue_pop()will refetch the element.
+ */
void virtqueue_discard(VirtQueue *vq, const VirtQueueElement *elem,
unsigned int len){ vq->last_avail_idx--;hw/virtio/virtio.c static void virtqueue_unmap_sg(VirtQueue *vq, const VirtQueueElement *elem, · line 295
Quoted 3 lines
hw/virtio/virtio.c +1
-2- vq->inuse--; -virtqueue_unmap_sg (vq, elem, len); +virtqueue_detach_element (vq, elem, len);Quoted 7 lines
Random comment, not directly related to this change. Would it be worth adding an assert to this function that
elem->indexandvq->last_avail_idxmatch? In other words, enforce the "most recent" qualifier mentioned in the comment. As more virtqueue_* functions are added and the complexity goes up, it is easy to get confused. Also, I think that naming this functionvirtqueue_unpopinstead ofvirtqueue_discardwould help.Quoted 3 lines
elem->indexis a descriptor ring index.vq->last_avail_idxis an index into the available ring. They are different but your suggestion makes sense in general.Oh, right, I didn't mean they would be identical but something like this:
g_assert(elem->index == virtqueue_get_head(vq, vq->last_avail_idx));
Quoted 7 lines
Quoted 3 lines
We shouldn't read from vring memory again for an assertion so deferencing the available ring isn't possible (because we cannot rely on vring memory contents after processing the request).
Not sure I follow, shouldn't available ring memory at that index still be the same? Basically I'd like to assert that the next
virtqueue_popwould return the same element.
Assertions cannot be guest-triggerable. The guest can make the assertion fail by writing a new value to the available ring.
That might not sound like an issue but consider a scenario where the virtio PCI device is passed through to a nested guest. Now the nested guest can kill the parent hypervisor and all sibling VMs.
Stefan
Re: [Qemu-devel] [PATCH 1/3] virtio: add virtio_detach_element()
Quoted 44 lines · Stefan Hajnoczi
Quoted 35 lines · Ladi Prosek
Quoted 26 lines · Stefan Hajnoczi
Quoted 17 lines · Ladi Prosek
Quoted 12 lines · Stefan Hajnoczi
During device res> > +/*
virtqueue_discard:
+ * @vq: The #VirtQueue
+ * @elem: The #VirtQueueElement
+ * @len: number of bytes written
+ *
+ * Pretend the most recent element wasn't popped from the virtqueue. The next
+ * call tovirtqueue_pop()will refetch the element.
+ */
void virtqueue_discard(VirtQueue *vq, const VirtQueueElement *elem,
unsigned int len){ vq->last_avail_idx--;hw/virtio/virtio.c static void virtqueue_unmap_sg(VirtQueue *vq, const VirtQueueElement *elem, · line 295
Quoted 3 lines
hw/virtio/virtio.c +1
-2- vq->inuse--; -virtqueue_unmap_sg (vq, elem, len); +virtqueue_detach_element (vq, elem, len);Quoted 7 lines
Random comment, not directly related to this change. Would it be worth adding an assert to this function that
elem->indexandvq->last_avail_idxmatch? In other words, enforce the "most recent" qualifier mentioned in the comment. As more virtqueue_* functions are added and the complexity goes up, it is easy to get confused. Also, I think that naming this functionvirtqueue_unpopinstead ofvirtqueue_discardwould help.Quoted 3 lines
elem->indexis a descriptor ring index.vq->last_avail_idxis an index into the available ring. They are different but your suggestion makes sense in general.Oh, right, I didn't mean they would be identical but something like this:
g_assert(elem->index == virtqueue_get_head(vq, vq->last_avail_idx));Quoted 7 lines
Quoted 3 lines
We shouldn't read from vring memory again for an assertion so deferencing the available ring isn't possible (because we cannot rely on vring memory contents after processing the request).
Not sure I follow, shouldn't available ring memory at that index still be the same? Basically I'd like to assert that the next
virtqueue_popwould return the same element.
Quoted 6 lines
Assertions cannot be guest-triggerable. The guest can make the assertion fail by writing a new value to the available ring.
That might not sound like an issue but consider a scenario where the virtio PCI device is passed through to a nested guest. Now the nested guest can kill the parent hypervisor and all sibling VMs.
Got it, all clear now, thanks!
Quoted 1 line
Stefan
PATCH 2/3 virtio-blk: add missing virtio_detach_element() call
In reply to Stefan HajnocziMake sure to unmap the scatter-gather list and decrement vq->inuse before freeing requests in virtio_blk_reset().
--- hw/block/virtio-blk.c | 1 + 1 file changed, 1 insertion(+)
hw/block/virtio-blk.c +1 -0
@@ -665,6 +665,7 @@ static void virtio_blk_reset(VirtIODevice *vdev)while (s->rq) { req = s->rq; s->rq = req->next; +virtqueue_detach_element (req->vq, &req->elem,0 );virtio_blk_free_request (req); }
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH 2/3] virtio-blk: add missing virtio_detach_element() call
Quoted 13 lines · Stefan Hajnoczi
Make sure to unmap the scatter-gather list and decrement
vq->inusebefore freeing requests invirtio_blk_reset().Signed-off-by Stefan Hajnoczi <[email protected]>--- hw/block/virtio-blk.c | 1 + 1 file changed, 1 insertion(+)hw/block/virtio-blk.c +0
-0
hw/block/virtio-blk.c static void virtio_blk_reset(VirtIODevice *vdev) · line 669
Quoted 5 lines
hw/block/virtio-blk.c +1
-0@@ -665,6 +665,7 @@ static void virtio_blk_reset(VirtIODevice *vdev)while (s->rq) { req = s->rq; s->rq = req->next; +virtqueue_detach_element (req->vq, &req->elem,0 );virtio_blk_free_request (req);
Random observation. virtio_blk_free_request should be static and removed from the header file. Or maybe removed altogether because g_free takes NULL pointers just fine.
Quoted 5 lines
hw/block/virtio-blk.c +0
-1} --2.7.4
Thanks!
Re: [Qemu-devel] [PATCH 2/3] virtio-blk: add missing virtio_detach_element() call
Quoted 9 lines · On Tue, 27 Sep 2016 09:49:17 +0200 Ladi Prosek <[email protected]> wrote:
Quoted 8 lines · Stefan Hajnoczi
Make sure to unmap the scatter-gather list and decrement
vq->inusebefore freeing requests invirtio_blk_reset().Signed-off-by Stefan Hajnoczi <[email protected]>--- hw/block/virtio-blk.c | 1 + 1 file changed, 1 insertion(+)
Quoted 13 lines
hw/block/virtio-blk.c static void virtio_blk_reset(VirtIODevice *vdev) · line 669
Quoted 10 lines
hw/block/virtio-blk.c +1
-0@@ -665,6 +665,7 @@ static void virtio_blk_reset(VirtIODevice *vdev)while (s->rq) { req = s->rq; s->rq = req->next; +virtqueue_detach_element (req->vq, &req->elem,0 );virtio_blk_free_request (req);Random observation.
virtio_blk_free_requestshould be static and removed from the header file.
I've sent a followup patch for this:
<147487884587.6679.6170297932839464278.stgit@bahia>
Quoted 2 lines
Or maybe removed altogether because
g_freetakes NULL pointers just fine.
virtio_blk_free_request() does not seem useful indeed... :)
Cheers.
--
Greg
Quoted 10 lines
Quoted 5 lines
hw/block/virtio-blk.c +0
-1} --2.7.4
Reviewed-by Ladi Prosek <[email protected]>Thanks!
PATCH 3/3 virtio-serial: add missing virtio_detach_element() call
In reply to Stefan HajnocziPorts enter a "throttled" state when writing to the chardev would block. The current output VirtQueueElement is kept around until the chardev becomes writable again.
There are several places in the virtio-serial lifecycle where the VirtQueueElement should be thrown away. For example, if the virtio device is reset then virtqueue elements are no longer valid.
This patch adds the discard_throttle_data() function to unmap the scatter-gather list and decrement vq->inuse. This ensures that the VirtQueueElement is freed properly.
--- hw/char/virtio-serial-bus.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
hw/char/virtio-serial-bus.c +14 -0
@@ -132,6 +132,15 @@ static void discard_vq_data(VirtQueue *vq, VirtIODevice *vdev)virtio_notify (vdev, vq); } +static void discard_throttle_data (VirtIOSerialPort *port) +{ +if (port->elem) { +virtqueue_detach_element (port->ovq, port->elem,0 ); +g_free (port->elem); + port->elem =NULL ; + } +} +static void do_flush_queued_data (VirtIOSerialPort *port,VirtQueue *vq,VirtIODevice *vdev) {
@@ -254,6 +263,7 @@ int virtio_serial_close(VirtIOSerialPort *port)* consume, reset the throttling flag and discard the data. */ port->throttled = false; +discard_throttle_data (port);discard_vq_data (port->ovq,VIRTIO_DEVICE (port->vser));send_control_event (port->vser, port->id,VIRTIO_CONSOLE_PORT_OPEN ,0 );
@@ -554,6 +564,9 @@ static void guest_reset(VirtIOSerial *vser) QTAILQ_FOREACH(port, &vser->ports, next) { vsc =VIRTIO_SERIAL_PORT_GET_CLASS (port); + +discard_throttle_data (port); +if (port->guest_connected) { port->guest_connected = false;if (vsc->set_guest_connected) {
@@ -864,6 +877,7 @@ static void remove_port(VirtIOSerial *vser, uint32_t port_id)assert (port);/* Flush out any unconsumed buffers first */ +discard_throttle_data (port);discard_vq_data (port->ovq,VIRTIO_DEVICE (port->vser));send_control_event (vser, port->id,VIRTIO_CONSOLE_PORT_REMOVE ,1 );
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH 3/3] virtio-serial: add missing virtio_detach_element() call
Quoted 8 lines · Stefan Hajnoczi
Ports enter a "throttled" state when writing to the chardev would block. The current output VirtQueueElement is kept around until the chardev becomes writable again.
There are several places in the virtio-serial lifecycle where the VirtQueueElement should be thrown away. For example, if the virtio device is reset then virtqueue elements are no longer valid.
Quoted 6 lines
This patch adds the
discard_throttle_data()function to unmap the scatter-gather list and decrementvq->inuse. This ensures that the VirtQueueElement is freed properly.Signed-off-by Stefan Hajnoczi <[email protected]>
I have tested this patch with a simple serial stress test to exercise the code paths.
Quoted 13 lines · Stefan Hajnoczi
virtio-blk and virtio-serial need to free VirtQueueElements during device reset. Simply calling
g_free(elem)is not enough because the scatter-gather list should be unmapped andvq->inusemust be decremented.These patches address the issue. I am not including a patch that changes
vq->inuse= 0 toassert(!vq->inuse)invirtio_reset()yet because virtio-9p, virtio-gpu, and virtio-net have code paths that do not decrementvq->inuse.Stefan Hajnoczi (3):
virtio: addvirtio_detach_element()
virtio-blk: add missingvirtio_detach_element()call
virtio-serial: add missingvirtio_detach_element()call
Quoted 5 lines
hw/block/virtio-blk.c | 1 + hw/char/virtio-serial-bus.c | 14 ++++++++++++++ hw/virtio/virtio.c | 27 +++++++++++++++++++++++++-- include/hw/virtio/virtio.h | 2 ++ 4 files changed, 42 insertions(+), 2 deletions(-)
Ping?
Quoted 14 lines · On Tue, 27 Sep 2016 11:08:53 +0100 Stefan Hajnoczi <[email protected]> wrote:
Quoted 13 lines · Stefan Hajnoczi
virtio-blk and virtio-serial need to free VirtQueueElements during device reset. Simply calling
g_free(elem)is not enough because the scatter-gather list should be unmapped andvq->inusemust be decremented.These patches address the issue. I am not including a patch that changes
vq->inuse= 0 toassert(!vq->inuse)invirtio_reset()yet because virtio-9p, virtio-gpu, and virtio-net have code paths that do not decrementvq->inuse.Stefan Hajnoczi (3):
virtio: addvirtio_detach_element()
virtio-blk: add missingvirtio_detach_element()call
virtio-serial: add missingvirtio_detach_element()call
Quoted 7 lines
Quoted 5 lines
hw/block/virtio-blk.c | 1 + hw/char/virtio-serial-bus.c | 14 ++++++++++++++ hw/virtio/virtio.c | 27 +++++++++++++++++++++++++-- include/hw/virtio/virtio.h | 2 ++ 4 files changed, 42 insertions(+), 2 deletions(-)Ping?
+1 because patch 1/3 of this series is required by:
Subject: [PATCH v4 0/9] virtio: avoid inappropriate QEMU termination in device code
Date: Fri, 30 Sep 2016 17:12:32 +0200
Message-Id: <147524835229.953.16853431367911587573.stgit@bahia>
Cheers.
--
Greg