Skip to contentSkip to conversation

Various minor cleanups

PATCH In review Jens Axboe 2 participants 10 messages Nov 3, 2025 – Nov 5, 2025 io_uring

lore
Share & tools
lore

Jens Axboe

author maintainer
#0 lore raw

cover Various minor cleanups

Hi,

No particular theme to this "series", it's mostly just moving code around a bit to more appropriate spots, and removing dead declarations that are entirely unneeded. Mostly in preparation for moving more of the cancel code into cancel.c and out of io_uring.c.

No functional changes in this series.

 io_uring/cancel.c   | 44 ++++++++++++++++++++++++++++++++++++++++++++
 io_uring/cancel.h   |  2 ++
 io_uring/io_uring.c | 44 --------------------------------------------
 io_uring/io_uring.h |  3 ---
 io_uring/memmap.h   |  5 -----
 io_uring/net.c      | 14 +++++++++++---
 io_uring/notif.h    |  8 --------
 io_uring/rsrc.c     |  4 ++--
 io_uring/slist.h    | 18 ------------------
 9 files changed, 59 insertions(+), 83 deletions(-)
Signature · 1 line
Jens Axboe
author maintainer
#1 lore raw

PATCH 1/6 io_uring/slist: remove unused wq list splice helpers

Nobody is using those helpers anymore, get rid of them.

---
 io_uring/slist.h | 18 ------------------
 1 file changed, 18 deletions(-)
io_uring/slist.h +0 -18
index 0eb194817242..7ef747442754 100644
@@ -67,24 +67,6 @@ static inline void wq_list_cut(struct io_wq_work_list *list,
 	last->next = NULL;
 }
 
