[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAPhsuW7BM=X06Tr+HURsCbD8LwAO=Fdu+ZfKDy6RNK=UNNC1Rg@mail.gmail.com>
Date: Fri, 9 May 2025 14:58:42 -0700
From: Song Liu <song@...nel.org>
To: "T.J. Mercier" <tjmercier@...gle.com>
Cc: sumit.semwal@...aro.org, christian.koenig@....com, ast@...nel.org,
daniel@...earbox.net, andrii@...nel.org, martin.lau@...ux.dev,
skhan@...uxfoundation.org, alexei.starovoitov@...il.com,
linux-kernel@...r.kernel.org, linux-media@...r.kernel.org,
dri-devel@...ts.freedesktop.org, linaro-mm-sig@...ts.linaro.org,
bpf@...r.kernel.org, linux-kselftest@...r.kernel.org, android-mm@...gle.com,
simona@...ll.ch, eddyz87@...il.com, yonghong.song@...ux.dev,
john.fastabend@...il.com, kpsingh@...nel.org, sdf@...ichev.me,
jolsa@...nel.org, mykolal@...com, shuah@...nel.org
Subject: Re: [PATCH bpf-next v4 5/5] selftests/bpf: Add test for open coded dmabuf_iter
On Fri, May 9, 2025 at 2:43 PM T.J. Mercier <tjmercier@...gle.com> wrote:
>
[...]
> >
> > Personally, I would prefer we just merge all the logic of
> > create_udmabuf() and create_sys_heap_dmabuf()
> > into create_test_buffers().
>
> That's a lot of different stuff to put in one place. How about
> returning file descriptors from the buffer create functions while
> having them clean up after themselves:
I do like this version better. Some nitpicks though.
>
> -static int memfd, udmabuf;
> +static int udmabuf;
About this, and ...
> static const char udmabuf_test_buffer_name[DMA_BUF_NAME_LEN] =
> "udmabuf_test_buffer_for_iter";
> static size_t udmabuf_test_buffer_size;
> static int sysheap_dmabuf;
> static const char sysheap_test_buffer_name[DMA_BUF_NAME_LEN] =
> "sysheap_test_buffer_for_iter";
> static size_t sysheap_test_buffer_size;
>
> -static int create_udmabuf(int map_fd)
> +static int create_udmabuf(void)
> {
> struct udmabuf_create create;
> - int dev_udmabuf;
> - bool f = false;
> + int dev_udmabuf, memfd, udmabuf;
.. here.
It is not ideal to have a global udmabuf and a local udmabuf.
If we want the global version, let's rename the local one.
[...]
>
> static int create_test_buffers(int map_fd)
> {
> - int ret;
> + bool f = false;
> +
> + udmabuf = create_udmabuf();
> + sysheap_dmabuf = create_sys_heap_dmabuf();
>
> - ret = create_udmabuf(map_fd);
> - if (ret)
> - return ret;
> + if (udmabuf < 0 || sysheap_dmabuf < 0)
> + return -1;
We also need destroy_test_buffers() on the error path here,
or at the caller.
>
> - return create_sys_heap_dmabuf(map_fd);
> + return bpf_map_update_elem(map_fd, udmabuf_test_buffer_name,
> &f, BPF_ANY) ||
> + bpf_map_update_elem(map_fd, sysheap_test_buffer_name,
> &f, BPF_ANY);
> }
>
> static void destroy_test_buffers(void)
> {
> close(udmabuf);
> - close(memfd);
> close(sysheap_dmabuf);
For the two global fds, let's reset them to -1 right after close().
Thanks,
Song
Powered by blists - more mailing lists