* [PATCH 0/2] cancellation fixes
@ 2021-01-04 20:39 Pavel Begunkov
2021-01-04 20:39 ` [PATCH -v2 2/2] io_uring: cancel more aggressively in exit_work Pavel Begunkov
` (3 more replies)
0 siblings, 4 replies; 7+ messages in thread
From: Pavel Begunkov @ 2021-01-04 20:39 UTC (permalink / raw)
To: Jens Axboe, io-uring
[previously a part of "bunch of random fixes"]
haven't changed since then
Pavel Begunkov (2):
io_uring: drop file refs after task cancel
io_uring: cancel more aggressively in exit_work
fs/io_uring.c | 38 +++++++++++++++++++++++++-------------
1 file changed, 25 insertions(+), 13 deletions(-)
--
2.24.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v2 1/2] io_uring: drop file refs after task cancel
2021-01-04 20:43 ` [PATCH v2 1/2] io_uring: drop file refs after task cancel Pavel Begunkov
@ 2021-01-04 20:39 ` Pavel Begunkov
0 siblings, 0 replies; 7+ messages in thread
From: Pavel Begunkov @ 2021-01-04 20:39 UTC (permalink / raw)
To: Jens Axboe, io-uring
io_uring fds marked O_CLOEXEC and we explicitly cancel all requests
before going through exec, so we don't want to leave task's file
references to not our anymore io_uring instances.
Signed-off-by: Pavel Begunkov <[email protected]>
---
fs/io_uring.c | 25 ++++++++++++++++---------
1 file changed, 16 insertions(+), 9 deletions(-)
diff --git a/fs/io_uring.c b/fs/io_uring.c
index 445035b24a50..85de42c42433 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -8958,6 +8958,15 @@ static void io_uring_attempt_task_drop(struct file *file)
io_uring_del_task_file(file);
}
+static void io_uring_remove_task_files(struct io_uring_task *tctx)
+{
+ struct file *file;
+ unsigned long index;
+
+ xa_for_each(&tctx->xa, index, file)
+ io_uring_del_task_file(file);
+}
+
void __io_uring_files_cancel(struct files_struct *files)
{
struct io_uring_task *tctx = current->io_uring;
@@ -8966,16 +8975,12 @@ void __io_uring_files_cancel(struct files_struct *files)
/* make sure overflow events are dropped */
atomic_inc(&tctx->in_idle);
-
- xa_for_each(&tctx->xa, index, file) {
- struct io_ring_ctx *ctx = file->private_data;
-
- io_uring_cancel_task_requests(ctx, files);
- if (files)
- io_uring_del_task_file(file);
- }
-
+ xa_for_each(&tctx->xa, index, file)
+ io_uring_cancel_task_requests(file->private_data, files);
atomic_dec(&tctx->in_idle);
+
+ if (files)
+ io_uring_remove_task_files(tctx);
}
static s64 tctx_inflight(struct io_uring_task *tctx)
@@ -9038,6 +9043,8 @@ void __io_uring_task_cancel(void)
} while (1);
atomic_dec(&tctx->in_idle);
+
+ io_uring_remove_task_files(tctx);
}
static int io_uring_flush(struct file *file, void *data)
--
2.24.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH -v2 2/2] io_uring: cancel more aggressively in exit_work
2021-01-04 20:39 [PATCH 0/2] cancellation fixes Pavel Begunkov
@ 2021-01-04 20:39 ` Pavel Begunkov
2021-01-04 20:43 ` Pavel Begunkov
2021-01-04 20:43 ` [PATCH 0/2] cancellation fixes Pavel Begunkov
` (2 subsequent siblings)
3 siblings, 1 reply; 7+ messages in thread
From: Pavel Begunkov @ 2021-01-04 20:39 UTC (permalink / raw)
To: Jens Axboe, io-uring
While io_ring_exit_work() is running new requests of all sorts may be
issued, so it should do a bit more to cancel them, otherwise they may
just get stuck. e.g. in io-wq, in poll lists, etc.
Signed-off-by: Pavel Begunkov <[email protected]>
---
fs/io_uring.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/fs/io_uring.c b/fs/io_uring.c
index 85de42c42433..5bccb235271f 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -992,6 +992,9 @@ enum io_mem_account {
ACCT_PINNED,
};
+static void __io_uring_cancel_task_requests(struct io_ring_ctx *ctx,
+ struct task_struct *task);
+
static void destroy_fixed_file_ref_node(struct fixed_file_ref_node *ref_node);
static struct fixed_file_ref_node *alloc_fixed_file_ref_node(
struct io_ring_ctx *ctx);
@@ -8675,7 +8678,7 @@ static void io_ring_exit_work(struct work_struct *work)
* as nobody else will be looking for them.
*/
do {
- io_iopoll_try_reap_events(ctx);
+ __io_uring_cancel_task_requests(ctx, NULL);
} while (!wait_for_completion_timeout(&ctx->ref_comp, HZ/20));
io_ring_ctx_free(ctx);
}
@@ -8830,9 +8833,11 @@ static void __io_uring_cancel_task_requests(struct io_ring_ctx *ctx,
enum io_wq_cancel cret;
bool ret = false;
- cret = io_wq_cancel_cb(ctx->io_wq, io_cancel_task_cb, &cancel, true);
- if (cret != IO_WQ_CANCEL_NOTFOUND)
- ret = true;
+ if (ctx->io_wq) {
+ cret = io_wq_cancel_cb(ctx->io_wq, io_cancel_task_cb,
+ &cancel, true);
+ ret |= (cret != IO_WQ_CANCEL_NOTFOUND);
+ }
/* SQPOLL thread does its own polling */
if (!(ctx->flags & IORING_SETUP_SQPOLL)) {
--
2.24.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 0/2] cancellation fixes
2021-01-04 20:39 [PATCH 0/2] cancellation fixes Pavel Begunkov
2021-01-04 20:39 ` [PATCH -v2 2/2] io_uring: cancel more aggressively in exit_work Pavel Begunkov
@ 2021-01-04 20:43 ` Pavel Begunkov
2021-01-04 20:43 ` [PATCH v2 1/2] io_uring: drop file refs after task cancel Pavel Begunkov
2021-01-04 22:23 ` [PATCH 0/2] cancellation fixes Jens Axboe
3 siblings, 0 replies; 7+ messages in thread
From: Pavel Begunkov @ 2021-01-04 20:43 UTC (permalink / raw)
To: Jens Axboe, io-uring
[previously a part of "bunch of random fixes"]
haven't changed since then
Pavel Begunkov (2):
io_uring: drop file refs after task cancel
io_uring: cancel more aggressively in exit_work
fs/io_uring.c | 38 +++++++++++++++++++++++++-------------
1 file changed, 25 insertions(+), 13 deletions(-)
--
2.24.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v2 1/2] io_uring: drop file refs after task cancel
2021-01-04 20:39 [PATCH 0/2] cancellation fixes Pavel Begunkov
2021-01-04 20:39 ` [PATCH -v2 2/2] io_uring: cancel more aggressively in exit_work Pavel Begunkov
2021-01-04 20:43 ` [PATCH 0/2] cancellation fixes Pavel Begunkov
@ 2021-01-04 20:43 ` Pavel Begunkov
2021-01-04 20:39 ` Pavel Begunkov
2021-01-04 22:23 ` [PATCH 0/2] cancellation fixes Jens Axboe
3 siblings, 1 reply; 7+ messages in thread
From: Pavel Begunkov @ 2021-01-04 20:43 UTC (permalink / raw)
To: Jens Axboe, io-uring
io_uring fds marked O_CLOEXEC and we explicitly cancel all requests
before going through exec, so we don't want to leave task's file
references to not our anymore io_uring instances.
Signed-off-by: Pavel Begunkov <[email protected]>
---
fs/io_uring.c | 25 ++++++++++++++++---------
1 file changed, 16 insertions(+), 9 deletions(-)
diff --git a/fs/io_uring.c b/fs/io_uring.c
index 445035b24a50..85de42c42433 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -8958,6 +8958,15 @@ static void io_uring_attempt_task_drop(struct file *file)
io_uring_del_task_file(file);
}
+static void io_uring_remove_task_files(struct io_uring_task *tctx)
+{
+ struct file *file;
+ unsigned long index;
+
+ xa_for_each(&tctx->xa, index, file)
+ io_uring_del_task_file(file);
+}
+
void __io_uring_files_cancel(struct files_struct *files)
{
struct io_uring_task *tctx = current->io_uring;
@@ -8966,16 +8975,12 @@ void __io_uring_files_cancel(struct files_struct *files)
/* make sure overflow events are dropped */
atomic_inc(&tctx->in_idle);
-
- xa_for_each(&tctx->xa, index, file) {
- struct io_ring_ctx *ctx = file->private_data;
-
- io_uring_cancel_task_requests(ctx, files);
- if (files)
- io_uring_del_task_file(file);
- }
-
+ xa_for_each(&tctx->xa, index, file)
+ io_uring_cancel_task_requests(file->private_data, files);
atomic_dec(&tctx->in_idle);
+
+ if (files)
+ io_uring_remove_task_files(tctx);
}
static s64 tctx_inflight(struct io_uring_task *tctx)
@@ -9038,6 +9043,8 @@ void __io_uring_task_cancel(void)
} while (1);
atomic_dec(&tctx->in_idle);
+
+ io_uring_remove_task_files(tctx);
}
static int io_uring_flush(struct file *file, void *data)
--
2.24.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH -v2 2/2] io_uring: cancel more aggressively in exit_work
2021-01-04 20:39 ` [PATCH -v2 2/2] io_uring: cancel more aggressively in exit_work Pavel Begunkov
@ 2021-01-04 20:43 ` Pavel Begunkov
0 siblings, 0 replies; 7+ messages in thread
From: Pavel Begunkov @ 2021-01-04 20:43 UTC (permalink / raw)
To: Jens Axboe, io-uring
While io_ring_exit_work() is running new requests of all sorts may be
issued, so it should do a bit more to cancel them, otherwise they may
just get stuck. e.g. in io-wq, in poll lists, etc.
Signed-off-by: Pavel Begunkov <[email protected]>
---
fs/io_uring.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/fs/io_uring.c b/fs/io_uring.c
index 85de42c42433..5bccb235271f 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -992,6 +992,9 @@ enum io_mem_account {
ACCT_PINNED,
};
+static void __io_uring_cancel_task_requests(struct io_ring_ctx *ctx,
+ struct task_struct *task);
+
static void destroy_fixed_file_ref_node(struct fixed_file_ref_node *ref_node);
static struct fixed_file_ref_node *alloc_fixed_file_ref_node(
struct io_ring_ctx *ctx);
@@ -8675,7 +8678,7 @@ static void io_ring_exit_work(struct work_struct *work)
* as nobody else will be looking for them.
*/
do {
- io_iopoll_try_reap_events(ctx);
+ __io_uring_cancel_task_requests(ctx, NULL);
} while (!wait_for_completion_timeout(&ctx->ref_comp, HZ/20));
io_ring_ctx_free(ctx);
}
@@ -8830,9 +8833,11 @@ static void __io_uring_cancel_task_requests(struct io_ring_ctx *ctx,
enum io_wq_cancel cret;
bool ret = false;
- cret = io_wq_cancel_cb(ctx->io_wq, io_cancel_task_cb, &cancel, true);
- if (cret != IO_WQ_CANCEL_NOTFOUND)
- ret = true;
+ if (ctx->io_wq) {
+ cret = io_wq_cancel_cb(ctx->io_wq, io_cancel_task_cb,
+ &cancel, true);
+ ret |= (cret != IO_WQ_CANCEL_NOTFOUND);
+ }
/* SQPOLL thread does its own polling */
if (!(ctx->flags & IORING_SETUP_SQPOLL)) {
--
2.24.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 0/2] cancellation fixes
2021-01-04 20:39 [PATCH 0/2] cancellation fixes Pavel Begunkov
` (2 preceding siblings ...)
2021-01-04 20:43 ` [PATCH v2 1/2] io_uring: drop file refs after task cancel Pavel Begunkov
@ 2021-01-04 22:23 ` Jens Axboe
3 siblings, 0 replies; 7+ messages in thread
From: Jens Axboe @ 2021-01-04 22:23 UTC (permalink / raw)
To: Pavel Begunkov, io-uring
On 1/4/21 1:43 PM, Pavel Begunkov wrote:
> [previously a part of "bunch of random fixes"]
> haven't changed since then
>
> Pavel Begunkov (2):
> io_uring: drop file refs after task cancel
> io_uring: cancel more aggressively in exit_work
>
> fs/io_uring.c | 38 +++++++++++++++++++++++++-------------
> 1 file changed, 25 insertions(+), 13 deletions(-)
Applied, thanks.
--
Jens Axboe
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2021-01-04 23:50 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-01-04 20:39 [PATCH 0/2] cancellation fixes Pavel Begunkov
2021-01-04 20:39 ` [PATCH -v2 2/2] io_uring: cancel more aggressively in exit_work Pavel Begunkov
2021-01-04 20:43 ` Pavel Begunkov
2021-01-04 20:43 ` [PATCH 0/2] cancellation fixes Pavel Begunkov
2021-01-04 20:43 ` [PATCH v2 1/2] io_uring: drop file refs after task cancel Pavel Begunkov
2021-01-04 20:39 ` Pavel Begunkov
2021-01-04 22:23 ` [PATCH 0/2] cancellation fixes Jens Axboe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox