On 12/01/2021 21:33, Bijan Mottahedeh wrote: > Implement buffer sharing among multiple rings. > > A ring shares its (future) buffer registrations at setup time with > IORING_SETUP_SHARE_BUF. A ring attaches to another ring's buffer > registration at setup time with IORING_SETUP_ATTACH_BUF, after > authenticating with the buffer registration owner's fd. Any updates to > the owner's buffer registrations become immediately available to the > attached rings. I'm thinking it through, but there is an easy to miss potential bug, so see below a comment to not forget. > > Signed-off-by: Bijan Mottahedeh <bijan.mottahedeh@xxxxxxxxxx> > > Conflicts: > fs/io_uring.c > --- > fs/io_uring.c | 85 +++++++++++++++++++++++++++++++++++++++++-- > include/uapi/linux/io_uring.h | 2 + > 2 files changed, 83 insertions(+), 4 deletions(-) [...] > + > +static int io_init_buf_data(struct io_ring_ctx *ctx, struct io_uring_params *p) > +{ > + if ((p->flags & (IORING_SETUP_SHARE_BUF | IORING_SETUP_ATTACH_BUF)) == > + (IORING_SETUP_SHARE_BUF | IORING_SETUP_ATTACH_BUF)) > + return -EINVAL; > + > + if (p->flags & IORING_SETUP_SHARE_BUF) { > + struct fixed_rsrc_data *buf_data; > + > + buf_data = alloc_fixed_rsrc_data(ctx); > + if (IS_ERR(buf_data)) > + return PTR_ERR(buf_data); Because of sneaked through 5.11 fixes it'll be if (!buf_data) return -ENOMEM > + > + ctx->buf_data = buf_data; > + return 0; > + } > + > + if (p->flags & IORING_SETUP_ATTACH_BUF) > + return io_attach_buf_data(ctx, p); > + > + return 0; > +} > + -- Pavel Begunkov