[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 18/22] vdpa: manual forward CVQ buffers
From: |
Eugenio Pérez |
Subject: |
[PATCH 18/22] vdpa: manual forward CVQ buffers |
Date: |
Fri, 8 Jul 2022 12:50:09 +0200 |
Do a simple forwarding of CVQ buffers, the same work SVQ could do but
through callbacks. No functional change intended.
Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
---
include/hw/virtio/vhost-vdpa.h | 3 ++
hw/virtio/vhost-vdpa.c | 3 +-
net/vhost-vdpa.c | 59 ++++++++++++++++++++++++++++++++++
3 files changed, 64 insertions(+), 1 deletion(-)
diff --git a/include/hw/virtio/vhost-vdpa.h b/include/hw/virtio/vhost-vdpa.h
index 7214eb47dc..1111d85643 100644
--- a/include/hw/virtio/vhost-vdpa.h
+++ b/include/hw/virtio/vhost-vdpa.h
@@ -15,6 +15,7 @@
#include <gmodule.h>
#include "hw/virtio/vhost-iova-tree.h"
+#include "hw/virtio/vhost-shadow-virtqueue.h"
#include "hw/virtio/virtio.h"
#include "standard-headers/linux/vhost_types.h"
@@ -35,6 +36,8 @@ typedef struct vhost_vdpa {
/* IOVA mapping used by the Shadow Virtqueue */
VhostIOVATree *iova_tree;
GPtrArray *shadow_vqs;
+ const VhostShadowVirtqueueOps *shadow_vq_ops;
+ void *shadow_vq_ops_opaque;
struct vhost_dev *dev;
VhostVDPAHostNotifier notifier[VIRTIO_QUEUE_MAX];
} VhostVDPA;
diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c
index 7d2922ccbf..c1162daecc 100644
--- a/hw/virtio/vhost-vdpa.c
+++ b/hw/virtio/vhost-vdpa.c
@@ -419,7 +419,8 @@ static int vhost_vdpa_init_svq(struct vhost_dev *hdev,
struct vhost_vdpa *v,
for (unsigned n = 0; n < hdev->nvqs; ++n) {
g_autoptr(VhostShadowVirtqueue) svq;
- svq = vhost_svq_new(v->iova_tree, NULL, NULL);
+ svq = vhost_svq_new(v->iova_tree, v->shadow_vq_ops,
+ v->shadow_vq_ops_opaque);
if (unlikely(!svq)) {
error_setg(errp, "Cannot create svq %u", n);
return -1;
diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c
index df1e69ee72..8558ad7a01 100644
--- a/net/vhost-vdpa.c
+++ b/net/vhost-vdpa.c
@@ -11,11 +11,14 @@
#include "qemu/osdep.h"
#include "clients.h"
+#include "hw/virtio/virtio-net.h"
#include "net/vhost_net.h"
#include "net/vhost-vdpa.h"
#include "hw/virtio/vhost-vdpa.h"
#include "qemu/config-file.h"
#include "qemu/error-report.h"
+#include "qemu/log.h"
+#include "qemu/memalign.h"
#include "qemu/option.h"
#include "qapi/error.h"
#include <linux/vhost.h>
@@ -187,6 +190,58 @@ static NetClientInfo net_vhost_vdpa_info = {
.check_peer_type = vhost_vdpa_check_peer_type,
};
+/**
+ * Forward buffer for the moment.
+ */
+static bool vhost_vdpa_net_handle_ctrl_avail(VhostShadowVirtqueue *svq,
+ VirtQueueElement *guest_elem,
+ void *opaque)
+{
+ g_autofree VirtQueueElement *elem = guest_elem;
+ unsigned int n = elem->out_num + elem->in_num;
+ g_autofree struct iovec *iov = g_new(struct iovec, n);
+ size_t in_len;
+ virtio_net_ctrl_ack status = VIRTIO_NET_ERR;
+ int r;
+
+ memcpy(iov, elem->out_sg, elem->out_num);
+ memcpy(iov + elem->out_num, elem->in_sg, elem->in_num);
+
+ r = vhost_svq_inject(svq, iov, elem->out_num, elem->in_num, elem);
+ if (unlikely(r != 0)) {
+ goto err;
+ }
+
+ /* Now elem belongs to SVQ */
+ g_steal_pointer(&elem);
+ return true;
+
+err:
+ in_len = iov_from_buf(elem->in_sg, elem->in_num, 0, &status,
+ sizeof(status));
+ vhost_svq_push_elem(svq, elem, in_len);
+ return true;
+}
+
+static VirtQueueElement *vhost_vdpa_net_handle_ctrl_detach(void *elem_opaque)
+{
+ return elem_opaque;
+}
+
+static void vhost_vdpa_net_handle_ctrl_used(VhostShadowVirtqueue *svq,
+ void *vq_elem_opaque,
+ uint32_t dev_written)
+{
+ g_autofree VirtQueueElement *guest_elem = vq_elem_opaque;
+ vhost_svq_push_elem(svq, guest_elem, sizeof(virtio_net_ctrl_ack));
+}
+
+static const VhostShadowVirtqueueOps vhost_vdpa_net_svq_ops = {
+ .avail_handler = vhost_vdpa_net_handle_ctrl_avail,
+ .used_handler = vhost_vdpa_net_handle_ctrl_used,
+ .detach_handler = vhost_vdpa_net_handle_ctrl_detach,
+};
+
static NetClientState *net_vhost_vdpa_init(NetClientState *peer,
const char *device,
const char *name,
@@ -211,6 +266,10 @@ static NetClientState *net_vhost_vdpa_init(NetClientState
*peer,
s->vhost_vdpa.device_fd = vdpa_device_fd;
s->vhost_vdpa.index = queue_pair_index;
+ if (!is_datapath) {
+ s->vhost_vdpa.shadow_vq_ops = &vhost_vdpa_net_svq_ops;
+ s->vhost_vdpa.shadow_vq_ops_opaque = s;
+ }
ret = vhost_vdpa_add(nc, (void *)&s->vhost_vdpa, queue_pair_index, nvqs);
if (ret) {
qemu_del_net_client(nc);
--
2.31.1
- [PATCH 06/22] vhost: Reorder vhost_svq_last_desc_of_chain, (continued)
- [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, 2022/07/08
- [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 <=
- [PATCH 15/22] vhost: Add svq avail_handler callback, Eugenio Pérez, 2022/07/08
- [PATCH 17/22] vdpa: Export vhost_vdpa_dma_map and unmap calls, Eugenio Pérez, 2022/07/08
- [PATCH 19/22] vdpa: Buffer CVQ support on shadow virtqueue, Eugenio Pérez, 2022/07/08
- [PATCH 20/22] vdpa: Extract get features part from vhost_vdpa_get_max_queue_pairs, Eugenio Pérez, 2022/07/08
- [PATCH 14/22] vhost: Add custom used buffer callback, Eugenio Pérez, 2022/07/08
- [PATCH 21/22] vdpa: Add device migration blocker, Eugenio Pérez, 2022/07/08
- [PATCH 22/22] vdpa: Add x-svq to NetdevVhostVDPAOptions, Eugenio Pérez, 2022/07/08