-static inline void __wq_list_splice(struct io_wq_work_list *list,
-				    struct io_wq_work_node *to)
-{
-	list->last->next = to->next;
-	to->next = list->first;
-	INIT_WQ_LIST(list);
-}
-
-static inline bool wq_list_splice(struct io_wq_work_list *list,
-				  struct io_wq_work_node *to)
-{
-	if (!wq_list_empty(list)) {
-		__wq_list_splice(list, to);
-		return true;
-	}
-	return false;
-}
-
 static inline void wq_stack_add_head(struct io_wq_work_node *node,
 				     struct io_wq_work_node *stack)
 {
Signature · 1 line
2.51.0
author maintainer
#2 lore raw

PATCH 2/6 io_uring/rsrc: use get/put_user() for integer copy

In reply to Jens Axboe

It's just getting an integer from userspace, installing a file, then copying the output direct descriptor back. No need to use the full copy_to/from_user() for that.

---
 io_uring/rsrc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
io_uring/rsrc.c +2 -2
index d787c16dc1c3..4cc38eb56758 100644
@@ -454,7 +454,7 @@ static int io_files_update_with_index_alloc(struct io_kiocb *req,
 		return -ENXIO;
 
 	for (done = 0; done < up->nr_args; done++) {
-		if (copy_from_user(&fd, &fds[done], sizeof(fd))) {
+		if (get_user(fd, &fds[done])) {
 			ret = -EFAULT;
 			break;
 		}
@@ -468,7 +468,7 @@ static int io_files_update_with_index_alloc(struct io_kiocb *req,
 					  IORING_FILE_INDEX_ALLOC);
 		if (ret < 0)
 			break;
-		if (copy_to_user(&fds[done], &ret, sizeof(ret))) {
+		if (put_user(ret, &fds[done])) {
 			__io_close_fixed(req->ctx, issue_flags, ret);
 			ret = -EFAULT;
 			break;
Signature · 1 line
2.51.0
author maintainer
#3 lore raw

PATCH 3/6 io_uring/notif: move io_notif_flush() to net.c

In reply to Jens Axboe

It's specific to the networking side, move it in there.

---
 io_uring/net.c   | 14 +++++++++++---
 io_uring/notif.h |  8 --------
 2 files changed, 11 insertions(+), 11 deletions(-)
io_uring/net.c +11 -3
index f99b90c762fc..a786d5a01a2e 100644
@@ -1303,6 +1303,14 @@ int io_recvzc(struct io_kiocb *req, unsigned int issue_flags)
 	return IOU_RETRY;
 }
 
+static void io_send_notif_flush(struct io_kiocb *notif)
+	__must_hold(&notif->ctx->uring_lock)
+{
+	struct io_notif_data *nd = io_notif_to_data(notif);
+
+	io_tx_ubuf_complete(NULL, &nd->uarg, true);
+}
+
 void io_send_zc_cleanup(struct io_kiocb *req)
 {
 	struct io_sr_msg *zc = io_kiocb_to_cmd(req, struct io_sr_msg);
@@ -1311,7 +1319,7 @@ void io_send_zc_cleanup(struct io_kiocb *req)
 	if (req_has_async_data(req))
 		io_netmsg_iovec_free(io);
 	if (zc->notif) {
-		io_notif_flush(zc->notif);
+		io_send_notif_flush(zc->notif);
 		zc->notif = NULL;
 	}
 }
@@ -1512,7 +1520,7 @@ int io_send_zc(struct io_kiocb *req, unsigned int issue_flags)
 	 * flushing notif to io_send_zc_cleanup()
 	 */
 	if (!(issue_flags & IO_URING_F_UNLOCKED)) {
-		io_notif_flush(zc->notif);
+		io_send_notif_flush(zc->notif);
 		zc->notif = NULL;
 		io_req_msg_cleanup(req, 0);
 	}
@@ -1582,7 +1590,7 @@ int io_sendmsg_zc(struct io_kiocb *req, unsigned int issue_flags)
 	 * flushing notif to io_send_zc_cleanup()
 	 */
 	if (!(issue_flags & IO_URING_F_UNLOCKED)) {
-		io_notif_flush(sr->notif);
+		io_send_notif_flush(sr->notif);
 		sr->notif = NULL;
 		io_req_msg_cleanup(req, 0);
 	}
io_uring/notif.h +0 -8
index f3589cfef4a9..a8e079991997 100644
@@ -32,14 +32,6 @@ static inline struct io_notif_data *io_notif_to_data(struct io_kiocb *notif)
 	return io_kiocb_to_cmd(notif, struct io_notif_data);
 }
 
-static inline void io_notif_flush(struct io_kiocb *notif)
-	__must_hold(&notif->ctx->uring_lock)
-{
-	struct io_notif_data *nd = io_notif_to_data(notif);
-
-	io_tx_ubuf_complete(NULL, &nd->uarg, true);
-}
-
 static inline int io_notif_account_mem(struct io_kiocb *notif, unsigned len)
 {
 	struct io_ring_ctx *ctx = notif->ctx;
Signature · 1 line
2.51.0
author maintainer
#7 lore raw

PATCH 4/6 io_uring/memmap: remove dead io_create_region_mmap_safe() declaration

In reply to Jens Axboe

No longer used and doesn't even exist, kill it from the memmap header file.

---
 io_uring/memmap.h | 5 -----
 1 file changed, 5 deletions(-)
io_uring/memmap.h +0 -5
index 58002976e0c3..f9e94458c01f 100644
@@ -21,11 +21,6 @@ int io_create_region(struct io_ring_ctx *ctx, struct io_mapped_region *mr,
 		     struct io_uring_region_desc *reg,
 		     unsigned long mmap_offset);
 
-int io_create_region_mmap_safe(struct io_ring_ctx *ctx,
-				struct io_mapped_region *mr,
-				struct io_uring_region_desc *reg,
-				unsigned long mmap_offset);
-
 static inline void *io_region_get_ptr(struct io_mapped_region *mr)
 {
 	return mr->ptr;
Signature · 1 line
2.51.0
author maintainer
#8 lore raw

PATCH 5/6 io_uring/cancel: move request/task cancelation logic into cancel.c

In reply to Jens Axboe

Move io_match_task_safe() and helpers into cancel.c, where it belongs.

---
 io_uring/cancel.c   | 38 ++++++++++++++++++++++++++++++++++++++
 io_uring/cancel.h   |  2 ++
 io_uring/io_uring.c | 38 --------------------------------------
 io_uring/io_uring.h |  3 ---
 4 files changed, 40 insertions(+), 41 deletions(-)
io_uring/cancel.c +38 -0
index 64b51e82baa2..2754ea80e288 100644
@@ -384,3 +384,41 @@ int io_cancel_remove(struct io_ring_ctx *ctx, struct io_cancel_data *cd,
 	io_ring_submit_unlock(ctx, issue_flags);
 	return nr ?: -ENOENT;
 }
+
+static bool io_match_linked(struct io_kiocb *head)
+{
+	struct io_kiocb *req;
+
+	io_for_each_link(req, head) {
+		if (req->flags & REQ_F_INFLIGHT)
+			return true;
+	}
+	return false;
+}
+
+/*
+ * As io_match_task() but protected against racing with linked timeouts.
+ * User must not hold timeout_lock.
+ */
+bool io_match_task_safe(struct io_kiocb *head, struct io_uring_task *tctx,
+			bool cancel_all)
+{
+	bool matched;
+
+	if (tctx && head->tctx != tctx)
+		return false;
+	if (cancel_all)
+		return true;
+
+	if (head->flags & REQ_F_LINK_TIMEOUT) {
+		struct io_ring_ctx *ctx = head->ctx;
+
+		/* protect against races with linked timeouts */
+		raw_spin_lock_irq(&ctx->timeout_lock);
+		matched = io_match_linked(head);
+		raw_spin_unlock_irq(&ctx->timeout_lock);
+	} else {
+		matched = io_match_linked(head);
+	}
+	return matched;
+}
io_uring/cancel.h +2 -0
index 43e9bb74e9d1..6d5208e9d7a6 100644
@@ -23,6 +23,8 @@ int io_try_cancel(struct io_uring_task *tctx, struct io_cancel_data *cd,
 
 int io_sync_cancel(struct io_ring_ctx *ctx, void __user *arg);
 bool io_cancel_req_match(struct io_kiocb *req, struct io_cancel_data *cd);
+bool io_match_task_safe(struct io_kiocb *head, struct io_uring_task *tctx,
+			bool cancel_all);
 
 bool io_cancel_remove_all(struct io_ring_ctx *ctx, struct io_uring_task *tctx,
 			  struct hlist_head *list, bool cancel_all,
io_uring/io_uring.c +0 -38
index 01631b6ff442..75bd049a1efd 100644
@@ -207,44 +207,6 @@ static inline unsigned int __io_cqring_events_user(struct io_ring_ctx *ctx)
 	return READ_ONCE(ctx->rings->cq.tail) - READ_ONCE(ctx->rings->cq.head);
 }
 
-static bool io_match_linked(struct io_kiocb *head)
-{
-	struct io_kiocb *req;
-
-	io_for_each_link(req, head) {
-		if (req->flags & REQ_F_INFLIGHT)
-			return true;
-	}
-	return false;
-}
-
-/*
- * As io_match_task() but protected against racing with linked timeouts.
- * User must not hold timeout_lock.
- */
-bool io_match_task_safe(struct io_kiocb *head, struct io_uring_task *tctx,
-			bool cancel_all)
-{
-	bool matched;
-
-	if (tctx && head->tctx != tctx)
-		return false;
-	if (cancel_all)
-		return true;
-
-	if (head->flags & REQ_F_LINK_TIMEOUT) {
-		struct io_ring_ctx *ctx = head->ctx;
-
-		/* protect against races with linked timeouts */
-		raw_spin_lock_irq(&ctx->timeout_lock);
-		matched = io_match_linked(head);
-		raw_spin_unlock_irq(&ctx->timeout_lock);
-	} else {
-		matched = io_match_linked(head);
-	}
-	return matched;
-}
-
 static inline void req_fail_link_node(struct io_kiocb *req, int res)
 {
 	req_set_fail(req);
io_uring/io_uring.h +0 -3
index f97356ce29d0..2f4d43e69648 100644
@@ -174,9 +174,6 @@ void io_queue_next(struct io_kiocb *req);
 void io_task_refs_refill(struct io_uring_task *tctx);
 bool __io_alloc_req_refill(struct io_ring_ctx *ctx);
 
-bool io_match_task_safe(struct io_kiocb *head, struct io_uring_task *tctx,
-			bool cancel_all);
-
 void io_activate_pollwq(struct io_ring_ctx *ctx);
 
 static inline void io_lockdep_assert_cq_locked(struct io_ring_ctx *ctx)
Signature · 1 line
2.51.0
author maintainer
#9 lore raw

PATCH 6/6 io_uring/cancel: move __io_uring_cancel() into cancel.c

In reply to Jens Axboe

Yet another function that should be in cancel.c, move it over.

---
 io_uring/cancel.c   | 6 ++++++
 io_uring/io_uring.c | 6 ------
 2 files changed, 6 insertions(+), 6 deletions(-)
io_uring/cancel.c +6 -0
index 2754ea80e288..3ba82a1bfe80 100644
@@ -422,3 +422,9 @@ bool io_match_task_safe(struct io_kiocb *head, struct io_uring_task *tctx,
 	}
 	return matched;
 }
+
+void __io_uring_cancel(bool cancel_all)
+{
+	io_uring_unreg_ringfd();
+	io_uring_cancel_generic(cancel_all, NULL);
+}
io_uring/io_uring.c +0 -6
index 75bd049a1efd..b3be305b99be 100644
@@ -3336,12 +3336,6 @@ __cold void io_uring_cancel_generic(bool cancel_all, struct io_sq_data *sqd)
 	}
 }
 
-void __io_uring_cancel(bool cancel_all)
-{
-	io_uring_unreg_ringfd();
-	io_uring_cancel_generic(cancel_all, NULL);
-}
-
 static struct io_uring_reg_wait *io_get_ext_arg_reg(struct io_ring_ctx *ctx,
 			const struct io_uring_getevents_arg __user *uarg)
 {
Signature · 1 line
2.51.0
#4 lore raw

Re: [PATCH 3/6] io_uring/notif: move io_notif_flush() to net.c

In reply to Jens Axboe
Quoted 1 line · Jens Axboe

It's specific to the networking side, move it in there.

It's there because notif.[c,h] know about struct io_notif_data internals and net.c in general shouldn't, otherwise it's not any more net specific than anything else notification related.

Signature · 1 line
Pavel Begunkov
author maintainer
#5 lore raw

Re: [PATCH 3/6] io_uring/notif: move io_notif_flush() to net.c

Quoted 6 lines · Pavel Begunkov
Quoted 1 line · Jens Axboe

It's specific to the networking side, move it in there.

It's there because notif.[c,h] know about struct io_notif_data internals and net.c in general shouldn't, otherwise it's not any more net specific than anything else notification related.

I guess the notif stuff is all networking anyway, almost doesn't make sense to have it split out. But as long as we do, we can keep that stuff in there. I'll drop this one.

Signature · 1 line
Jens Axboe
#6 lore raw

Re: [PATCH 3/6] io_uring/notif: move io_notif_flush() to net.c

Quoted 9 lines · Jens Axboe
Quoted 6 lines · Pavel Begunkov
Quoted 1 line · Jens Axboe

It's specific to the networking side, move it in there.

It's there because notif.[c,h] know about struct io_notif_data internals and net.c in general shouldn't, otherwise it's not any more net specific than anything else notification related.

I guess the notif stuff is all networking anyway, almost doesn't

Right, that's my point. And separation is not a bad thing considering that net.c is a bit too fat.

Quoted 2 lines

make sense to have it split out. But as long as we do, we can keep that stuff in there. I'll drop this one.

Signature · 1 line
Pavel Begunkov