public inbox for [email protected]
 help / color / mirror / Atom feed
* [PATCH liburing 0/4] test kernel allocated regions
@ 2024-11-20 23:39 Pavel Begunkov
  2024-11-20 23:39 ` [PATCH liburing 1/4] tests/reg-wait: test registering RO memory Pavel Begunkov
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Pavel Begunkov @ 2024-11-20 23:39 UTC (permalink / raw)
  To: io-uring; +Cc: asml.silence

Patch 1 excersices one additional failure path for user provided regions,
and the rest test kernel allocated regions.

Pavel Begunkov (4):
  tests/reg-wait: test registering RO memory
  test/reg-wait: basic test + probing of kernel regions
  test/reg-wait: add allocation abstraction
  test/reg-wait: test kernel allocated regions

 test/reg-wait.c | 181 +++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 147 insertions(+), 34 deletions(-)

-- 
2.46.0


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

* [PATCH liburing 1/4] tests/reg-wait: test registering RO memory
  2024-11-20 23:39 [PATCH liburing 0/4] test kernel allocated regions Pavel Begunkov
@ 2024-11-20 23:39 ` Pavel Begunkov
  2024-11-20 23:39 ` [PATCH liburing 2/4] test/reg-wait: basic test + probing of kernel regions Pavel Begunkov
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Pavel Begunkov @ 2024-11-20 23:39 UTC (permalink / raw)
  To: io-uring; +Cc: asml.silence

Mapping should be writable and those we can't use read only user memory,
check that it fails. It also exercises one of the fail paths.

Signed-off-by: Pavel Begunkov <[email protected]>
---
 test/reg-wait.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/test/reg-wait.c b/test/reg-wait.c
index b7c823a..544cd48 100644
--- a/test/reg-wait.c
+++ b/test/reg-wait.c
@@ -365,8 +365,22 @@ static int test_regions(void)
 		return T_EXIT_FAIL;
 	}
 	rd.user_addr = (__u64)(unsigned long)buffer;
-
 	free(buffer);
+
+	buffer = mmap(NULL, page_size, PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+	if (buffer == MAP_FAILED) {
+		fprintf(stderr, "mmap alloc failed\n");
+		return 1;
+	}
+
+	rd.user_addr = (__u64)(unsigned long)buffer;
+	ret = test_try_register_region(&mr, true);
+	if (ret != -EFAULT) {
+		fprintf(stderr, "test_try_register_region() RO uptr %i\n", ret);
+		return T_EXIT_FAIL;
+	}
+
+	munmap(buffer, page_size);
 	return 0;
 }
 
-- 
2.46.0


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

* [PATCH liburing 2/4] test/reg-wait: basic test + probing of kernel regions
  2024-11-20 23:39 [PATCH liburing 0/4] test kernel allocated regions Pavel Begunkov
  2024-11-20 23:39 ` [PATCH liburing 1/4] tests/reg-wait: test registering RO memory Pavel Begunkov
@ 2024-11-20 23:39 ` Pavel Begunkov
  2024-11-20 23:39 ` [PATCH liburing 3/4] test/reg-wait: add allocation abstraction Pavel Begunkov
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Pavel Begunkov @ 2024-11-20 23:39 UTC (permalink / raw)
  To: io-uring; +Cc: asml.silence

Signed-off-by: Pavel Begunkov <[email protected]>
---
 test/reg-wait.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/test/reg-wait.c b/test/reg-wait.c
index 544cd48..9b18ab1 100644
--- a/test/reg-wait.c
+++ b/test/reg-wait.c
@@ -23,6 +23,8 @@ static const struct io_uring_reg_wait brief_wait = {
 	.ts.tv_nsec = 1000,
 };
 
+static bool has_kernel_regions;
+
 static int test_wait_reg_offset(struct io_uring *ring,
 				 unsigned wait_nr, unsigned long offset)
 {
@@ -380,6 +382,27 @@ static int test_regions(void)
 		return T_EXIT_FAIL;
 	}
 
+	rd.flags = 0;
+	rd.user_addr = 0;
+	ret = test_try_register_region(&mr, true);
+	if (ret == -EINVAL) {
+		has_kernel_regions = false;
+		goto out;
+	}
+	if (ret) {
+		fprintf(stderr, "test_try_register_region() failed kernel alloc %i\n", ret);
+		return T_EXIT_FAIL;
+	}
+
+	has_kernel_regions = true;
+	rd.flags = 0;
+	rd.user_addr = (__u64)(unsigned long)buffer;
+	ret = test_try_register_region(&mr, true);
+	if (!ret) {
+		fprintf(stderr, "test_try_register_region() failed uptr w kernel alloc %i\n", ret);
+		return T_EXIT_FAIL;
+	}
+out:
 	munmap(buffer, page_size);
 	return 0;
 }
-- 
2.46.0


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

* [PATCH liburing 3/4] test/reg-wait: add allocation abstraction
  2024-11-20 23:39 [PATCH liburing 0/4] test kernel allocated regions Pavel Begunkov
  2024-11-20 23:39 ` [PATCH liburing 1/4] tests/reg-wait: test registering RO memory Pavel Begunkov
  2024-11-20 23:39 ` [PATCH liburing 2/4] test/reg-wait: basic test + probing of kernel regions Pavel Begunkov
@ 2024-11-20 23:39 ` Pavel Begunkov
  2024-11-20 23:39 ` [PATCH liburing 4/4] test/reg-wait: test kernel allocated regions Pavel Begunkov
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Pavel Begunkov @ 2024-11-20 23:39 UTC (permalink / raw)
  To: io-uring; +Cc: asml.silence

Signed-off-by: Pavel Begunkov <[email protected]>
---
 test/reg-wait.c | 82 +++++++++++++++++++++++++++++++++----------------
 1 file changed, 56 insertions(+), 26 deletions(-)

diff --git a/test/reg-wait.c b/test/reg-wait.c
index 9b18ab1..d59e51b 100644
--- a/test/reg-wait.c
+++ b/test/reg-wait.c
@@ -67,12 +67,6 @@ err:
 	return ret;
 }
 
-static int init_ring_with_region(struct io_uring *ring, unsigned ring_flags,
-				 struct io_uring_mem_region_reg *pr)
-{
-	return __init_ring_with_region(ring, ring_flags, pr, true);
-}
-
 static int page_size;
 static struct io_uring_reg_wait *reg;
 
@@ -407,15 +401,49 @@ out:
 	return 0;
 }
 
-static void *alloc_region_buffer(size_t size, bool huge)
+struct t_region {
+	void *ptr;
+	bool user_mem;
+	size_t size;
+};
+
+static void t_region_free(struct t_region *r)
 {
+	if (r->ptr)
+		munmap(r->ptr, r->size);
+}
+
+static int t_region_create_user(struct t_region *r,
+				struct io_uring *ring,
+				bool huge)
+{
+	struct io_uring_region_desc rd = {};
+	struct io_uring_mem_region_reg mr = {};
 	int flags = MAP_PRIVATE | MAP_ANONYMOUS;
 	void *p;
+	int ret;
 
 	if (huge)
 		flags |= MAP_HUGETLB | MAP_HUGE_2MB;
-	p = mmap(NULL, size, PROT_READ | PROT_WRITE, flags, -1, 0);
-	return p == MAP_FAILED ? NULL : p;
+
+	p = mmap(NULL, r->size, PROT_READ | PROT_WRITE, flags, -1, 0);
+	if (p == MAP_FAILED)
+		return -ENOMEM;
+
+	mr.region_uptr = (__u64)(unsigned long)&rd;
+	mr.flags = IORING_MEM_REGION_REG_WAIT_ARG;
+	rd.user_addr = (__u64)(unsigned long)p;
+	rd.flags = IORING_MEM_REGION_TYPE_USER;
+	rd.size = r->size;
+
+	ret = io_uring_register_region(ring, &mr);
+	if (ret) {
+		munmap(p, r->size);
+		return ret;
+	}
+	r->ptr = p;
+	r->user_mem = true;
+	return 0;
 }
 
 static int test_region_buffer_types(void)
