io_uring/zcrx.c
Source file repositories/reference/linux-study-clean/io_uring/zcrx.c
File Facts
- System
- Linux kernel
- Corpus path
io_uring/zcrx.c- Extension
.c- Size
- 41820 bytes
- Lines
- 1793
- Domain
- Kernel Services
- Bucket
- io_uring
- Inferred role
- Kernel Services: operation-table or driver-model contract
- Status
- pattern implementation candidate
Why This File Exists
Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- 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.
- 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/kernel.hlinux/errno.hlinux/dma-map-ops.hlinux/mm.hlinux/nospec.hlinux/io_uring.hlinux/netdevice.hlinux/rtnetlink.hlinux/skbuff_ref.hlinux/anon_inodes.hnet/page_pool/helpers.hnet/page_pool/memory_provider.hnet/netlink.hnet/netdev_queues.hnet/netdev_rx_queue.hnet/tcp.hnet/rps.htrace/events/page_pool.huapi/linux/io_uring.hio_uring.hkbuf.hmemmap.hzcrx.hrsrc.h
Detected Declarations
struct io_zcrx_argsstruct io_copy_cachefunction zcrx_set_ring_ctxfunction io_area_max_shiftfunction io_populate_area_dmafunction for_each_sgtable_dma_sgfunction io_release_dmabuffunction io_import_dmabuffunction io_count_account_pagesfunction io_import_umemfunction io_release_area_memfunction io_import_areafunction io_zcrx_unmap_areafunction zcrx_sync_for_devicefunction io_zcrx_put_niov_ureffunction io_zcrx_get_niov_ureffunction io_fill_zcrx_offsetsfunction io_allocate_rbuf_ringfunction io_free_rbuf_ringfunction io_zcrx_free_areafunction io_zcrx_append_areafunction io_zcrx_create_areafunction io_zcrx_drop_netdevfunction io_close_queuefunction scoped_guardfunction io_zcrx_ifq_freefunction io_put_zcrx_ifqfunction io_zcrx_return_niov_freelistfunction io_zcrx_return_niovfunction io_zcrx_scrubfunction zcrx_unregister_userfunction zcrx_unregisterfunction zcrx_box_releasefunction zcrx_exportfunction import_zcrxfunction scoped_guardfunction scoped_guardfunction zcrx_register_netdevfunction zcrx_validate_notif_statsfunction io_register_zcrxfunction scoped_guardfunction scoped_guardfunction is_zcrx_entry_markedfunction set_zcrx_entry_markfunction io_terminate_zcrxfunction io_unregister_zcrxfunction zcrx_rq_entriesfunction io_parse_rqe
Annotated Snippet
static const struct file_operations zcrx_box_fops = {
.owner = THIS_MODULE,
.release = zcrx_box_release,
};
static int zcrx_export(struct io_ring_ctx *ctx, struct io_zcrx_ifq *ifq,
struct zcrx_ctrl *ctrl, void __user *arg)
{
struct zcrx_ctrl_export *ce = &ctrl->zc_export;
struct file *file;
int fd;
if (!mem_is_zero(ce, sizeof(*ce)))
return -EINVAL;
refcount_inc(&ifq->refs);
refcount_inc(&ifq->user_refs);
file = anon_inode_create_getfile("[zcrx]", &zcrx_box_fops,
ifq, O_CLOEXEC, NULL);
if (IS_ERR(file)) {
zcrx_unregister(ifq, NULL);
return PTR_ERR(file);
}
fd = get_unused_fd_flags(O_CLOEXEC);
if (fd < 0) {
fput(file);
return fd;
}
ce->zcrx_fd = fd;
if (copy_to_user(arg, ctrl, sizeof(*ctrl))) {
fput(file);
put_unused_fd(fd);
return -EFAULT;
}
fd_install(fd, file);
return 0;
}
static int import_zcrx(struct io_ring_ctx *ctx,
struct io_uring_zcrx_ifq_reg __user *arg,
struct io_uring_zcrx_ifq_reg *reg)
{
struct io_zcrx_ifq *ifq;
struct file *file;
int fd, ret;
u32 id;
if (!(ctx->flags & IORING_SETUP_DEFER_TASKRUN))
return -EINVAL;
if (!(ctx->flags & (IORING_SETUP_CQE32|IORING_SETUP_CQE_MIXED)))
return -EINVAL;
if (reg->if_rxq || reg->rq_entries || reg->area_ptr || reg->region_ptr)
return -EINVAL;
if (reg->notif_desc)
return -EINVAL;
if (reg->flags & ~ZCRX_REG_IMPORT)
return -EINVAL;
fd = reg->if_idx;
CLASS(fd, f)(fd);
if (fd_empty(f))
return -EBADF;
file = fd_file(f);
if (file->f_op != &zcrx_box_fops || !file->private_data)
return -EBADF;
ifq = file->private_data;
refcount_inc(&ifq->refs);
refcount_inc(&ifq->user_refs);
scoped_guard(mutex, &ctx->mmap_lock) {
ret = xa_alloc(&ctx->zcrx_ctxs, &id, NULL, xa_limit_31b, GFP_KERNEL);
if (ret)
goto err;
}
reg->zcrx_id = id;
io_fill_zcrx_offsets(®->offsets);
if (copy_to_user(arg, reg, sizeof(*reg))) {
ret = -EFAULT;
goto err_xa_erase;
}
scoped_guard(mutex, &ctx->mmap_lock) {
ret = -ENOMEM;
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/errno.h`, `linux/dma-map-ops.h`, `linux/mm.h`, `linux/nospec.h`, `linux/io_uring.h`, `linux/netdevice.h`, `linux/rtnetlink.h`.
- Detected declarations: `struct io_zcrx_args`, `struct io_copy_cache`, `function zcrx_set_ring_ctx`, `function io_area_max_shift`, `function io_populate_area_dma`, `function for_each_sgtable_dma_sg`, `function io_release_dmabuf`, `function io_import_dmabuf`, `function io_count_account_pages`, `function io_import_umem`.
- Atlas domain: Kernel Services / io_uring.
- 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.
- 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.