public inbox for [email protected]
 help / color / mirror / Atom feed
* [PATCH for-next 0/3] unrelated cleanups for next
@ 2020-05-17 11:13 Pavel Begunkov
  2020-05-17 11:13 ` [PATCH 1/3] io_uring: remove req->needs_fixed_files Pavel Begunkov
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Pavel Begunkov @ 2020-05-17 11:13 UTC (permalink / raw)
  To: Jens Axboe, io-uring, linux-kernel

Independent cleanups, that's it.

Pavel Begunkov (3):
  io_uring: remove req->needs_fixed_files
  io_uring: rename io_file_put()
  io_uring: don't repeat valid flag list

 fs/io_uring.c | 47 ++++++++++++++++++++++++++---------------------
 1 file changed, 26 insertions(+), 21 deletions(-)

-- 
2.24.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/3] io_uring: remove req->needs_fixed_files
  2020-05-17 11:13 [PATCH for-next 0/3] unrelated cleanups for next Pavel Begunkov
@ 2020-05-17 11:13 ` Pavel Begunkov
  2020-05-17 11:13 ` [PATCH 2/3] io_uring: rename io_file_put() Pavel Begunkov
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Pavel Begunkov @ 2020-05-17 11:13 UTC (permalink / raw)
  To: Jens Axboe, io-uring, linux-kernel

A submission is "async" IIF it's done by SQPOLL thread. Instead of
passing @async flag into io_submit_sqes(), deduce it from ctx->flags.

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

diff --git a/fs/io_uring.c b/fs/io_uring.c
index 3d0a08560689..739aae7070c1 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -626,7 +626,6 @@ struct io_kiocb {
 
 	struct io_async_ctx		*io;
 	int				cflags;
-	bool				needs_fixed_file;
 	u8				opcode;
 
 	struct io_ring_ctx	*ctx;
@@ -891,6 +890,11 @@ EXPORT_SYMBOL(io_uring_get_socket);
 
 static void io_file_put_work(struct work_struct *work);
 
+static inline bool io_async_submit(struct io_ring_ctx *ctx)
+{
+	return ctx->flags & IORING_SETUP_SQPOLL;
+}
+
 static void io_ring_ctx_ref_free(struct percpu_ref *ref)
 {
 	struct io_ring_ctx *ctx = container_of(ref, struct io_ring_ctx, refs);
@@ -5487,7 +5491,7 @@ static int io_req_set_file(struct io_submit_state *state, struct io_kiocb *req,
 	bool fixed;
 
 	fixed = (req->flags & REQ_F_FIXED_FILE) != 0;
-	if (unlikely(!fixed && req->needs_fixed_file))
+	if (unlikely(!fixed && io_async_submit(req->ctx)))
 		return -EBADF;
 
 	return io_file_get(state, req, fd, &req->file, fixed);
@@ -5866,7 +5870,7 @@ static inline void io_consume_sqe(struct io_ring_ctx *ctx)
 
 static int io_init_req(struct io_ring_ctx *ctx, struct io_kiocb *req,
 		       const struct io_uring_sqe *sqe,
-		       struct io_submit_state *state, bool async)
+		       struct io_submit_state *state)
 {
 	unsigned int sqe_flags;
 	int id;
@@ -5887,7 +5891,6 @@ static int io_init_req(struct io_ring_ctx *ctx, struct io_kiocb *req,
 	refcount_set(&req->refs, 2);
 	req->task = NULL;
 	req->result = 0;
-	req->needs_fixed_file = async;
 	INIT_IO_WORK(&req->work, io_wq_submit_work);
 
 	if (unlikely(req->opcode >= IORING_OP_LAST))
@@ -5928,7 +5931,7 @@ static int io_init_req(struct io_ring_ctx *ctx, struct io_kiocb *req,
 }
 
 static int io_submit_sqes(struct io_ring_ctx *ctx, unsigned int nr,
-			  struct file *ring_file, int ring_fd, bool async)
+			  struct file *ring_file, int ring_fd)
 {
 	struct io_submit_state state, *statep = NULL;
 	struct io_kiocb *link = NULL;
@@ -5972,7 +5975,7 @@ static int io_submit_sqes(struct io_ring_ctx *ctx, unsigned int nr,
 			break;
 		}
 
-		err = io_init_req(ctx, req, sqe, statep, async);
+		err = io_init_req(ctx, req, sqe, statep);
 		io_consume_sqe(ctx);
 		/* will complete beyond this point, count as submitted */
 		submitted++;
@@ -5985,7 +5988,7 @@ static int io_submit_sqes(struct io_ring_ctx *ctx, unsigned int nr,
 		}
 
 		trace_io_uring_submit_sqe(ctx, req->opcode, req->user_data,
-						true, async);
+						true, io_async_submit(ctx));
 		err = io_submit_sqe(req, sqe, &link);
 		if (err)
 			goto fail_req;
@@ -6124,7 +6127,7 @@ static int io_sq_thread(void *data)
 		}
 
 		mutex_lock(&ctx->uring_lock);
-		ret = io_submit_sqes(ctx, to_submit, NULL, -1, true);
+		ret = io_submit_sqes(ctx, to_submit, NULL, -1);
 		mutex_unlock(&ctx->uring_lock);
 		timeout = jiffies + ctx->sq_thread_idle;
 	}
@@ -7635,7 +7638,7 @@ SYSCALL_DEFINE6(io_uring_enter, unsigned int, fd, u32, to_submit,
 		submitted = to_submit;
 	} else if (to_submit) {
 		mutex_lock(&ctx->uring_lock);
-		submitted = io_submit_sqes(ctx, to_submit, f.file, fd, false);
+		submitted = io_submit_sqes(ctx, to_submit, f.file, fd);
 		mutex_unlock(&ctx->uring_lock);
 
 		if (submitted != to_submit)
-- 
2.24.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/3] io_uring: rename io_file_put()
  2020-05-17 11:13 [PATCH for-next 0/3] unrelated cleanups for next Pavel Begunkov
  2020-05-17 11:13 ` [PATCH 1/3] io_uring: remove req->needs_fixed_files Pavel Begunkov
@ 2020-05-17 11:13 ` Pavel Begunkov
  2020-05-17 11:13 ` [PATCH 3/3] io_uring: don't repeat valid flag list Pavel Begunkov
  2020-05-17 20:24 ` [PATCH for-next 0/3] unrelated cleanups for next Jens Axboe
  3 siblings, 0 replies; 5+ messages in thread
From: Pavel Begunkov @ 2020-05-17 11:13 UTC (permalink / raw)
  To: Jens Axboe, io-uring, linux-kernel

io_file_put() deals with flushing state's file refs, adding "state" to
its name makes it a bit clearer. Also, avoid double check of
state->file in __io_file_get() in some cases.

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

diff --git a/fs/io_uring.c b/fs/io_uring.c
index 739aae7070c1..9c5a95414cbd 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -1999,15 +1999,19 @@ static void io_iopoll_req_issued(struct io_kiocb *req)
 		wake_up(&ctx->sqo_wait);
 }
 
-static void io_file_put(struct io_submit_state *state)
+static void __io_state_file_put(struct io_submit_state *state)
 {
-	if (state->file) {
-		int diff = state->has_refs - state->used_refs;
+	int diff = state->has_refs - state->used_refs;
 
-		if (diff)
-			fput_many(state->file, diff);
-		state->file = NULL;
-	}
+	if (diff)
+		fput_many(state->file, diff);
+	state->file = NULL;
+}
+
+static inline void io_state_file_put(struct io_submit_state *state)
+{
+	if (state->file)
+		__io_state_file_put(state);
 }
 
 /*
@@ -2026,7 +2030,7 @@ static struct file *__io_file_get(struct io_submit_state *state, int fd)
 			state->ios_left--;
 			return state->file;
 		}
-		io_file_put(state);
+		__io_state_file_put(state);
 	}
 	state->file = fget_many(fd, state->ios_left);
 	if (!state->file)
@@ -5799,7 +5803,7 @@ static int io_submit_sqe(struct io_kiocb *req, const struct io_uring_sqe *sqe,
 static void io_submit_state_end(struct io_submit_state *state)
 {
 	blk_finish_plug(&state->plug);
-	io_file_put(state);
+	io_state_file_put(state);
 	if (state->free_reqs)
 		kmem_cache_free_bulk(req_cachep, state->free_reqs, state->reqs);
 }
-- 
2.24.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/3] io_uring: don't repeat valid flag list
  2020-05-17 11:13 [PATCH for-next 0/3] unrelated cleanups for next Pavel Begunkov
  2020-05-17 11:13 ` [PATCH 1/3] io_uring: remove req->needs_fixed_files Pavel Begunkov
  2020-05-17 11:13 ` [PATCH 2/3] io_uring: rename io_file_put() Pavel Begunkov
@ 2020-05-17 11:13 ` Pavel Begunkov
  2020-05-17 20:24 ` [PATCH for-next 0/3] unrelated cleanups for next Jens Axboe
  3 siblings, 0 replies; 5+ messages in thread
From: Pavel Begunkov @ 2020-05-17 11:13 UTC (permalink / raw)
  To: Jens Axboe, io-uring, linux-kernel

req->flags stores all sqe->flags. After checking that sqe->flags are
valid set if IOSQE* flags, no need to double check it, just forward them
all.

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

diff --git a/fs/io_uring.c b/fs/io_uring.c
index 9c5a95414cbd..83b599815cf0 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -5924,9 +5924,7 @@ static int io_init_req(struct io_ring_ctx *ctx, struct io_kiocb *req,
 	}
 
 	/* same numerical values with corresponding REQ_F_*, safe to copy */
-	req->flags |= sqe_flags & (IOSQE_IO_DRAIN | IOSQE_IO_HARDLINK |
-					IOSQE_ASYNC | IOSQE_FIXED_FILE |
-					IOSQE_BUFFER_SELECT | IOSQE_IO_LINK);
+	req->flags |= sqe_flags;
 
 	if (!io_op_defs[req->opcode].needs_file)
 		return 0;
-- 
2.24.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH for-next 0/3] unrelated cleanups for next
  2020-05-17 11:13 [PATCH for-next 0/3] unrelated cleanups for next Pavel Begunkov
                   ` (2 preceding siblings ...)
  2020-05-17 11:13 ` [PATCH 3/3] io_uring: don't repeat valid flag list Pavel Begunkov
@ 2020-05-17 20:24 ` Jens Axboe
  3 siblings, 0 replies; 5+ messages in thread
From: Jens Axboe @ 2020-05-17 20:24 UTC (permalink / raw)
  To: Pavel Begunkov, io-uring, linux-kernel

On 5/17/20 5:13 AM, Pavel Begunkov wrote:
> Independent cleanups, that's it.
> 
> Pavel Begunkov (3):
>   io_uring: remove req->needs_fixed_files
>   io_uring: rename io_file_put()
>   io_uring: don't repeat valid flag list
> 
>  fs/io_uring.c | 47 ++++++++++++++++++++++++++---------------------
>  1 file changed, 26 insertions(+), 21 deletions(-)

Applied, thanks.

-- 
Jens Axboe


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-05-17 20:24 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-05-17 11:13 [PATCH for-next 0/3] unrelated cleanups for next Pavel Begunkov
2020-05-17 11:13 ` [PATCH 1/3] io_uring: remove req->needs_fixed_files Pavel Begunkov
2020-05-17 11:13 ` [PATCH 2/3] io_uring: rename io_file_put() Pavel Begunkov
2020-05-17 11:13 ` [PATCH 3/3] io_uring: don't repeat valid flag list Pavel Begunkov
2020-05-17 20:24 ` [PATCH for-next 0/3] unrelated cleanups for next Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox