io_uring: add fully sparse buffer registration

Honour IORING_RSRC_REGISTER_SPARSE not only for direct files but fixed
buffers as well. It makes the rsrc API more consistent.

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Link: https://lore.kernel.org/r/66f429e4912fe39fb3318217ff33a2853d4544be.1652879898.git.asml.silence@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
Pavel Begunkov 2022-05-18 19:13:49 +01:00 committed by Jens Axboe
parent 0bf1dbee9b
commit 0184f08e65

View File

@ -10134,12 +10134,17 @@ static int io_sqe_buffers_register(struct io_ring_ctx *ctx, void __user *arg,
} }
for (i = 0; i < nr_args; i++, ctx->nr_user_bufs++) { for (i = 0; i < nr_args; i++, ctx->nr_user_bufs++) {
ret = io_copy_iov(ctx, &iov, arg, i); if (arg) {
if (ret) ret = io_copy_iov(ctx, &iov, arg, i);
break; if (ret)
ret = io_buffer_validate(&iov); break;
if (ret) ret = io_buffer_validate(&iov);
break; if (ret)
break;
} else {
memset(&iov, 0, sizeof(iov));
}
if (!iov.iov_base && *io_get_tag_slot(data, i)) { if (!iov.iov_base && *io_get_tag_slot(data, i)) {
ret = -EINVAL; ret = -EINVAL;
break; break;
@ -11986,7 +11991,7 @@ static __cold int io_register_rsrc(struct io_ring_ctx *ctx, void __user *arg,
return io_sqe_files_register(ctx, u64_to_user_ptr(rr.data), return io_sqe_files_register(ctx, u64_to_user_ptr(rr.data),
rr.nr, u64_to_user_ptr(rr.tags)); rr.nr, u64_to_user_ptr(rr.tags));
case IORING_RSRC_BUFFER: case IORING_RSRC_BUFFER:
if (rr.flags & IORING_RSRC_REGISTER_SPARSE) if (rr.flags & IORING_RSRC_REGISTER_SPARSE && rr.data)
break; break;
return io_sqe_buffers_register(ctx, u64_to_user_ptr(rr.data), return io_sqe_buffers_register(ctx, u64_to_user_ptr(rr.data),
rr.nr, u64_to_user_ptr(rr.tags)); rr.nr, u64_to_user_ptr(rr.tags));
@ -12224,6 +12229,9 @@ static int __io_uring_register(struct io_ring_ctx *ctx, unsigned opcode,
switch (opcode) { switch (opcode) {
case IORING_REGISTER_BUFFERS: case IORING_REGISTER_BUFFERS:
ret = -EFAULT;
if (!arg)
break;
ret = io_sqe_buffers_register(ctx, arg, nr_args, NULL); ret = io_sqe_buffers_register(ctx, arg, nr_args, NULL);
break; break;
case IORING_UNREGISTER_BUFFERS: case IORING_UNREGISTER_BUFFERS: