From: Connor Kite <connorkite@gmail.com>
To: qemu-devel@nongnu.org
Cc: "Michael S. Tsirkin" <mst@redhat.com>,
"Stefano Garzarella" <sgarzare@redhat.com>,
"Alex Bennée" <alex.bennee@linaro.org>,
"Viresh Kumar" <viresh.kumar@linaro.org>,
"Gerd Hoffmann" <kraxel@redhat.com>,
"Mathieu Poirier" <mathieu.poirier@linaro.org>,
"Manos Pitsidianakis" <manos.pitsidianakis@linaro.org>,
"Raphael Norwitz" <rnorwitz@nvidia.com>,
"Kevin Wolf" <kwolf@redhat.com>,
"Hanna Reitz" <hreitz@redhat.com>,
"Marc-André Lureau" <marcandre.lureau@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Fam Zheng" <fam@euphon.net>,
"Stefan Hajnoczi" <stefanha@redhat.com>,
"Milan Zamazal" <mzamazal@redhat.com>,
"Akihiko Odaki" <odaki@rsg.ci.i.u-tokyo.ac.jp>,
"Dmitry Osipenko" <dmitry.osipenko@collabora.com>,
qemu-block@nongnu.org, virtio-fs@lists.linux.dev,
"Gonglei (Arei)" <arei.gonglei@huawei.com>,
"zhenwei pi" <zhenwei.pi@linux.dev>,
"Daniel P. Berrangé" <berrange@redhat.com>,
"Eric Blake" <eblake@redhat.com>,
"Markus Armbruster" <armbru@redhat.com>,
"Jason Wang" <jasowangio@gmail.com>,
"Peter Xu" <peterx@redhat.com>,
"Eugenio Pérez" <eperezma@redhat.com>,
"Alyssa Ross" <hi@alyssa.is>,
"Demi Marie Obenour" <demiobenour@gmail.com>,
"Connor Kite" <connorkite@gmail.com>,
20260817233147.2867623-1-connorkite@gmail.com
Subject: [PATCH RFC v2 08/13] hw/virtio/vhost-user: send isolation regions to device
Date: Mon, 17 Aug 2026 22:12:23 -0700 [thread overview]
Message-ID: <20260817-vhost-user-isolated-memory-v2-8-948aae960abb@gmail.com> (raw)
In-Reply-To: <20260817-vhost-user-isolated-memory-v2-0-948aae960abb@gmail.com>
Adds features to fill a vhost_user_set_mem_table message with the
addresses of isolation memory regions corresponding to bounce buffers
and vrings.
Signed-off-by: Connor Kite <connorkite@gmail.com>
---
hw/virtio/vhost-user.c | 118 ++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 117 insertions(+), 1 deletion(-)
diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c
index 7e9233e174..e1e5cba53d 100644
--- a/hw/virtio/vhost-user.c
+++ b/hw/virtio/vhost-user.c
@@ -1140,7 +1140,77 @@ static void cleanup_isolation_regions(struct vhost_dev *dev)
}
}
-__attribute__((unused))
+typedef struct {
+ VhostUserMsg *msg;
+ struct vhost_user *u;
+ int *fds;
+ size_t fds_size;
+ uint64_t vring_iova;
+ size_t vring_size;
+ bool vring_node_visited;
+ size_t *idx;
+} IOVATreeTraversalArgs;
+
+static gboolean vhost_user_fill_msg_reg_from_tree(gpointer key,
+ gpointer value,
+ gpointer data)
+{
+ IOVATreeTraversalArgs *args = data;
+ struct vhost_user *u;
+ VhostUserMsg *msg = args->msg;
+ DMAMap *map = key;
+ uint64_t offset;
+
+ assert(args && key && value);
+ if (!args->vring_node_visited) {
+ args->vring_node_visited = true;
+ return false;
+ }
+
+ u = args->u;
+ assert(*args->idx < args->fds_size);
+
+ args->fds[*args->idx] = args->u->iso_mem_ctx.fd;
+
+ /*
+ * If the number of regions is fixed, it would be wasteful to use one for
+ * only the vrings. The first vhost_iova_tree element is always
+ * reserved for the vrings, so we can simply combine the first and second
+ * elements, which are contiguous in IOVA space, when sending regions to
+ * the backend.
+ */
+ if (*args->idx == 0) {
+ offset = u->iso_mem_ctx.vring_hva_addr - u->iso_mem_ctx.shared_mem_addr;
+ msg->payload.memory.regions[*args->idx].userspace_addr =
+ args->vring_iova;
+ /*
+ * The size from the iova tree is inclusive, so 1 is added to it.
+ * args->vring_size is exclusive, so no addition is required.
+ */
+ msg->payload.memory.regions[*args->idx].memory_size =
+ args->vring_size + map->size + 1;
+ msg->payload.memory.regions[*args->idx].guest_phys_addr =
+ args->vring_iova;
+ msg->payload.memory.regions[*args->idx].mmap_offset = offset;
+ } else {
+ /* Use 128 bit operation in unlikely case of negative iso_iova_offset */
+ offset = int128_get64(int128_add(int128_make64(map->iova),
+ u->iso_mem_ctx.iso_iova_offset)) -
+ (uint64_t)u->iso_mem_ctx.shared_mem_addr;
+
+ msg->payload.memory.regions[*args->idx].userspace_addr = map->iova;
+ msg->payload.memory.regions[*args->idx].memory_size = map->size + 1;
+ msg->payload.memory.regions[*args->idx].guest_phys_addr = map->iova;
+ msg->payload.memory.regions[*args->idx].mmap_offset = offset;
+ }
+
+ assert(offset + msg->payload.memory.regions[*args->idx].memory_size <=
+ u->iso_mem_ctx.size);
+ (*args->idx)++;
+
+ return false;
+}
+
static int init_isolation_regions(struct vhost_dev *dev,
VhostUserMsg *msg,
int *fds, size_t *fd_num)
@@ -1159,6 +1229,7 @@ static int init_isolation_regions(struct vhost_dev *dev,
DMAMap *map;
DMAMap vring_map;
int r;
+ IOVATreeTraversalArgs trav_args;
msg->hdr.request = VHOST_USER_SET_MEM_TABLE;
@@ -1244,6 +1315,27 @@ static int init_isolation_regions(struct vhost_dev *dev,
}
}
+ *fd_num = 0;
+ trav_args.idx = fd_num;
+ trav_args.fds = fds;
+ trav_args.msg = msg;
+ trav_args.u = u;
+ trav_args.vring_iova = vring_map.iova;
+ trav_args.vring_size = total_vring_size;
+ trav_args.fds_size = nregions;
+ trav_args.vring_node_visited = false;
+
+ vhost_iova_tree_foreach(u->iso_mem_ctx.tree,
+ vhost_user_fill_msg_reg_from_tree, &trav_args);
+
+ msg->payload.memory.nregions = *fd_num;
+
+ assert(*fd_num == nregions);
+
+ msg->hdr.size = sizeof(msg->payload.memory.nregions);
+ msg->hdr.size += sizeof(msg->payload.memory.padding);
+ msg->hdr.size += *fd_num * sizeof(VhostUserMemoryRegion);
+
return 0;
}
@@ -1251,6 +1343,7 @@ static int vhost_user_set_mem_table(struct vhost_dev *dev,
struct vhost_memory *mem)
{
struct vhost_user *u = dev->opaque;
+ bool memory_isolation = u->user->memory_isolation;
int fds[VHOST_MEMORY_BASELINE_NREGIONS];
size_t fd_num = 0;
bool do_postcopy = u->postcopy_listen && u->postcopy_fd.handler;
@@ -1262,6 +1355,11 @@ static int vhost_user_set_mem_table(struct vhost_dev *dev,
int ret;
if (do_postcopy) {
+ /* Postcopy is not supported with memory isolation yet */
+ if (memory_isolation) {
+ return -1;
+ }
+
/*
* Postcopy has enough differences that it's best done in it's own
* version
@@ -1278,6 +1376,24 @@ static int vhost_user_set_mem_table(struct vhost_dev *dev,
msg.hdr.flags |= VHOST_USER_NEED_REPLY_MASK;
}
+ if (memory_isolation) {
+ ret = init_isolation_regions(dev, &msg, fds, &fd_num);
+ if (ret < 0) {
+ return ret;
+ }
+
+ ret = vhost_user_write(dev, &msg, fds, fd_num);
+ if (ret < 0) {
+ return ret;
+ }
+
+ if (reply_supported) {
+ return process_message_reply(dev, &msg);
+ }
+
+ return 0;
+ }
+
if (config_mem_slots) {
ret = vhost_user_add_remove_regions(dev, &msg, reply_supported, false);
if (ret < 0) {
--
2.43.0
next prev parent reply other threads:[~2026-08-18 5:12 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-18 5:12 [PATCH RFC v2 00/13] vhost-user: isolated memory Connor Kite
2026-08-18 5:12 ` [PATCH RFC v2 01/13] vhost-user: Consolidate chardev property definitions Connor Kite
2026-08-18 5:12 ` [PATCH RFC v2 02/13] util/iova-tree: g_tree_foreach wrapper Connor Kite
2026-08-18 5:12 ` [PATCH RFC v2 03/13] hw/virtio: iova_tree_foreach wrapper Connor Kite
2026-08-18 5:12 ` [PATCH RFC v2 04/13] hw/virtio/vhost-shadow-virtqueue: used callback Connor Kite
2026-08-19 6:23 ` Akihiko Odaki
2026-08-20 1:06 ` Connor Kite
2026-08-20 5:15 ` Akihiko Odaki
2026-08-20 23:42 ` Connor Kite
2026-08-21 7:21 ` Akihiko Odaki
2026-08-18 5:12 ` [PATCH RFC v2 05/13] hw/virtio/vhost-shadow-virtqueue: specified vring placement Connor Kite
2026-08-18 5:12 ` [PATCH RFC v2 06/13] vhost-user: add memory_isolation to VhostUserState Connor Kite
2026-08-18 5:12 ` [PATCH RFC v2 07/13] hw/virtio/vhost-user: create isolation region Connor Kite
2026-08-19 7:36 ` Akihiko Odaki
2026-08-21 2:57 ` Connor Kite
2026-08-18 5:12 ` Connor Kite [this message]
2026-08-18 11:31 ` [PATCH RFC v2 08/13] hw/virtio/vhost-user: send isolation regions to device Akihiko Odaki
2026-08-18 5:12 ` [PATCH RFC v2 09/13] hw/virtio/vhost-user: add shadow virtqueues and eventfd intercepts Connor Kite
2026-08-18 12:34 ` Akihiko Odaki
2026-08-20 20:38 ` Connor Kite
2026-08-18 5:12 ` [PATCH RFC v2 10/13] hw/virtio/vhost-user: handle data movement with shadow vqs Connor Kite
2026-08-19 7:37 ` Akihiko Odaki
2026-08-18 5:12 ` [PATCH RFC v2 11/13] vhost-user: Add memory-isolation qdev property to vhost-user devices Connor Kite
2026-08-18 5:12 ` [PATCH RFC v2 12/13] backends/cryptodev-vhost-user: add memory isolation bool Connor Kite
2026-08-20 9:00 ` Markus Armbruster
2026-08-18 5:12 ` [PATCH RFC v2 13/13] net/vhost-user: add memory isolation Connor Kite
2026-08-19 7:37 ` Akihiko Odaki
2026-08-20 1:22 ` Connor Kite
2026-08-20 9:02 ` Markus Armbruster
2026-08-21 0:39 ` Connor Kite
2026-08-21 5:54 ` Markus Armbruster
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=20260817-vhost-user-isolated-memory-v2-8-948aae960abb@gmail.com \
--to=connorkite@gmail.com \
--cc=20260817233147.2867623-1-connorkite@gmail.com \
--cc=alex.bennee@linaro.org \
--cc=arei.gonglei@huawei.com \
--cc=armbru@redhat.com \
--cc=berrange@redhat.com \
--cc=demiobenour@gmail.com \
--cc=dmitry.osipenko@collabora.com \
--cc=eblake@redhat.com \
--cc=eperezma@redhat.com \
--cc=fam@euphon.net \
--cc=hi@alyssa.is \
--cc=hreitz@redhat.com \
--cc=jasowangio@gmail.com \
--cc=kraxel@redhat.com \
--cc=kwolf@redhat.com \
--cc=manos.pitsidianakis@linaro.org \
--cc=marcandre.lureau@redhat.com \
--cc=mathieu.poirier@linaro.org \
--cc=mst@redhat.com \
--cc=mzamazal@redhat.com \
--cc=odaki@rsg.ci.i.u-tokyo.ac.jp \
--cc=pbonzini@redhat.com \
--cc=peterx@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=rnorwitz@nvidia.com \
--cc=sgarzare@redhat.com \
--cc=stefanha@redhat.com \
--cc=viresh.kumar@linaro.org \
--cc=virtio-fs@lists.linux.dev \
--cc=zhenwei.pi@linux.dev \
/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