From nobody Mon Nov 25 09:24:05 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=1716476264; cv=none; d=zohomail.com; s=zohoarc; b=cyz1K3y27gB8EcNqtwR+JVEDbXUilsI9E3/i42w/4oVyqF8Ikmd27dbX4IYUwQNOFS5uCZ1ifIzsHtYeTJDosfUr937H2qA7+CrO1PIkYOMasq5KVLOvqSlEzyc0Sj1N8FFDMI3XmDisIcY4VsdKY3OpGUmJFrgTxlGsgqSKTbY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716476264; 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=ed87FKKG9Cqt1GwYddqrz8W/sjzd+H8eONgekNTejbo=; b=Vte/3bI92hEySkoMy9KCjSUmmTJ7JJL98d7/ixSYRsXqRYiT2ZZ4/HQ85gzvZMsvP287LRlQ1lC5KVaOhtVE8wFLXWGnj6WtU0muRLtgltX545PlcES2Ioyeh168Av4oa/EG6CHNhYDBj0SWSCUDpAp6PReMVqj1+wijiJQX+1Q= 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 1716476264104584.284180004537; Thu, 23 May 2024 07:57:44 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sA9s7-00031j-RV; Thu, 23 May 2024 10:56:47 -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 1sA9s4-00030c-VP for qemu-devel@nongnu.org; Thu, 23 May 2024 10:56:44 -0400 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 1sA9s0-00043E-QD for qemu-devel@nongnu.org; Thu, 23 May 2024 10:56:44 -0400 Received: from mail-oo1-f69.google.com (mail-oo1-f69.google.com [209.85.161.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-354-DzeDc88yP4WBruWdu44NVA-1; Thu, 23 May 2024 10:56:39 -0400 Received: by mail-oo1-f69.google.com with SMTP id 006d021491bc7-5b27fcd20ebso1526087eaf.1 for ; Thu, 23 May 2024 07:56:38 -0700 (PDT) Received: from step1.redhat.com (host-79-53-30-109.retail.telecomitalia.it. [79.53.30.109]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6ab840e24eesm15842686d6.135.2024.05.23.07.56.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 May 2024 07:56:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716476200; 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=ed87FKKG9Cqt1GwYddqrz8W/sjzd+H8eONgekNTejbo=; b=HfxUAllZPGHl3whgv5YUq//NUnuq2tnnvNGFx/dns3UPlzNlEuh0r2Eq5fXd2p+ZkcTMMk g1eCqgognrvzHqGhzQ+OKL+H0rD7AlXYHJnBT1oPVdBfcPkOqODfU5u0P12gfNjf8lqXUP yPtBkhpFAfcgLcvu5mTEGUuqLRSaSbA= X-MC-Unique: DzeDc88yP4WBruWdu44NVA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716476197; x=1717080997; 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=ed87FKKG9Cqt1GwYddqrz8W/sjzd+H8eONgekNTejbo=; b=jgPBzhEZ/4otFWGw1xWIBrm8TeUSG1xx4KyvCQ2gmDA5FlOIXQ+koayfnGFRIQAEwR qjppRsv0Qeb8S4dnvHx9F7wa4VlgImwCIbTRYPYQQsWq0Jsj5Uy9J0jdyEwj8Hes1LIB prpKCYmEtAPUNZih94VdNCqiAx2faWrQQTscImGm+A+vqF4Fr5t05ofbGmd2MhZpOlrg MUpOd3cy9UUi4dVWUB71dyj7BvRiHXISoDO3CNEQy4WzUPhA3ncy9t7utI7ihwA/171C xtr5uvnPcq01I9Kd8em5ZXFPtwpLz2hLJxF/PZU+0PBW46na7kqXjJb/l5ela8oNOt36 cVqg== X-Gm-Message-State: AOJu0Ywig0ivQV8QT1sHbk2DB6kJmE7tV1NPrFxLmfB1IyS5JpCZ+Im8 XCBuTnAFfn1UFfWu9ZV4p4ucR7HfAMQNJG4TTfNF9Zfukp167TdsEBBUfAEdR6B61W1p6RcITjH hUmwxLXAXiwZxq9K6h8GyZ1kE7tGku7TbHfxw1dKFAlhg6x6goadsbd0gxPhv2mpLzwaCqff9Q0 CUtryabwuM4aqFLUJme0kV/+8VUYHLOi3roCM7 X-Received: by 2002:a05:6358:a08:b0:192:8eec:3280 with SMTP id e5c5f4694b2df-1979213fd5amr401872355d.29.1716476196623; Thu, 23 May 2024 07:56:36 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHg8MltlA9GvC1ZpHWRCt5JxW7+kyPlmn9hVQ7/1VFxvoowgNrC3TzwYmjfT55P06G3gkn/7Q== X-Received: by 2002:a05:6358:a08:b0:192:8eec:3280 with SMTP id e5c5f4694b2df-1979213fd5amr401869455d.29.1716476196033; Thu, 23 May 2024 07:56:36 -0700 (PDT) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: Gerd Hoffmann , Eric Blake , Igor Mammedov , Paolo Bonzini , Laurent Vivier , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Brad Smith , "Michael S. Tsirkin" , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Coiby Xu , Markus Armbruster , David Hildenbrand , slp@redhat.com, Eduardo Habkost , stefanha@redhat.com, Hanna Reitz , Raphael Norwitz , Jason Wang , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Kevin Wolf , gmaglione@redhat.com, Thomas Huth , qemu-block@nongnu.org, Stefano Garzarella Subject: [PATCH v5 08/13] libvhost-user: enable it on any POSIX system Date: Thu, 23 May 2024 16:55:17 +0200 Message-ID: <20240523145522.313012-9-sgarzare@redhat.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240523145522.313012-1-sgarzare@redhat.com> References: <20240523145522.313012-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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=unavailable 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: 1716476264379100008 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=C3=A9 Tested-by: Philippe Mathieu-Daud=C3=A9 Acked-by: Stefan Hajnoczi Signed-off-by: Stefano Garzarella --- v5: - fixed typos in the commit description [Phil] --- 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 5a6f7a36eb..543105af2a 100644 --- a/meson.build +++ b/meson.build @@ -3155,7 +3155,7 @@ if have_system and vfio_user_server_allowed endif =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 2c20cdc16e..57e58d4adb 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.1