[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20210107092901.19712-4-zhukeqian1@huawei.com>
Date: Thu, 7 Jan 2021 17:28:59 +0800
From: Keqian Zhu <zhukeqian1@...wei.com>
To: <linux-kernel@...r.kernel.org>,
<linux-arm-kernel@...ts.infradead.org>,
<iommu@...ts.linux-foundation.org>, <kvm@...r.kernel.org>,
<kvmarm@...ts.cs.columbia.edu>,
Alex Williamson <alex.williamson@...hat.com>,
Kirti Wankhede <kwankhede@...dia.com>,
Cornelia Huck <cohuck@...hat.com>,
Will Deacon <will@...nel.org>, Marc Zyngier <maz@...nel.org>,
Catalin Marinas <catalin.marinas@....com>
CC: Mark Rutland <mark.rutland@....com>,
James Morse <james.morse@....com>,
Robin Murphy <robin.murphy@....com>,
Joerg Roedel <joro@...tes.org>,
"Daniel Lezcano" <daniel.lezcano@...aro.org>,
Thomas Gleixner <tglx@...utronix.de>,
Suzuki K Poulose <suzuki.poulose@....com>,
Julien Thierry <julien.thierry.kdev@...il.com>,
Andrew Morton <akpm@...ux-foundation.org>,
Alexios Zavras <alexios.zavras@...el.com>,
<wanghaibin.wang@...wei.com>, <jiangkunkun@...wei.com>
Subject: [PATCH 3/5] vfio/iommu_type1: Populate dirty bitmap when attach group
Attach an iommu backend group will potentially access all dma
ranges. We should traverse all dma ranges to mark dirty.
Fixes: d6a4c185660c ("vfio iommu: Implementation of ioctl for dirty pages tracking")
Signed-off-by: Keqian Zhu <zhukeqian1@...wei.com>
---
drivers/vfio/vfio_iommu_type1.c | 18 +++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)
diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c
index 29c8702c3b6e..26b7eb2a5cfc 100644
--- a/drivers/vfio/vfio_iommu_type1.c
+++ b/drivers/vfio/vfio_iommu_type1.c
@@ -255,6 +255,17 @@ static void vfio_dma_populate_bitmap(struct vfio_iommu *iommu,
vfio_dma_populate_bitmap_full(dma, pgsize);
}
+static void vfio_iommu_populate_bitmap(struct vfio_iommu *iommu)
+{
+ struct rb_node *n;
+ struct vfio_dma *dma;
+
+ for (n = rb_first(&iommu->dma_list); n; n = rb_next(n)) {
+ dma = rb_entry(n, struct vfio_dma, node);
+ vfio_dma_populate_bitmap(iommu, dma);
+ }
+}
+
static int vfio_dma_bitmap_alloc_all(struct vfio_iommu *iommu)
{
struct rb_node *n;
@@ -2190,7 +2201,12 @@ static int vfio_iommu_type1_attach_group(void *iommu_data,
* demotes the iommu scope until it declares itself dirty tracking
* capable via the page pinning interface.
*/
- iommu->pinned_page_dirty_scope = false;
+ if (iommu->pinned_page_dirty_scope) {
+ iommu->pinned_page_dirty_scope = false;
+ if (iommu->dirty_page_tracking)
+ vfio_iommu_populate_bitmap(iommu);
+ }
+
mutex_unlock(&iommu->lock);
vfio_iommu_resv_free(&group_resv_regions);
--
2.19.1
Powered by blists - more mailing lists