* [PATCH liburing 0/2] add example for using dmabuf backed zcrx @ 2025-05-06 10:21 Pavel Begunkov 2025-05-06 10:21 ` [PATCH liburing 1/2] Update io_uring.h with zcrx dmabuf interface Pavel Begunkov ` (2 more replies) 0 siblings, 3 replies; 4+ messages in thread From: Pavel Begunkov @ 2025-05-06 10:21 UTC (permalink / raw) To: io-uring; +Cc: asml.silence Update the headers and add a option to create a dmabuf backed area in the zcrx example. Pavel Begunkov (2): Update io_uring.h with zcrx dmabuf interface examples/zcrx: udmabuf backed areas examples/zcrx.c | 55 +++++++++++++++++++++++++++++++++ src/include/liburing/io_uring.h | 6 +++- 2 files changed, 60 insertions(+), 1 deletion(-) -- 2.48.1 ^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH liburing 1/2] Update io_uring.h with zcrx dmabuf interface 2025-05-06 10:21 [PATCH liburing 0/2] add example for using dmabuf backed zcrx Pavel Begunkov @ 2025-05-06 10:21 ` Pavel Begunkov 2025-05-06 10:21 ` [PATCH liburing 2/2] examples/zcrx: udmabuf backed areas Pavel Begunkov 2025-05-06 13:54 ` [PATCH liburing 0/2] add example for using dmabuf backed zcrx Jens Axboe 2 siblings, 0 replies; 4+ messages in thread From: Pavel Begunkov @ 2025-05-06 10:21 UTC (permalink / raw) To: io-uring; +Cc: asml.silence Signed-off-by: Pavel Begunkov <asml.silence@gmail.com> --- src/include/liburing/io_uring.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/include/liburing/io_uring.h b/src/include/liburing/io_uring.h index 572ff59f..0baa3272 100644 --- a/src/include/liburing/io_uring.h +++ b/src/include/liburing/io_uring.h @@ -955,12 +955,16 @@ struct io_uring_zcrx_offsets { __u64 __resv[2]; }; +enum io_uring_zcrx_area_flags { + IORING_ZCRX_AREA_DMABUF = 1, +}; + struct io_uring_zcrx_area_reg { __u64 addr; __u64 len; __u64 rq_area_token; __u32 flags; - __u32 __resv1; + __u32 dmabuf_fd; __u64 __resv2[2]; }; -- 2.48.1 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH liburing 2/2] examples/zcrx: udmabuf backed areas 2025-05-06 10:21 [PATCH liburing 0/2] add example for using dmabuf backed zcrx Pavel Begunkov 2025-05-06 10:21 ` [PATCH liburing 1/2] Update io_uring.h with zcrx dmabuf interface Pavel Begunkov @ 2025-05-06 10:21 ` Pavel Begunkov 2025-05-06 13:54 ` [PATCH liburing 0/2] add example for using dmabuf backed zcrx Jens Axboe 2 siblings, 0 replies; 4+ messages in thread From: Pavel Begunkov @ 2025-05-06 10:21 UTC (permalink / raw) To: io-uring; +Cc: asml.silence Add an example of how to create dmabuf backed area. For that we use udmabuf and mmap it into user space, however in more realistic scenarios won't have direct access to the memory and will need to use dmabuf provider specific api, e.g. OpenCl. Signed-off-by: Pavel Begunkov <asml.silence@gmail.com> --- examples/zcrx.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/examples/zcrx.c b/examples/zcrx.c index 6b06e4fa..c5e1b42f 100644 --- a/examples/zcrx.c +++ b/examples/zcrx.c @@ -37,6 +37,10 @@ #include <sys/wait.h> #include <linux/mman.h> +#include <linux/memfd.h> +#include <linux/dma-buf.h> +#include <linux/udmabuf.h> + #include "liburing.h" #include "helpers.h" @@ -56,6 +60,7 @@ static long page_size; enum { AREA_TYPE_NORMAL, AREA_TYPE_HUGE_PAGES, + AREA_TYPE_DMABUF, __AREA_TYPE_MAX, }; @@ -83,6 +88,9 @@ static bool stop; static size_t received; static __u32 zcrx_id; +static int dmabuf_fd; +static int memfd; + static inline size_t get_refill_ring_size(unsigned int rq_entries) { ring_size = rq_entries * sizeof(struct io_uring_zcrx_rqe); @@ -91,11 +99,58 @@ static inline size_t get_refill_ring_size(unsigned int rq_entries) return T_ALIGN_UP(ring_size, page_size); } +static void zcrx_populate_area_udmabuf(struct io_uring_zcrx_area_reg *area_reg) +{ + struct udmabuf_create create; + int ret, devfd; + + devfd = open("/dev/udmabuf", O_RDWR); + if (devfd < 0) + t_error(1, devfd, "Failed to open udmabuf dev"); + + memfd = memfd_create("udmabuf-test", MFD_ALLOW_SEALING); + if (memfd < 0) + t_error(1, memfd, "Failed to open udmabuf dev"); + + ret = fcntl(memfd, F_ADD_SEALS, F_SEAL_SHRINK); + if (ret < 0) + t_error(1, 0, "Failed to set seals"); + + ret = ftruncate(memfd, AREA_SIZE); + if (ret == -1) + t_error(1, 0, "Failed to resize udmabuf"); + + memset(&create, 0, sizeof(create)); + create.memfd = memfd; + create.offset = 0; + create.size = AREA_SIZE; + dmabuf_fd = ioctl(devfd, UDMABUF_CREATE, &create); + if (dmabuf_fd < 0) + t_error(1, dmabuf_fd, "Failed to create udmabuf"); + + area_ptr = mmap(NULL, AREA_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, + dmabuf_fd, 0); + if (area_ptr == MAP_FAILED) + t_error(1, 0, "Failed to mmap udmabuf"); + + memset(area_reg, 0, sizeof(*area_reg)); + area_reg->addr = 0; /* offset into dmabuf */ + area_reg->len = AREA_SIZE; + area_reg->flags |= IORING_ZCRX_AREA_DMABUF; + area_reg->dmabuf_fd = dmabuf_fd; + + close(devfd); +} + static void zcrx_populate_area(struct io_uring_zcrx_area_reg *area_reg) { unsigned flags = MAP_PRIVATE | MAP_ANONYMOUS; unsigned prot = PROT_READ | PROT_WRITE; + if (cfg_area_type == AREA_TYPE_DMABUF) { + zcrx_populate_area_udmabuf(area_reg); + return; + } if (cfg_area_type == AREA_TYPE_NORMAL) { area_ptr = mmap(NULL, AREA_SIZE, prot, flags, 0, 0); -- 2.48.1 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH liburing 0/2] add example for using dmabuf backed zcrx 2025-05-06 10:21 [PATCH liburing 0/2] add example for using dmabuf backed zcrx Pavel Begunkov 2025-05-06 10:21 ` [PATCH liburing 1/2] Update io_uring.h with zcrx dmabuf interface Pavel Begunkov 2025-05-06 10:21 ` [PATCH liburing 2/2] examples/zcrx: udmabuf backed areas Pavel Begunkov @ 2025-05-06 13:54 ` Jens Axboe 2 siblings, 0 replies; 4+ messages in thread From: Jens Axboe @ 2025-05-06 13:54 UTC (permalink / raw) To: io-uring, Pavel Begunkov On Tue, 06 May 2025 11:21:49 +0100, Pavel Begunkov wrote: > Update the headers and add a option to create a dmabuf backed area > in the zcrx example. > > Pavel Begunkov (2): > Update io_uring.h with zcrx dmabuf interface > examples/zcrx: udmabuf backed areas > > [...] Applied, thanks! [1/2] Update io_uring.h with zcrx dmabuf interface commit: 425f6d5c9b9371519990935e5412568fe736cc0f [2/2] examples/zcrx: udmabuf backed areas commit: 93d3a7a70b4a6d6ade45a02915dda81c2cdf9810 Best regards, -- Jens Axboe ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-05-06 13:54 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2025-05-06 10:21 [PATCH liburing 0/2] add example for using dmabuf backed zcrx Pavel Begunkov 2025-05-06 10:21 ` [PATCH liburing 1/2] Update io_uring.h with zcrx dmabuf interface Pavel Begunkov 2025-05-06 10:21 ` [PATCH liburing 2/2] examples/zcrx: udmabuf backed areas Pavel Begunkov 2025-05-06 13:54 ` [PATCH liburing 0/2] add example for using dmabuf backed zcrx Jens Axboe
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox