qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v6 00/12] vhost-user: support any POSIX system (tested on macOS, FreeBSD, OpenBSD)
@ 2024-05-28 10:35 Stefano Garzarella
  2024-05-28 10:35 ` [PATCH v6 01/12] libvhost-user: set msg.msg_control to NULL when it is empty Stefano Garzarella
                   ` (11 more replies)
  0 siblings, 12 replies; 18+ messages in thread
From: Stefano Garzarella @ 2024-05-28 10:35 UTC (permalink / raw)
  To: qemu-devel
  Cc: slp, David Hildenbrand, Paolo Bonzini, Eduardo Habkost,
	Igor Mammedov, Brad Smith, gmaglione, Philippe Mathieu-Daudé,
	Laurent Vivier, Kevin Wolf, Jason Wang, Michael S. Tsirkin,
	Eric Blake, Markus Armbruster, Coiby Xu, qemu-block, Hanna Reitz,
	Marc-André Lureau, Raphael Norwitz, Thomas Huth, stefanha,
	Daniel P. Berrangé, Gerd Hoffmann, Stefano Garzarella

v1: https://patchew.org/QEMU/20240228114759.44758-1-sgarzare@redhat.com/
v2: https://patchew.org/QEMU/20240326133936.125332-1-sgarzare@redhat.com/
v3: https://patchew.org/QEMU/20240404122330.92710-1-sgarzare@redhat.com/
v4: https://patchew.org/QEMU/20240508074457.12367-1-sgarzare@redhat.com/
v5: https://patchew.org/QEMU/20240523145522.313012-1-sgarzare@redhat.com/
v6:
- rebased on 60b54b67c63d8f076152e0f7dccf39854dfc6a77
- added David R-b tags [thanks!]
- patch 9 (was split in 9 & 10 in v5): reverted v5 changes since we can't
  move O_DSYNC and O_DIRECT in osdep [Daniel, failing tests on Windows]
- patch 11: removed `share=on` since it's the default [David]
- the series is now fully acked/reviewed

The vhost-user protocol is not really Linux-specific, so let's try support
QEMU's frontends and backends (including libvhost-user) in any POSIX system
with this series. The main use case is to be able to use virtio devices that
we don't have built-in in QEMU (e.g. virtiofsd, vhost-user-vsock, etc.) even
in non-Linux systems.

The first 5 patches are more like fixes discovered at runtime on macOS or
FreeBSD that could go even independently of this series.

Patches 6, 7, 8, 9 enable building of frontends and backends (including
libvhost-user) with associated code changes to succeed in compilation.

Patch 10 adds `memory-backend-shm` that uses the POSIX shm_open() API to
create shared memory which is identified by an fd that can be shared with
vhost-user backends. This is useful on those systems (like macOS) where
we don't have memfd_create() or special filesystems like "/dev/shm".

Patches 11 and 12 use `memory-backend-shm` in some vhost-user tests.

Maybe the first 5 patches can go separately, but I only discovered those
problems after testing patches 6 - 9, so I have included them in this series
for now. Please let me know if you prefer that I send them separately.

I tested this series using vhost-user-blk and QSD on macOS Sonoma 14.4
(aarch64), FreeBSD 14 (x86_64), OpenBSD 7.4 (x86_64), and Fedora 40 (x86_64)
in this way:

- Start vhost-user-blk or QSD (same commands for all systems)

  vhost-user-blk -s /tmp/vhost.socket \
    -b Fedora-Cloud-Base-39-1.5.x86_64.raw

  qemu-storage-daemon \
    --blockdev file,filename=Fedora-Cloud-Base-39-1.5.x86_64.qcow2,node-name=file \
    --blockdev qcow2,file=file,node-name=qcow2 \
    --export vhost-user-blk,addr.type=unix,addr.path=/tmp/vhost.socket,id=vub,num-queues=1,node-name=qcow2,writable=on

- macOS (aarch64): start QEMU (using hvf accelerator)

  qemu-system-aarch64 -smp 2 -cpu host -M virt,accel=hvf,memory-backend=mem \
    -drive file=./build/pc-bios/edk2-aarch64-code.fd,if=pflash,format=raw,readonly=on \
    -device virtio-net-device,netdev=net0 -netdev user,id=net0 \
    -device ramfb -device usb-ehci -device usb-kbd \
    -object memory-backend-shm,id=mem,size=512M \
    -device vhost-user-blk-pci,num-queues=1,disable-legacy=on,chardev=char0 \
    -chardev socket,id=char0,path=/tmp/vhost.socket

- FreeBSD/OpenBSD (x86_64): start QEMU (no accelerators available)

  qemu-system-x86_64 -smp 2 -M q35,memory-backend=mem \
    -object memory-backend-shm,id=mem,size="512M" \
    -device vhost-user-blk-pci,num-queues=1,chardev=char0 \
    -chardev socket,id=char0,path=/tmp/vhost.socket

- Fedora (x86_64): start QEMU (using kvm accelerator)

  qemu-system-x86_64 -smp 2 -M q35,accel=kvm,memory-backend=mem \
    -object memory-backend-shm,size="512M" \
    -device vhost-user-blk-pci,num-queues=1,chardev=char0 \
    -chardev socket,id=char0,path=/tmp/vhost.socket

Branch pushed (and CI started) at https://gitlab.com/sgarzarella/qemu/-/tree/macos-vhost-user?ref_type=heads

Thanks,
Stefano

Stefano Garzarella (12):
  libvhost-user: set msg.msg_control to NULL when it is empty
  libvhost-user: fail vu_message_write() if sendmsg() is failing
  libvhost-user: mask F_INFLIGHT_SHMFD if memfd is not supported
  vhost-user-server: do not set memory fd non-blocking
  contrib/vhost-user-blk: fix bind() using the right size of the address
  contrib/vhost-user-*: use QEMU bswap helper functions
  vhost-user: enable frontends on any POSIX system
  libvhost-user: enable it on any POSIX system
  contrib/vhost-user-blk: enable it on any POSIX system
  hostmem: add a new memory backend based on POSIX shm_open()
  tests/qtest/vhost-user-blk-test: use memory-backend-shm
  tests/qtest/vhost-user-test: add a test case for memory-backend-shm

 docs/system/devices/vhost-user.rst        |   5 +-
 meson.build                               |   5 +-
 qapi/qom.json                             |  19 ++++
 subprojects/libvhost-user/libvhost-user.h |   2 +-
 backends/hostmem-shm.c                    | 123 ++++++++++++++++++++++
 contrib/vhost-user-blk/vhost-user-blk.c   |  27 +++--
 contrib/vhost-user-input/main.c           |  16 +--
 hw/net/vhost_net.c                        |   5 +
 subprojects/libvhost-user/libvhost-user.c |  77 +++++++++++++-
 tests/qtest/vhost-user-blk-test.c         |   2 +-
 tests/qtest/vhost-user-test.c             |  23 ++++
 util/vhost-user-server.c                  |  12 +++
 backends/meson.build                      |   1 +
 hw/block/Kconfig                          |   2 +-
 qemu-options.hx                           |  16 +++
 util/meson.build                          |   4 +-
 16 files changed, 311 insertions(+), 28 deletions(-)
 create mode 100644 backends/hostmem-shm.c

-- 
2.45.1



^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2024-06-04 13:30 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-28 10:35 [PATCH v6 00/12] vhost-user: support any POSIX system (tested on macOS, FreeBSD, OpenBSD) Stefano Garzarella
2024-05-28 10:35 ` [PATCH v6 01/12] libvhost-user: set msg.msg_control to NULL when it is empty Stefano Garzarella
2024-05-28 10:35 ` [PATCH v6 02/12] libvhost-user: fail vu_message_write() if sendmsg() is failing Stefano Garzarella
2024-05-28 10:35 ` [PATCH v6 03/12] libvhost-user: mask F_INFLIGHT_SHMFD if memfd is not supported Stefano Garzarella
2024-05-28 10:35 ` [PATCH v6 04/12] vhost-user-server: do not set memory fd non-blocking Stefano Garzarella
2024-05-28 10:35 ` [PATCH v6 05/12] contrib/vhost-user-blk: fix bind() using the right size of the address Stefano Garzarella
2024-05-28 10:35 ` [PATCH v6 06/12] contrib/vhost-user-*: use QEMU bswap helper functions Stefano Garzarella
2024-05-28 10:35 ` [PATCH v6 07/12] vhost-user: enable frontends on any POSIX system Stefano Garzarella
2024-05-28 10:35 ` [PATCH v6 08/12] libvhost-user: enable it " Stefano Garzarella
2024-05-28 10:38 ` [PATCH v6 09/12] contrib/vhost-user-blk: " Stefano Garzarella
2024-05-28 10:38 ` [PATCH v6 10/12] hostmem: add a new memory backend based on POSIX shm_open() Stefano Garzarella
2024-05-29 14:50   ` Markus Armbruster
2024-05-29 15:07     ` Stefano Garzarella
2024-06-03  9:42       ` Markus Armbruster
2024-06-04 13:29         ` Stefano Garzarella
2024-05-28 10:38 ` [PATCH v6 11/12] tests/qtest/vhost-user-blk-test: use memory-backend-shm Stefano Garzarella
2024-05-28 10:38 ` [PATCH v6 12/12] tests/qtest/vhost-user-test: add a test case for memory-backend-shm Stefano Garzarella
2024-05-28 12:40   ` Philippe Mathieu-Daudé

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).