qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Albert Esteve <aesteve@redhat.com>
To: qemu-devel@nongnu.org
Cc: david@redhat.com, "Michael S. Tsirkin" <mst@redhat.com>,
	hi@alyssa.is, jasowang@redhat.com,
	"Laurent Vivier" <lvivier@redhat.com>,
	dbassey@redhat.com, "Stefano Garzarella" <sgarzare@redhat.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	stefanha@redhat.com, stevensd@chromium.org,
	"Fabiano Rosas" <farosas@suse.de>,
	"Alex Bennée" <alex.bennee@linaro.org>,
	slp@redhat.com, "Albert Esteve" <aesteve@redhat.com>
Subject: [PATCH v7 0/8] vhost-user: Add SHMEM_MAP/UNMAP requests
Date: Mon, 18 Aug 2025 12:03:45 +0200	[thread overview]
Message-ID: <20250818100353.1560655-1-aesteve@redhat.com> (raw)

Hi all,

v6->v7
- Fixed vhost_user_shmem_object_new to use
  memory_region_init_ram_from_fd as before
v5->v6
- Added intermediate QOM object to manage shared
  MemoryRegion lifecycle with reference counting,
  and automatic cleanup
- Resolved BAR conflict, change from 2 to 3
  to avoid conflict with `modern-pio-notify=on`
- Added SHMEM_CONFIG validation in vhost-user-test
- Changed VirtSharedMemory -> VirtioSharedMemory
- Changed MappedMemoryRegion -> VirtioSharedMemoryMapping
- Changed from heap-allocated MemoryRegion *mr to
  embedded MemoryRegion mr in VirtioSharedMemory
  structure to eliminate memory leaks and
  simplify cleanup
- Fixed VirtioSharedMemory initialization and
  cleanup with memory_region_init() and object_unparent()
- Other minor fixes, typos, and updates.

This patch series implements dynamic fd-backed
memory mapping support for vhost-user backends,
enabling backends to dynamically request memory
mappings and unmappings during runtime through the new
VHOST_USER_BACKEND_SHMEM_MAP/UNMAP protocol messages.

This feature benefits various VIRTIO devices that
require dynamic shared memory management, including
virtiofs (for DAX mappings), virtio-gpu (for resource
sharing), and the recently standardized virtio-media
device.

The implementation introduces a robust QOM-based
architecture for managing shared memory lifecycle:

- VhostUserShmemObject: an intermediate object that
  manages individual memory mappings
- VIRTIO Shared Memory Regions: generic container
  regions declared in VirtIODevice to support any
  vhost-user device type
- Dynamic Mapping: backends can request mappings via
  SHMEM_MAP messages, with the frontend creating
  MemoryRegions from the provided file descriptors and
  adding them as subregions

When a SHMEM_MAP request is received, the frontend:
1. Creates VhostUserShmemObject to manage the mapping
   lifecycle
2. Maps the provided fd with memory_region_init_ram_from_fd()
3. Creates a MemoryRegion backed by the mapped memory
4. Adds it as a subregion of the appropiate VIRTIO
   Shared Memory Region

The QOM reference counting ensures automatic cleanup
when mappings are removed or the device is destroyed.

This patch also includes:
- VHOST_USER_GET_SHMEM_CONFIG: a new frontend request
  allowing generic vhost-user devices to query shared
  memory configuration from backends at device
  initialization, enabling the generic vhost-user-device
  frontend to work with any backend regardless of specific
  shared memory requirements.

The implementation has been tested with rust-vmm based
backends and includes SHMEM_CONFIG QTest validation.

