From: Matt Bobrowski <mattbobrowski@google.com>
To: bpf@vger.kernel.org
Cc: ast@kernel.org, andrii@kernel.org, yonghong.song@linux.dev,
daniel@iogearbox.net
Subject: Generic Data Structure Iterators
Date: Mon, 12 Feb 2024 20:48:07 +0000 [thread overview]
Message-ID: <ZcqEB3REkEKJahQu@google.com> (raw)
In numerous BPF programs, I've found myself needing to iterate over
some in-kernel generic data structure i.e. list_head, hlist_head,
rbtree, etc. The approach that I generally use to do this consists of
using bpf_loop(), container_of(), and BPF_CORE_READ(). The end result
of this approach is always rather messy as it's mostly implementation
specific and bound to a specific in-kernel type i.e. mount, dentry,
inode, etc.
Recently, I came across the newly added bpf_for_each() open-coded
iterator, which could possibly help out a little with trivially
performing such iterations within BPF programs. However, looking into
the usage of this helper a little more, I realized that this too needs
to be backed by the new kfunc iterator framework
i.e. bpf_iter_##type##_new(), bpf_iter_##type##_destroy(),
bpf_iter_##type##_next(). So, in practice it seems like adopting this
approach to solve this specific iterator problem would lead us into a
situation where we'd be having to define iterator kfuncs for each
in-kernel type and respective field.
Now having said this, I'm wondering whether anyone here has considered
possibly solving this iterator based problem a little more
generically? That is, by exposing a set of kfuncs that allow you to
iterate over a list_head, hlist_head, rbtree, etc, independent of an
underlying in-kernel type and similar to your *list_for_each*() based
helpers that you'd typically find for each of these in-kernel generic
data structures. If so, what were your findings when exploring this
problem space?
/M
next reply other threads:[~2024-02-12 20:48 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-12 20:48 Matt Bobrowski [this message]
2024-02-12 23:20 ` Generic Data Structure Iterators Song Liu
2024-02-13 20:37 ` Alexei Starovoitov
2024-02-13 20:47 ` Kumar Kartikeya Dwivedi
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=ZcqEB3REkEKJahQu@google.com \
--to=mattbobrowski@google.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=yonghong.song@linux.dev \
/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