Skip to contentSkip to conversation

io_uring/rsrc: get rid of the empty node and dummy_ubuf

PATCH New Jens Axboe 1 participant 1 message Oct 30, 2024 io_uring

lore
Share & tools
lore

Jens Axboe

author maintainer
#0 lore raw

PATCH 1/1 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.

---

io_uring/io_uring.c +2 -2
index 3a535e9e8ac3..44a772013c09 100644
@@ -947,8 +947,8 @@ void io_req_defer_failed(struct io_kiocb *req, s32 res)
 static void io_preinit_req(struct io_kiocb *req, struct io_ring_ctx *ctx)
 {
 	req->ctx = ctx;
-	req->rsrc_nodes[IORING_RSRC_FILE] = rsrc_empty_node;
-	req->rsrc_nodes[IORING_RSRC_BUFFER] = rsrc_empty_node;
+	req->rsrc_nodes[IORING_RSRC_FILE] = NULL;
+	req->rsrc_nodes[IORING_RSRC_BUFFER] = NULL;
 	req->link = NULL;
 	req->async_data = NULL;
 	/* not necessary, but safer to zero */
io_uring/notif.c +2 -2
index 44bf21c0f810..4f02e969cf08 100644
@@ -117,8 +117,8 @@ struct io_kiocb *io_alloc_notif(struct io_ring_ctx *ctx)
 	notif->file = NULL;
 	notif->task = current;
 	io_get_task_refs(1);
-	notif->rsrc_nodes[IORING_RSRC_FILE] = rsrc_empty_node;
-	notif->rsrc_nodes[IORING_RSRC_BUFFER] = rsrc_empty_node;
+	notif->rsrc_nodes[IORING_RSRC_FILE] = NULL;
+	notif->rsrc_nodes[IORING_RSRC_BUFFER] = NULL;
 
 	nd = io_notif_to_data(notif);
 	nd->zc_report = false;
io_uring/rsrc.c +17 -26

94 lines not on this page · raw message

io_uring/rsrc.h +7 -16
index 43b19e516f5f..a40fad783a69 100644
@@ -67,9 +67,6 @@ int io_register_rsrc_update(struct io_ring_ctx *ctx, void __user *arg,
 int io_register_rsrc(struct io_ring_ctx *ctx, void __user *arg,
 			unsigned int size, unsigned int type);
 
-extern const struct io_rsrc_node empty_node;
-#define rsrc_empty_node	(struct io_rsrc_node *) &empty_node
-
 static inline struct io_rsrc_node *io_rsrc_node_lookup(struct io_rsrc_data *data,
 						       int index)
 {
@@ -80,7 +77,7 @@ static inline struct io_rsrc_node *io_rsrc_node_lookup(struct io_rsrc_data *data
 
 static inline void io_put_rsrc_node(struct io_rsrc_node *node)
 {
-	if (node != rsrc_empty_node && !--node->refs)
+	if (node && !--node->refs)
 		io_free_rsrc_node(node);
 }
 
@@ -97,23 +94,17 @@ static inline bool io_reset_rsrc_node(struct io_rsrc_data *data, int index)
 
 static inline void io_req_put_rsrc_nodes(struct io_kiocb *req)
 {
-	if (req->rsrc_nodes[IORING_RSRC_FILE] != rsrc_empty_node) {
-		io_put_rsrc_node(req->rsrc_nodes[IORING_RSRC_FILE]);
-		req->rsrc_nodes[IORING_RSRC_FILE] = rsrc_empty_node;
-	}
-	if (req->rsrc_nodes[IORING_RSRC_BUFFER] != rsrc_empty_node) {
-		io_put_rsrc_node(req->rsrc_nodes[IORING_RSRC_BUFFER]);
-		req->rsrc_nodes[IORING_RSRC_BUFFER] = rsrc_empty_node;
-	}
+	io_put_rsrc_node(req->rsrc_nodes[IORING_RSRC_FILE]);
+	io_put_rsrc_node(req->rsrc_nodes[IORING_RSRC_BUFFER]);
+	req->rsrc_nodes[IORING_RSRC_FILE] = NULL;
+	req->rsrc_nodes[IORING_RSRC_BUFFER] = NULL;
 }
 
 static inline void io_req_assign_rsrc_node(struct io_kiocb *req,
 					   struct io_rsrc_node *node)
 {
-	if (node != rsrc_empty_node) {
-		node->refs++;
-		req->rsrc_nodes[node->type] = node;
-	}
+	node->refs++;
+	req->rsrc_nodes[node->type] = node;
 }
 
 int io_files_update(struct io_kiocb *req, unsigned int issue_flags);
io_uring/splice.c +1 -1
index deeb8bb18651..e8ed15f4ea1a 100644
@@ -35,7 +35,7 @@ static int __io_splice_prep(struct io_kiocb *req,
 	if (unlikely(sp->flags & ~valid_flags))
 		return -EINVAL;
 	sp->splice_fd_in = READ_ONCE(sqe->splice_fd_in);
-	sp->rsrc_node = rsrc_empty_node;
+	sp->rsrc_node = NULL;
 	req->flags |= REQ_F_FORCE_ASYNC;
 	return 0;
 }
Signature · 1 line
Jens Axboe