public inbox for [email protected]
 help / color / mirror / Atom feed
From: Pavel Begunkov <[email protected]>
To: [email protected]
Cc: [email protected]
Subject: [PATCH 3/8] io_uring/kbuf: move locking into io_kbuf_drop()
Date: Wed,  5 Feb 2025 11:36:44 +0000	[thread overview]
Message-ID: <530f0cf1f06963029399f819a9a58b1a34bebef3.1738724373.git.asml.silence@gmail.com> (raw)
In-Reply-To: <[email protected]>

Move the burden of locking out of the caller into io_kbuf_drop(), that
will help with furher refactoring.

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

diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
index 6fa1e88e40fbe..ed7c9081352a4 100644
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -398,11 +398,8 @@ static bool req_need_defer(struct io_kiocb *req, u32 seq)
 
 static void io_clean_op(struct io_kiocb *req)
 {
-	if (req->flags & REQ_F_BUFFER_SELECTED) {
-		spin_lock(&req->ctx->completion_lock);
+	if (unlikely(req->flags & REQ_F_BUFFER_SELECTED))
 		io_kbuf_drop(req);
-		spin_unlock(&req->ctx->completion_lock);
-	}
 
 	if (req->flags & REQ_F_NEED_CLEANUP) {
 		const struct io_cold_def *def = &io_cold_defs[req->opcode];
diff --git a/io_uring/kbuf.h b/io_uring/kbuf.h
index bd80c44c5af1e..310f94a0727a6 100644
--- a/io_uring/kbuf.h
+++ b/io_uring/kbuf.h
@@ -174,13 +174,13 @@ static inline void __io_put_kbuf_list(struct io_kiocb *req, int len,
 
 static inline void io_kbuf_drop(struct io_kiocb *req)
 {
-	lockdep_assert_held(&req->ctx->completion_lock);
-
 	if (!(req->flags & (REQ_F_BUFFER_SELECTED|REQ_F_BUFFER_RING)))
 		return;
 
+	spin_lock(&req->ctx->completion_lock);
 	/* len == 0 is fine here, non-ring will always drop all of it */
 	__io_put_kbuf_list(req, 0, &req->ctx->io_buffers_comp);
+	spin_unlock(&req->ctx->completion_lock);
 }
 
 static inline unsigned int __io_put_kbufs(struct io_kiocb *req, int len,
-- 
2.47.1


  parent reply	other threads:[~2025-02-05 11:36 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-05 11:36 [PATCH 0/8] legacy provided buffer deprecation / deoptimisation Pavel Begunkov
2025-02-05 11:36 ` [PATCH 1/8] io_uring/kbuf: remove legacy kbuf bulk allocation Pavel Begunkov
2025-02-05 11:36 ` [PATCH 2/8] io_uring/kbuf: remove legacy kbuf kmem cache Pavel Begunkov
2025-02-05 11:36 ` Pavel Begunkov [this message]
2025-02-05 11:36 ` [PATCH 4/8] io_uring/kbuf: simplify __io_put_kbuf Pavel Begunkov
2025-02-05 11:36 ` [PATCH 5/8] io_uring/kbuf: remove legacy kbuf caching Pavel Begunkov
2025-02-05 11:36 ` [PATCH 6/8] io_uring/kbuf: open code __io_put_kbuf() Pavel Begunkov
2025-02-05 11:36 ` [PATCH 7/8] io_uring/kbuf: introduce io_kbuf_drop_legacy() Pavel Begunkov
2025-02-05 11:36 ` [PATCH 8/8] io_uring/kbuf: uninline __io_put_kbufs Pavel Begunkov
2025-02-05 16:17 ` [PATCH 0/8] legacy provided buffer deprecation / deoptimisation Jens Axboe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=530f0cf1f06963029399f819a9a58b1a34bebef3.1738724373.git.asml.silence@gmail.com \
    [email protected] \
    [email protected] \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox