From nobody Fri Nov 7 10:27:13 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1547573754815888.5885814531739; Tue, 15 Jan 2019 09:35:54 -0800 (PST) Received: from localhost ([127.0.0.1]:57326 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gjScz-0004CB-Ml for importer@patchew.org; Tue, 15 Jan 2019 12:35:53 -0500 Received: from eggs.gnu.org ([209.51.188.92]:56120) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gjSaq-0002kC-Ag for qemu-devel@nongnu.org; Tue, 15 Jan 2019 12:33:42 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gjSao-0007oY-Fd for qemu-devel@nongnu.org; Tue, 15 Jan 2019 12:33:40 -0500 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]:34834) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gjSao-0007l1-78 for qemu-devel@nongnu.org; Tue, 15 Jan 2019 12:33:38 -0500 Received: by mail-wr1-x444.google.com with SMTP id 96so3948289wrb.2 for ; Tue, 15 Jan 2019 09:33:32 -0800 (PST) Received: from 640k.lan ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id n9sm62982018wrx.80.2019.01.15.09.33.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 15 Jan 2019 09:33:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/eWr4k9J6YIScFX2CNKzOt7DFaAd1BW9ZdrQ4vBatOQ=; b=fG/X9j+VmC7GxWn86zeuJou9cfRNhWI8y9vw/fp461+XL0xz/vOQ7LoCYR4lJfJ+0y OXqYlvP2jptQTWHAfJCM2Nd708l8Nkj7vGPakLzjs+g0KG14s9EWRX3wx2XQseCKfHVl zRTpkJnQ8/WfDrvxAv6o6BEdVoCZ11/uEbVTlQ0lbZwz4jj/Qn38MF+sXtxmpGXCJS7J 2BSDoGNycZSYIWmZMLj/Dgsw5Nq0k3GtTjWr971cwC4qqZ91WhPP/qg3o/OTNDckBESf iUjWac1N0AZKuMXTrYH3kZ2SP8F2Mf9ZXEuOrDYXucYCyj4Ks+2luSNk96dwHdPwKMDd N7VQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=/eWr4k9J6YIScFX2CNKzOt7DFaAd1BW9ZdrQ4vBatOQ=; b=qSKfdVDsz+vXFfIW9ohglvPNpf9ny1S00I991W6W//QoWLNwzQOiDJ+Df//JSHxuWU 7X8AlOB3J7QuhDkObtKmQaZpMClHZYxs1ToDrFnWrw1ZL70KMYq1AMRRT9WNII6rG3zC uMYQoqbr3H51MeiEZkg0wUzlZGw1LI9YiJBWbIyM48ewVhqJTzzTNciVMHtdBqzlKgqQ wlzscaMNFrWNnjjP0PdyB+AzENsX4ZppspQUBGpOG3DZ2wgjw0X7hUbZ4AsdWF0Lr9DU WB0uI7fYjiwHQpMkPOYGkA5A2xLPm2o2Ghd519T3sFTlnYcipFk8pRl0gxSRc5utRd+1 dlzw== X-Gm-Message-State: AJcUukeLo6eDKAc0KgpgiJMVsmQR54zVL0ieKu6Teb+9YhXpB9QG8Mw7 mnb1OLkvgpexk+cvmP6QK49dgS/A X-Google-Smtp-Source: ALg8bN4rCPqCw4e4JYqH+9sy2KmM+yZ2TDBR/iQhhYjhhQU7mqUfEj7LF8h0492j2Ub6zKa1NXIG8g== X-Received: by 2002:a5d:6b81:: with SMTP id n1mr4334040wrx.149.1547573611205; Tue, 15 Jan 2019 09:33:31 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Tue, 15 Jan 2019 18:33:23 +0100 Message-Id: <1547573605-25711-4-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1547573605-25711-1-git-send-email-pbonzini@redhat.com> References: <1547573605-25711-1-git-send-email-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::444 Subject: [Qemu-devel] [PATCH 3/5] vhost: restrict Linux dependency to kernel vhost X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: philmd@redhat.com, mst@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) vhost-user does not depend on Linux; it can run on any POSIX system. Restr= ict vhost-kernel to Linux in hw/virtio/vhost-backend.c, everything else can be compiled on all POSIX systems. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Thomas Huth Message-Id: <1543851204-41186-4-git-send-email-pbonzini@redhat.com> Signed-off-by: Paolo Bonzini --- backends/Makefile.objs | 5 ++--- default-configs/virtio.mak | 4 ++-- hw/net/vhost_net.c | 3 +-- hw/virtio/Makefile.objs | 5 +++-- hw/virtio/vhost-backend.c | 12 ++++++++++-- hw/virtio/vhost-user.c | 13 ++++++++++++- hw/virtio/vhost.c | 2 +- 7 files changed, 31 insertions(+), 13 deletions(-) diff --git a/backends/Makefile.objs b/backends/Makefile.objs index 717fcbd..ff619d3 100644 --- a/backends/Makefile.objs +++ b/backends/Makefile.objs @@ -9,10 +9,9 @@ common-obj-$(CONFIG_POSIX) +=3D hostmem-file.o common-obj-y +=3D cryptodev.o common-obj-y +=3D cryptodev-builtin.o =20 -ifeq ($(CONFIG_VIRTIO),y) +ifeq ($(CONFIG_VIRTIO_CRYPTO),y) common-obj-y +=3D cryptodev-vhost.o -common-obj-$(call land,$(CONFIG_VHOST_USER),$(CONFIG_LINUX)) +=3D \ - cryptodev-vhost-user.o +common-obj-$(CONFIG_VHOST_CRYPTO) +=3D cryptodev-vhost-user.o endif =20 common-obj-$(CONFIG_LINUX) +=3D hostmem-memfd.o diff --git a/default-configs/virtio.mak b/default-configs/virtio.mak index 1304849..340050a 100644 --- a/default-configs/virtio.mak +++ b/default-configs/virtio.mak @@ -1,5 +1,5 @@ -CONFIG_VHOST_USER_SCSI=3D$(call land,$(CONFIG_VHOST_USER),$(CONFIG_LINUX)) -CONFIG_VHOST_USER_BLK=3D$(call land,$(CONFIG_VHOST_USER),$(CONFIG_LINUX)) +CONFIG_VHOST_USER_SCSI=3D$(CONFIG_VHOST_USER) +CONFIG_VHOST_USER_BLK=3D$(CONFIG_VHOST_USER) CONFIG_VIRTIO=3Dy CONFIG_VIRTIO_9P=3Dy CONFIG_VIRTIO_BALLOON=3Dy diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index 2a300ee..ae3ca23 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -18,14 +18,13 @@ #include "net/tap.h" #include "net/vhost-user.h" =20 +#include "standard-headers/linux/vhost_types.h" #include "hw/virtio/virtio-net.h" #include "net/vhost_net.h" #include "qemu/error-report.h" =20 =20 -#include #include -#include #include #include #include diff --git a/hw/virtio/Makefile.objs b/hw/virtio/Makefile.objs index 1b2799c..e8eff80 100644 --- a/hw/virtio/Makefile.objs +++ b/hw/virtio/Makefile.objs @@ -9,9 +9,10 @@ obj-$(CONFIG_VIRTIO_BALLOON) +=3D virtio-balloon.o obj-$(CONFIG_VIRTIO_CRYPTO) +=3D virtio-crypto.o obj-$(call land,$(CONFIG_VIRTIO_CRYPTO),$(CONFIG_VIRTIO_PCI)) +=3D virtio-= crypto-pci.o =20 -obj-$(CONFIG_LINUX) +=3D vhost.o vhost-backend.o vhost-user.o +obj-$(CONFIG_VHOST_USER) +=3D vhost-user.o obj-$(CONFIG_VHOST_VSOCK) +=3D vhost-vsock.o +obj-$(call lor,$(CONFIG_VHOST_USER),$(CONFIG_LINUX)) +=3D vhost.o vhost-ba= ckend.o +common-obj-$(call lnot,$(call lor,$(CONFIG_VHOST_USER),$(CONFIG_LINUX))) += =3D vhost-stub.o endif =20 -common-obj-$(call lnot,$(call land,$(CONFIG_VIRTIO),$(CONFIG_LINUX))) +=3D= vhost-stub.o common-obj-$(CONFIG_ALL) +=3D vhost-stub.o diff --git a/hw/virtio/vhost-backend.c b/hw/virtio/vhost-backend.c index 7f09efa..e0f0bb7 100644 --- a/hw/virtio/vhost-backend.c +++ b/hw/virtio/vhost-backend.c @@ -9,11 +9,14 @@ */ =20 #include "qemu/osdep.h" -#include -#include #include "hw/virtio/vhost.h" #include "hw/virtio/vhost-backend.h" #include "qemu/error-report.h" +#include "standard-headers/linux/vhost_types.h" + +#ifdef CONFIG_LINUX +#include +#include =20 static int vhost_kernel_call(struct vhost_dev *dev, unsigned long int requ= est, void *arg) @@ -265,18 +268,23 @@ static const VhostOps kernel_ops =3D { .vhost_set_iotlb_callback =3D vhost_kernel_set_iotlb_callback, .vhost_send_device_iotlb_msg =3D vhost_kernel_send_device_iotlb_ms= g, }; +#endif =20 int vhost_set_backend_type(struct vhost_dev *dev, VhostBackendType backend= _type) { int r =3D 0; =20 switch (backend_type) { +#ifdef CONFIG_LINUX case VHOST_BACKEND_TYPE_KERNEL: dev->vhost_ops =3D &kernel_ops; break; +#endif +#ifdef CONFIG_VHOST_USER case VHOST_BACKEND_TYPE_USER: dev->vhost_ops =3D &user_ops; break; +#endif default: error_report("Unknown vhost backend type"); r =3D -1; diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index e09bed0..836bca5 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -27,8 +27,12 @@ #include #include #include -#include + +#include "standard-headers/linux/vhost_types.h" + +#ifdef CONFIG_LINUX #include +#endif =20 #define VHOST_MEMORY_MAX_NREGIONS 8 #define VHOST_USER_F_PROTOCOL_FEATURES 30 @@ -1110,6 +1114,7 @@ out: return ret; } =20 +#ifdef CONFIG_LINUX /* * Called back from the postcopy fault thread when a fault is received on = our * ufd. @@ -1177,6 +1182,7 @@ static int vhost_user_postcopy_waker(struct PostCopyF= D *pcfd, RAMBlock *rb, trace_vhost_user_postcopy_waker_nomatch(qemu_ram_get_idstr(rb), offset= ); return 0; } +#endif =20 /* * Called at the start of an inbound postcopy on reception of the @@ -1184,6 +1190,7 @@ static int vhost_user_postcopy_waker(struct PostCopyF= D *pcfd, RAMBlock *rb, */ static int vhost_user_postcopy_advise(struct vhost_dev *dev, Error **errp) { +#ifdef CONFIG_LINUX struct vhost_user *u =3D dev->opaque; CharBackend *chr =3D u->user->chr; int ufd; @@ -1227,6 +1234,10 @@ static int vhost_user_postcopy_advise(struct vhost_d= ev *dev, Error **errp) u->postcopy_fd.idstr =3D "vhost-user"; /* Need to find unique name */ postcopy_register_shared_ufd(&u->postcopy_fd); return 0; +#else + error_setg(errp, "Postcopy not supported on non-Linux systems"); + return -1; +#endif } =20 /* diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 569c405..311432f 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -21,7 +21,7 @@ #include "qemu/range.h" #include "qemu/error-report.h" #include "qemu/memfd.h" -#include +#include "standard-headers/linux/vhost_types.h" #include "exec/address-spaces.h" #include "hw/virtio/virtio-bus.h" #include "hw/virtio/virtio-access.h" --=20 1.8.3.1