@@ -423,40 +451,42 @@ static int test_region_buffer_types(void)
 	const size_t huge_size = 1024 * 1024 * 2;
 	const size_t map_sizes[] = { page_size, page_size * 2, page_size * 16,
 				     huge_size, 2 * huge_size};
-	struct io_uring_region_desc rd = {};
-	struct io_uring_mem_region_reg mr = {};
 	struct io_uring ring;
 	int sz_idx, ret;
 
-	mr.region_uptr = (__u64)(unsigned long)&rd;
-	mr.flags = IORING_MEM_REGION_REG_WAIT_ARG;
-
 	for (sz_idx = 0; sz_idx < ARRAY_SIZE(map_sizes); sz_idx++) {
 		size_t size = map_sizes[sz_idx];
-		void *buffer;
+		struct t_region r = { .size = size, };
 
-		buffer = alloc_region_buffer(size, size >= huge_size);
-		if (!buffer)
-			continue;
-
-		rd.user_addr = (__u64)(unsigned long)buffer;
-		rd.size = size;
-		rd.flags = IORING_MEM_REGION_TYPE_USER;
+		ret = io_uring_queue_init(8, &ring, IORING_SETUP_R_DISABLED);
+		if (ret) {
+			fprintf(stderr, "ring setup failed: %d\n", ret);
+			return ret;
+		}
 
-		ret = init_ring_with_region(&ring, 0, &mr);
+		ret = t_region_create_user(&r, &ring, size >= huge_size);
 		if (ret) {
-			fprintf(stderr, "init ring failed %i\n", ret);
+			io_uring_queue_exit(&ring);
+			if (ret == -ENOMEM || ret == -EINVAL)
+				continue;
+			fprintf(stderr, "t_region_create_user failed\n");
 			return 1;
 		}
 
-		ret = test_offsets(&ring, buffer, size, false);
+		ret = io_uring_enable_rings(&ring);
+		if (ret) {
+			fprintf(stderr, "io_uring_enable_rings failure %i\n", ret);
+			return ret;
+		}
+
+		ret = test_offsets(&ring, r.ptr, size, false);
 		if (ret) {
 			fprintf(stderr, "test_offsets failed, size %lu\n",
 				(unsigned long)size);
 			return 1;
 		}
 
-		munmap(buffer, size);
+		t_region_free(&r);
 		io_uring_queue_exit(&ring);
 	}
 
-- 
2.46.0


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

* [PATCH liburing 4/4] test/reg-wait: test kernel allocated regions
  2024-11-20 23:39 [PATCH liburing 0/4] test kernel allocated regions Pavel Begunkov
                   ` (2 preceding siblings ...)
  2024-11-20 23:39 ` [PATCH liburing 3/4] test/reg-wait: add allocation abstraction Pavel Begunkov
