[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 05/22] vhost: Decouple vhost_svq_add_split from VirtQueueElement
From: |
Eugenio Pérez |
Subject: |
[PATCH 05/22] vhost: Decouple vhost_svq_add_split from VirtQueueElement |
Date: |
Fri, 8 Jul 2022 12:49:56 +0200 |
VirtQueueElement comes from the guest, but we're heading SVQ to be able
to inject element without the guest's knowledge.
To do so, make this accept sg buffers directly, instead of using
VirtQueueElement.
Add vhost_svq_add_element to maintain element convenience
Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
---
hw/virtio/vhost-shadow-virtqueue.c | 38 +++++++++++++++++++++---------
1 file changed, 27 insertions(+), 11 deletions(-)
diff --git a/hw/virtio/vhost-shadow-virtqueue.c
b/hw/virtio/vhost-shadow-virtqueue.c
index 115d769b86..2d70f832e9 100644
--- a/hw/virtio/vhost-shadow-virtqueue.c
+++ b/hw/virtio/vhost-shadow-virtqueue.c
@@ -172,30 +172,32 @@ static bool
vhost_svq_vring_write_descs(VhostShadowVirtqueue *svq, hwaddr *sg,
}
static bool vhost_svq_add_split(VhostShadowVirtqueue *svq,
- VirtQueueElement *elem, unsigned *head)
+ const struct iovec *out_sg, size_t out_num,
+ const struct iovec *in_sg, size_t in_num,
+ unsigned *head)
{
unsigned avail_idx;
vring_avail_t *avail = svq->vring.avail;
bool ok;
- g_autofree hwaddr *sgs = g_new(hwaddr, MAX(elem->out_num, elem->in_num));
+ g_autofree hwaddr *sgs = NULL;
*head = svq->free_head;
/* We need some descriptors here */
- if (unlikely(!elem->out_num && !elem->in_num)) {
+ if (unlikely(!out_num && !in_num)) {
qemu_log_mask(LOG_GUEST_ERROR,
"Guest provided element with no descriptors");
return false;
}
- ok = vhost_svq_vring_write_descs(svq, sgs, elem->out_sg, elem->out_num,
- elem->in_num > 0, false);
+ sgs = g_new(hwaddr, MAX(out_num, in_num));
+ ok = vhost_svq_vring_write_descs(svq, sgs, out_sg, out_num, in_num > 0,
+ false);
if (unlikely(!ok)) {
return false;
}
- ok = vhost_svq_vring_write_descs(svq, sgs, elem->in_sg, elem->in_num,
false,
- true);
+ ok = vhost_svq_vring_write_descs(svq, sgs, in_sg, in_num, false, true);
if (unlikely(!ok)) {
return false;
}
@@ -222,10 +224,13 @@ static bool vhost_svq_add_split(VhostShadowVirtqueue *svq,
* takes ownership of the element: In case of failure, it is free and the SVQ
* is considered broken.
*/
-static bool vhost_svq_add(VhostShadowVirtqueue *svq, VirtQueueElement *elem)
+static bool vhost_svq_add(VhostShadowVirtqueue *svq, const struct iovec
*out_sg,
+ size_t out_num, const struct iovec *in_sg,
+ size_t in_num, VirtQueueElement *elem)
{
unsigned qemu_head;
- bool ok = vhost_svq_add_split(svq, elem, &qemu_head);
+ bool ok = vhost_svq_add_split(svq, out_sg, out_num, in_sg, in_num,
+ &qemu_head);
if (unlikely(!ok)) {
g_free(elem);
return false;
@@ -249,6 +254,18 @@ static void vhost_svq_kick(VhostShadowVirtqueue *svq)
event_notifier_set(&svq->hdev_kick);
}
+static bool vhost_svq_add_element(VhostShadowVirtqueue *svq,
+ VirtQueueElement *elem)
+{
+ bool ok = vhost_svq_add(svq, elem->out_sg, elem->out_num, elem->in_sg,
+ elem->in_num, elem);
+ if (ok) {
+ vhost_svq_kick(svq);
+ }
+
+ return ok;
+}
+
/**
* Forward available buffers.
*
@@ -301,12 +318,11 @@ static void vhost_handle_guest_kick(VhostShadowVirtqueue
*svq)
return;
}
- ok = vhost_svq_add(svq, elem);
+ ok = vhost_svq_add_element(svq, g_steal_pointer(&elem));
if (unlikely(!ok)) {
/* VQ is broken, just return and ignore any other kicks */
return;
}
- vhost_svq_kick(svq);
}
virtio_queue_set_notification(svq->vq, true);
--
2.31.1
- [PATCH 00/22] vdpa net devices Rx filter change notification with Shadow VQ, Eugenio Pérez, 2022/07/08
- [PATCH 01/22] vhost: Return earlier if used buffers overrun, Eugenio Pérez, 2022/07/08
- [PATCH 02/22] vhost: move descriptor translation to vhost_svq_vring_write_descs, Eugenio Pérez, 2022/07/08
- [PATCH 03/22] vdpa: Clean vhost_vdpa_dev_start(dev, false), Eugenio Pérez, 2022/07/08
- [PATCH 04/22] virtio-net: Expose ctrl virtqueue logic, Eugenio Pérez, 2022/07/08
- [PATCH 06/22] vhost: Reorder vhost_svq_last_desc_of_chain, Eugenio Pérez, 2022/07/08
- [PATCH 05/22] vhost: Decouple vhost_svq_add_split from VirtQueueElement,
Eugenio Pérez <=
- [PATCH 07/22] vhost: Add SVQElement, Eugenio Pérez, 2022/07/08
- [PATCH 08/22] vhost: Move last chain id to SVQ element, Eugenio Pérez, 2022/07/08
- [PATCH 11/22] vhost: add vhost_svq_push_elem, Eugenio Pérez, 2022/07/08
- [PATCH 10/22] vdpa: Small rename of error labels, Eugenio Pérez, 2022/07/08
- [PATCH 09/22] vhost: Add opaque member to SVQElement, Eugenio Pérez, 2022/07/08
- [PATCH 12/22] vhost: Add vhost_svq_inject, Eugenio Pérez, 2022/07/08
- [PATCH 13/22] vhost: add vhost_svq_poll, Eugenio Pérez, 2022/07/08
- [PATCH 16/22] vhost: add detach SVQ operation, Eugenio Pérez, 2022/07/08
- [PATCH 18/22] vdpa: manual forward CVQ buffers, Eugenio Pérez, 2022/07/08
- [PATCH 15/22] vhost: Add svq avail_handler callback, Eugenio Pérez, 2022/07/08