[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v6 08/29] libvhost-user: Open userfaultfd
From: |
Dr. David Alan Gilbert (git) |
Subject: |
[Qemu-devel] [PATCH v6 08/29] libvhost-user: Open userfaultfd |
Date: |
Wed, 14 Mar 2018 11:55:57 +0000 |
From: "Dr. David Alan Gilbert" <address@hidden>
Open a userfaultfd (on a postcopy_advise) and send it back in
the reply to the qemu for it to monitor.
Signed-off-by: Dr. David Alan Gilbert <address@hidden>
Reviewed-by: Marc-André Lureau <address@hidden>
---
contrib/libvhost-user/libvhost-user.c | 42 +++++++++++++++++++++++++++++++++--
contrib/libvhost-user/libvhost-user.h | 3 +++
2 files changed, 43 insertions(+), 2 deletions(-)
diff --git a/contrib/libvhost-user/libvhost-user.c
b/contrib/libvhost-user/libvhost-user.c
index ed9f3148d3..9e31f47b7a 100644
--- a/contrib/libvhost-user/libvhost-user.c
+++ b/contrib/libvhost-user/libvhost-user.c
@@ -26,9 +26,20 @@
#include <sys/socket.h>
#include <sys/eventfd.h>
#include <sys/mman.h>
+#include "qemu/compiler.h"
+
+#if defined(__linux__)
+#include <sys/syscall.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
#include <linux/vhost.h>
-#include "qemu/compiler.h"
+#ifdef __NR_userfaultfd
+#include <linux/userfaultfd.h>
+#endif
+
+#endif
+
#include "qemu/atomic.h"
#include "libvhost-user.h"
@@ -888,8 +899,35 @@ vu_set_config(VuDev *dev, VhostUserMsg *vmsg)
static bool
vu_set_postcopy_advise(VuDev *dev, VhostUserMsg *vmsg)
{
- /* TODO: Open ufd, pass it back in the request */
+ dev->postcopy_ufd = -1;
+#ifdef UFFDIO_API
+ struct uffdio_api api_struct;
+
+ dev->postcopy_ufd = syscall(__NR_userfaultfd, O_CLOEXEC | O_NONBLOCK);
vmsg->size = 0;
+#endif
+
+ if (dev->postcopy_ufd == -1) {
+ vu_panic(dev, "Userfaultfd not available: %s", strerror(errno));
+ goto out;
+ }
+
+#ifdef UFFDIO_API
+ api_struct.api = UFFD_API;
+ api_struct.features = 0;
+ if (ioctl(dev->postcopy_ufd, UFFDIO_API, &api_struct)) {
+ vu_panic(dev, "Failed UFFDIO_API: %s", strerror(errno));
+ close(dev->postcopy_ufd);
+ dev->postcopy_ufd = -1;
+ goto out;
+ }
+ /* TODO: Stash feature flags somewhere */
+#endif
+
+out:
+ /* Return a ufd to the QEMU */
+ vmsg->fd_num = 1;
+ vmsg->fds[0] = dev->postcopy_ufd;
return true; /* = send a reply */
}
diff --git a/contrib/libvhost-user/libvhost-user.h
b/contrib/libvhost-user/libvhost-user.h
index 00d78a8810..074b7860f6 100644
--- a/contrib/libvhost-user/libvhost-user.h
+++ b/contrib/libvhost-user/libvhost-user.h
@@ -282,6 +282,9 @@ struct VuDev {
* re-initialize */
vu_panic_cb panic;
const VuDevIface *iface;
+
+ /* Postcopy data */
+ int postcopy_ufd;
};
typedef struct VuVirtqElement {
--
2.14.3
- [Qemu-devel] [PATCH v6 00/29] postcopy+vhost-user/shared ram, Dr. David Alan Gilbert (git), 2018/03/14
- [Qemu-devel] [PATCH v6 02/29] qemu_ram_block_host_offset, Dr. David Alan Gilbert (git), 2018/03/14
- [Qemu-devel] [PATCH v6 04/29] postcopy: Add notifier chain, Dr. David Alan Gilbert (git), 2018/03/14
- [Qemu-devel] [PATCH v6 01/29] migrate: Update ram_block_discard_range for shared, Dr. David Alan Gilbert (git), 2018/03/14
- [Qemu-devel] [PATCH v6 05/29] postcopy: Add vhost-user flag for postcopy and check it, Dr. David Alan Gilbert (git), 2018/03/14
- [Qemu-devel] [PATCH v6 03/29] postcopy: use UFFDIO_ZEROPAGE only when available, Dr. David Alan Gilbert (git), 2018/03/14
- [Qemu-devel] [PATCH v6 08/29] libvhost-user: Open userfaultfd,
Dr. David Alan Gilbert (git) <=
- [Qemu-devel] [PATCH v6 07/29] libvhost-user: Support sending fds back to qemu, Dr. David Alan Gilbert (git), 2018/03/14
- [Qemu-devel] [PATCH v6 06/29] vhost-user: Add 'VHOST_USER_POSTCOPY_ADVISE' message, Dr. David Alan Gilbert (git), 2018/03/14
- [Qemu-devel] [PATCH v6 09/29] postcopy: Allow registering of fd handler, Dr. David Alan Gilbert (git), 2018/03/14
- [Qemu-devel] [PATCH v6 11/29] vhost+postcopy: Transmit 'listen' to slave, Dr. David Alan Gilbert (git), 2018/03/14
- [Qemu-devel] [PATCH v6 10/29] vhost+postcopy: Register shared ufd with postcopy, Dr. David Alan Gilbert (git), 2018/03/14
- [Qemu-devel] [PATCH v6 12/29] postcopy+vhost-user: Split set_mem_table for postcopy, Dr. David Alan Gilbert (git), 2018/03/14
- [Qemu-devel] [PATCH v6 13/29] migration/ram: ramblock_recv_bitmap_test_byte_offset, Dr. David Alan Gilbert (git), 2018/03/14
- [Qemu-devel] [PATCH v6 14/29] libvhost-user+postcopy: Register new regions with the ufd, Dr. David Alan Gilbert (git), 2018/03/14
- [Qemu-devel] [PATCH v6 15/29] vhost+postcopy: Send address back to qemu, Dr. David Alan Gilbert (git), 2018/03/14
- [Qemu-devel] [PATCH v6 16/29] vhost+postcopy: Stash RAMBlock and offset, Dr. David Alan Gilbert (git), 2018/03/14