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.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
unistd.hstddef.hsys/fcntl.hsys/ioctl.hstdint.hassert.hpoll.hkselftest_harness.h../../../../drivers/iommu/iommufd/iommufd_test.h
Detected Declarations
function set_bitfunction test_bitfunction _test_cmd_mock_domainfunction _test_cmd_mock_domain_flagsfunction _test_cmd_mock_domain_flagsfunction _test_cmd_hwpt_allocfunction _test_cmd_hwpt_invalidatefunction _test_cmd_viommu_invalidatefunction _test_cmd_access_replace_ioasfunction _test_cmd_set_dirty_trackingfunction _test_cmd_get_dirty_bitmapfunction _test_cmd_mock_domain_set_dirtyfunction _test_cmd_mock_domain_set_dirtyfunction _test_cmd_create_accessfunction _test_cmd_destroy_accessfunction _test_cmd_destroy_access_pagesfunction _test_cmd_get_dmabuffunction _test_cmd_revoke_dmabuffunction _test_ioctl_destroyfunction _test_ioctl_ioas_allocfunction _test_ioctl_ioas_mapfunction _test_ioctl_ioas_unmapfunction _test_ioctl_ioas_map_filefunction _test_ioctl_set_temp_memory_limitfunction teardown_iommufdfunction _test_cmd_get_hw_infofunction _test_cmd_get_hw_infofunction _test_cmd_trigger_iopffunction _test_cmd_viommu_allocfunction _test_cmd_viommu_allocfunction _test_cmd_vdevice_allocfunction _test_cmd_hw_queue_allocfunction _test_cmd_veventq_allocfunction _test_cmd_read_veventsfunction _test_cmd_read_veventsfunction _test_cmd_pasid_attachfunction _test_cmd_pasid_replacefunction test_cmd_pasid_check_hwpt
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
- Immediate include surface: `unistd.h`, `stddef.h`, `sys/fcntl.h`, `sys/ioctl.h`, `stdint.h`, `assert.h`, `poll.h`, `kselftest_harness.h`.
- Detected declarations: `function set_bit`, `function test_bit`, `function _test_cmd_mock_domain`, `function _test_cmd_mock_domain_flags`, `function _test_cmd_mock_domain_flags`, `function _test_cmd_hwpt_alloc`, `function _test_cmd_hwpt_invalidate`, `function _test_cmd_viommu_invalidate`, `function _test_cmd_access_replace_ioas`, `function _test_cmd_set_dirty_tracking`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.