[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <0495a6ca0a025ff3b1e29d24d4a4b30a3e468bde.1693012755.git.jiangdongxu1@huawei.com>
Date: Sat, 26 Aug 2023 09:23:32 +0800
From: Jiang Dongxu <jiangdongxu1@...wei.com>
To: <mst@...hat.com>, <jasowang@...hat.com>
CC: jiangdongxu <jiangdongxu1@...wei.com>,
<virtualization@...ts.linux-foundation.org>,
<linux-kernel@...r.kernel.org>, <longpeng2@...wei.com>,
<eric.fangyi@...wei.com>
Subject: [PATCH 2/2] vhost-vdpa: add uAPI for logging
From: jiangdongxu <jiangdongxu1@...wei.com>
These new ioctl add support for setting bitmaps config,
like base address and buffer size from userspace.
When setup migration, VMM will call VHOST_SET_LOG_BASE and
VHOST_SET_LOG_SIZE to set address and size of buffer used
for storing bitmaps.
Then VMM start live migration, VMM will enable logging
vhost device by set feature VHOST_F_LOG_ALL.
And during live migration iterate, VMM get dirty page info
from vhost device by calling VHOST_LOG_SYNC.
Signed-off-by: jiangdongxu <jiangdongxu1@...wei.com>
---
drivers/vhost/vdpa.c | 49 ++++++++++++++++++++++++++++++++++++++
include/uapi/linux/vhost.h | 4 ++++
2 files changed, 53 insertions(+)
diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c
index b43e8680eee8..75e17d9b136b 100644
--- a/drivers/vhost/vdpa.c
+++ b/drivers/vhost/vdpa.c
@@ -556,6 +556,47 @@ static long vhost_vdpa_resume(struct vhost_vdpa *v)
return ops->resume(vdpa);
}
+static long vhost_vdpa_set_log_base(struct vhost_vdpa *v, u64 __user *argp)
+{
+ struct vdpa_device *vdpa = v->vdpa;
+ const struct vdpa_config_ops *ops = vdpa->config;
+ u64 log;
+
+ if (!ops->set_log_base)
+ return -EOPNOTSUPP;
+
+ if (copy_from_user(&log, argp, sizeof(uint64_t)))
+ return -EFAULT;
+
+ return ops->set_log_base(vdpa, log);
+}
+
+static long vhost_vdpa_set_log_size(struct vhost_vdpa *v, u64 __user *sizep)
+{
+ struct vdpa_device *vdpa = v->vdpa;
+ const struct vdpa_config_ops *ops = vdpa->config;
+ u64 log_size;
+
+ if (!ops->set_log_size)
+ return -EOPNOTSUPP;
+
+ if (copy_from_user(&log_size, sizep, sizeof(log_size)))
+ return -EFAULT;
+
+ return ops->set_log_size(vdpa, log_size);
+}
+
+static long vhost_vdpa_log_sync(struct vhost_vdpa *v)
+{
+ struct vdpa_device *vdpa = v->vdpa;
+ const struct vdpa_config_ops *ops = vdpa->config;
+
+ if (!ops->log_sync)
+ return -EOPNOTSUPP;
+
+ return ops->log_sync(vdpa);
+}
+
static long vhost_vdpa_vring_ioctl(struct vhost_vdpa *v, unsigned int cmd,
void __user *argp)
{
@@ -729,6 +770,14 @@ static long vhost_vdpa_unlocked_ioctl(struct file *filep,
r = -EFAULT;
break;
case VHOST_SET_LOG_BASE:
+ r = vhost_vdpa_set_log_base(v, argp);
+ break;
+ case VHOST_SET_LOG_SIZE:
+ r = vhost_vdpa_set_log_size(v, argp);
+ break;
+ case VHOST_LOG_SYNC:
+ r = vhost_vdpa_log_sync(v);
+ break;
case VHOST_SET_LOG_FD:
r = -ENOIOCTLCMD;
break;
diff --git a/include/uapi/linux/vhost.h b/include/uapi/linux/vhost.h
index f5c48b61ab62..ce9d187432d1 100644
--- a/include/uapi/linux/vhost.h
+++ b/include/uapi/linux/vhost.h
@@ -43,6 +43,10 @@
* The bit is set using an atomic 32 bit operation. */
/* Set base address for logging. */
#define VHOST_SET_LOG_BASE _IOW(VHOST_VIRTIO, 0x04, __u64)
+/* Set buffer size for logging */
+#define VHOST_SET_LOG_SIZE _IOW(VHOST_VIRTIO, 0x05, __u64)
+/* Synchronize logging buffer from kernel space to user space */
+#define VHOST_LOG_SYNC _IO(VHOST_VIRTIO, 0x06)
/* Specify an eventfd file descriptor to signal on log write. */
#define VHOST_SET_LOG_FD _IOW(VHOST_VIRTIO, 0x07, int)
/* By default, a device gets one vhost_worker that its virtqueues share. This
--
2.27.0
Powered by blists - more mailing lists