qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PULL 05/49] vhost: restrict Linux dependency to kernel vhost
Date: Mon, 21 Jan 2019 19:05:36 +0100	[thread overview]
Message-ID: <1548093980-43088-6-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1548093980-43088-1-git-send-email-pbonzini@redhat.com>

vhost-user does not depend on Linux; it can run on any POSIX system.  Restrict
vhost-kernel to Linux in hw/virtio/vhost-backend.c, everything else can be
compiled on all POSIX systems.

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Message-Id: <1543851204-41186-4-git-send-email-pbonzini@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 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) += hostmem-file.o
 common-obj-y += cryptodev.o
 common-obj-y += cryptodev-builtin.o
 
-ifeq ($(CONFIG_VIRTIO),y)
+ifeq ($(CONFIG_VIRTIO_CRYPTO),y)
 common-obj-y += cryptodev-vhost.o
-common-obj-$(call land,$(CONFIG_VHOST_USER),$(CONFIG_LINUX)) += \
-    cryptodev-vhost-user.o
+common-obj-$(CONFIG_VHOST_CRYPTO) += cryptodev-vhost-user.o
 endif
 
 common-obj-$(CONFIG_LINUX) += 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=$(call land,$(CONFIG_VHOST_USER),$(CONFIG_LINUX))
-CONFIG_VHOST_USER_BLK=$(call land,$(CONFIG_VHOST_USER),$(CONFIG_LINUX))
+CONFIG_VHOST_USER_SCSI=$(CONFIG_VHOST_USER)
+CONFIG_VHOST_USER_BLK=$(CONFIG_VHOST_USER)
 CONFIG_VIRTIO=y
 CONFIG_VIRTIO_9P=$(CONFIG_VIRTFS)
 CONFIG_VIRTIO_BALLOON=y
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"
 
+#include "standard-headers/linux/vhost_types.h"
 #include "hw/virtio/virtio-net.h"
 #include "net/vhost_net.h"
 #include "qemu/error-report.h"
 
 
-#include <linux/vhost.h>
 #include <sys/socket.h>
-#include <linux/kvm.h>
 #include <netpacket/packet.h>
 #include <net/ethernet.h>
 #include <net/if.h>
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 += virtio-bus.o
 obj-y += virtio.o
 
+obj-$(call lor,$(CONFIG_VHOST_USER),$(CONFIG_LINUX)) += vhost.o vhost-backend.o
+common-obj-$(call lnot,$(call lor,$(CONFIG_VHOST_USER),$(CONFIG_LINUX))) += vhost-stub.o
+obj-$(CONFIG_VHOST_USER) += vhost-user.o
+
 common-obj-$(CONFIG_VIRTIO_RNG) += virtio-rng.o
 common-obj-$(CONFIG_VIRTIO_PCI) += virtio-pci.o
 common-obj-$(CONFIG_VIRTIO_MMIO) += virtio-mmio.o
 obj-$(CONFIG_VIRTIO_BALLOON) += virtio-balloon.o
 obj-$(CONFIG_VIRTIO_CRYPTO) += virtio-crypto.o
 obj-$(call land,$(CONFIG_VIRTIO_CRYPTO),$(CONFIG_VIRTIO_PCI)) += virtio-crypto-pci.o
-
-obj-$(CONFIG_LINUX) += vhost.o vhost-backend.o vhost-user.o
 obj-$(CONFIG_VHOST_VSOCK) += vhost-vsock.o
+
 ifeq ($(CONFIG_PCI),y)
 obj-$(CONFIG_VHOST_VSOCK) += vhost-vsock-pci.o
 obj-$(CONFIG_VHOST_USER_BLK) += vhost-user-blk-pci.o
@@ -28,5 +31,4 @@ obj-$(CONFIG_VIRTIO_SERIAL) += virtio-serial-pci.o
 endif
 endif
 
-common-obj-$(call lnot,$(call land,$(CONFIG_VIRTIO),$(CONFIG_LINUX))) += vhost-stub.o
 common-obj-$(CONFIG_ALL) += 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 @@
  */
 
 #include "qemu/osdep.h"
-#include <linux/vhost.h>
-#include <sys/ioctl.h>
 #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 <linux/vhost.h>
+#include <sys/ioctl.h>
 
 static int vhost_kernel_call(struct vhost_dev *dev, unsigned long int request,
                              void *arg)
@@ -265,18 +268,23 @@ static const VhostOps kernel_ops = {
         .vhost_set_iotlb_callback = vhost_kernel_set_iotlb_callback,
         .vhost_send_device_iotlb_msg = vhost_kernel_send_device_iotlb_msg,
 };
