From nobody Fri Nov 7 14:33:35 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 1548094649044412.43175042564667; Mon, 21 Jan 2019 10:17:29 -0800 (PST) Received: from localhost ([127.0.0.1]:57502 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gle8R-0004e8-MB for importer@patchew.org; Mon, 21 Jan 2019 13:17:23 -0500 Received: from eggs.gnu.org ([209.51.188.92]:51596) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gldy3-0004Ij-So for qemu-devel@nongnu.org; Mon, 21 Jan 2019 13:06:42 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gldy1-00043l-Lh for qemu-devel@nongnu.org; Mon, 21 Jan 2019 13:06:39 -0500 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]:36960) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gldxz-0003vh-Jr for qemu-devel@nongnu.org; Mon, 21 Jan 2019 13:06:37 -0500 Received: by mail-wm1-x343.google.com with SMTP id g67so11691690wmd.2 for ; Mon, 21 Jan 2019 10:06:29 -0800 (PST) Received: from 640k.lan ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id 133sm56197732wme.9.2019.01.21.10.06.26 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 21 Jan 2019 10:06:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Wd4wko6U5shAXhdr6xymCFjsDOwIikjQwYc8nu19xCc=; b=KjRY7ys91Ygyf4KFip2TJ3PXAmy5tHXWwmex/7MJN78JjG67cw9raofXvd8OQdJmzD yFo4CSCjnaLqpj+4oEYs8WCobOm2Zh/urt0WVaKqpyEpeXItzoQhcrduIrqfdqWer1gS 5NZubgJdSK3CgU+/gmRKDPC7Wh5NBm+dmWkJHY2tDPFGRptH/MH9qLsM5Ji+95qxbdYg chPrRTBqTluwhkUR4Yo7jHFBsf9yPP9+udB8vqYcmw0IfvwiyTPpBSXj6AshGDdqSTwk VZiKeXcP7Z+dqqBBpgwzLhEV9d2CzUAHVe7slPv2hXhS4oB4symv/u1mDBpIsbzUwK02 +BJw== 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:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=Wd4wko6U5shAXhdr6xymCFjsDOwIikjQwYc8nu19xCc=; b=rYBNw6EHvoOkI9PLsNy508+pGnkxSA6JYTwfy1XIcra56qBkHcWICkrWJCDHdgR7fd roeLgUMXi5ybNUR5XSfwasQF7fHtqB7NhBOAG/TCjgoo/Het8f0d+zYNr+0+W3NCX3py ksnL+21dLRTKjpwq1LUQg9Ie/5sQqdDhlMfsE9zgTyRR+6AoDHST/eduO9wCkFDGx1KW U88ndpBRKvyQR9bModbLwnfSTk8bFF0ORA7ud3Rm4RHNEnOcw6apSOS18OUf9tlGbPI1 T4Ne/97t26nzx2KRiVdXiNuYq4HgsrV2pWWyiyYUhxXsd3HNFXyApmShrJMjvC5PT9L5 Zl9A== X-Gm-Message-State: AJcUukdsbZ5kd9AH4H8mmUC9gcDrCYMwSqV5IGry+1zwTRKO65hpOK0r T9XE0F0/3AvEGybvZM+tgoUZc3+i X-Google-Smtp-Source: ALg8bN4y3FBVw0wCzzynXPkkMCXuchwTuEtBH87MHWMG1LYyE1xLCgQ/2toDSvtp2rBsK3ea9j5gmg== X-Received: by 2002:a1c:d00d:: with SMTP id h13mr408148wmg.13.1548093988062; Mon, 21 Jan 2019 10:06:28 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 21 Jan 2019 19:05:36 +0100 Message-Id: <1548093980-43088-6-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1548093980-43088-1-git-send-email-pbonzini@redhat.com> References: <1548093980-43088-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::343 Subject: [Qemu-devel] [PULL 05/49] 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: , 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 | 8 +++++--- hw/virtio/vhost-backend.c | 12 ++++++++++-- hw/virtio/vhost-user.c | 13 ++++++++++++- hw/virtio/vhost.c | 2 +- 7 files changed, 33 insertions(+), 14 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 ecb4420..b653aa0 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=3D$(CONFIG_VIRTFS) 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 ea7913d..d8685a1 100644 --- a/hw/virtio/Makefile.objs +++ b/hw/virtio/Makefile.objs @@ -2,15 +2,18 @@ ifeq ($(CONFIG_VIRTIO),y) common-obj-y +=3D virtio-bus.o obj-y +=3D virtio.o =20 +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 +obj-$(CONFIG_VHOST_USER) +=3D vhost-user.o + common-obj-$(CONFIG_VIRTIO_RNG) +=3D virtio-rng.o common-obj-$(CONFIG_VIRTIO_PCI) +=3D virtio-pci.o common-obj-$(CONFIG_VIRTIO_MMIO) +=3D virtio-mmio.o 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 - -obj-$(CONFIG_LINUX) +=3D vhost.o vhost-backend.o vhost-user.o obj-$(CONFIG_VHOST_VSOCK) +=3D vhost-vsock.o + ifeq ($(CONFIG_PCI),y) obj-$(CONFIG_VHOST_VSOCK) +=3D vhost-vsock-pci.o obj-$(CONFIG_VHOST_USER_BLK) +=3D vhost-user-blk-pci.o @@ -28,5 +31,4 @@ obj-$(CONFIG_VIRTIO_SERIAL) +=3D virtio-serial-pci.o endif 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 564a31d..0d6c64e 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