From: "Michael S. Tsirkin" <mst@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Peter Maydell" <peter.maydell@linaro.org>,
"Stefano Garzarella" <sgarzare@redhat.com>,
"Philippe Mathieu-Daudé" <philmd@linaro.org>,
"Stefan Hajnoczi" <stefanha@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Marc-André Lureau" <marcandre.lureau@redhat.com>,
"Daniel P. Berrangé" <berrange@redhat.com>,
"Thomas Huth" <thuth@redhat.com>
Subject: [PULL 54/91] libvhost-user: enable it on any POSIX system
Date: Tue, 2 Jul 2024 10:09:41 -0400 [thread overview]
Message-ID: <800a3dfe84bb922f27156451007ed3e2e3b8abdb.1719929191.git.mst@redhat.com> (raw)
In-Reply-To: <cover.1719929191.git.mst@redhat.com>
From: Stefano Garzarella <sgarzare@redhat.com>
The vhost-user protocol is not really Linux-specific so let's enable
libvhost-user for any POSIX system.
Compiling it on macOS and FreeBSD some problems came up:
- avoid to include linux/vhost.h which is available only on Linux
(vhost_types.h contains many of the things we need)
- macOS doesn't provide sys/endian.h, so let's define them
(note: libvhost-user doesn't include QEMU's headers, so we can't use
use "qemu/bswap.h")
- define eventfd_[write|read] as write/read wrapper when system doesn't
provide those (e.g. macOS)
- copy SEAL defines from include/qemu/memfd.h to make the code works
on FreeBSD where MFD_ALLOW_SEALING is defined
- define MAP_NORESERVE if it's not defined (e.g. on FreeBSD)
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Tested-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
Message-Id: <20240618100503.145768-1-sgarzare@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
subprojects/libvhost-user/libvhost-user.h | 2 +-
subprojects/libvhost-user/libvhost-user.c | 60 +++++++++++++++++++++--
meson.build | 2 +-
3 files changed, 59 insertions(+), 5 deletions(-)
diff --git a/subprojects/libvhost-user/libvhost-user.h b/subprojects/libvhost-user/libvhost-user.h
index deb40e77b3..e13e1d3931 100644
--- a/subprojects/libvhost-user/libvhost-user.h
+++ b/subprojects/libvhost-user/libvhost-user.h
@@ -18,9 +18,9 @@
#include <stdbool.h>
#include <stddef.h>
#include <poll.h>
-#include <linux/vhost.h>
#include <pthread.h>
#include "standard-headers/linux/virtio_ring.h"
+#include "standard-headers/linux/vhost_types.h"
/* Based on qemu/hw/virtio/vhost-user.c */
#define VHOST_USER_F_PROTOCOL_FEATURES 30
diff --git a/subprojects/libvhost-user/libvhost-user.c b/subprojects/libvhost-user/libvhost-user.c
index 9c630c2170..d855a97a4c 100644
--- a/subprojects/libvhost-user/libvhost-user.c
+++ b/subprojects/libvhost-user/libvhost-user.c
@@ -28,9 +28,7 @@
#include <inttypes.h>
#include <sys/types.h>
#include <sys/socket.h>
-#include <sys/eventfd.h>
#include <sys/mman.h>
-#include <endian.h>
/* Necessary to provide VIRTIO_F_VERSION_1 on system
* with older linux headers. Must appear before
@@ -39,8 +37,8 @@
#include "standard-headers/linux/virtio_config.h"
#if defined(__linux__)
+#include <endian.h>
#include <sys/syscall.h>
-#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/vhost.h>
#include <sys/vfs.h>
@@ -52,6 +50,62 @@
#endif
+#if defined(__APPLE__) && (__MACH__)
+#include <libkern/OSByteOrder.h>
+#define htobe16(x) OSSwapHostToBigInt16(x)
+#define htole16(x) OSSwapHostToLittleInt16(x)
+#define be16toh(x) OSSwapBigToHostInt16(x)
+#define le16toh(x) OSSwapLittleToHostInt16(x)
+
+#define htobe32(x) OSSwapHostToBigInt32(x)
+#define htole32(x) OSSwapHostToLittleInt32(x)
+#define be32toh(x) OSSwapBigToHostInt32(x)
+#define le32toh(x) OSSwapLittleToHostInt32(x)
+
+#define htobe64(x) OSSwapHostToBigInt64(x)
+#define htole64(x) OSSwapHostToLittleInt64(x)
+#define be64toh(x) OSSwapBigToHostInt64(x)
+#define le64toh(x) OSSwapLittleToHostInt64(x)
+#endif
+
+#ifdef CONFIG_EVENTFD
+#include <sys/eventfd.h>
+#else
+#define eventfd_t uint64_t
+
+int eventfd_write(int fd, eventfd_t value)
+{
+ return (write(fd, &value, sizeof(value)) == sizeof(value)) ? 0 : -1;
+}
+
+int eventfd_read(int fd, eventfd_t *value)
+{
+ return (read(fd, value, sizeof(*value)) == sizeof(*value)) ? 0 : -1;
+}
+#endif
+
+#ifdef MFD_ALLOW_SEALING
+#include <fcntl.h>
+
+#ifndef F_LINUX_SPECIFIC_BASE
+#define F_LINUX_SPECIFIC_BASE 1024
+#endif
+
+#ifndef F_ADD_SEALS
+#define F_ADD_SEALS (F_LINUX_SPECIFIC_BASE + 9)
+#define F_GET_SEALS (F_LINUX_SPECIFIC_BASE + 10)
+
+#define F_SEAL_SEAL 0x0001 /* prevent further seals from being set */
+#define F_SEAL_SHRINK 0x0002 /* prevent file from shrinking */
+#define F_SEAL_GROW 0x0004 /* prevent file from growing */
+#define F_SEAL_WRITE 0x0008 /* prevent writes */
+#endif
+#endif
+
+#ifndef MAP_NORESERVE
+#define MAP_NORESERVE 0
+#endif
+
#include "include/atomic.h"
#include "libvhost-user.h"
diff --git a/meson.build b/meson.build
index 98db5ea322..6c1a489cc0 100644
--- a/meson.build
+++ b/meson.build
@@ -3203,7 +3203,7 @@ if have_system and vfio_user_server_allowed
endif
vhost_user = not_found
-if host_os == 'linux' and have_vhost_user
+if have_vhost_user
libvhost_user = subproject('libvhost-user')
vhost_user = libvhost_user.get_variable('vhost_user_dep')
endif
--
MST
next prev parent reply other threads:[~2024-07-02 14:17 UTC|newest]
Thread overview: 94+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-02 14:06 [PULL 00/91] virtio: features,fixes Michael S. Tsirkin
2024-07-02 14:06 ` [PULL 01/91] vhost: dirty log should be per backend type Michael S. Tsirkin
2024-07-02 14:07 ` [PULL 02/91] vhost: Perform memory section dirty scans once per iteration Michael S. Tsirkin
2024-07-02 14:07 ` [PULL 03/91] vhost-vdpa: check vhost_vdpa_set_vring_ready() return value Michael S. Tsirkin
2024-07-02 14:07 ` [PULL 04/91] virtio/virtio-pci: Handle extra notification data Michael S. Tsirkin
2024-07-02 14:07 ` [PULL 05/91] virtio: Prevent creation of device using notification-data with ioeventfd Michael S. Tsirkin
2024-07-02 14:07 ` [PULL 06/91] virtio-mmio: Handle extra notification data Michael S. Tsirkin
2024-07-02 14:07 ` [PULL 07/91] virtio-ccw: " Michael S. Tsirkin
2024-07-02 14:07 ` [PULL 08/91] vhost/vhost-user: Add VIRTIO_F_NOTIFICATION_DATA to vhost feature bits Michael S. Tsirkin
2024-07-02 14:07 ` [PULL 09/91] Fix vhost user assertion when sending more than one fd Michael S. Tsirkin
2024-07-02 14:07 ` [PULL 10/91] vhost-vsock: add VIRTIO_F_RING_PACKED to feature_bits Michael S. Tsirkin
2024-07-02 14:07 ` [PULL 11/91] hw/virtio: Fix obtain the buffer id from the last descriptor Michael S. Tsirkin
2024-07-02 14:07 ` [PULL 12/91] virtio-pci: only reset pm state during resetting Michael S. Tsirkin
2024-07-02 14:07 ` [PULL 13/91] vhost-user-gpu: fix import of DMABUF Michael S. Tsirkin
2024-07-02 14:07 ` [PULL 14/91] Revert "vhost-user: fix lost reconnect" Michael S. Tsirkin
2024-07-02 14:07 ` [PULL 15/91] vhost-user: fix lost reconnect again Michael S. Tsirkin
2024-07-02 14:07 ` [PULL 16/91] hw/cxl/mailbox: change CCI cmd set structure to be a member, not a reference Michael S. Tsirkin
2024-07-02 14:07 ` [PULL 17/91] hw/cxl/mailbox: interface to add CCI commands to an existing CCI Michael S. Tsirkin
2024-07-02 14:07 ` [PULL 18/91] hw/cxl/cxl-mailbox-utils: Add dc_event_log_size field to output payload of identify memory device command Michael S. Tsirkin
2024-07-02 14:07 ` [PULL 19/91] hw/cxl/cxl-mailbox-utils: Add dynamic capacity region representative and mailbox command support Michael S. Tsirkin
2024-07-02 14:07 ` [PULL 20/91] include/hw/cxl/cxl_device: Rename mem_size as static_mem_size for type3 memory devices Michael S. Tsirkin
2024-07-02 14:08 ` [PULL 21/91] hw/mem/cxl_type3: Add support to create DC regions to " Michael S. Tsirkin
2024-07-02 14:08 ` [PULL 22/91] hw/mem/cxl-type3: Refactor ct3_build_cdat_entries_for_mr to take mr size instead of mr as argument Michael S. Tsirkin
2024-07-02 14:08 ` [PULL 23/91] hw/mem/cxl_type3: Add host backend and address space handling for DC regions Michael S. Tsirkin
2024-07-02 14:08 ` [PULL 24/91] hw/mem/cxl_type3: Add DC extent list representative and get DC extent list mailbox support Michael S. Tsirkin
2024-07-02 14:08 ` [PULL 25/91] hw/cxl/cxl-mailbox-utils: Add mailbox commands to support add/release dynamic capacity response Michael S. Tsirkin
2024-07-02 14:08 ` [PULL 26/91] hw/cxl/events: Add qmp interfaces to add/release dynamic capacity extents Michael S. Tsirkin
2024-07-02 14:08 ` [PULL 27/91] hw/mem/cxl_type3: Add DPA range validation for accesses to DC regions Michael S. Tsirkin
2024-07-02 14:08 ` [PULL 28/91] hw/cxl/cxl-mailbox-utils: Add superset extent release mailbox support Michael S. Tsirkin
2024-07-02 14:08 ` [PULL 29/91] hw/mem/cxl_type3: Allow to release extent superset in QMP interface Michael S. Tsirkin
2024-07-02 14:08 ` [PULL 30/91] linux-headers: update to 6.10-rc1 Michael S. Tsirkin
2024-07-02 14:08 ` [PULL 31/91] hw/misc/pvpanic: centralize definition of supported events Michael S. Tsirkin
2024-07-02 14:08 ` [PULL 32/91] tests/qtest/pvpanic: use centralized " Michael S. Tsirkin
2024-07-02 14:08 ` [PULL 33/91] hw/misc/pvpanic: add support for normal shutdowns Michael S. Tsirkin
2024-07-02 14:08 ` [PULL 34/91] pvpanic: Emit GUEST_PVSHUTDOWN QMP event on pvpanic shutdown signal Michael S. Tsirkin
2024-07-02 14:08 ` [PULL 35/91] tests/qtest/pvpanic: add tests for pvshutdown event Michael S. Tsirkin
2024-07-02 14:08 ` [PULL 36/91] Revert "docs/specs/pvpanic: mark shutdown event as not implemented" Michael S. Tsirkin
2024-07-02 14:08 ` [PULL 37/91] virtio-pci: Fix the failure process in kvm_virtio_pci_vector_use_one() Michael S. Tsirkin
2024-07-02 14:08 ` [PULL 38/91] hw/cxl: Fix read from bogus memory Michael S. Tsirkin
2024-07-02 14:08 ` [PULL 39/91] virtio-pci: implement No_Soft_Reset bit Michael S. Tsirkin
2024-07-02 14:09 ` [PULL 40/91] vhost-user-test: don't set call fd -1 non-blocking Michael S. Tsirkin
2024-07-02 14:09 ` [PULL 41/91] i386/apic: Add hint on boot failure because of disabling x2APIC Michael S. Tsirkin
2024-07-02 14:09 ` [PULL 42/91] hw/virtio: Free vqs after vhost_dev_cleanup() Michael S. Tsirkin
2024-07-02 14:09 ` [PULL 43/91] virtio-iommu: add error check before assert Michael S. Tsirkin
2024-07-02 14:09 ` [PULL 44/91] vhost-user: Skip unnecessary duplicated VHOST_USER_SET_LOG_BASE requests Michael S. Tsirkin
2024-07-02 14:09 ` [PULL 45/91] hw/net/virtio-net.c: fix crash in iov_copy() Michael S. Tsirkin
2024-07-02 14:09 ` [PULL 46/91] qapi: clarify that the default is backend dependent Michael S. Tsirkin
2024-07-02 14:09 ` [PULL 47/91] libvhost-user: set msg.msg_control to NULL when it is empty Michael S. Tsirkin
2024-07-02 14:09 ` [PULL 48/91] libvhost-user: fail vu_message_write() if sendmsg() is failing Michael S. Tsirkin
2024-07-02 14:09 ` [PULL 49/91] libvhost-user: mask F_INFLIGHT_SHMFD if memfd is not supported Michael S. Tsirkin
2024-07-02 14:09 ` [PULL 50/91] vhost-user-server: do not set memory fd non-blocking Michael S. Tsirkin
2024-07-02 14:09 ` [PULL 51/91] contrib/vhost-user-blk: fix bind() using the right size of the address Michael S. Tsirkin
2024-07-02 14:09 ` [PULL 52/91] contrib/vhost-user-*: use QEMU bswap helper functions Michael S. Tsirkin
2024-07-02 14:09 ` [PULL 53/91] vhost-user: enable frontends on any POSIX system Michael S. Tsirkin
2024-07-02 14:09 ` Michael S. Tsirkin [this message]
2024-07-02 14:09 ` [PULL 55/91] contrib/vhost-user-blk: enable it " Michael S. Tsirkin
2024-07-02 14:09 ` [PULL 56/91] hostmem: add a new memory backend based on POSIX shm_open() Michael S. Tsirkin
2024-07-02 14:09 ` [PULL 57/91] tests/qtest/vhost-user-blk-test: use memory-backend-shm Michael S. Tsirkin
2024-07-02 14:09 ` [PULL 58/91] tests/qtest/vhost-user-test: add a test case for memory-backend-shm Michael S. Tsirkin
2024-07-02 14:10 ` [PULL 59/91] hw/virtio: Fix the de-initialization of vhost-user devices Michael S. Tsirkin
2024-07-02 14:10 ` [PULL 60/91] hw/arm/virt-acpi-build: Drop local iort_node_offset Michael S. Tsirkin
2024-07-02 14:10 ` [PULL 61/91] hw/i386/fw_cfg: Add etc/e820 to fw_cfg late Michael S. Tsirkin
2024-07-02 14:10 ` [PULL 62/91] hw/arm/virt-acpi-build: Fix id_count in build_iort_id_mapping Michael S. Tsirkin
2024-07-02 14:10 ` [PULL 63/91] uefi-test-tools/UefiTestToolsPkg: Add RISC-V support Michael S. Tsirkin
2024-07-02 14:10 ` [PULL 64/91] uefi-test-tools: Add support for python based build script Michael S. Tsirkin
2024-07-02 14:10 ` [PULL 65/91] tests/data/uefi-boot-images: Add RISC-V ISO image Michael S. Tsirkin
2024-07-02 14:10 ` [PULL 66/91] qtest: bios-tables-test: Rename aarch64 tests with aarch64 in them Michael S. Tsirkin
2024-07-02 14:10 ` [PULL 67/91] tests/qtest/bios-tables-test.c: Add support for arch in path Michael S. Tsirkin
2024-07-02 14:10 ` [PULL 68/91] tests/qtest/bios-tables-test.c: Set "arch" for aarch64 tests Michael S. Tsirkin
2024-07-02 14:10 ` [PULL 69/91] tests/qtest/bios-tables-test.c: Set "arch" for x86 tests Michael S. Tsirkin
2024-07-02 14:10 ` [PULL 70/91] tests/data/acpi: Move x86 ACPI tables under x86/${machine} path Michael S. Tsirkin
2024-07-02 14:10 ` [PULL 71/91] tests/data/acpi/virt: Move ARM64 ACPI tables under aarch64/${machine} path Michael S. Tsirkin
2024-07-02 14:10 ` [PULL 72/91] meson.build: Add RISC-V to the edk2-target list Michael S. Tsirkin
2024-07-02 14:10 ` [PULL 73/91] pc-bios/meson.build: Add support for RISC-V in unpack_edk2_blobs Michael S. Tsirkin
2024-07-02 14:10 ` [PULL 74/91] tests/data/acpi/rebuild-expected-aml.sh: Add RISC-V Michael S. Tsirkin
2024-07-02 14:10 ` [PULL 75/91] tests/qtest/bios-tables-test: Add empty ACPI data files for RISC-V Michael S. Tsirkin
2024-07-02 14:10 ` [PULL 76/91] tests/qtest/bios-tables-test.c: Enable basic testing " Michael S. Tsirkin
2024-07-02 14:10 ` [PULL 77/91] tests/qtest/bios-tables-test: Add expected ACPI data files " Michael S. Tsirkin
2024-07-02 14:11 ` [PULL 78/91] hw/cxl/events: Improve QMP interfaces and documentation for add/release dynamic capacity Michael S. Tsirkin
2024-07-02 14:11 ` [PULL 79/91] hw/cxl/events: Mark cxl-add-dynamic-capacity and cxl-release-dynamic-capcity unstable Michael S. Tsirkin
2024-07-02 14:11 ` [PULL 80/91] virtio: remove virtio_tswap16s() call in vring_packed_event_read() Michael S. Tsirkin
2024-07-02 14:11 ` [PULL 81/91] virtio-iommu: Clear IOMMUDevice when VFIO device is unplugged Michael S. Tsirkin
2024-07-02 14:11 ` [PULL 82/91] hw/pci: Rename has_power to enabled Michael S. Tsirkin
2024-07-02 14:11 ` [PULL 83/91] hw/ppc/spapr_pci: Do not create DT for disabled PCI device Michael S. Tsirkin
2024-07-02 14:11 ` [PULL 84/91] hw/ppc/spapr_pci: Do not reject VFs created after a PF Michael S. Tsirkin
2024-07-02 14:11 ` [PULL 85/91] pcie_sriov: Do not manually unrealize Michael S. Tsirkin
2024-07-02 14:11 ` [PULL 86/91] pcie_sriov: Ensure VF function number does not overflow Michael S. Tsirkin
2024-07-02 14:11 ` [PULL 87/91] pcie_sriov: Reuse SR-IOV VF device instances Michael S. Tsirkin
2024-07-02 14:11 ` [PULL 88/91] pcie_sriov: Release VFs failed to realize Michael S. Tsirkin
2024-07-02 14:11 ` [PULL 89/91] pcie_sriov: Remove num_vfs from PCIESriovPF Michael S. Tsirkin
2024-07-02 14:11 ` [PULL 90/91] pcie_sriov: Register VFs after migration Michael S. Tsirkin
2024-07-02 14:11 ` [PULL 91/91] hw/pci: Replace -1 with UINT32_MAX for romsize Michael S. Tsirkin
2024-07-02 14:35 ` [PULL 00/91] virtio: features,fixes Michael S. Tsirkin
2024-07-02 15:25 ` Michael S. Tsirkin
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=800a3dfe84bb922f27156451007ed3e2e3b8abdb.1719929191.git.mst@redhat.com \
--to=mst@redhat.com \
--cc=berrange@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=philmd@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=sgarzare@redhat.com \
--cc=stefanha@redhat.com \
--cc=thuth@redhat.com \
/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).