public inbox for io-uring@vger.kernel.org
 help / color / mirror / Atom feed
From: Pavel Begunkov <asml.silence@gmail.com>
To: io-uring@vger.kernel.org
Cc: asml.silence@gmail.com, axboe@kernel.dk
Subject: [PATCH liburing] examples/zcrx: don't forget to sync dmabuf
Date: Fri, 16 Oct 2026 17:25:05 +0100	[thread overview]
Message-ID: <73b2654e41519acb2ec310ba1d6dc99cbafcbdfd.1792167723.git.asml.silence@gmail.com> (raw)

dma-bufs are not always coherent and we need to sync it before
accessing. Use proper dma-buf API for that.

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
---
 examples/zcrx.c | 40 +++++++++++++++++++++++++++++++++++++++-
 1 file changed, 39 insertions(+), 1 deletion(-)

diff --git a/examples/zcrx.c b/examples/zcrx.c
index b55b07ce..47036a33 100644
--- a/examples/zcrx.c
+++ b/examples/zcrx.c
@@ -39,6 +39,7 @@
 
 #include <linux/memfd.h>
 #include <linux/udmabuf.h>
+#include <linux/dma-buf.h>
 
 #include "liburing.h"
 #include "helpers.h"
@@ -103,12 +104,46 @@ static unsigned long area_token;
 static bool stop;
 static __u32 zcrx_id;
 
-static int dmabuf_fd;
+static int dmabuf_fd = -1;
 static int memfd;
 
 static int listen_fd;
 static int target_cpu = -1;
 
+static void dma_buf_begin_cpu_access(void)
+{
+	struct dma_buf_sync sync = {
+		.flags = DMA_BUF_SYNC_START | DMA_BUF_SYNC_RW,
+	};
+	int ret;
+
+	if (dmabuf_fd < 0)
+		return;
+
+	ret = ioctl(dmabuf_fd, DMA_BUF_IOCTL_SYNC, &sync);
+	if (ret) {
+		fprintf(stderr, "sync failed %i\n", errno);
+		exit(1);
+	}
+}
+
+static void dma_buf_end_cpu_access(void)
+{
+	struct dma_buf_sync sync = {
+		.flags = DMA_BUF_SYNC_END | DMA_BUF_SYNC_RW,
+	};
+	int ret;
+
+	if (dmabuf_fd < 0)
+		return;
+
+	ret = ioctl(dmabuf_fd, DMA_BUF_IOCTL_SYNC, &sync);
+	if (ret) {
+		fprintf(stderr, "sync failed %i\n", errno);
+		exit(1);
+	}
+}
+
 static int get_sock_cpu(int sockfd)
 {
 	int cpu;
@@ -373,6 +408,8 @@ static void verify_data(__u8 *data, size_t size, unsigned long seq)
 	if (!cfg_verify_data)
 		return;
 
+	dma_buf_begin_cpu_access();
+
 	for (i = 0; i < size; i++) {
 		__u8 expected = (__u8)'a' + (seq + i) % 26;
 		__u8 v = data[i];
@@ -382,6 +419,7 @@ static void verify_data(__u8 *data, size_t size, unsigned long seq)
 				(unsigned)i, expected, v, (int)expected - v,
 				seq, seq + i);
 	}
+	dma_buf_end_cpu_access();
 }
 
 static unsigned rq_nr_queued(struct io_uring_zcrx_rq *rq)
-- 
2.54.0


             reply	other threads:[~2026-10-16 16:25 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-16 16:25 Pavel Begunkov [this message]
2026-10-16 16:29 ` [PATCH liburing] examples/zcrx: don't forget to sync dmabuf Jens Axboe
2026-10-16 16:36   ` Pavel Begunkov
2026-10-16 16:38     ` Jens Axboe
2026-10-16 16:47       ` Pavel Begunkov
2026-10-16 16:57         ` Jens Axboe
2026-10-18 22:30           ` Pavel Begunkov
2026-10-16 16:39 ` Jens Axboe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=73b2654e41519acb2ec310ba1d6dc99cbafcbdfd.1792167723.git.asml.silence@gmail.com \
    --to=asml.silence@gmail.com \
    --cc=axboe@kernel.dk \
    --cc=io-uring@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox