Skip to content

RFC vhost-user: isolated memory

Connor Kite qemu-devel virtio-fs 2 versions – In review

Get series with b4
b4 am [email protected] change-id 20260604-vhost-user-isolated-memory-070ed4833ee7

Versions newest first

  1. v2 RFC Latest13 patches 27 repliesIn review
  2. v1 RFC15 patches 83 repliesSuperseded

Changes in v2 from the cover letter

Series:
- Updates to svq address translation moved to a different patch series.

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/13vhost-user: Consolidate chardev property definitionshw/virtio/vhost-user-base.c hw/virtio/vhost-user-gpio.c hw/virtio/vhost-user-i2c.c +6 more+9 -300 replies
2/13util/iova-tree: g_tree_foreach wrapperinclude/qemu/iova-tree.h util/iova-tree.c+26 -00 replies
3/13hw/virtio: iova_tree_foreach wrapperhw/virtio/vhost-iova-tree.c hw/virtio/vhost-iova-tree.h+17 -00 replies
4/13hw/virtio/vhost-shadow-virtqueue: used callbackhw/virtio/vhost-shadow-virtqueue.c hw/virtio/vhost-shadow-virtqueue.h+25 -05 replies
5/13hw/virtio/vhost-shadow-virtqueue: specified vring placementhw/virtio/vhost-shadow-virtqueue.c hw/virtio/vhost-shadow-virtqueue.h+66 -114 replies
6/13vhost-user: add memory_isolation to VhostUserStatebackends/cryptodev-vhost-user.c backends/vhost-user.c hw/block/vhost-user-blk.c +12 more+45 -210 replies
7/13hw/virtio/vhost-user: create isolation regionhw/virtio/vhost-user.c+136 -03 replies
8/13hw/virtio/vhost-user: send isolation regions to devicehw/virtio/vhost-user.c+117 -13 replies
9/13hw/virtio/vhost-user: add shadow virtqueues and eventfd interceptshw/virtio/vhost-user.c+119 -173 replies
10/13hw/virtio/vhost-user: handle data movement with shadow vqshw/virtio/vhost-shadow-virtqueue.c hw/virtio/vhost-shadow-virtqueue.h hw/virtio/vhost-user.c+286 -92 replies
11/13vhost-user: Add memory-isolation qdev property to vhost-user deviceshw/block/vhost-user-blk.c hw/display/vhost-user-gpu.c hw/scsi/vhost-user-scsi.c +11 more+27 -80 replies
12/13backends/cryptodev-vhost-user: add memory isolation boolbackends/cryptodev-vhost-user.c qapi/qom.json+34 -21 reply
13/13net/vhost-user: add memory isolationnet/passt.c net/vhost-user.c qapi/net.json+20 -46 replies

Reviews trailers per patch

3 of 13 patches have a Reviewed-by or Acked-by.

PatchStefan Hajnoczi
1/13R-b
2/13R-b
3/13
4/13
5/13
6/13
7/13
8/13
9/13
10/13
11/13R-b
12/13
13/13

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v2 thread

Cover letter [PATCH RFC v2 00/13] vhost-user: isolated memory

This patch series implements a memory isolation mode in vhost-user. The purpose of this mode is to provide the option of additional security by eliminating direct access of guest memory by vhost-user devices. At a high level this works by:

1. Adding qdev and qapi properties required to enable isolation mode for various devices.
2. Allocating an isolation memory region in an anonymous file and mapping it to host memory. This isolation region will hold the bounce buffers and vrings necessary to move data.
3. Using a vhost-iova-tree to allocate and track the mapping between guest regions and their corresponding bounce buffers in the isolation memory.
4. Creating shadow virtqueues to intercept request notifications. As kick and call events are received by an svq, it copies buffer contents and descriptors between isolation and guest memory before notifying the backend or guest.

Note: This project is currently in a partially functional state. While the overall method will stay the same, the implementation is planned to move up into vhost to simplify some elements of initializing and using the shadow virtqueues.
However, the desire is to make this work public at this stage for comment on the overall approach.

To: [email protected]

