2020-05-26 17:38:28

by Pavel Begunkov

[permalink] [raw]
Subject: [PATCH 0/6] random patches for 5.8

Nothing insteresting in particular, just start flushing stashed patches.
Ones in this series are pretty easy and short.

Pavel Begunkov (6):
io_uring: fix flush req->refs underflow
io_uring: simplify io_timeout locking
io_uring: don't re-read sqe->off in timeout_prep()
io_uring: separate DRAIN flushing into a cold path
io_uring: get rid of manual punting in io_close
io_uring: let io_req_aux_free() handle fixed files

fs/io_uring.c | 64 ++++++++++++++++++++-------------------------------
1 file changed, 25 insertions(+), 39 deletions(-)

--
2.24.0


2020-05-26 17:38:42

by Pavel Begunkov

[permalink] [raw]
Subject: [PATCH 5/6] io_uring: get rid of manual punting in io_close

io_close() was punting async manually to skip grabbing files. Use
REQ_F_NO_FILE_TABLE instead, and pass it through the generic path
with -EAGAIN.

Signed-off-by: Pavel Begunkov <[email protected]>
---
fs/io_uring.c | 20 +++++---------------
1 file changed, 5 insertions(+), 15 deletions(-)

diff --git a/fs/io_uring.c b/fs/io_uring.c
index acf6ce9eee68..ac1aa25f4a55 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -3492,25 +3492,15 @@ static int io_close(struct io_kiocb *req, bool force_nonblock)

req->close.put_file = NULL;
ret = __close_fd_get_file(req->close.fd, &req->close.put_file);
- if (ret < 0) {
- if (ret == -ENOENT)
- ret = -EBADF;
- return ret;
- }
+ if (ret < 0)
+ return (ret == -ENOENT) ? -EBADF : ret;

/* if the file has a flush method, be safe and punt to async */
if (req->close.put_file->f_op->flush && force_nonblock) {
- /* submission ref will be dropped, take it for async */
- refcount_inc(&req->refs);
-
+ /* avoid grabbing files - we don't need the files */
+ req->flags |= REQ_F_NO_FILE_TABLE | REQ_F_MUST_PUNT;
req->work.func = io_close_finish;
- /*
- * Do manual async queue here to avoid grabbing files - we don't
- * need the files, and it'll cause io_close_finish() to close
- * the file again and cause a double CQE entry for this request
- */
- io_queue_async_work(req);
- return 0;
+ return -EAGAIN;
}

/*
--
2.24.0

2020-05-26 17:39:15

by Pavel Begunkov

[permalink] [raw]
Subject: [PATCH 2/6] io_uring: simplify io_timeout locking

Move spin_lock_irq() earlier to have only 1 call site of it in
io_timeout(). It makes the flow easier.

Signed-off-by: Pavel Begunkov <[email protected]>
---
fs/io_uring.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/fs/io_uring.c b/fs/io_uring.c
index 42b5603ee410..e30fc17dd268 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -4845,6 +4845,7 @@ static int io_timeout(struct io_kiocb *req)
u32 seq = req->sequence;

data = &req->io->timeout;
+ spin_lock_irq(&ctx->completion_lock);

/*
* sqe->off holds how many events that need to occur for this
@@ -4853,7 +4854,6 @@ static int io_timeout(struct io_kiocb *req)
*/
if (!count) {
req->flags |= REQ_F_TIMEOUT_NOSEQ;
- spin_lock_irq(&ctx->completion_lock);
entry = ctx->timeout_list.prev;
goto add;
}
@@ -4864,7 +4864,6 @@ static int io_timeout(struct io_kiocb *req)
* Insertion sort, ensuring the first entry in the list is always
* the one we need first.
*/
- spin_lock_irq(&ctx->completion_lock);
list_for_each_prev(entry, &ctx->timeout_list) {
struct io_kiocb *nxt = list_entry(entry, struct io_kiocb, list);
unsigned nxt_seq;
--
2.24.0

2020-05-26 17:39:58

by Pavel Begunkov

[permalink] [raw]
Subject: [PATCH 1/6] io_uring: fix flush req->refs underflow

In io_uring_cancel_files(), after refcount_sub_and_test() leaves 0
req->refs, it calls io_put_req(), which would also put a ref. Call
io_free_req() instead.

Signed-off-by: Pavel Begunkov <[email protected]>
---
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 bf75ac753b9d..42b5603ee410 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -7534,7 +7534,7 @@ static void io_uring_cancel_files(struct io_ring_ctx *ctx,
* all we had, then we're done with this request.
*/
if (refcount_sub_and_test(2, &cancel_req->refs)) {
- io_put_req(cancel_req);
+ io_free_req(cancel_req);
finish_wait(&ctx->inflight_wait, &wait);
continue;
}
--
2.24.0

2020-05-26 17:40:39

by Pavel Begunkov

[permalink] [raw]
Subject: [PATCH 6/6] io_uring: let io_req_aux_free() handle fixed files

Remove duplicated code putting fixed files in io_free_req_many(),
__io_req_aux_free() does the same thing, let it handle them.

Signed-off-by: Pavel Begunkov <[email protected]>
---
fs/io_uring.c | 4 ----
1 file changed, 4 deletions(-)

diff --git a/fs/io_uring.c b/fs/io_uring.c
index ac1aa25f4a55..a3dbd5f40391 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -1413,10 +1413,6 @@ static void io_free_req_many(struct io_ring_ctx *ctx, struct req_batch *rb)
for (i = 0; i < rb->to_free; i++) {
struct io_kiocb *req = rb->reqs[i];

- if (req->flags & REQ_F_FIXED_FILE) {
- req->file = NULL;
- percpu_ref_put(req->fixed_file_refs);
- }
if (req->flags & REQ_F_INFLIGHT)
inflight++;
__io_req_aux_free(req);
--
2.24.0

2020-05-26 18:06:27

by Jens Axboe

[permalink] [raw]
Subject: Re: [PATCH 6/6] io_uring: let io_req_aux_free() handle fixed files

On 5/26/20 11:34 AM, Pavel Begunkov wrote:
> Remove duplicated code putting fixed files in io_free_req_many(),
> __io_req_aux_free() does the same thing, let it handle them.

This one is already changed in mainline:


> commit 9d9e88a24c1f20ebfc2f28b1762ce78c0b9e1cb3 (tag: io_uring-5.7-2020-05-15)
Author: Jens Axboe <[email protected]>
Date: Wed May 13 12:53:19 2020 -0600

io_uring: polled fixed file must go through free iteration


--
Jens Axboe

2020-05-26 18:09:46

by Jens Axboe

[permalink] [raw]
Subject: Re: [PATCH 1/6] io_uring: fix flush req->refs underflow

On 5/26/20 11:34 AM, Pavel Begunkov wrote:
> In io_uring_cancel_files(), after refcount_sub_and_test() leaves 0
> req->refs, it calls io_put_req(), which would also put a ref. Call
> io_free_req() instead.

Needs a:

Fixes: 2ca10259b418 ("io_uring: prune request from overflow list on flush")

I added it.

--
Jens Axboe

2020-05-26 18:15:12

by Pavel Begunkov

[permalink] [raw]
Subject: Re: [PATCH 6/6] io_uring: let io_req_aux_free() handle fixed files

On 26/05/2020 21:03, Jens Axboe wrote:
> On 5/26/20 11:34 AM, Pavel Begunkov wrote:
>> Remove duplicated code putting fixed files in io_free_req_many(),
>> __io_req_aux_free() does the same thing, let it handle them.
>
> This one is already changed in mainline:
>
>
>> commit 9d9e88a24c1f20ebfc2f28b1762ce78c0b9e1cb3 (tag: io_uring-5.7-2020-05-15)
> Author: Jens Axboe <[email protected]>
> Date: Wed May 13 12:53:19 2020 -0600
>
> io_uring: polled fixed file must go through free iteration
>

I see, missed it.

And thanks for adding the fixes tag for the other one.

--
Pavel Begunkov

2020-05-26 23:20:26

by Jens Axboe

[permalink] [raw]
Subject: Re: [PATCH 0/6] random patches for 5.8

On 5/26/20 11:34 AM, Pavel Begunkov wrote:
> Nothing insteresting in particular, just start flushing stashed patches.
> Ones in this series are pretty easy and short.
>
> Pavel Begunkov (6):
> io_uring: fix flush req->refs underflow
> io_uring: simplify io_timeout locking
> io_uring: don't re-read sqe->off in timeout_prep()
> io_uring: separate DRAIN flushing into a cold path
> io_uring: get rid of manual punting in io_close
> io_uring: let io_req_aux_free() handle fixed files
>
> fs/io_uring.c | 64 ++++++++++++++++++++-------------------------------
> 1 file changed, 25 insertions(+), 39 deletions(-)

Applied 1-5, thanks.

--
Jens Axboe