All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/8] libvhost-user: make it a subproject (was: "lower dependency on QEMU headers")
@ 2020-11-25 10:06 marcandre.lureau
  2020-11-25 10:06 ` [PATCH v2 1/8] libvhost-user: replace qemu/bswap.h with glibc endian.h marcandre.lureau
                   ` (7 more replies)
  0 siblings, 8 replies; 19+ messages in thread
From: marcandre.lureau @ 2020-11-25 10:06 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marc-André Lureau, Dr. David Alan Gilbert, Stefan Hajnoczi,
	Michael S. Tsirkin

From: Marc-André Lureau <marcandre.lureau@redhat.com>

Hi,

libvhost-user is meant to be free of glib dependency, and easily
copyable/reusable outside of QEMU. Clean-up some dependencies that crept in
recently (the one remaining is qemu/atomic.h, from which a subset is used)

v2:
- fix memfd flags argument (spotted by D. Gilbert)
- new patches to remove dependency from QEMU headers
- make it a standalone meson subproject
- check subproject build in gitlab CI (suggested by S. Hajnoczi)
- add some r-b tags

Marc-André Lureau (8):
  libvhost-user: replace qemu/bswap.h with glibc endian.h
  libvhost-user: replace qemu/memfd.h usage
  libvhost-user: remove qemu/compiler.h usage
  libvhost-user: drop qemu/osdep.h dependency
  libvhost-user: make it a meson subproject
  libvhost-user: check memfd API
  libvhost-user: add a simple link test without glib
  .gitlab-ci: add build-libvhost-user

 meson.build                                   |   7 +-
 contrib/vhost-user-gpu/vugpu.h                |   2 +-
 include/qemu/vhost-user-server.h              |   2 +-
 .../libvhost-user/libvhost-user-glib.h        |   0
 .../libvhost-user/libvhost-user.h             |   0
 block/export/vhost-user-blk-server.c          |   2 +-
 contrib/vhost-user-blk/vhost-user-blk.c       |   3 +-
 contrib/vhost-user-input/main.c               |   3 +-
 contrib/vhost-user-scsi/vhost-user-scsi.c     |   2 +-
 .../libvhost-user/libvhost-user-glib.c        |  10 +-
 .../libvhost-user/libvhost-user.c             | 126 +++++++++++-------
 subprojects/libvhost-user/link-test.c         |  45 +++++++
 tests/vhost-user-bridge.c                     |   2 +-
 tools/virtiofsd/fuse_virtio.c                 |   2 +-
 .gitlab-ci.yml                                |  11 ++
 contrib/libvhost-user/meson.build             |   4 -
 contrib/vhost-user-blk/meson.build            |   3 +-
 contrib/vhost-user-gpu/meson.build            |   3 +-
 contrib/vhost-user-input/meson.build          |   3 +-
 contrib/vhost-user-scsi/meson.build           |   3 +-
 subprojects/libvhost-user/meson.build         |  36 +++++
 tests/meson.build                             |   3 +-
 tools/virtiofsd/meson.build                   |   3 +-
 23 files changed, 201 insertions(+), 74 deletions(-)
 rename {contrib => subprojects}/libvhost-user/libvhost-user-glib.h (100%)
 rename {contrib => subprojects}/libvhost-user/libvhost-user.h (100%)
 rename {contrib => subprojects}/libvhost-user/libvhost-user-glib.c (93%)
 rename {contrib => subprojects}/libvhost-user/libvhost-user.c (96%)
 create mode 100644 subprojects/libvhost-user/link-test.c
 delete mode 100644 contrib/libvhost-user/meson.build
 create mode 100644 subprojects/libvhost-user/meson.build

-- 
2.29.0




^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH v2 1/8] libvhost-user: replace qemu/bswap.h with glibc endian.h
  2020-11-25 10:06 [PATCH v2 0/8] libvhost-user: make it a subproject (was: "lower dependency on QEMU headers") marcandre.lureau
@ 2020-11-25 10:06 ` marcandre.lureau
  2020-12-02 14:20   ` Stefan Hajnoczi
  2020-11-25 10:06 ` [PATCH v2 2/8] libvhost-user: replace qemu/memfd.h usage marcandre.lureau
                   ` (6 subsequent siblings)
  7 siblings, 1 reply; 19+ messages in thread
From: marcandre.lureau @ 2020-11-25 10:06 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marc-André Lureau, Dr. David Alan Gilbert, Stefan Hajnoczi,
	Michael S. Tsirkin

From: Marc-André Lureau <marcandre.lureau@redhat.com>

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 contrib/libvhost-user/libvhost-user.c | 77 ++++++++++++++-------------
 1 file changed, 40 insertions(+), 37 deletions(-)

diff --git a/contrib/libvhost-user/libvhost-user.c b/contrib/libvhost-user/libvhost-user.c
index 5c73ffdd6b..1c1cfbf1e7 100644
--- a/contrib/libvhost-user/libvhost-user.c
+++ b/contrib/libvhost-user/libvhost-user.c
@@ -26,6 +26,7 @@
 #include <sys/socket.h>
 #include <sys/eventfd.h>
 #include <sys/mman.h>
+#include <endian.h>
 #include "qemu/compiler.h"
 
 #if defined(__linux__)
@@ -42,7 +43,6 @@
 
 #include "qemu/atomic.h"
 #include "qemu/osdep.h"
-#include "qemu/bswap.h"
 #include "qemu/memfd.h"
 
 #include "libvhost-user.h"
@@ -1081,7 +1081,7 @@ vu_set_vring_addr_exec(VuDev *dev, VhostUserMsg *vmsg)
         return false;
     }
 
-    vq->used_idx = lduw_le_p(&vq->vring.used->idx);
+    vq->used_idx = le16toh(vq->vring.used->idx);
 
     if (vq->last_avail_idx != vq->used_idx) {
         bool resume = dev->iface->queue_is_processed_in_order &&
@@ -1198,7 +1198,7 @@ vu_check_queue_inflights(VuDev *dev, VuVirtq *vq)
         return 0;
     }
 
-    vq->used_idx = lduw_le_p(&vq->vring.used->idx);
+    vq->used_idx = le16toh(vq->vring.used->idx);
     vq->resubmit_num = 0;
     vq->resubmit_list = NULL;
     vq->counter = 0;
@@ -2031,13 +2031,13 @@ vu_queue_started(const VuDev *dev, const VuVirtq *vq)
 static inline uint16_t
 vring_avail_flags(VuVirtq *vq)
 {
-    return lduw_le_p(&vq->vring.avail->flags);
+    return le16toh(vq->vring.avail->flags);
 }
 
 static inline uint16_t
 vring_avail_idx(VuVirtq *vq)
 {
-    vq->shadow_avail_idx = lduw_le_p(&vq->vring.avail->idx);
+    vq->shadow_avail_idx = le16toh(vq->vring.avail->idx);
 
     return vq->shadow_avail_idx;
 }
@@ -2045,7 +2045,7 @@ vring_avail_idx(VuVirtq *vq)
 static inline uint16_t
 vring_avail_ring(VuVirtq *vq, int i)
 {
-    return lduw_le_p(&vq->vring.avail->ring[i]);
+    return le16toh(vq->vring.avail->ring[i]);
 }
 
 static inline uint16_t
