From: "Eugenio Pérez" <eperezma@redhat.com>
To: qemu-devel@nongnu.org
Cc: Laurent Vivier <lvivier@redhat.com>,
Parav Pandit <parav@mellanox.com>, Cindy Lu <lulu@redhat.com>,
"Michael S. Tsirkin" <mst@redhat.com>,
Jason Wang <jasowang@redhat.com>,
Gautam Dawar <gdawar@xilinx.com>,
Harpreet Singh Anand <hanand@xilinx.com>,
"Gonglei \(Arei\)" <arei.gonglei@huawei.com>,
Eli Cohen <eli@mellanox.com>,
Liuxiangdong <liuxiangdong5@huawei.com>,
Zhu Lingshan <lingshan.zhu@intel.com>
Subject: [RFC PATCH v7 06/25] vdpa: Send all updates in memory listener commit
Date: Wed, 13 Apr 2022 18:31:47 +0200 [thread overview]
Message-ID: <20220413163206.1958254-7-eperezma@redhat.com> (raw)
In-Reply-To: <20220413163206.1958254-1-eperezma@redhat.com>
With the introduction of many ASID it can happen that many changes on
different listeners come before the commit call. Since kernel vhost-vdpa
still does not support it, send it all in one shot.
This also have one extra advantage: If there is no update to notify, we
save the iotlb_{begin,end} calls.
Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
---
include/hw/virtio/vhost-vdpa.h | 2 +-
hw/virtio/vhost-vdpa.c | 69 +++++++++++++++++-----------------
2 files changed, 36 insertions(+), 35 deletions(-)
diff --git a/include/hw/virtio/vhost-vdpa.h b/include/hw/virtio/vhost-vdpa.h
index a29dbb3f53..4961acea8b 100644
--- a/include/hw/virtio/vhost-vdpa.h
+++ b/include/hw/virtio/vhost-vdpa.h
@@ -27,7 +27,7 @@ typedef struct vhost_vdpa {
int device_fd;
int index;
uint32_t msg_type;
- bool iotlb_batch_begin_sent;
+ GArray *iotlb_updates;
MemoryListener listener;
struct vhost_vdpa_iova_range iova_range;
uint64_t acked_features;
diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c
index 1f229ff4cb..27ee678dc9 100644
--- a/hw/virtio/vhost-vdpa.c
+++ b/hw/virtio/vhost-vdpa.c
@@ -85,6 +85,11 @@ static int vhost_vdpa_dma_map(struct vhost_vdpa *v, hwaddr iova, hwaddr size,
msg.iotlb.perm = readonly ? VHOST_ACCESS_RO : VHOST_ACCESS_RW;
msg.iotlb.type = VHOST_IOTLB_UPDATE;
+ if (v->dev->backend_cap & BIT_ULL(VHOST_BACKEND_F_IOTLB_BATCH)) {
+ g_array_append_val(v->iotlb_updates, msg);
+ return 0;
+ }
+
trace_vhost_vdpa_dma_map(v, fd, msg.type, msg.iotlb.iova, msg.iotlb.size,
msg.iotlb.uaddr, msg.iotlb.perm, msg.iotlb.type);
@@ -109,6 +114,11 @@ static int vhost_vdpa_dma_unmap(struct vhost_vdpa *v, hwaddr iova,
msg.iotlb.size = size;
msg.iotlb.type = VHOST_IOTLB_INVALIDATE;
+ if (v->dev->backend_cap & BIT_ULL(VHOST_BACKEND_F_IOTLB_BATCH)) {
+ g_array_append_val(v->iotlb_updates, msg);
+ return 0;
+ }
+
trace_vhost_vdpa_dma_unmap(v, fd, msg.type, msg.iotlb.iova,
msg.iotlb.size, msg.iotlb.type);
@@ -121,56 +131,47 @@ static int vhost_vdpa_dma_unmap(struct vhost_vdpa *v, hwaddr iova,
return ret;
}
-static void vhost_vdpa_listener_begin_batch(struct vhost_vdpa *v)
-{
- int fd = v->device_fd;
- struct vhost_msg_v2 msg = {
- .type = v->msg_type,
- .iotlb.type = VHOST_IOTLB_BATCH_BEGIN,
- };
-
- trace_vhost_vdpa_listener_begin_batch(v, fd, msg.type, msg.iotlb.type);
- if (write(fd, &msg, sizeof(msg)) != sizeof(msg)) {
- error_report("failed to write, fd=%d, errno=%d (%s)",
- fd, errno, strerror(errno));
- }
-}
-
-static void vhost_vdpa_iotlb_batch_begin_once(struct vhost_vdpa *v)
-{
- if (v->dev->backend_cap & (0x1ULL << VHOST_BACKEND_F_IOTLB_BATCH) &&
- !v->iotlb_batch_begin_sent) {
- vhost_vdpa_listener_begin_batch(v);
- }
-
- v->iotlb_batch_begin_sent = true;
-}
-
static void vhost_vdpa_listener_commit(MemoryListener *listener)
{
struct vhost_vdpa *v = container_of(listener, struct vhost_vdpa, listener);
- struct vhost_dev *dev = v->dev;
struct vhost_msg_v2 msg = {};
int fd = v->device_fd;
+ size_t num = v->iotlb_updates->len;
- if (!(dev->backend_cap & (0x1ULL << VHOST_BACKEND_F_IOTLB_BATCH))) {
+ if (!num) {
return;
}
- if (!v->iotlb_batch_begin_sent) {
- return;
+ msg.type = v->msg_type;
+ msg.iotlb.type = VHOST_IOTLB_BATCH_BEGIN;
+ trace_vhost_vdpa_listener_begin_batch(v, fd, msg.type, msg.iotlb.type);
+ if (write(fd, &msg, sizeof(msg)) != sizeof(msg)) {
+ error_report("failed to write BEGIN_BATCH, fd=%d, errno=%d (%s)",
+ fd, errno, strerror(errno));
+ goto done;
}
- msg.type = v->msg_type;
- msg.iotlb.type = VHOST_IOTLB_BATCH_END;
+ for (size_t i = 0; i < num; ++i) {
+ struct vhost_msg_v2 *update = &g_array_index(v->iotlb_updates,
+ struct vhost_msg_v2, i);
+ if (write(fd, update, sizeof(*update)) != sizeof(*update)) {
+ error_report("failed to write dma update, fd=%d, errno=%d (%s)",
+ fd, errno, strerror(errno));
+ goto done;
+ }
+ }
+ msg.iotlb.type = VHOST_IOTLB_BATCH_END;
trace_vhost_vdpa_listener_commit(v, fd, msg.type, msg.iotlb.type);
if (write(fd, &msg, sizeof(msg)) != sizeof(msg)) {
error_report("failed to write, fd=%d, errno=%d (%s)",
fd, errno, strerror(errno));
}
- v->iotlb_batch_begin_sent = false;
+done:
+ g_array_set_size(v->iotlb_updates, 0);
+ return;
+
}
static void vhost_vdpa_listener_region_add(MemoryListener *listener,
@@ -227,7 +228,6 @@ static void vhost_vdpa_listener_region_add(MemoryListener *listener,
iova = mem_region.iova;
}
- vhost_vdpa_iotlb_batch_begin_once(v);
ret = vhost_vdpa_dma_map(v, iova, int128_get64(llsize),
vaddr, section->readonly);
if (ret) {
@@ -292,7 +292,6 @@ static void vhost_vdpa_listener_region_del(MemoryListener *listener,
iova = result->iova;
vhost_iova_tree_remove(v->iova_tree, &mem_region);
}
- vhost_vdpa_iotlb_batch_begin_once(v);
ret = vhost_vdpa_dma_unmap(v, iova, int128_get64(llsize));
if (ret) {
error_report("vhost_vdpa dma unmap error!");
@@ -446,6 +445,7 @@ static int vhost_vdpa_init(struct vhost_dev *dev, void *opaque, Error **errp)
dev->opaque = opaque ;
v->listener = vhost_vdpa_memory_listener;
v->msg_type = VHOST_IOTLB_MSG_V2;
+ v->iotlb_updates = g_array_new(false, false, sizeof(struct vhost_msg_v2));
ret = vhost_vdpa_init_svq(dev, v, errp);
if (ret) {
goto err;
@@ -579,6 +579,7 @@ static int vhost_vdpa_cleanup(struct vhost_dev *dev)
trace_vhost_vdpa_cleanup(dev, v);
vhost_vdpa_host_notifiers_uninit(dev, dev->nvqs);
memory_listener_unregister(&v->listener);
+ g_array_free(v->iotlb_updates, true);
vhost_vdpa_svq_cleanup(dev);
dev->opaque = NULL;
--
2.27.0
next prev parent reply other threads:[~2022-04-13 16:37 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-13 16:31 [RFC PATCH v7 00/25] Net Control VQ support with asid in vDPA SVQ Eugenio Pérez
2022-04-13 16:31 ` [RFC PATCH v7 01/25] vhost: Track descriptor chain in private at SVQ Eugenio Pérez
2022-04-14 3:48 ` Jason Wang
2022-04-22 14:16 ` Eugenio Perez Martin
2022-04-13 16:31 ` [RFC PATCH v7 02/25] vdpa: Add missing tracing to batch mapping functions Eugenio Pérez
2022-04-14 3:49 ` Jason Wang
2022-04-13 16:31 ` [RFC PATCH v7 03/25] vdpa: Fix bad index calculus at vhost_vdpa_get_vring_base Eugenio Pérez
2022-04-14 3:50 ` Jason Wang
2022-04-13 16:31 ` [RFC PATCH v7 04/25] util: Return void on iova_tree_remove Eugenio Pérez
2022-04-14 3:50 ` Jason Wang
2022-04-13 16:31 ` [RFC PATCH v7 05/25] hw/virtio: Replace g_memdup() by g_memdup2() Eugenio Pérez
2022-04-14 3:51 ` Jason Wang
2022-04-14 4:01 ` Jason Wang
2022-04-13 16:31 ` Eugenio Pérez [this message]
2022-04-14 4:11 ` [RFC PATCH v7 06/25] vdpa: Send all updates in memory listener commit Jason Wang
2022-04-22 9:17 ` Eugenio Perez Martin
2022-04-13 16:31 ` [RFC PATCH v7 07/25] vhost: Add reference counting to vhost_iova_tree Eugenio Pérez
2022-04-14 5:30 ` Jason Wang
2022-04-13 16:31 ` [RFC PATCH v7 08/25] vdpa: Add x-svq to NetdevVhostVDPAOptions Eugenio Pérez
2022-04-14 5:32 ` Jason Wang
2022-04-18 10:36 ` Eugenio Perez Martin
2022-04-13 16:31 ` [RFC PATCH v7 09/25] vhost: move descriptor translation to vhost_svq_vring_write_descs Eugenio Pérez
2022-04-14 5:48 ` Jason Wang
2022-04-13 16:31 ` [RFC PATCH v7 10/25] vdpa: Fix index calculus at vhost_vdpa_svqs_start Eugenio Pérez
2022-04-14 5:59 ` Jason Wang
2022-04-13 16:31 ` [RFC PATCH v7 11/25] virtio-net: Expose ctrl virtqueue logic Eugenio Pérez
2022-04-13 16:31 ` [RFC PATCH v7 12/25] vdpa: Extract get features part from vhost_vdpa_get_max_queue_pairs Eugenio Pérez
2022-04-13 16:31 ` [RFC PATCH v7 13/25] virtio: Make virtqueue_alloc_element non-static Eugenio Pérez
2022-04-13 16:31 ` [RFC PATCH v7 14/25] vhost: Add SVQElement Eugenio Pérez
2022-04-13 16:31 ` [RFC PATCH v7 15/25] vhost: Add custom used buffer callback Eugenio Pérez
2022-04-13 16:31 ` [RFC PATCH v7 16/25] vdpa: control virtqueue support on shadow virtqueue Eugenio Pérez
2022-04-14 9:10 ` Jason Wang
2022-04-18 10:55 ` Eugenio Perez Martin
2022-04-13 16:31 ` [RFC PATCH v7 17/25] vhost: Add vhost_iova_tree_find Eugenio Pérez
2022-04-13 16:31 ` [RFC PATCH v7 18/25] vdpa: Add map/unmap operation callback to SVQ Eugenio Pérez
2022-04-14 9:13 ` Jason Wang
2022-04-13 16:32 ` [RFC PATCH v7 19/25] vhost: Add vhost_svq_inject Eugenio Pérez
2022-04-14 9:09 ` Jason Wang
2022-04-18 13:58 ` Eugenio Perez Martin
2022-04-13 16:32 ` [RFC PATCH v7 20/25] vdpa: add NetClientState->start() callback Eugenio Pérez
2022-04-14 9:14 ` Jason Wang
2022-04-13 16:32 ` [RFC PATCH v7 21/25] vdpa: Add vhost_vdpa_start_control_svq Eugenio Pérez
2022-04-13 16:32 ` [RFC PATCH v7 22/25] vhost: Update kernel headers Eugenio Pérez
2022-04-13 16:32 ` [RFC PATCH v7 23/25] vhost: Make possible to check for device exclusive vq group Eugenio Pérez
2022-04-13 16:32 ` [RFC PATCH v7 24/25] vdpa: Add asid attribute to vdpa device Eugenio Pérez
2022-04-14 9:10 ` Jason Wang
2022-04-18 14:03 ` Eugenio Perez Martin
2022-04-13 16:32 ` [RFC PATCH v7 25/25] vdpa: Add x-cvq-svq Eugenio Pérez
2022-04-14 9:09 ` Jason Wang
2022-04-18 14:16 ` Eugenio Perez Martin
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=20220413163206.1958254-7-eperezma@redhat.com \
--to=eperezma@redhat.com \
--cc=arei.gonglei@huawei.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 \
/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).