+#endif
 
 int vhost_set_backend_type(struct vhost_dev *dev, VhostBackendType backend_type)
 {
     int r = 0;
 
     switch (backend_type) {
+#ifdef CONFIG_LINUX
     case VHOST_BACKEND_TYPE_KERNEL:
         dev->vhost_ops = &kernel_ops;
         break;
+#endif
+#ifdef CONFIG_VHOST_USER
     case VHOST_BACKEND_TYPE_USER:
         dev->vhost_ops = &user_ops;
         break;
+#endif
     default:
         error_report("Unknown vhost backend type");
         r = -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 <sys/ioctl.h>
 #include <sys/socket.h>
 #include <sys/un.h>
-#include <linux/vhost.h>
+
+#include "standard-headers/linux/vhost_types.h"
+
+#ifdef CONFIG_LINUX
 #include <linux/userfaultfd.h>
+#endif
 
 #define VHOST_MEMORY_MAX_NREGIONS    8
 #define VHOST_USER_F_PROTOCOL_FEATURES 30
@@ -1110,6 +1114,7 @@ out:
     return ret;
 }
 
+#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 PostCopyFD *pcfd, RAMBlock *rb,
     trace_vhost_user_postcopy_waker_nomatch(qemu_ram_get_idstr(rb), offset);
     return 0;
 }
