Skip to contentSkip to conversation

io_uring/rsrc: declare io_find_buf_node() in header file

PATCH Applied Caleb Sander Mateos 3 participants 17 messages Mar 1, 2025 io_uring

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 io_uring/rsrc: declare io_find_buf_node() in header file

Declare io_find_buf_node() in io_uring/rsrc.h so it can be called from other files.

---
 io_uring/rsrc.c | 4 ++--
 io_uring/rsrc.h | 2 ++
 2 files changed, 4 insertions(+), 2 deletions(-)
io_uring/rsrc.c +2 -2
index 45bfb37bca1e..4c4f57cd77f9 100644
@@ -1066,12 +1066,12 @@ static int io_import_fixed(int ddir, struct iov_iter *iter,
 	}
 
 	return 0;
 }
 
-static inline struct io_rsrc_node *io_find_buf_node(struct io_kiocb *req,
-						    unsigned issue_flags)
+struct io_rsrc_node *io_find_buf_node(struct io_kiocb *req,
+				      unsigned issue_flags)
 {
 	struct io_ring_ctx *ctx = req->ctx;
 	struct io_rsrc_node *node;
 
 	if (req->flags & REQ_F_BUF_NODE)
io_uring/rsrc.h +2 -0
index 6fe7b9e615bf..8f912aa6bcc9 100644
@@ -53,10 +53,12 @@ void io_rsrc_cache_free(struct io_ring_ctx *ctx);
 struct io_rsrc_node *io_rsrc_node_alloc(struct io_ring_ctx *ctx, int type);
 void io_free_rsrc_node(struct io_ring_ctx *ctx, struct io_rsrc_node *node);
 void io_rsrc_data_free(struct io_ring_ctx *ctx, struct io_rsrc_data *data);
 int io_rsrc_data_alloc(struct io_rsrc_data *data, unsigned nr);
 
+struct io_rsrc_node *io_find_buf_node(struct io_kiocb *req,
+				      unsigned issue_flags);
 int io_import_reg_buf(struct io_kiocb *req, struct iov_iter *iter,
 			u64 buf_addr, size_t len, int ddir,
 			unsigned issue_flags);
 
 int io_register_clone_buffers(struct io_ring_ctx *ctx, void __user *arg);
Signature · 1 line
2.45.2
#1 lore raw

PATCH 2/2 io_uring/nop: use io_find_buf_node()

Call io_find_buf_node() to avoid duplicating it in io_nop().

---
 io_uring/nop.c | 13 ++-----------
 1 file changed, 2 insertions(+), 11 deletions(-)
io_uring/nop.c +2 -11
index ea539531cb5f..28f06285fdc2 100644
@@ -59,21 +59,12 @@ int io_nop(struct io_kiocb *req, unsigned int issue_flags)
 			ret = -EBADF;
 			goto done;
 		}
 	}
 	if (nop->flags & IORING_NOP_FIXED_BUFFER) {
-		struct io_ring_ctx *ctx = req->ctx;
-		struct io_rsrc_node *node;
-
-		ret = -EFAULT;
-		io_ring_submit_lock(ctx, issue_flags);
-		node = io_rsrc_node_lookup(&ctx->buf_table, req->buf_index);
-		if (node) {
-			io_req_assign_buf_node(req, node);
-			ret = 0;
-		}
-		io_ring_submit_unlock(ctx, issue_flags);
+		if (!io_find_buf_node(req, issue_flags))
+			ret = -EFAULT;
 	}
 done:
 	if (ret < 0)
 		req_set_fail(req);
 	io_req_set_res(req, nop->result, 0);
Signature · 1 line
2.45.2
#2 lore raw

Re: [PATCH 2/2] io_uring/nop: use io_find_buf_node()

Quoted 1 line · Caleb Sander Mateos

Call io_find_buf_node() to avoid duplicating it in io_nop().

IORING_NOP_FIXED_BUFFER interface looks odd, instead of pretending to use a buffer, it basically pokes directly into internal infra, it's not something userspace should be able to do.

Jens, did use it anywhere? It's new, I'd rather kill it or align with how requests consume buffers, i.e. addr+len, and then do io_import_reg_buf() instead. That'd break the api though, but would anyone care?

Quoted 33 lines
---
  io_uring/nop.c | 13 ++-----------
  1 file changed, 2 insertions(+), 11 deletions(-)
io_uring/nop.c +2 -11
index ea539531cb5f..28f06285fdc2 100644
@@ -59,21 +59,12 @@ int io_nop(struct io_kiocb *req, unsigned int issue_flags)
  			ret = -EBADF;
  			goto done;
  		}
  	}
  	if (nop->flags & IORING_NOP_FIXED_BUFFER) {
-		struct io_ring_ctx *ctx = req->ctx;
-		struct io_rsrc_node *node;
-
-		ret = -EFAULT;
-		io_ring_submit_lock(ctx, issue_flags);
-		node = io_rsrc_node_lookup(&ctx->buf_table, req->buf_index);
-		if (node) {
-			io_req_assign_buf_node(req, node);
-			ret = 0;
-		}
-		io_ring_submit_unlock(ctx, issue_flags);
+		if (!io_find_buf_node(req, issue_flags))
+			ret = -EFAULT;
  	}
  done:
  	if (ret < 0)
  		req_set_fail(req);
  	io_req_set_res(req, nop->result, 0);
Signature · 1 line
Pavel Begunkov
#3 lore raw

Re: [PATCH 2/2] io_uring/nop: use io_find_buf_node()

Quoted 7 lines · Pavel Begunkov
Quoted 1 line · Caleb Sander Mateos

Call io_find_buf_node() to avoid duplicating it in io_nop().

IORING_NOP_FIXED_BUFFER interface looks odd, instead of pretending to use a buffer, it basically pokes directly into internal infra, it's not something userspace should be able to do.

I assumed it was just for benchmarking the overhead of fixed buffer lookup. Since a normal IORING_OP_NOP doesn't use any buffer, it makes sense for IORING_NOP_FIXED_BUFFER not to do anything with the fixed buffer either.

Added in this commit:
commit a85f31052bce52111b4e9d5a536003481d0421d0

Author: Jens Axboe <[email protected]>
Date:   Sun Oct 27 08:59:10 2024

io_uring/nop: add support for testing registered files and buffers

Useful for testing performance/efficiency impact of registered files and buffers, vs (particularly) non-registered files.

Best,
Caleb

Quoted 44 lines

Jens, did use it anywhere? It's new, I'd rather kill it or align with how requests consume buffers, i.e. addr+len, and then do io_import_reg_buf() instead. That'd break the api though, but would anyone care?

Quoted 23 lines
---
  io_uring/nop.c | 13 ++-----------
  1 file changed, 2 insertions(+), 11 deletions(-)
io_uring/nop.c +0 -8
index ea539531cb5f..28f06285fdc2 100644
@@ -59,21 +59,12 @@ int io_nop(struct io_kiocb *req, unsigned int issue_flags)
                      ret = -EBADF;
                      goto done;
              }
      }
      if (nop->flags & IORING_NOP_FIXED_BUFFER) {
-             struct io_ring_ctx *ctx = req->ctx;
-             struct io_rsrc_node *node;
-
-             ret = -EFAULT;
-             io_ring_submit_lock(ctx, issue_flags);
-             node = io_rsrc_node_lookup(&ctx->buf_table, req->buf_index);
-             if (node) {
-                     io_req_assign_buf_node(req, node);

io_uring/nop.c int io_nop(struct io_kiocb *req, unsigned int issue_flags) · line 70

Quoted 10 lines
io_uring/nop.c +2 -3
-                     ret = 0;
-             }
-             io_ring_submit_unlock(ctx, issue_flags);
+             if (!io_find_buf_node(req, issue_flags))
+                     ret = -EFAULT;
      }
  done:
      if (ret < 0)
              req_set_fail(req);
      io_req_set_res(req, nop->result, 0);

--
Pavel Begunkov

#4 lore raw

Re: [PATCH 2/2] io_uring/nop: use io_find_buf_node()

Quoted 10 lines · Caleb Sander Mateos
Quoted 7 lines · Pavel Begunkov
Quoted 1 line · Caleb Sander Mateos

Call io_find_buf_node() to avoid duplicating it in io_nop().

