|
|
586cba |
From 56f4bebc591893e590481617da7cd7ecffeb166d Mon Sep 17 00:00:00 2001
|
|
|
586cba |
From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= <eperezma@redhat.com>
|
|
|
586cba |
Date: Tue, 23 Aug 2022 20:30:34 +0200
|
|
|
586cba |
Subject: [PATCH 19/23] vdpa: extract vhost_vdpa_net_cvq_add from
|
|
|
586cba |
vhost_vdpa_net_handle_ctrl_avail
|
|
|
586cba |
MIME-Version: 1.0
|
|
|
586cba |
Content-Type: text/plain; charset=UTF-8
|
|
|
586cba |
Content-Transfer-Encoding: 8bit
|
|
|
586cba |
|
|
|
586cba |
RH-Author: Eugenio Pérez <eperezma@redhat.com>
|
|
|
586cba |
RH-MergeRequest: 116: vdpa: Restore device state on destination
|
|
|
586cba |
RH-Bugzilla: 2114060
|
|
|
586cba |
RH-Acked-by: Cindy Lu <lulu@redhat.com>
|
|
|
586cba |
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
586cba |
RH-Commit: [18/21] 08ab71dbf050f5c2e97c622d1915f71a56c135b8 (eperezmartin/qemu-kvm)
|
|
|
586cba |
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2114060
|
|
|
586cba |
Upstream status: git@github.com:jasowang/qemu.git net-next
|
|
|
586cba |
|
|
|
586cba |
So we can reuse it to inject state messages.
|
|
|
586cba |
|
|
|
586cba |
Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
|
|
|
586cba |
Acked-by: Jason Wang <jasowang@redhat.com>
|
|
|
586cba |
--
|
|
|
586cba |
v7:
|
|
|
586cba |
* Remove double free error
|
|
|
586cba |
|
|
|
586cba |
v6:
|
|
|
586cba |
* Do not assume in buffer sent to the device is sizeof(virtio_net_ctrl_ack)
|
|
|
586cba |
|
|
|
586cba |
v5:
|
|
|
586cba |
* Do not use an artificial !NULL VirtQueueElement
|
|
|
586cba |
* Use only out size instead of iovec dev_buffers for these functions.
|
|
|
586cba |
|
|
|
586cba |
Signed-off-by: Jason Wang <jasowang@redhat.com>
|
|
|
586cba |
(cherry picked from commit d9afb1f0ee4d662ed67d3bc1220b943f7e4cfa6f)
|
|
|
586cba |
---
|
|
|
586cba |
net/vhost-vdpa.c | 59 +++++++++++++++++++++++++++++++-----------------
|
|
|
586cba |
1 file changed, 38 insertions(+), 21 deletions(-)
|
|
|
586cba |
|
|
|
586cba |
diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c
|
|
|
586cba |
index 17626feb8d..f09f044ec1 100644
|
|
|
586cba |
--- a/net/vhost-vdpa.c
|
|
|
586cba |
+++ b/net/vhost-vdpa.c
|
|
|
586cba |
@@ -331,6 +331,38 @@ static void vhost_vdpa_net_cvq_stop(NetClientState *nc)
|
|
|
586cba |
}
|
|
|
586cba |
}
|
|
|
586cba |
|
|
|
586cba |
+static ssize_t vhost_vdpa_net_cvq_add(VhostVDPAState *s, size_t out_len,
|
|
|
586cba |
+ size_t in_len)
|
|
|
586cba |
+{
|
|
|
586cba |
+ /* Buffers for the device */
|
|
|
586cba |
+ const struct iovec out = {
|
|
|
586cba |
+ .iov_base = s->cvq_cmd_out_buffer,
|
|
|
586cba |
+ .iov_len = out_len,
|
|
|
586cba |
+ };
|
|
|
586cba |
+ const struct iovec in = {
|
|
|
586cba |
+ .iov_base = s->cvq_cmd_in_buffer,
|
|
|
586cba |
+ .iov_len = sizeof(virtio_net_ctrl_ack),
|
|
|
586cba |
+ };
|
|
|
586cba |
+ VhostShadowVirtqueue *svq = g_ptr_array_index(s->vhost_vdpa.shadow_vqs, 0);
|
|
|
586cba |
+ int r;
|
|
|
586cba |
+
|
|
|
586cba |
+ r = vhost_svq_add(svq, &out, 1, &in, 1, NULL);
|
|
|
586cba |
+ if (unlikely(r != 0)) {
|
|
|
586cba |
+ if (unlikely(r == -ENOSPC)) {
|
|
|
586cba |
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: No space on device queue\n",
|
|
|
586cba |
+ __func__);
|
|
|
586cba |
+ }
|
|
|
586cba |
+ return r;
|
|
|
586cba |
+ }
|
|
|
586cba |
+
|
|
|
586cba |
+ /*
|
|
|
586cba |
+ * We can poll here since we've had BQL from the time we sent the
|
|
|
586cba |
+ * descriptor. Also, we need to take the answer before SVQ pulls by itself,
|
|
|
586cba |
+ * when BQL is released
|
|
|
586cba |
+ */
|
|
|
586cba |
+ return vhost_svq_poll(svq);
|
|
|
586cba |
+}
|
|
|
586cba |
+
|
|
|
586cba |
static NetClientInfo net_vhost_vdpa_cvq_info = {
|
|
|
586cba |
.type = NET_CLIENT_DRIVER_VHOST_VDPA,
|
|
|
586cba |
.size = sizeof(VhostVDPAState),
|
|
|
586cba |
@@ -387,23 +419,18 @@ static int vhost_vdpa_net_handle_ctrl_avail(VhostShadowVirtqueue *svq,
|
|
|
586cba |
void *opaque)
|
|
|
586cba |
{
|
|
|
586cba |
VhostVDPAState *s = opaque;
|
|
|
586cba |
- size_t in_len, dev_written;
|
|
|
586cba |
+ size_t in_len;
|
|
|
586cba |
virtio_net_ctrl_ack status = VIRTIO_NET_ERR;
|
|
|
586cba |
/* Out buffer sent to both the vdpa device and the device model */
|
|
|
586cba |
struct iovec out = {
|
|
|
586cba |
.iov_base = s->cvq_cmd_out_buffer,
|
|
|
586cba |
};
|
|
|
586cba |
- /* In buffer sent to the device */
|
|
|
586cba |
- const struct iovec dev_in = {
|
|
|
586cba |
- .iov_base = s->cvq_cmd_in_buffer,
|
|
|
586cba |
- .iov_len = sizeof(virtio_net_ctrl_ack),
|
|
|
586cba |
- };
|
|
|
586cba |
/* in buffer used for device model */
|
|
|
586cba |
const struct iovec in = {
|
|
|
586cba |
.iov_base = &status,
|
|
|
586cba |
.iov_len = sizeof(status),
|
|
|
586cba |
};
|
|
|
586cba |
- int r = -EINVAL;
|
|
|
586cba |
+ ssize_t dev_written = -EINVAL;
|
|
|
586cba |
bool ok;
|
|
|
586cba |
|
|
|
586cba |
out.iov_len = iov_to_buf(elem->out_sg, elem->out_num, 0,
|
|
|
586cba |
@@ -414,21 +441,11 @@ static int vhost_vdpa_net_handle_ctrl_avail(VhostShadowVirtqueue *svq,
|
|
|
586cba |
goto out;
|
|
|
586cba |
}
|
|
|
586cba |
|
|
|
586cba |
- r = vhost_svq_add(svq, &out, 1, &dev_in, 1, elem);
|
|
|
586cba |
- if (unlikely(r != 0)) {
|
|
|
586cba |
- if (unlikely(r == -ENOSPC)) {
|
|
|
586cba |
- qemu_log_mask(LOG_GUEST_ERROR, "%s: No space on device queue\n",
|
|
|
586cba |
- __func__);
|
|
|
586cba |
- }
|
|
|
586cba |
+ dev_written = vhost_vdpa_net_cvq_add(s, out.iov_len, sizeof(status));
|
|
|
586cba |
+ if (unlikely(dev_written < 0)) {
|
|
|
586cba |
goto out;
|
|
|
586cba |
}
|
|
|
586cba |
|
|
|
586cba |
- /*
|
|
|
586cba |
- * We can poll here since we've had BQL from the time we sent the
|
|
|
586cba |
- * descriptor. Also, we need to take the answer before SVQ pulls by itself,
|
|
|
586cba |
- * when BQL is released
|
|
|
586cba |
- */
|
|
|
586cba |
- dev_written = vhost_svq_poll(svq);
|
|
|
586cba |
if (unlikely(dev_written < sizeof(status))) {
|
|
|
586cba |
error_report("Insufficient written data (%zu)", dev_written);
|
|
|
586cba |
goto out;
|
|
|
586cba |
@@ -436,7 +453,7 @@ static int vhost_vdpa_net_handle_ctrl_avail(VhostShadowVirtqueue *svq,
|
|
|
586cba |
|
|
|
586cba |
memcpy(&status, s->cvq_cmd_in_buffer, sizeof(status));
|
|
|
586cba |
if (status != VIRTIO_NET_OK) {
|
|
|
586cba |
- goto out;
|
|
|
586cba |
+ return VIRTIO_NET_ERR;
|
|
|
586cba |
}
|
|
|
586cba |
|
|
|
586cba |
status = VIRTIO_NET_ERR;
|
|
|
586cba |
@@ -453,7 +470,7 @@ out:
|
|
|
586cba |
}
|
|
|
586cba |
vhost_svq_push_elem(svq, elem, MIN(in_len, sizeof(status)));
|
|
|
586cba |
g_free(elem);
|
|
|
586cba |
- return r;
|
|
|
586cba |
+ return dev_written < 0 ? dev_written : 0;
|
|
|
586cba |
}
|
|
|
586cba |
|
|
|
586cba |
static const VhostShadowVirtqueueOps vhost_vdpa_net_svq_ops = {
|
|
|
586cba |
--
|
|
|
586cba |
2.31.1
|
|
|
586cba |
|