* [PATCH liburing v2 5/6] test/reg-wait: use uring_ptr_to_u64() helper to convert ptr to u64
[not found] <20250618110034.30904-1-haiyue.wang@cloudprime.ai>
` (3 preceding siblings ...)
2025-06-18 10:55 ` [PATCH liburing v2 4/6] examples/zcrx: " Haiyue Wang
@ 2025-06-18 10:55 ` Haiyue Wang
2025-06-18 10:55 ` [PATCH liburing v2 6/6] test/zcrx: " Haiyue Wang
5 siblings, 0 replies; 7+ messages in thread
From: Haiyue Wang @ 2025-06-18 10:55 UTC (permalink / raw)
To: io-uring; +Cc: Haiyue Wang
Use the helper to handle type convertions, instead of two type
convertions by hand: '(__u64) (unsigned long)'.
Signed-off-by: Haiyue Wang <haiyue.wang@cloudprime.ai>
---
test/reg-wait.c | 24 ++++++++++++------------
1 file changed, 12 insertions(+), 12 deletions(-)
diff --git a/test/reg-wait.c b/test/reg-wait.c
index 01d5e8f..af517a1 100644
--- a/test/reg-wait.c
+++ b/test/reg-wait.c
@@ -219,10 +219,10 @@ static int test_wait_arg(void)
return T_EXIT_FAIL;
}
- rd.user_addr = (__u64)(unsigned long)buffer;
+ rd.user_addr = uring_ptr_to_u64(buffer);
rd.size = page_size;
rd.flags = IORING_MEM_REGION_TYPE_USER;
- mr.region_uptr = (__u64)(unsigned long)&rd;
+ mr.region_uptr = uring_ptr_to_u64(&rd);
mr.flags = IORING_MEM_REGION_REG_WAIT_ARG;
ret = io_uring_register_region(&ring, &mr);
@@ -287,11 +287,11 @@ static int test_regions(void)
return T_EXIT_FAIL;
}
- rd.user_addr = (__u64)(unsigned long)buffer;
+ rd.user_addr = uring_ptr_to_u64(buffer);
rd.size = page_size;
rd.flags = IORING_MEM_REGION_TYPE_USER;
- mr.region_uptr = (__u64)(unsigned long)&rd;
+ mr.region_uptr = uring_ptr_to_u64(&rd);
mr.flags = IORING_MEM_REGION_REG_WAIT_ARG;
ret = test_try_register_region(&mr, true);
@@ -324,7 +324,7 @@ static int test_regions(void)
fprintf(stderr, "test_try_register_region() null uptr fail %i\n", ret);
return T_EXIT_FAIL;
}
- rd.user_addr = (__u64)(unsigned long)buffer;
+ rd.user_addr = uring_ptr_to_u64(buffer);
rd.flags = 0;
ret = test_try_register_region(&mr, true);
@@ -348,7 +348,7 @@ static int test_regions(void)
fprintf(stderr, "test_try_register_region() NULL region %i\n", ret);
return T_EXIT_FAIL;
}
- mr.region_uptr = (__u64)(unsigned long)&rd;
+ mr.region_uptr = uring_ptr_to_u64(&rd);
rd.user_addr += 16;
ret = test_try_register_region(&mr, true);
@@ -363,7 +363,7 @@ static int test_regions(void)
fprintf(stderr, "test_try_register_region() bogus uptr %i\n", ret);
return T_EXIT_FAIL;
}
- rd.user_addr = (__u64)(unsigned long)buffer;
+ rd.user_addr = uring_ptr_to_u64(buffer);
free(buffer);
buffer = mmap(NULL, page_size, PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
@@ -372,7 +372,7 @@ static int test_regions(void)
return 1;
}
- rd.user_addr = (__u64)(unsigned long)buffer;
+ rd.user_addr = uring_ptr_to_u64(buffer);
ret = test_try_register_region(&mr, true);
if (ret != -EFAULT) {
fprintf(stderr, "test_try_register_region() RO uptr %i\n", ret);
@@ -393,7 +393,7 @@ static int test_regions(void)
has_kernel_regions = true;
rd.flags = 0;
- rd.user_addr = (__u64)(unsigned long)buffer;
+ rd.user_addr = uring_ptr_to_u64(buffer);
ret = test_try_register_region(&mr, true);
if (!ret) {
fprintf(stderr, "test_try_register_region() failed uptr w kernel alloc %i\n", ret);
@@ -421,7 +421,7 @@ static int t_region_create_kernel(struct t_region *r,
{
struct io_uring_region_desc rd = { .size = r->size, };
struct io_uring_mem_region_reg mr = {
- .region_uptr = (__u64)(unsigned long)&rd,
+ .region_uptr = uring_ptr_to_u64(&rd),
.flags = IORING_MEM_REGION_REG_WAIT_ARG,
};
void *p;
@@ -458,9 +458,9 @@ static int t_region_create_user(struct t_region *r,
if (p == MAP_FAILED)
return -ENOMEM;
- mr.region_uptr = (__u64)(unsigned long)&rd;
+ mr.region_uptr = uring_ptr_to_u64(&rd);
mr.flags = IORING_MEM_REGION_REG_WAIT_ARG;
- rd.user_addr = (__u64)(unsigned long)p;
+ rd.user_addr = uring_ptr_to_u64(p);
rd.flags = IORING_MEM_REGION_TYPE_USER;
rd.size = r->size;
--
2.49.0
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH liburing v2 6/6] test/zcrx: use uring_ptr_to_u64() helper to convert ptr to u64
[not found] <20250618110034.30904-1-haiyue.wang@cloudprime.ai>
` (4 preceding siblings ...)
2025-06-18 10:55 ` [PATCH liburing v2 5/6] test/reg-wait: " Haiyue Wang
@ 2025-06-18 10:55 ` Haiyue Wang
5 siblings, 0 replies; 7+ messages in thread
From: Haiyue Wang @ 2025-06-18 10:55 UTC (permalink / raw)
To: io-uring; +Cc: Haiyue Wang
Use the helper to handle type convertions, instead of two type
convertions by hand: '(__u64) (unsigned long)'.
Signed-off-by: Haiyue Wang <haiyue.wang@cloudprime.ai>
---
test/zcrx.c | 44 ++++++++++++++++++++++----------------------
1 file changed, 22 insertions(+), 22 deletions(-)
diff --git a/test/zcrx.c b/test/zcrx.c
index 61c984d..572e118 100644
--- a/test/zcrx.c
+++ b/test/zcrx.c
@@ -43,7 +43,7 @@ static char str[] = "iv5t4dl500w7wsrf14fsuq8thptto0z7i2q62z1p8dwrv5u4kaxpqhm2rb7
static int probe_zcrx(void *area)
{
struct io_uring_zcrx_area_reg area_reg = {
- .addr = (__u64)(unsigned long)area,
+ .addr = uring_ptr_to_u64(area),
.len = AREA_SZ,
.flags = 0,
};
@@ -51,7 +51,7 @@ static int probe_zcrx(void *area)
.if_idx = ifidx,
.if_rxq = rxq,
.rq_entries = RQ_ENTRIES,
- .area_ptr = (__u64)(unsigned long)&area_reg,
+ .area_ptr = uring_ptr_to_u64(&area_reg),
};
struct io_uring ring;
int ret;
@@ -99,7 +99,7 @@ static int test_invalid_if(void *area)
{
int ret;
struct io_uring_zcrx_area_reg area_reg = {
- .addr = (__u64)(unsigned long)area,
+ .addr = uring_ptr_to_u64(area),
.len = AREA_SZ,
.flags = 0,
};
@@ -107,7 +107,7 @@ static int test_invalid_if(void *area)
.if_idx = -1,
.if_rxq = rxq,
.rq_entries = RQ_ENTRIES,
- .area_ptr = (__u64)(unsigned long)&area_reg,
+ .area_ptr = uring_ptr_to_u64(&area_reg),
};
ret = try_register_ifq(®);
@@ -131,7 +131,7 @@ static int test_invalid_ifq_collision(void *area)
{
struct io_uring ring, ring2;
struct io_uring_zcrx_area_reg area_reg = {
- .addr = (__u64)(unsigned long)area,
+ .addr = uring_ptr_to_u64(area),
.len = AREA_SZ,
.flags = 0,
};
@@ -139,7 +139,7 @@ static int test_invalid_ifq_collision(void *area)
.if_idx = ifidx,
.if_rxq = rxq,
.rq_entries = RQ_ENTRIES,
- .area_ptr = (__u64)(unsigned long)&area_reg,
+ .area_ptr = uring_ptr_to_u64(&area_reg),
};
int ret;
@@ -182,7 +182,7 @@ static int test_rq_setup(void *area)
{
int ret;
struct io_uring_zcrx_area_reg area_reg = {
- .addr = (__u64)(unsigned long)area,
+ .addr = uring_ptr_to_u64(area),
.len = AREA_SZ,
.flags = 0,
};
@@ -191,7 +191,7 @@ static int test_rq_setup(void *area)
.if_idx = ifidx,
.if_rxq = rxq,
.rq_entries = 0,
- .area_ptr = (__u64)(unsigned long)&area_reg,
+ .area_ptr = uring_ptr_to_u64(&area_reg),
};
ret = try_register_ifq(®);
@@ -232,7 +232,7 @@ static int test_null_area_reg_struct(void)
.if_idx = ifidx,
.if_rxq = rxq,
.rq_entries = RQ_ENTRIES,
- .area_ptr = (__u64)(unsigned long)0,
+ .area_ptr = uring_ptr_to_u64(0),
};
ret = try_register_ifq(®);
@@ -244,7 +244,7 @@ static int test_null_area(void)
int ret;
struct io_uring_zcrx_area_reg area_reg = {
- .addr = (__u64)(unsigned long)0,
+ .addr = uring_ptr_to_u64(0),
.len = AREA_SZ,
.flags = 0,
};
@@ -253,7 +253,7 @@ static int test_null_area(void)
.if_idx = ifidx,
.if_rxq = rxq,
.rq_entries = RQ_ENTRIES,
- .area_ptr = (__u64)(unsigned long)&area_reg,
+ .area_ptr = uring_ptr_to_u64(&area_reg),
};
ret = try_register_ifq(®);
@@ -264,7 +264,7 @@ static int test_misaligned_area(void *area)
{
int ret;
struct io_uring_zcrx_area_reg area_reg = {
- .addr = (__u64)(unsigned long)(area + 1),
+ .addr = uring_ptr_to_u64(area + 1),
.len = AREA_SZ,
.flags = 0,
};
@@ -273,13 +273,13 @@ static int test_misaligned_area(void *area)
.if_idx = ifidx,
.if_rxq = rxq,
.rq_entries = RQ_ENTRIES,
- .area_ptr = (__u64)(unsigned long)&area_reg,
+ .area_ptr = uring_ptr_to_u64(&area_reg),
};
if (!try_register_ifq(®))
return T_EXIT_FAIL;
- area_reg.addr = (__u64)(unsigned long)area;
+ area_reg.addr = uring_ptr_to_u64(area);
area_reg.len = AREA_SZ - 1;
ret = try_register_ifq(®);
return ret ? T_EXIT_PASS : T_EXIT_FAIL;
@@ -289,7 +289,7 @@ static int test_larger_than_alloc_area(void *area)
{
int ret;
struct io_uring_zcrx_area_reg area_reg = {
- .addr = (__u64)(unsigned long)area,
+ .addr = uring_ptr_to_u64(area),
.len = AREA_SZ + 4096,
.flags = 0,
};
@@ -298,7 +298,7 @@ static int test_larger_than_alloc_area(void *area)
.if_idx = ifidx,
.if_rxq = rxq,
.rq_entries = RQ_ENTRIES,
- .area_ptr = (__u64)(unsigned long)&area_reg,
+ .area_ptr = uring_ptr_to_u64(&area_reg),
};
ret = try_register_ifq(®);
@@ -315,7 +315,7 @@ static int test_area_access(void)
.if_idx = ifidx,
.if_rxq = rxq,
.rq_entries = RQ_ENTRIES,
- .area_ptr = (__u64)(unsigned long)&area_reg,
+ .area_ptr = uring_ptr_to_u64(&area_reg),
};
int i, ret;
void *area;
@@ -331,7 +331,7 @@ static int test_area_access(void)
return T_EXIT_FAIL;
}
- area_reg.addr = (__u64)(unsigned long)area;
+ area_reg.addr = uring_ptr_to_u64(area);
ret = try_register_ifq(®);
if (ret != -EFAULT) {
@@ -348,7 +348,7 @@ static int test_area_access(void)
static int create_ring_with_ifq(struct io_uring *ring, void *area, __u32 *id)
{
struct io_uring_zcrx_area_reg area_reg = {
- .addr = (__u64)(unsigned long)area,
+ .addr = uring_ptr_to_u64(area),
.len = AREA_SZ,
.flags = 0,
};
@@ -356,7 +356,7 @@ static int create_ring_with_ifq(struct io_uring *ring, void *area, __u32 *id)
.if_idx = ifidx,
.if_rxq = rxq,
.rq_entries = RQ_ENTRIES,
- .area_ptr = (__u64)(unsigned long)&area_reg,
+ .area_ptr = uring_ptr_to_u64(&area_reg),
};
int ret;
@@ -653,7 +653,7 @@ static void *recv_fn(void *data)
struct io_uring ring;
int ret, sock;
struct io_uring_zcrx_area_reg area_reg = {
- .addr = (__u64)(unsigned long)rd->area,
+ .addr = uring_ptr_to_u64(rd->area),
.len = AREA_SZ,
.flags = 0,
};
@@ -661,7 +661,7 @@ static void *recv_fn(void *data)
.if_idx = ifidx,
.if_rxq = rxq,
.rq_entries = RQ_ENTRIES,
- .area_ptr = (__u64)(unsigned long)&area_reg,
+ .area_ptr = uring_ptr_to_u64(&area_reg),
};
p.flags = RING_FLAGS;
--
2.49.0
^ permalink raw reply related [flat|nested] 7+ messages in thread