drivers/iommu/iommufd/vfio_compat.c
Source file repositories/reference/linux-study-clean/drivers/iommu/iommufd/vfio_compat.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iommu/iommufd/vfio_compat.c- Extension
.c- Size
- 14472 bytes
- Lines
- 537
- Domain
- Driver Families
- Bucket
- drivers/iommu
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/file.hlinux/interval_tree.hlinux/iommu.hlinux/iommufd.hlinux/slab.hlinux/vfio.huapi/linux/vfio.huapi/linux/iommufd.hiommufd_private.h
Detected Declarations
function iommufd_vfio_compat_ioas_get_idfunction iommufd_vfio_compat_set_no_iommufunction iommufd_vfio_compat_ioas_createfunction iommufd_vfio_ioasfunction iommufd_vfio_map_dmafunction iommufd_vfio_unmap_dmafunction iommufd_vfio_cc_iommufunction iommufd_vfio_check_extensionfunction iommufd_vfio_set_iommufunction iommufd_get_pagesizesfunction iommufd_fill_cap_iovafunction interval_tree_for_each_spanfunction iommufd_fill_cap_dma_availfunction iommufd_vfio_iommu_get_infofunction iommufd_vfio_ioctl
Annotated Snippet
if (unmap.iova != 0 || unmap.size != 0) {
rc = -EINVAL;
goto err_put;
}
rc = iopt_unmap_all(&ioas->iopt, &unmapped);
} else {
if (READ_ONCE(ioas->iopt.disable_large_pages)) {
/*
* Create cuts at the start and last of the requested
* range. If the start IOVA is 0 then it doesn't need to
* be cut.
*/
unsigned long iovas[] = { unmap.iova + unmap.size - 1,
unmap.iova - 1 };
rc = iopt_cut_iova(&ioas->iopt, iovas,
unmap.iova ? 2 : 1);
if (rc)
goto err_put;
}
rc = iopt_unmap_iova(&ioas->iopt, unmap.iova, unmap.size,
&unmapped);
}
unmap.size = unmapped;
if (copy_to_user(arg, &unmap, minsz))
rc = -EFAULT;
err_put:
iommufd_put_object(ictx, &ioas->obj);
return rc;
}
static int iommufd_vfio_cc_iommu(struct iommufd_ctx *ictx)
{
struct iommufd_hwpt_paging *hwpt_paging;
struct iommufd_ioas *ioas;
int rc = 1;
ioas = get_compat_ioas(ictx);
if (IS_ERR(ioas))
return PTR_ERR(ioas);
mutex_lock(&ioas->mutex);
list_for_each_entry(hwpt_paging, &ioas->hwpt_list, hwpt_item) {
if (!hwpt_paging->enforce_cache_coherency) {
rc = 0;
break;
}
}
mutex_unlock(&ioas->mutex);
iommufd_put_object(ictx, &ioas->obj);
return rc;
}
static int iommufd_vfio_check_extension(struct iommufd_ctx *ictx,
unsigned long type)
{
switch (type) {
case VFIO_TYPE1_IOMMU:
case VFIO_TYPE1v2_IOMMU:
case VFIO_UNMAP_ALL:
return !ictx->no_iommu_mode;
case VFIO_NOIOMMU_IOMMU:
return IS_ENABLED(CONFIG_VFIO_NOIOMMU);
case VFIO_DMA_CC_IOMMU:
return iommufd_vfio_cc_iommu(ictx);
case __VFIO_RESERVED_TYPE1_NESTING_IOMMU:
return 0;
/*
* VFIO_DMA_MAP_FLAG_VADDR
* https://lore.kernel.org/kvm/1611939252-7240-1-git-send-email-steven.sistare@oracle.com/
* https://lore.kernel.org/all/Yz777bJZjTyLrHEQ@nvidia.com/
*
* It is hard to see how this could be implemented safely.
*/
case VFIO_UPDATE_VADDR:
default:
return 0;
}
}
static int iommufd_vfio_set_iommu(struct iommufd_ctx *ictx, unsigned long type)
{
bool no_iommu_mode = READ_ONCE(ictx->no_iommu_mode);
struct iommufd_ioas *ioas = NULL;
Annotation
- Immediate include surface: `linux/file.h`, `linux/interval_tree.h`, `linux/iommu.h`, `linux/iommufd.h`, `linux/slab.h`, `linux/vfio.h`, `uapi/linux/vfio.h`, `uapi/linux/iommufd.h`.
- Detected declarations: `function iommufd_vfio_compat_ioas_get_id`, `function iommufd_vfio_compat_set_no_iommu`, `function iommufd_vfio_compat_ioas_create`, `function iommufd_vfio_ioas`, `function iommufd_vfio_map_dma`, `function iommufd_vfio_unmap_dma`, `function iommufd_vfio_cc_iommu`, `function iommufd_vfio_check_extension`, `function iommufd_vfio_set_iommu`, `function iommufd_get_pagesizes`.
- Atlas domain: Driver Families / drivers/iommu.
- Implementation status: integration 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.