From: Pavel Begunkov <[email protected]>
To: [email protected]
Cc: Jens Axboe <[email protected]>,
[email protected], Dylan Yudaken <[email protected]>
Subject: [PATCH 1/6] io_uring: further limit non-owner defer-tw cq waiting
Date: Thu, 8 Sep 2022 16:56:52 +0100 [thread overview]
Message-ID: <94c83c0a7fe468260ee2ec31bdb0095d6e874ba2.1662652536.git.asml.silence@gmail.com> (raw)
In-Reply-To: <[email protected]>
In case of DEFER_TASK_WORK we try to restrict waiters to only one task,
which is also the only submitter; however, we don't do it reliably,
which might be very confusing and backfire in the future. E.g. we
currently allow multiple tasks in io_iopoll_check().
Fixes: dacbb30102689 ("io_uring: add IORING_SETUP_DEFER_TASKRUN")
Signed-off-by: Pavel Begunkov <[email protected]>
---
io_uring/io_uring.c | 6 ++++++
io_uring/io_uring.h | 11 +++++++++++
2 files changed, 17 insertions(+)
diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
index 0482087b7c64..dc6f64ecd926 100644
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -1398,6 +1398,9 @@ static int io_iopoll_check(struct io_ring_ctx *ctx, long min)
int ret = 0;
unsigned long check_cq;
+ if (!io_allowed_run_tw(ctx))
+ return -EEXIST;
+
check_cq = READ_ONCE(ctx->check_cq);
if (unlikely(check_cq)) {
if (check_cq & BIT(IO_CHECK_CQ_OVERFLOW_BIT))
@@ -2386,6 +2389,9 @@ static int io_cqring_wait(struct io_ring_ctx *ctx, int min_events,
ktime_t timeout = KTIME_MAX;
int ret;
+ if (!io_allowed_run_tw(ctx))
+ return -EEXIST;
+
do {
/* always run at least 1 task work to process local work */
ret = io_run_task_work_ctx(ctx);
diff --git a/io_uring/io_uring.h b/io_uring/io_uring.h
index 9d89425292b7..4eea0836170e 100644
--- a/io_uring/io_uring.h
+++ b/io_uring/io_uring.h
@@ -329,4 +329,15 @@ static inline struct io_kiocb *io_alloc_req(struct io_ring_ctx *ctx)
return container_of(node, struct io_kiocb, comp_list);
}
+static inline bool io_allowed_run_tw(struct io_ring_ctx *ctx)
+{
+ if (!(ctx->flags & IORING_SETUP_DEFER_TASKRUN))
+ return true;
+ if (unlikely(ctx->submitter_task != current)) {
+ /* maybe this is before any submissions */
+ return !ctx->submitter_task;
+ }
+ return true;
+}
+
#endif
--
2.37.2
next prev parent reply other threads:[~2022-09-08 15:59 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-08 15:56 [PATCH for-next 0/6] defer tw fixes and other cleanups Pavel Begunkov
2022-09-08 15:56 ` Pavel Begunkov [this message]
2022-09-08 16:39 ` [PATCH 1/6] io_uring: further limit non-owner defer-tw cq waiting Dylan Yudaken
2022-09-08 15:56 ` [PATCH 2/6] io_uring: disallow defer-tw run w/ no submitters Pavel Begunkov
2022-09-08 16:43 ` Dylan Yudaken
2022-09-08 15:56 ` [PATCH 3/6] io_uring/iopoll: fix unexpected returns Pavel Begunkov
2022-09-08 16:43 ` Dylan Yudaken
2022-09-08 15:56 ` [PATCH 4/6] io_uring/iopoll: unify tw breaking logic Pavel Begunkov
2022-09-08 15:56 ` [PATCH 5/6] io_uring: add fast path for io_run_local_work() Pavel Begunkov
2022-09-08 16:44 ` Dylan Yudaken
2022-09-08 15:56 ` [PATCH 6/6] io_uring: remove unused return from io_disarm_next Pavel Begunkov
2022-09-08 21:23 ` [PATCH for-next 0/6] defer tw fixes and other cleanups Jens Axboe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=94c83c0a7fe468260ee2ec31bdb0095d6e874ba2.1662652536.git.asml.silence@gmail.com \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox