Skip to content

Commit ac86912

Browse files
nicolincjgunthorpe
authored andcommitted
iommufd/selftest: Add mock_domain_cache_invalidate_user support
Add mock_domain_cache_invalidate_user() data structure to support user space selftest program to cover user cache invalidation pathway. Link: https://lore.kernel.org/r/20240111041015.47920-5-yi.l.liu@intel.com Reviewed-by: Kevin Tian <kevin.tian@intel.com> Signed-off-by: Nicolin Chen <nicolinc@nvidia.com> Co-developed-by: Yi Liu <yi.l.liu@intel.com> Signed-off-by: Yi Liu <yi.l.liu@intel.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
1 parent 7778511 commit ac86912

2 files changed

Lines changed: 68 additions & 0 deletions

File tree

drivers/iommu/iommufd/iommufd_test.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,4 +148,22 @@ struct iommu_hwpt_selftest {
148148
__u32 iotlb;
149149
};
150150

151+
/* Should not be equal to any defined value in enum iommu_hwpt_invalidate_data_type */
152+
#define IOMMU_HWPT_INVALIDATE_DATA_SELFTEST 0xdeadbeef
153+
#define IOMMU_HWPT_INVALIDATE_DATA_SELFTEST_INVALID 0xdadbeef
154+
155+
/**
156+
* struct iommu_hwpt_invalidate_selftest - Invalidation data for Mock driver
157+
* (IOMMU_HWPT_INVALIDATE_DATA_SELFTEST)
158+
* @flags: Invalidate flags
159+
* @iotlb_id: Invalidate iotlb entry index
160+
*
161+
* If IOMMU_TEST_INVALIDATE_ALL is set in @flags, @iotlb_id will be ignored
162+
*/
163+
struct iommu_hwpt_invalidate_selftest {
164+
#define IOMMU_TEST_INVALIDATE_FLAG_ALL (1 << 0)
165+
__u32 flags;
166+
__u32 iotlb_id;
167+
};
168+
151169
#endif

drivers/iommu/iommufd/selftest.c

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,9 +473,59 @@ static void mock_domain_free_nested(struct iommu_domain *domain)
473473
kfree(mock_nested);
474474
}
475475

476+
static int
477+
mock_domain_cache_invalidate_user(struct iommu_domain *domain,
478+
struct iommu_user_data_array *array)
479+
{
480+
struct mock_iommu_domain_nested *mock_nested =
481+
container_of(domain, struct mock_iommu_domain_nested, domain);
482+
struct iommu_hwpt_invalidate_selftest inv;
483+
u32 processed = 0;
484+
int i = 0, j;
485+
int rc = 0;
486+
487+
if (array->type != IOMMU_HWPT_INVALIDATE_DATA_SELFTEST) {
488+
rc = -EINVAL;
489+
goto out;
490+
}
491+
492+
for ( ; i < array->entry_num; i++) {
493+
rc = iommu_copy_struct_from_user_array(&inv, array,
494+
IOMMU_HWPT_INVALIDATE_DATA_SELFTEST,
495+
i, iotlb_id);
496+
if (rc)
497+
break;
498+
499+
if (inv.flags & ~IOMMU_TEST_INVALIDATE_FLAG_ALL) {
500+
rc = -EOPNOTSUPP;
501+
break;
502+
}
503+
504+
if (inv.iotlb_id > MOCK_NESTED_DOMAIN_IOTLB_ID_MAX) {
505+
rc = -EINVAL;
506+
break;
507+
}
508+
509+
if (inv.flags & IOMMU_TEST_INVALIDATE_FLAG_ALL) {
510+
/* Invalidate all mock iotlb entries and ignore iotlb_id */
511+
for (j = 0; j < MOCK_NESTED_DOMAIN_IOTLB_NUM; j++)
512+
mock_nested->iotlb[j] = 0;
513+
} else {
514+
mock_nested->iotlb[inv.iotlb_id] = 0;
515+
}
516+
517+
processed++;
518+
}
519+
520+
out:
521+
array->entry_num = processed;
522+
return rc;
523+
}
524+
476525
static struct iommu_domain_ops domain_nested_ops = {
477526
.free = mock_domain_free_nested,
478527
.attach_dev = mock_domain_nop_attach,
528+
.cache_invalidate_user = mock_domain_cache_invalidate_user,
479529
};
480530

481531
static inline struct iommufd_hw_pagetable *

0 commit comments

Comments
 (0)