From nobody Tue Nov 26 08:32:09 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=1709120993; cv=none; d=zohomail.com; s=zohoarc; b=KaVncjYYG2hxXgkgt+1KjOCgMR5JikcjBxyGw3yE0/YM6a3h7ZS8ST0tXQZxh00l/1iCzpqPa4jfZ+hKRg+89qszVd1OMfnnyqQ+0tAbBFAJwiNtexbsxLczIK33uXkukLGhwefdBkA97UBVvgkP2wQwXKRqwMICHb1E4ks1iQQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709120993; 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=KwzcXy+YqtjSTOiLxTxsvP3DT1VDsjM8bZULtaq2AAU=; b=jxlAviO9hDSKqcNjQ7nUIO6VJcjMiaOEWTRyUbpbM/lsgsW8wYza1AewsZ5GO6W82b9/XbD9TWRjP98TxBGCUh0BCD5Apyy63+VhgYO+sO2oV5PUZ5uBWx1h2s/pBt5Nf6CrL2leiDlUyF0Ig3Vu0UDc2C5kuzMOnQAzRfRnuc4= 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 1709120993435920.3575317917179; Wed, 28 Feb 2024 03:49:53 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfIQr-0004GB-5Y; Wed, 28 Feb 2024 06:49:05 -0500 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 1rfIQp-0004BH-O4 for qemu-devel@nongnu.org; Wed, 28 Feb 2024 06:49:03 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rfIQn-0003uQ-Ov for qemu-devel@nongnu.org; Wed, 28 Feb 2024 06:49:03 -0500 Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-176-soCxqwNvPvK5q08SrLlMlg-1; Wed, 28 Feb 2024 06:48:58 -0500 Received: by mail-qv1-f70.google.com with SMTP id 6a1803df08f44-68f71d9992cso72057186d6.2 for ; Wed, 28 Feb 2024 03:48:58 -0800 (PST) Received: from step1.redhat.com (host-82-57-51-64.retail.telecomitalia.it. [82.57.51.64]) by smtp.gmail.com with ESMTPSA id lv4-20020a056214578400b0068f9c181fc0sm4715254qvb.113.2024.02.28.03.48.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 03:48:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709120939; 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=KwzcXy+YqtjSTOiLxTxsvP3DT1VDsjM8bZULtaq2AAU=; b=FPzF6xteeQe3Fn9pLbdDdZr/tio8qh3+FHJqDaYBt4wRU2fmHBMhcxkk8FSOO50QYkyJnd ndww0HtwQt5FvJJQ8mU70baa/oFeYkMn5EhU8D3wbVl0KjzvAr/BILu1+snVyVw9wZasP5 h2FfHpd86Ye05QGVkKQc9dbiAZJYK6I= X-MC-Unique: soCxqwNvPvK5q08SrLlMlg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709120938; x=1709725738; 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=KwzcXy+YqtjSTOiLxTxsvP3DT1VDsjM8bZULtaq2AAU=; b=pf3BL9fmp0sSFgD85Ta8RYSbl96UbqoRj0Djicsr3/yRKhxfWh4q6OwSu4OREPFSsl 00QB/qTZwBv0o8eBw8q9f2uakIXOKakh+UHjcVWZXSJlJRLeiBmWislYeRKXxR4WuEAs 7+da9dEYc26oI75ui8LnYjw/AxR7rulx0OMAbOzXU0c2feqzMjDOmYjpQkkYCZ/BjOMZ J4JOWgZWCNWNcXXqGmwh1fL92omK3WU58FnKZPH7fet+uqba1slDCNgNeArrTskDVI/5 dqBJ1YFY8N40wLGgX+a3C9nKeCCsOkppm9J22XeSHuPGlc3eLbCBjHgOXpNwyfgF3Gou CH+w== X-Gm-Message-State: AOJu0YzMJXA73LFz4O5aWuDHmq0iWqkSId2bHvfF9GyDRc9iLpV2+KaE lXsDlkklei4uERMyEZHV2PV2i3tFqRNPFUpWogKHg92OwDRj0V87lCSbYZq0IOl52ZJv+pjbSyR YtdQi/upm3DEXUSnpJGtnA83xEaMFkwx8zxiu5nr1FIRS2M8gQzYL1QIInwUrqWQE/Tj4dauBfj q50+bMM+Rlgkv9ofcCGZPF0JyCO5WBPxe2JXXB X-Received: by 2002:a0c:f012:0:b0:68f:74f3:d571 with SMTP id z18-20020a0cf012000000b0068f74f3d571mr5024394qvk.16.1709120937771; Wed, 28 Feb 2024 03:48:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IFtr6Qgec/Mncv/nO92N5SUo8bcRvvFkpwWX0mQZ3OXmX7lo/S7vhT1vTI8cTTv+GKik+MVDw== X-Received: by 2002:a0c:f012:0:b0:68f:74f3:d571 with SMTP id z18-20020a0cf012000000b0068f74f3d571mr5024354qvk.16.1709120937213; Wed, 28 Feb 2024 03:48:57 -0800 (PST) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: Paolo Bonzini , qemu-block@nongnu.org, =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Thomas Huth , "Michael S. Tsirkin" , Jason Wang , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Markus Armbruster , Eric Blake , Coiby Xu , slp@redhat.com, Eduardo Habkost , Hanna Reitz , Igor Mammedov , Raphael Norwitz , Kevin Wolf , David Hildenbrand , stefanha@redhat.com, gmaglione@redhat.com, Stefano Garzarella Subject: [PATCH 7/9] libvhost-user: enable it on any POSIX system Date: Wed, 28 Feb 2024 12:47:57 +0100 Message-ID: <20240228114759.44758-8-sgarzare@redhat.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240228114759.44758-1-sgarzare@redhat.com> References: <20240228114759.44758-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.133.124; envelope-from=sgarzare@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.102, 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, T_SCC_BODY_TEXT_LINE=-0.01 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: 1709120993879100003 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 --- 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 462f2d7593..af15178969 100644 --- a/meson.build +++ b/meson.build @@ -3188,7 +3188,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 c2352904f0..e684b999b4 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 5da8de838b..1075fd3147 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 =20 @@ -50,6 +48,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.43.2