6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jens Axboe [ Upstream commit 0d677936d67774f1b4ebfb3b26f207320f0fe3c6 ] Move io_match_task_safe() and helpers into cancel.c, where it belongs. Signed-off-by: Jens Axboe Stable-dep-of: fddcf4c5321b ("io_uring/cancel: don't spin on local work the task can't run") Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- 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(-) --- a/io_uring/cancel.c +++ b/io_uring/cancel.c @@ -384,3 +384,41 @@ int io_cancel_remove(struct io_ring_ctx 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; +} --- a/io_uring/cancel.h +++ b/io_uring/cancel.h @@ -21,6 +21,8 @@ int io_try_cancel(struct io_uring_task * 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, --- a/io_uring/io_uring.c +++ b/io_uring/io_uring.c @@ -210,44 +210,6 @@ static inline unsigned int __io_cqring_e return READ_ONCE(rings->cq.tail) - READ_ONCE(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); --- a/io_uring/io_uring.h +++ b/io_uring/io_uring.h @@ -185,9 +185,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)