Cc Michael S. Tsirkin <[email protected]>
Cc Stefano Garzarella <[email protected]>
Cc Alex Bennée <[email protected]>
Cc Viresh Kumar <[email protected]>
Cc Gerd Hoffmann <[email protected]>
Cc Mathieu Poirier <[email protected]>
Cc Manos Pitsidianakis <[email protected]>
Cc Raphael Norwitz <[email protected]>
Cc Kevin Wolf <[email protected]>
Cc Hanna Reitz <[email protected]>
Cc Marc-André Lureau <[email protected]>
Cc Paolo Bonzini <[email protected]>
Cc Fam Zheng <[email protected]>
Cc Stefan Hajnoczi <[email protected]>
Cc Milan Zamazal <[email protected]>
Cc Akihiko Odaki <[email protected]>
Cc Dmitry Osipenko <[email protected]>
Cc Gonglei (Arei) <[email protected]>
Cc zhenwei pi <[email protected]>
Cc Daniel P. Berrangé <[email protected]>
Cc Eric Blake <[email protected]>
Cc Markus Armbruster <[email protected]>
Cc Jason Wang <[email protected]>
Cc Peter Xu <[email protected]>
Cc Eugenio Pérez <[email protected]>
Cc Alyssa Ross <[email protected]>
Cc Demi Marie Obenour <[email protected]>

Based-on: [email protected]
---
Changelog:
V2:
Series:
- Updates to svq address translation moved to a different patch series.

- The "shadow vq cleanup" has been merged into the earlier patch
handling svq setup.
- Link to v1: https://lore.kernel.org/qemu-devel/[email protected]

Individual Patches:
vhost-user: Consolidate chardev property definitions
- Patch author updated from ConKite to Connor Kite

util/iova-tree: g_tree_foreach wrapper
- Added clarification comments about the function passed to iova_tree_foreach

hw/virtio: iova_tree_foreach wrapper
- Corrected comment about GTraverseFUnc end condition

hw/virtio/vhost-shadow-virtqueue: used callback
- Changed name of "used_handler" to "used_callback"
- Added handling if callback returns with error value
- Comments added clarifying callback return values

hw/virtio/vhost-shadow-virtqueue: specified vring placement
- Formatting improvements
- Change hwaddr to void * for pointers to host memory
- Bounds checking added when allocating vrings

vhost-user: add memory_isolation to VhostUserState
- Updated net_passt_vhost_user_init signature that is active when !defined(CONFIG_VHOST_USER)
- Comment updates for clarity

hw/virtio/vhost-user: create isolation region
- Formatting fixes
- Many comments added
- Read-after-zeroing bug fixed in cleanup_isolation_regions
- User-after-free bug in init_isolation_regions fixed by removing duplicate calls, and consolidating those steps in cleanup_isolation_regions
- Data unique to isolation mode consolidated in IsolationModeCtx struct
- Vring memory size calculations now only done via an API exposed by vhost-shadow-virtqueue
- Isolation region memfd file given a unique name
- Iova-tree IOVA space now starts at 0 + page_size to avoid exposing qemu addresses
- buffer_regions array moved changed from GArray to dynamically allocated array of predetermined size. Avoids GArray formatting ugliness

Note: Devicies implemented with multiple vhost threads, like virtio-net, are not currently supported. Work is still required to update the vring allocation code to run only for vq_index=0 and propagate to the other vhost-user instances.

hw/virtio/vhost-user: send isolation regions to device
- Formatting improvements
- Vring region combined with contiguous buffer region in IOVA space to avoid wasting one of the available region slots that can be sent to the back-end
- Traversal callback for filling out msg regions renamed to vhost_user_fill_msg_reg_from_tree and simplified
- Check added if postcopy is in use as it is not currently supported

hw/virtio/vhost-user: add shadow virtqueues and eventfd intercepts
- Vring mapping now occurs during the vhost_user_set_mem_tables call, which means that vring addresses can be sent to the backend when expected by vhost
- The svq's device-facing event notifiers are now cleaned up in case of error or reset
- Bounds checking on vq index added in various locations
- SVQ cleanup code added

