public inbox for [email protected]
 help / color / mirror / Atom feed
* [PATCH for-next 0/3] Misc cleanups
@ 2023-08-10 16:23 Jens Axboe
  2023-08-10 16:23 ` [PATCH 1/3] io_uring/fdinfo: get rid of ref tryget Jens Axboe
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Jens Axboe @ 2023-08-10 16:23 UTC (permalink / raw)
  To: io-uring

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.

-- 
Jens Axboe



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

* [PATCH 1/3] io_uring/fdinfo: get rid of ref tryget
  2023-08-10 16:23 [PATCH for-next 0/3] Misc cleanups Jens Axboe
@ 2023-08-10 16:23 ` Jens Axboe
  2023-08-10 16:23 ` [PATCH 2/3] io_uring/splice: use fput() directly Jens Axboe
  2023-08-10 16:23 ` [PATCH 3/3] io_uring: have io_file_put() take an io_kiocb rather than the file Jens Axboe
  2 siblings, 0 replies; 5+ messages in thread
From: Jens Axboe @ 2023-08-10 16:23 UTC (permalink / raw)
  To: io-uring; +Cc: Jens Axboe

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.

Signed-off-by: Jens Axboe <[email protected]>
---
 io_uring/fdinfo.c | 18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)

diff --git a/io_uring/fdinfo.c b/io_uring/fdinfo.c
index 76c279b13aee..300455b4bc12 100644
--- a/io_uring/fdinfo.c
+++ b/io_uring/fdinfo.c
@@ -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
-- 
2.40.1


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

* [PATCH 2/3] io_uring/splice: use fput() directly
  2023-08-10 16:23 [PATCH for-next 0/3] Misc cleanups Jens Axboe
  2023-08-10 16:23 ` [PATCH 1/3] io_uring/fdinfo: get rid of ref tryget Jens Axboe
@ 2023-08-10 16:23 ` Jens Axboe
  2023-08-10 16:23 ` [PATCH 3/3] io_uring: have io_file_put() take an io_kiocb rather than the file Jens Axboe
  2 siblings, 0 replies; 5+ messages in thread
From: Jens Axboe @ 2023-08-10 16:23 UTC (permalink / raw)
  To: io-uring; +Cc: 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.

Signed-off-by: Jens Axboe <[email protected]>
---
 io_uring/splice.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/io_uring/splice.c b/io_uring/splice.c
index 2a4bbb719531..7c4469e9540e 100644
--- a/io_uring/splice.c
+++ b/io_uring/splice.c
@@ -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);
-- 
2.40.1


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

* [PATCH 3/3] io_uring: have io_file_put() take an io_kiocb rather than the file
  2023-08-10 16:23 [PATCH for-next 0/3] Misc cleanups Jens Axboe
  2023-08-10 16:23 ` [PATCH 1/3] io_uring/fdinfo: get rid of ref tryget Jens Axboe
  2023-08-10 16:23 ` [PATCH 2/3] io_uring/splice: use fput() directly Jens Axboe
@ 2023-08-10 16:23 ` Jens Axboe
  2023-08-10 16:29   ` Jens Axboe
  2 siblings, 1 reply; 5+ messages in thread
From: Jens Axboe @ 2023-08-10 16:23 UTC (permalink / raw)
  To: io-uring; +Cc: Jens Axboe

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

Signed-off-by: Jens Axboe <[email protected]>
---
 io_uring/io_uring.c | 4 ++--
 io_uring/io_uring.h | 6 +++---
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
index 3da26171599b..138635e66d44 100644
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -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);
 
diff --git a/io_uring/io_uring.h b/io_uring/io_uring.h
index 12769bad5cee..46643bc9f3c5 100644
--- a/io_uring/io_uring.h
+++ b/io_uring/io_uring.h
@@ -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,
-- 
2.40.1


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

* Re: [PATCH 3/3] io_uring: have io_file_put() take an io_kiocb rather than the file
  2023-08-10 16:23 ` [PATCH 3/3] io_uring: have io_file_put() take an io_kiocb rather than the file Jens Axboe
@ 2023-08-10 16:29   ` Jens Axboe
  0 siblings, 0 replies; 5+ messages in thread
From: Jens Axboe @ 2023-08-10 16:29 UTC (permalink / raw)
  To: io-uring

On 8/10/23 10:23 AM, Jens Axboe wrote:
> 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().
    
    Signed-off-by: Jens Axboe <[email protected]>

diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
index dadd745d389e..15697d88930d 100644
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -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);
 
diff --git a/io_uring/io_uring.h b/io_uring/io_uring.h
index 12769bad5cee..ff153af28236 100644
--- a/io_uring/io_uring.h
+++ b/io_uring/io_uring.h
@@ -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,

-- 
Jens Axboe


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

end of thread, other threads:[~2023-08-10 16:29 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-10 16:23 [PATCH for-next 0/3] Misc cleanups Jens Axboe
2023-08-10 16:23 ` [PATCH 1/3] io_uring/fdinfo: get rid of ref tryget Jens Axboe
2023-08-10 16:23 ` [PATCH 2/3] io_uring/splice: use fput() directly Jens Axboe
2023-08-10 16:23 ` [PATCH 3/3] io_uring: have io_file_put() take an io_kiocb rather than the file Jens Axboe
2023-08-10 16:29   ` Jens Axboe

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