On Fri, 3 Feb 2017 16:22:36 +0800
Peter Xu <[email protected]> wrote:
> In this patch, IOMMUNotifier.{start|end} are introduced to store section
> information for a specific notifier. When notification occurs, we not
> only check the notification type (MAP|UNMAP), but also check whether the
> notified iova range overlaps with the range of specific IOMMU notifier,
> and skip those notifiers if not in the listened range.
>
> When removing an region, we need to make sure we removed the correct
> VFIOGuestIOMMU by checking the IOMMUNotifier.start address as well.
>
> Suggested-by: David Gibson <[email protected]>
> Signed-off-by: Peter Xu <[email protected]>
> ---
> hw/vfio/common.c | 12 +++++++++---
> hw/virtio/vhost.c | 4 ++--
> include/exec/memory.h | 19 ++++++++++++++++++-
> memory.c | 9 +++++++++
> 4 files changed, 38 insertions(+), 6 deletions(-)
>
> diff --git a/hw/vfio/common.c b/hw/vfio/common.c
> index f3ba9b9..6b33b9f 100644
> --- a/hw/vfio/common.c
> +++ b/hw/vfio/common.c
> @@ -478,8 +478,13 @@ static void vfio_listener_region_add(MemoryListener
> *listener,
> giommu->iommu_offset = section->offset_within_address_space -
> section->offset_within_region;
> giommu->container = container;
> - giommu->n.notify = vfio_iommu_map_notify;
> - giommu->n.notifier_flags = IOMMU_NOTIFIER_ALL;
> + llend = int128_add(int128_make64(section->offset_within_region),
> + section->size);
> + llend = int128_sub(llend, int128_one());
> + iommu_notifier_init(&giommu->n, vfio_iommu_map_notify,
> + IOMMU_NOTIFIER_ALL,
> + section->offset_within_region,
> + int128_get64(llend));
> QLIST_INSERT_HEAD(&container->giommu_list, giommu, giommu_next);
>
> memory_region_register_iommu_notifier(giommu->iommu, &giommu->n);
> @@ -550,7 +555,8 @@ static void vfio_listener_region_del(MemoryListener
> *listener,
> VFIOGuestIOMMU *giommu;
>
> QLIST_FOREACH(giommu, &container->giommu_list, giommu_next) {
> - if (giommu->iommu == section->mr) {
> + if (giommu->iommu == section->mr &&
> + giommu->n.start == section->offset_within_region) {
> memory_region_unregister_iommu_notifier(giommu->iommu,
> &giommu->n);
> QLIST_REMOVE(giommu, giommu_next);
Acked-by: Alex Williamson <[email protected]>