hw/virtio/vhost-user: handle data movement with shadow vqs
- Removed unecessary changes to elements during handling
- Fixed incorrect memcpy of used buffers in reverse direction
- Formatting improvements
- Bounds and error checking to handle mapping failures or buffers with invalid ranges
- Add error if isolation mode is used while IOMMU is active
- Add error if isolation mode is used with packed vrings

vhost-user: Add memory-isolation qdev property to vhost-user devices
- Patch moved to end of patch series
- Fixed overlong lines

backends/cryptodev-vhost-user: add memory isolation bool
- Fixed style in qapi and added "since" field
- Clarification added to comments
- The memory_isolation bool can no longer be set in vhost-cryptodev once initialization finishes

net/vhost-user: add memory isolation
- Moved to the back of the patch series
- Dead code removed by hard-coding memory_isolation args to vhost_user_init

---
Connor Kite (13):
vhost-user: Consolidate chardev property definitions util/iova-tree: g_tree_foreach wrapper
hw/virtio: iova_tree_foreach wrapper hw/virtio/vhost-shadow-virtqueue: used callback hw/virtio/vhost-shadow-virtqueue: specified vring placement
vhost-user: add memory_isolation to VhostUserState hw/virtio/vhost-user: create isolation region hw/virtio/vhost-user: send isolation regions to device hw/virtio/vhost-user: add shadow virtqueues and eventfd intercepts hw/virtio/vhost-user: handle data movement with shadow vqs
vhost-user: Add memory-isolation qdev property to vhost-user devices backends/cryptodev-vhost-user: add memory isolation bool net/vhost-user: add memory isolation

 backends/cryptodev-vhost-user.c      |  28 +-
 backends/vhost-user.c                |   4 +-
 hw/block/vhost-user-blk.c            |   4 +-
 hw/display/vhost-user-gpu.c          |   4 +-
 hw/scsi/vhost-user-scsi.c            |   5 +-
 hw/virtio/vhost-iova-tree.c          |  15 +
 hw/virtio/vhost-iova-tree.h          |   2 +
 hw/virtio/vhost-shadow-virtqueue.c   |  80 ++++-
 hw/virtio/vhost-shadow-virtqueue.h   |  25 +-
 hw/virtio/vhost-stub.c               |   3 +-
 hw/virtio/vhost-user-base.c          |  14 +-
 hw/virtio/vhost-user-fs.c            |   5 +-
 hw/virtio/vhost-user-gpio.c          |   4 -
 hw/virtio/vhost-user-i2c.c           |   5 -
 hw/virtio/vhost-user-input.c         |   5 -
 hw/virtio/vhost-user-rng.c           |   5 -
 hw/virtio/vhost-user-rtc.c           |   4 -
 hw/virtio/vhost-user-scmi.c          |   5 +-
 hw/virtio/vhost-user-snd.c           |   1 -
 hw/virtio/vhost-user-spi.c           |   5 -
 hw/virtio/vhost-user-test-device.c   |   1 -
 hw/virtio/vhost-user-vsock.c         |   5 +-
 hw/virtio/vhost-user.c               | 657 ++++++++++++++++++++++++++++++++++-
 include/hw/virtio/vhost-user-base.h  |   1 +
 include/hw/virtio/vhost-user-blk.h   |   1 +
 include/hw/virtio/vhost-user-fs.h    |   1 +
 include/hw/virtio/vhost-user-scmi.h  |   1 +
 include/hw/virtio/vhost-user-vsock.h |   1 +
 include/hw/virtio/vhost-user.h       |   6 +-
 include/hw/virtio/virtio-gpu.h       |   1 +
 include/hw/virtio/virtio-scsi.h      |   1 +
 include/qemu/iova-tree.h             |  21 ++
 include/system/vhost-user-backend.h  |   3 +-
 net/passt.c                          |  19 +-
 net/vhost-user.c                     |  11 +-
 qapi/net.json                        |  16 +-
 qapi/qom.json                        |   8 +-
 util/iova-tree.c                     |   5 +
 38 files changed, 903 insertions(+), 79 deletions(-)

---
base-commit: 88aac004fb1bef50277d8484f4aeacf2e8cb9e38
change-id: 20260604-vhost-user-isolated-memory-070ed4833ee7

Best regards,

Signature · 1 line
Connor Kite <[email protected]>