drivers/iommu/iommufd/selftest.c
Source file repositories/reference/linux-study-clean/drivers/iommu/iommufd/selftest.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iommu/iommufd/selftest.c- Extension
.c- Size
- 57262 bytes
- Lines
- 2241
- Domain
- Driver Families
- Bucket
- drivers/iommu
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/anon_inodes.hlinux/debugfs.hlinux/dma-buf.hlinux/dma-resv.hlinux/fault-inject.hlinux/file.hlinux/iommu.hlinux/platform_device.hlinux/slab.hlinux/xarray.huapi/linux/iommufd.hlinux/generic_pt/iommu.h../iommu-pages.h../iommu-priv.hio_pagetable.hiommufd_private.hiommufd_test.h
Detected Declarations
struct mock_bus_typestruct syz_layoutstruct mock_iommu_domainstruct mock_iommu_domain_nestedstruct mock_viommustruct mock_hw_queuestruct mock_devstruct selftest_objstruct selftest_accessstruct selftest_access_itemstruct iommufd_test_dma_bufenum selftest_obj_typefunction __iommufd_test_syz_conv_iovafunction iommufd_test_syz_conv_iovafunction iommufd_test_syz_conv_iova_idfunction to_mock_domainfunction to_mock_nestedfunction to_mock_hw_queuefunction mock_domain_nop_attachfunction mock_domain_set_dev_pasid_nopfunction mock_domain_set_dirty_trackingfunction __mock_domain_alloc_nestedfunction mock_domain_alloc_nestedfunction mock_domain_freefunction mock_iotlb_syncfunction mock_domain_alloc_pgtablefunction mock_domain_alloc_paging_flagsfunction mock_domain_capablefunction mock_domain_page_responsefunction mock_dev_disable_iopffunction mock_viommu_destroyfunction mock_viommu_alloc_domain_nestedfunction mock_viommu_cache_invalidatefunction mock_viommu_get_hw_queue_sizefunction mock_hw_queue_destroyfunction mock_hw_queue_init_physfunction mock_get_viommu_sizefunction mock_viommu_initfunction mock_domain_free_nestedfunction mock_domain_cache_invalidate_userfunction __get_md_pagetablefunction get_md_pagetablefunction get_md_pagetable_nestedfunction mock_dev_releasefunction mock_dev_destroyfunction iommufd_selftest_is_mock_devfunction iommufd_test_mock_domainfunction iommufd_test_get_selftest_obj
Annotated Snippet
struct bus_type bus;
struct notifier_block nb;
};
static struct mock_bus_type iommufd_mock_bus_type = {
.bus = {
.name = "iommufd_mock",
},
};
static DEFINE_IDA(mock_dev_ida);
enum {
MOCK_DIRTY_TRACK = 1,
};
static int mock_dev_enable_iopf(struct device *dev, struct iommu_domain *domain);
static void mock_dev_disable_iopf(struct device *dev, struct iommu_domain *domain);
/*
* Syzkaller has trouble randomizing the correct iova to use since it is linked
* to the map ioctl's output, and it has no ide about that. So, simplify things.
* In syzkaller mode the 64 bit IOVA is converted into an nth area and offset
* value. This has a much smaller randomization space and syzkaller can hit it.
*/
static unsigned long __iommufd_test_syz_conv_iova(struct io_pagetable *iopt,
u64 *iova)
{
struct syz_layout {
__u32 nth_area;
__u32 offset;
};
struct syz_layout *syz = (void *)iova;
unsigned int nth = syz->nth_area;
struct iopt_area *area;
down_read(&iopt->iova_rwsem);
for (area = iopt_area_iter_first(iopt, 0, ULONG_MAX); area;
area = iopt_area_iter_next(area, 0, ULONG_MAX)) {
if (nth == 0) {
up_read(&iopt->iova_rwsem);
return iopt_area_iova(area) + syz->offset;
}
nth--;
}
up_read(&iopt->iova_rwsem);
return 0;
}
static unsigned long iommufd_test_syz_conv_iova(struct iommufd_access *access,
u64 *iova)
{
unsigned long ret;
mutex_lock(&access->ioas_lock);
if (!access->ioas) {
mutex_unlock(&access->ioas_lock);
return 0;
}
ret = __iommufd_test_syz_conv_iova(&access->ioas->iopt, iova);
mutex_unlock(&access->ioas_lock);
return ret;
}
void iommufd_test_syz_conv_iova_id(struct iommufd_ucmd *ucmd,
unsigned int ioas_id, u64 *iova, u32 *flags)
{
struct iommufd_ioas *ioas;
if (!(*flags & MOCK_FLAGS_ACCESS_SYZ))
return;
*flags &= ~(u32)MOCK_FLAGS_ACCESS_SYZ;
ioas = iommufd_get_ioas(ucmd->ictx, ioas_id);
if (IS_ERR(ioas))
return;
*iova = __iommufd_test_syz_conv_iova(&ioas->iopt, iova);
iommufd_put_object(ucmd->ictx, &ioas->obj);
}
struct mock_iommu_domain {
union {
struct iommu_domain domain;
struct pt_iommu iommu;
struct pt_iommu_amdv1 amdv1;
};
unsigned long flags;
};
PT_IOMMU_CHECK_DOMAIN(struct mock_iommu_domain, iommu, domain);
Annotation
- Immediate include surface: `linux/anon_inodes.h`, `linux/debugfs.h`, `linux/dma-buf.h`, `linux/dma-resv.h`, `linux/fault-inject.h`, `linux/file.h`, `linux/iommu.h`, `linux/platform_device.h`.
- Detected declarations: `struct mock_bus_type`, `struct syz_layout`, `struct mock_iommu_domain`, `struct mock_iommu_domain_nested`, `struct mock_viommu`, `struct mock_hw_queue`, `struct mock_dev`, `struct selftest_obj`, `struct selftest_access`, `struct selftest_access_item`.
- Atlas domain: Driver Families / drivers/iommu.
- Implementation status: pattern implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.