drivers/iommu/iommufd/eventq.c
Source file repositories/reference/linux-study-clean/drivers/iommu/iommufd/eventq.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iommu/iommufd/eventq.c- Extension
.c- Size
- 15278 bytes
- Lines
- 569
- 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/file.hlinux/fs.hlinux/iommufd.hlinux/module.hlinux/mutex.hlinux/poll.huapi/linux/iommufd.h../iommu-priv.hiommufd_private.h
Detected Declarations
function iommufd_auto_response_faultsfunction list_for_each_entry_safefunction xa_for_eachfunction iommufd_fault_destroyfunction iommufd_compose_fault_messagefunction iommufd_fault_deliver_fetchfunction iommufd_fault_deliver_restorefunction iommufd_fault_fops_readfunction list_for_each_entryfunction iommufd_fault_fops_writefunction iommufd_veventq_abortfunction list_for_each_entry_safefunction iommufd_veventq_destroyfunction iommufd_veventq_deliver_fetchfunction iommufd_veventq_deliver_restorefunction iommufd_veventq_fops_readfunction iommufd_eventq_fops_pollfunction iommufd_eventq_fops_releasefunction iommufd_eventq_initfunction iommufd_fault_allocfunction iommufd_fault_iopf_handlerfunction iommufd_veventq_alloc
Annotated Snippet
((const struct file_operations){ \
.owner = THIS_MODULE, \
.open = nonseekable_open, \
.read = read_op, \
.write = write_op, \
.poll = iommufd_eventq_fops_poll, \
.release = iommufd_eventq_fops_release, \
})
static int iommufd_eventq_init(struct iommufd_eventq *eventq, char *name,
struct iommufd_ctx *ictx,
const struct file_operations *fops)
{
struct file *filep;
spin_lock_init(&eventq->lock);
INIT_LIST_HEAD(&eventq->deliver);
init_waitqueue_head(&eventq->wait_queue);
/* The filep is fput() by the core code during failure */
filep = anon_inode_getfile(name, fops, eventq, O_RDWR);
if (IS_ERR(filep))
return PTR_ERR(filep);
eventq->ictx = ictx;
iommufd_ctx_get(eventq->ictx);
eventq->filep = filep;
refcount_inc(&eventq->obj.users);
return get_unused_fd_flags(O_CLOEXEC);
}
static const struct file_operations iommufd_fault_fops =
INIT_EVENTQ_FOPS(iommufd_fault_fops_read, iommufd_fault_fops_write);
int iommufd_fault_alloc(struct iommufd_ucmd *ucmd)
{
struct iommu_fault_alloc *cmd = ucmd->cmd;
struct iommufd_fault *fault;
int fdno;
int rc;
if (cmd->flags)
return -EOPNOTSUPP;
fault = __iommufd_object_alloc_ucmd(ucmd, fault, IOMMUFD_OBJ_FAULT,
common.obj);
if (IS_ERR(fault))
return PTR_ERR(fault);
xa_init_flags(&fault->response, XA_FLAGS_ALLOC1);
mutex_init(&fault->mutex);
fdno = iommufd_eventq_init(&fault->common, "[iommufd-pgfault]",
ucmd->ictx, &iommufd_fault_fops);
if (fdno < 0)
return fdno;
cmd->out_fault_id = fault->common.obj.id;
cmd->out_fault_fd = fdno;
rc = iommufd_ucmd_respond(ucmd, sizeof(*cmd));
if (rc)
goto out_put_fdno;
fd_install(fdno, fault->common.filep);
return 0;
out_put_fdno:
put_unused_fd(fdno);
return rc;
}
int iommufd_fault_iopf_handler(struct iopf_group *group)
{
struct iommufd_hw_pagetable *hwpt;
struct iommufd_fault *fault;
hwpt = group->attach_handle->domain->iommufd_hwpt;
fault = hwpt->fault;
spin_lock(&fault->common.lock);
list_add_tail(&group->node, &fault->common.deliver);
spin_unlock(&fault->common.lock);
wake_up_interruptible(&fault->common.wait_queue);
return 0;
}
Annotation
- Immediate include surface: `linux/anon_inodes.h`, `linux/file.h`, `linux/fs.h`, `linux/iommufd.h`, `linux/module.h`, `linux/mutex.h`, `linux/poll.h`, `uapi/linux/iommufd.h`.
- Detected declarations: `function iommufd_auto_response_faults`, `function list_for_each_entry_safe`, `function xa_for_each`, `function iommufd_fault_destroy`, `function iommufd_compose_fault_message`, `function iommufd_fault_deliver_fetch`, `function iommufd_fault_deliver_restore`, `function iommufd_fault_fops_read`, `function list_for_each_entry`, `function iommufd_fault_fops_write`.
- 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.