[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230724110406.107212-13-yi.l.liu@intel.com>
Date: Mon, 24 Jul 2023 04:04:01 -0700
From: Yi Liu <yi.l.liu@...el.com>
To: joro@...tes.org, alex.williamson@...hat.com, jgg@...dia.com,
kevin.tian@...el.com, robin.murphy@....com,
baolu.lu@...ux.intel.com
Cc: cohuck@...hat.com, eric.auger@...hat.com, nicolinc@...dia.com,
kvm@...r.kernel.org, mjrosato@...ux.ibm.com,
chao.p.peng@...ux.intel.com, yi.l.liu@...el.com,
yi.y.sun@...ux.intel.com, peterx@...hat.com, jasowang@...hat.com,
shameerali.kolothum.thodi@...wei.com, lulu@...hat.com,
suravee.suthikulpanit@....com, iommu@...ts.linux.dev,
linux-kernel@...r.kernel.org, linux-kselftest@...r.kernel.org,
zhenzhong.duan@...el.com
Subject: [PATCH v3 12/17] iommufd/selftest: Add .get_resv_regions() for mock_dev
This makes mock_dev to report resv_regions.
Signed-off-by: Yi Liu <yi.l.liu@...el.com>
---
drivers/iommu/iommufd/selftest.c | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/drivers/iommu/iommufd/selftest.c b/drivers/iommu/iommufd/selftest.c
index 271c6c261eb4..e40780db88b5 100644
--- a/drivers/iommu/iommufd/selftest.c
+++ b/drivers/iommu/iommufd/selftest.c
@@ -292,6 +292,32 @@ static void mock_domain_set_plaform_dma_ops(struct device *dev)
*/
}
+static void iommufd_test_get_resv_regions(struct device *dev,
+ struct list_head *head)
+{
+ struct mock_dev *mdev = container_of(dev, struct mock_dev, dev);
+ struct interval_tree_node *reserved, *next;
+
+ down_read(&mdev->reserved_rwsem);
+ for (reserved = interval_tree_iter_first(&mdev->reserved_itree, 0, ULONG_MAX);
+ reserved; reserved = next) {
+ struct iommu_resv_region *resv;
+
+ next = interval_tree_iter_next(reserved, 0, ULONG_MAX);
+ /* Only adds IOMMU_RESV_DIRECT so far */
+ resv = iommu_alloc_resv_region(reserved->start,
+ reserved->last + 1 - reserved->start,
+ IOMMU_READ | IOMMU_WRITE,
+ IOMMU_RESV_DIRECT,
+ GFP_ATOMIC);
+ if (!resv)
+ break;
+
+ list_add_tail(&resv->list, head);
+ }
+ up_read(&mdev->reserved_rwsem);
+}
+
static const struct iommu_ops mock_ops = {
.owner = THIS_MODULE,
.pgsize_bitmap = MOCK_IO_PAGE_SIZE,
@@ -299,6 +325,7 @@ static const struct iommu_ops mock_ops = {
.hw_info = mock_domain_hw_info,
.domain_alloc = mock_domain_alloc,
.capable = mock_domain_capable,
+ .get_resv_regions = iommufd_test_get_resv_regions,
.set_platform_dma_ops = mock_domain_set_plaform_dma_ops,
.default_domain_ops =
&(struct iommu_domain_ops){
--
2.34.1
Powered by blists - more mailing lists