summaryrefslogtreecommitdiff
path: root/io_uring/rsrc.c
diff options
context:
space:
mode:
authorJens Axboe <axboe@kernel.dk>2024-10-30 09:51:58 -0600
committerJens Axboe <axboe@kernel.dk>2024-11-02 15:45:30 -0600
commitd50f94d761a5d9a34e03a86e512e19d88cbeaf06 (patch)
tree7b7bc09d5f47e085122e8aa1f9da6c356c7da504 /io_uring/rsrc.c
parent4007c3d8c22a2025367953f4ee36ae106a69d855 (diff)
io_uring/rsrc: get rid of the empty node and dummy_ubuf
The empty node was used as a placeholder for a sparse entry, but it didn't really solve any issues. The caller still has to check for whether it's the empty node or not, it may as well just check for a NULL return instead. The dummy_ubuf was used for a sparse buffer entry, but NULL will serve the same purpose there of ensuring an -EFAULT on attempted import. Just use NULL for a sparse node, regardless of whether or not it's a file or buffer resource. Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'io_uring/rsrc.c')
-rw-r--r--io_uring/rsrc.c48
1 files changed, 21 insertions, 27 deletions
diff --git a/io_uring/rsrc.c b/io_uring/rsrc.c
index 378f33746457..7ad91f180566 100644
--- a/io_uring/rsrc.c
+++ b/io_uring/rsrc.c
@@ -32,17 +32,6 @@ static struct io_rsrc_node *io_sqe_buffer_register(struct io_ring_ctx *ctx,
#define IORING_MAX_FIXED_FILES (1U << 20)
#define IORING_MAX_REG_BUFFERS (1U << 14)
-static const struct io_mapped_ubuf dummy_ubuf = {
- /* set invalid range, so io_import_fixed() fails meeting it */
- .ubuf = -1UL,
- .len = UINT_MAX,
-};
-
-const struct io_rsrc_node empty_node = {
- .type = IORING_RSRC_BUFFER,
- .buf = (struct io_mapped_ubuf *) &dummy_ubuf,
-};
-
int __io_account_mem(struct user_struct *user, unsigned long nr_pages)
{
unsigned long page_limit, cur_pages, new_pages;
@@ -116,7 +105,7 @@ static void io_buffer_unmap(struct io_ring_ctx *ctx, struct io_rsrc_node *node)
{
unsigned int i;
- if (node->buf != &dummy_ubuf) {
+ if (node->buf) {
struct io_mapped_ubuf *imu = node->buf;
if (!refcount_dec_and_test(&imu->refs))
@@ -265,20 +254,21 @@ static int __io_sqe_buffers_update(struct io_ring_ctx *ctx,
err = io_buffer_validate(iov);
if (err)
break;
- if (!iov->iov_base && tag) {
- err = -EINVAL;
- break;
- }
node = io_sqe_buffer_register(ctx, iov, &last_hpage);
if (IS_ERR(node)) {
err = PTR_ERR(node);
break;
}
+ if (tag) {
+ if (!node) {
+ err = -EINVAL;
+ break;
+ }
+ node->tag = tag;
+ }
i = array_index_nospec(up->offset + done, ctx->buf_table.nr);
io_reset_rsrc_node(&ctx->buf_table, i);
ctx->buf_table.nodes[i] = node;
- if (tag)
- node->tag = tag;
if (ctx->compat)
user_data += sizeof(struct compat_iovec);
else
@@ -591,8 +581,11 @@ static bool headpage_already_acct(struct io_ring_ctx *ctx, struct page **pages,
/* check previously registered pages */
for (i = 0; i < ctx->buf_table.nr; i++) {
struct io_rsrc_node *node = ctx->buf_table.nodes[i];
- struct io_mapped_ubuf *imu = node->buf;
+ struct io_mapped_ubuf *imu;
+ if (!node)
+ continue;
+ imu = node->buf;
for (j = 0; j < imu->nr_bvecs; j++) {
if (!PageCompound(imu->bvec[j].bv_page))
continue;
@@ -742,7 +735,7 @@ static struct io_rsrc_node *io_sqe_buffer_register(struct io_ring_ctx *ctx,
bool coalesced;
if (!iov->iov_base)
- return rsrc_empty_node;
+ return NULL;
node = io_rsrc_node_alloc(ctx, IORING_RSRC_BUFFER);
if (!node)
@@ -850,10 +843,6 @@ int io_sqe_buffers_register(struct io_ring_ctx *ctx, void __user *arg,
ret = -EFAULT;
break;
}
- if (tag && !iov->iov_base) {
- ret = -EINVAL;
- break;
- }
}
node = io_sqe_buffer_register(ctx, iov, &last_hpage);
@@ -861,8 +850,13 @@ int io_sqe_buffers_register(struct io_ring_ctx *ctx, void __user *arg,
ret = PTR_ERR(node);
break;
}
- if (tag)
+ if (tag) {
+ if (!node) {
+ ret = -EINVAL;
+ break;
+ }
node->tag = tag;
+ }
data.nodes[i] = node;
}
@@ -957,8 +951,8 @@ static int io_clone_buffers(struct io_ring_ctx *ctx, struct io_ring_ctx *src_ctx
struct io_rsrc_node *dst_node, *src_node;
src_node = io_rsrc_node_lookup(&src_ctx->buf_table, i);
- if (src_node == rsrc_empty_node) {
- dst_node = rsrc_empty_node;
+ if (!src_node) {
+ dst_node = NULL;
} else {
dst_node = io_rsrc_node_alloc(ctx, IORING_RSRC_BUFFER);
if (!dst_node) {