public inbox for io-uring@vger.kernel.org
 help / color / mirror / Atom feed
From: Ming Lei <ming.lei@redhat.com>
To: Jens Axboe <axboe@kernel.dk>
Cc: io-uring@vger.kernel.org, Pavel Begunkov <asml.silence@gmail.com>,
	Caleb Sander Mateos <csander@purestorage.com>,
	Stefan Metzmacher <metze@samba.org>,
	Ming Lei <ming.lei@redhat.com>
Subject: [PATCH V2 13/13] selftests/io_uring: add copy_user_to_reg_vec() and copy_reg_vec_to_user() bpf_memcpy tests
Date: Tue,  6 Jan 2026 18:11:22 +0800	[thread overview]
Message-ID: <20260106101126.4064990-14-ming.lei@redhat.com> (raw)
In-Reply-To: <20260106101126.4064990-1-ming.lei@redhat.com>

Add tests for IO_BPF_BUF_REG_VEC buffer type to verify uring_bpf_memcpy()
kfunc works correctly with registered vectored buffers.

IO_BPF_BUF_REG_VEC combines the vectored buffer layout (iovec array) with
registered buffer optimization - the underlying buffer is registered with
io_uring while the descriptor points to an iovec array for flexible
scatter-gather access.

Changes:
- Add is_registered_buf() helper to check if buffer type needs registration
- Update allocate_buf()/free_buf() to handle IO_BPF_BUF_REG_VEC type
- Update register_fixed_bufs()/unregister_fixed_bufs() to handle REG_VEC
- Update allocate_bufs() to set up REG_VEC descriptors with buf_index
- Add copy_user_to_reg_vec(): Tests USER source to REG_VEC destination
- Add copy_reg_vec_to_user(): Tests REG_VEC source to USER destination

Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
 tools/testing/selftests/io_uring/bpf_memcpy.c | 57 +++++++++++++++++--
 1 file changed, 52 insertions(+), 5 deletions(-)

diff --git a/tools/testing/selftests/io_uring/bpf_memcpy.c b/tools/testing/selftests/io_uring/bpf_memcpy.c
index 923b9d81b508..a221b84839bd 100644
--- a/tools/testing/selftests/io_uring/bpf_memcpy.c
+++ b/tools/testing/selftests/io_uring/bpf_memcpy.c
@@ -130,6 +130,7 @@ static int allocate_buf(char **buf, size_t size, __u8 buf_type,
 		*buf = p;
 		return 0;
 	case IO_BPF_BUF_VEC:
+	case IO_BPF_BUF_REG_VEC:
 		if (nr_vec <= 0 || nr_vec > MAX_VECS)
 			return -EINVAL;
 		p = aligned_alloc(4096, size);
@@ -156,6 +157,7 @@ static void free_buf(char *buf, __u8 buf_type)
 	case IO_BPF_BUF_USER:
 	case IO_BPF_BUF_VEC:
 	case IO_BPF_BUF_FIXED:
+	case IO_BPF_BUF_REG_VEC:
 		free(buf);
 		break;
 	default:
@@ -163,20 +165,25 @@ static void free_buf(char *buf, __u8 buf_type)
 	}
 }
 
