Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

+40 -50
+7 -2
io_uring/fdinfo.c
··· 178 178 } 179 179 seq_printf(m, "UserBufs:\t%u\n", ctx->buf_table.nr); 180 180 for (i = 0; has_lock && i < ctx->buf_table.nr; i++) { 181 - struct io_mapped_ubuf *buf = ctx->buf_table.nodes[i]->buf; 181 + struct io_mapped_ubuf *buf = NULL; 182 182 183 - seq_printf(m, "%5u: 0x%llx/%u\n", i, buf->ubuf, buf->len); 183 + if (ctx->buf_table.nodes[i]) 184 + buf = ctx->buf_table.nodes[i]->buf; 185 + if (buf) 186 + seq_printf(m, "%5u: 0x%llx/%u\n", i, buf->ubuf, buf->len); 187 + else 188 + seq_printf(m, "%5u: <none>\n", i); 184 189 } 185 190 if (has_lock && !xa_empty(&ctx->personalities)) { 186 191 unsigned long index;
+2 -2
io_uring/io_uring.c
··· 947 947 static void io_preinit_req(struct io_kiocb *req, struct io_ring_ctx *ctx) 948 948 { 949 949 req->ctx = ctx; 950 - req->rsrc_nodes[IORING_RSRC_FILE] = rsrc_empty_node; 951 - req->rsrc_nodes[IORING_RSRC_BUFFER] = rsrc_empty_node; 950 + req->rsrc_nodes[IORING_RSRC_FILE] = NULL; 951 + req->rsrc_nodes[IORING_RSRC_BUFFER] = NULL; 952 952 req->link = NULL; 953 953 req->async_data = NULL; 954 954 /* not necessary, but safer to zero */
+2 -2
io_uring/notif.c
··· 117 117 notif->file = NULL; 118 118 notif->task = current; 119 119 io_get_task_refs(1); 120 - notif->rsrc_nodes[IORING_RSRC_FILE] = rsrc_empty_node; 121 - notif->rsrc_nodes[IORING_RSRC_BUFFER] = rsrc_empty_node; 120 + notif->rsrc_nodes[IORING_RSRC_FILE] = NULL; 121 + notif->rsrc_nodes[IORING_RSRC_BUFFER] = NULL; 122 122 123 123 nd = io_notif_to_data(notif); 124 124 nd->zc_report = false;
+21 -27
io_uring/rsrc.c
··· 32 32 #define IORING_MAX_FIXED_FILES (1U << 20) 33 33 #define IORING_MAX_REG_BUFFERS (1U << 14) 34 34 35 - static const struct io_mapped_ubuf dummy_ubuf = { 36 - /* set invalid range, so io_import_fixed() fails meeting it */ 37 - .ubuf = -1UL, 38 - .len = UINT_MAX, 39 - }; 40 - 41 - const struct io_rsrc_node empty_node = { 42 - .type = IORING_RSRC_BUFFER, 43 - .buf = (struct io_mapped_ubuf *) &dummy_ubuf, 44 - }; 45 - 46 35 int __io_account_mem(struct user_struct *user, unsigned long nr_pages) 47 36 { 48 37 unsigned long page_limit, cur_pages, new_pages; ··· 105 116 { 106 117 unsigned int i; 107 118 108 - if (node->buf != &dummy_ubuf) { 119 + if (node->buf) { 109 120 struct io_mapped_ubuf *imu = node->buf; 110 121 111 122 if (!refcount_dec_and_test(&imu->refs)) ··· 254 265 err = io_buffer_validate(iov); 255 266 if (err) 256 267 break; 257 - if (!iov->iov_base && tag) { 258 - err = -EINVAL; 259 - break; 260 - } 261 268 node = io_sqe_buffer_register(ctx, iov, &last_hpage); 262 269 if (IS_ERR(node)) { 263 270 err = PTR_ERR(node); 264 271 break; 265 272 } 273 + if (tag) { 274 + if (!node) { 275 + err = -EINVAL; 276 + break; 277 + } 278 + node->tag = tag; 279 + } 266 280 i = array_index_nospec(up->offset + done, ctx->buf_table.nr); 267 281 io_reset_rsrc_node(&ctx->buf_table, i); 268 282 ctx->buf_table.nodes[i] = node; 269 - if (tag) 270 - node->tag = tag; 271 283 if (ctx->compat) 272 284 user_data += sizeof(struct compat_iovec); 273 285 else ··· 581 591 /* check previously registered pages */ 582 592 for (i = 0; i < ctx->buf_table.nr; i++) { 583 593 struct io_rsrc_node *node = ctx->buf_table.nodes[i]; 584 - struct io_mapped_ubuf *imu = node->buf; 594 + struct io_mapped_ubuf *imu; 585 595 596 + if (!node) 597 + continue; 598 + imu = node->buf; 586 599 for (j = 0; j < imu->nr_bvecs; j++) { 587 600 if (!PageCompound(imu->bvec[j].bv_page)) 588 601 continue; ··· 735 742 bool coalesced; 736 743 737 744 if (!iov->iov_base) 738 - return rsrc_empty_node; 745 + return NULL; 739 746 740 747 node = io_rsrc_node_alloc(ctx, IORING_RSRC_BUFFER); 741 748 if (!node) ··· 843 850 ret = -EFAULT; 844 851 break; 845 852 } 846 - if (tag && !iov->iov_base) { 847 - ret = -EINVAL; 848 - break; 849 - } 850 853 } 851 854 852 855 node = io_sqe_buffer_register(ctx, iov, &last_hpage); ··· 850 861 ret = PTR_ERR(node); 851 862 break; 852 863 } 853 - if (tag) 864 + if (tag) { 865 + if (!node) { 866 + ret = -EINVAL; 867 + break; 868 + } 854 869 node->tag = tag; 870 + } 855 871 data.nodes[i] = node; 856 872 } 857 873 ··· 951 957 struct io_rsrc_node *dst_node, *src_node; 952 958 953 959 src_node = io_rsrc_node_lookup(&src_ctx->buf_table, i); 954 - if (src_node == rsrc_empty_node) { 955 - dst_node = rsrc_empty_node; 960 + if (!src_node) { 961 + dst_node = NULL; 956 962 } else { 957 963 dst_node = io_rsrc_node_alloc(ctx, IORING_RSRC_BUFFER); 958 964 if (!dst_node) {
+7 -16
io_uring/rsrc.h
··· 67 67 int io_register_rsrc(struct io_ring_ctx *ctx, void __user *arg, 68 68 unsigned int size, unsigned int type); 69 69 70 - extern const struct io_rsrc_node empty_node; 71 - #define rsrc_empty_node (struct io_rsrc_node *) &empty_node 72 - 73 70 static inline struct io_rsrc_node *io_rsrc_node_lookup(struct io_rsrc_data *data, 74 71 int index) 75 72 { ··· 77 80 78 81 static inline void io_put_rsrc_node(struct io_rsrc_node *node) 79 82 { 80 - if (node != rsrc_empty_node && !--node->refs) 83 + if (node && !--node->refs) 81 84 io_free_rsrc_node(node); 82 85 } 83 86 ··· 94 97 95 98 static inline void io_req_put_rsrc_nodes(struct io_kiocb *req) 96 99 { 97 - if (req->rsrc_nodes[IORING_RSRC_FILE] != rsrc_empty_node) { 98 - io_put_rsrc_node(req->rsrc_nodes[IORING_RSRC_FILE]); 99 - req->rsrc_nodes[IORING_RSRC_FILE] = rsrc_empty_node; 100 - } 101 - if (req->rsrc_nodes[IORING_RSRC_BUFFER] != rsrc_empty_node) { 102 - io_put_rsrc_node(req->rsrc_nodes[IORING_RSRC_BUFFER]); 103 - req->rsrc_nodes[IORING_RSRC_BUFFER] = rsrc_empty_node; 104 - } 100 + io_put_rsrc_node(req->rsrc_nodes[IORING_RSRC_FILE]); 101 + io_put_rsrc_node(req->rsrc_nodes[IORING_RSRC_BUFFER]); 102 + req->rsrc_nodes[IORING_RSRC_FILE] = NULL; 103 + req->rsrc_nodes[IORING_RSRC_BUFFER] = NULL; 105 104 } 106 105 107 106 static inline void io_req_assign_rsrc_node(struct io_kiocb *req, 108 107 struct io_rsrc_node *node) 109 108 { 110 - if (node != rsrc_empty_node) { 111 - node->refs++; 112 - req->rsrc_nodes[node->type] = node; 113 - } 109 + node->refs++; 110 + req->rsrc_nodes[node->type] = node; 114 111 } 115 112 116 113 int io_files_update(struct io_kiocb *req, unsigned int issue_flags);
+1 -1
io_uring/splice.c
··· 35 35 if (unlikely(sp->flags & ~valid_flags)) 36 36 return -EINVAL; 37 37 sp->splice_fd_in = READ_ONCE(sqe->splice_fd_in); 38 - sp->rsrc_node = rsrc_empty_node; 38 + sp->rsrc_node = NULL; 39 39 req->flags |= REQ_F_FORCE_ASYNC; 40 40 return 0; 41 41 }