mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
synced 2025-01-17 22:05:08 +00:00
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>
This commit is contained in:
parent
77785117f9
commit
ac8691203c
@ -148,4 +148,22 @@ struct iommu_hwpt_selftest {
|
|||||||
__u32 iotlb;
|
__u32 iotlb;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* Should not be equal to any defined value in enum iommu_hwpt_invalidate_data_type */
|
||||||
|
#define IOMMU_HWPT_INVALIDATE_DATA_SELFTEST 0xdeadbeef
|
||||||
|
#define IOMMU_HWPT_INVALIDATE_DATA_SELFTEST_INVALID 0xdadbeef
|
||||||
|
|
||||||
|
/**
|
||||||
|
* struct iommu_hwpt_invalidate_selftest - Invalidation data for Mock driver
|
||||||
|
* (IOMMU_HWPT_INVALIDATE_DATA_SELFTEST)
|
||||||
|
* @flags: Invalidate flags
|
||||||
|
* @iotlb_id: Invalidate iotlb entry index
|
||||||
|
*
|
||||||
|
* If IOMMU_TEST_INVALIDATE_ALL is set in @flags, @iotlb_id will be ignored
|
||||||
|
*/
|
||||||
|
struct iommu_hwpt_invalidate_selftest {
|
||||||
|
#define IOMMU_TEST_INVALIDATE_FLAG_ALL (1 << 0)
|
||||||
|
__u32 flags;
|
||||||
|
__u32 iotlb_id;
|
||||||
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -473,9 +473,59 @@ static void mock_domain_free_nested(struct iommu_domain *domain)
|
|||||||
kfree(mock_nested);
|
kfree(mock_nested);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
mock_domain_cache_invalidate_user(struct iommu_domain *domain,
|
||||||
|
struct iommu_user_data_array *array)
|
||||||
|
{
|
||||||
|
struct mock_iommu_domain_nested *mock_nested =
|
||||||
|
container_of(domain, struct mock_iommu_domain_nested, domain);
|
||||||
|
struct iommu_hwpt_invalidate_selftest inv;
|
||||||
|
u32 processed = 0;
|
||||||
|
int i = 0, j;
|
||||||
|
int rc = 0;
|
||||||
|
|
||||||
|
if (array->type != IOMMU_HWPT_INVALIDATE_DATA_SELFTEST) {
|
||||||
|
rc = -EINVAL;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
for ( ; i < array->entry_num; i++) {
|
||||||
|
rc = iommu_copy_struct_from_user_array(&inv, array,
|
||||||
|
IOMMU_HWPT_INVALIDATE_DATA_SELFTEST,
|
||||||
|
i, iotlb_id);
|
||||||
|
if (rc)
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (inv.flags & ~IOMMU_TEST_INVALIDATE_FLAG_ALL) {
|
||||||
|
rc = -EOPNOTSUPP;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (inv.iotlb_id > MOCK_NESTED_DOMAIN_IOTLB_ID_MAX) {
|
||||||
|
rc = -EINVAL;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (inv.flags & IOMMU_TEST_INVALIDATE_FLAG_ALL) {
|
||||||
|
/* Invalidate all mock iotlb entries and ignore iotlb_id */
|
||||||
|
for (j = 0; j < MOCK_NESTED_DOMAIN_IOTLB_NUM; j++)
|
||||||
|
mock_nested->iotlb[j] = 0;
|
||||||
|
} else {
|
||||||
|
mock_nested->iotlb[inv.iotlb_id] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
processed++;
|
||||||
|
}
|
||||||
|
|
||||||
|
out:
|
||||||
|
array->entry_num = processed;
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
static struct iommu_domain_ops domain_nested_ops = {
|
static struct iommu_domain_ops domain_nested_ops = {
|
||||||
.free = mock_domain_free_nested,
|
.free = mock_domain_free_nested,
|
||||||
.attach_dev = mock_domain_nop_attach,
|
.attach_dev = mock_domain_nop_attach,
|
||||||
|
.cache_invalidate_user = mock_domain_cache_invalidate_user,
|
||||||
};
|
};
|
||||||
|
|
||||||
static inline struct iommufd_hw_pagetable *
|
static inline struct iommufd_hw_pagetable *
|
||||||
|
Loading…
x
Reference in New Issue
Block a user