+static inline bool is_registered_buf(__u8 type)
+{
+	return type == IO_BPF_BUF_FIXED || type == IO_BPF_BUF_REG_VEC;
+}
+
 static enum iou_test_status register_fixed_bufs(struct test_ctx *ctx)
 {
 	struct iovec iovecs[2];
 	int nr_iovecs = 0;
 	int ret;
 
-	if (ctx->src_type == IO_BPF_BUF_FIXED) {
+	if (is_registered_buf(ctx->src_type)) {
 		ctx->src_buf_index = nr_iovecs;
 		iovecs[nr_iovecs].iov_base = ctx->src_buf;
 		iovecs[nr_iovecs].iov_len = ctx->src_buf_size;
 		nr_iovecs++;
 	}
 
-	if (ctx->dst_type == IO_BPF_BUF_FIXED) {
+	if (is_registered_buf(ctx->dst_type)) {
 		ctx->dst_buf_index = nr_iovecs;
 		iovecs[nr_iovecs].iov_base = ctx->dst_buf;
 		iovecs[nr_iovecs].iov_len = ctx->dst_buf_size;
@@ -197,8 +204,8 @@ static enum iou_test_status register_fixed_bufs(struct test_ctx *ctx)
 
 static void unregister_fixed_bufs(struct test_ctx *ctx)
 {
-	if (ctx->src_type == IO_BPF_BUF_FIXED ||
-	    ctx->dst_type == IO_BPF_BUF_FIXED)
+	if (is_registered_buf(ctx->src_type) ||
+	    is_registered_buf(ctx->dst_type))
 		io_uring_unregister_buffers(&ctx->ring);
 }
 
@@ -249,6 +256,10 @@ static enum iou_test_status allocate_bufs(struct test_ctx *ctx)
 		ctx->descs[0].addr = (__u64)(uintptr_t)ctx->src_buf;
 		ctx->descs[0].len = ctx->src_buf_size;
 		ctx->descs[0].buf_index = ctx->src_buf_index;
+	} else if (ctx->src_type == IO_BPF_BUF_REG_VEC) {
+		ctx->descs[0].addr = (__u64)(uintptr_t)ctx->src_vec;
+		ctx->descs[0].len = ctx->src_nr_vec;
+		ctx->descs[0].buf_index = ctx->src_buf_index;
 	} else {
 		ctx->descs[0].addr = (__u64)(uintptr_t)ctx->src_buf;
 		ctx->descs[0].len = ctx->src_buf_size;
@@ -261,6 +272,10 @@ static enum iou_test_status allocate_bufs(struct test_ctx *ctx)
 		ctx->descs[1].addr = (__u64)(uintptr_t)ctx->dst_buf;
 		ctx->descs[1].len = ctx->dst_buf_size;
 		ctx->descs[1].buf_index = ctx->dst_buf_index;
+	} else if (ctx->dst_type == IO_BPF_BUF_REG_VEC) {
+		ctx->descs[1].addr = (__u64)(uintptr_t)ctx->dst_vec;
+		ctx->descs[1].len = ctx->dst_nr_vec;
+		ctx->descs[1].buf_index = ctx->dst_buf_index;
 	} else {
 		ctx->descs[1].addr = (__u64)(uintptr_t)ctx->dst_buf;
 		ctx->descs[1].len = ctx->dst_buf_size;
@@ -420,6 +435,30 @@ static enum iou_test_status copy_fixed_to_user(struct test_ctx *ctx)
 	return test_copy(ctx);
 }
 
+static enum iou_test_status copy_user_to_reg_vec(struct test_ctx *ctx)
+{
+	ctx->src_type = IO_BPF_BUF_USER;
+	ctx->dst_type = IO_BPF_BUF_REG_VEC;
+	ctx->src_buf_size = TEST_BUF_SIZE;
+	ctx->dst_buf_size = TEST_BUF_SIZE;
+	ctx->dst_nr_vec = 4;
+	ctx->desc = "USER -> REG_VEC";
+
+	return test_copy(ctx);
+}
+
+static enum iou_test_status copy_reg_vec_to_user(struct test_ctx *ctx)
+{
+	ctx->src_type = IO_BPF_BUF_REG_VEC;
+	ctx->dst_type = IO_BPF_BUF_USER;
+	ctx->src_buf_size = TEST_BUF_SIZE;
+	ctx->dst_buf_size = TEST_BUF_SIZE;
+	ctx->src_nr_vec = 4;
+	ctx->desc = "REG_VEC -> USER";
+
+	return test_copy(ctx);
+}
+
 static enum iou_test_status run(void *ctx_ptr)
 {
 	struct test_ctx *ctx = ctx_ptr;
@@ -445,6 +484,14 @@ static enum iou_test_status run(void *ctx_ptr)
 	if (status != IOU_TEST_PASS)
 		return status;
 
+	status = copy_user_to_reg_vec(ctx);
+	if (status != IOU_TEST_PASS)
+		return status;
+
+	status = copy_reg_vec_to_user(ctx);
+	if (status != IOU_TEST_PASS)
+		return status;
+
 	return IOU_TEST_PASS;
 }
 
@@ -462,7 +509,7 @@ static void cleanup(void *ctx_ptr)
 
 struct iou_test bpf_memcpy_test = {
 	.name = "bpf_memcpy",
-	.description = "Test uring_bpf_memcpy() kfunc with USER, VEC, FIXED buffer types",
+	.description = "Test uring_bpf_memcpy() kfunc with USER, VEC, FIXED, REG_VEC buffer types",
 	.setup = setup,
 	.run = run,
 	.cleanup = cleanup,
-- 
2.47.0


      parent reply	other threads:[~2026-01-06 10:12 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-06 10:11 [PATCH v2 0/13] io_uring: add IORING_OP_BPF for extending io_uring Ming Lei
2026-01-06 10:11 ` [PATCH V2 01/13] io_uring: make io_import_fixed() global Ming Lei
2026-01-06 10:11 ` [PATCH V2 02/13] io_uring: refactor io_prep_reg_iovec() for BPF kfunc use Ming Lei
2026-01-06 10:11 ` [PATCH V2 03/13] io_uring: refactor io_import_reg_vec() " Ming Lei
2026-01-06 10:11 ` [PATCH V2 04/13] io_uring: prepare for extending io_uring with bpf Ming Lei
2026-01-06 10:11 ` [PATCH V2 05/13] io_uring: bpf: extend io_uring with bpf struct_ops Ming Lei
2026-01-06 10:11 ` [PATCH V2 06/13] io_uring: bpf: implement struct_ops registration Ming Lei
2026-01-06 10:11 ` [PATCH V2 07/13] io_uring: bpf: add BPF buffer descriptor for IORING_OP_BPF Ming Lei
2026-01-06 10:11 ` [PATCH V2 08/13] io_uring: bpf: add uring_bpf_memcpy() kfunc Ming Lei
2026-01-06 10:11 ` [PATCH V2 09/13] selftests/io_uring: update mini liburing Ming Lei
2026-01-06 10:11 ` [PATCH V2 10/13] selftests/io_uring: add BPF struct_ops and kfunc tests Ming Lei
2026-01-06 10:11 ` [PATCH V2 11/13] selftests/io_uring: add bpf_memcpy selftest for uring_bpf_memcpy() kfunc Ming Lei
2026-01-06 10:11 ` [PATCH V2 12/13] selftests/io_uring: add copy_user_to_fixed() and copy_fixed_to_user() bpf_memcpy tests Ming Lei
2026-01-06 10:11 ` Ming Lei [this message]

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=20260106101126.4064990-14-ming.lei@redhat.com \
    --to=ming.lei@redhat.com \
    --cc=asml.silence@gmail.com \
    --cc=axboe@kernel.dk \
    --cc=csander@purestorage.com \
    --cc=io-uring@vger.kernel.org \
    --cc=metze@samba.org \
    /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