drivers/iommu/iommufd/io_pagetable.c
Source file repositories/reference/linux-study-clean/drivers/iommu/iommufd/io_pagetable.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iommu/iommufd/io_pagetable.c- Extension
.c- Size
- 40810 bytes
- Lines
- 1552
- Domain
- Driver Families
- Bucket
- drivers/iommu
- Inferred role
- Driver Families: implementation source
- Status
- source 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- 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/dma-buf.hlinux/err.hlinux/errno.hlinux/file.hlinux/iommu.hlinux/iommufd.hlinux/lockdep.hlinux/sched/mm.hlinux/slab.huapi/linux/iommufd.hdouble_span.hio_pagetable.h
Detected Declarations
struct iopt_pages_liststruct iova_bitmap_fn_argfunction __alloc_iova_check_rangefunction __alloc_iova_check_holefunction __alloc_iova_check_usedfunction iopt_alloc_iovafunction interval_tree_for_each_spanfunction interval_tree_for_each_double_spanfunction iopt_check_iovafunction iopt_insert_areafunction iopt_alloc_area_pagesfunction list_for_each_entryfunction iopt_abort_areafunction iopt_free_pages_listfunction iopt_fill_domains_pagesfunction list_for_each_entryfunction iopt_map_pagesfunction iopt_map_commonfunction iopt_map_user_pagesfunction iopt_map_file_pagesfunction __iommu_read_and_clear_dirtyfunction iopt_for_each_contig_areafunction iommu_read_and_clear_dirtyfunction iommufd_check_iova_rangefunction iopt_read_and_clear_dirty_datafunction iopt_clear_dirty_datafunction iopt_set_dirty_trackingfunction iopt_get_pagesfunction iopt_unmap_iova_rangefunction iopt_unmap_iovafunction iopt_unmap_allfunction iopt_set_allow_iovafunction iopt_reserve_iovafunction __iopt_remove_reserved_iovafunction iopt_remove_reserved_iovafunction iopt_init_tablefunction iopt_destroy_tablefunction iopt_unfill_domainfunction iopt_fill_domainfunction iopt_check_iova_alignmentfunction iopt_table_add_domainfunction xa_for_eachfunction iopt_calculate_iova_alignmentfunction iopt_table_remove_domainfunction iopt_area_splitfunction iopt_cut_iovafunction iopt_enable_large_pagesfunction iopt_disable_large_pages
Annotated Snippet
struct iopt_pages_list {
struct iopt_pages *pages;
struct iopt_area *area;
struct list_head next;
unsigned long start_byte;
unsigned long length;
};
struct iopt_area *iopt_area_contig_init(struct iopt_area_contig_iter *iter,
struct io_pagetable *iopt,
unsigned long iova,
unsigned long last_iova)
{
lockdep_assert_held(&iopt->iova_rwsem);
iter->cur_iova = iova;
iter->last_iova = last_iova;
iter->area = iopt_area_iter_first(iopt, iova, iova);
if (!iter->area)
return NULL;
if (!iter->area->pages) {
iter->area = NULL;
return NULL;
}
return iter->area;
}
struct iopt_area *iopt_area_contig_next(struct iopt_area_contig_iter *iter)
{
unsigned long last_iova;
if (!iter->area)
return NULL;
last_iova = iopt_area_last_iova(iter->area);
if (iter->last_iova <= last_iova)
return NULL;
iter->cur_iova = last_iova + 1;
iter->area = iopt_area_iter_next(iter->area, iter->cur_iova,
iter->last_iova);
if (!iter->area)
return NULL;
if (iter->cur_iova != iopt_area_iova(iter->area) ||
!iter->area->pages) {
iter->area = NULL;
return NULL;
}
return iter->area;
}
static bool __alloc_iova_check_range(unsigned long *start, unsigned long last,
unsigned long length,
unsigned long iova_alignment,
unsigned long page_offset)
{
unsigned long aligned_start;
/* ALIGN_UP() */
if (check_add_overflow(*start, iova_alignment - 1, &aligned_start))
return false;
aligned_start &= ~(iova_alignment - 1);
aligned_start |= page_offset;
if (aligned_start >= last || last - aligned_start < length - 1)
return false;
*start = aligned_start;
return true;
}
static bool __alloc_iova_check_hole(struct interval_tree_double_span_iter *span,
unsigned long length,
unsigned long iova_alignment,
unsigned long page_offset)
{
if (span->is_used)
return false;
return __alloc_iova_check_range(&span->start_hole, span->last_hole,
length, iova_alignment, page_offset);
}
static bool __alloc_iova_check_used(struct interval_tree_span_iter *span,
unsigned long length,
unsigned long iova_alignment,
unsigned long page_offset)
{
if (span->is_hole)
return false;
return __alloc_iova_check_range(&span->start_used, span->last_used,
length, iova_alignment, page_offset);
}
Annotation
- Immediate include surface: `linux/dma-buf.h`, `linux/err.h`, `linux/errno.h`, `linux/file.h`, `linux/iommu.h`, `linux/iommufd.h`, `linux/lockdep.h`, `linux/sched/mm.h`.
- Detected declarations: `struct iopt_pages_list`, `struct iova_bitmap_fn_arg`, `function __alloc_iova_check_range`, `function __alloc_iova_check_hole`, `function __alloc_iova_check_used`, `function iopt_alloc_iova`, `function interval_tree_for_each_span`, `function interval_tree_for_each_double_span`, `function iopt_check_iova`, `function iopt_insert_area`.
- Atlas domain: Driver Families / drivers/iommu.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.