io_uring/register: add IORING_REGISTER_CLONE_FILES opcode
PATCH v3 1/1 io_uring/register: add IORING_REGISTER_CLONE_FILES opcode
Currently, if an application wants to duplicate registered file descriptors from one io_uring instance to another, it must manually unregister and re-register them, incurring unnecessary overhead.
Add IORING_REGISTER_CLONE_FILES to allow direct cloning of the file table from a source ring to a destination ring. This implementation strictly mirrors the io_clone_buffers UAPI, supporting partial offsets and the IORING_REGISTER_DST_REPLACE flag.
To ensure lock synchronization safety, destination nodes are strictly allocated as new, private io_rsrc_nodes rather than sharing references across rings.
---
v3:
- Rewrote the cloning loop to allocate private destination nodes via io_rsrc_node_alloc to fix non-atomic ref lock synchronization (Jens).
- Maintained partial offset/copy support to mirror io_clone_buffers UAPI (Jens).
- Gated the replacement free check on ctx->file_table.data.nr (Gabriel).
- Prevented self-cloning by checking ctx == src_ctx (Gabriel).
- Removed submitter_task check to allow cross-thread pooling setups (Gabriel).
v2: Dropped unrelated whitespace formatting changes from v1
--- include/uapi/linux/io_uring.h | 12 +++ io_uring/register.c | 6 ++ io_uring/rsrc.c | 149 ++++++++++++++++++++++++++++++++++ io_uring/rsrc.h | 1 + 4 files changed, 168 insertions(+)
include/uapi/linux/io_uring.h +12 -0
@@ -723,6 +723,9 @@ enum io_uring_register_op {/* register bpf filtering programs */ IORING_REGISTER_BPF_FILTER =37 , +/* clone file descriptors from another ring*/ +IORING_REGISTER_CLONE_FILES =38 , +/* this goes last */ IORING_REGISTER_LAST,
@@ -854,6 +857,15 @@ struct io_uring_clone_buffers {__u32 pad[3 ]; }; +struct io_uring_clone_files { +__u32 src_fd; +__u32 flags; +__u32 src_off; +__u32 dst_off; +__u32 nr; +__u32 pad[3 ]; +}; +struct io_uring_buf {__u64 addr;__u32 len;
io_uring/register.c +6 -0
@@ -924,6 +924,12 @@ static int __io_uring_register(struct io_ring_ctx *ctx, unsigned opcode,break ; ret =io_register_clone_buffers (ctx, arg);break ; +case IORING_REGISTER_CLONE_FILES : + ret = -EINVAL ; +if (!arg || nr_args !=1 ) +break ; + ret =io_register_clone_files (ctx, arg); +break ;case IORING_REGISTER_ZCRX_IFQ : ret = -EINVAL ;if (!arg || nr_args !=1 )
io_uring/rsrc.c +149 -0
155 lines not on this page · raw message
io_uring/rsrc.h +1 -0
@@ -75,6 +75,7 @@ int io_prep_reg_iovec(struct io_kiocb *req, struct iou_vec *iv, const struct iovec __user *uvec, size_t uvec_segs);int io_register_clone_buffers (struct io_ring_ctx *ctx,void __user *arg); +int io_register_clone_files (struct io_ring_ctx *ctx,void __user *arg);int io_sqe_buffers_unregister (struct io_ring_ctx *ctx);int io_sqe_buffers_register (struct io_ring_ctx *ctx,void __user *arg,unsigned int nr_args,u64 __user *tags);
Signature · 1 line
2.54.0
Quoted 22 lines · On Fri, Jun 19, 2026 at 12:27:00PM +0530, harshal24-chavan wrote:
Currently, if an application wants to duplicate registered file descriptors from one
io_uringinstance to another, it must manually unregister and re-register them, incurring unnecessary overhead.Add
IORING_REGISTER_CLONE_FILESto allow direct cloning of the file table from a source ring to a destination ring. This implementation strictly mirrors theio_clone_buffersUAPI, supporting partial offsets and theIORING_REGISTER_DST_REPLACEflag.To ensure lock synchronization safety, destination nodes are strictly allocated as new, private
io_rsrc_nodesrather than sharing references across rings.---
v3:
- Rewrote the cloning loop to allocate private destination nodes viaio_rsrc_node_allocto fix non-atomic ref lock synchronization (Jens).
- Maintained partial offset/copy support to mirrorio_clone_buffersUAPI (Jens).
- Gated the replacement free check onctx->file_table.data.nr(Gabriel).
- Prevented self-cloning by checking ctx ==src_ctx(Gabriel).
- Removedsubmitter_taskcheck to allow cross-thread pooling setups (Gabriel).
v2: Dropped unrelated whitespace formatting changes from v1
Quoted 1 line
Signed-off-by harshal24-chavan <[email protected]>
Needs to be a name, not an email alias, and above the --- line.
thanks,
greg k-h
Quoted 5 lines · Greg Kroah-Hartman
Needs to be a name, not an email alias, and above the --- line.
thanks,
greg k-h
Thank you for catching this. I have updated my git config to use my real name and ensured the Signed-off-by is part of the actual commit message above the --- line. I'll send out v4 shortly.