vifo: introduce new VFIO ioctl VFIO_IOMMU_GET_DIRTY_BITMAP
RFC PATCH v4 4/4 vifo: introduce new VFIO ioctl VFIO_IOMMU_GET_DIRTY_BITMAP
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.
--- hw/vfio/common.c | 34 ++++++++++++++++++++++++++++++++++ linux-headers/linux/vfio.h | 14 ++++++++++++++ 2 files changed, 48 insertions(+)
hw/vfio/common.c +34 -0
@@ -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)
linux-headers/linux/vfio.h +14 -0
@@ -589,6 +589,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 -------- */ /*
Signature · 1 line
2.7.4
Quoted 4 lines · Yulei Zhang
New VFIO ioctl
VFIO_IOMMU_GET_DIRTY_BITMAPis 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.
[meta-comment]
This patch, and the other 3 in the series, were sent with no 'In-Reply-To:' or 'References:' headers; as such, they were not threaded to the 0/4 cover letter ('Message-Id:
<[email protected]>'). In the future, you'll want to make sure that proper threading is preserved in the mail messages, as it makes it a lot easier when each message in the series is not a new top-level thread.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org