lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <5b192832f6a8a02e24ba0712b1f9ab20735fd583.1690487690.git.nicolinc@nvidia.com>
Date:   Thu, 27 Jul 2023 14:09:43 -0700
From:   Nicolin Chen <nicolinc@...dia.com>
To:     <jgg@...dia.com>, <kevin.tian@...el.com>
CC:     <robin.murphy@....com>, <eric.auger@...hat.com>,
        <yi.l.liu@...el.com>, <baolu.lu@...ux.intel.com>,
        <will@...nel.org>, <joro@...tes.org>,
        <shameerali.kolothum.thodi@...wei.com>, <jean-philippe@...aro.org>,
        <linux-arm-kernel@...ts.infradead.org>, <iommu@...ts.linux.dev>,
        <linux-kernel@...r.kernel.org>
Subject: [PATCH v5 4/4] iommufd/selftest: Add coverage for IOMMU_SET/UNSET_DEV_DATA

Add a new IOMMU_TEST_OP_DEV_CHECK_DATA to verify whether the dev_data
is properly set/unset by the IOMMU_SET/UNSET_DEV_DATA.

Signed-off-by: Nicolin Chen <nicolinc@...dia.com>
---
 tools/testing/selftests/iommu/iommufd.c       | 22 +++++++
 tools/testing/selftests/iommu/iommufd_utils.h | 59 +++++++++++++++++++
 2 files changed, 81 insertions(+)

diff --git a/tools/testing/selftests/iommu/iommufd.c b/tools/testing/selftests/iommu/iommufd.c
index bf0082d88a38..b437b890e4f5 100644
--- a/tools/testing/selftests/iommu/iommufd.c
+++ b/tools/testing/selftests/iommu/iommufd.c
@@ -123,6 +123,8 @@ TEST_F(iommufd, cmd_length)
 	TEST_LENGTH(iommu_ioas_copy, IOMMU_IOAS_COPY);
 	TEST_LENGTH(iommu_ioas_unmap, IOMMU_IOAS_UNMAP);
 	TEST_LENGTH(iommu_option, IOMMU_OPTION);
+	TEST_LENGTH(iommu_set_dev_data, IOMMU_SET_DEV_DATA);
+	TEST_LENGTH(iommu_unset_dev_data, IOMMU_UNSET_DEV_DATA);
 	TEST_LENGTH(iommu_vfio_ioas, IOMMU_VFIO_IOAS);
 #undef TEST_LENGTH
 }
@@ -1517,6 +1519,26 @@ TEST_F(iommufd_mock_domain, alloc_hwpt)
 	}
 }
 
+TEST_F(iommufd_mock_domain, set_dev_data)
+{
+	struct iommu_test_device_data dev_data = {
+		.val = IOMMU_DEVICE_DATA_SELFTEST,
+	};
+	int i;
+
+	for (i = 0; i != variant->mock_domains; i++) {
+		test_err_set_dev_data(ENOENT, 0, &dev_data);
+		test_err_set_dev_data(EINVAL, self->idev_ids[i], NULL);
+		test_cmd_set_dev_data(self->idev_ids[i], &dev_data);
+		test_err_set_dev_data(EEXIST, self->idev_ids[i], &dev_data);
+		test_cmd_dev_check_data(self->idev_ids[i], dev_data.val);
+		test_err_unset_dev_data(ENOENT, 0);
+		test_cmd_unset_dev_data(self->idev_ids[i]);
+		test_err_unset_dev_data(ENOENT, self->idev_ids[i]);
+		test_cmd_dev_check_data(self->idev_ids[i], 0);
+	}
+}
+
 /* VFIO compatibility IOCTLs */
 
 TEST_F(iommufd, simple_ioctls)
diff --git a/tools/testing/selftests/iommu/iommufd_utils.h b/tools/testing/selftests/iommu/iommufd_utils.h
index 9b3e5f36c4a3..eb756fffbc89 100644
--- a/tools/testing/selftests/iommu/iommufd_utils.h
+++ b/tools/testing/selftests/iommu/iommufd_utils.h
@@ -444,3 +444,62 @@ static int _test_cmd_get_hw_info(int fd, __u32 device_id,
 	EXPECT_ERRNO(_errno,                                    \
 		     _test_cmd_get_hw_info(self->fd, device_id, \
 						  data_len, data))
+
+#define test_cmd_dev_check_data(device_id, expected)                           \
+	({                                                                     \
+		struct iommu_test_cmd test_cmd = {                             \
+			.size = sizeof(test_cmd),                              \
+			.op = IOMMU_TEST_OP_DEV_CHECK_DATA,                    \
+			.id = device_id,                                       \
+			.check_dev_data = { .val = expected },                 \
+		};                                                             \
+		ASSERT_EQ(0,                                                   \
+			  ioctl(self->fd,                                      \
+				_IOMMU_TEST_CMD(IOMMU_TEST_OP_DEV_CHECK_DATA), \
+				&test_cmd));                                   \
+	})
+
+static int _test_cmd_set_dev_data(int fd, __u32 device_id,
+				  struct iommu_test_device_data *dev_data)
+{
+	struct iommu_set_dev_data cmd = {
+		.size = sizeof(cmd),
+		.dev_id = device_id,
+		.data_uptr = (uint64_t)dev_data,
+		.data_len = sizeof(*dev_data),
+	};
+	int ret;
+
+	ret = ioctl(fd, IOMMU_SET_DEV_DATA, &cmd);
+	if (ret)
+		return ret;
+	return 0;
+}
+
+#define test_cmd_set_dev_data(device_id, dev_data) \
+	ASSERT_EQ(0, _test_cmd_set_dev_data(self->fd, device_id, dev_data))
+
+#define test_err_set_dev_data(_errno, device_id, dev_data) \
+	EXPECT_ERRNO(_errno,                               \
+		     _test_cmd_set_dev_data(self->fd, device_id, dev_data))
+
+static int _test_cmd_unset_dev_data(int fd, __u32 device_id)
+{
+	struct iommu_unset_dev_data cmd = {
+		.size = sizeof(cmd),
+		.dev_id = device_id,
+	};
+	int ret;
+
+	ret = ioctl(fd, IOMMU_UNSET_DEV_DATA, &cmd);
+	if (ret)
+		return ret;
+	return 0;
+}
+
+#define test_cmd_unset_dev_data(device_id) \
+	ASSERT_EQ(0, _test_cmd_unset_dev_data(self->fd, device_id))
+
+#define test_err_unset_dev_data(_errno, device_id) \
+	EXPECT_ERRNO(_errno,                       \
+		     _test_cmd_unset_dev_data(self->fd, device_id))
-- 
2.41.0

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