public inbox for io-uring@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1 1/3] io_uring/rsrc: clean up buffer cloning arg validation
@ 2025-12-04 21:51 Joanne Koong
  2025-12-04 21:51 ` [PATCH v1 2/3] io_uring/rsrc: rename misleading src_node variable in io_clone_buffers() Joanne Koong
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Joanne Koong @ 2025-12-04 21:51 UTC (permalink / raw)
  To: axboe; +Cc: io-uring, asml.silence, csander

Get rid of some redundant checks and move the src arg validation to
before the buffer table allocation, which simplifies error handling.

Signed-off-by: Joanne Koong <joannelkoong@gmail.com>
---
 io_uring/rsrc.c | 27 ++++++---------------------
 1 file changed, 6 insertions(+), 21 deletions(-)

diff --git a/io_uring/rsrc.c b/io_uring/rsrc.c
index 3765a50329a8..5ad3d10413eb 100644
--- a/io_uring/rsrc.c
+++ b/io_uring/rsrc.c
@@ -1186,12 +1186,16 @@ static int io_clone_buffers(struct io_ring_ctx *ctx, struct io_ring_ctx *src_ctx
 		return -EBUSY;
 
 	nbufs = src_ctx->buf_table.nr;
+	if (!nbufs)
+		return -ENXIO;
 	if (!arg->nr)
 		arg->nr = nbufs;
 	else if (arg->nr > nbufs)
 		return -EINVAL;
 	else if (arg->nr > IORING_MAX_REG_BUFFERS)
 		return -EINVAL;
+	if (check_add_overflow(arg->nr, arg->src_off, &off) || off > nbufs)
+		return -EOVERFLOW;
 	if (check_add_overflow(arg->nr, arg->dst_off, &nbufs))
 		return -EOVERFLOW;
 	if (nbufs > IORING_MAX_REG_BUFFERS)
@@ -1211,21 +1215,6 @@ static int io_clone_buffers(struct io_ring_ctx *ctx, struct io_ring_ctx *src_ctx
 		}
 	}
 
-	ret = -ENXIO;
-	nbufs = src_ctx->buf_table.nr;
-	if (!nbufs)
-		goto out_free;
-	ret = -EINVAL;
-	if (!arg->nr)
-		arg->nr = nbufs;
-	else if (arg->nr > nbufs)
-		goto out_free;
-	ret = -EOVERFLOW;
-	if (check_add_overflow(arg->nr, arg->src_off, &off))
-		goto out_free;
-	if (off > nbufs)
-		goto out_free;
-
 	off = arg->dst_off;
 	i = arg->src_off;
 	nr = arg->nr;
@@ -1238,8 +1227,8 @@ static int io_clone_buffers(struct io_ring_ctx *ctx, struct io_ring_ctx *src_ctx
 		} else {
 			dst_node = io_rsrc_node_alloc(ctx, IORING_RSRC_BUFFER);
 			if (!dst_node) {
-				ret = -ENOMEM;
-				goto out_free;
+				io_rsrc_data_free(ctx, &data);
+				return -ENOMEM;
 			}
 
 			refcount_inc(&src_node->buf->refs);
@@ -1265,10 +1254,6 @@ static int io_clone_buffers(struct io_ring_ctx *ctx, struct io_ring_ctx *src_ctx
 	WARN_ON_ONCE(ctx->buf_table.nr);
 	ctx->buf_table = data;
 	return 0;
-
-out_free:
-	io_rsrc_data_free(ctx, &data);
-	return ret;
 }
 
 /*
-- 
2.47.3


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

* [PATCH v1 2/3] io_uring/rsrc: rename misleading src_node variable in io_clone_buffers()
  2025-12-04 21:51 [PATCH v1 1/3] io_uring/rsrc: clean up buffer cloning arg validation Joanne Koong
@ 2025-12-04 21:51 ` Joanne Koong
  2025-12-04 21:51 ` [PATCH v1 3/3] io_uring/rsrc: fix lost entries after cloned range Joanne Koong
  2025-12-04 22:47 ` [PATCH v1 1/3] io_uring/rsrc: clean up buffer cloning arg validation Jens Axboe
  2 siblings, 0 replies; 4+ messages in thread
From: Joanne Koong @ 2025-12-04 21:51 UTC (permalink / raw)
  To: axboe; +Cc: io-uring, asml.silence, csander

The variable holds nodes from the destination ring's existing buffer
table. In io_clone_buffers(), the term "src" is used to refer to the
source ring.

Rename to node for clarity.

Signed-off-by: Joanne Koong <joannelkoong@gmail.com>
---
 io_uring/rsrc.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/io_uring/rsrc.c b/io_uring/rsrc.c