IORING_NOP_FIXED_BUFFER interface looks odd, instead of pretending to use a buffer, it basically pokes directly into internal infra, it's not something userspace should be able to do.

I assumed it was just for benchmarking the overhead of fixed buffer

Right

Quoted 3 lines

lookup. Since a normal IORING_OP_NOP doesn't use any buffer, it makes sense for IORING_NOP_FIXED_BUFFER not to do anything with the fixed buffer either.

That's a special api that benchmarks internal details that no other request knows about, no, that's not great.

Signature · 1 line
Pavel Begunkov
maintainer
#5 lore raw

Re: [PATCH 2/2] io_uring/nop: use io_find_buf_node()

In reply to Caleb Sander Mateos
Quoted 5 lines · Caleb Sander Mateos
Quoted 4 lines · Pavel Begunkov
Quoted 1 line · Caleb Sander Mateos

Call io_find_buf_node() to avoid duplicating it in io_nop().

Quoted 8 lines
Quoted 3 lines

IORING_NOP_FIXED_BUFFER interface looks odd, instead of pretending to use a buffer, it basically pokes directly into internal infra, it's not something userspace should be able to do.

I assumed it was just for benchmarking the overhead of fixed buffer lookup. Since a normal IORING_OP_NOP doesn't use any buffer, it makes sense for IORING_NOP_FIXED_BUFFER not to do anything with the fixed buffer either.

That's exactly right, it's just for benchmarking purposes. NOP doesn't transfer anything, obviously, so it doesn't do anything with it.

Signature · 1 line
Jens Axboe
#6 lore raw

Re: [PATCH 2/2] io_uring/nop: use io_find_buf_node()

In reply to Pavel Begunkov
Quoted 11 lines · Pavel Begunkov
Quoted 1 line · Caleb Sander Mateos

Call io_find_buf_node() to avoid duplicating it in io_nop().

IORING_NOP_FIXED_BUFFER interface looks odd, instead of pretending to use a buffer, it basically pokes directly into internal infra, it's not something userspace should be able to do.

Jens, did use it anywhere? It's new, I'd rather kill it or align with how requests consume buffers, i.e. addr+len, and then do io_import_reg_buf() instead. That'd break the api though, but would anyone care?

3rd option is to ignore the flag and let the req succeed.

Signature · 1 line
Pavel Begunkov
maintainer
#7 lore raw

Re: [PATCH 2/2] io_uring/nop: use io_find_buf_node()

Quoted 8 lines · Pavel Begunkov
Quoted 7 lines · Pavel Begunkov
Quoted 1 line · Caleb Sander Mateos

Call io_find_buf_node() to avoid duplicating it in io_nop().

IORING_NOP_FIXED_BUFFER interface looks odd, instead of pretending to use a buffer, it basically pokes directly into internal infra, it's not something userspace should be able to do.

Quoted 6 lines
Quoted 4 lines

Jens, did use it anywhere? It's new, I'd rather kill it or align with how requests consume buffers, i.e. addr+len, and then do io_import_reg_buf() instead. That'd break the api though, but would anyone care?

3rd option is to ignore the flag and let the req succeed.

Honestly what is the problem here? NOP isn't doing anything that other commands types can't or aren't already. So no, it should stay, it's been handy for testing overheads, which is why it was added in the first place.

Signature · 1 line
Jens Axboe
#8 lore raw

Re: [PATCH 2/2] io_uring/nop: use io_find_buf_node()

Quoted 14 lines · Jens Axboe
Quoted 13 lines · Pavel Begunkov
Quoted 11 lines · Pavel Begunkov
Quoted 1 line · Caleb Sander Mateos

Call io_find_buf_node() to avoid duplicating it in io_nop().

IORING_NOP_FIXED_BUFFER interface looks odd, instead of pretending to use a buffer, it basically pokes directly into internal infra, it's not something userspace should be able to do.

Jens, did use it anywhere? It's new, I'd rather kill it or align with how requests consume buffers, i.e. addr+len, and then do io_import_reg_buf() instead. That'd break the api though, but would anyone care?

Quoted 4 lines
Quoted 1 line

3rd option is to ignore the flag and let the req succeed.

Honestly what is the problem here? NOP isn't doing anything that other commands types can't or aren't already. So no, it should stay,

It completely ignores any checking and buffer importing stopping half way at looking at nodes, the behaviour other requests don't do. We can also add a request that take a lock and releases it back because other requests do that as well but as a part of some useful sequence of actions.

Quoted 2 lines

it's been handy for testing overheads, which is why it was added in the first place.

Signature · 1 line
Pavel Begunkov
maintainer
#9 lore raw

Re: [PATCH 2/2] io_uring/nop: use io_find_buf_node()

Quoted 17 lines · Pavel Begunkov
Quoted 16 lines · Jens Axboe
Quoted 14 lines · Pavel Begunkov
Quoted 11 lines · Pavel Begunkov
Quoted 1 line · Caleb Sander Mateos

Call io_find_buf_node() to avoid duplicating it in io_nop().

IORING_NOP_FIXED_BUFFER interface looks odd, instead of pretending to use a buffer, it basically pokes directly into internal infra, it's not something userspace should be able to do.

Jens, did use it anywhere? It's new, I'd rather kill it or align with how requests consume buffers, i.e. addr+len, and then do io_import_reg_buf() instead. That'd break the api though, but would anyone care?

3rd option is to ignore the flag and let the req succeed.

Quoted 8 lines
Quoted 2 lines

Honestly what is the problem here? NOP isn't doing anything that other commands types can't or aren't already. So no, it should stay,

It completely ignores any checking and buffer importing stopping half way at looking at nodes, the behaviour other requests don't do. We can also add a request that take a lock and releases it back because other requests do that as well but as a part of some useful sequence of actions.

Let's not resort to hyperbole - it's useful to be able to test (and hence quantify) provided buffer usage. I used it while doing the resource node rework. We also have a NOP opcode to be able to test generic overhead for that very reason. For testing _io_uring_ infrastructure it was already useful for me. Of course we should not add random things that test things like lock acquire and release, that's not the scope of NOP.

Sure you could add import as well, but a) nop doesn't touch the data, and b) that's largely testing generic kernel infrastructure as well.

The whole point of NOP is to be able to test io_uring infrastructure.

Signature · 1 line
Jens Axboe
#10 lore raw

Re: [PATCH 2/2] io_uring/nop: use io_find_buf_node()

Quoted 21 lines · Jens Axboe
Quoted 20 lines · Pavel Begunkov
Quoted 18 lines · Jens Axboe
Quoted 8 lines · Pavel Begunkov
Quoted 7 lines · Pavel Begunkov
Quoted 1 line · Caleb Sander Mateos

Call io_find_buf_node() to avoid duplicating it in io_nop().

IORING_NOP_FIXED_BUFFER interface looks odd, instead of pretending to use a buffer, it basically pokes directly into internal infra, it's not something userspace should be able to do.

Quoted 6 lines
Quoted 4 lines

Jens, did use it anywhere? It's new, I'd rather kill it or align with how requests consume buffers, i.e. addr+len, and then do io_import_reg_buf() instead. That'd break the api though, but would anyone care?

3rd option is to ignore the flag and let the req succeed.

Honestly what is the problem here? NOP isn't doing anything that other commands types can't or aren't already. So no, it should stay,

Quoted 7 lines
Quoted 5 lines

It completely ignores any checking and buffer importing stopping half way at looking at nodes, the behaviour other requests don't do. We can also add a request that take a lock and releases it back because other requests do that as well but as a part of some useful sequence of actions.

Let's not resort to hyperbole - it's useful to be able to test (and

That's not a hyperbole, it's a direct analogy.

Quoted 11 lines

hence quantify) provided buffer usage. I used it while doing the resource node rework. We also have a NOP opcode to be able to test generic overhead for that very reason. For testing _io_uring_ infrastructure it was already useful for me. Of course we should not add random things that test things like lock acquire and release, that's not the scope of NOP.

Sure you could add import as well, but a) nop doesn't touch the data, and b) that's largely testing generic kernel infrastructure as well.

The whole point of NOP is to be able to test io_uring infrastructure.

