[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [RFC v2 3/4] libvhost-user: support VFIO container message
From: |
Tiwei Bie |
Subject: |
[Qemu-devel] [RFC v2 3/4] libvhost-user: support VFIO container message |
Date: |
Wed, 19 Sep 2018 14:28:33 +0800 |
This patch introduces the VFIO container message support
in libvhost-user. A new API is added to support setting
the VFIO container for the vhost device.
Signed-off-by: Tiwei Bie <address@hidden>
---
contrib/libvhost-user/libvhost-user.c | 29 ++++++++++++++++++++++++++-
contrib/libvhost-user/libvhost-user.h | 12 +++++++++++
2 files changed, 40 insertions(+), 1 deletion(-)
diff --git a/contrib/libvhost-user/libvhost-user.c
b/contrib/libvhost-user/libvhost-user.c
index a6b46cdc03..b960449f9e 100644
--- a/contrib/libvhost-user/libvhost-user.c
+++ b/contrib/libvhost-user/libvhost-user.c
@@ -979,6 +979,32 @@ bool vu_set_queue_host_notifier(VuDev *dev, VuVirtq *vq,
int fd,
return vu_process_message_reply(dev, &vmsg);
}
+bool vu_set_vfio_container(VuDev *dev, int fd)
+{
+ int fd_num = 0;
+ VhostUserMsg vmsg = {
+ .request = VHOST_USER_SLAVE_VFIO_CONTAINER_MSG,
+ .flags = VHOST_USER_VERSION | VHOST_USER_NEED_REPLY_MASK,
+ .size = 0,
+ };
+
+ if (fd != -1) {
+ vmsg.fds[fd_num++] = fd;
+ }
+
+ vmsg.fd_num = fd_num;
+
+ if ((dev->protocol_features & VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD) == 0) {
+ return false;
+ }
+
+ if (!vu_message_write(dev, dev->slave_fd, &vmsg)) {
+ return false;
+ }
+
+ return vu_process_message_reply(dev, &vmsg);
+}
+
static bool
vu_set_vring_call_exec(VuDev *dev, VhostUserMsg *vmsg)
{
@@ -1033,7 +1059,8 @@ vu_get_protocol_features_exec(VuDev *dev, VhostUserMsg
*vmsg)
uint64_t features = 1ULL << VHOST_USER_PROTOCOL_F_LOG_SHMFD |
1ULL << VHOST_USER_PROTOCOL_F_SLAVE_REQ |
1ULL << VHOST_USER_PROTOCOL_F_HOST_NOTIFIER |
- 1ULL << VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD;
+ 1ULL << VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD |
+ 1ULL << VHOST_USER_PROTOCOL_F_VFIO_CONTAINER;
if (have_userfault()) {
features |= 1ULL << VHOST_USER_PROTOCOL_F_PAGEFAULT;
diff --git a/contrib/libvhost-user/libvhost-user.h
b/contrib/libvhost-user/libvhost-user.h
index 4aa55b4d2d..5232bd85ab 100644
--- a/contrib/libvhost-user/libvhost-user.h
+++ b/contrib/libvhost-user/libvhost-user.h
@@ -53,6 +53,7 @@ enum VhostUserProtocolFeature {
VHOST_USER_PROTOCOL_F_CONFIG = 9,
VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD = 10,
VHOST_USER_PROTOCOL_F_HOST_NOTIFIER = 11,
+ VHOST_USER_PROTOCOL_F_VFIO_CONTAINER = 12,
VHOST_USER_PROTOCOL_F_MAX
};
@@ -99,6 +100,7 @@ typedef enum VhostUserSlaveRequest {
VHOST_USER_SLAVE_IOTLB_MSG = 1,
VHOST_USER_SLAVE_CONFIG_CHANGE_MSG = 2,
VHOST_USER_SLAVE_VRING_HOST_NOTIFIER_MSG = 3,
+ VHOST_USER_SLAVE_VFIO_CONTAINER_MSG = 4,
VHOST_USER_SLAVE_MAX
} VhostUserSlaveRequest;
@@ -401,6 +403,16 @@ void vu_set_queue_handler(VuDev *dev, VuVirtq *vq,
bool vu_set_queue_host_notifier(VuDev *dev, VuVirtq *vq, int fd,
int size, int offset);
+/**
+ * vu_set_vfio_container:
+ * @dev: a VuDev context
+ * @fd: a VFIO container file descriptor
+ *
+ * Set device's VFIO container file descriptor. If called with
+ * -1 @fd, the container is destroyed.
+ */
+bool vu_set_vfio_container(VuDev *dev, int fd);
+
/**
* vu_queue_set_notification:
* @dev: a VuDev context
--
2.18.0