From nobody Mon Nov 25 15:24:41 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1715154470; cv=none; d=zohomail.com; s=zohoarc; b=i4kFlLzpb35jQeGoFrWk4TrPpoFSKMXxreTWPLTYhEK6bRoSgAVn+FT+7mFGLTjN8TF9NgqulH9xBAA+VDM/FahE5f+DFBZlsGE4jabCteZGMeEi35FilJXSFOtxrkpg9JoLfQg0T8YCtTY10FS3V55on7xB4XN4OEAdkJ0wk2I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715154470; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=c2iLWpiAMoSh5bQUokPRhQNz1XWV7X7XRsP0hDRBa4c=; b=BAQcO0NcUDwbKjbBnIbyg4uvmxVCAwS49FoLo+skFXQ8KYKT4WUL0ep36LP5EEc7xEhofiERc9N5ByVhzjR5WTx0AjZVzqZkkaFUrFAvuxQVHMCt/KH4wZXPzZoHo5hYS/A0YKSICg10hQ9UfYsBtR5jfVyWeaL9gflrg+kZSjM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1715154470983917.9990978894672; Wed, 8 May 2024 00:47:50 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s4c0A-0004N5-V9; Wed, 08 May 2024 03:46:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s4bzz-0003w5-JU for qemu-devel@nongnu.org; Wed, 08 May 2024 03:45:59 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s4bzx-00011l-Rq for qemu-devel@nongnu.org; Wed, 08 May 2024 03:45:59 -0400 Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-595-pv2HmawDOVacDG6LKND-Fw-1; Wed, 08 May 2024 03:45:54 -0400 Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-a599dffe736so55481266b.1 for ; Wed, 08 May 2024 00:45:54 -0700 (PDT) Received: from localhost.localdomain (host-87-12-25-56.business.telecomitalia.it. [87.12.25.56]) by smtp.gmail.com with ESMTPSA id oy29-20020a170907105d00b00a59b077a70esm4689996ejb.2.2024.05.08.00.45.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 May 2024 00:45:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1715154355; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=c2iLWpiAMoSh5bQUokPRhQNz1XWV7X7XRsP0hDRBa4c=; b=fwdKopCWfuYDrx82Dhfyhf8pEY6jTuRITGlYiEMCRQQzYVnsNqG6YmyKRFJO1oSbOtXJMN 2oGp4S3fV8ywzD9WTRIEzmI1BWxh4oDSGciEIJl4TVC33scn+yp53HpAAIVPaBQ+Rfy3u0 afp9cjn8aNHzQTm+P9QHm0dHH4l8S8E= X-MC-Unique: pv2HmawDOVacDG6LKND-Fw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715154352; x=1715759152; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=c2iLWpiAMoSh5bQUokPRhQNz1XWV7X7XRsP0hDRBa4c=; b=VOPuXNn/lqo1jeAmelQgeZ+JMRG911I7mjZl0UPyKdRYuVhfdLQWd1kdKH+OTRq2AO VY+CvHvtwKsO9QjQeR0hk/dbOvSe7YUeTpC+q3gwTTRvQeuZC3P1RJVoGbiiuGGMtbPH WhS2L5rI6MEy5IfQThMZHowQyyt9ritB3QBtgVbAHAHaw02MzmOSsG1ffoY2N7t8nxKm uCK1XvAfoGlQDvGKdHcuPc14wxw4AdvysYdWzM1bkQjD4u5Gk3xSU3XxlrAh+do/rqp8 hqG9qf0Xu3uy3AsfnAoO3YRtL3bKWfw/MeiVtyLJ9itUuZZy17NNae68Yz0/15FGKUNl LmEw== X-Gm-Message-State: AOJu0YzWy6Itg4FyZ0LNCT/WW9GAii+KoBJG6uvjBbVqnseyC3WuAM4D WAdgMvPQkp+/rBnEmDvSffJ0ekUA+bC+XwTIcP53pPnze0mcH5b5Y0REn2ivqVdoCQsQOonGO4B 0kpLryOwMv5cfV+AfoYhfcCGu0BTTPETYnw4Co82V+3NTmULY9DHZv3XcVHd2mPSoMfuSDSFPf2 CRsC2aTONzjD8+5yRaq4U+4vwbSnlb0HiQsIe0 X-Received: by 2002:a17:906:498:b0:a59:9636:f3e with SMTP id a640c23a62f3a-a59e4e861a4mr407165366b.33.1715154352266; Wed, 08 May 2024 00:45:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFEHbvCtZ9hcsvG3a9DzMXNl9DxNDxD4G+5ADPgwPi0p6h0oawBgSnDwz8pL6CljHUwDaKxGA== X-Received: by 2002:a17:906:498:b0:a59:9636:f3e with SMTP id a640c23a62f3a-a59e4e861a4mr407161766b.33.1715154351754; Wed, 08 May 2024 00:45:51 -0700 (PDT) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: Jason Wang , Coiby Xu , Paolo Bonzini , qemu-block@nongnu.org, =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Gerd Hoffmann , slp@redhat.com, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Brad Smith , Eduardo Habkost , Thomas Huth , Eric Blake , Kevin Wolf , Markus Armbruster , Raphael Norwitz , gmaglione@redhat.com, Laurent Vivier , stefanha@redhat.com, David Hildenbrand , Hanna Reitz , "Michael S. Tsirkin" , Igor Mammedov , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Stefano Garzarella Subject: [PATCH v4 08/12] libvhost-user: enable it on any POSIX system Date: Wed, 8 May 2024 09:44:52 +0200 Message-ID: <20240508074457.12367-9-sgarzare@redhat.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240508074457.12367-1-sgarzare@redhat.com> References: <20240508074457.12367-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=sgarzare@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.581, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1715154472346100001 Content-Type: text/plain; charset="utf-8" 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 avaibale 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) Signed-off-by: Stefano Garzarella Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Philippe Mathieu-Daud=C3=A9 --- meson.build | 2 +- subprojects/libvhost-user/libvhost-user.h | 2 +- subprojects/libvhost-user/libvhost-user.c | 60 +++++++++++++++++++++-- 3 files changed, 59 insertions(+), 5 deletions(-) diff --git a/meson.build b/meson.build index 955921dcb8..7954da5971 100644 --- a/meson.build +++ b/meson.build @@ -3168,7 +3168,7 @@ endif config_host_data.set('CONFIG_FDT', fdt.found()) =20 vhost_user =3D not_found -if host_os =3D=3D 'linux' and have_vhost_user +if have_vhost_user libvhost_user =3D subproject('libvhost-user') vhost_user =3D libvhost_user.get_variable('vhost_user_dep') endif diff --git a/subprojects/libvhost-user/libvhost-user.h b/subprojects/libvho= st-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 #include #include -#include #include #include "standard-headers/linux/virtio_ring.h" +#include "standard-headers/linux/vhost_types.h" =20 /* 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/libvho= st-user/libvhost-user.c index 1c361ffd51..03edb4bf64 100644 --- a/subprojects/libvhost-user/libvhost-user.c +++ b/subprojects/libvhost-user/libvhost-user.c @@ -28,9 +28,7 @@ #include #include #include -#include #include -#include =20 /* 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" =20 #if defined(__linux__) +#include #include -#include #include #include #include @@ -52,6 +50,62 @@ =20 #endif =20 +#if defined(__APPLE__) && (__MACH__) +#include +#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 +#else +#define eventfd_t uint64_t + +int eventfd_write(int fd, eventfd_t value) +{ + return (write(fd, &value, sizeof(value)) =3D=3D sizeof(value)) ? 0 : -= 1; +} + +int eventfd_read(int fd, eventfd_t *value) +{ + return (read(fd, value, sizeof(*value)) =3D=3D sizeof(*value)) ? 0 : -= 1; +} +#endif + +#ifdef MFD_ALLOW_SEALING +#include + +#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" =20 #include "libvhost-user.h" --=20 2.45.0