@ 2024-11-20 23:39 ` Pavel Begunkov
  2024-12-09 21:14 ` [PATCH liburing 0/4] " Pavel Begunkov
  2024-12-09 21:16 ` Jens Axboe
  5 siblings, 0 replies; 7+ messages in thread
From: Pavel Begunkov @ 2024-11-20 23:39 UTC (permalink / raw)
  To: io-uring; +Cc: asml.silence

Signed-off-by: Pavel Begunkov <[email protected]>
---
 test/reg-wait.c | 68 +++++++++++++++++++++++++++++++++++++++++--------
 1 file changed, 57 insertions(+), 11 deletions(-)

diff --git a/test/reg-wait.c b/test/reg-wait.c
index d59e51b..299fbf1 100644
--- a/test/reg-wait.c
+++ b/test/reg-wait.c
@@ -413,6 +413,31 @@ static void t_region_free(struct t_region *r)
 		munmap(r->ptr, r->size);
 }
 
+static int t_region_create_kernel(struct t_region *r,
+				  struct io_uring *ring)
+{
+	struct io_uring_region_desc rd = { .size = r->size, };
+	struct io_uring_mem_region_reg mr = {
+		.region_uptr = (__u64)(unsigned long)&rd,
+		.flags = IORING_MEM_REGION_REG_WAIT_ARG,
+	};
+	void *p;
+	int ret;
+
+	ret = io_uring_register_region(ring, &mr);
+	if (ret)
+		return ret;
+
+	p = mmap(NULL, r->size, PROT_READ | PROT_WRITE,
+		 MAP_SHARED | MAP_POPULATE, ring->ring_fd, rd.mmap_offset);
+	if (p == MAP_FAILED)
+		return -EFAULT;
+
+	r->ptr = p;
+	r->user_mem = false;
+	return 0;
+}
+
 static int t_region_create_user(struct t_region *r,
 				struct io_uring *ring,
 				bool huge)
@@ -446,17 +471,36 @@ static int t_region_create_user(struct t_region *r,
 	return 0;
 }
 
+struct test_param {
+	size_t size;
+	bool huge_page;
+	bool kern_buf;
+};
+
 static int test_region_buffer_types(void)
 {
 	const size_t huge_size = 1024 * 1024 * 2;
-	const size_t map_sizes[] = { page_size, page_size * 2, page_size * 16,
-				     huge_size, 2 * huge_size};
+	struct test_param params[] = {
+		{ .size = page_size },
+		/* forcing vmap */
+		{ .size = page_size * 2 },
+		{ .size = page_size * 16 },
+		/* huge page w/o vmap */
+		{ .size = huge_size, .huge_page = true },
+		/* huge page w/ vmap */
+		{ .size = huge_size * 2, .huge_page = true },
+		{ .size = page_size, .kern_buf = true },
+		/* likely to be a compound page */
+		{ .size = page_size * 2, .kern_buf = true },
+		{ .size = page_size * 8, .kern_buf = true },
+		/* kernel allocation + vmap */
+		{ .size = page_size * 512, .kern_buf = true },
+	};
 	struct io_uring ring;
-	int sz_idx, ret;
+	int i, ret;
 
-	for (sz_idx = 0; sz_idx < ARRAY_SIZE(map_sizes); sz_idx++) {
-		size_t size = map_sizes[sz_idx];
-		struct t_region r = { .size = size, };
+	for (i = 0; i < ARRAY_SIZE(params); i++) {
+		struct t_region r = { .size = params[i].size, };
 
 		ret = io_uring_queue_init(8, &ring, IORING_SETUP_R_DISABLED);
 		if (ret) {
@@ -464,12 +508,15 @@ static int test_region_buffer_types(void)
 			return ret;
 		}
 
-		ret = t_region_create_user(&r, &ring, size >= huge_size);
+		if (params[i].kern_buf)
+			ret = t_region_create_kernel(&r, &ring);
+		else
+			ret = t_region_create_user(&r, &ring, params[i].huge_page);
 		if (ret) {
 			io_uring_queue_exit(&ring);
 			if (ret == -ENOMEM || ret == -EINVAL)
 				continue;
-			fprintf(stderr, "t_region_create_user failed\n");
+			fprintf(stderr, "t_region_create_user failed, idx %i\n", i);
 			return 1;
 		}
 
@@ -479,10 +526,9 @@ static int test_region_buffer_types(void)
 			return ret;
 		}
 
-		ret = test_offsets(&ring, r.ptr, size, false);
+		ret = test_offsets(&ring, r.ptr, r.size, false);
 		if (ret) {
-			fprintf(stderr, "test_offsets failed, size %lu\n",
-				(unsigned long)size);
+			fprintf(stderr, "test_offsets failed, idx %i\n", i);
 			return 1;
 		}
 
-- 
2.46.0


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

* Re: [PATCH liburing 0/4] test kernel allocated regions
  2024-11-20 23:39 [PATCH liburing 0/4] test kernel allocated regions Pavel Begunkov
                   ` (3 preceding siblings ...)
  2024-11-20 23:39 ` [PATCH liburing 4/4] test/reg-wait: test kernel allocated regions Pavel Begunkov
@ 2024-12-09 21:14 ` Pavel Begunkov
  2024-12-09 21:16 ` Jens Axboe
  5 siblings, 0 replies; 7+ messages in thread
From: Pavel Begunkov @ 2024-12-09 21:14 UTC (permalink / raw)
  To: Pavel Begunkov, io-uring

On 11/20/24 23:39, Pavel Begunkov wrote:
> Patch 1 excersices one additional failure path for user provided regions,
> and the rest test kernel allocated regions.

This set should still be good to go, I've been testing with it
all along.


> Pavel Begunkov (4):
>    tests/reg-wait: test registering RO memory
>    test/reg-wait: basic test + probing of kernel regions
>    test/reg-wait: add allocation abstraction
>    test/reg-wait: test kernel allocated regions
> 
>   test/reg-wait.c | 181 +++++++++++++++++++++++++++++++++++++++---------
>   1 file changed, 147 insertions(+), 34 deletions(-)
> 

-- 
Pavel Begunkov


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

* Re: [PATCH liburing 0/4] test kernel allocated regions
  2024-11-20 23:39 [PATCH liburing 0/4] test kernel allocated regions Pavel Begunkov
                   ` (4 preceding siblings ...)
  2024-12-09 21:14 ` [PATCH liburing 0/4] " Pavel Begunkov
@ 2024-12-09 21:16 ` Jens Axboe
  5 siblings, 0 replies; 7+ messages in thread
