Skip to content

Commit b2b67c9

Browse files
committed
iommufd: Organize the mock domain alloc functions closer to Joerg's tree
Patches in Joerg's iommu tree to convert the mock driver to use domain_alloc_paging() that clash badly with the way the selftest changes for nesting were structured. Massage the selftest so that it looks closer the code after the domain_alloc_paging() conversion to ease the merge. Change __mock_domain_alloc_paging() into mock_domain_alloc_paging() in the same way as the iommu tree. The merge resolution then trivially takes both and deletes mock_domain_alloc(). Link: https://lore.kernel.org/r/0-v1-90a855762c96+19de-mock_merge_jgg@nvidia.com Reviewed-by: Nicolin Chen <nicolinc@nvidia.com> Reviewed-by: Kevin Tian <kevin.tian@intel.com> Reviewed-by: Yi Liu <yi.l.liu@intel.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
1 parent 2e22aac commit b2b67c9

1 file changed

Lines changed: 16 additions & 19 deletions

File tree

drivers/iommu/iommufd/selftest.c

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
static DECLARE_FAULT_ATTR(fail_iommufd);
2121
static struct dentry *dbgfs_root;
2222
static struct platform_device *selftest_iommu_dev;
23+
static const struct iommu_ops mock_ops;
24+
static struct iommu_domain_ops domain_nested_ops;
2325

2426
size_t iommufd_test_memory_limit = 65536;
2527

@@ -222,24 +224,18 @@ const struct iommu_dirty_ops dirty_ops = {
222224
.read_and_clear_dirty = mock_domain_read_and_clear_dirty,
223225
};
224226

225-
static const struct iommu_ops mock_ops;
226-
static struct iommu_domain_ops domain_nested_ops;
227-
228-
static struct iommu_domain *
229-
__mock_domain_alloc_paging(unsigned int iommu_domain_type, bool needs_dirty_ops)
227+
static struct iommu_domain *mock_domain_alloc_paging(struct device *dev)
230228
{
231229
struct mock_iommu_domain *mock;
232230

233231
mock = kzalloc(sizeof(*mock), GFP_KERNEL);
234232
if (!mock)
235-
return ERR_PTR(-ENOMEM);
233+
return NULL;
236234
mock->domain.geometry.aperture_start = MOCK_APERTURE_START;
237235
mock->domain.geometry.aperture_end = MOCK_APERTURE_LAST;
238236
mock->domain.pgsize_bitmap = MOCK_IO_PAGE_SIZE;
239237
mock->domain.ops = mock_ops.default_domain_ops;
240-
if (needs_dirty_ops)
241-
mock->domain.dirty_ops = &dirty_ops;
242-
mock->domain.type = iommu_domain_type;
238+
mock->domain.type = IOMMU_DOMAIN_UNMANAGED;
243239
xa_init(&mock->pfns);
244240
return &mock->domain;
245241
}
@@ -264,16 +260,11 @@ __mock_domain_alloc_nested(struct mock_iommu_domain *mock_parent,
264260

265261
static struct iommu_domain *mock_domain_alloc(unsigned int iommu_domain_type)
266262
{
267-
struct iommu_domain *domain;
268-
269263
if (iommu_domain_type == IOMMU_DOMAIN_BLOCKED)
270264
return &mock_blocking_domain;
271-
if (iommu_domain_type != IOMMU_DOMAIN_UNMANAGED)
272-
return NULL;
273-
domain = __mock_domain_alloc_paging(iommu_domain_type, false);
274-
if (IS_ERR(domain))
275-
domain = NULL;
276-
return domain;
265+
if (iommu_domain_type == IOMMU_DOMAIN_UNMANAGED)
266+
return mock_domain_alloc_paging(NULL);
267+
return NULL;
277268
}
278269

279270
static struct iommu_domain *
@@ -290,14 +281,20 @@ mock_domain_alloc_user(struct device *dev, u32 flags,
290281
struct mock_dev *mdev = container_of(dev, struct mock_dev, dev);
291282
bool has_dirty_flag = flags & IOMMU_HWPT_ALLOC_DIRTY_TRACKING;
292283
bool no_dirty_ops = mdev->flags & MOCK_FLAGS_DEVICE_NO_DIRTY;
284+
struct iommu_domain *domain;
293285

294286
if (flags & (~(IOMMU_HWPT_ALLOC_NEST_PARENT |
295287
IOMMU_HWPT_ALLOC_DIRTY_TRACKING)))
296288
return ERR_PTR(-EOPNOTSUPP);
297289
if (user_data || (has_dirty_flag && no_dirty_ops))
298290
return ERR_PTR(-EOPNOTSUPP);
299-
return __mock_domain_alloc_paging(IOMMU_DOMAIN_UNMANAGED,
300-
has_dirty_flag);
291+
domain = mock_domain_alloc_paging(NULL);
292+
if (!domain)
293+
return ERR_PTR(-ENOMEM);
294+
if (has_dirty_flag)
295+
container_of(domain, struct mock_iommu_domain, domain)
296+
->domain.dirty_ops = &dirty_ops;
297+
return domain;
301298
}
302299

303300
/* must be mock_domain_nested */

0 commit comments

Comments
 (0)