@@ -2133,12 +2133,12 @@ virtqueue_read_next_desc(VuDev *dev, struct vring_desc *desc,
                          int i, unsigned int max, unsigned int *next)
 {
     /* If this descriptor says it doesn't chain, we're done. */
-    if (!(lduw_le_p(&desc[i].flags) & VRING_DESC_F_NEXT)) {
+    if (!(le16toh(desc[i].flags) & VRING_DESC_F_NEXT)) {
         return VIRTQUEUE_READ_DESC_DONE;
     }
 
     /* Check they're not leading us off end of descriptors. */
-    *next = lduw_le_p(&desc[i].next);
+    *next = le16toh(desc[i].next);
     /* Make sure compiler knows to grab that: we don't want it changing! */
     smp_wmb();
 
@@ -2181,8 +2181,8 @@ vu_queue_get_avail_bytes(VuDev *dev, VuVirtq *vq, unsigned int *in_bytes,
         }
         desc = vq->vring.desc;
 
-        if (lduw_le_p(&desc[i].flags) & VRING_DESC_F_INDIRECT) {
-            if (ldl_le_p(&desc[i].len) % sizeof(struct vring_desc)) {
+        if (le16toh(desc[i].flags) & VRING_DESC_F_INDIRECT) {
+            if (le32toh(desc[i].len) % sizeof(struct vring_desc)) {
                 vu_panic(dev, "Invalid size for indirect buffer table");
                 goto err;
             }
@@ -2195,8 +2195,8 @@ vu_queue_get_avail_bytes(VuDev *dev, VuVirtq *vq, unsigned int *in_bytes,
 
             /* loop over the indirect descriptor table */
             indirect = 1;
-            desc_addr = ldq_le_p(&desc[i].addr);
-            desc_len = ldl_le_p(&desc[i].len);
+            desc_addr = le64toh(desc[i].addr);
+            desc_len = le32toh(desc[i].len);
             max = desc_len / sizeof(struct vring_desc);
             read_len = desc_len;
             desc = vu_gpa_to_va(dev, &read_len, desc_addr);
@@ -2223,10 +2223,10 @@ vu_queue_get_avail_bytes(VuDev *dev, VuVirtq *vq, unsigned int *in_bytes,
                 goto err;
             }
 
-            if (lduw_le_p(&desc[i].flags) & VRING_DESC_F_WRITE) {
-                in_total += ldl_le_p(&desc[i].len);
+            if (le16toh(desc[i].flags) & VRING_DESC_F_WRITE) {
+                in_total += le32toh(desc[i].len);
             } else {
-                out_total += ldl_le_p(&desc[i].len);
+                out_total += le32toh(desc[i].len);
             }
             if (in_total >= max_in_bytes && out_total >= max_out_bytes) {
                 goto done;
@@ -2377,7 +2377,7 @@ vring_used_flags_set_bit(VuVirtq *vq, int mask)
 
     flags = (uint16_t *)((char*)vq->vring.used +
                          offsetof(struct vring_used, flags));
-    stw_le_p(flags, lduw_le_p(flags) | mask);
+    *flags = htole16(le16toh(*flags) | mask);
 }
 
 static inline void
@@ -2387,17 +2387,20 @@ vring_used_flags_unset_bit(VuVirtq *vq, int mask)
 
     flags = (uint16_t *)((char*)vq->vring.used +
                          offsetof(struct vring_used, flags));
-    stw_le_p(flags, lduw_le_p(flags) & ~mask);
+    *flags = htole16(le16toh(*flags) & ~mask);
 }
 
 static inline void
 vring_set_avail_event(VuVirtq *vq, uint16_t val)
 {
+    uint16_t *avail;
+
     if (!vq->notification) {
         return;
     }
 
-    stw_le_p(&vq->vring.used->ring[vq->vring.num], val);
+    avail = (uint16_t *)&vq->vring.used->ring[vq->vring.num];
+    *avail = htole16(val);
 }
 
 void
@@ -2487,15 +2490,15 @@ vu_queue_map_desc(VuDev *dev, VuVirtq *vq, unsigned int idx, size_t sz)
     struct vring_desc desc_buf[VIRTQUEUE_MAX_SIZE];
     int rc;
 
-    if (lduw_le_p(&desc[i].flags) & VRING_DESC_F_INDIRECT) {
-        if (ldl_le_p(&desc[i].len) % sizeof(struct vring_desc)) {
+    if (le16toh(desc[i].flags) & VRING_DESC_F_INDIRECT) {
+        if (le32toh(desc[i].len) % sizeof(struct vring_desc)) {
             vu_panic(dev, "Invalid size for indirect buffer table");
             return NULL;
         }
 
         /* loop over the indirect descriptor table */
-        desc_addr = ldq_le_p(&desc[i].addr);
-        desc_len = ldl_le_p(&desc[i].len);
+        desc_addr = le64toh(desc[i].addr);
+        desc_len = le32toh(desc[i].len);
         max = desc_len / sizeof(struct vring_desc);
         read_len = desc_len;
         desc = vu_gpa_to_va(dev, &read_len, desc_addr);
@@ -2517,11 +2520,11 @@ vu_queue_map_desc(VuDev *dev, VuVirtq *vq, unsigned int idx, size_t sz)
 
     /* Collect all the descriptors */
     do {
-        if (lduw_le_p(&desc[i].flags) & VRING_DESC_F_WRITE) {
+        if (le16toh(desc[i].flags) & VRING_DESC_F_WRITE) {
             if (!virtqueue_map_desc(dev, &in_num, iov + out_num,
                                VIRTQUEUE_MAX_SIZE - out_num, true,
-                               ldq_le_p(&desc[i].addr),
-                               ldl_le_p(&desc[i].len))) {
+                               le64toh(desc[i].addr),
+                               le32toh(desc[i].len))) {
                 return NULL;
             }
         } else {
@@ -2531,8 +2534,8 @@ vu_queue_map_desc(VuDev *dev, VuVirtq *vq, unsigned int idx, size_t sz)
             }
             if (!virtqueue_map_desc(dev, &out_num, iov,
                                VIRTQUEUE_MAX_SIZE, false,
-                               ldq_le_p(&desc[i].addr),
-                               ldl_le_p(&desc[i].len))) {
+                               le64toh(desc[i].addr),
+                               le32toh(desc[i].len))) {
                 return NULL;
             }
         }
@@ -2731,15 +2734,15 @@ vu_log_queue_fill(VuDev *dev, VuVirtq *vq,
     max = vq->vring.num;
     i = elem->index;
 
-    if (lduw_le_p(&desc[i].flags) & VRING_DESC_F_INDIRECT) {
-        if (ldl_le_p(&desc[i].len) % sizeof(struct vring_desc)) {
+    if (le16toh(desc[i].flags) & VRING_DESC_F_INDIRECT) {
+        if (le32toh(desc[i].len) % sizeof(struct vring_desc)) {
             vu_panic(dev, "Invalid size for indirect buffer table");
             return;
         }
 
         /* loop over the indirect descriptor table */
-        desc_addr = ldq_le_p(&desc[i].addr);
-        desc_len = ldl_le_p(&desc[i].len);
+        desc_addr = le64toh(desc[i].addr);
+        desc_len = le32toh(desc[i].len);
         max = desc_len / sizeof(struct vring_desc);
         read_len = desc_len;
         desc = vu_gpa_to_va(dev, &read_len, desc_addr);
@@ -2765,9 +2768,9 @@ vu_log_queue_fill(VuDev *dev, VuVirtq *vq,
             return;
         }
 
-        if (lduw_le_p(&desc[i].flags) & VRING_DESC_F_WRITE) {
-            min = MIN(ldl_le_p(&desc[i].len), len);
-            vu_log_write(dev, ldq_le_p(&desc[i].addr), min);
+        if (le16toh(desc[i].flags) & VRING_DESC_F_WRITE) {
+            min = MIN(le32toh(desc[i].len), len);
+            vu_log_write(dev, le64toh(desc[i].addr), min);
             len -= min;
         }
 
@@ -2792,15 +2795,15 @@ vu_queue_fill(VuDev *dev, VuVirtq *vq,
 
     idx = (idx + vq->used_idx) % vq->vring.num;
 
-    stl_le_p(&uelem.id, elem->index);
-    stl_le_p(&uelem.len, len);
+    uelem.id = htole32(elem->index);
+    uelem.len = htole32(len);
     vring_used_write(dev, vq, &uelem, idx);
 }
 
 static inline
 void vring_used_idx_set(VuDev *dev, VuVirtq *vq, uint16_t val)
 {
-    stw_le_p(&vq->vring.used->idx, val);
+    vq->vring.used->idx = htole16(val);
     vu_log_write(dev,
                  vq->vring.log_guest_addr + offsetof(struct vring_used, idx),
                  sizeof(vq->vring.used->idx));
-- 
2.29.0



^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v2 2/8] libvhost-user: replace qemu/memfd.h usage
  2020-11-25 10:06 [PATCH v2 0/8] libvhost-user: make it a subproject (was: "lower dependency on QEMU headers") marcandre.lureau
  2020-11-25 10:06 ` [PATCH v2 1/8] libvhost-user: replace qemu/bswap.h with glibc endian.h marcandre.lureau
@ 2020-11-25 10:06 ` marcandre.lureau
  2020-12-02 14:20   ` Stefan Hajnoczi
  2020-11-25 10:06 ` [PATCH v2 3/8] libvhost-user: remove qemu/compiler.h usage marcandre.lureau
                   ` (5 subsequent siblings)
  7 siblings, 1 reply; 19+ messages in thread
From: marcandre.lureau @ 2020-11-25 10:06 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marc-André Lureau, Dr. David Alan Gilbert, Stefan Hajnoczi,
	Michael S. Tsirkin

From: Marc-André Lureau <marcandre.lureau@redhat.com>

Undo the damage from commit 5f9ff1eff3 ("libvhost-user: Support tracking
inflight I/O in shared memory") which introduced glib dependency through
osdep.h inclusion.

libvhost-user.c tries to stay free from glib usage.

Use glibc memfd_create directly when available (assumed so when
MFD_ALLOW_SEALING is defined). A following commit will make the project
standalone and check for memfd API at configure time, instead of a
panic at runtime.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 contrib/libvhost-user/libvhost-user.c | 50 +++++++++++++++++++++++----
 1 file changed, 43 insertions(+), 7 deletions(-)

diff --git a/contrib/libvhost-user/libvhost-user.c b/contrib/libvhost-user/libvhost-user.c
index 1c1cfbf1e7..54aabd1878 100644
--- a/contrib/libvhost-user/libvhost-user.c
+++ b/contrib/libvhost-user/libvhost-user.c
@@ -42,8 +42,6 @@
 #endif
 
 #include "qemu/atomic.h"
-#include "qemu/osdep.h"
-#include "qemu/memfd.h"
 
 #include "libvhost-user.h"
 
@@ -1615,11 +1613,45 @@ vu_inflight_queue_size(uint16_t queue_size)
            sizeof(uint16_t), INFLIGHT_ALIGNMENT);
 }
 
+#ifdef MFD_ALLOW_SEALING
+static void *
+memfd_alloc(const char *name, size_t size, unsigned int flags, int *fd)
+{
+    void *ptr;
+    int ret;
+
+    *fd = memfd_create(name, MFD_ALLOW_SEALING);
+    if (*fd < 0) {
+        return NULL;
+    }
+
+    ret = ftruncate(*fd, size);
+    if (ret < 0) {
+        close(*fd);
+        return NULL;
+    }
+
+    ret = fcntl(*fd, F_ADD_SEALS, flags);
+    if (ret < 0) {
+        close(*fd);
+        return NULL;
+    }
+
+    ptr = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, *fd, 0);
+    if (ptr == MAP_FAILED) {
+        close(*fd);
+        return NULL;
+    }
+
+    return ptr;
+}
+#endif
+
 static bool
 vu_get_inflight_fd(VuDev *dev, VhostUserMsg *vmsg)
 {
-    int fd;
-    void *addr;
+    int fd = -1;
+    void *addr = NULL;
     uint64_t mmap_size;
     uint16_t num_queues, queue_size;
 
@@ -1637,9 +1669,13 @@ vu_get_inflight_fd(VuDev *dev, VhostUserMsg *vmsg)
 
     mmap_size = vu_inflight_queue_size(queue_size) * num_queues;
 
-    addr = qemu_memfd_alloc("vhost-inflight", mmap_size,
-                            F_SEAL_GROW | F_SEAL_SHRINK | F_SEAL_SEAL,
-                            &fd, NULL);
+#ifdef MFD_ALLOW_SEALING
+    addr = memfd_alloc("vhost-inflight", mmap_size,
+                       F_SEAL_GROW | F_SEAL_SHRINK | F_SEAL_SEAL,
+                       &fd);
+#else
+    vu_panic(dev, "Not implemented: memfd support is missing");
+#endif
 
     if (!addr) {
         vu_panic(dev, "Failed to alloc vhost inflight area");
-- 
2.29.0



^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v2 3/8] libvhost-user: remove qemu/compiler.h usage
  2020-11-25 10:06 [PATCH v2 0/8] libvhost-user: make it a subproject (was: "lower dependency on QEMU headers") marcandre.lureau
  2020-11-25 10:06 ` [PATCH v2 1/8] libvhost-user: replace qemu/bswap.h with glibc endian.h marcandre.lureau
  2020-11-25 10:06 ` [PATCH v2 2/8] libvhost-user: replace qemu/memfd.h usage marcandre.lureau
@ 2020-11-25 10:06 ` marcandre.lureau
  2020-12-02 14:20   ` Stefan Hajnoczi
  2020-11-25 10:06 ` [PATCH v2 4/8] libvhost-user: drop qemu/osdep.h dependency marcandre.lureau
                   ` (4 subsequent siblings)
  7 siblings, 1 reply; 19+ messages in thread
From: marcandre.lureau @ 2020-11-25 10:06 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marc-André Lureau, Dr. David Alan Gilbert, Stefan Hajnoczi,
	Michael S. Tsirkin

From: Marc-André Lureau <marcandre.lureau@redhat.com>

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 contrib/libvhost-user/libvhost-user.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/contrib/libvhost-user/libvhost-user.c b/contrib/libvhost-user/libvhost-user.c
index 54aabd1878..fab7ca17ee 100644
--- a/contrib/libvhost-user/libvhost-user.c
+++ b/contrib/libvhost-user/libvhost-user.c
@@ -27,7 +27,6 @@
 #include <sys/eventfd.h>
 #include <sys/mman.h>
 #include <endian.h>
-#include "qemu/compiler.h"
 
 #if defined(__linux__)
 #include <sys/syscall.h>
@@ -60,6 +59,10 @@
 /* Round number up to multiple */
 #define ALIGN_UP(n, m) ALIGN_DOWN((n) + (m) - 1, (m))
 
+#ifndef unlikely
+#define unlikely(x)   __builtin_expect(!!(x), 0)
+#endif
+
 /* Align each region to cache line size in inflight buffer */
 #define INFLIGHT_ALIGNMENT 64
 
-- 
2.29.0



^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v2 4/8] libvhost-user: drop qemu/osdep.h dependency
  2020-11-25 10:06 [PATCH v2 0/8] libvhost-user: make it a subproject (was: "lower dependency on QEMU headers") marcandre.lureau
                   ` (2 preceding siblings ...)
  2020-11-25 10:06 ` [PATCH v2 3/8] libvhost-user: remove qemu/compiler.h usage marcandre.lureau
@ 2020-11-25 10:06 ` marcandre.lureau
  2020-12-02 14:20   ` Stefan Hajnoczi
  2020-11-25 10:06 ` [PATCH v2 5/8] libvhost-user: make it a meson subproject marcandre.lureau
                   ` (3 subsequent siblings)
  7 siblings, 1 reply; 19+ messages in thread
From: marcandre.lureau @ 2020-11-25 10:06 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marc-André Lureau, Dr. David Alan Gilbert, Stefan Hajnoczi,
	Michael S. Tsirkin

From: Marc-André Lureau <marcandre.lureau@redhat.com>

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 contrib/libvhost-user/libvhost-user-glib.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/contrib/libvhost-user/libvhost-user-glib.c b/contrib/libvhost-user/libvhost-user-glib.c
index 0df2ec9271..efc9d814e3 100644
--- a/contrib/libvhost-user/libvhost-user-glib.c
+++ b/contrib/libvhost-user/libvhost-user-glib.c
@@ -12,10 +12,16 @@
  * later.  See the COPYING file in the top-level directory.
  */
 
-#include "qemu/osdep.h"
-
 #include "libvhost-user-glib.h"
 
+#ifndef container_of
+#define container_of(ptr, type, member)              \
+    __extension__({                                  \
+        void *__mptr = (void *)(ptr);                \
+        ((type *)(__mptr - offsetof(type, member))); \
+    })
+#endif
+
 /* glib event loop integration for libvhost-user and misc callbacks */
 
 G_STATIC_ASSERT((int)G_IO_IN == (int)VU_WATCH_IN);
-- 
2.29.0



^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v2 5/8] libvhost-user: make it a meson subproject
  2020-11-25 10:06 [PATCH v2 0/8] libvhost-user: make it a subproject (was: "lower dependency on QEMU headers") marcandre.lureau
                   ` (3 preceding siblings ...)
  2020-11-25 10:06 ` [PATCH v2 4/8] libvhost-user: drop qemu/osdep.h dependency marcandre.lureau
@ 2020-11-25 10:06 ` marcandre.lureau
  2020-12-02 14:25   ` Stefan Hajnoczi
  2020-11-25 10:06 ` [PATCH v2 6/8] libvhost-user: check memfd API marcandre.lureau
                   ` (2 subsequent siblings)
  7 siblings, 1 reply; 19+ messages in thread
From: marcandre.lureau @ 2020-11-25 10:06 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marc-André Lureau, Dr. David Alan Gilbert, Stefan Hajnoczi,
	Michael S. Tsirkin

From: Marc-André Lureau <marcandre.lureau@redhat.com>

By making libvhost-user a subproject, check it builds
standalone (without the global QEMU cflags etc).

Note that the library still relies on QEMU include/qemu/atomic.h and
linux_headers/.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 meson.build                                   |  7 ++++++-
 contrib/vhost-user-gpu/vugpu.h                |  2 +-
 include/qemu/vhost-user-server.h              |  2 +-
 .../libvhost-user/libvhost-user-glib.h        |  0
 .../libvhost-user/libvhost-user.h             |  0
 block/export/vhost-user-blk-server.c          |  2 +-
 contrib/vhost-user-blk/vhost-user-blk.c       |  3 +--
 contrib/vhost-user-input/main.c               |  3 +--
 contrib/vhost-user-scsi/vhost-user-scsi.c     |  2 +-
 .../libvhost-user/libvhost-user-glib.c        |  0
 .../libvhost-user/libvhost-user.c             |  0
 tests/vhost-user-bridge.c                     |  2 +-
 tools/virtiofsd/fuse_virtio.c                 |  2 +-
 contrib/libvhost-user/meson.build             |  4 ----
 contrib/vhost-user-blk/meson.build            |  3 +--
 contrib/vhost-user-gpu/meson.build            |  3 +--
 contrib/vhost-user-input/meson.build          |  3 +--
 contrib/vhost-user-scsi/meson.build           |  3 +--
 subprojects/libvhost-user/meson.build         | 20 +++++++++++++++++++
 tests/meson.build                             |  3 +--
 tools/virtiofsd/meson.build                   |  3 +--
 21 files changed, 40 insertions(+), 27 deletions(-)
 rename {contrib => subprojects}/libvhost-user/libvhost-user-glib.h (100%)
 rename {contrib => subprojects}/libvhost-user/libvhost-user.h (100%)
 rename {contrib => subprojects}/libvhost-user/libvhost-user-glib.c (100%)
 rename {contrib => subprojects}/libvhost-user/libvhost-user.c (100%)
 delete mode 100644 contrib/libvhost-user/meson.build
 create mode 100644 subprojects/libvhost-user/meson.build

diff --git a/meson.build b/meson.build
index 5062407c70..1b14998691 100644
--- a/meson.build
+++ b/meson.build
@@ -1476,7 +1476,12 @@ trace_events_subdirs += [
   'util',
 ]
 
-subdir('contrib/libvhost-user')
+vhost_user = not_found
+if 'CONFIG_VHOST_USER' in config_host
+  libvhost_user = subproject('libvhost-user')
+  vhost_user = libvhost_user.get_variable('vhost_user_dep')
+endif
+
 subdir('qapi')
 subdir('qobject')
 subdir('stubs')
diff --git a/contrib/vhost-user-gpu/vugpu.h b/contrib/vhost-user-gpu/vugpu.h
index 3153c9a6de..bdf9a74b46 100644
--- a/contrib/vhost-user-gpu/vugpu.h
+++ b/contrib/vhost-user-gpu/vugpu.h
@@ -17,7 +17,7 @@
 
 #include "qemu/osdep.h"
 
-#include "contrib/libvhost-user/libvhost-user-glib.h"
+#include "libvhost-user-glib.h"
 #include "standard-headers/linux/virtio_gpu.h"
 
 #include "qemu/queue.h"
diff --git a/include/qemu/vhost-user-server.h b/include/qemu/vhost-user-server.h
index 0da4c2cc4c..121ea1dedf 100644
--- a/include/qemu/vhost-user-server.h
+++ b/include/qemu/vhost-user-server.h
@@ -11,7 +11,7 @@
 #ifndef VHOST_USER_SERVER_H
 #define VHOST_USER_SERVER_H
 
-#include "contrib/libvhost-user/libvhost-user.h"
+#include "subprojects/libvhost-user/libvhost-user.h" /* only for the type definitions */
 #include "io/channel-socket.h"
 #include "io/channel-file.h"
 #include "io/net-listener.h"
diff --git a/contrib/libvhost-user/libvhost-user-glib.h b/subprojects/libvhost-user/libvhost-user-glib.h
similarity index 100%
rename from contrib/libvhost-user/libvhost-user-glib.h
rename to subprojects/libvhost-user/libvhost-user-glib.h
diff --git a/contrib/libvhost-user/libvhost-user.h b/subprojects/libvhost-user/libvhost-user.h
similarity index 100%
rename from contrib/libvhost-user/libvhost-user.h
rename to subprojects/libvhost-user/libvhost-user.h
diff --git a/block/export/vhost-user-blk-server.c b/block/export/vhost-user-blk-server.c
index 62672d1cb9..a3d95ca012 100644
--- a/block/export/vhost-user-blk-server.c
+++ b/block/export/vhost-user-blk-server.c
@@ -11,7 +11,7 @@
  */
 #include "qemu/osdep.h"
 #include "block/block.h"
-#include "contrib/libvhost-user/libvhost-user.h"
+#include "subprojects/libvhost-user/libvhost-user.h" /* only for the type definitions */
 #include "standard-headers/linux/virtio_blk.h"
 #include "qemu/vhost-user-server.h"
 #include "vhost-user-blk-server.h"
diff --git a/contrib/vhost-user-blk/vhost-user-blk.c b/contrib/vhost-user-blk/vhost-user-blk.c
index dc981bf945..6abd7835a8 100644
--- a/contrib/vhost-user-blk/vhost-user-blk.c
+++ b/contrib/vhost-user-blk/vhost-user-blk.c
@@ -17,8 +17,7 @@
 
 #include "qemu/osdep.h"
 #include "standard-headers/linux/virtio_blk.h"
-#include "contrib/libvhost-user/libvhost-user-glib.h"
-#include "contrib/libvhost-user/libvhost-user.h"
+#include "libvhost-user-glib.h"
 
 #if defined(__linux__)
 #include <linux/fs.h>
diff --git a/contrib/vhost-user-input/main.c b/contrib/vhost-user-input/main.c
index 6020c6f33a..3ea840cf44 100644
--- a/contrib/vhost-user-input/main.c
+++ b/contrib/vhost-user-input/main.c
@@ -12,8 +12,7 @@
 #include "qemu/iov.h"
 #include "qemu/bswap.h"
 #include "qemu/sockets.h"
-#include "contrib/libvhost-user/libvhost-user.h"
-#include "contrib/libvhost-user/libvhost-user-glib.h"
+#include "libvhost-user-glib.h"
 #include "standard-headers/linux/virtio_input.h"
 #include "qapi/error.h"
 
diff --git a/contrib/vhost-user-scsi/vhost-user-scsi.c b/contrib/vhost-user-scsi/vhost-user-scsi.c
index 0f9ba4b2a2..306434df70 100644
--- a/contrib/vhost-user-scsi/vhost-user-scsi.c
+++ b/contrib/vhost-user-scsi/vhost-user-scsi.c
@@ -15,7 +15,7 @@
 #define inline __attribute__((gnu_inline))  /* required for libiscsi v1.9.0 */
 #include <iscsi/scsi-lowlevel.h>
 #undef inline
-#include "contrib/libvhost-user/libvhost-user-glib.h"
+#include "libvhost-user-glib.h"
 #include "standard-headers/linux/virtio_scsi.h"
 
 
diff --git a/contrib/libvhost-user/libvhost-user-glib.c b/subprojects/libvhost-user/libvhost-user-glib.c
similarity index 100%
rename from contrib/libvhost-user/libvhost-user-glib.c
rename to subprojects/libvhost-user/libvhost-user-glib.c
diff --git a/contrib/libvhost-user/libvhost-user.c b/subprojects/libvhost-user/libvhost-user.c
similarity index 100%
rename from contrib/libvhost-user/libvhost-user.c
rename to subprojects/libvhost-user/libvhost-user.c
diff --git a/tests/vhost-user-bridge.c b/tests/vhost-user-bridge.c
index bd43607a4d..24815920b2 100644
--- a/tests/vhost-user-bridge.c
+++ b/tests/vhost-user-bridge.c
@@ -34,7 +34,7 @@
 #include "qemu/ctype.h"
 #include "qemu/iov.h"
 #include "standard-headers/linux/virtio_net.h"
-#include "contrib/libvhost-user/libvhost-user.h"
+#include "libvhost-user.h"
 
 #define VHOST_USER_BRIDGE_DEBUG 1
 
diff --git a/tools/virtiofsd/fuse_virtio.c b/tools/virtiofsd/fuse_virtio.c
index 83ba07c6cd..623812c432 100644
--- a/tools/virtiofsd/fuse_virtio.c
+++ b/tools/virtiofsd/fuse_virtio.c
@@ -35,7 +35,7 @@
 #include <grp.h>
 #include <unistd.h>
 
-#include "contrib/libvhost-user/libvhost-user.h"
+#include "libvhost-user.h"
 
 struct fv_VuDev;
 struct fv_QueueInfo {
diff --git a/contrib/libvhost-user/meson.build b/contrib/libvhost-user/meson.build
deleted file mode 100644
index a261e7665f..0000000000
--- a/contrib/libvhost-user/meson.build
+++ /dev/null
@@ -1,4 +0,0 @@
-libvhost_user = static_library('vhost-user',
-                               files('libvhost-user.c', 'libvhost-user-glib.c'),
-                               build_by_default: false)
-vhost_user = declare_dependency(link_with: libvhost_user)
diff --git a/contrib/vhost-user-blk/meson.build b/contrib/vhost-user-blk/meson.build
index 5db8cc3fe2..601ea15ef5 100644
--- a/contrib/vhost-user-blk/meson.build
+++ b/contrib/vhost-user-blk/meson.build
@@ -1,6 +1,5 @@
 # FIXME: broken on 32-bit architectures
 executable('vhost-user-blk', files('vhost-user-blk.c'),
-           link_with: libvhost_user,
-           dependencies: qemuutil,
+           dependencies: [qemuutil, vhost_user],
            build_by_default: false,
            install: false)
diff --git a/contrib/vhost-user-gpu/meson.build b/contrib/vhost-user-gpu/meson.build
index c487ca72c1..2fc2320b52 100644
--- a/contrib/vhost-user-gpu/meson.build
+++ b/contrib/vhost-user-gpu/meson.build
@@ -2,8 +2,7 @@ if 'CONFIG_TOOLS' in config_host and 'CONFIG_VIRGL' in config_host \
     and 'CONFIG_GBM' in config_host and 'CONFIG_LINUX' in config_host \
     and pixman.found()
   executable('vhost-user-gpu', files('vhost-user-gpu.c', 'virgl.c', 'vugbm.c'),
-             link_with: libvhost_user,
-             dependencies: [qemuutil, pixman, gbm, virgl],
+             dependencies: [qemuutil, pixman, gbm, virgl, vhost_user],
              install: true,
              install_dir: get_option('libexecdir'))
 
diff --git a/contrib/vhost-user-input/meson.build b/contrib/vhost-user-input/meson.build
index 1eeb1329d9..21a9ed4f15 100644
--- a/contrib/vhost-user-input/meson.build
+++ b/contrib/vhost-user-input/meson.build
@@ -1,5 +1,4 @@
 executable('vhost-user-input', files('main.c'),
-           link_with: libvhost_user,
-           dependencies: qemuutil,
+           dependencies: [qemuutil, vhost_user],
            build_by_default: targetos == 'linux',
            install: false)
diff --git a/contrib/vhost-user-scsi/meson.build b/contrib/vhost-user-scsi/meson.build
index 257cbffc8e..044c50bf43 100644
--- a/contrib/vhost-user-scsi/meson.build
+++ b/contrib/vhost-user-scsi/meson.build
@@ -1,7 +1,6 @@
 if 'CONFIG_LIBISCSI' in config_host
   executable('vhost-user-scsi', files('vhost-user-scsi.c'),
-             link_with: libvhost_user,
-             dependencies: [qemuutil, libiscsi],
+             dependencies: [qemuutil, libiscsi, vhost_user],
              build_by_default: targetos == 'linux',
              install: false)
 endif
diff --git a/subprojects/libvhost-user/meson.build b/subprojects/libvhost-user/meson.build
new file mode 100644
index 0000000000..f9ecc534cf
--- /dev/null
+++ b/subprojects/libvhost-user/meson.build
@@ -0,0 +1,20 @@
+project('libvhost-user', 'c',
+        license: 'GPL-2.0-or-later',
+        default_options: ['c_std=gnu99'])
+
+glib = dependency('glib-2.0')
+inc = include_directories('../../include', '../../linux-headers')
+
+vhost_user = static_library('vhost-user',
+                            files('libvhost-user.c'),
+                            include_directories: inc,
+                            c_args: '-D_GNU_SOURCE')
+
+vhost_user_glib = static_library('vhost-user-glib',
+                                 files('libvhost-user-glib.c'),
+                                 include_directories: inc,
+                                 link_with: vhost_user,
+                                 dependencies: glib)
+
+vhost_user_dep = declare_dependency(link_with: vhost_user_glib,
+                                    include_directories: include_directories('.'))
diff --git a/tests/meson.build b/tests/meson.build
index afeb6be689..1fa068f27b 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -264,8 +264,7 @@ endforeach
 if have_tools and 'CONFIG_VHOST_USER' in config_host and 'CONFIG_LINUX' in config_host
   executable('vhost-user-bridge',
              sources: files('vhost-user-bridge.c'),
-             link_with: [libvhost_user],
-             dependencies: [qemuutil])
+             dependencies: [qemuutil, vhost_user])
 endif
 
 if have_system and 'CONFIG_POSIX' in config_host
diff --git a/tools/virtiofsd/meson.build b/tools/virtiofsd/meson.build
index 17edecf55c..c134ba633f 100644
--- a/tools/virtiofsd/meson.build
+++ b/tools/virtiofsd/meson.build
@@ -8,8 +8,7 @@ executable('virtiofsd', files(
   'helper.c',
   'passthrough_ll.c',
   'passthrough_seccomp.c'),
-  link_with: libvhost_user,
-  dependencies: [seccomp, qemuutil, libcap_ng],
+  dependencies: [seccomp, qemuutil, libcap_ng, vhost_user],
   install: true,
   install_dir: get_option('libexecdir'))
 
-- 
2.29.0



^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v2 6/8] libvhost-user: check memfd API
  2020-11-25 10:06 [PATCH v2 0/8] libvhost-user: make it a subproject (was: "lower dependency on QEMU headers") marcandre.lureau
                   ` (4 preceding siblings ...)
  2020-11-25 10:06 ` [PATCH v2 5/8] libvhost-user: make it a meson subproject marcandre.lureau
@ 2020-11-25 10:06 ` marcandre.lureau
  2020-12-02 14:27   ` Stefan Hajnoczi
  2020-11-25 10:06 ` [PATCH v2 7/8] libvhost-user: add a simple link test without glib marcandre.lureau
  2020-11-25 10:06 ` [PATCH v2 8/8] .gitlab-ci: add build-libvhost-user marcandre.lureau
  7 siblings, 1 reply; 19+ messages in thread
From: marcandre.lureau @ 2020-11-25 10:06 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marc-André Lureau, Dr. David Alan Gilbert, Stefan Hajnoczi,
	Michael S. Tsirkin

From: Marc-André Lureau <marcandre.lureau@redhat.com>

Do not compile potentially panicking code, instead check memfd API is
present during configure time.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 subprojects/libvhost-user/libvhost-user.c |  6 ------
 subprojects/libvhost-user/meson.build     | 12 ++++++++++++
 2 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/subprojects/libvhost-user/libvhost-user.c b/subprojects/libvhost-user/libvhost-user.c
index fab7ca17ee..09741a7b49 100644
--- a/subprojects/libvhost-user/libvhost-user.c
+++ b/subprojects/libvhost-user/libvhost-user.c
@@ -1616,7 +1616,6 @@ vu_inflight_queue_size(uint16_t queue_size)
            sizeof(uint16_t), INFLIGHT_ALIGNMENT);
 }
 
-#ifdef MFD_ALLOW_SEALING
 static void *
 memfd_alloc(const char *name, size_t size, unsigned int flags, int *fd)
 {
@@ -1648,7 +1647,6 @@ memfd_alloc(const char *name, size_t size, unsigned int flags, int *fd)
 
     return ptr;
 }
-#endif
 
 static bool
 vu_get_inflight_fd(VuDev *dev, VhostUserMsg *vmsg)
@@ -1672,13 +1670,9 @@ vu_get_inflight_fd(VuDev *dev, VhostUserMsg *vmsg)
 
     mmap_size = vu_inflight_queue_size(queue_size) * num_queues;
 
-#ifdef MFD_ALLOW_SEALING
     addr = memfd_alloc("vhost-inflight", mmap_size,
                        F_SEAL_GROW | F_SEAL_SHRINK | F_SEAL_SEAL,
                        &fd);
-#else
-    vu_panic(dev, "Not implemented: memfd support is missing");
-#endif
 
     if (!addr) {
         vu_panic(dev, "Failed to alloc vhost inflight area");
diff --git a/subprojects/libvhost-user/meson.build b/subprojects/libvhost-user/meson.build
index f9ecc534cf..ac228b5ba6 100644
--- a/subprojects/libvhost-user/meson.build
+++ b/subprojects/libvhost-user/meson.build
@@ -2,7 +2,19 @@ project('libvhost-user', 'c',
         license: 'GPL-2.0-or-later',
         default_options: ['c_std=gnu99'])
 
+cc = meson.get_compiler('c')
+
 glib = dependency('glib-2.0')
+foreach h, syms: {
+  'sys/mman.h': ['memfd_create', 'MFD_ALLOW_SEALING'],
+  'sys/fcntl.h': ['F_SEAL_GROW', 'F_SEAL_SHRINK', 'F_SEAL_SEAL'] }
+  foreach sym: syms
+    cc.has_header_symbol(h, sym,
+                         args: ['-D_GNU_SOURCE'],
+                         required: true)
+  endforeach
+endforeach
+
 inc = include_directories('../../include', '../../linux-headers')
 
 vhost_user = static_library('vhost-user',
-- 
2.29.0



^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v2 7/8] libvhost-user: add a simple link test without glib
  2020-11-25 10:06 [PATCH v2 0/8] libvhost-user: make it a subproject (was: "lower dependency on QEMU headers") marcandre.lureau
                   ` (5 preceding siblings ...)
  2020-11-25 10:06 ` [PATCH v2 6/8] libvhost-user: check memfd API marcandre.lureau
@ 2020-11-25 10:06 ` marcandre.lureau
  2020-12-02 14:28   ` Stefan Hajnoczi
  2020-11-25 10:06 ` [PATCH v2 8/8] .gitlab-ci: add build-libvhost-user marcandre.lureau
  7 siblings, 1 reply; 19+ messages in thread
From: marcandre.lureau @ 2020-11-25 10:06 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marc-André Lureau, Dr. David Alan Gilbert, Stefan Hajnoczi,
	Michael S. Tsirkin

From: Marc-André Lureau <marcandre.lureau@redhat.com>

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 subprojects/libvhost-user/link-test.c | 45 +++++++++++++++++++++++++++
 subprojects/libvhost-user/meson.build |  4 +++
 2 files changed, 49 insertions(+)
 create mode 100644 subprojects/libvhost-user/link-test.c

diff --git a/subprojects/libvhost-user/link-test.c b/subprojects/libvhost-user/link-test.c
new file mode 100644
index 0000000000..e01d6eb1fa
--- /dev/null
+++ b/subprojects/libvhost-user/link-test.c
@@ -0,0 +1,45 @@
+/*
+ * A trivial unit test to check linking without glib. A real test suite should
+ * probably based off libvhost-user-glib instead.
+ */
+#include <assert.h>
+#include <stdlib.h>
+#include "libvhost-user.h"
+
+static void
+panic(VuDev *dev, const char *err)
+{
+    abort();
+}
+
+static void
+set_watch(VuDev *dev, int fd, int condition,
+          vu_watch_cb cb, void *data)
+{
+    abort();
+}
+
+static void
+remove_watch(VuDev *dev, int fd)
+{
+    abort();
+}
+
+static const VuDevIface iface = {
+    0,
+};
+
+int
+main(int argc, const char *argv[])
+{
+    bool rc;
+    uint16_t max_queues = 2;
+    int socket = 0;
+    VuDev dev = { 0, };
+
+    rc = vu_init(&dev, max_queues, socket, panic, NULL, set_watch, remove_watch, &iface);
+    assert(rc == true);
+    vu_deinit(&dev);
+
+    return 0;
+}
diff --git a/subprojects/libvhost-user/meson.build b/subprojects/libvhost-user/meson.build
index ac228b5ba6..76e83c0cec 100644
--- a/subprojects/libvhost-user/meson.build
+++ b/subprojects/libvhost-user/meson.build
@@ -22,6 +22,10 @@ vhost_user = static_library('vhost-user',
                             include_directories: inc,
                             c_args: '-D_GNU_SOURCE')
 
+executable('link-test', files('link-test.c'),
+           link_whole: vhost_user,
+           include_directories: inc)
+
 vhost_user_glib = static_library('vhost-user-glib',
                                  files('libvhost-user-glib.c'),
                                  include_directories: inc,
-- 
2.29.0



^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v2 8/8] .gitlab-ci: add build-libvhost-user
  2020-11-25 10:06 [PATCH v2 0/8] libvhost-user: make it a subproject (was: "lower dependency on QEMU headers") marcandre.lureau
                   ` (6 preceding siblings ...)
  2020-11-25 10:06 ` [PATCH v2 7/8] libvhost-user: add a simple link test without glib marcandre.lureau
@ 2020-11-25 10:06 ` marcandre.lureau
  2020-12-02 14:28   ` Stefan Hajnoczi
  2020-12-02 14:49   ` Philippe Mathieu-Daudé
  7 siblings, 2 replies; 19+ messages in thread
From: marcandre.lureau @ 2020-11-25 10:06 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marc-André Lureau, Dr. David Alan Gilbert, Stefan Hajnoczi,
	Michael S. Tsirkin

From: Marc-André Lureau <marcandre.lureau@redhat.com>

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 .gitlab-ci.yml | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index d0173e82b1..e517506c35 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -455,6 +455,17 @@ check-dco:
   variables:
     GIT_DEPTH: 1000
 
+build-libvhost-user:
+  stage: build
+  image: $CI_REGISTRY_IMAGE/qemu/fedora:latest
+  before_script:
+    - dnf install -y meson ninja-build
+  script:
+    - mkdir subprojects/libvhost-user/build
+    - cd subprojects/libvhost-user/build
+    - meson
+    - ninja
+
 pages:
   image: $CI_REGISTRY_IMAGE/qemu/ubuntu2004:latest
   stage: test
-- 
2.29.0



^ permalink raw reply related	[flat|nested] 19+ messages in thread

* Re: [PATCH v2 1/8] libvhost-user: replace qemu/bswap.h with glibc endian.h
  2020-11-25 10:06 ` [PATCH v2 1/8] libvhost-user: replace qemu/bswap.h with glibc endian.h marcandre.lureau
@ 2020-12-02 14:20   ` Stefan Hajnoczi
  0 siblings, 0 replies; 19+ messages in thread
From: Stefan Hajnoczi @ 2020-12-02 14:20 UTC (permalink / raw)
  To: marcandre.lureau; +Cc: Michael S. Tsirkin, qemu-devel, Dr. David Alan Gilbert

[-- Attachment #1: Type: text/plain, Size: 510 bytes --]

On Wed, Nov 25, 2020 at 02:06:33PM +0400, marcandre.lureau@redhat.com wrote:
> From: Marc-André Lureau <marcandre.lureau@redhat.com>
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
> ---
>  contrib/libvhost-user/libvhost-user.c | 77 ++++++++++++++-------------
>  1 file changed, 40 insertions(+), 37 deletions(-)

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v2 2/8] libvhost-user: replace qemu/memfd.h usage
  2020-11-25 10:06 ` [PATCH v2 2/8] libvhost-user: replace qemu/memfd.h usage marcandre.lureau
@ 2020-12-02 14:20   ` Stefan Hajnoczi
  0 siblings, 0 replies; 19+ messages in thread
From: Stefan Hajnoczi @ 2020-12-02 14:20 UTC (permalink / raw)
  To: marcandre.lureau; +Cc: Michael S. Tsirkin, qemu-devel, Dr. David Alan Gilbert

[-- Attachment #1: Type: text/plain, Size: 922 bytes --]

On Wed, Nov 25, 2020 at 02:06:34PM +0400, marcandre.lureau@redhat.com wrote:
> From: Marc-André Lureau <marcandre.lureau@redhat.com>
> 
> Undo the damage from commit 5f9ff1eff3 ("libvhost-user: Support tracking
> inflight I/O in shared memory") which introduced glib dependency through
> osdep.h inclusion.
> 
> libvhost-user.c tries to stay free from glib usage.
> 
> Use glibc memfd_create directly when available (assumed so when
> MFD_ALLOW_SEALING is defined). A following commit will make the project
> standalone and check for memfd API at configure time, instead of a
> panic at runtime.
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
> ---
>  contrib/libvhost-user/libvhost-user.c | 50 +++++++++++++++++++++++----
>  1 file changed, 43 insertions(+), 7 deletions(-)

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v2 3/8] libvhost-user: remove qemu/compiler.h usage
  2020-11-25 10:06 ` [PATCH v2 3/8] libvhost-user: remove qemu/compiler.h usage marcandre.lureau
@ 2020-12-02 14:20   ` Stefan Hajnoczi
  0 siblings, 0 replies; 19+ messages in thread
From: Stefan Hajnoczi @ 2020-12-02 14:20 UTC (permalink / raw)
  To: marcandre.lureau; +Cc: Michael S. Tsirkin, qemu-devel, Dr. David Alan Gilbert

[-- Attachment #1: Type: text/plain, Size: 369 bytes --]

On Wed, Nov 25, 2020 at 02:06:35PM +0400, marcandre.lureau@redhat.com wrote:
> From: Marc-André Lureau <marcandre.lureau@redhat.com>
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  contrib/libvhost-user/libvhost-user.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v2 4/8] libvhost-user: drop qemu/osdep.h dependency
  2020-11-25 10:06 ` [PATCH v2 4/8] libvhost-user: drop qemu/osdep.h dependency marcandre.lureau
@ 2020-12-02 14:20   ` Stefan Hajnoczi
  0 siblings, 0 replies; 19+ messages in thread
From: Stefan Hajnoczi @ 2020-12-02 14:20 UTC (permalink / raw)
  To: marcandre.lureau; +Cc: Michael S. Tsirkin, qemu-devel, Dr. David Alan Gilbert

[-- Attachment #1: Type: text/plain, Size: 381 bytes --]

On Wed, Nov 25, 2020 at 02:06:36PM +0400, marcandre.lureau@redhat.com wrote:
> From: Marc-André Lureau <marcandre.lureau@redhat.com>
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  contrib/libvhost-user/libvhost-user-glib.c | 10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v2 5/8] libvhost-user: make it a meson subproject
  2020-11-25 10:06 ` [PATCH v2 5/8] libvhost-user: make it a meson subproject marcandre.lureau
@ 2020-12-02 14:25   ` Stefan Hajnoczi
  0 siblings, 0 replies; 19+ messages in thread
From: Stefan Hajnoczi @ 2020-12-02 14:25 UTC (permalink / raw)
  To: marcandre.lureau; +Cc: Michael S. Tsirkin, qemu-devel, Dr. David Alan Gilbert

[-- Attachment #1: Type: text/plain, Size: 828 bytes --]

On Wed, Nov 25, 2020 at 02:06:37PM +0400, marcandre.lureau@redhat.com wrote:
> diff --git a/meson.build b/meson.build
> index 5062407c70..1b14998691 100644
> --- a/meson.build
> +++ b/meson.build
> @@ -1476,7 +1476,12 @@ trace_events_subdirs += [
>    'util',
>  ]
>  
> -subdir('contrib/libvhost-user')
> +vhost_user = not_found
> +if 'CONFIG_VHOST_USER' in config_host
> +  libvhost_user = subproject('libvhost-user')
> +  vhost_user = libvhost_user.get_variable('vhost_user_dep')
> +endif
> +
>  subdir('qapi')
>  subdir('qobject')
>  subdir('stubs')

I wonder if qemu-system-ARCH and qemu-storage-daemon targets will break
with ./configure --disable-vhost-user because of util/meson.build:

  util_ss.add(when: 'CONFIG_LINUX', if_true: [
    files('vhost-user-server.c'), vhost_user
  ])

Stefan

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v2 6/8] libvhost-user: check memfd API
  2020-11-25 10:06 ` [PATCH v2 6/8] libvhost-user: check memfd API marcandre.lureau
@ 2020-12-02 14:27   ` Stefan Hajnoczi
  2020-12-09 18:08     ` Michael S. Tsirkin
  0 siblings, 1 reply; 19+ messages in thread
From: Stefan Hajnoczi @ 2020-12-02 14:27 UTC (permalink / raw)
  To: marcandre.lureau; +Cc: Michael S. Tsirkin, qemu-devel, Dr. David Alan Gilbert

[-- Attachment #1: Type: text/plain, Size: 906 bytes --]

On Wed, Nov 25, 2020 at 02:06:38PM +0400, marcandre.lureau@redhat.com wrote:
> From: Marc-André Lureau <marcandre.lureau@redhat.com>
> 
> Do not compile potentially panicking code, instead check memfd API is
> present during configure time.
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  subprojects/libvhost-user/libvhost-user.c |  6 ------
>  subprojects/libvhost-user/meson.build     | 12 ++++++++++++
>  2 files changed, 12 insertions(+), 6 deletions(-)

Runtime checks are useful in environments where the QEMU and kernel
version are not matched. In other words, if QEMU can be built against
new kernel headers and launched on an old kernel then it needs to handle
ENOSYS. But in some cases this situation is unlikely and we can stick to
static feature checks. I'm not sure if it matters here, so...

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v2 7/8] libvhost-user: add a simple link test without glib
  2020-11-25 10:06 ` [PATCH v2 7/8] libvhost-user: add a simple link test without glib marcandre.lureau
@ 2020-12-02 14:28   ` Stefan Hajnoczi
  0 siblings, 0 replies; 19+ messages in thread
From: Stefan Hajnoczi @ 2020-12-02 14:28 UTC (permalink / raw)
  To: marcandre.lureau; +Cc: Michael S. Tsirkin, qemu-devel, Dr. David Alan Gilbert

[-- Attachment #1: Type: text/plain, Size: 491 bytes --]

On Wed, Nov 25, 2020 at 02:06:39PM +0400, marcandre.lureau@redhat.com wrote:
> From: Marc-André Lureau <marcandre.lureau@redhat.com>
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  subprojects/libvhost-user/link-test.c | 45 +++++++++++++++++++++++++++
>  subprojects/libvhost-user/meson.build |  4 +++
>  2 files changed, 49 insertions(+)
>  create mode 100644 subprojects/libvhost-user/link-test.c

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v2 8/8] .gitlab-ci: add build-libvhost-user
  2020-11-25 10:06 ` [PATCH v2 8/8] .gitlab-ci: add build-libvhost-user marcandre.lureau
@ 2020-12-02 14:28   ` Stefan Hajnoczi
  2020-12-02 14:49   ` Philippe Mathieu-Daudé
  1 sibling, 0 replies; 19+ messages in thread
From: Stefan Hajnoczi @ 2020-12-02 14:28 UTC (permalink / raw)
  To: marcandre.lureau; +Cc: Michael S. Tsirkin, qemu-devel, Dr. David Alan Gilbert

[-- Attachment #1: Type: text/plain, Size: 339 bytes --]

On Wed, Nov 25, 2020 at 02:06:40PM +0400, marcandre.lureau@redhat.com wrote:
> From: Marc-André Lureau <marcandre.lureau@redhat.com>
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  .gitlab-ci.yml | 11 +++++++++++
>  1 file changed, 11 insertions(+)

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v2 8/8] .gitlab-ci: add build-libvhost-user
  2020-11-25 10:06 ` [PATCH v2 8/8] .gitlab-ci: add build-libvhost-user marcandre.lureau
  2020-12-02 14:28   ` Stefan Hajnoczi
@ 2020-12-02 14:49   ` Philippe Mathieu-Daudé
  1 sibling, 0 replies; 19+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-12-02 14:49 UTC (permalink / raw)
  To: marcandre.lureau, qemu-devel
  Cc: Dr. David Alan Gilbert, Stefan Hajnoczi, Michael S. Tsirkin

On 11/25/20 11:06 AM, marcandre.lureau@redhat.com wrote:
> From: Marc-André Lureau <marcandre.lureau@redhat.com>
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  .gitlab-ci.yml | 11 +++++++++++
>  1 file changed, 11 insertions(+)
> 
> diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
> index d0173e82b1..e517506c35 100644
> --- a/.gitlab-ci.yml
> +++ b/.gitlab-ci.yml
> @@ -455,6 +455,17 @@ check-dco:
>    variables:
>      GIT_DEPTH: 1000
>  
> +build-libvhost-user:
> +  stage: build
> +  image: $CI_REGISTRY_IMAGE/qemu/fedora:latest
> +  before_script:
> +    - dnf install -y meson ninja-build
> +  script:
> +    - mkdir subprojects/libvhost-user/build
> +    - cd subprojects/libvhost-user/build
> +    - meson
> +    - ninja
> +

It would be better to have this job in a separate Yaml so
you can cover it in MAINTAINERS.

>  pages:
>    image: $CI_REGISTRY_IMAGE/qemu/ubuntu2004:latest
>    stage: test
> 



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v2 6/8] libvhost-user: check memfd API
  2020-12-02 14:27   ` Stefan Hajnoczi
@ 2020-12-09 18:08     ` Michael S. Tsirkin
  0 siblings, 0 replies; 19+ messages in thread
From: Michael S. Tsirkin @ 2020-12-09 18:08 UTC (permalink / raw)
  To: Stefan Hajnoczi; +Cc: marcandre.lureau, qemu-devel, Dr. David Alan Gilbert

On Wed, Dec 02, 2020 at 02:27:53PM +0000, Stefan Hajnoczi wrote:
> On Wed, Nov 25, 2020 at 02:06:38PM +0400, marcandre.lureau@redhat.com wrote:
> > From: Marc-André Lureau <marcandre.lureau@redhat.com>
> > 
> > Do not compile potentially panicking code, instead check memfd API is
> > present during configure time.
> > 
> > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> > ---
> >  subprojects/libvhost-user/libvhost-user.c |  6 ------
> >  subprojects/libvhost-user/meson.build     | 12 ++++++++++++
> >  2 files changed, 12 insertions(+), 6 deletions(-)
> 
> Runtime checks are useful in environments where the QEMU and kernel
> version are not matched. In other words, if QEMU can be built against
> new kernel headers and launched on an old kernel then it needs to handle
> ENOSYS. But in some cases this situation is unlikely and we can stick to
> static feature checks. I'm not sure if it matters here, so...
> 
> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>

It's a good point, and given this patch also made build fail on a bunch
of systems, I dropped it.

-- 
MST



^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2020-12-09 18:29 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-25 10:06 [PATCH v2 0/8] libvhost-user: make it a subproject (was: "lower dependency on QEMU headers") marcandre.lureau
2020-11-25 10:06 ` [PATCH v2 1/8] libvhost-user: replace qemu/bswap.h with glibc endian.h marcandre.lureau
2020-12-02 14:20   ` Stefan Hajnoczi
2020-11-25 10:06 ` [PATCH v2 2/8] libvhost-user: replace qemu/memfd.h usage marcandre.lureau
2020-12-02 14:20   ` Stefan Hajnoczi
2020-11-25 10:06 ` [PATCH v2 3/8] libvhost-user: remove qemu/compiler.h usage marcandre.lureau
2020-12-02 14:20   ` Stefan Hajnoczi
2020-11-25 10:06 ` [PATCH v2 4/8] libvhost-user: drop qemu/osdep.h dependency marcandre.lureau
2020-12-02 14:20   ` Stefan Hajnoczi
2020-11-25 10:06 ` [PATCH v2 5/8] libvhost-user: make it a meson subproject marcandre.lureau
2020-12-02 14:25   ` Stefan Hajnoczi
2020-11-25 10:06 ` [PATCH v2 6/8] libvhost-user: check memfd API marcandre.lureau
2020-12-02 14:27   ` Stefan Hajnoczi
2020-12-09 18:08     ` Michael S. Tsirkin
2020-11-25 10:06 ` [PATCH v2 7/8] libvhost-user: add a simple link test without glib marcandre.lureau
2020-12-02 14:28   ` Stefan Hajnoczi
2020-11-25 10:06 ` [PATCH v2 8/8] .gitlab-ci: add build-libvhost-user marcandre.lureau
2020-12-02 14:28   ` Stefan Hajnoczi
2020-12-02 14:49   ` Philippe Mathieu-Daudé

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.