index 5ad3d10413eb..04f56212398a 100644
--- a/io_uring/rsrc.c
+++ b/io_uring/rsrc.c
@@ -1207,11 +1207,11 @@ static int io_clone_buffers(struct io_ring_ctx *ctx, struct io_ring_ctx *src_ctx
 
 	/* Fill entries in data from dst that won't overlap with src */
 	for (i = 0; i < min(arg->dst_off, ctx->buf_table.nr); i++) {
-		struct io_rsrc_node *src_node = ctx->buf_table.nodes[i];
+		struct io_rsrc_node *node = ctx->buf_table.nodes[i];
 
-		if (src_node) {
-			data.nodes[i] = src_node;
-			src_node->refs++;
+		if (node) {
+			data.nodes[i] = node;
+			node->refs++;
 		}
 	}
 
-- 
2.47.3


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

* [PATCH v1 3/3] io_uring/rsrc: fix lost entries after cloned range
  2025-12-04 21:51 [PATCH v1 1/3] io_uring/rsrc: clean up buffer cloning arg validation Joanne Koong
  2025-12-04 21:51 ` [PATCH v1 2/3] io_uring/rsrc: rename misleading src_node variable in io_clone_buffers() Joanne Koong
@ 2025-12-04 21:51 ` Joanne Koong
  2025-12-04 22:47 ` [PATCH v1 1/3] io_uring/rsrc: clean up buffer cloning arg validation Jens Axboe
  2 siblings, 0 replies; 4+ messages in thread
From: Joanne Koong @ 2025-12-04 21:51 UTC (permalink / raw)
  To: axboe; +Cc: io-uring, asml.silence, csander, stable

When cloning with node replacements (IORING_REGISTER_DST_REPLACE),
destination entries after the cloned range are not copied over.

Add logic to copy them over to the new destination table.

Fixes: c1329532d5aa ("io_uring/rsrc: allow cloning with node replacements")
Cc: stable@vger.kernel.org
Signed-off-by: Joanne Koong <joannelkoong@gmail.com>
---
 io_uring/rsrc.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/io_uring/rsrc.c b/io_uring/rsrc.c
index 04f56212398a..a63474b331bf 100644
--- a/io_uring/rsrc.c
+++ b/io_uring/rsrc.c
@@ -1205,7 +1205,7 @@ static int io_clone_buffers(struct io_ring_ctx *ctx, struct io_ring_ctx *src_ctx
 	if (ret)
 		return ret;
 
-	/* Fill entries in data from dst that won't overlap with src */
+	/* Copy original dst nodes from before the cloned range */
 	for (i = 0; i < min(arg->dst_off, ctx->buf_table.nr); i++) {
 		struct io_rsrc_node *node = ctx->buf_table.nodes[i];
 
@@ -1238,6 +1238,16 @@ static int io_clone_buffers(struct io_ring_ctx *ctx, struct io_ring_ctx *src_ctx
 		i++;
 	}
 
+	/* Copy original dst nodes from after the cloned range */
+	for (i = nbufs; i < ctx->buf_table.nr; i++) {
+		struct io_rsrc_node *node = ctx->buf_table.nodes[i];
+
+		if (node) {
+			data.nodes[i] = node;
+			node->refs++;
+		}
+	}
+
 	/*
 	 * If asked for replace, put the old table. data->nodes[] holds both
 	 * old and new nodes at this point.
-- 
2.47.3


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

* Re: [PATCH v1 1/3] io_uring/rsrc: clean up buffer cloning arg validation
  2025-12-04 21:51 [PATCH v1 1/3] io_uring/rsrc: clean up buffer cloning arg validation Joanne Koong
  2025-12-04 21:51 ` [PATCH v1 2/3] io_uring/rsrc: rename misleading src_node variable in io_clone_buffers() Joanne Koong
  2025-12-04 21:51 ` [PATCH v1 3/3] io_uring/rsrc: fix lost entries after cloned range Joanne Koong
@ 2025-12-04 22:47 ` Jens Axboe
  2 siblings, 0 replies; 4+ messages in thread
From: Jens Axboe @ 2025-12-04 22:47 UTC (permalink / raw)
  To: Joanne Koong; +Cc: io-uring, asml.silence, csander


On Thu, 04 Dec 2025 13:51:14 -0800, Joanne Koong wrote:
> Get rid of some redundant checks and move the src arg validation to
> before the buffer table allocation, which simplifies error handling.
> 
> 

Applied, thanks!

[1/3] io_uring/rsrc: clean up buffer cloning arg validation
      commit: b8201b50e403815f941d1c6581a27fdbfe7d0fd4
[2/3] io_uring/rsrc: rename misleading src_node variable in io_clone_buffers()
      commit: e29af2aba262833c8eba578b58d6bbb6b0866a67
[3/3] io_uring/rsrc: fix lost entries after cloned range
      commit: 525916ce496615f531091855604eab9ca573b195

Best regards,
-- 
Jens Axboe




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

end of thread, other threads:[~2025-12-04 22:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-04 21:51 [PATCH v1 1/3] io_uring/rsrc: clean up buffer cloning arg validation Joanne Koong
2025-12-04 21:51 ` [PATCH v1 2/3] io_uring/rsrc: rename misleading src_node variable in io_clone_buffers() Joanne Koong
2025-12-04 21:51 ` [PATCH v1 3/3] io_uring/rsrc: fix lost entries after cloned range Joanne Koong
2025-12-04 22:47 ` [PATCH v1 1/3] io_uring/rsrc: clean up buffer cloning arg validation Jens Axboe

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