[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 08/33] virtio: add virtio_detach_element()
From: |
Michael S. Tsirkin |
Subject: |
[Qemu-devel] [PULL 08/33] virtio: add virtio_detach_element() |
Date: |
Mon, 10 Oct 2016 05:57:45 +0300 |
From: Stefan Hajnoczi <address@hidden>
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.
Signed-off-by: Stefan Hajnoczi <address@hidden>
Acked-by: Greg Kurz <address@hidden>
Reviewed-by: Ladi Prosek <address@hidden>
Reviewed-by: Michael S. Tsirkin <address@hidden>
Signed-off-by: Michael S. Tsirkin <address@hidden>
---
include/hw/virtio/virtio.h | 2 ++
hw/virtio/virtio.c | 27 +++++++++++++++++++++++++--
2 files changed, 27 insertions(+), 2 deletions(-)
diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h
index 888c8de..e25ec4f 100644
--- a/include/hw/virtio/virtio.h
+++ b/include/hw/virtio/virtio.h
@@ -155,6 +155,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);
diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index 18ce333..46f79c9 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -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:
--
MST
- [Qemu-devel] [PULL 00/33] virtio, pc: fixes and features, Michael S. Tsirkin, 2016/10/09
- [Qemu-devel] [PULL 02/33] virtio-serial: add plumbing for virtio console emergency write support, Michael S. Tsirkin, 2016/10/09
- [Qemu-devel] [PULL 01/33] virtio-balloon: Remove needless precompiled directive, Michael S. Tsirkin, 2016/10/09
- [Qemu-devel] [PULL 03/33] virtio-serial: enable virtio console emergency write feature, Michael S. Tsirkin, 2016/10/09
- [Qemu-devel] [PULL 06/33] tests: acpi: extend cphp testcase with numa check, Michael S. Tsirkin, 2016/10/09
- [Qemu-devel] [PULL 08/33] virtio: add virtio_detach_element(),
Michael S. Tsirkin <=
- [Qemu-devel] [PULL 07/33] tests: acpi tables expected blobs update, Michael S. Tsirkin, 2016/10/09
- [Qemu-devel] [PULL 05/33] acpi: provide _PXM method for CPU devices if QEMU is started numa enabled, Michael S. Tsirkin, 2016/10/09
- [Qemu-devel] [PULL 09/33] virtio-blk: add missing virtio_detach_element() call, Michael S. Tsirkin, 2016/10/09
- [Qemu-devel] [PULL 04/33] numa: reduce code duplication by adding helper numa_get_node_for_cpu(), Michael S. Tsirkin, 2016/10/09
- [Qemu-devel] [PULL 17/33] virtio-net: handle virtio_net_flush_tx() errors, Michael S. Tsirkin, 2016/10/09
- [Qemu-devel] [PULL 19/33] virtio-scsi: handle virtio_scsi_set_config() error, Michael S. Tsirkin, 2016/10/09
- [Qemu-devel] [PULL 13/33] virtio-9p: handle handle_9p_output() error, Michael S. Tsirkin, 2016/10/09
- [Qemu-devel] [PULL 18/33] virtio-scsi: convert virtio_scsi_bad_req() to use virtio_error(), Michael S. Tsirkin, 2016/10/09
- [Qemu-devel] [PULL 24/33] virtio-9p: convert VMSTATE_VIRTIO_DEVICE, Michael S. Tsirkin, 2016/10/09
- [Qemu-devel] [PULL 27/33] virtio-input: convert VMSTATE_VIRTIO_DEVICE, Michael S. Tsirkin, 2016/10/09