* [PATCH 1/2] vdpa: add log operations
2023-08-26 1:23 [PATCH 0/2] vdpa: Add logging operatins Jiang Dongxu
@ 2023-08-26 1:23 ` Jiang Dongxu
2023-08-26 1:23 ` [PATCH 2/2] vhost-vdpa: add uAPI for logging Jiang Dongxu
2023-09-11 6:56 ` [PATCH 0/2] vdpa: Add logging operatins Jason Wang
2 siblings, 0 replies; 6+ messages in thread
From: Jiang Dongxu @ 2023-08-26 1:23 UTC (permalink / raw)
To: mst, jasowang
Cc: jiangdongxu, virtualization, linux-kernel, longpeng2, eric.fangyi
From: jiangdongxu <jiangdongxu1@huawei.com>
Several new interfaces are introduced to allow vdpa
device logging guest memory during live migration and
return to the VMM.
The set_log_base interface is used to set the base
address for buffer storing bitmaps.
The set_log_size interface is used to set the size
of buffer used for storing bitmaps.
The log_sync interface is used to copy the bitmaps
from kernel space to user space of VMM.
These operations are optional. If they are not implemented,
these operations will return EOPNOTSUPP.
Signed-off-by: jiangdongxu <jiangdongxu1@huawei.com>
---
include/linux/vdpa.h | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/include/linux/vdpa.h b/include/linux/vdpa.h
index db1b0eaef4eb..985eed4f05b3 100644
--- a/include/linux/vdpa.h
+++ b/include/linux/vdpa.h
@@ -327,6 +327,15 @@ struct vdpa_map_file {
* @unbind_mm: Unbind the device from the address space
* bound using the bind_mm callback. (optional)
* @vdev: vdpa device
+ * @set_log_base Set base address for logging. (optional)
+ * @vdev: vdpa device
+ * @base: base address
+ * @set_log_size Set buffer size for logging. (optional)
+ * @vdev: vdpa device
+ * @size: logging buffer size
+ * @log_sync Synchronize logging buffer from kernel space to
+ * user space. (optional)
+ * @vdev: vdpa device
* @free: Free resources that belongs to vDPA (optional)
* @vdev: vdpa device
*/
@@ -396,6 +405,11 @@ struct vdpa_config_ops {
int (*bind_mm)(struct vdpa_device *vdev, struct mm_struct *mm);
void (*unbind_mm)(struct vdpa_device *vdev);
+ /* Log ops */
+ int (*set_log_base)(struct vdpa_device *vdev, uint64_t base);
+ int (*set_log_size)(struct vdpa_device *vdev, uint64_t size);
+ int (*log_sync)(struct vdpa_device *vdev);
+
/* Free device resources */
void (*free)(struct vdpa_device *vdev);
};
--
2.27.0
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH 2/2] vhost-vdpa: add uAPI for logging
2023-08-26 1:23 [PATCH 0/2] vdpa: Add logging operatins Jiang Dongxu
2023-08-26 1:23 ` [PATCH 1/2] vdpa: add log operations Jiang Dongxu
@ 2023-08-26 1:23 ` Jiang Dongxu
2023-09-11 6:56 ` [PATCH 0/2] vdpa: Add logging operatins Jason Wang
2 siblings, 0 replies; 6+ messages in thread
From: Jiang Dongxu @ 2023-08-26 1:23 UTC (permalink / raw)
To: mst, jasowang
Cc: jiangdongxu, virtualization, linux-kernel, longpeng2, eric.fangyi
From: jiangdongxu <jiangdongxu1@huawei.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@huawei.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
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH 0/2] vdpa: Add logging operatins
2023-08-26 1:23 [PATCH 0/2] vdpa: Add logging operatins Jiang Dongxu
2023-08-26 1:23 ` [PATCH 1/2] vdpa: add log operations Jiang Dongxu
2023-08-26 1:23 ` [PATCH 2/2] vhost-vdpa: add uAPI for logging Jiang Dongxu
@ 2023-09-11 6:56 ` Jason Wang
2023-10-18 15:07 ` Michael S. Tsirkin
2023-11-01 13:01 ` Michael S. Tsirkin
2 siblings, 2 replies; 6+ messages in thread
From: Jason Wang @ 2023-09-11 6:56 UTC (permalink / raw)
To: Jiang Dongxu
Cc: mst, virtualization, linux-kernel, longpeng2, eric.fangyi,
eperezma, Siwei Liu
Adding Eugenio and Si Wei.
On Sat, Aug 26, 2023 at 9:24 AM Jiang Dongxu <jiangdongxu1@huawei.com> wrote:
>
> From: jiangdongxu <jiangdongxu1@huawei.com>
>
> Currently, the vdpa device supports suspend and resume operations.
> To support vdpa device live migration, we need to support logging
> operations and device state save/load opertions.
>
> These series introduces some new operations for vdpa devices.
> They allow vdpa to enable logging while vm start live migration.
>
> And I will submit another patches about saving and loading
> vdpa device state later.
Thanks for working on this, I have several questions:
1) Is there an example implementation of the logging in the drivers?
We need a real user in order to merge this.
2) Is the logging based on IOVA or VA? How the DMA isolation is being
done with this? Do we need a SET_LOGGING_ASID uAPI for this? (We had
some discussion on this in the past).
Thanks
>
> jiangdongxu (2):
> vdpa: add log operations
> vhost-vdpa: add uAPI for logging
>
> drivers/vhost/vdpa.c | 49 ++++++++++++++++++++++++++++++++++++++
> include/linux/vdpa.h | 14 +++++++++++
> include/uapi/linux/vhost.h | 4 ++++
> 3 files changed, 67 insertions(+)
>
> --
> 2.27.0
>
^ permalink raw reply [flat|nested] 6+ messages in thread