drivers/iommu/iommufd/main.c
Source file repositories/reference/linux-study-clean/drivers/iommu/iommufd/main.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iommu/iommufd/main.c- Extension
.c- Size
- 22743 bytes
- Lines
- 809
- 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.
- 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/bug.hlinux/file.hlinux/fs.hlinux/iommufd.hlinux/miscdevice.hlinux/module.hlinux/mutex.hlinux/slab.huapi/linux/iommufd.hio_pagetable.hiommufd_private.hiommufd_test.h
Detected Declarations
struct iommufd_object_opsstruct iommufd_ioctl_opfunction iommufd_object_abortfunction iommufd_object_abortfunction iommufd_object_abort_and_destroyfunction iommufd_object_dec_waitfunction iommufd_object_removefunction pre_destroyfunction iommufd_put_objectfunction iommufd_destroyfunction iommufd_fops_openfunction iommufd_fops_releasefunction xa_for_eachfunction iommufd_optionfunction iommufd_fops_ioctlfunction iommufd_fops_vma_openfunction iommufd_fops_vma_closefunction iommufd_fops_mmapfunction mtree_loadfunction iommufd_ctx_getfunction iommufd_ctx_putfunction iommufd_ctx_putfunction iommufd_ctx_putfunction iommufd_initfunction iommufd_exitmodule init iommufd_init
Annotated Snippet
static const struct file_operations iommufd_fops = {
.owner = THIS_MODULE,
.open = iommufd_fops_open,
.release = iommufd_fops_release,
.unlocked_ioctl = iommufd_fops_ioctl,
.mmap = iommufd_fops_mmap,
};
/**
* iommufd_ctx_get - Get a context reference
* @ictx: Context to get
*
* The caller must already hold a valid reference to ictx.
*/
void iommufd_ctx_get(struct iommufd_ctx *ictx)
{
get_file(ictx->file);
}
EXPORT_SYMBOL_NS_GPL(iommufd_ctx_get, "IOMMUFD");
/**
* iommufd_ctx_from_file - Acquires a reference to the iommufd context
* @file: File to obtain the reference from
*
* Returns a pointer to the iommufd_ctx, otherwise ERR_PTR. The struct file
* remains owned by the caller and the caller must still do fput. On success
* the caller is responsible to call iommufd_ctx_put().
*/
struct iommufd_ctx *iommufd_ctx_from_file(struct file *file)
{
struct iommufd_ctx *ictx;
if (file->f_op != &iommufd_fops)
return ERR_PTR(-EBADFD);
ictx = file->private_data;
iommufd_ctx_get(ictx);
return ictx;
}
EXPORT_SYMBOL_NS_GPL(iommufd_ctx_from_file, "IOMMUFD");
/**
* iommufd_ctx_from_fd - Acquires a reference to the iommufd context
* @fd: File descriptor to obtain the reference from
*
* Returns a pointer to the iommufd_ctx, otherwise ERR_PTR. On success
* the caller is responsible to call iommufd_ctx_put().
*/
struct iommufd_ctx *iommufd_ctx_from_fd(int fd)
{
struct file *file;
file = fget(fd);
if (!file)
return ERR_PTR(-EBADF);
if (file->f_op != &iommufd_fops) {
fput(file);
return ERR_PTR(-EBADFD);
}
/* fget is the same as iommufd_ctx_get() */
return file->private_data;
}
EXPORT_SYMBOL_NS_GPL(iommufd_ctx_from_fd, "IOMMUFD");
/**
* iommufd_ctx_put - Put back a reference
* @ictx: Context to put back
*/
void iommufd_ctx_put(struct iommufd_ctx *ictx)
{
fput(ictx->file);
}
EXPORT_SYMBOL_NS_GPL(iommufd_ctx_put, "IOMMUFD");
#define IOMMUFD_FILE_OFFSET(_struct, _filep, _obj) \
.file_offset = (offsetof(_struct, _filep) + \
BUILD_BUG_ON_ZERO(!__same_type( \
struct file *, ((_struct *)NULL)->_filep)) + \
BUILD_BUG_ON_ZERO(offsetof(_struct, _obj)))
static const struct iommufd_object_ops iommufd_object_ops[] = {
[IOMMUFD_OBJ_ACCESS] = {
.destroy = iommufd_access_destroy_object,
},
[IOMMUFD_OBJ_DEVICE] = {
.pre_destroy = iommufd_device_pre_destroy,
.destroy = iommufd_device_destroy,
},
[IOMMUFD_OBJ_FAULT] = {
.destroy = iommufd_fault_destroy,
Annotation
- Immediate include surface: `linux/bug.h`, `linux/file.h`, `linux/fs.h`, `linux/iommufd.h`, `linux/miscdevice.h`, `linux/module.h`, `linux/mutex.h`, `linux/slab.h`.
- Detected declarations: `struct iommufd_object_ops`, `struct iommufd_ioctl_op`, `function iommufd_object_abort`, `function iommufd_object_abort`, `function iommufd_object_abort_and_destroy`, `function iommufd_object_dec_wait`, `function iommufd_object_remove`, `function pre_destroy`, `function iommufd_put_object`, `function iommufd_destroy`.
- 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.
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.