examples/zcrx: don't forget to sync dmabuf
PATCH 1/1 examples/zcrx: don't forget to sync dmabuf
dma-bufs are not always coherent and we need to sync it before accessing. Use proper dma-buf API for that.
--- examples/zcrx.c | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-)
examples/zcrx.c +39 -1
@@ -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)
Signature · 1 line
2.54.0
Jens Axboe
maintainerQuoted 2 lines · Pavel Begunkov
dma-bufs are not always coherent and we need to sync it before accessing. Use proper dma-buf API for that.
Can we get a Fixes tag for this please? Other fixes from today lacked that as well, please always add fixes tags.
Signature · 1 line
Jens Axboe
Quoted 6 lines · Jens Axboe
Quoted 2 lines · Pavel Begunkov
dma-bufs are not always coherent and we need to sync it before accessing. Use proper dma-buf API for that.
Can we get a Fixes tag for this please? Other fixes from today lacked that as well, please always add fixes tags.
There was no "fixes" today. I didn't know you care about liburing fixes tags either, but if you want to put one:
Signature · 1 line
Pavel Begunkov
Jens Axboe
maintainerQuoted 9 lines · Pavel Begunkov
Quoted 6 lines · Jens Axboe
Quoted 2 lines · Pavel Begunkov
dma-bufs are not always coherent and we need to sync it before accessing. Use proper dma-buf API for that.
Can we get a Fixes tag for this please? Other fixes from today lacked that as well, please always add fixes tags.
There was no "fixes" today.
Sure let's argue that, I merged 4 fixes from you this morning. None of them had Fixes tags.
Quoted 3 lines
liburing fixes tags either, but if you want to put one:
Fixes 93d3a7a70b4a6 ("examples/zcrx: udmabuf backed areas")
Because it's always nice to have the reference, even if there are no stable trees or anything like that on the liburing side.
Signature · 1 line
Jens Axboe
Quoted 6 lines · Jens Axboe
Quoted 5 lines · Pavel Begunkov
Quoted 4 lines · Jens Axboe
Quoted 2 lines · Pavel Begunkov
dma-bufs are not always coherent and we need to sync it before accessing. Use proper dma-buf API for that.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Can we get a Fixes tag for this please? Other fixes from today lacked that as well, please always add fixes tags.
There was no "fixes" today.
Sure let's argue that, I merged 4 fixes from you this morning. None of them had Fixes tags.
There is nothing to argue about, I doubt anyone would call a tabulation change or adding a kerneldoc "a fix".
Quoted 6 lines
Quoted 3 lines
liburing fixes tags either, but if you want to put one:
Fixes 93d3a7a70b4a6 ("examples/zcrx: udmabuf backed areas")Because it's always nice to have the reference, even if there are no stable trees or anything like that on the liburing side.
Sure
Signature · 1 line
Pavel Begunkov
Jens Axboe
maintainerQuoted 10 lines · Pavel Begunkov
Quoted 9 lines · Jens Axboe
Quoted 8 lines · Pavel Begunkov
Quoted 6 lines · Jens Axboe
Quoted 2 lines · Pavel Begunkov
dma-bufs are not always coherent and we need to sync it before accessing. Use proper dma-buf API for that.
Can we get a Fixes tag for this please? Other fixes from today lacked that as well, please always add fixes tags.
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
There was no "fixes" today.
Sure let's argue that, I merged 4 fixes from you this morning. None of them had Fixes tags.
There is nothing to argue about, I doubt anyone would call a tabulation change or adding a kerneldoc "a fix".
But we're talking about it, now another round... And justifying it. The way I see it, anything that fixes something in a previous patch is, by definition, a fix for that patch and should be labeled as such. That's usually not something that people question. It doesn't need to fix something that's functionally broken to be labeled a fix. For the latter, if it's broken in a user visible way, we'd add stable to that patch as well. Or just send it manually too, if it's missing from the patch. That's the definition I use as the maintainer of those areas, and that's why I ask for them.
Signature · 1 line
Jens Axboe
Quoted 19 lines · Jens Axboe
Quoted 10 lines · Pavel Begunkov
Quoted 9 lines · Jens Axboe
Quoted 8 lines · Pavel Begunkov
Quoted 6 lines · Jens Axboe
Quoted 2 lines · Pavel Begunkov
dma-bufs are not always coherent and we need to sync it before accessing. Use proper dma-buf API for that.
Can we get a Fixes tag for this please? Other fixes from today lacked that as well, please always add fixes tags.
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
There was no "fixes" today.
Sure let's argue that, I merged 4 fixes from you this morning. None of them had Fixes tags.
There is nothing to argue about, I doubt anyone would call a tabulation change or adding a kerneldoc "a fix".
Quoted 9 lines
But we're talking about it, now another round... And justifying it. The way I see it, anything that fixes something in a previous patch is, by definition, a fix for that patch and should be labeled as such. That's usually not something that people question. It doesn't need to fix something that's functionally broken to be labeled a fix. For the latter, if it's broken in a user visible way, we'd add stable to that patch as well. Or just send it manually too, if it's missing from the patch. That's the definition I use as the maintainer of those areas, and that's why I ask for them.
Jens, thank you for the insight. It was confusing because the public documentation refer to bugs, but since you use it differently, I'll make sure all patches that correct typos and indentation, add new docs, introduce new APIs and extending existing ones, or do other enhancements have a "Fixes" tag for you as the maintainer of those areas.
Signature · 1 line
Pavel Begunkov
Quoted 2 lines · Pavel Begunkov
dma-bufs are not always coherent and we need to sync it before accessing. Use proper dma-buf API for that.
Applied, thanks!
[1/1] examples/zcrx: don't forget to sync dmabuf
commit: efa5f5efbeef6967d0a69e3b2c620650e76f4624
Best regards,
Signature · 1 line
Jens Axboe