Re: [RFC PATCH bpf-next 1/2] bpf: Add open-coded style iterator kfuncs for bpf dynamic pointers

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Sep 3, 2024 at 3:08 PM Juntong Deng <juntong.deng@xxxxxxxxxxx> wrote:
>
> This patch adds open coded style bpf dynamic pointer iterator kfuncs
> bpf_iter_dynptr_{new,next,destroy} for iterating over all data in the
> memory region referenced by dynamic pointer.
>
> The idea of bpf dynamic pointer iterator comes from skb data iterator
> [0], we need a way to get all the data in skb. Adding iterator for bpf
> dynamic pointer is a more general choice than adding separate skb data
> iterator.
>
> Each iteration (next) copies the data to the specified buffer and
> updates the offset, with the pointer to the length of the read data
> (errno if errors occurred) as the return value. Note that the offset
> in iterator does not affect the offset in dynamic pointer.
>
> The bpf dynamic pointer iterator has a getter kfunc,
> bpf_iter_dynptr_get_last_offset, which is used to get the offset
> of the last iteration.
>
> The bpf dynamic pointer iterator has a setter kfunc,
> bpf_iter_dynptr_set_buffer, which is used to set the buffer and buffer
> size to be used when copying data in the iteration.
>
> [0]: https://lore.kernel.org/bpf/AM6PR03MB5848DE102F47F592D8B479E999A52@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/
>
> Signed-off-by: Juntong Deng <juntong.deng@xxxxxxxxxxx>
> ---
>  kernel/bpf/helpers.c | 110 +++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 110 insertions(+)
>

Why can't you implement all this using just normal numbers iterator
(bpf_for() loop) and using bpf_dynptr_size(), bpf_dynptr_slice(), etc,
generic helpers.

Seeing that you have to add bpf_iter_dynptr_set_buffer() and
bpf_iter_dynptr_get_last_offset() suggests that this might not be the
best fit for an open-coded iterator. But again, there doesn't seem to
be a real need. dynptr API is generic and usable enough to do whatever
you need without adding more code to the kernel.


[...]





[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux