Skip to contentSkip to conversation

Misc cleanups

PATCH In review Jens Axboe 1 participant 5 messages Aug 10, 2023 io_uring

lore
Share & tools
lore

Jens Axboe

author maintainer
#0 lore raw

cover Misc cleanups

Hi,

Nothing major in here:

1) Drop fdinfo grabbing a reference to the ring, the caller has already grabbed a reference to the ring fd so we don't need it.

2) Cleanup around file putting.

Signature · 1 line
Jens Axboe
author maintainer
#1 lore raw

PATCH 1/3 io_uring/fdinfo: get rid of ref tryget

The caller holds a reference to the ring itself, so by definition the ring cannot go away. There's no need to play games with tryget for the reference, as we don't need an extra reference at all.

---
 io_uring/fdinfo.c | 18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)
io_uring/fdinfo.c +6 -12
index 76c279b13aee..300455b4bc12 100644
@@ -46,9 +46,13 @@ static __cold int io_uring_show_cred(struct seq_file *m, unsigned int id,
 	return 0;
 }
 
-static __cold void __io_uring_show_fdinfo(struct io_ring_ctx *ctx,
-					  struct seq_file *m)
+/*
+ * Caller holds a reference to the file already, we don't need to do
+ * anything else to get an extra reference.
+ */
+__cold void io_uring_show_fdinfo(struct seq_file *m, struct file *f)
 {
+	struct io_ring_ctx *ctx = f->private_data;
 	struct io_sq_data *sq = NULL;
 	struct io_overflow_cqe *ocqe;
 	struct io_rings *r = ctx->rings;
@@ -203,14 +207,4 @@ static __cold void __io_uring_show_fdinfo(struct io_ring_ctx *ctx,
 
 	spin_unlock(&ctx->completion_lock);
 }
-
-__cold void io_uring_show_fdinfo(struct seq_file *m, struct file *f)
-{
-	struct io_ring_ctx *ctx = f->private_data;
-
-	if (percpu_ref_tryget(&ctx->refs)) {
-		__io_uring_show_fdinfo(ctx, m);
-		percpu_ref_put(&ctx->refs);
-	}
-}
 #endif
Signature · 1 line
2.40.1
author maintainer
#2 lore raw

PATCH 2/3 io_uring/splice: use fput() directly

In reply to Jens Axboe

No point in using io_file_put() here, as we need to check if it's a fixed file in the caller anyway.

---
 io_uring/splice.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
io_uring/splice.c +2 -2
index 2a4bbb719531..7c4469e9540e 100644
@@ -68,7 +68,7 @@ int io_tee(struct io_kiocb *req, unsigned int issue_flags)
 		ret = do_tee(in, out, sp->len, flags);
 
 	if (!(sp->flags & SPLICE_F_FD_IN_FIXED))
-		io_put_file(in);
+		fput(in);
 done:
 	if (ret != sp->len)
 		req_set_fail(req);
@@ -112,7 +112,7 @@ int io_splice(struct io_kiocb *req, unsigned int issue_flags)
 		ret = do_splice(in, poff_in, out, poff_out, sp->len, flags);
 
 	if (!(sp->flags & SPLICE_F_FD_IN_FIXED))
-		io_put_file(in);
+		fput(in);
 done:
 	if (ret != sp->len)
 		req_set_fail(req);
Signature · 1 line
2.40.1
author maintainer
#3 lore raw

PATCH 3/3 io_uring: have io_file_put() take an io_kiocb rather than the file

In reply to Jens Axboe

No functional changes in this patch, just a prep patch for needing the request in io_file_put().

---
 io_uring/io_uring.c | 4 ++--
 io_uring/io_uring.h | 6 +++---
 2 files changed, 5 insertions(+), 5 deletions(-)
io_uring/io_uring.c +2 -2
index 3da26171599b..138635e66d44 100644
@@ -1004,7 +1004,7 @@ static void __io_req_complete_post(struct io_kiocb *req, unsigned issue_flags)
 		if (unlikely(req->flags & IO_REQ_CLEAN_FLAGS))
 			io_clean_op(req);
 		if (!(req->flags & REQ_F_FIXED_FILE))
-			io_put_file(req->file);
+			io_put_file(req);
 
 		rsrc_node = req->rsrc_node;
 		/*
@@ -1539,7 +1539,7 @@ void io_free_batch_list(struct io_ring_ctx *ctx, struct io_wq_work_node *node)
 				io_clean_op(req);
 		}
 		if (!(req->flags & REQ_F_FIXED_FILE))
-			io_put_file(req->file);
+			io_put_file(req);
 
 		io_req_put_rsrc_locked(req, ctx);
 
io_uring/io_uring.h +3 -3
index 12769bad5cee..46643bc9f3c5 100644
@@ -196,10 +196,10 @@ static inline bool req_has_async_data(struct io_kiocb *req)
 	return req->flags & REQ_F_ASYNC_DATA;
 }
 
-static inline void io_put_file(struct file *file)
+static inline void io_put_file(struct io_kiocb *req)
 {
-	if (file)
-		fput(file);
+	if (req->file)
+		fput(req->file);
 }
 
 static inline void io_ring_submit_unlock(struct io_ring_ctx *ctx,
Signature · 1 line
2.40.1
author maintainer
#4 lore raw

Re: [PATCH 3/3] io_uring: have io_file_put() take an io_kiocb rather than the file

Quoted 2 lines · Jens Axboe

No functional changes in this patch, just a prep patch for needing the request in io_file_put().

Gah, that was an older version. Newer version checks the REQ_F_FIXED_FILE flag in the helper instead:

commit 17bc28374cd06b7d2d3f1e88470ef89f9cd3a497

Author: Jens Axboe <[email protected]>
Date:   Fri Jul 7 11:14:40 2023 -0600

io_uring: have io_file_put() take an io_kiocb rather than the file

No functional changes in this patch, just a prep patch for needing the request in io_file_put().

io_uring/io_uring.c +2 -4
index dadd745d389e..15697d88930d 100644
@@ -998,8 +998,7 @@ static void __io_req_complete_post(struct io_kiocb *req, unsigned issue_flags)
 		io_put_kbuf_comp(req);
 		if (unlikely(req->flags & IO_REQ_CLEAN_FLAGS))
 			io_clean_op(req);
-		if (!(req->flags & REQ_F_FIXED_FILE))
-			io_put_file(req->file);
+		io_put_file(req);
 
 		rsrc_node = req->rsrc_node;
 		/*
@@ -1533,8 +1532,7 @@ void io_free_batch_list(struct io_ring_ctx *ctx, struct io_wq_work_node *node)
 			if (unlikely(req->flags & IO_REQ_CLEAN_FLAGS))
 				io_clean_op(req);
 		}
-		if (!(req->flags & REQ_F_FIXED_FILE))
-			io_put_file(req->file);
+		io_put_file(req);
 
 		io_req_put_rsrc_locked(req, ctx);
 
io_uring/io_uring.h +3 -3
index 12769bad5cee..ff153af28236 100644
@@ -196,10 +196,10 @@ static inline bool req_has_async_data(struct io_kiocb *req)
 	return req->flags & REQ_F_ASYNC_DATA;
 }
 
-static inline void io_put_file(struct file *file)
+static inline void io_put_file(struct io_kiocb *req)
 {
-	if (file)
-		fput(file);
+	if (!(req->flags & REQ_F_FIXED_FILE) && req->file)
+		fput(req->file);
 }
 
 static inline void io_ring_submit_unlock(struct io_ring_ctx *ctx,
Signature · 1 line
Jens Axboe