tools/testing/selftests/iommu/iommufd.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/iommu/iommufd.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/iommu/iommufd.c- Extension
.c- Size
- 105166 bytes
- Lines
- 3617
- 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.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
asm/unistd.hstdlib.hsys/capability.hsys/mman.hsys/eventfd.hlinux/vfio.hiommufd_utils.h
Detected Declarations
struct iommu_test_hw_info_buffer_largerfunction get_huge_page_sizefunction __attribute__function drop_cap_ipc_lockfunction get_proc_status_valuefunction get_vm_pinnedfunction get_vm_lockedfunction check_access_rwfunction test_basic_mmapfunction test_basic_filefunction is_filledfunction check_vfio_info_cap_chainfunction shuffle_array
Annotated Snippet
struct iommu_test_hw_info_buffer_larger {
struct iommu_test_hw_info info;
uint64_t trailing_bytes;
} buffer_larger;
if (self->device_id) {
uint8_t max_pasid = 0;
/* Provide a zero-size user_buffer */
test_cmd_get_hw_info(self->device_id,
IOMMU_HW_INFO_TYPE_DEFAULT, NULL, 0);
/* Provide a user_buffer with exact size */
test_cmd_get_hw_info(self->device_id,
IOMMU_HW_INFO_TYPE_DEFAULT, &buffer_exact,
sizeof(buffer_exact));
/* Request for a wrong data_type, and a correct one */
test_err_get_hw_info(EOPNOTSUPP, self->device_id,
IOMMU_HW_INFO_TYPE_SELFTEST + 1,
&buffer_exact, sizeof(buffer_exact));
test_cmd_get_hw_info(self->device_id,
IOMMU_HW_INFO_TYPE_SELFTEST, &buffer_exact,
sizeof(buffer_exact));
/*
* Provide a user_buffer with size larger than the exact size to check if
* kernel zero the trailing bytes.
*/
test_cmd_get_hw_info(self->device_id,
IOMMU_HW_INFO_TYPE_DEFAULT, &buffer_larger,
sizeof(buffer_larger));
/*
* Provide a user_buffer with size smaller than the exact size to check if
* the fields within the size range still gets updated.
*/
test_cmd_get_hw_info(self->device_id,
IOMMU_HW_INFO_TYPE_DEFAULT, &buffer_exact,
offsetofend(struct iommu_test_hw_info,
flags));
test_cmd_get_hw_info_pasid(self->device_id, &max_pasid);
ASSERT_EQ(0, max_pasid);
if (variant->pasid_capable) {
test_cmd_get_hw_info_pasid(self->device_pasid_id,
&max_pasid);
ASSERT_EQ(MOCK_PASID_WIDTH, max_pasid);
}
} else {
test_err_get_hw_info(ENOENT, self->device_id,
IOMMU_HW_INFO_TYPE_DEFAULT, &buffer_exact,
sizeof(buffer_exact));
test_err_get_hw_info(ENOENT, self->device_id,
IOMMU_HW_INFO_TYPE_DEFAULT, &buffer_larger,
sizeof(buffer_larger));
}
}
TEST_F(iommufd_ioas, area)
{
int i;
/* Unmap fails if nothing is mapped */
for (i = 0; i != 10; i++)
test_err_ioctl_ioas_unmap(ENOENT, i * PAGE_SIZE, PAGE_SIZE);
/* Unmap works */
for (i = 0; i != 10; i++)
test_ioctl_ioas_map_fixed(buffer, PAGE_SIZE,
self->base_iova + i * PAGE_SIZE);
for (i = 0; i != 10; i++)
test_ioctl_ioas_unmap(self->base_iova + i * PAGE_SIZE,
PAGE_SIZE);
/* Split fails */
test_ioctl_ioas_map_fixed(buffer, PAGE_SIZE * 2,
self->base_iova + 16 * PAGE_SIZE);
test_err_ioctl_ioas_unmap(ENOENT, self->base_iova + 16 * PAGE_SIZE,
PAGE_SIZE);
test_err_ioctl_ioas_unmap(ENOENT, self->base_iova + 17 * PAGE_SIZE,
PAGE_SIZE);
/* Over map fails */
test_err_ioctl_ioas_map_fixed(EEXIST, buffer, PAGE_SIZE * 2,
self->base_iova + 16 * PAGE_SIZE);
test_err_ioctl_ioas_map_fixed(EEXIST, buffer, PAGE_SIZE,
self->base_iova + 16 * PAGE_SIZE);
test_err_ioctl_ioas_map_fixed(EEXIST, buffer, PAGE_SIZE,
self->base_iova + 17 * PAGE_SIZE);
test_err_ioctl_ioas_map_fixed(EEXIST, buffer, PAGE_SIZE * 2,
self->base_iova + 15 * PAGE_SIZE);
test_err_ioctl_ioas_map_fixed(EEXIST, buffer, PAGE_SIZE * 3,
self->base_iova + 15 * PAGE_SIZE);
Annotation
- Immediate include surface: `asm/unistd.h`, `stdlib.h`, `sys/capability.h`, `sys/mman.h`, `sys/eventfd.h`, `linux/vfio.h`, `iommufd_utils.h`.
- Detected declarations: `struct iommu_test_hw_info_buffer_larger`, `function get_huge_page_size`, `function __attribute__`, `function drop_cap_ipc_lock`, `function get_proc_status_value`, `function get_vm_pinned`, `function get_vm_locked`, `function check_access_rw`, `function test_basic_mmap`, `function test_basic_file`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
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.