[ldv-project] [PATCH 5.10 1/2] io_uring: cancel files inflight counting
Fedor Pchelkin
pchelkin at ispras.ru
Sat Aug 20 23:50:43 MSK 2022
From: Pavel Begunkov <asml.silence at gmail.com>
To not skip events, io_uring_cancel_files() is pretty much counts on
io_uring_count_inflight() to be monotonous for the time it's used.
That's not the case when it includes requests of other thats that are
PF_EXITING.
Cancel as before, but don't account extra in io_uring_count_inflight(),
we can hang otherwise.
Signed-off-by: Pavel Begunkov <asml.silence at gmail.com>
Signed-off-by: Fedor Pchelkin <pchelkin at ispras.ru>
---
fs/io_uring.c | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/fs/io_uring.c b/fs/io_uring.c
index a952288b2ab8..25f2b87673bf 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -1028,15 +1028,14 @@ static void io_refs_resurrect(struct percpu_ref *ref, struct completion *compl)
percpu_ref_put(ref);
}
-static bool io_match_task(struct io_kiocb *head,
- struct task_struct *task,
- struct files_struct *files)
+static bool __io_match_task(struct io_kiocb *head, struct task_struct *task,
+ struct files_struct *files, bool match_exiting)
{
struct io_kiocb *link;
if (task && head->task != task) {
/* in terms of cancelation, always match if req task is dead */
- if (head->task->flags & PF_EXITING)
+ if (match_exiting && (head->task->flags & PF_EXITING))
return true;
return false;
}
@@ -1053,6 +1052,12 @@ static bool io_match_task(struct io_kiocb *head,
return false;
}
+static bool io_match_task(struct io_kiocb *head,
+ struct task_struct *task,
+ struct files_struct *files)
+{
+ return __io_match_task(head, task, files, true);
+}
static void io_sq_thread_drop_mm(void)
{
@@ -8656,7 +8661,7 @@ static int io_uring_count_inflight(struct io_ring_ctx *ctx,
spin_lock_irq(&ctx->inflight_lock);
list_for_each_entry(req, &ctx->inflight_list, inflight_entry)
- cnt += io_match_task(req, task, files);
+ cnt += __io_match_task(req, task, files, false);
spin_unlock_irq(&ctx->inflight_lock);
return cnt;
}
--
2.25.1
More information about the ldv-project
mailing list