On Thu, May 8, 2025 at 5:27 PM Song Liu <s...@kernel.org> wrote: > > On Thu, May 8, 2025 at 11:20 AM T.J. Mercier <tjmerc...@google.com> wrote: > > > > The dmabuf iterator traverses the list of all DMA buffers. > > > > DMA buffers are refcounted through their associated struct file. A > > reference is taken on each buffer as the list is iterated to ensure each > > buffer persists for the duration of the bpf program execution without > > holding the list mutex. > > > > Signed-off-by: T.J. Mercier <tjmerc...@google.com> > > Reviewed-by: Christian König <christian.koe...@amd.com> > > Acked-by: Song Liu <s...@kernel.org> > > With one nitpick below.
Thanks! > > --- > [...] > > diff --git a/include/linux/dma-buf.h b/include/linux/dma-buf.h > > index 8ff4add71f88..7af2ea839f58 100644 > > --- a/include/linux/dma-buf.h > > +++ b/include/linux/dma-buf.h > > @@ -634,4 +634,6 @@ int dma_buf_vmap(struct dma_buf *dmabuf, struct > > iosys_map *map); > > void dma_buf_vunmap(struct dma_buf *dmabuf, struct iosys_map *map); > > int dma_buf_vmap_unlocked(struct dma_buf *dmabuf, struct iosys_map *map); > > void dma_buf_vunmap_unlocked(struct dma_buf *dmabuf, struct iosys_map > > *map); > > +struct dma_buf *dma_buf_iter_begin(void); > > +struct dma_buf *dma_buf_iter_next(struct dma_buf *dmbuf); > > #endif /* __DMA_BUF_H__ */ > > diff --git a/kernel/bpf/Makefile b/kernel/bpf/Makefile > > index 70502f038b92..3a335c50e6e3 100644 > > --- a/kernel/bpf/Makefile > > +++ b/kernel/bpf/Makefile > > @@ -53,6 +53,9 @@ obj-$(CONFIG_BPF_SYSCALL) += relo_core.o > > obj-$(CONFIG_BPF_SYSCALL) += btf_iter.o > > obj-$(CONFIG_BPF_SYSCALL) += btf_relocate.o > > obj-$(CONFIG_BPF_SYSCALL) += kmem_cache_iter.o > > +ifeq ($(CONFIG_DMA_SHARED_BUFFER),y) > > +obj-$(CONFIG_BPF_SYSCALL) += dmabuf_iter.o > > +endif > > > > CFLAGS_REMOVE_percpu_freelist.o = $(CC_FLAGS_FTRACE) > > CFLAGS_REMOVE_bpf_lru_list.o = $(CC_FLAGS_FTRACE) > > diff --git a/kernel/bpf/dmabuf_iter.c b/kernel/bpf/dmabuf_iter.c > > new file mode 100644 > > index 000000000000..96b4ba7f0b2c > > --- /dev/null > > +++ b/kernel/bpf/dmabuf_iter.c > > @@ -0,0 +1,102 @@ > > +// SPDX-License-Identifier: GPL-2.0-only > > +/* Copyright (c) 2025 Google LLC */ > > +#include <linux/bpf.h> > > +#include <linux/btf_ids.h> > > +#include <linux/dma-buf.h> > > +#include <linux/kernel.h> > > +#include <linux/seq_file.h> > > + > > +BTF_ID_LIST_SINGLE(bpf_dmabuf_btf_id, struct, dma_buf) > > +DEFINE_BPF_ITER_FUNC(dmabuf, struct bpf_iter_meta *meta, struct dma_buf > > *dmabuf) > > nit: It is better to move these two lines later, to where they > are about to be used. I've moved them both to just before dmabuf_iter_init() farther down.