From: Jakub Sitnicki <jakub@cloudflare.com>
To: Yaniv Agman <yanivagman@gmail.com>
Cc: bpf <bpf@vger.kernel.org>
Subject: Re: Are BPF programs preemptible?
Date: Mon, 23 Jan 2023 11:46:58 +0100 [thread overview]
Message-ID: <878rhty100.fsf@cloudflare.com> (raw)
In-Reply-To: <CAMy7=ZW27JeWd-o7dYaXob2BC+qKRqRqpihiN9viTqq1+Eib-g@mail.gmail.com>
On Mon, Jan 23, 2023 at 11:21 AM +02, Yaniv Agman wrote:
> Hello!
>
> Several places state that eBPF programs cannot be preempted by the
> kernel (e.g. https://docs.cilium.io/en/latest/bpf/toolchain), however,
> I did see a strange behavior where an eBPF percpu map gets overridden,
> and I'm trying to figure out if it's due to a bug in my program or
> some misunderstanding I have about eBPF. What caught my eye was a
> sentence in a LWN article (https://lwn.net/Articles/812503/) that
> says: "Alexei thankfully enlightened me recently over a beer that the
> real intent here is to guarantee that the program runs to completion
> on the same CPU where it started".
>
> So my question is - are BPF programs guaranteed to run from start to
> end without being interrupted at all or the only guarantee I get is
> that they run on the same CPU but IRQs (NMIs, soft irqs, whatever) can
> interrupt their run?
>
> If the only guarantee is no migration, it means that a percpu map
> cannot be safely used by two different BPF programs that can preempt
> each other (e.g. some kprobe and a network cgroup program).
Since v5.7 BPF program runners use migrate_disable() instead of
preempt_disable(). See commit 2a916f2f546c ("bpf: Use
migrate_disable/enable in array macros and cgroup/lirc code.") [1].
But at that time migrate_disable() was merely an alias for
preempt_disable() on !CONFIG_PREEMPT_RT kernels.
Since v5.11 migrate_disable() does no longer disable preemption on
!CONFIG_PREEMPT_RT kernels. See commit 74d862b682f5 ("sched: Make
migrate_disable/enable() independent of RT") [2].
So, yes, you are right, but it depends on the kernel version.
PS. The migrate_disable vs per-CPU data problem is also covered in [3].
[1]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=2a916f2f546ca1c1e3323e2a4269307f6d9890eb
[2]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=74d862b682f51e45d25b95b1ecf212428a4967b0
[3]: https://lwn.net/Articles/836503/
next prev parent reply other threads:[~2023-01-23 10:54 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-23 9:21 Are BPF programs preemptible? Yaniv Agman
2023-01-23 10:46 ` Jakub Sitnicki [this message]
2023-01-23 12:30 ` Yaniv Agman
2023-01-23 17:02 ` Yonghong Song
2023-01-23 17:32 ` Yaniv Agman
2023-01-23 20:06 ` Martin KaFai Lau
2023-01-23 21:01 ` Yaniv Agman
2023-01-23 21:22 ` Jakub Sitnicki
2023-01-23 21:56 ` Yaniv Agman
2023-01-24 12:30 ` Alexei Starovoitov
2023-01-24 15:47 ` Yaniv Agman
2023-01-24 17:24 ` Alexei Starovoitov
2023-01-24 17:38 ` Yaniv Agman
2023-01-25 0:04 ` Alexei Starovoitov
2023-01-25 16:39 ` Yaniv Agman
2023-01-25 18:52 ` Alexei Starovoitov
2023-01-25 19:59 ` Yaniv Agman
2023-01-26 2:22 ` Alexei Starovoitov
2023-01-26 6:59 ` Yaniv Agman
2023-01-26 15:29 ` Alexei Starovoitov
2023-01-26 17:51 ` Yaniv Agman
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=878rhty100.fsf@cloudflare.com \
--to=jakub@cloudflare.com \
--cc=bpf@vger.kernel.org \
--cc=yanivagman@gmail.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.