@@ -22,6 +22,7 @@ enum {
IOMMU_TEST_OP_DEV_ADD_RESERVED,
IOMMU_TEST_OP_DEV_DEL_RESERVED,
IOMMU_TEST_OP_MD_CHECK_IOTLB,
+ IOMMU_TEST_OP_DEV_CHECK_DATA,
};
enum {
@@ -105,6 +106,9 @@ struct iommu_test_cmd {
struct {
__u32 iotlb;
} check_iotlb;
+ struct {
+ __u32 val;
+ } check_dev_data;
};
__u32 last;
};
@@ -119,6 +123,17 @@ struct iommu_test_hw_info {
__u32 test_reg;
};
+#define IOMMU_DEVICE_DATA_SELFTEST 0xdadbeef
+
+/**
+ * struct iommu_test_device_data
+ *
+ * @val: Should be set to IOMMU_DEVICE_DATA_SELFTEST or unset to 0x0
+ */
+struct iommu_test_device_data {
+ __u32 val;
+};
+
/* Should not be equal to any defined value in enum iommu_hwpt_type */
#define IOMMU_HWPT_TYPE_SELFTTEST 0xdead
@@ -97,6 +97,7 @@ struct mock_dev {
struct device dev;
struct rw_semaphore reserved_rwsem;
struct rb_root_cached reserved_itree;
+ u32 dev_data;
};
struct selftest_obj {
@@ -375,6 +376,23 @@ static void iommufd_test_get_resv_regions(struct device *dev,
up_read(&mdev->reserved_rwsem);
}
+static int mock_domain_set_dev_user_data(struct device *dev,
+ const void *user_data)
+{
+ struct mock_dev *mdev = container_of(dev, struct mock_dev, dev);
+ const struct iommu_test_device_data *data = user_data;
+
+ mdev->dev_data = data->val;
+ return 0;
+}
+
+static void mock_domain_unset_dev_user_data(struct device *dev)
+{
+ struct mock_dev *mdev = container_of(dev, struct mock_dev, dev);
+
+ mdev->dev_data = 0;
+}
+
static const struct iommu_ops mock_ops = {
.owner = THIS_MODULE,
.pgsize_bitmap = MOCK_IO_PAGE_SIZE,
@@ -385,6 +403,9 @@ static const struct iommu_ops mock_ops = {
.capable = mock_domain_capable,
.get_resv_regions = iommufd_test_get_resv_regions,
.set_platform_dma_ops = mock_domain_set_plaform_dma_ops,
+ .set_dev_user_data = mock_domain_set_dev_user_data,
+ .unset_dev_user_data = mock_domain_unset_dev_user_data,
+ .dev_user_data_len = sizeof(struct iommu_test_device_data),
.default_domain_ops =
&(struct iommu_domain_ops){
.free = mock_domain_free,
@@ -833,6 +854,24 @@ static int iommufd_test_md_check_iotlb(struct iommufd_ucmd *ucmd,
return rc;
}
+static int iommufd_test_dev_check_data(struct iommufd_ucmd *ucmd,
+ u32 dev_id, u32 val)
+{
+ struct iommufd_device *idev;
+ struct mock_dev *mdev;
+ int rc = 0;
+
+ idev = iommufd_get_device(ucmd, dev_id);
+ if (IS_ERR(idev))
+ return PTR_ERR(idev);
+ mdev = container_of(idev->dev, struct mock_dev, dev);
+
+ if (mdev->dev_data != val)
+ rc = -EINVAL;
+ iommufd_put_object(&idev->obj);
+ return rc;
+}
+
struct selftest_access {
struct iommufd_access *access;
struct file *file;
@@ -1255,6 +1294,9 @@ int iommufd_test(struct iommufd_ucmd *ucmd)
case IOMMU_TEST_OP_MD_CHECK_IOTLB:
return iommufd_test_md_check_iotlb(ucmd, cmd->id,
cmd->check_iotlb.iotlb);
+ case IOMMU_TEST_OP_DEV_CHECK_DATA:
+ return iommufd_test_dev_check_data(ucmd, cmd->id,
+ cmd->check_dev_data.val);
case IOMMU_TEST_OP_CREATE_ACCESS:
return iommufd_test_create_access(ucmd, cmd->id,
cmd->create_access.flags);