From: Jens Axboe @ 2024-12-09 21:16 UTC (permalink / raw)
  To: io-uring, Pavel Begunkov


On Wed, 20 Nov 2024 23:39:47 +0000, Pavel Begunkov wrote:
> Patch 1 excersices one additional failure path for user provided regions,
> and the rest test kernel allocated regions.
> 
> Pavel Begunkov (4):
>   tests/reg-wait: test registering RO memory
>   test/reg-wait: basic test + probing of kernel regions
>   test/reg-wait: add allocation abstraction
>   test/reg-wait: test kernel allocated regions
> 
> [...]

Applied, thanks!

[1/4] tests/reg-wait: test registering RO memory
      commit: 67a8f570f9e14aef41c880d60edb675f4517f267
[2/4] test/reg-wait: basic test + probing of kernel regions
      commit: 30ce99006af9403ffdb84ea31223fb0c13f7612e
[3/4] test/reg-wait: add allocation abstraction
      commit: b526f2354b49acc120ff9abd9cd245ef62f07325
[4/4] test/reg-wait: test kernel allocated regions
      commit: 895b45b59e10b543f5c0b9d901d9f39da7687c07

Best regards,
-- 
Jens Axboe




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

end of thread, other threads:[~2024-12-09 21:16 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-20 23:39 [PATCH liburing 0/4] test kernel allocated regions Pavel Begunkov
2024-11-20 23:39 ` [PATCH liburing 1/4] tests/reg-wait: test registering RO memory Pavel Begunkov
2024-11-20 23:39 ` [PATCH liburing 2/4] test/reg-wait: basic test + probing of kernel regions Pavel Begunkov
2024-11-20 23:39 ` [PATCH liburing 3/4] test/reg-wait: add allocation abstraction Pavel Begunkov
2024-11-20 23:39 ` [PATCH liburing 4/4] test/reg-wait: test kernel allocated regions Pavel Begunkov
2024-12-09 21:14 ` [PATCH liburing 0/4] " Pavel Begunkov
2024-12-09 21:16 ` Jens Axboe

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