[PATCH v10 0/7] vhost-user: Add SHMEM_MAP/UNMAP requests

Albert Esteve posted 7 patches 1 week, 1 day ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20251016143827.1850397-1-aesteve@redhat.com
Maintainers: "Michael S. Tsirkin" <mst@redhat.com>, Stefano Garzarella <sgarzare@redhat.com>, "Alex Bennée" <alex.bennee@linaro.org>
docs/interop/vhost-user.rst               | 101 ++++++++
hw/virtio/vhost-user-base.c               |  47 +++-
hw/virtio/vhost-user-test-device-pci.c    |  39 +++-
hw/virtio/vhost-user.c                    | 267 ++++++++++++++++++++++
hw/virtio/virtio-qmp.c                    |   3 +
hw/virtio/virtio.c                        | 199 ++++++++++++++++
include/hw/virtio/vhost-backend.h         |  10 +
include/hw/virtio/vhost-user.h            |   1 +
include/hw/virtio/virtio.h                | 137 +++++++++++
subprojects/libvhost-user/libvhost-user.c |  70 ++++++
subprojects/libvhost-user/libvhost-user.h |  54 +++++
11 files changed, 923 insertions(+), 5 deletions(-)
[PATCH v10 0/7] vhost-user: Add SHMEM_MAP/UNMAP requests
Posted by Albert Esteve 1 week, 1 day ago
Hi all,

v9->v10
- Fix transaction_commit invoked without transaction_begin
  on vhost_user_backend_handle_shmem_map() early errors
- Removed fd tracking on VirtioSharedMemoryMapping, it
  is handled by the RAMBlock
- Reject invalid BAR configurations when VIRTIO Shared Memory
  Regions are in use by vhost-user-test-device
v8->v9
- Fixed vhost-user new handlers to ensure that they always
  reply
- Made MMAP request flags field u64 everywhere
- Fixed double memory_region_del_subregion() on UNMAP
- Add mappings cleaning on virtio_reset()
- Some small typos and fixes
- Fixed virtio pci bar mapping for vhost-user-test-device
v7->v8
- Unified VhostUserShmemObject and VirtioSharedMemoryMapping
- Refined shmem_obj lifecycle by transferring ownership
- Other small improvements

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.

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

- VirtioSharedMemoryMapping: an intermediate object that manages
  individual memory mappings by acting as generic container for regions
  declared in 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 VirtioSharedMemoryMapping 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.

Albert Esteve (7):
  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
  qmp: add shmem feature map
  vhost-user-device: Add shared memory BAR

 docs/interop/vhost-user.rst               | 101 ++++++++
 hw/virtio/vhost-user-base.c               |  47 +++-
 hw/virtio/vhost-user-test-device-pci.c    |  39 +++-
 hw/virtio/vhost-user.c                    | 267 ++++++++++++++++++++++
 hw/virtio/virtio-qmp.c                    |   3 +
 hw/virtio/virtio.c                        | 199 ++++++++++++++++
 include/hw/virtio/vhost-backend.h         |  10 +
 include/hw/virtio/vhost-user.h            |   1 +
 include/hw/virtio/virtio.h                | 137 +++++++++++
 subprojects/libvhost-user/libvhost-user.c |  70 ++++++
 subprojects/libvhost-user/libvhost-user.h |  54 +++++
 11 files changed, 923 insertions(+), 5 deletions(-)

-- 
2.49.0
Re: [PATCH v10 0/7] vhost-user: Add SHMEM_MAP/UNMAP requests
Posted by Stefan Hajnoczi 1 week, 1 day ago
On Thu, Oct 16, 2025 at 04:38:20PM +0200, Albert Esteve wrote:
> v9->v10
> - Fix transaction_commit invoked without transaction_begin
>   on vhost_user_backend_handle_shmem_map() early errors
> - Removed fd tracking on VirtioSharedMemoryMapping, it
>   is handled by the RAMBlock
> - Reject invalid BAR configurations when VIRTIO Shared Memory
>   Regions are in use by vhost-user-test-device

Hi Michael,
I have finished reviewing this series. If no one else has comments then
it can be considered for merging through your VIRTIO/vhost tree.

Thanks,
Stefan
Re: [PATCH v10 0/7] vhost-user: Add SHMEM_MAP/UNMAP requests
Posted by David Hildenbrand 4 days, 18 hours ago
On 16.10.25 17:05, Stefan Hajnoczi wrote:
> On Thu, Oct 16, 2025 at 04:38:20PM +0200, Albert Esteve wrote:
>> v9->v10
>> - Fix transaction_commit invoked without transaction_begin
>>    on vhost_user_backend_handle_shmem_map() early errors
>> - Removed fd tracking on VirtioSharedMemoryMapping, it
>>    is handled by the RAMBlock
>> - Reject invalid BAR configurations when VIRTIO Shared Memory
>>    Regions are in use by vhost-user-test-device
> 
> Hi Michael,
> I have finished reviewing this series. If no one else has comments then
> it can be considered for merging through your VIRTIO/vhost tree.

Skimmed once again over it and only had one comment that could also be 
addressed later.

-- 
Cheers

David / dhildenb
Re: [PATCH v10 0/7] vhost-user: Add SHMEM_MAP/UNMAP requests
Posted by Michael S. Tsirkin 1 week ago
On Thu, Oct 16, 2025 at 11:05:44AM -0400, Stefan Hajnoczi wrote:
> On Thu, Oct 16, 2025 at 04:38:20PM +0200, Albert Esteve wrote:
> > v9->v10
> > - Fix transaction_commit invoked without transaction_begin
> >   on vhost_user_backend_handle_shmem_map() early errors
> > - Removed fd tracking on VirtioSharedMemoryMapping, it
> >   is handled by the RAMBlock
> > - Reject invalid BAR configurations when VIRTIO Shared Memory
> >   Regions are in use by vhost-user-test-device
> 
> Hi Michael,
> I have finished reviewing this series. If no one else has comments then
> it can be considered for merging through your VIRTIO/vhost tree.
> 
> Thanks,
> Stefan

will do, thanks!
Re: [PATCH v10 0/7] vhost-user: Add SHMEM_MAP/UNMAP requests
Posted by Stefano Garzarella 1 week ago
On Thu, Oct 16, 2025 at 11:05:44AM -0400, Stefan Hajnoczi wrote:
>On Thu, Oct 16, 2025 at 04:38:20PM +0200, Albert Esteve wrote:
>> v9->v10
>> - Fix transaction_commit invoked without transaction_begin
>>   on vhost_user_backend_handle_shmem_map() early errors
>> - Removed fd tracking on VirtioSharedMemoryMapping, it
>>   is handled by the RAMBlock
>> - Reject invalid BAR configurations when VIRTIO Shared Memory
>>   Regions are in use by vhost-user-test-device
>
>Hi Michael,
>I have finished reviewing this series. If no one else has comments then
>it can be considered for merging through your VIRTIO/vhost tree.

iI left a few comments, and I still have my doubts about the error path, 
but as Albert said, it doesn't seem easy to manage, so for now I think 
the series can go ahead as it is.

Acked-by: Stefano Garzarella <sgarzare@redhat.com>

Thanks,
Stefano