* [PATCH liburing 1/8] test/reg-wait: fix test_regions
2024-11-16 21:27 [PATCH liburing 0/8] region test fixes + improvements Pavel Begunkov
@ 2024-11-16 21:27 ` Pavel Begunkov
2024-11-16 21:27 ` [PATCH liburing 2/8] test/reg-wait: pass right timeout indexes Pavel Begunkov
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Pavel Begunkov @ 2024-11-16 21:27 UTC (permalink / raw)
To: io-uring; +Cc: asml.silence
Regions for CQ wait arguments are registered to disabled rings, and
test_try_register_region() doesn't do it right. While at it kill the
extra argument as it doesn't do anything useful.
Signed-off-by: Pavel Begunkov <[email protected]>
---
test/reg-wait.c | 43 +++++++++++++++++++------------------------
1 file changed, 19 insertions(+), 24 deletions(-)
diff --git a/test/reg-wait.c b/test/reg-wait.c
index aef4546..eef10e0 100644
--- a/test/reg-wait.c
+++ b/test/reg-wait.c
@@ -222,7 +222,7 @@ err:
}
static int test_try_register_region(struct io_uring_mem_region_reg *pr,
- bool disabled, bool reenable)
+ bool disabled)
{
struct io_uring ring;
int flags = 0;
@@ -237,15 +237,16 @@ static int test_try_register_region(struct io_uring_mem_region_reg *pr,
return 1;
}
- if (reenable) {
+ ret = io_uring_register_region(&ring, pr);
+ if (ret)
+ goto err;
+
+ if (disabled) {
ret = io_uring_enable_rings(&ring);
- if (ret) {
+ if (ret)
fprintf(stderr, "io_uring_enable_rings failure %i\n", ret);
- return 1;
- }
}
-
- ret = io_uring_register_region(&ring, pr);
+err:
io_uring_queue_exit(&ring);
return ret;
}
@@ -270,28 +271,22 @@ static int test_regions(void)
mr.region_uptr = (__u64)(unsigned long)&rd;
mr.flags = IORING_MEM_REGION_REG_WAIT_ARG;
- ret = test_try_register_region(&mr, true, false);
+ ret = test_try_register_region(&mr, true);
if (ret == -EINVAL)
return T_EXIT_SKIP;
if (ret) {
- fprintf(stderr, "test_try_register_region(true, false) fail %i\n", ret);
- return T_EXIT_FAIL;
- }
-
- ret = test_try_register_region(&mr, false, false);
- if (ret != -EINVAL) {
- fprintf(stderr, "test_try_register_region(false, false) fail %i\n", ret);
+ fprintf(stderr, "region: register normal fail %i\n", ret);
return T_EXIT_FAIL;
}
- ret = test_try_register_region(&mr, true, true);
+ ret = test_try_register_region(&mr, false);
if (ret != -EINVAL) {
- fprintf(stderr, "test_try_register_region(true, true) fail %i\n", ret);
+ fprintf(stderr, "region: register with !R_DISABLED fail %i\n", ret);
return T_EXIT_FAIL;
}
rd.size = 4096 * 4;
- ret = test_try_register_region(&mr, true, false);
+ ret = test_try_register_region(&mr, true);
if (ret) {
fprintf(stderr, "test_try_register_region() 16KB fail %i\n", ret);
return T_EXIT_FAIL;
@@ -299,7 +294,7 @@ static int test_regions(void)
rd.size = 4096;
rd.user_addr = 0;
- ret = test_try_register_region(&mr, true, false);
+ ret = test_try_register_region(&mr, true);
if (ret != -EFAULT) {
fprintf(stderr, "test_try_register_region() null uptr fail %i\n", ret);
return T_EXIT_FAIL;
@@ -307,7 +302,7 @@ static int test_regions(void)
rd.user_addr = (__u64)(unsigned long)buffer;
rd.flags = 0;
- ret = test_try_register_region(&mr, true, false);
+ ret = test_try_register_region(&mr, true);
if (!ret) {
fprintf(stderr, "test_try_register_region() kernel alloc with uptr fail %i\n", ret);
return T_EXIT_FAIL;
@@ -315,7 +310,7 @@ static int test_regions(void)
rd.flags = IORING_MEM_REGION_TYPE_USER;
rd.size = 0;
- ret = test_try_register_region(&mr, true, false);
+ ret = test_try_register_region(&mr, true);
if (!ret) {
fprintf(stderr, "test_try_register_region() 0-size fail %i\n", ret);
return T_EXIT_FAIL;
@@ -323,7 +318,7 @@ static int test_regions(void)
rd.size = 4096;
mr.region_uptr = 0;
- ret = test_try_register_region(&mr, true, false);
+ ret = test_try_register_region(&mr, true);
if (!ret) {
fprintf(stderr, "test_try_register_region() NULL region %i\n", ret);
return T_EXIT_FAIL;
@@ -331,14 +326,14 @@ static int test_regions(void)
mr.region_uptr = (__u64)(unsigned long)&rd;
rd.user_addr += 16;
- ret = test_try_register_region(&mr, true, false);
+ ret = test_try_register_region(&mr, true);
if (!ret) {
fprintf(stderr, "test_try_register_region() misaligned region %i\n", ret);
return T_EXIT_FAIL;
}
rd.user_addr = 0x1000;
- ret = test_try_register_region(&mr, true, false);
+ ret = test_try_register_region(&mr, true);
if (!ret) {
fprintf(stderr, "test_try_register_region() bogus uptr %i\n", ret);
return T_EXIT_FAIL;
--
2.46.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH liburing 2/8] test/reg-wait: pass right timeout indexes
2024-11-16 21:27 [PATCH liburing 0/8] region test fixes + improvements Pavel Begunkov
2024-11-16 21:27 ` [PATCH liburing 1/8] test/reg-wait: fix test_regions Pavel Begunkov
@ 2024-11-16 21:27 ` Pavel Begunkov
2024-11-16 21:27 ` [PATCH liburing 3/8] test/reg-wait: use queried page_size Pavel Begunkov
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Pavel Begunkov @ 2024-11-16 21:27 UTC (permalink / raw)
To: io-uring; +Cc: asml.silence
Signed-off-by: Pavel Begunkov <[email protected]>
---
test/reg-wait.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/test/reg-wait.c b/test/reg-wait.c
index eef10e0..ec90019 100644
--- a/test/reg-wait.c
+++ b/test/reg-wait.c
@@ -72,10 +72,11 @@ static int test_offsets(struct io_uring *ring)
rw = reg + max_index;
memset(rw, 0, sizeof(*rw));
+ rw->flags = IORING_REG_WAIT_TS;
rw->ts.tv_sec = 0;
rw->ts.tv_nsec = 1000;
- ret = io_uring_submit_and_wait_reg(ring, &cqe, 1, 0);
+ ret = io_uring_submit_and_wait_reg(ring, &cqe, 1, max_index);
if (ret != -EFAULT) {
fprintf(stderr, "max+1 index failed: %d\n", ret);
return T_EXIT_FAIL;
--
2.46.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH liburing 3/8] test/reg-wait: use queried page_size
2024-11-16 21:27 [PATCH liburing 0/8] region test fixes + improvements Pavel Begunkov
2024-11-16 21:27 ` [PATCH liburing 1/8] test/reg-wait: fix test_regions Pavel Begunkov
2024-11-16 21:27 ` [PATCH liburing 2/8] test/reg-wait: pass right timeout indexes Pavel Begunkov
@ 2024-11-16 21:27 ` Pavel Begunkov
2024-11-16 21:27 ` [PATCH liburing 4/8] test/reg-wait: skip when R_DISABLED is not supported Pavel Begunkov
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Pavel Begunkov @ 2024-11-16 21:27 UTC (permalink / raw)
To: io-uring; +Cc: asml.silence
Signed-off-by: Pavel Begunkov <[email protected]>
---
test/reg-wait.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/test/reg-wait.c b/test/reg-wait.c
index ec90019..6cf47bf 100644
--- a/test/reg-wait.c
+++ b/test/reg-wait.c
@@ -101,7 +101,7 @@ static int test_offsets(struct io_uring *ring)
return T_EXIT_FAIL;
}
- offset = 4096 - sizeof(long);
+ offset = page_size - sizeof(long);
rw = (void *)reg + offset;
memset(rw, 0, sizeof(*rw));
rw->flags = IORING_REG_WAIT_TS;
@@ -259,14 +259,14 @@ static int test_regions(void)
void *buffer;
int ret;
- buffer = aligned_alloc(4096, 4096 * 4);
+ buffer = aligned_alloc(page_size, page_size * 4);
if (!buffer) {
fprintf(stderr, "allocation failed\n");
return T_EXIT_FAIL;
}
rd.user_addr = (__u64)(unsigned long)buffer;
- rd.size = 4096;
+ rd.size = page_size;
rd.flags = IORING_MEM_REGION_TYPE_USER;
mr.region_uptr = (__u64)(unsigned long)&rd;
@@ -286,13 +286,13 @@ static int test_regions(void)
return T_EXIT_FAIL;
}
- rd.size = 4096 * 4;
+ rd.size = page_size * 4;
ret = test_try_register_region(&mr, true);
if (ret) {
fprintf(stderr, "test_try_register_region() 16KB fail %i\n", ret);
return T_EXIT_FAIL;
}
- rd.size = 4096;
+ rd.size = page_size;
rd.user_addr = 0;
ret = test_try_register_region(&mr, true);
@@ -316,7 +316,7 @@ static int test_regions(void)
fprintf(stderr, "test_try_register_region() 0-size fail %i\n", ret);
return T_EXIT_FAIL;
}
- rd.size = 4096;
+ rd.size = page_size;
mr.region_uptr = 0;
ret = test_try_register_region(&mr, true);
--
2.46.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH liburing 4/8] test/reg-wait: skip when R_DISABLED is not supported
2024-11-16 21:27 [PATCH liburing 0/8] region test fixes + improvements Pavel Begunkov
` (2 preceding siblings ...)
2024-11-16 21:27 ` [PATCH liburing 3/8] test/reg-wait: use queried page_size Pavel Begunkov
@ 2024-11-16 21:27 ` Pavel Begunkov
2024-11-16 21:27 ` [PATCH liburing 5/8] test/reg-wait: dedup regwait init Pavel Begunkov
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Pavel Begunkov @ 2024-11-16 21:27 UTC (permalink / raw)
To: io-uring; +Cc: asml.silence
Signed-off-by: Pavel Begunkov <[email protected]>
---
test/reg-wait.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/test/reg-wait.c b/test/reg-wait.c
index 6cf47bf..c4e5863 100644
--- a/test/reg-wait.c
+++ b/test/reg-wait.c
@@ -234,8 +234,9 @@ static int test_try_register_region(struct io_uring_mem_region_reg *pr,
ret = io_uring_queue_init(8, &ring, flags);
if (ret) {
- fprintf(stderr, "ring setup failed: %d\n", ret);
- return 1;
+ if (ret != -EINVAL)
+ fprintf(stderr, "ring setup failed: %d\n", ret);
+ return ret;
}
ret = io_uring_register_region(&ring, pr);
--
2.46.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH liburing 5/8] test/reg-wait: dedup regwait init
2024-11-16 21:27 [PATCH liburing 0/8] region test fixes + improvements Pavel Begunkov
` (3 preceding siblings ...)
2024-11-16 21:27 ` [PATCH liburing 4/8] test/reg-wait: skip when R_DISABLED is not supported Pavel Begunkov
@ 2024-11-16 21:27 ` Pavel Begunkov
2024-11-16 21:27 ` [PATCH liburing 6/8] test/reg-wait: parameterise test_offsets Pavel Begunkov
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Pavel Begunkov @ 2024-11-16 21:27 UTC (permalink / raw)
To: io-uring; +Cc: asml.silence
Signed-off-by: Pavel Begunkov <[email protected]>
---
test/reg-wait.c | 30 ++++++++++--------------------
1 file changed, 10 insertions(+), 20 deletions(-)
diff --git a/test/reg-wait.c b/test/reg-wait.c
index c4e5863..10ab3a2 100644
--- a/test/reg-wait.c
+++ b/test/reg-wait.c
@@ -15,6 +15,12 @@
#include "test.h"
#include "../src/syscall.h"
+static const struct io_uring_reg_wait brief_wait = {
+ .flags = IORING_REG_WAIT_TS,
+ .ts.tv_sec = 0,
+ .ts.tv_nsec = 1000,
+};
+
static int test_wait_reg_offset(struct io_uring *ring,
unsigned wait_nr, unsigned long offset)
{
@@ -71,11 +77,7 @@ static int test_offsets(struct io_uring *ring)
int ret;
rw = reg + max_index;
- memset(rw, 0, sizeof(*rw));
- rw->flags = IORING_REG_WAIT_TS;
- rw->ts.tv_sec = 0;
- rw->ts.tv_nsec = 1000;
-
+ memcpy(rw, &brief_wait, sizeof(brief_wait));
ret = io_uring_submit_and_wait_reg(ring, &cqe, 1, max_index);
if (ret != -EFAULT) {
fprintf(stderr, "max+1 index failed: %d\n", ret);
@@ -83,11 +85,7 @@ static int test_offsets(struct io_uring *ring)
}
rw = reg + max_index - 1;
- memset(rw, 0, sizeof(*rw));
- rw->flags = IORING_REG_WAIT_TS;
- rw->ts.tv_sec = 0;
- rw->ts.tv_nsec = 1000;
-
+ memcpy(rw, &brief_wait, sizeof(brief_wait));
ret = io_uring_submit_and_wait_reg(ring, &cqe, 1, max_index - 1);
if (ret != -ETIME) {
fprintf(stderr, "last index failed: %d\n", ret);
@@ -103,11 +101,7 @@ static int test_offsets(struct io_uring *ring)
offset = page_size - sizeof(long);
rw = (void *)reg + offset;
- memset(rw, 0, sizeof(*rw));
- rw->flags = IORING_REG_WAIT_TS;
- rw->ts.tv_sec = 0;
- rw->ts.tv_nsec = 1000;
-
+ memcpy(rw, &brief_wait, sizeof(brief_wait));
ret = test_wait_reg_offset(ring, 1, offset);
if (ret != -EFAULT) {
fprintf(stderr, "OOB offset failed: %d\n", ret);
@@ -116,11 +110,7 @@ static int test_offsets(struct io_uring *ring)
offset = 1;
rw = (void *)reg + offset;
- memset(rw, 0, sizeof(*rw));
- rw->flags = IORING_REG_WAIT_TS;
- rw->ts.tv_sec = 0;
- rw->ts.tv_nsec = 1000;
-
+ memcpy(rw, &brief_wait, sizeof(brief_wait));
/* undefined behaviour, check the kernel doesn't crash */
(void)test_wait_reg_offset(ring, 1, offset);
--
2.46.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH liburing 6/8] test/reg-wait: parameterise test_offsets
2024-11-16 21:27 [PATCH liburing 0/8] region test fixes + improvements Pavel Begunkov
` (4 preceding siblings ...)
2024-11-16 21:27 ` [PATCH liburing 5/8] test/reg-wait: dedup regwait init Pavel Begunkov
@ 2024-11-16 21:27 ` Pavel Begunkov
2024-11-16 21:27 ` [PATCH liburing 7/8] test/reg-wait: add registration helper Pavel Begunkov
` (2 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Pavel Begunkov @ 2024-11-16 21:27 UTC (permalink / raw)
To: io-uring; +Cc: asml.silence
Signed-off-by: Pavel Begunkov <[email protected]>
---
test/reg-wait.c | 24 +++++++++++++++---------
1 file changed, 15 insertions(+), 9 deletions(-)
diff --git a/test/reg-wait.c b/test/reg-wait.c
index 10ab3a2..ffe4c1d 100644
--- a/test/reg-wait.c
+++ b/test/reg-wait.c
@@ -68,23 +68,27 @@ static int test_invalid_sig(struct io_uring *ring)
return T_EXIT_PASS;
}
-static int test_offsets(struct io_uring *ring)
+static int test_offsets(struct io_uring *ring, struct io_uring_reg_wait *base,
+ size_t size, bool overallocated)
{
struct io_uring_cqe *cqe;
- int max_index = page_size / sizeof(struct io_uring_reg_wait);
+ int max_index = size / sizeof(struct io_uring_reg_wait);
struct io_uring_reg_wait *rw;
unsigned long offset;
+ int copy_size;
int ret;
- rw = reg + max_index;
- memcpy(rw, &brief_wait, sizeof(brief_wait));
+ if (overallocated) {
+ rw = base + max_index;
+ memcpy(rw, &brief_wait, sizeof(brief_wait));
+ }
ret = io_uring_submit_and_wait_reg(ring, &cqe, 1, max_index);
if (ret != -EFAULT) {
fprintf(stderr, "max+1 index failed: %d\n", ret);
return T_EXIT_FAIL;
}
- rw = reg + max_index - 1;
+ rw = base + max_index - 1;
memcpy(rw, &brief_wait, sizeof(brief_wait));
ret = io_uring_submit_and_wait_reg(ring, &cqe, 1, max_index - 1);
if (ret != -ETIME) {
@@ -100,8 +104,10 @@ static int test_offsets(struct io_uring *ring)
}
offset = page_size - sizeof(long);
- rw = (void *)reg + offset;
- memcpy(rw, &brief_wait, sizeof(brief_wait));
+ rw = (void *)base + offset;
+ copy_size = overallocated ? sizeof(brief_wait) : sizeof(long);
+ memcpy(rw, &brief_wait, copy_size);
+
ret = test_wait_reg_offset(ring, 1, offset);
if (ret != -EFAULT) {
fprintf(stderr, "OOB offset failed: %d\n", ret);
@@ -109,7 +115,7 @@ static int test_offsets(struct io_uring *ring)
}
offset = 1;
- rw = (void *)reg + offset;
+ rw = (void *)base + offset;
memcpy(rw, &brief_wait, sizeof(brief_wait));
/* undefined behaviour, check the kernel doesn't crash */
(void)test_wait_reg_offset(ring, 1, offset);
@@ -201,7 +207,7 @@ static int test_wait_arg(void)
goto err;
}
- ret = test_offsets(&ring);
+ ret = test_offsets(&ring, buffer, page_size, true);
if (ret == T_EXIT_FAIL) {
fprintf(stderr, "test_offsets failed\n");
goto err;
--
2.46.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH liburing 7/8] test/reg-wait: add registration helper
2024-11-16 21:27 [PATCH liburing 0/8] region test fixes + improvements Pavel Begunkov
` (5 preceding siblings ...)
2024-11-16 21:27 ` [PATCH liburing 6/8] test/reg-wait: parameterise test_offsets Pavel Begunkov
@ 2024-11-16 21:27 ` Pavel Begunkov
2024-11-16 21:27 ` [PATCH liburing 8/8] test/reg-wait: test various sized regions Pavel Begunkov
2024-11-17 16:03 ` [PATCH liburing 0/8] region test fixes + improvements Jens Axboe
8 siblings, 0 replies; 10+ messages in thread
From: Pavel Begunkov @ 2024-11-16 21:27 UTC (permalink / raw)
To: io-uring; +Cc: asml.silence
Signed-off-by: Pavel Begunkov <[email protected]>
---
test/reg-wait.c | 56 ++++++++++++++++++++++++++++++-------------------
1 file changed, 34 insertions(+), 22 deletions(-)
diff --git a/test/reg-wait.c b/test/reg-wait.c
index ffe4c1d..559228f 100644
--- a/test/reg-wait.c
+++ b/test/reg-wait.c
@@ -32,6 +32,37 @@ static int test_wait_reg_offset(struct io_uring *ring,
sizeof(struct io_uring_reg_wait));
}
+static int __init_ring_with_region(struct io_uring *ring, unsigned ring_flags,
+ struct io_uring_mem_region_reg *pr,
+ bool disabled)
+{
+ int flags = disabled ? IORING_SETUP_R_DISABLED : 0;
+ int ret;
+
+ ret = io_uring_queue_init(8, ring, flags);
+ if (ret) {
+ if (ret != -EINVAL)
+ fprintf(stderr, "ring setup failed: %d\n", ret);
+ return ret;
+ }
+
+ ret = io_uring_register_region(ring, pr);
+ if (ret)
+ goto err;
+
+ if (disabled) {
+ ret = io_uring_enable_rings(ring);
+ if (ret) {
+ fprintf(stderr, "io_uring_enable_rings failure %i\n", ret);
+ goto err;
+ }
+ }
+ return 0;
+err:
+ io_uring_queue_exit(ring);
+ return ret;
+}
+
static int page_size;
static struct io_uring_reg_wait *reg;
@@ -222,30 +253,11 @@ static int test_try_register_region(struct io_uring_mem_region_reg *pr,
bool disabled)
{
struct io_uring ring;
- int flags = 0;
int ret;
- if (disabled)
- flags = IORING_SETUP_R_DISABLED;
-
- ret = io_uring_queue_init(8, &ring, flags);
- if (ret) {
- if (ret != -EINVAL)
- fprintf(stderr, "ring setup failed: %d\n", ret);
- return ret;
- }
-
- ret = io_uring_register_region(&ring, pr);
- if (ret)
- goto err;
-
- if (disabled) {
- ret = io_uring_enable_rings(&ring);
- if (ret)
- fprintf(stderr, "io_uring_enable_rings failure %i\n", ret);
- }
-err:
- io_uring_queue_exit(&ring);
+ ret = __init_ring_with_region(&ring, 0, pr, disabled);
+ if (!ret)
+ io_uring_queue_exit(&ring);
return ret;
}
--
2.46.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH liburing 8/8] test/reg-wait: test various sized regions
2024-11-16 21:27 [PATCH liburing 0/8] region test fixes + improvements Pavel Begunkov
` (6 preceding siblings ...)
2024-11-16 21:27 ` [PATCH liburing 7/8] test/reg-wait: add registration helper Pavel Begunkov
@ 2024-11-16 21:27 ` Pavel Begunkov
2024-11-17 16:03 ` [PATCH liburing 0/8] region test fixes + improvements Jens Axboe
8 siblings, 0 replies; 10+ messages in thread
From: Pavel Begunkov @ 2024-11-16 21:27 UTC (permalink / raw)
To: io-uring; +Cc: asml.silence
Signed-off-by: Pavel Begunkov <[email protected]>
---
test/reg-wait.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 80 insertions(+), 1 deletion(-)
diff --git a/test/reg-wait.c b/test/reg-wait.c
index 559228f..b7c823a 100644
--- a/test/reg-wait.c
+++ b/test/reg-wait.c
@@ -9,6 +9,8 @@
#include <string.h>
#include <fcntl.h>
#include <sys/time.h>
+#include <sys/mman.h>
+#include <linux/mman.h>
#include "liburing.h"
#include "helpers.h"
@@ -63,6 +65,12 @@ 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;
@@ -109,6 +117,14 @@ static int test_offsets(struct io_uring *ring, struct io_uring_reg_wait *base,
int copy_size;
int ret;
+ rw = base;
+ memcpy(rw, &brief_wait, sizeof(brief_wait));
+ ret = io_uring_submit_and_wait_reg(ring, &cqe, 1, 0);
+ if (ret != -ETIME) {
+ fprintf(stderr, "0 index failed: %d\n", ret);
+ return T_EXIT_FAIL;
+ }
+
if (overallocated) {
rw = base + max_index;
memcpy(rw, &brief_wait, sizeof(brief_wait));
@@ -134,7 +150,7 @@ static int test_offsets(struct io_uring *ring, struct io_uring_reg_wait *base,
return T_EXIT_FAIL;
}
- offset = page_size - sizeof(long);
+ offset = size - sizeof(long);
rw = (void *)base + offset;
copy_size = overallocated ? sizeof(brief_wait) : sizeof(long);
memcpy(rw, &brief_wait, copy_size);
@@ -354,6 +370,62 @@ static int test_regions(void)
return 0;
}
+static void *alloc_region_buffer(size_t size, bool huge)
+{
+ int flags = MAP_PRIVATE | MAP_ANONYMOUS;
+ void *p;
+
+ 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;
+}
+
+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;
+
+ 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 = init_ring_with_region(&ring, 0, &mr);
+ if (ret) {
+ fprintf(stderr, "init ring failed %i\n", ret);
+ return 1;
+ }
+
+ ret = test_offsets(&ring, buffer, size, false);
+ if (ret) {
+ fprintf(stderr, "test_offsets failed, size %lu\n",
+ (unsigned long)size);
+ return 1;
+ }
+
+ munmap(buffer, size);
+ io_uring_queue_exit(&ring);
+ }
+
+ return 0;
+}
+
int main(int argc, char *argv[])
{
int ret;
@@ -381,5 +453,12 @@ int main(int argc, char *argv[])
fprintf(stderr, "test_wait_arg failed\n");
return 1;
}
+
+ ret = test_region_buffer_types();
+ if (ret == T_EXIT_FAIL) {
+ fprintf(stderr, "test_region_buffer_types failed\n");
+ return 1;
+ }
+
return 0;
}
--
2.46.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH liburing 0/8] region test fixes + improvements
2024-11-16 21:27 [PATCH liburing 0/8] region test fixes + improvements Pavel Begunkov
` (7 preceding siblings ...)
2024-11-16 21:27 ` [PATCH liburing 8/8] test/reg-wait: test various sized regions Pavel Begunkov
@ 2024-11-17 16:03 ` Jens Axboe
8 siblings, 0 replies; 10+ messages in thread
From: Jens Axboe @ 2024-11-17 16:03 UTC (permalink / raw)
To: io-uring, Pavel Begunkov
On Sat, 16 Nov 2024 21:27:40 +0000, Pavel Begunkov wrote:
> Some tests are effectively ignored because of bugs, fix it. While
> at it, improve it a bit and add tests for different region sizes.
> Not very improtant for now but it'll be once the kernel has huge
> page and other optimisations.
>
> Pavel Begunkov (8):
> test/reg-wait: fix test_regions
> test/reg-wait: pass right timeout indexes
> test/reg-wait: use queried page_size
> test/reg-wait: skip when R_DISABLED is not supported
> test/reg-wait: dedup regwait init
> test/reg-wait: parameterise test_offsets
> test/reg-wait: add registration helper
> test/reg-wait: test various sized regions
>
> [...]
Applied, thanks!
[1/8] test/reg-wait: fix test_regions
commit: 2da94b9c3f16906e8b85c6a3bdbd842cedcba716
[2/8] test/reg-wait: pass right timeout indexes
commit: 2a11ca289f26d8fb624534259f1fb75b94971e21
[3/8] test/reg-wait: use queried page_size
commit: c4e792a8cb5836673d9654742cfb25d881958ba5
[4/8] test/reg-wait: skip when R_DISABLED is not supported
commit: 4a1a872388defba685596709911ebc06530146a3
[5/8] test/reg-wait: dedup regwait init
commit: 2f002f396e575f4ed2a8afbe2e10fea006773e00
[6/8] test/reg-wait: parameterise test_offsets
commit: a2c742d8cb8ddd97348ed44f4cdd6f18f781aa8a
[7/8] test/reg-wait: add registration helper
commit: 414c6a8f9c63d702f5c248d728693e027802b9af
[8/8] test/reg-wait: test various sized regions
commit: f113218015556f41f3f06a6ffc07b194dfbf209c
Best regards,
--
Jens Axboe
^ permalink raw reply [flat|nested] 10+ messages in thread