|
|
383d26 |
From bf38c0c9b897040dddc38456f731006c817e3c39 Mon Sep 17 00:00:00 2001
|
|
|
383d26 |
From: "plai@redhat.com" <plai@redhat.com>
|
|
|
383d26 |
Date: Thu, 21 Jun 2018 18:54:45 +0200
|
|
|
383d26 |
Subject: [PATCH 36/57] libvhost-user: support host notifier
|
|
|
383d26 |
|
|
|
383d26 |
RH-Author: plai@redhat.com
|
|
|
383d26 |
Message-id: <1529607285-9942-11-git-send-email-plai@redhat.com>
|
|
|
383d26 |
Patchwork-id: 80939
|
|
|
383d26 |
O-Subject: [RHEL7.6 PATCH BZ 1526645 10/10] libvhost-user: support host notifier
|
|
|
383d26 |
Bugzilla: 1526645
|
|
|
383d26 |
RH-Acked-by: Michael S. Tsirkin <mst@redhat.com>
|
|
|
383d26 |
RH-Acked-by: Maxime Coquelin <maxime.coquelin@redhat.com>
|
|
|
383d26 |
RH-Acked-by: Laurent Vivier <lvivier@redhat.com>
|
|
|
383d26 |
|
|
|
383d26 |
From: Tiwei Bie <tiwei.bie@intel.com>
|
|
|
383d26 |
|
|
|
383d26 |
This patch introduces the host notifier support in
|
|
|
383d26 |
libvhost-user. A new API is added to support setting
|
|
|
383d26 |
host notifier for each queue.
|
|
|
383d26 |
|
|
|
383d26 |
Signed-off-by: Tiwei Bie <tiwei.bie@intel.com>
|
|
|
383d26 |
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
|
|
|
383d26 |
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
|
|
|
383d26 |
(cherry picked from commit d84599f56c820d8c1ac9928a76500dcdfbbf194d)
|
|
|
383d26 |
Signed-off-by: Paul Lai <plai@redhat.com>
|
|
|
383d26 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
383d26 |
---
|
|
|
383d26 |
contrib/libvhost-user/libvhost-user.c | 81 +++++++++++++++++++++++++++++++----
|
|
|
383d26 |
contrib/libvhost-user/libvhost-user.h | 32 ++++++++++++++
|
|
|
383d26 |
2 files changed, 105 insertions(+), 8 deletions(-)
|
|
|
383d26 |
|
|
|
383d26 |
diff --git a/contrib/libvhost-user/libvhost-user.c b/contrib/libvhost-user/libvhost-user.c
|
|
|
383d26 |
index beeed0c..fa06eee 100644
|
|
|
383d26 |
--- a/contrib/libvhost-user/libvhost-user.c
|
|
|
383d26 |
+++ b/contrib/libvhost-user/libvhost-user.c
|
|
|
383d26 |
@@ -314,11 +314,6 @@ vu_message_write(VuDev *dev, int conn_fd, VhostUserMsg *vmsg)
|
|
|
383d26 |
msg.msg_controllen = 0;
|
|
|
383d26 |
}
|
|
|
383d26 |
|
|
|
383d26 |
- /* Set the version in the flags when sending the reply */
|
|
|
383d26 |
- vmsg->flags &= ~VHOST_USER_VERSION_MASK;
|
|
|
383d26 |
- vmsg->flags |= VHOST_USER_VERSION;
|
|
|
383d26 |
- vmsg->flags |= VHOST_USER_REPLY_MASK;
|
|
|
383d26 |
-
|
|
|
383d26 |
do {
|
|
|
383d26 |
rc = sendmsg(conn_fd, &msg, 0);
|
|
|
383d26 |
} while (rc < 0 && (errno == EINTR || errno == EAGAIN));
|
|
|
383d26 |
@@ -339,6 +334,39 @@ vu_message_write(VuDev *dev, int conn_fd, VhostUserMsg *vmsg)
|
|
|
383d26 |
return true;
|
|
|
383d26 |
}
|
|
|
383d26 |
|
|
|
383d26 |
+static bool
|
|
|
383d26 |
+vu_send_reply(VuDev *dev, int conn_fd, VhostUserMsg *vmsg)
|
|
|
383d26 |
+{
|
|
|
383d26 |
+ /* Set the version in the flags when sending the reply */
|
|
|
383d26 |
+ vmsg->flags &= ~VHOST_USER_VERSION_MASK;
|
|
|
383d26 |
+ vmsg->flags |= VHOST_USER_VERSION;
|
|
|
383d26 |
+ vmsg->flags |= VHOST_USER_REPLY_MASK;
|
|
|
383d26 |
+
|
|
|
383d26 |
+ return vu_message_write(dev, conn_fd, vmsg);
|
|
|
383d26 |
+}
|
|
|
383d26 |
+
|
|
|
383d26 |
+static bool
|
|
|
383d26 |
+vu_process_message_reply(VuDev *dev, const VhostUserMsg *vmsg)
|
|
|
383d26 |
+{
|
|
|
383d26 |
+ VhostUserMsg msg_reply;
|
|
|
383d26 |
+
|
|
|
383d26 |
+ if ((vmsg->flags & VHOST_USER_NEED_REPLY_MASK) == 0) {
|
|
|
383d26 |
+ return true;
|
|
|
383d26 |
+ }
|
|
|
383d26 |
+
|
|
|
383d26 |
+ if (!vu_message_read(dev, dev->slave_fd, &msg_reply)) {
|
|
|
383d26 |
+ return false;
|
|
|
383d26 |
+ }
|
|
|
383d26 |
+
|
|
|
383d26 |
+ if (msg_reply.request != vmsg->request) {
|
|
|
383d26 |
+ DPRINT("Received unexpected msg type. Expected %d received %d",
|
|
|
383d26 |
+ vmsg->request, msg_reply.request);
|
|
|
383d26 |
+ return false;
|
|
|
383d26 |
+ }
|
|
|
383d26 |
+
|
|
|
383d26 |
+ return msg_reply.payload.u64 == 0;
|
|
|
383d26 |
+}
|
|
|
383d26 |
+
|
|
|
383d26 |
/* Kick the log_call_fd if required. */
|
|
|
383d26 |
static void
|
|
|
383d26 |
vu_log_kick(VuDev *dev)
|
|
|
383d26 |
@@ -534,7 +562,7 @@ vu_set_mem_table_exec_postcopy(VuDev *dev, VhostUserMsg *vmsg)
|
|
|
383d26 |
|
|
|
383d26 |
/* Send the message back to qemu with the addresses filled in */
|
|
|
383d26 |
vmsg->fd_num = 0;
|
|
|
383d26 |
- if (!vu_message_write(dev, dev->sock, vmsg)) {
|
|
|
383d26 |
+ if (!vu_send_reply(dev, dev->sock, vmsg)) {
|
|
|
383d26 |
vu_panic(dev, "failed to respond to set-mem-table for postcopy");
|
|
|
383d26 |
return false;
|
|
|
383d26 |
}
|
|
|
383d26 |
@@ -914,6 +942,41 @@ void vu_set_queue_handler(VuDev *dev, VuVirtq *vq,
|
|
|
383d26 |
}
|
|
|
383d26 |
}
|
|
|
383d26 |
|
|
|
383d26 |
+bool vu_set_queue_host_notifier(VuDev *dev, VuVirtq *vq, int fd,
|
|
|
383d26 |
+ int size, int offset)
|
|
|
383d26 |
+{
|
|
|
383d26 |
+ int qidx = vq - dev->vq;
|
|
|
383d26 |
+ int fd_num = 0;
|
|
|
383d26 |
+ VhostUserMsg vmsg = {
|
|
|
383d26 |
+ .request = VHOST_USER_SLAVE_VRING_HOST_NOTIFIER_MSG,
|
|
|
383d26 |
+ .flags = VHOST_USER_VERSION | VHOST_USER_NEED_REPLY_MASK,
|
|
|
383d26 |
+ .size = sizeof(vmsg.payload.area),
|
|
|
383d26 |
+ .payload.area = {
|
|
|
383d26 |
+ .u64 = qidx & VHOST_USER_VRING_IDX_MASK,
|
|
|
383d26 |
+ .size = size,
|
|
|
383d26 |
+ .offset = offset,
|
|
|
383d26 |
+ },
|
|
|
383d26 |
+ };
|
|
|
383d26 |
+
|
|
|
383d26 |
+ if (fd == -1) {
|
|
|
383d26 |
+ vmsg.payload.area.u64 |= VHOST_USER_VRING_NOFD_MASK;
|
|
|
383d26 |
+ } else {
|
|
|
383d26 |
+ vmsg.fds[fd_num++] = fd;
|
|
|
383d26 |
+ }
|
|
|
383d26 |
+
|
|
|
383d26 |
+ vmsg.fd_num = fd_num;
|
|
|
383d26 |
+
|
|
|
383d26 |
+ if ((dev->protocol_features & VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD) == 0) {
|
|
|
383d26 |
+ return false;
|
|
|
383d26 |
+ }
|
|
|
383d26 |
+
|
|
|
383d26 |
+ if (!vu_message_write(dev, dev->slave_fd, &vmsg)) {
|
|
|
383d26 |
+ return false;
|
|
|
383d26 |
+ }
|
|
|
383d26 |
+
|
|
|
383d26 |
+ return vu_process_message_reply(dev, &vmsg);
|
|
|
383d26 |
+}
|
|
|
383d26 |
+
|
|
|
383d26 |
static bool
|
|
|
383d26 |
vu_set_vring_call_exec(VuDev *dev, VhostUserMsg *vmsg)
|
|
|
383d26 |
{
|
|
|
383d26 |
@@ -966,7 +1029,9 @@ static bool
|
|
|
383d26 |
vu_get_protocol_features_exec(VuDev *dev, VhostUserMsg *vmsg)
|
|
|
383d26 |
{
|
|
|
383d26 |
uint64_t features = 1ULL << VHOST_USER_PROTOCOL_F_LOG_SHMFD |
|
|
|
383d26 |
- 1ULL << VHOST_USER_PROTOCOL_F_SLAVE_REQ;
|
|
|
383d26 |
+ 1ULL << VHOST_USER_PROTOCOL_F_SLAVE_REQ |
|
|
|
383d26 |
+ 1ULL << VHOST_USER_PROTOCOL_F_HOST_NOTIFIER |
|
|
|
383d26 |
+ 1ULL << VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD;
|
|
|
383d26 |
|
|
|
383d26 |
if (have_userfault()) {
|
|
|
383d26 |
features |= 1ULL << VHOST_USER_PROTOCOL_F_PAGEFAULT;
|
|
|
383d26 |
@@ -1250,7 +1315,7 @@ vu_dispatch(VuDev *dev)
|
|
|
383d26 |
goto end;
|
|
|
383d26 |
}
|
|
|
383d26 |
|
|
|
383d26 |
- if (!vu_message_write(dev, dev->sock, &vmsg)) {
|
|
|
383d26 |
+ if (!vu_send_reply(dev, dev->sock, &vmsg)) {
|
|
|
383d26 |
goto end;
|
|
|
383d26 |
}
|
|
|
383d26 |
|
|
|
383d26 |
diff --git a/contrib/libvhost-user/libvhost-user.h b/contrib/libvhost-user/libvhost-user.h
|
|
|
383d26 |
index b27075e..4aa55b4 100644
|
|
|
383d26 |
--- a/contrib/libvhost-user/libvhost-user.h
|
|
|
383d26 |
+++ b/contrib/libvhost-user/libvhost-user.h
|
|
|
383d26 |
@@ -51,6 +51,8 @@ enum VhostUserProtocolFeature {
|
|
|
383d26 |
VHOST_USER_PROTOCOL_F_CRYPTO_SESSION = 7,
|
|
|
383d26 |
VHOST_USER_PROTOCOL_F_PAGEFAULT = 8,
|
|
|
383d26 |
VHOST_USER_PROTOCOL_F_CONFIG = 9,
|
|
|
383d26 |
+ VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD = 10,
|
|
|
383d26 |
+ VHOST_USER_PROTOCOL_F_HOST_NOTIFIER = 11,
|
|
|
383d26 |
|
|
|
383d26 |
VHOST_USER_PROTOCOL_F_MAX
|
|
|
383d26 |
};
|
|
|
383d26 |
@@ -92,6 +94,14 @@ typedef enum VhostUserRequest {
|
|
|
383d26 |
VHOST_USER_MAX
|
|
|
383d26 |
} VhostUserRequest;
|
|
|
383d26 |
|
|
|
383d26 |
+typedef enum VhostUserSlaveRequest {
|
|
|
383d26 |
+ VHOST_USER_SLAVE_NONE = 0,
|
|
|
383d26 |
+ VHOST_USER_SLAVE_IOTLB_MSG = 1,
|
|
|
383d26 |
+ VHOST_USER_SLAVE_CONFIG_CHANGE_MSG = 2,
|
|
|
383d26 |
+ VHOST_USER_SLAVE_VRING_HOST_NOTIFIER_MSG = 3,
|
|
|
383d26 |
+ VHOST_USER_SLAVE_MAX
|
|
|
383d26 |
+} VhostUserSlaveRequest;
|
|
|
383d26 |
+
|
|
|
383d26 |
typedef struct VhostUserMemoryRegion {
|
|
|
383d26 |
uint64_t guest_phys_addr;
|
|
|
383d26 |
uint64_t memory_size;
|
|
|
383d26 |
@@ -122,6 +132,12 @@ static VhostUserConfig c __attribute__ ((unused));
|
|
|
383d26 |
+ sizeof(c.size) \
|
|
|
383d26 |
+ sizeof(c.flags))
|
|
|
383d26 |
|
|
|
383d26 |
+typedef struct VhostUserVringArea {
|
|
|
383d26 |
+ uint64_t u64;
|
|
|
383d26 |
+ uint64_t size;
|
|
|
383d26 |
+ uint64_t offset;
|
|
|
383d26 |
+} VhostUserVringArea;
|
|
|
383d26 |
+
|
|
|
383d26 |
#if defined(_WIN32)
|
|
|
383d26 |
# define VU_PACKED __attribute__((gcc_struct, packed))
|
|
|
383d26 |
#else
|
|
|
383d26 |
@@ -133,6 +149,7 @@ typedef struct VhostUserMsg {
|
|
|
383d26 |
|
|
|
383d26 |
#define VHOST_USER_VERSION_MASK (0x3)
|
|
|
383d26 |
#define VHOST_USER_REPLY_MASK (0x1 << 2)
|
|
|
383d26 |
+#define VHOST_USER_NEED_REPLY_MASK (0x1 << 3)
|
|
|
383d26 |
uint32_t flags;
|
|
|
383d26 |
uint32_t size; /* the following payload size */
|
|
|
383d26 |
|
|
|
383d26 |
@@ -145,6 +162,7 @@ typedef struct VhostUserMsg {
|
|
|
383d26 |
VhostUserMemory memory;
|
|
|
383d26 |
VhostUserLog log;
|
|
|
383d26 |
VhostUserConfig config;
|
|
|
383d26 |
+ VhostUserVringArea area;
|
|
|
383d26 |
} payload;
|
|
|
383d26 |
|
|
|
383d26 |
int fds[VHOST_MEMORY_MAX_NREGIONS];
|
|
|
383d26 |
@@ -368,6 +386,20 @@ VuVirtq *vu_get_queue(VuDev *dev, int qidx);
|
|
|
383d26 |
void vu_set_queue_handler(VuDev *dev, VuVirtq *vq,
|
|
|
383d26 |
vu_queue_handler_cb handler);
|
|
|
383d26 |
|
|
|
383d26 |
+/**
|
|
|
383d26 |
+ * vu_set_queue_host_notifier:
|
|
|
383d26 |
+ * @dev: a VuDev context
|
|
|
383d26 |
+ * @vq: a VuVirtq queue
|
|
|
383d26 |
+ * @fd: a file descriptor
|
|
|
383d26 |
+ * @size: host page size
|
|
|
383d26 |
+ * @offset: notifier offset in @fd file
|
|
|
383d26 |
+ *
|
|
|
383d26 |
+ * Set queue's host notifier. This function may be called several
|
|
|
383d26 |
+ * times for the same queue. If called with -1 @fd, the notifier
|
|
|
383d26 |
+ * is removed.
|
|
|
383d26 |
+ */
|
|
|
383d26 |
+bool vu_set_queue_host_notifier(VuDev *dev, VuVirtq *vq, int fd,
|
|
|
383d26 |
+ int size, int offset);
|
|
|
383d26 |
|
|
|
383d26 |
/**
|
|
|
383d26 |
* vu_queue_set_notification:
|
|
|
383d26 |
--
|
|
|
383d26 |
1.8.3.1
|
|
|
383d26 |
|