From: Martin Kelly <martin.kelly@crowdstrike.com>
To: "andrii.nakryiko@gmail.com" <andrii.nakryiko@gmail.com>
Cc: "mykolal@fb.com" <mykolal@fb.com>,
"shuah@kernel.org" <shuah@kernel.org>,
"eddyz87@gmail.com" <eddyz87@gmail.com>,
"song@kernel.org" <song@kernel.org>,
Mark Fontana <mark.fontana@crowdstrike.com>,
"john.fastabend@gmail.com" <john.fastabend@gmail.com>,
"yonghong.song@linux.dev" <yonghong.song@linux.dev>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"andrii@kernel.org" <andrii@kernel.org>,
"kpsingh@kernel.org" <kpsingh@kernel.org>,
"martin.lau@linux.dev" <martin.lau@linux.dev>,
"ast@kernel.org" <ast@kernel.org>,
"bpf@vger.kernel.org" <bpf@vger.kernel.org>,
"sdf@fomichev.me" <sdf@fomichev.me>,
"daniel@iogearbox.net" <daniel@iogearbox.net>,
"linux-kselftest@vger.kernel.org"
<linux-kselftest@vger.kernel.org>,
"Slava Imameev" <slava.imameev@crowdstrike.com>,
"jolsa@kernel.org" <jolsa@kernel.org>,
"haoluo@google.com" <haoluo@google.com>
Subject: Re: Re: Re: Re: [PATCH 2/2] libbpf: BPF programs dynamic loading and attaching
Date: Wed, 12 Feb 2025 22:31:21 +0000 [thread overview]
Message-ID: <7727e5d4f035c04d03ba274ad8b7fb8bc7da696c.camel@crowdstrike.com> (raw)
In-Reply-To: <CAEf4BzZ8H0nQMEMaDGMfyngb15zMFEduy_R_ajakrdjGGtiOQA@mail.gmail.com>
On Mon, 2025-02-10 at 16:06 -0800, Andrii Nakryiko wrote:
> > Tracking associated maps for a program is not necessary. As long as
> > the last BPF program using the BPF map is unloaded, the kernel will
> > automatically free not-anymore-referenced BPF map. Note that
> > bpf_object itself will keep FDs for BPF maps, so you'd need to make
> > sure to do bpf_object__close() to release those references.
> >
> > But if you are going to ask to re-create BPF maps next time BPF
> > program is loaded... Well, I'll say you are asking for a bit too >
> > much,
> > tbh. If you want to be *that* sophisticated, it shouldn't be too
> > hard
> > for you to get all this information from BPF program's
> > instructions.
> >
We really are that sophisticated (see below for more details). We could
scan program instructions, but we'd then tie our logic to BPF
implementation details and duplicate logic already present in libbpf
(https://elixir.bootlin.com/linux/v6.13.2/source/tools/lib/bpf/libbpf.c#L6087
). Obviously this *can* be done but it's not at all ideal from an
application perspective.
> > > >
> > bpf_object is the unit of coherence in libbpf, so I don't see us
> > refcounting maps between bpf_objects. Kernel is doing refcounting
> > based on FDs, so see if you can use that.
> >
I can understand that. That said, I think if there's no logic across
objects, and bpf_object access is not thread-safe, it puts us into a
tough situation:
- Complex refcounting, code scanning, etc to keep consistency when
manipulating maps used by multiple programs.
- Parallel loading not being well-balanced, if we split programs across
objects.
We could alternatively write our own custom loader, but then we’d have
to duplicate much of the useful logic that libbpf already implements:
skeleton generation, map/program association, embedding programs into
ELFs, loading logic and kernel probing, etc. We’d like some way to
handle dynamic/parallel loading without having to replicate all the
advantages libbpf grants us.
> >
> >
> > Is 100 just a nicely looking rather large number, or do you really
> > have 100 different BPF programs? Why so many and are they really
> > all
> > unique?
> >
> > Asking because if it's just a way to attach BPF program doing more
> > or
> > less uniform set of actions for different hooks, then perhaps there
> > are better ways to do this without having to duplicating BPF
> > programs
> > so much (like BPF cookie, multi-kprobes, etc, etc)
100 is not an arbitrary number; we have that and higher (~200 is a good
current estimate, and that grows as new product features are added).
The programs are really doing different things. We also have to support
a wide range of kernels, handling cases like: "on this kernel range,
trampolines aren't supported, so use kretprobes with a context map for
function args instead of fexit, but on newer kernels just use an fexit
hook."
The use case here is that our security monitoring agent leverages eBPF
as its foundational technology to gather telemetry from the kernel. As
part of that, we hook many different kernel subsystems (process,
memory, filesystem, network, etc), tying them together and tracking
with maps. So we legitimately have a very large number of programs all
doing different work. For products of this scale, it increases security
and performance to load this set of programs and their maps in an
optimized, parallel fashion and subsequently change the loaded set of
programs and maps dynamically without disturbing the rest of the
application.
next prev parent reply other threads:[~2025-02-12 22:32 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-22 21:52 [PATCH 1/2] libbpf: BPF program load type enum Slava Imameev
2025-01-22 21:52 ` [PATCH 2/2] libbpf: BPF programs dynamic loading and attaching Slava Imameev
2025-01-24 18:31 ` Andrii Nakryiko
2025-01-28 23:08 ` Martin Kelly
2025-02-05 22:33 ` Andrii Nakryiko
2025-02-08 1:13 ` Martin Kelly
2025-02-11 0:06 ` Andrii Nakryiko
2025-02-12 22:31 ` Martin Kelly [this message]
2025-02-21 17:40 ` Andrii Nakryiko
2025-02-25 1:12 ` Slava Imameev
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=7727e5d4f035c04d03ba274ad8b7fb8bc7da696c.camel@crowdstrike.com \
--to=martin.kelly@crowdstrike.com \
--cc=andrii.nakryiko@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=haoluo@google.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=mark.fontana@crowdstrike.com \
--cc=martin.lau@linux.dev \
--cc=mykolal@fb.com \
--cc=sdf@fomichev.me \
--cc=shuah@kernel.org \
--cc=slava.imameev@crowdstrike.com \
--cc=song@kernel.org \
--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