BPF List
 help / color / mirror / Atom feed
From: Martin Kelly <martin.kelly@crowdstrike.com>
To: "andrii.nakryiko@gmail.com" <andrii.nakryiko@gmail.com>,
	Slava Imameev <slava.imameev@crowdstrike.com>
Cc: "mykolal@fb.com" <mykolal@fb.com>,
	"shuah@kernel.org" <shuah@kernel.org>,
	"eddyz87@gmail.com" <eddyz87@gmail.com>,
	"andrii@kernel.org" <andrii@kernel.org>,
	"song@kernel.org" <song@kernel.org>,
	"john.fastabend@gmail.com" <john.fastabend@gmail.com>,
	"yonghong.song@linux.dev" <yonghong.song@linux.dev>,
	Mark Fontana <mark.fontana@crowdstrike.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"kpsingh@kernel.org" <kpsingh@kernel.org>,
	"ast@kernel.org" <ast@kernel.org>,
	"martin.lau@linux.dev" <martin.lau@linux.dev>,
	"daniel@iogearbox.net" <daniel@iogearbox.net>,
	"sdf@fomichev.me" <sdf@fomichev.me>,
	"bpf@vger.kernel.org" <bpf@vger.kernel.org>,
	"linux-kselftest@vger.kernel.org"
	<linux-kselftest@vger.kernel.org>,
	"jolsa@kernel.org" <jolsa@kernel.org>,
	"haoluo@google.com" <haoluo@google.com>
Subject: Re: Re: [PATCH 2/2] libbpf: BPF programs dynamic loading and attaching
Date: Tue, 28 Jan 2025 23:08:25 +0000	[thread overview]
Message-ID: <8831ed8fa183f76fefd71244360fa0ca35b11910.camel@crowdstrike.com> (raw)
In-Reply-To: <CAEf4Bzajxh4xvg-aCaBhLQdNOZdhwceYUD2UsCcWku4ZBca_Hw@mail.gmail.com>

On Fri, 2025-01-24 at 10:31 -0800, Andrii Nakryiko wrote:
> > On Wed, Jan 22, 2025 at 1:53 PM Slava Imameev
> > <slava.imameev@crowdstrike.com> wrote:
> > > > 
> > > > BPF programs designated as dynamically loaded can be loaded and
> > > > attached independently after the initial bpf_object loading and
> > > > attaching.
> > > > 
> > > > These programs can also be reloaded and reattached multiple
> > > > times,
> > > > enabling more flexible management of a resident BPF program
> > > > set.
> > > > 
> > > > A key motivation for this feature is to reduce load times for
> > > > utilities that include hundreds of BPF programs. When the
> > > > selection
> > > > of a resident BPF program set cannot be determined at the time
> > > > of
> > > > bpf_object loading and attaching, all BPF programs would
> > > > otherwise
> > > > need to be marked as autoload, leading to unnecessary overhead.
> > > > This patch addresses that inefficiency.
> > 
> > Can you elaborate on why it's impossible to determine which BPF
> > programs should be loaded before BPF object load step?
> > 

The main use case for this patch is large applications that need to
dynamically load/unload BPF programs. Our specific use case is a
continuously-running security application with a dynamically-
reconfigurable feature set. As part of that reconfiguration, BPF
programs may get loaded/unloaded on-the-fly. Restarting the entire
application during reconfiguration is undesirable, as critical state
data can be lost and loading hundreds of BPF programs is time-
consuming.

The above points apply more generically to *any* application that
requires dynamic loading/unloading. Reconfiguration can be done via a
restart, but that has drawbacks:
(a) Losing any non-persistent application state on restart. In our
case, this creates a lapse in security that could be exploited by
adversaries.
(b) In applications with many programs, load+attach can take a long
time. We measured load+attach of ~100 BPF programs taking ~10 seconds
when done with current libbpf serially. Dynamically loading only the
programs needed avoids wasting memory and CPU cycles.
(c) The application itself might take a long time to restart, separate
from the BPF load/attach time. By loading dynamically, the BPF programs
can take effect much sooner and avoid wasted restart cycles.

This patch set also permits loading BPF programs in parallel if the
application wishes. We tested parallel loading with 200+ BPF programs
and found the load time dropped from 18 seconds to 5 seconds when done
in parallel on a 6.8 kernel.

In the future, this approach could also allow maps to not be
autoloaded, further saving on memory if no program needs the underlying
map.

In summary, we believe dynamic loading of BPF programs is an important
capability that will improve the performance of CrowdStrike's security
applications as well as being useful to other applications that want to
avoid restarts.
> 

  reply	other threads:[~2025-01-28 23:09 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 [this message]
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
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=8831ed8fa183f76fefd71244360fa0ca35b11910.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