From: Yulei Zhang <yulei.zhang@intel.com>
To: qemu-devel@nongnu.org
Cc: kevin.tian@intel.com, zhenyuw@linux.intel.com,
kwankhede@nvidia.com, alex.williamson@redhat.com,
Yulei Zhang <yulei.zhang@intel.com>
Subject: [Qemu-devel] [PATCH V3 4/4] vifo: introduce new VFIO ioctl VFIO_IOMMU_GET_DIRTY_BITMAP
Date: Mon, 5 Mar 2018 14:00:53 +0800 [thread overview]
Message-ID: <1520229653-10658-5-git-send-email-yulei.zhang@intel.com> (raw)
In-Reply-To: <1520229653-10658-1-git-send-email-yulei.zhang@intel.com>
New VFIO ioctl VFIO_IOMMU_GET_DIRTY_BITMAP is used to fetch the
bitmap of pinned memory in iommu container, we need copy those
memory to the target during the migration as they are dirtied by
mdev devices.
Signed-off-by: Yulei Zhang <yulei.zhang@intel.com>
---
hw/vfio/common.c | 34 ++++++++++++++++++++++++++++++++++
| 14 ++++++++++++++
2 files changed, 48 insertions(+)
diff --git a/hw/vfio/common.c b/hw/vfio/common.c
index 7b2924c..a952554 100644
--- a/hw/vfio/common.c
+++ b/hw/vfio/common.c
@@ -35,6 +35,7 @@
#include "sysemu/kvm.h"
#include "trace.h"
#include "qapi/error.h"
+#include "exec/ram_addr.h"
struct vfio_group_head vfio_group_list =
QLIST_HEAD_INITIALIZER(vfio_group_list);
@@ -624,9 +625,42 @@ static void vfio_listener_region_del(MemoryListener *listener,
}
}
+static void vfio_log_sync(MemoryListener *listener,
+ MemoryRegionSection *section)
+{
+ VFIOContainer *container = container_of(listener, VFIOContainer, listener);
+ VFIOGroup *group = QLIST_FIRST(&container->group_list);
+ VFIODevice *vbasedev;
+ QLIST_FOREACH(vbasedev, &group->device_list, next) {
+ if (vbasedev->device_state == VFIO_DEVICE_START) {
+ return;
+ }
+ }
+
+ struct vfio_iommu_get_dirty_bitmap *d;
+ ram_addr_t size = int128_get64(section->size);
+ unsigned long page_nr = size >> TARGET_PAGE_BITS;
+ unsigned long bitmap_size =
+ (BITS_TO_LONGS(page_nr) + 1) * sizeof(unsigned long);
+ d = g_malloc0(sizeof(*d) + bitmap_size);
+ d->start_addr = section->offset_within_address_space;
+ d->page_nr = page_nr;
+
+ if (ioctl(container->fd, VFIO_IOMMU_GET_DIRTY_BITMAP, d)) {
+ error_report("vfio: Failed to fetch dirty pages for migration");
+ goto exit;
+ }
+
+ cpu_physical_memory_set_dirty_lebitmap((unsigned long *)&d->dirty_bitmap,
+ d->start_addr, d->page_nr);
+exit:
+ g_free(d);
+}
+
static const MemoryListener vfio_memory_listener = {
.region_add = vfio_listener_region_add,
.region_del = vfio_listener_region_del,
+ .log_sync = vfio_log_sync,
};
static void vfio_listener_release(VFIOContainer *container)
--git a/linux-headers/linux/vfio.h b/linux-headers/linux/vfio.h
index 4451a8f..a41f73b 100644
--- a/linux-headers/linux/vfio.h
+++ b/linux-headers/linux/vfio.h
@@ -574,6 +574,20 @@ struct vfio_iommu_type1_dma_unmap {
#define VFIO_IOMMU_ENABLE _IO(VFIO_TYPE, VFIO_BASE + 15)
#define VFIO_IOMMU_DISABLE _IO(VFIO_TYPE, VFIO_BASE + 16)
+/**
+ * VFIO_IOMMU_GET_DIRTY_BITMAP - _IOW(VFIO_TYPE, VFIO_BASE + 17,
+ * struct vfio_iommu_get_dirty_bitmap)
+ *
+ * Return: 0 on success, -errno on failure.
+ */
+struct vfio_iommu_get_dirty_bitmap {
+ __u64 start_addr;
+ __u64 page_nr;
+ __u8 dirty_bitmap[];
+};
+
+#define VFIO_IOMMU_GET_DIRTY_BITMAP _IO(VFIO_TYPE, VFIO_BASE + 17)
+
/* -------- Additional API for SPAPR TCE (Server POWERPC) IOMMU -------- */
/*
--
2.7.4
next prev parent reply other threads:[~2018-03-05 5:55 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-05 6:00 [Qemu-devel] [PATCH V3 0/4] vfio: Introduce Live migration capability to vfio_mdev device Yulei Zhang
2018-03-05 6:00 ` no-reply
2018-03-05 6:00 ` [Qemu-devel] [PATCH V3 1/4] vfio: introduce a new VFIO subregion for mdev device migration support Yulei Zhang
2018-03-09 11:43 ` Dr. David Alan Gilbert
2018-03-13 8:27 ` Zhang, Yulei
2018-03-05 6:00 ` [Qemu-devel] [PATCH V3 2/4] vfio: Add vm status change callback to stop/restart the mdev device Yulei Zhang
2018-03-05 6:00 ` [Qemu-devel] [PATCH V3 3/4] vfio: Add struct vfio_vmstate_info to introduce put/get callback funtion for vfio device status save/restore Yulei Zhang
2018-03-09 11:59 ` Dr. David Alan Gilbert
2018-03-14 8:52 ` Zhang, Yulei
2018-03-05 6:00 ` Yulei Zhang [this message]
2018-03-05 13:02 ` [Qemu-devel] [PATCH V3 0/4] vfio: Introduce Live migration capability to vfio_mdev device Kirti Wankhede
2018-03-06 13:34 ` Zhang, Yulei
2018-03-07 2:11 ` Tian, Kevin
2018-03-12 22:21 ` Alex Williamson
2018-03-13 8:16 ` Zhang, Yulei
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1520229653-10658-5-git-send-email-yulei.zhang@intel.com \
--to=yulei.zhang@intel.com \
--cc=alex.williamson@redhat.com \
--cc=kevin.tian@intel.com \
--cc=kwankhede@nvidia.com \
--cc=qemu-devel@nongnu.org \
--cc=zhenyuw@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).