From: "Eugenio Pérez" <eperezma@redhat.com>
To: qemu-devel@nongnu.org
Cc: Liuxiangdong <liuxiangdong5@huawei.com>,
Stefan Hajnoczi <stefanha@redhat.com>,
Jason Wang <jasowang@redhat.com>,
Harpreet Singh Anand <hanand@xilinx.com>,
Gautam Dawar <gdawar@xilinx.com>,
Zhu Lingshan <lingshan.zhu@intel.com>, Cindy Lu <lulu@redhat.com>,
Si-Wei Liu <si-wei.liu@oracle.com>,
"Michael S. Tsirkin" <mst@redhat.com>,
"Dr. David Alan Gilbert" <dgilbert@redhat.com>,
Laurent Vivier <lvivier@redhat.com>, Eli Cohen <eli@mellanox.com>,
Stefano Garzarella <sgarzare@redhat.com>,
Juan Quintela <quintela@redhat.com>,
Parav Pandit <parav@mellanox.com>
Subject: [RFC PATCH for 8.0 06/13] virtio: refactor qemu_get_virtqueue_element
Date: Mon, 5 Dec 2022 18:04:29 +0100 [thread overview]
Message-ID: <20221205170436.2977336-7-eperezma@redhat.com> (raw)
In-Reply-To: <20221205170436.2977336-1-eperezma@redhat.com>
The core of the function is useful to transform from VirtQueueElementOld
to VirtQueueElement. Extract from qemu_get_virtqueue_element, and leave
there the handling of QEMUFile.
No functional change intended.
Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
---
hw/virtio/virtio.c | 68 ++++++++++++++++++++++++++++------------------
1 file changed, 42 insertions(+), 26 deletions(-)
diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index 6efff3d441..b0245ce4e8 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -2297,50 +2297,66 @@ typedef struct VirtQueueElementOld {
struct iovec out_sg[VIRTQUEUE_MAX_SIZE];
} VirtQueueElementOld;
-void *qemu_get_virtqueue_element(VirtIODevice *vdev, QEMUFile *f, size_t sz)
+/* Convert VirtQueueElementOld to VirtQueueElement */
+static void *qemu_get_virtqueue_element_from_old(VirtIODevice *vdev,
+ const VirtQueueElementOld *data,
+ size_t sz)
{
- VirtQueueElement *elem;
- VirtQueueElementOld data;
- int i;
-
- qemu_get_buffer(f, (uint8_t *)&data, sizeof(VirtQueueElementOld));
-
- /* TODO: teach all callers that this can fail, and return failure instead
- * of asserting here.
- * This is just one thing (there are probably more) that must be
- * fixed before we can allow NDEBUG compilation.
- */
- assert(ARRAY_SIZE(data.in_addr) >= data.in_num);
- assert(ARRAY_SIZE(data.out_addr) >= data.out_num);
-
- elem = virtqueue_alloc_element(sz, data.out_num, data.in_num);
- elem->index = data.index;
+ VirtQueueElement *elem = virtqueue_alloc_element(sz, data->out_num,
+ data->in_num);
+ elem->index = data->index;
- for (i = 0; i < elem->in_num; i++) {
- elem->in_addr[i] = data.in_addr[i];
+ for (uint16_t i = 0; i < elem->in_num; i++) {
+ elem->in_addr[i] = data->in_addr[i];
}
- for (i = 0; i < elem->out_num; i++) {
- elem->out_addr[i] = data.out_addr[i];
+ for (uint16_t i = 0; i < elem->out_num; i++) {
+ elem->out_addr[i] = data->out_addr[i];
}
- for (i = 0; i < elem->in_num; i++) {
+ for (uint16_t i = 0; i < elem->in_num; i++) {
/* Base is overwritten by virtqueue_map. */
elem->in_sg[i].iov_base = 0;
- elem->in_sg[i].iov_len = data.in_sg[i].iov_len;
+ elem->in_sg[i].iov_len = data->in_sg[i].iov_len;
}
- for (i = 0; i < elem->out_num; i++) {
+ for (uint16_t i = 0; i < elem->out_num; i++) {
/* Base is overwritten by virtqueue_map. */
elem->out_sg[i].iov_base = 0;
- elem->out_sg[i].iov_len = data.out_sg[i].iov_len;
+ elem->out_sg[i].iov_len = data->out_sg[i].iov_len;
}
+ virtqueue_map(vdev, elem);
+ return elem;
+}
+
+static bool vq_element_in_range(void *opaque, int version_id)
+{
+ VirtQueueElementOld *data = opaque;
+
+ return ARRAY_SIZE(data->in_addr) >= data->in_num &&
+ ARRAY_SIZE(data->out_addr) >= data->out_num;
+}
+
+void *qemu_get_virtqueue_element(VirtIODevice *vdev, QEMUFile *f, size_t sz)
+{
+ VirtQueueElement *elem;
+ VirtQueueElementOld data;
+
+ qemu_get_buffer(f, (uint8_t *)&data, sizeof(VirtQueueElementOld));
+
+ /* TODO: teach all callers that this can fail, and return failure instead
+ * of asserting here.
+ * This is just one thing (there are probably more) that must be
+ * fixed before we can allow NDEBUG compilation.
+ */
+ assert(vq_element_in_range(&data, 0));
+
+ elem = qemu_get_virtqueue_element_from_old(vdev, &data, sz);
if (virtio_host_has_feature(vdev, VIRTIO_F_RING_PACKED)) {
qemu_get_be32s(f, &elem->ndescs);
}
- virtqueue_map(vdev, elem);
return elem;
}
--
2.31.1
next prev parent reply other threads:[~2022-12-05 17:06 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-05 17:04 [RFC PATCH for 8.0 00/13] vDPA-net inflight descriptors migration with SVQ Eugenio Pérez
2022-12-05 17:04 ` [RFC PATCH for 8.0 01/13] vhost: add available descriptor list in SVQ Eugenio Pérez
2022-12-05 17:04 ` [RFC PATCH for 8.0 02/13] vhost: iterate only available descriptors at SVQ stop Eugenio Pérez
2022-12-05 17:04 ` [RFC PATCH for 8.0 03/13] vhost: merge avail list and next avail descriptors detach Eugenio Pérez
2022-12-05 17:04 ` [RFC PATCH for 8.0 04/13] vhost: add vhost_svq_save_inflight Eugenio Pérez
2022-12-05 17:04 ` [RFC PATCH for 8.0 05/13] virtio: Specify uint32_t as VirtQueueElementOld members type Eugenio Pérez
2022-12-05 17:04 ` Eugenio Pérez [this message]
2022-12-05 17:04 ` [RFC PATCH for 8.0 07/13] virtio: refactor qemu_put_virtqueue_element Eugenio Pérez
2022-12-05 17:04 ` [RFC PATCH for 8.0 08/13] virtio: expose VirtQueueElementOld Eugenio Pérez
2022-12-05 17:04 ` [RFC PATCH for 8.0 09/13] virtio: add vmstate_virtqueue_element_old Eugenio Pérez
2022-12-05 17:04 ` [RFC PATCH for 8.0 10/13] virtio-net: Migrate vhost inflight descriptors Eugenio Pérez
2022-12-05 20:52 ` Parav Pandit
2022-12-07 8:40 ` Eugenio Perez Martin
2022-12-06 3:24 ` Jason Wang
2022-12-07 8:56 ` Eugenio Perez Martin
2023-01-16 21:01 ` Michael S. Tsirkin
2023-01-17 3:38 ` Jason Wang
2023-01-10 3:02 ` Parav Pandit
2023-01-11 4:34 ` Jason Wang
2023-01-11 4:40 ` Parav Pandit
2023-01-11 5:51 ` Jason Wang
2023-01-16 19:53 ` Parav Pandit
2023-01-16 20:58 ` Michael S. Tsirkin
2023-01-17 6:54 ` Jason Wang
2022-12-05 17:04 ` [RFC PATCH for 8.0 11/13] virtio-net: save inflight descriptors at vhost shutdown Eugenio Pérez
2022-12-05 17:04 ` [RFC PATCH for 8.0 12/13] vhost: expose vhost_svq_add_element Eugenio Pérez
2022-12-05 17:04 ` [RFC PATCH for 8.0 13/13] vdpa: Recover inflight descriptors Eugenio Pérez
2022-12-06 7:07 ` [RFC PATCH for 8.0 00/13] vDPA-net inflight descriptors migration with SVQ Jason Wang
2022-12-07 8:59 ` Eugenio Perez Martin
2022-12-08 7:31 ` Jason Wang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221205170436.2977336-7-eperezma@redhat.com \
--to=eperezma@redhat.com \
--cc=dgilbert@redhat.com \
--cc=eli@mellanox.com \
--cc=gdawar@xilinx.com \
--cc=hanand@xilinx.com \
--cc=jasowang@redhat.com \
--cc=lingshan.zhu@intel.com \
--cc=liuxiangdong5@huawei.com \
--cc=lulu@redhat.com \
--cc=lvivier@redhat.com \
--cc=mst@redhat.com \
--cc=parav@mellanox.com \
--cc=qemu-devel@nongnu.org \
--cc=quintela@redhat.com \
--cc=sgarzare@redhat.com \
--cc=si-wei.liu@oracle.com \
--cc=stefanha@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).