[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH QEMU v25 12/17] vfio: Add function to start and stop dirty pa
From: |
Cornelia Huck |
Subject: |
Re: [PATCH QEMU v25 12/17] vfio: Add function to start and stop dirty pages tracking |
Date: |
Tue, 23 Jun 2020 12:32:16 +0200 |
On Sun, 21 Jun 2020 01:51:21 +0530
Kirti Wankhede <kwankhede@nvidia.com> wrote:
> Call VFIO_IOMMU_DIRTY_PAGES ioctl to start and stop dirty pages tracking
> for VFIO devices.
>
> Signed-off-by: Kirti Wankhede <kwankhede@nvidia.com>
> Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
> ---
> hw/vfio/migration.c | 36 ++++++++++++++++++++++++++++++++++++
> 1 file changed, 36 insertions(+)
>
> diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c
> index faacea5327cb..e0fbb3a01855 100644
> --- a/hw/vfio/migration.c
> +++ b/hw/vfio/migration.c
> @@ -11,6 +11,7 @@
> #include "qemu/main-loop.h"
> #include "qemu/cutils.h"
> #include <linux/vfio.h>
> +#include <sys/ioctl.h>
>
> #include "sysemu/runstate.h"
> #include "hw/vfio/vfio-common.h"
> @@ -329,6 +330,32 @@ static int vfio_load_device_config_state(QEMUFile *f,
> void *opaque)
> return qemu_file_get_error(f);
> }
>
> +static int vfio_start_dirty_page_tracking(VFIODevice *vbasedev, bool start)
I find 'start' functions that may also stop something a bit confusing.
Maybe vfio_toggle_dirty_page_tracking()?
> +{
> + int ret;
> + VFIOContainer *container = vbasedev->group->container;
> + struct vfio_iommu_type1_dirty_bitmap dirty = {
> + .argsz = sizeof(dirty),
> + };
> +
> + if (start) {
> + if (vbasedev->device_state & VFIO_DEVICE_STATE_SAVING) {
> + dirty.flags = VFIO_IOMMU_DIRTY_PAGES_FLAG_START;
> + } else {
> + return -EINVAL;
> + }
> + } else {
> + dirty.flags = VFIO_IOMMU_DIRTY_PAGES_FLAG_STOP;
> + }
> +
> + ret = ioctl(container->fd, VFIO_IOMMU_DIRTY_PAGES, &dirty);
> + if (ret) {
> + error_report("Failed to set dirty tracking flag 0x%x errno: %d",
> + dirty.flags, errno);
> + }
> + return ret;
> +}
> +
> /* ---------------------------------------------------------------------- */
>
> static int vfio_save_setup(QEMUFile *f, void *opaque)
> @@ -360,6 +387,11 @@ static int vfio_save_setup(QEMUFile *f, void *opaque)
> return ret;
> }
>
> + ret = vfio_start_dirty_page_tracking(vbasedev, true);
> + if (ret) {
> + return ret;
> + }
> +
> qemu_put_be64(f, VFIO_MIG_FLAG_END_OF_STATE);
>
> ret = qemu_file_get_error(f);
> @@ -375,6 +407,8 @@ static void vfio_save_cleanup(void *opaque)
> VFIODevice *vbasedev = opaque;
> VFIOMigration *migration = vbasedev->migration;
>
> + vfio_start_dirty_page_tracking(vbasedev, false);
I suppose we can't do anything useful if stopping dirty page tracking
fails?
> +
> if (migration->region.mmaps) {
> vfio_region_unmap(&migration->region);
> }
> @@ -706,6 +740,8 @@ static void vfio_migration_state_notifier(Notifier
> *notifier, void *data)
> if (ret) {
> error_report("%s: Failed to set state RUNNING", vbasedev->name);
> }
> +
> + vfio_start_dirty_page_tracking(vbasedev, false);
> }
> }
>
- Re: [PATCH QEMU v25 09/17] vfio: Add load state functions to SaveVMHandlers, (continued)
[PATCH QEMU v25 10/17] memory: Set DIRTY_MEMORY_MIGRATION when IOMMU is enabled, Kirti Wankhede, 2020/06/20
[PATCH QEMU v25 11/17] vfio: Get migration capability flags for container, Kirti Wankhede, 2020/06/20
[PATCH QEMU v25 12/17] vfio: Add function to start and stop dirty pages tracking, Kirti Wankhede, 2020/06/20
- Re: [PATCH QEMU v25 12/17] vfio: Add function to start and stop dirty pages tracking,
Cornelia Huck <=
Re: [PATCH QEMU v25 12/17] vfio: Add function to start and stop dirty pages tracking, Alex Williamson, 2020/06/24
[PATCH QEMU v25 13/17] vfio: create mapped iova list when vIOMMU is enabled, Kirti Wankhede, 2020/06/20
[PATCH QEMU v25 14/17] vfio: Add vfio_listener_log_sync to mark dirty pages, Kirti Wankhede, 2020/06/20