* [PATCH liburing v1 1/6] Add uring_ptr_to_u64() helper
[not found] <20250618075056.142118-1-haiyue.wang@cloudprime.ai>
@ 2025-06-18 7:49 ` Haiyue Wang
2025-06-18 7:49 ` [PATCH liburing v1 2/6] liburing: use uring_ptr_to_u64() helper to convert ptr to u64 Haiyue Wang
` (4 subsequent siblings)
5 siblings, 0 replies; 6+ messages in thread
From: Haiyue Wang @ 2025-06-18 7:49 UTC (permalink / raw)
To: io-uring; +Cc: Haiyue Wang
Add this helper to convert *ptr type to u64 type easily.
Signed-off-by: Haiyue Wang <haiyue.wang@cloudprime.ai>
---
src/include/liburing.h | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/src/include/liburing.h b/src/include/liburing.h
index 96eeed3..6d87248 100644
--- a/src/include/liburing.h
+++ b/src/include/liburing.h
@@ -32,6 +32,11 @@
#define IOURINGINLINE static inline
#endif
+IOURINGINLINE __u64 uring_ptr_to_u64(const void *ptr)
+{
+ return (__u64) (unsigned long) ptr;
+}
+
#ifdef __alpha__
/*
* alpha and mips are the exceptions, all other architectures have
--
2.49.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH liburing v1 2/6] liburing: use uring_ptr_to_u64() helper to convert ptr to u64
[not found] <20250618075056.142118-1-haiyue.wang@cloudprime.ai>
2025-06-18 7:49 ` [PATCH liburing v1 1/6] Add uring_ptr_to_u64() helper Haiyue Wang
@ 2025-06-18 7:49 ` Haiyue Wang
2025-06-18 7:49 ` [PATCH liburing v1 3/6] examples/reg-wait: " Haiyue Wang
` (3 subsequent siblings)
5 siblings, 0 replies; 6+ messages in thread
From: Haiyue Wang @ 2025-06-18 7:49 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>
---
src/include/liburing.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/include/liburing.h b/src/include/liburing.h
index 6d87248..9f13e78 100644
--- a/src/include/liburing.h
+++ b/src/include/liburing.h
@@ -721,7 +721,7 @@ IOURINGINLINE void io_uring_prep_accept(struct io_uring_sqe *sqe, int fd,
socklen_t *addrlen, int flags)
{
io_uring_prep_rw(IORING_OP_ACCEPT, sqe, fd, addr, 0,
- (__u64) (unsigned long) addrlen);
+ uring_ptr_to_u64(addrlen));
sqe->accept_flags = (__u32) flags;
}
@@ -907,7 +907,7 @@ IOURINGINLINE void io_uring_prep_statx(struct io_uring_sqe *sqe, int dfd,
unsigned mask, struct statx *statxbuf)
{
io_uring_prep_rw(IORING_OP_STATX, sqe, dfd, path, mask,
- (__u64) (unsigned long) statxbuf);
+ uring_ptr_to_u64(statxbuf));
sqe->statx_flags = (__u32) flags;
}
--
2.49.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH liburing v1 3/6] examples/reg-wait: use uring_ptr_to_u64() helper to convert ptr to u64
[not found] <20250618075056.142118-1-haiyue.wang@cloudprime.ai>
2025-06-18 7:49 ` [PATCH liburing v1 1/6] Add uring_ptr_to_u64() helper Haiyue Wang
2025-06-18 7:49 ` [PATCH liburing v1 2/6] liburing: use uring_ptr_to_u64() helper to convert ptr to u64 Haiyue Wang
@ 2025-06-18 7:49 ` Haiyue Wang
2025-06-18 7:49 ` [PATCH liburing v1 4/6] examples/zcrx: " Haiyue Wang
` (2 subsequent siblings)
5 siblings, 0 replies; 6+ messages in thread
From: Haiyue Wang @ 2025-06-18 7:49 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>
---
examples/reg-wait.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/examples/reg-wait.c b/examples/reg-wait.c
index e868f3f..4f04293 100644
--- a/examples/reg-wait.c
+++ b/examples/reg-wait.c
@@ -45,10 +45,10 @@ static int register_memory(struct io_uring *ring, void *ptr, size_t size)
struct io_uring_region_desc rd = {};
struct io_uring_mem_region_reg mr = {};
- rd.user_addr = (__u64)(unsigned long)ptr;
+ rd.user_addr = uring_ptr_to_u64(ptr);
rd.size = 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;
return io_uring_register_region(ring, &mr);
--
2.49.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH liburing v1 4/6] examples/zcrx: use uring_ptr_to_u64() helper to convert ptr to u64
[not found] <20250618075056.142118-1-haiyue.wang@cloudprime.ai>
` (2 preceding siblings ...)
2025-06-18 7:49 ` [PATCH liburing v1 3/6] examples/reg-wait: " Haiyue Wang
@ 2025-06-18 7:49 ` Haiyue Wang
2025-06-18 7:49 ` [PATCH liburing v1 5/6] test/reg-wait: " Haiyue Wang
2025-06-18 7:49 ` [PATCH liburing v1 6/6] test/zcrx: " Haiyue Wang
5 siblings, 0 replies; 6+ messages in thread
From: Haiyue Wang @ 2025-06-18 7:49 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>
---
examples/zcrx.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/examples/zcrx.c b/examples/zcrx.c
index 5fc8814..a269b1a 100644
--- a/examples/zcrx.c
+++ b/examples/zcrx.c
@@ -163,7 +163,7 @@ static void zcrx_populate_area(struct io_uring_zcrx_area_reg *area_reg)
t_error(1, 0, "mmap(): area allocation failed");
memset(area_reg, 0, sizeof(*area_reg));
- area_reg->addr = (__u64)(unsigned long)area_ptr;
+ area_reg->addr = uring_ptr_to_u64(area_ptr);
area_reg->len = AREA_SIZE;
area_reg->flags = 0;
}
@@ -194,7 +194,7 @@ static void setup_zcrx(struct io_uring *ring)
struct io_uring_region_desc region_reg = {
.size = ring_size,
- .user_addr = (__u64)(unsigned long)ring_ptr,
+ .user_addr = uring_ptr_to_u64(ring_ptr),
.flags = rq_flags,
};
@@ -204,8 +204,8 @@ static void setup_zcrx(struct io_uring *ring)
.if_idx = ifindex,
.if_rxq = cfg_queue_id,
.rq_entries = rq_entries,
- .area_ptr = (__u64)(unsigned long)&area_reg,
- .region_ptr = (__u64)(unsigned long)®ion_reg,
+ .area_ptr = uring_ptr_to_u64(&area_reg),
+ .region_ptr = uring_ptr_to_u64(®ion_reg),
};
ret = io_uring_register_ifq(ring, ®);
--
2.49.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH liburing v1 5/6] test/reg-wait: use uring_ptr_to_u64() helper to convert ptr to u64
[not found] <20250618075056.142118-1-haiyue.wang@cloudprime.ai>
` (3 preceding siblings ...)
2025-06-18 7:49 ` [PATCH liburing v1 4/6] examples/zcrx: " Haiyue Wang
@ 2025-06-18 7:49 ` Haiyue Wang
2025-06-18 7:49 ` [PATCH liburing v1 6/6] test/zcrx: " Haiyue Wang
5 siblings, 0 replies; 6+ messages in thread
From: Haiyue Wang @ 2025-06-18 7:49 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] 6+ messages in thread
* [PATCH liburing v1 6/6] test/zcrx: use uring_ptr_to_u64() helper to convert ptr to u64
[not found] <20250618075056.142118-1-haiyue.wang@cloudprime.ai>
` (4 preceding siblings ...)
2025-06-18 7:49 ` [PATCH liburing v1 5/6] test/reg-wait: " Haiyue Wang
@ 2025-06-18 7:49 ` Haiyue Wang
5 siblings, 0 replies; 6+ messages in thread
From: Haiyue Wang @ 2025-06-18 7:49 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] 6+ messages in thread
end of thread, other threads:[~2025-06-18 7:53 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20250618075056.142118-1-haiyue.wang@cloudprime.ai>
2025-06-18 7:49 ` [PATCH liburing v1 1/6] Add uring_ptr_to_u64() helper Haiyue Wang
2025-06-18 7:49 ` [PATCH liburing v1 2/6] liburing: use uring_ptr_to_u64() helper to convert ptr to u64 Haiyue Wang
2025-06-18 7:49 ` [PATCH liburing v1 3/6] examples/reg-wait: " Haiyue Wang
2025-06-18 7:49 ` [PATCH liburing v1 4/6] examples/zcrx: " Haiyue Wang
2025-06-18 7:49 ` [PATCH liburing v1 5/6] test/reg-wait: " Haiyue Wang
2025-06-18 7:49 ` [PATCH liburing v1 6/6] test/zcrx: " Haiyue Wang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox