Message ID | 20201125100640.366523-7-marcandre.lureau@redhat.com |
---|---|
State | New |
Headers | show |
Series | libvhost-user: make it a subproject (was: "lower dependency on QEMU headers") | expand |
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>
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.
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',