io_uring/msg_ring.c
Source file repositories/reference/linux-study-clean/io_uring/msg_ring.c
File Facts
- System
- Linux kernel
- Corpus path
io_uring/msg_ring.c- Extension
.c- Size
- 8639 bytes
- Lines
- 339
- Domain
- Kernel Services
- Bucket
- io_uring
- Inferred role
- Kernel Services: implementation source
- Status
- source 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.
- 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/kernel.hlinux/errno.hlinux/file.hlinux/slab.hlinux/nospec.hlinux/io_uring.huapi/linux/io_uring.hio_uring.hrsrc.hfiletable.hmsg_ring.h
Detected Declarations
struct io_msgfunction io_double_unlock_ctxfunction io_lock_external_ctxfunction io_msg_ring_cleanupfunction io_msg_need_remotefunction io_msg_tw_completefunction io_msg_remote_postfunction io_msg_data_remotefunction __io_msg_ring_datafunction io_msg_ring_datafunction io_msg_grab_filefunction io_msg_install_completefunction io_msg_tw_fd_completefunction io_msg_fd_remotefunction io_msg_send_fdfunction __io_msg_ring_prepfunction io_msg_ring_prepfunction io_msg_ringfunction io_uring_sync_msg_ring
Annotated Snippet
struct io_msg {
struct file *file;
struct file *src_file;
struct callback_head tw;
u64 user_data;
u32 len;
u32 cmd;
u32 src_fd;
union {
u32 dst_fd;
u32 cqe_flags;
};
u32 flags;
};
static void io_double_unlock_ctx(struct io_ring_ctx *octx)
{
mutex_unlock(&octx->uring_lock);
}
static int io_lock_external_ctx(struct io_ring_ctx *octx,
unsigned int issue_flags)
{
/*
* To ensure proper ordering between the two ctxs, we can only
* attempt a trylock on the target. If that fails and we already have
* the source ctx lock, punt to io-wq.
*/
if (!(issue_flags & IO_URING_F_UNLOCKED)) {
if (!mutex_trylock(&octx->uring_lock))
return -EAGAIN;
return 0;
}
mutex_lock(&octx->uring_lock);
return 0;
}
void io_msg_ring_cleanup(struct io_kiocb *req)
{
struct io_msg *msg = io_kiocb_to_cmd(req, struct io_msg);
if (WARN_ON_ONCE(!msg->src_file))
return;
fput(msg->src_file);
msg->src_file = NULL;
}
static inline bool io_msg_need_remote(struct io_ring_ctx *target_ctx)
{
return target_ctx->int_flags & IO_RING_F_TASK_COMPLETE;
}
static void io_msg_tw_complete(struct io_tw_req tw_req, io_tw_token_t tw)
{
struct io_kiocb *req = tw_req.req;
struct io_ring_ctx *ctx = req->ctx;
io_add_aux_cqe(ctx, req->cqe.user_data, req->cqe.res, req->cqe.flags);
kfree_rcu(req, rcu_head);
percpu_ref_put(&ctx->refs);
}
static void io_msg_remote_post(struct io_ring_ctx *ctx, struct io_kiocb *req,
int res, u32 cflags, u64 user_data)
{
req->opcode = IORING_OP_NOP;
req->cqe.user_data = user_data;
io_req_set_res(req, res, cflags);
percpu_ref_get(&ctx->refs);
req->ctx = ctx;
req->tctx = NULL;
req->io_task_work.func = io_msg_tw_complete;
io_req_task_work_add_remote(req, IOU_F_TWQ_LAZY_WAKE);
}
static int io_msg_data_remote(struct io_ring_ctx *target_ctx,
struct io_msg *msg)
{
struct io_kiocb *target;
u32 flags = 0;
target = kmem_cache_alloc(req_cachep, GFP_KERNEL | __GFP_NOWARN | __GFP_ZERO) ;
if (unlikely(!target))
return -ENOMEM;
if (msg->flags & IORING_MSG_RING_FLAGS_PASS)
flags = msg->cqe_flags;
io_msg_remote_post(target_ctx, target, msg->len, flags, msg->user_data);
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/errno.h`, `linux/file.h`, `linux/slab.h`, `linux/nospec.h`, `linux/io_uring.h`, `uapi/linux/io_uring.h`, `io_uring.h`.
- Detected declarations: `struct io_msg`, `function io_double_unlock_ctx`, `function io_lock_external_ctx`, `function io_msg_ring_cleanup`, `function io_msg_need_remote`, `function io_msg_tw_complete`, `function io_msg_remote_post`, `function io_msg_data_remote`, `function __io_msg_ring_data`, `function io_msg_ring_data`.
- Atlas domain: Kernel Services / io_uring.
- Implementation status: source implementation candidate.
- 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.