+#endif
 
 /*
  * Called at the start of an inbound postcopy on reception of the
@@ -1184,6 +1190,7 @@ static int vhost_user_postcopy_waker(struct PostCopyFD *pcfd, RAMBlock *rb,
  */
 static int vhost_user_postcopy_advise(struct vhost_dev *dev, Error **errp)
 {
+#ifdef CONFIG_LINUX
     struct vhost_user *u = dev->opaque;
     CharBackend *chr = u->user->chr;
     int ufd;
@@ -1227,6 +1234,10 @@ static int vhost_user_postcopy_advise(struct vhost_dev *dev, Error **errp)
     u->postcopy_fd.idstr = "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
 }
 
 /*
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 <linux/vhost.h>
+#include "standard-headers/linux/vhost_types.h"
 #include "exec/address-spaces.h"
 #include "hw/virtio/virtio-bus.h"
 #include "hw/virtio/virtio-access.h"
-- 
1.8.3.1

  parent reply	other threads:[~2019-01-21 18:06 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-21 18:05 [Qemu-devel] [PULL 00/49] Misc patches for 2019-01-21 Paolo Bonzini
2019-01-21 18:05 ` [Qemu-devel] [PULL 01/49] scripts/update-linux-headers.sh: adjust for Linux 4.21-rc1 (or 5.0-rc1) Paolo Bonzini
2019-01-21 18:05 ` [Qemu-devel] [PULL 02/49] include: update Linux headers to 4.21-rc1/5.0-rc1 Paolo Bonzini
2019-01-21 18:05 ` [Qemu-devel] [PULL 03/49] vhost-net: move stubs to a separate file Paolo Bonzini
2019-01-21 18:05 ` [Qemu-devel] [PULL 04/49] vhost-net-user: add stubs for when no virtio-net device is present Paolo Bonzini
2019-01-21 18:05 ` Paolo Bonzini [this message]
2019-01-21 18:05 ` [Qemu-devel] [PULL 06/49] vhost-net: compile it on all targets that have virtio-net Paolo Bonzini
2019-01-21 18:05 ` [Qemu-devel] [PULL 07/49] vhost-net: revamp configure logic Paolo Bonzini
2019-01-21 18:05 ` [Qemu-devel] [PULL 08/49] vhost-user-test: use g_cond_broadcast Paolo Bonzini
2019-01-21 18:05 ` [Qemu-devel] [PULL 09/49] vhost-user-test: signal data_cond when s->rings changes Paolo Bonzini
2019-01-21 18:05 ` [Qemu-devel] [PULL 10/49] vhost-user: support cross-endian vnet headers Paolo Bonzini
2019-01-21 18:05 ` [Qemu-devel] [PULL 11/49] vhost-user-test: support VHOST_USER_PROTOCOL_F_CROSS_ENDIAN Paolo Bonzini
2019-01-21 18:05 ` [Qemu-devel] [PULL 12/49] vhost-user-test: skip if there is no memory at address 0 Paolo Bonzini
2019-01-21 18:05 ` [Qemu-devel] [PULL 13/49] vhost-user-test: reduce usage of global_qtest Paolo Bonzini
2019-01-21 18:05 ` [Qemu-devel] [PULL 14/49] vhost-user-test: create a main loop per TestServer Paolo Bonzini
2019-01-21 18:05 ` [Qemu-devel] [PULL 15/49] vhost-user-test: small changes to init_hugepagefs Paolo Bonzini
2019-01-21 18:05 ` [Qemu-devel] [PULL 16/49] vhost-user-test: create a temporary directory per TestServer Paolo Bonzini
2019-01-21 18:05 ` [Qemu-devel] [PULL 17/49] tap: flush STDOUT on newline Paolo Bonzini
2019-01-21 18:05 ` [Qemu-devel] [PULL 18/49] tests/hexloader-test: Don't pass -nographic to the QEMU under test Paolo Bonzini
2019-01-21 18:05 ` [Qemu-devel] [PULL 19/49] cpu-exec: add assert_no_pages_locked() after longjmp Paolo Bonzini
2019-01-21 18:05 ` [Qemu-devel] [PULL 20/49] cpu-exec: reset BQL after longjmp in cpu_exec_step_atomic Paolo Bonzini
2019-01-21 18:05 ` [Qemu-devel] [PULL 21/49] configure: Add a proper check for openpty() in libutil Paolo Bonzini
2019-01-21 18:05 ` [Qemu-devel] [PULL 22/49] cpus: ignore ESRCH in qemu_cpu_kick_thread() Paolo Bonzini
2019-01-21 18:05 ` [Qemu-devel] [PULL 23/49] elf: Add optional function ptr to load_elf() to parse ELF notes Paolo Bonzini
2019-01-21 18:05 ` [Qemu-devel] [PULL 24/49] elf-ops.h: Add get_elf_note_type() Paolo Bonzini
2019-01-21 18:05 ` [Qemu-devel] [PULL 25/49] pvh: Add x86/HVM direct boot ABI header file Paolo Bonzini
2019-01-21 18:05 ` [Qemu-devel] [PULL 26/49] pvh: Boot uncompressed kernel using direct boot ABI Paolo Bonzini
2019-01-21 18:05 ` [Qemu-devel] [PULL 27/49] pvh: load initrd and expose it through fw_cfg Paolo Bonzini
2019-01-21 18:05 ` [Qemu-devel] [PULL 28/49] linuxboot_dma: remove duplicate definitions of FW_CFG Paolo Bonzini
2019-01-21 18:06 ` [Qemu-devel] [PULL 29/49] linuxboot_dma: move common functions in a new header Paolo Bonzini
2019-01-21 18:06 ` [Qemu-devel] [PULL 30/49] hw/i386/pc: use PVH option rom Paolo Bonzini
2019-01-21 18:06 ` [Qemu-devel] [PULL 31/49] optionrom/pvh: load initrd from fw_cfg Paolo Bonzini
2019-01-21 18:06 ` [Qemu-devel] [PULL 32/49] i386: remove the new CPUID 'PCONFIG' from Icelake-Server CPU model Paolo Bonzini
2019-01-21 18:06 ` [Qemu-devel] [PULL 33/49] i386: remove the 'INTEL_PT' CPUID bit from named CPU models Paolo Bonzini
2019-01-21 18:06 ` [Qemu-devel] [PULL 34/49] Revert "i386: Add CPUID bit for PCONFIG" Paolo Bonzini
2019-01-21 18:06 ` [Qemu-devel] [PULL 35/49] target-i386: hvf: remove MPX support Paolo Bonzini
2019-01-21 18:06 ` [Qemu-devel] [PULL 36/49] contrib/elf2dmp: fix elf.h including Paolo Bonzini
2019-01-21 18:06 ` [Qemu-devel] [PULL 37/49] contrib/elf2dmp: use GLib in ELF processing Paolo Bonzini
2019-01-21 18:06 ` [Qemu-devel] [PULL 38/49] contrib/elf2dmp: use GLib in PDB processing Paolo Bonzini
2019-01-21 18:06 ` [Qemu-devel] [PULL 39/49] contrib/elf2dmp: fix structures definitions Paolo Bonzini
2019-01-21 18:06 ` [Qemu-devel] [PULL 41/49] configure: enable elf2dmp build for Windows hosts Paolo Bonzini
2019-01-21 18:06 ` [Qemu-devel] [PULL 42/49] monitor: do not use QTAILQ_FOREACH_SAFE across critical sections Paolo Bonzini
2019-01-21 18:06 ` [Qemu-devel] [PULL 43/49] crypto: finish removing TABs Paolo Bonzini
2019-01-21 18:06 ` [Qemu-devel] [PULL 44/49] ui: vnc: " Paolo Bonzini
2019-01-21 18:06 ` [Qemu-devel] [PULL 45/49] unify len and addr type for memory/address APIs Paolo Bonzini
2019-01-21 18:06 ` [Qemu-devel] [PULL 46/49] hw/core/loader.c: Read as long as possible in load_image_size() Paolo Bonzini
2019-01-21 18:06 ` [Qemu-devel] [PULL 47/49] i386: import & use bootparam.h Paolo Bonzini
2019-01-21 18:06 ` [Qemu-devel] [PULL 48/49] i386: allow to load initrd below 4 GB for recent linux Paolo Bonzini
2019-01-21 18:06 ` [Qemu-devel] [PULL 49/49] docker: disable Xen on CentOS 7 Paolo Bonzini
2019-01-24 12:07   ` Daniel P. Berrangé
2019-01-22 17:19 ` [Qemu-devel] [PULL 00/49] Misc patches for 2019-01-21 Peter Maydell
2019-01-23 11:06   ` Stefano Garzarella

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1548093980-43088-6-git-send-email-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).