* [PATCH 5.12 0/4] cancellation fixes
@ 2021-03-25 18:32 Pavel Begunkov
2021-03-25 18:32 ` [PATCH 1/4] io_uring: fix timeout cancel return code Pavel Begunkov
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: Pavel Begunkov @ 2021-03-25 18:32 UTC (permalink / raw)
To: Jens Axboe, io-uring
1-3 timeout cancellation fixes
4/4 prevents a regression cancelling more than needed
Pavel Begunkov (4):
io_uring: fix timeout cancel return code
io_uring: do post-completion chore on t-out cancel
io_uring: don't cancel-track common timeouts
io_uring: don't cancel extra on files match
fs/io_uring.c | 53 ++++++++++++++++++++++++++-------------------------
1 file changed, 27 insertions(+), 26 deletions(-)
--
2.24.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/4] io_uring: fix timeout cancel return code
2021-03-25 18:32 [PATCH 5.12 0/4] cancellation fixes Pavel Begunkov
@ 2021-03-25 18:32 ` Pavel Begunkov
2021-03-25 18:32 ` [PATCH 2/4] io_uring: do post-completion chore on t-out cancel Pavel Begunkov
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Pavel Begunkov @ 2021-03-25 18:32 UTC (permalink / raw)
To: Jens Axboe, io-uring
When we cancel a timeout we should emit a sensible return code, like
-ECANCELED but not 0, otherwise it may trick users.
Signed-off-by: Pavel Begunkov <[email protected]>
---
fs/io_uring.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/fs/io_uring.c b/fs/io_uring.c
index 8c5789b96dbb..e4861095c4a7 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -1248,7 +1248,7 @@ static void io_queue_async_work(struct io_kiocb *req)
io_queue_linked_timeout(link);
}
-static void io_kill_timeout(struct io_kiocb *req)
+static void io_kill_timeout(struct io_kiocb *req, int status)
{
struct io_timeout_data *io = req->async_data;
int ret;
@@ -1258,7 +1258,7 @@ static void io_kill_timeout(struct io_kiocb *req)
atomic_set(&req->ctx->cq_timeouts,
atomic_read(&req->ctx->cq_timeouts) + 1);
list_del_init(&req->timeout.list);
- io_cqring_fill_event(req, 0);
+ io_cqring_fill_event(req, status);
io_put_req_deferred(req, 1);
}
}
@@ -1275,7 +1275,7 @@ static bool io_kill_timeouts(struct io_ring_ctx *ctx, struct task_struct *tsk,
spin_lock_irq(&ctx->completion_lock);
list_for_each_entry_safe(req, tmp, &ctx->timeout_list, timeout.list) {
if (io_match_task(req, tsk, files)) {
- io_kill_timeout(req);
+ io_kill_timeout(req, -ECANCELED);
canceled++;
}
}
@@ -1327,7 +1327,7 @@ static void io_flush_timeouts(struct io_ring_ctx *ctx)
break;
list_del_init(&req->timeout.list);
- io_kill_timeout(req);
+ io_kill_timeout(req, 0);
} while (!list_empty(&ctx->timeout_list));
ctx->cq_last_tm_flush = seq;
--
2.24.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/4] io_uring: do post-completion chore on t-out cancel
2021-03-25 18:32 [PATCH 5.12 0/4] cancellation fixes Pavel Begunkov
2021-03-25 18:32 ` [PATCH 1/4] io_uring: fix timeout cancel return code Pavel Begunkov
@ 2021-03-25 18:32 ` Pavel Begunkov
2021-03-25 18:32 ` [PATCH 3/4] io_uring: don't cancel-track common timeouts Pavel Begunkov
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Pavel Begunkov @ 2021-03-25 18:32 UTC (permalink / raw)
To: Jens Axboe, io-uring
Don't forget about io_commit_cqring() + io_cqring_ev_posted() after
exit/exec cancelling timeouts. Both functions declared only after
io_kill_timeouts(), so to avoid tons of forward declarations move
it down.
Signed-off-by: Pavel Begunkov <[email protected]>
---
fs/io_uring.c | 42 ++++++++++++++++++++++--------------------
1 file changed, 22 insertions(+), 20 deletions(-)
diff --git a/fs/io_uring.c b/fs/io_uring.c
index e4861095c4a7..3fcce81b24cd 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -1263,26 +1263,6 @@ static void io_kill_timeout(struct io_kiocb *req, int status)
}
}
-/*
- * Returns true if we found and killed one or more timeouts
- */
-static bool io_kill_timeouts(struct io_ring_ctx *ctx, struct task_struct *tsk,
- struct files_struct *files)
-{
- struct io_kiocb *req, *tmp;
- int canceled = 0;
-
- spin_lock_irq(&ctx->completion_lock);
- list_for_each_entry_safe(req, tmp, &ctx->timeout_list, timeout.list) {
- if (io_match_task(req, tsk, files)) {
- io_kill_timeout(req, -ECANCELED);
- canceled++;
- }
- }
- spin_unlock_irq(&ctx->completion_lock);
- return canceled != 0;
-}
-
static void __io_queue_deferred(struct io_ring_ctx *ctx)
{
do {
@@ -8608,6 +8588,28 @@ static void io_ring_exit_work(struct work_struct *work)
io_ring_ctx_free(ctx);
}
+/* Returns true if we found and killed one or more timeouts */
+static bool io_kill_timeouts(struct io_ring_ctx *ctx, struct task_struct *tsk,
+ struct files_struct *files)
+{
+ struct io_kiocb *req, *tmp;
+ int canceled = 0;
+
+ spin_lock_irq(&ctx->completion_lock);
+ list_for_each_entry_safe(req, tmp, &ctx->timeout_list, timeout.list) {
+ if (io_match_task(req, tsk, files)) {
+ io_kill_timeout(req, -ECANCELED);
+ canceled++;
+ }
+ }
+ io_commit_cqring(ctx);
+ spin_unlock_irq(&ctx->completion_lock);
+
+ if (canceled != 0)
+ io_cqring_ev_posted(ctx);
+ return canceled != 0;
+}
+
static void io_ring_ctx_wait_and_kill(struct io_ring_ctx *ctx)
{
unsigned long index;
--
2.24.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 3/4] io_uring: don't cancel-track common timeouts
2021-03-25 18:32 [PATCH 5.12 0/4] cancellation fixes Pavel Begunkov
2021-03-25 18:32 ` [PATCH 1/4] io_uring: fix timeout cancel return code Pavel Begunkov
2021-03-25 18:32 ` [PATCH 2/4] io_uring: do post-completion chore on t-out cancel Pavel Begunkov
@ 2021-03-25 18:32 ` Pavel Begunkov
2021-03-25 18:32 ` [PATCH 4/4] io_uring: don't cancel extra on files match Pavel Begunkov
2021-03-26 15:55 ` [PATCH 5.12 0/4] cancellation fixes Jens Axboe
4 siblings, 0 replies; 6+ messages in thread
From: Pavel Begunkov @ 2021-03-25 18:32 UTC (permalink / raw)
To: Jens Axboe, io-uring
Don't account usual timeouts (i.e. not linked) as REQ_F_INFLIGHT but
keep behaviour prior to dd59a3d595cc1 ("io_uring: reliably cancel linked
timeouts").
Signed-off-by: Pavel Begunkov <[email protected]>
---
fs/io_uring.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/fs/io_uring.c b/fs/io_uring.c
index 3fcce81b24cd..fabaf49fefa3 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -5564,7 +5564,8 @@ static int io_timeout_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe,
data->mode = io_translate_timeout_mode(flags);
hrtimer_init(&data->timer, CLOCK_MONOTONIC, data->mode);
- io_req_track_inflight(req);
+ if (is_timeout_link)
+ io_req_track_inflight(req);
return 0;
}
--
2.24.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 4/4] io_uring: don't cancel extra on files match
2021-03-25 18:32 [PATCH 5.12 0/4] cancellation fixes Pavel Begunkov
` (2 preceding siblings ...)
2021-03-25 18:32 ` [PATCH 3/4] io_uring: don't cancel-track common timeouts Pavel Begunkov
@ 2021-03-25 18:32 ` Pavel Begunkov
2021-03-26 15:55 ` [PATCH 5.12 0/4] cancellation fixes Jens Axboe
4 siblings, 0 replies; 6+ messages in thread
From: Pavel Begunkov @ 2021-03-25 18:32 UTC (permalink / raw)
To: Jens Axboe, io-uring
As tasks always wait and kill their io-wq on exec/exit, files are of no
more concern to us, so we don't need to specifically cancel them by hand
in those cases. Moreover we should not, because io_match_task() looks at
req->task->files now, which is always true and so leads to extra
cancellations, that wasn't a case before per-task io-wq.
Signed-off-by: Pavel Begunkov <[email protected]>
---
fs/io_uring.c | 2 --
1 file changed, 2 deletions(-)
diff --git a/fs/io_uring.c b/fs/io_uring.c
index fabaf49fefa3..f8df982017fa 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -1095,8 +1095,6 @@ static bool io_match_task(struct io_kiocb *head,
io_for_each_link(req, head) {
if (req->flags & REQ_F_INFLIGHT)
return true;
- if (req->task->files == files)
- return true;
}
return false;
}
--
2.24.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 5.12 0/4] cancellation fixes
2021-03-25 18:32 [PATCH 5.12 0/4] cancellation fixes Pavel Begunkov
` (3 preceding siblings ...)
2021-03-25 18:32 ` [PATCH 4/4] io_uring: don't cancel extra on files match Pavel Begunkov
@ 2021-03-26 15:55 ` Jens Axboe
4 siblings, 0 replies; 6+ messages in thread
From: Jens Axboe @ 2021-03-26 15:55 UTC (permalink / raw)
To: Pavel Begunkov, io-uring
On 3/25/21 12:32 PM, Pavel Begunkov wrote:
> 1-3 timeout cancellation fixes
> 4/4 prevents a regression cancelling more than needed
>
> Pavel Begunkov (4):
> io_uring: fix timeout cancel return code
> io_uring: do post-completion chore on t-out cancel
> io_uring: don't cancel-track common timeouts
> io_uring: don't cancel extra on files match
>
> fs/io_uring.c | 53 ++++++++++++++++++++++++++-------------------------
> 1 file changed, 27 insertions(+), 26 deletions(-)
Thanks, applied.
--
Jens Axboe
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2021-03-26 15:55 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-03-25 18:32 [PATCH 5.12 0/4] cancellation fixes Pavel Begunkov
2021-03-25 18:32 ` [PATCH 1/4] io_uring: fix timeout cancel return code Pavel Begunkov
2021-03-25 18:32 ` [PATCH 2/4] io_uring: do post-completion chore on t-out cancel Pavel Begunkov
2021-03-25 18:32 ` [PATCH 3/4] io_uring: don't cancel-track common timeouts Pavel Begunkov
2021-03-25 18:32 ` [PATCH 4/4] io_uring: don't cancel extra on files match Pavel Begunkov
2021-03-26 15:55 ` [PATCH 5.12 0/4] 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