* [PATCH 0/3] small cleanups for 5.12
@ 2021-02-12 18:41 Pavel Begunkov
2021-02-12 18:41 ` [PATCH 1/3] io_uring: don't check PF_EXITING from syscall Pavel Begunkov
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Pavel Begunkov @ 2021-02-12 18:41 UTC (permalink / raw)
To: Jens Axboe, io-uring
Final easy 5.12 cleanups.
Pavel Begunkov (3):
io_uring: don't check PF_EXITING from syscall
io_uring: clean io_req_find_next() fast check
io_uring: optimise io_init_req() flags setting
fs/io_uring.c | 24 ++++++++++--------------
1 file changed, 10 insertions(+), 14 deletions(-)
--
2.24.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/3] io_uring: don't check PF_EXITING from syscall
2021-02-12 18:41 [PATCH 0/3] small cleanups for 5.12 Pavel Begunkov
@ 2021-02-12 18:41 ` Pavel Begunkov
2021-02-12 18:41 ` [PATCH 2/3] io_uring: clean io_req_find_next() fast check Pavel Begunkov
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Pavel Begunkov @ 2021-02-12 18:41 UTC (permalink / raw)
To: Jens Axboe, io-uring
io_sq_thread_acquire_mm_files() can find a PF_EXITING task only when
it's called from task_work context. Don't check it in all other cases,
that are when we're in io_uring_enter().
Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
---
fs/io_uring.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/fs/io_uring.c b/fs/io_uring.c
index 9c58be0579f3..66bbb0dc50af 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -1213,8 +1213,6 @@ static int __io_sq_thread_acquire_mm_files(struct io_ring_ctx *ctx,
static inline int io_sq_thread_acquire_mm_files(struct io_ring_ctx *ctx,
struct io_kiocb *req)
{
- if (unlikely(current->flags & PF_EXITING))
- return -EFAULT;
if (!(ctx->flags & IORING_SETUP_SQPOLL))
return 0;
return __io_sq_thread_acquire_mm_files(ctx, req);
@@ -2338,7 +2336,8 @@ static void __io_req_task_submit(struct io_kiocb *req)
/* ctx stays valid until unlock, even if we drop all ours ctx->refs */
mutex_lock(&ctx->uring_lock);
- if (!ctx->sqo_dead && !io_sq_thread_acquire_mm_files(ctx, req))
+ if (!ctx->sqo_dead && !(current->flags & PF_EXITING) &&
+ !io_sq_thread_acquire_mm_files(ctx, req))
__io_queue_sqe(req);
else
__io_req_task_cancel(req, -EFAULT);
--
2.24.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/3] io_uring: clean io_req_find_next() fast check
2021-02-12 18:41 [PATCH 0/3] small cleanups for 5.12 Pavel Begunkov
2021-02-12 18:41 ` [PATCH 1/3] io_uring: don't check PF_EXITING from syscall Pavel Begunkov
@ 2021-02-12 18:41 ` Pavel Begunkov
2021-02-12 18:41 ` [PATCH 3/3] io_uring: optimise io_init_req() flags setting Pavel Begunkov
2021-02-12 19:25 ` [PATCH 0/3] small cleanups for 5.12 Jens Axboe
3 siblings, 0 replies; 5+ messages in thread
From: Pavel Begunkov @ 2021-02-12 18:41 UTC (permalink / raw)
To: Jens Axboe, io-uring
Indirectly io_req_find_next() is called for every request, optimise the
check by testing flags as it was long before -- __io_req_find_next()
tolerates false-positives well (i.e. link==NULL), and those should be
really rare.
Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
---
fs/io_uring.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/io_uring.c b/fs/io_uring.c
index 66bbb0dc50af..776531f6e18b 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -2172,7 +2172,7 @@ static struct io_kiocb *__io_req_find_next(struct io_kiocb *req)
static inline struct io_kiocb *io_req_find_next(struct io_kiocb *req)
{
- if (likely(!(req->link) && !(req->flags & REQ_F_LINK_TIMEOUT)))
+ if (likely(!(req->flags & (REQ_F_LINK|REQ_F_HARDLINK))))
return NULL;
return __io_req_find_next(req);
}
--
2.24.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 3/3] io_uring: optimise io_init_req() flags setting
2021-02-12 18:41 [PATCH 0/3] small cleanups for 5.12 Pavel Begunkov
2021-02-12 18:41 ` [PATCH 1/3] io_uring: don't check PF_EXITING from syscall Pavel Begunkov
2021-02-12 18:41 ` [PATCH 2/3] io_uring: clean io_req_find_next() fast check Pavel Begunkov
@ 2021-02-12 18:41 ` Pavel Begunkov
2021-02-12 19:25 ` [PATCH 0/3] small cleanups for 5.12 Jens Axboe
3 siblings, 0 replies; 5+ messages in thread
From: Pavel Begunkov @ 2021-02-12 18:41 UTC (permalink / raw)
To: Jens Axboe, io-uring
Invalid req->flags are tolerated by free/put well, avoid this dancing
needlessly presetting it to zero, and then not even resetting but
modifying it, i.e. "|=".
Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
---
fs/io_uring.c | 17 +++++++----------
1 file changed, 7 insertions(+), 10 deletions(-)
diff --git a/fs/io_uring.c b/fs/io_uring.c
index 776531f6e18b..2e8cb739c835 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -6806,14 +6806,15 @@ static int io_init_req(struct io_ring_ctx *ctx, struct io_kiocb *req,
{
struct io_submit_state *state;
unsigned int sqe_flags;
- int id, ret;
+ int id, ret = 0;
req->opcode = READ_ONCE(sqe->opcode);
+ /* same numerical values with corresponding REQ_F_*, safe to copy */
+ req->flags = sqe_flags = READ_ONCE(sqe->flags);
req->user_data = READ_ONCE(sqe->user_data);
req->async_data = NULL;
req->file = NULL;
req->ctx = ctx;
- req->flags = 0;
req->link = NULL;
req->fixed_rsrc_refs = NULL;
/* one is dropped after submission, the other at completion */
@@ -6821,17 +6822,16 @@ static int io_init_req(struct io_ring_ctx *ctx, struct io_kiocb *req,
req->task = current;
req->result = 0;
+ /* enforce forwards compatibility on users */
+ if (unlikely(sqe_flags & ~SQE_VALID_FLAGS))
+ return -EINVAL;
+
if (unlikely(req->opcode >= IORING_OP_LAST))
return -EINVAL;
if (unlikely(io_sq_thread_acquire_mm_files(ctx, req)))
return -EFAULT;
- sqe_flags = READ_ONCE(sqe->flags);
- /* enforce forwards compatibility on users */
- if (unlikely(sqe_flags & ~SQE_VALID_FLAGS))
- return -EINVAL;
-
if (unlikely(!io_check_restriction(ctx, req, sqe_flags)))
return -EACCES;
@@ -6854,8 +6854,6 @@ static int io_init_req(struct io_ring_ctx *ctx, struct io_kiocb *req,
req->work.flags |= IO_WQ_WORK_CREDS;
}
- /* same numerical values with corresponding REQ_F_*, safe to copy */
- req->flags |= sqe_flags;
state = &ctx->submit_state;
/*
@@ -6868,7 +6866,6 @@ static int io_init_req(struct io_ring_ctx *ctx, struct io_kiocb *req,
state->plug_started = true;
}
- ret = 0;
if (io_op_defs[req->opcode].needs_file) {
bool fixed = req->flags & REQ_F_FIXED_FILE;
--
2.24.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 0/3] small cleanups for 5.12
2021-02-12 18:41 [PATCH 0/3] small cleanups for 5.12 Pavel Begunkov
` (2 preceding siblings ...)
2021-02-12 18:41 ` [PATCH 3/3] io_uring: optimise io_init_req() flags setting Pavel Begunkov
@ 2021-02-12 19:25 ` Jens Axboe
3 siblings, 0 replies; 5+ messages in thread
From: Jens Axboe @ 2021-02-12 19:25 UTC (permalink / raw)
To: Pavel Begunkov, io-uring
On 2/12/21 11:41 AM, Pavel Begunkov wrote:
> Final easy 5.12 cleanups.
>
> Pavel Begunkov (3):
> io_uring: don't check PF_EXITING from syscall
> io_uring: clean io_req_find_next() fast check
> io_uring: optimise io_init_req() flags setting
>
> fs/io_uring.c | 24 ++++++++++--------------
> 1 file changed, 10 insertions(+), 14 deletions(-)
Nice little cleanups, applied.
--
Jens Axboe
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-02-12 19:26 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-02-12 18:41 [PATCH 0/3] small cleanups for 5.12 Pavel Begunkov
2021-02-12 18:41 ` [PATCH 1/3] io_uring: don't check PF_EXITING from syscall Pavel Begunkov
2021-02-12 18:41 ` [PATCH 2/3] io_uring: clean io_req_find_next() fast check Pavel Begunkov
2021-02-12 18:41 ` [PATCH 3/3] io_uring: optimise io_init_req() flags setting Pavel Begunkov
2021-02-12 19:25 ` [PATCH 0/3] small cleanups for 5.12 Jens Axboe
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.