Skip to contentSkip to conversation

task/files cancellation fixes

PATCH In review Pavel Begunkov 2 participants 6 messages Dec 20, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover task/files cancellation fixes

First two are only for task cancellation, the last one for both.

Jens, do you remember the exact reason why you added the check removed in [3/3]? I have a clue, but that stuff doesn't look right regardless. See "exit: do exit_task_work() before shooting off mm" thread.

Pavel Begunkov (3):
io_uring: always progress task_work on task cancel
io_uring: end waiting before task cancel attempts
io_uring: fix cancellation hangs

 fs/io_uring.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)
Signature · 1 line
2.24.0
#1 lore raw

PATCH 1/3 io_uring: always progress task_work on task cancel

Might happen that __io_uring_cancel_task_requests() cancels nothing but there are task_works pending. We need to always run them.

---
 fs/io_uring.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/io_uring.c +1 -1
index f3690dfdd564..051461b5bf52 100644
@@ -8794,9 +8794,9 @@ static void __io_uring_cancel_task_requests(struct io_ring_ctx *ctx,
 
 		ret |= io_poll_remove_all(ctx, task, NULL);
 		ret |= io_kill_timeouts(ctx, task, NULL);
+		ret |= io_run_task_work();
 		if (!ret)
 			break;
-		io_run_task_work();
 		cond_resched();
 	}
 }
Signature · 1 line
2.24.0
#2 lore raw

PATCH 2/3 io_uring: end waiting before task cancel attempts

In reply to Pavel Begunkov

Get rid of TASK_UNINTERRUPTIBLE and waiting with finish_wait before going for next iteration in __io_uring_task_cancel(), because __io_uring_files_cancel() doesn't expect that sheduling is disallowed.

---
 fs/io_uring.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/io_uring.c +1 -1
index 051461b5bf52..30edf47a8f1a 100644
@@ -8982,9 +8982,9 @@ void __io_uring_task_cancel(void)
 		if (inflight != tctx_inflight(tctx))
 			continue;
 		schedule();
+		finish_wait(&tctx->wait, &wait);
 	} while (1);
 
-	finish_wait(&tctx->wait, &wait);
 	atomic_dec(&tctx->in_idle);
 }
 
Signature · 1 line
2.24.0
#3 lore raw

PATCH 3/3 io_uring: fix cancellation hangs

In reply to Pavel Begunkov

We may enter files cancellation with requests that we want to cancel and that are currently enqueued as task_work. However, before that happens do_exit() sets PF_EXITING, disabling io_run_task_work() and so locking up cancellation.

Also, if run between setting PF_EXITING and exit_task_work(), as the case exit_files() and so io_uring cancellation, task_work_add() might actually enqueue more task works.

---
 fs/io_uring.c | 6 ------
 1 file changed, 6 deletions(-)
fs/io_uring.c +0 -6
index 30edf47a8f1a..941fe9b64fd9 100644
@@ -2357,12 +2357,6 @@ static inline unsigned int io_put_rw_kbuf(struct io_kiocb *req)
 
 static inline bool io_run_task_work(void)
 {
-	/*
-	 * Not safe to run on exiting task, and the task_work handling will
-	 * not add work to such a task.
-	 */
-	if (unlikely(current->flags & PF_EXITING))
-		return false;
 	if (current->task_works) {
 		__set_current_state(TASK_RUNNING);
 		task_work_run();
Signature · 1 line
2.24.0
#4 lore raw
In reply to Pavel Begunkov
Quoted 6 lines · Pavel Begunkov

First two are only for task cancellation, the last one for both.

Jens, do you remember the exact reason why you added the check removed in [3/3]? I have a clue, but that stuff doesn't look right regardless. See "exit: do exit_task_work() before shooting off mm" thread.

The question is answered, the bug is still here, but that's too early for 3/3. Please consider first 2 patches.

Quoted 9 lines

Pavel Begunkov (3):
io_uring: always progress task_work on task cancel
io_uring: end waiting before task cancel attempts
io_uring: fix cancellation hangs

 fs/io_uring.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)
Signature · 1 line
Pavel Begunkov
maintainer
#5 lore raw
Quoted 10 lines · Pavel Begunkov
Quoted 6 lines · Pavel Begunkov

First two are only for task cancellation, the last one for both.

Jens, do you remember the exact reason why you added the check removed in [3/3]? I have a clue, but that stuff doesn't look right regardless. See "exit: do exit_task_work() before shooting off mm" thread.

The question is answered, the bug is still here, but that's too early for 3/3. Please consider first 2 patches.

Yep, first two look good to me, thanks!

Signature · 1 line
Jens Axboe