From: Jens Axboe <axboe@kernel.dk>
To: io-uring@vger.kernel.org
Cc: Jens Axboe <axboe@kernel.dk>
Subject: [PATCH 5/6] io_uring/cancel: move request/task cancelation logic into cancel.c
Date: Mon, 3 Nov 2025 11:48:02 -0700 [thread overview]
Message-ID: <20251103184937.61634-6-axboe@kernel.dk> (raw)
In-Reply-To: <20251103184937.61634-1-axboe@kernel.dk>
Move io_match_task_safe() and helpers into cancel.c, where it belongs.
Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
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(-)
diff --git a/io_uring/cancel.c b/io_uring/cancel.c
index 64b51e82baa2..2754ea80e288 100644
--- a/io_uring/cancel.c
+++ b/io_uring/cancel.c
@@ -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;
+}
diff --git a/io_uring/cancel.h b/io_uring/cancel.h
index 43e9bb74e9d1..6d5208e9d7a6 100644
--- a/io_uring/cancel.h
+++ b/io_uring/cancel.h
@@ -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,
diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
index 01631b6ff442..75bd049a1efd 100644
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -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);
diff --git a/io_uring/io_uring.h b/io_uring/io_uring.h
index f97356ce29d0..2f4d43e69648 100644
--- a/io_uring/io_uring.h
+++ b/io_uring/io_uring.h
@@ -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)
--
2.51.0
next prev parent reply other threads:[~2025-11-03 18:49 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-03 18:47 [PATCHSET 0/6] Various minor cleanups Jens Axboe
2025-11-03 18:47 ` [PATCH 1/6] io_uring/slist: remove unused wq list splice helpers Jens Axboe
2025-11-03 18:47 ` [PATCH 2/6] io_uring/rsrc: use get/put_user() for integer copy Jens Axboe
2025-11-03 18:48 ` [PATCH 3/6] io_uring/notif: move io_notif_flush() to net.c Jens Axboe
2025-11-04 13:05 ` Pavel Begunkov
2025-11-04 16:31 ` Jens Axboe
2025-11-05 13:14 ` Pavel Begunkov
2025-11-03 18:48 ` [PATCH 4/6] io_uring/memmap: remove dead io_create_region_mmap_safe() declaration Jens Axboe
2025-11-03 18:48 ` Jens Axboe [this message]
2025-11-03 18:48 ` [PATCH 6/6] io_uring/cancel: move __io_uring_cancel() into cancel.c Jens Axboe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251103184937.61634-6-axboe@kernel.dk \
--to=axboe@kernel.dk \
--cc=io-uring@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.