Albert Esteve (8):
  vhost-user: Add VirtIO Shared Memory map request
  vhost_user.rst: Align VhostUserMsg excerpt members
  vhost_user.rst: Add SHMEM_MAP/_UNMAP to spec
  vhost_user: Add frontend get_shmem_config command
  vhost_user.rst: Add GET_SHMEM_CONFIG message
  tests/qtest: Add GET_SHMEM validation test
  qmp: add shmem feature map
  vhost-user-device: Add shared memory BAR

 docs/interop/vhost-user.rst               | 101 +++++++++
 hw/virtio/meson.build                     |   1 +
 hw/virtio/vhost-user-base.c               |  49 ++++-
 hw/virtio/vhost-user-device-pci.c         |  34 ++-
 hw/virtio/vhost-user-shmem.c              | 134 ++++++++++++
 hw/virtio/vhost-user.c                    | 250 +++++++++++++++++++++-
 hw/virtio/virtio-qmp.c                    |   3 +
 hw/virtio/virtio.c                        | 109 ++++++++++
 include/hw/virtio/vhost-backend.h         |  10 +
 include/hw/virtio/vhost-user-shmem.h      |  75 +++++++
 include/hw/virtio/vhost-user.h            |   1 +
 include/hw/virtio/virtio.h                |  95 ++++++++
 subprojects/libvhost-user/libvhost-user.c |  70 ++++++
 subprojects/libvhost-user/libvhost-user.h |  54 +++++
 tests/qtest/vhost-user-test.c             |  91 ++++++++
 15 files changed, 1070 insertions(+), 7 deletions(-)
 create mode 100644 hw/virtio/vhost-user-shmem.c
 create mode 100644 include/hw/virtio/vhost-user-shmem.h

-- 
2.49.0



             reply	other threads:[~2025-08-18 10:05 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-18 10:03 Albert Esteve [this message]
2025-08-18 10:03 ` [PATCH v7 1/8] vhost-user: Add VirtIO Shared Memory map request Albert Esteve
2025-08-18 18:58   ` Stefan Hajnoczi
2025-08-19 12:47     ` Albert Esteve
2025-08-19 12:56       ` Albert Esteve
2025-08-19  9:22   ` David Hildenbrand
2025-08-18 10:03 ` [PATCH v7 2/8] vhost_user.rst: Align VhostUserMsg excerpt members Albert Esteve
2025-08-18 10:03 ` [PATCH v7 3/8] vhost_user.rst: Add SHMEM_MAP/_UNMAP to spec Albert Esteve
2025-08-18 10:03 ` [PATCH v7 4/8] vhost_user: Add frontend get_shmem_config command Albert Esteve
2025-08-18 10:03 ` [PATCH v7 5/8] vhost_user.rst: Add GET_SHMEM_CONFIG message Albert Esteve
2025-08-18 10:03 ` [PATCH v7 6/8] tests/qtest: Add GET_SHMEM validation test Albert Esteve
2025-08-18 23:14   ` Stefan Hajnoczi
2025-08-19 12:16     ` Albert Esteve
2025-08-20  8:47       ` Alyssa Ross
2025-08-20 15:42       ` Stefan Hajnoczi
2025-08-20 20:33       ` Stefan Hajnoczi
2025-08-21  6:50         ` Albert Esteve
2025-09-10 11:10           ` Albert Esteve
2025-08-18 10:03 ` [PATCH v7 7/8] qmp: add shmem feature map Albert Esteve
2025-08-18 10:03 ` [PATCH v7 8/8] vhost-user-device: Add shared memory BAR Albert Esteve
2025-08-19 10:42   ` Stefan Hajnoczi
2025-08-19 11:41     ` Albert Esteve

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=20250818100353.1560655-1-aesteve@redhat.com \
    --to=aesteve@redhat.com \
    --cc=alex.bennee@linaro.org \
    --cc=david@redhat.com \
    --cc=dbassey@redhat.com \
    --cc=farosas@suse.de \
    --cc=hi@alyssa.is \
    --cc=jasowang@redhat.com \
    --cc=lvivier@redhat.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=sgarzare@redhat.com \
    --cc=slp@redhat.com \
    --cc=stefanha@redhat.com \
    --cc=stevensd@chromium.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).