And now we add overhead to test overhead of the very path we add overhead to, just splendid. It's intrusive, it looks into guts of infra that can change, and the way not to be intrusive is to follow the way others use the concept, which is why I'm suggesting importing the buffer, and that would be another direct analogy with the pure NOP (w/o flags).

Signature · 1 line
Pavel Begunkov
#11 lore raw
In reply to Caleb Sander Mateos
Quoted 14 lines · Caleb Sander Mateos

Declare io_find_buf_node() in io_uring/rsrc.h so it can be called from other files.

---
  io_uring/rsrc.c | 4 ++--
  io_uring/rsrc.h | 2 ++
  2 files changed, 4 insertions(+), 2 deletions(-)
io_uring/rsrc.c +0 -0
index 45bfb37bca1e..4c4f57cd77f9 100644

io_uring/rsrc.c static int io_import_fixed(int ddir, struct iov_iter *iter, · line 1072

Quoted 7 lines
io_uring/rsrc.c +0 -2
@@ -1066,12 +1066,12 @@ static int io_import_fixed(int ddir, struct iov_iter *iter,
  	}
 
  	return 0;
  }
 
-static inline struct io_rsrc_node *io_find_buf_node(struct io_kiocb *req,
-						    unsigned issue_flags)

That's a hot path, an extra function call wouldn't be great, and it's an internal detail as well. Let's better see what we can do with the nop situation.

btw, don't forget cover letters for series.

Signature · 1 line
Pavel Begunkov
#12 lore raw
Quoted 21 lines · Pavel Begunkov
Quoted 19 lines · Caleb Sander Mateos

Declare io_find_buf_node() in io_uring/rsrc.h so it can be called from other files.

---
  io_uring/rsrc.c | 4 ++--
  io_uring/rsrc.h | 2 ++
  2 files changed, 4 insertions(+), 2 deletions(-)
io_uring/rsrc.c +0 -0
index 45bfb37bca1e..4c4f57cd77f9 100644
@@ -1066,12 +1066,12 @@ static int io_import_fixed(int ddir, struct iov_iter *iter,
      }
 
      return 0;
  }
 
Quoted 6 lines

io_uring/rsrc.c static int io_import_fixed(int ddir, struct iov_iter *iter, · line 1072

Quoted 2 lines
io_uring/rsrc.c +0 -2
-static inline struct io_rsrc_node *io_find_buf_node(struct io_kiocb *req,
-                                                 unsigned issue_flags)

That's a hot path, an extra function call wouldn't be great, and it's an internal detail as well. Let's better see what we can do with the nop situation.

I can add back inline. With that, there shouldn't be any difference to the generated instructions for io_import_reg_buf().

Quoted 2 lines

btw, don't forget cover letters for series.

Okay, I didn't have much else to add to the brief commit messages. But sure, I'll add a cover letter in the future.

Best,
Caleb

maintainer
#13 lore raw
Quoted 29 lines · Caleb Sander Mateos
Quoted 21 lines · Pavel Begunkov
Quoted 19 lines · Caleb Sander Mateos

Declare io_find_buf_node() in io_uring/rsrc.h so it can be called from other files.

---
  io_uring/rsrc.c | 4 ++--
  io_uring/rsrc.h | 2 ++
  2 files changed, 4 insertions(+), 2 deletions(-)
io_uring/rsrc.c +0 -0
index 45bfb37bca1e..4c4f57cd77f9 100644
@@ -1066,12 +1066,12 @@ static int io_import_fixed(int ddir, struct iov_iter *iter,
      }
 
      return 0;
  }
 
Quoted 6 lines

io_uring/rsrc.c static int io_import_fixed(int ddir, struct iov_iter *iter, · line 1072

Quoted 2 lines
io_uring/rsrc.c +0 -2
-static inline struct io_rsrc_node *io_find_buf_node(struct io_kiocb *req,
-                                                 unsigned issue_flags)

That's a hot path, an extra function call wouldn't be great, and it's an internal detail as well. Let's better see what we can do with the nop situation.

Quoted 2 lines

I can add back inline. With that, there shouldn't be any difference to the generated instructions for io_import_reg_buf().

Yeah, in general I don't like manual inlines, unless it's been proven that the compiler messes it up for some reason. If it's short enough it'll be inlined.

Quoted 4 lines
Quoted 1 line

btw, don't forget cover letters for series.

Okay, I didn't have much else to add to the brief commit messages. But sure, I'll add a cover letter in the future.

Indeed, cover letters are always great to have.

Signature · 1 line
Jens Axboe
#14 lore raw
Quoted 30 lines · Jens Axboe
Quoted 29 lines · Caleb Sander Mateos
Quoted 27 lines · Pavel Begunkov
Quoted 14 lines · Caleb Sander Mateos

Declare io_find_buf_node() in io_uring/rsrc.h so it can be called from other files.

---
   io_uring/rsrc.c | 4 ++--
   io_uring/rsrc.h | 2 ++
   2 files changed, 4 insertions(+), 2 deletions(-)
io_uring/rsrc.c +0 -0
index 45bfb37bca1e..4c4f57cd77f9 100644

io_uring/rsrc.c static int io_import_fixed(int ddir, struct iov_iter *iter, · line 1072

Quoted 7 lines
io_uring/rsrc.c +0 -2
@@ -1066,12 +1066,12 @@ static int io_import_fixed(int ddir, struct iov_iter *iter,
       }
 
       return 0;
   }
 
-static inline struct io_rsrc_node *io_find_buf_node(struct io_kiocb *req,
-                                                 unsigned issue_flags)

That's a hot path, an extra function call wouldn't be great, and it's an internal detail as well. Let's better see what we can do with the nop situation.

Quoted 6 lines
Quoted 2 lines

I can add back inline. With that, there shouldn't be any difference to the generated instructions for io_import_reg_buf().

Yeah, in general I don't like manual inlines, unless it's been proven that the compiler messes it up for some reason. If it's short enough it'll be inlined.

It will _not_ be inlined in this case.

Signature · 1 line
Pavel Begunkov
maintainer
#15 lore raw
Quoted 31 lines · Pavel Begunkov
Quoted 30 lines · Jens Axboe
Quoted 29 lines · Caleb Sander Mateos
Quoted 27 lines · On Fri, Feb 28, 2025 at 5:45?PM Pavel Begunkov <[email protected]> wrote:
Quoted 14 lines · Caleb Sander Mateos

Declare io_find_buf_node() in io_uring/rsrc.h so it can be called from other files.

---
   io_uring/rsrc.c | 4 ++--
   io_uring/rsrc.h | 2 ++
   2 files changed, 4 insertions(+), 2 deletions(-)
io_uring/rsrc.c +0 -0
index 45bfb37bca1e..4c4f57cd77f9 100644

io_uring/rsrc.c static int io_import_fixed(int ddir, struct iov_iter *iter, · line 1072

Quoted 7 lines
io_uring/rsrc.c +0 -2
@@ -1066,12 +1066,12 @@ static int io_import_fixed(int ddir, struct iov_iter *iter,
       }
 
       return 0;
   }
 
-static inline struct io_rsrc_node *io_find_buf_node(struct io_kiocb *req,
-                                                 unsigned issue_flags)

That's a hot path, an extra function call wouldn't be great, and it's an internal detail as well. Let's better see what we can do with the nop situation.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

I can add back inline. With that, there shouldn't be any difference to the generated instructions for io_import_reg_buf().

Yeah, in general I don't like manual inlines, unless it's been proven that the compiler messes it up for some reason. If it's short enough it'll be inlined.

It will _not_ be inlined in this case.

Hmm ok - I wonder why that is. But if we want to force it to do that, then we can just re-add the inline for the local definition, that'll be fine with it still being non-static and available.

Signature · 1 line
Jens Axboe
maintainer Applied
#16 lore raw
In reply to Caleb Sander Mateos
Quoted 4 lines · Caleb Sander Mateos

Declare io_find_buf_node() in io_uring/rsrc.h so it can be called from other files.

Applied, thanks!

[1/2] io_uring/rsrc: declare io_find_buf_node() in header file

      commit: 98ddbefafecf270d51902cabfe289df10a702cef
[2/2] io_uring/nop: use io_find_buf_node()
      commit: 15d86dd9019c7a97bd8c5b6880870b97e7cc74ea

Best regards,

Signature · 1 line
Jens Axboe