tools/testing/selftests/iommu/iommufd_utils.h

Source file repositories/reference/linux-study-clean/tools/testing/selftests/iommu/iommufd_utils.h

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/iommu/iommufd_utils.h
Extension
.h
Size
40114 bytes
Lines
1261
Domain
Support Tooling And Documentation
Bucket
tools
Inferred role
Support Tooling And Documentation: implementation source
Status
source implementation candidate

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

while (idx < data_len - cmd.data_len) {
			assert(!*(ptr + idx));
			idx++;
		}
	}

	if (info) {
		if (data_len >= offsetofend(struct iommu_test_hw_info, test_reg))
			assert(info->test_reg == IOMMU_HW_INFO_SELFTEST_REGVAL);
		if (data_len >= offsetofend(struct iommu_test_hw_info, flags))
			assert(!info->flags);
	}

	if (max_pasid)
		*max_pasid = cmd.out_max_pasid_log2;

	if (capabilities)
		*capabilities = cmd.out_capabilities;

	return 0;
}

#define test_cmd_get_hw_info(device_id, data_type, data, data_len)         \
	ASSERT_EQ(0, _test_cmd_get_hw_info(self->fd, device_id, data_type, \
					   data, data_len, NULL, NULL))

#define test_err_get_hw_info(_errno, device_id, data_type, data, data_len) \
	EXPECT_ERRNO(_errno,                                               \
		     _test_cmd_get_hw_info(self->fd, device_id, data_type, \
					   data, data_len, NULL, NULL))

#define test_cmd_get_hw_capabilities(device_id, caps)                        \
	ASSERT_EQ(0, _test_cmd_get_hw_info(self->fd, device_id,              \
					   IOMMU_HW_INFO_TYPE_DEFAULT, NULL, \
					   0, &caps, NULL))

#define test_cmd_get_hw_info_pasid(device_id, max_pasid)                     \
	ASSERT_EQ(0, _test_cmd_get_hw_info(self->fd, device_id,              \
					   IOMMU_HW_INFO_TYPE_DEFAULT, NULL, \
					   0, NULL, max_pasid))

static int _test_ioctl_fault_alloc(int fd, __u32 *fault_id, __u32 *fault_fd)
{
	struct iommu_fault_alloc cmd = {
		.size = sizeof(cmd),
	};
	int ret;

	ret = ioctl(fd, IOMMU_FAULT_QUEUE_ALLOC, &cmd);
	if (ret)
		return ret;
	*fault_id = cmd.out_fault_id;
	*fault_fd = cmd.out_fault_fd;
	return 0;
}

#define test_ioctl_fault_alloc(fault_id, fault_fd)                       \
	({                                                               \
		ASSERT_EQ(0, _test_ioctl_fault_alloc(self->fd, fault_id, \
						     fault_fd));         \
		ASSERT_NE(0, *(fault_id));                               \
		ASSERT_NE(0, *(fault_fd));                               \
	})

static int _test_cmd_trigger_iopf(int fd, __u32 device_id, __u32 pasid,
				  __u32 fault_fd)
{
	struct iommu_test_cmd trigger_iopf_cmd = {
		.size = sizeof(trigger_iopf_cmd),
		.op = IOMMU_TEST_OP_TRIGGER_IOPF,
		.trigger_iopf = {
			.dev_id = device_id,
			.pasid = pasid,
			.grpid = 0x2,
			.perm = IOMMU_PGFAULT_PERM_READ | IOMMU_PGFAULT_PERM_WRITE,
			.addr = 0xdeadbeaf,
		},
	};
	struct iommu_hwpt_page_response response = {
		.code = IOMMUFD_PAGE_RESP_SUCCESS,
	};
	struct iommu_hwpt_pgfault fault = {};
	ssize_t bytes;
	int ret;

	ret = ioctl(fd, _IOMMU_TEST_CMD(IOMMU_TEST_OP_TRIGGER_IOPF), &trigger_iopf_cmd);
	if (ret)
		return ret;

	bytes = read(fault_fd, &fault, sizeof(fault));

Annotation

Implementation Notes