Should eBPF programs always be run in a non-preemptible mode? #421
-
Linux documents that BPF programs always execute in a non-preemptible mode. eBPF-for-Windows has three possible modes:
Should we simplify this logic and always run programs in a non-preemptible mode? This would simplify:
|
Beta Was this translation helpful? Give feedback.
Replies: 10 comments 6 replies
-
For the kernel as an execution context, I would say yes dispatch level only (non-preemptible). |
Beta Was this translation helpful? Give feedback.
-
For kernel-mode:
For user-mode, we can do the following:
This will give non-preemption behavior for user mode, with respect to the execution context. Only 1 thread per CPU will execute within the execution context and threads won't migrate between CPUs during the eBPF program execution. Threads can still be pre-empted by other non-EC threads, but this is no different than DPC's being pre-empted by hyper-v in the kernel. Thoughts? |
Beta Was this translation helpful? Give feedback.
-
@qmonnet @teknoraver can you provide more info on whether programs are pre-emptible on Linux? E.g., can a program be preempted by another program? By an interrupt? Nothing? If preempted, it always continues on the same CPU? |
Beta Was this translation helpful? Give feedback.
-
from https://elixir.bootlin.com/linux/latest/source/include/linux/filter.h#L777
|
Beta Was this translation helpful? Give feedback.
-
I don't have a perfect understanding on that level, but I think most programs are non-preemptible, as stated above. However, there was a need for some programs to be “sleep-able”, so they could use, for example, helpers like
|
Beta Was this translation helpful? Give feedback.
-
As per @qmonnet comment above Linux supports both preemptible and non-preemptible eBPF programs. Given that, eBPF for Windows should not drop support for preemptible eBPF programs and instead, permit attach points to define the contract for programs attached to them. |
Beta Was this translation helpful? Give feedback.
-
This is from BPF helper documentation: @qmonnet - maybe the below should be updated? `
` |
Beta Was this translation helpful? Give feedback.
-
Keep in mind, that even if preemption is enabled, migration is disabled, and the CPU id can't change |
Beta Was this translation helpful? Give feedback.
-
This topic was also discussed in https://www.youtube.com/watch?v=EViAho-6qoc&t=12697s, BPF re-entrancy, eBPF Summit 2023. |
Beta Was this translation helpful? Give feedback.
I don't have a perfect understanding on that level, but I think most programs are non-preemptible, as stated above.
However, there was a need for some programs to be “sleep-able”, so they could use, for example, helpers like
bpf_copy_from_user()
which is susceptible to sleep, and this was implemented last summer. This is the case for LSM programs in particular, if I remember correctly. Note that sleepable programs must be explicitly declared as such at load time (there is aBPF_F_SLEEPABLE
flag that can be passed). See related commit log for details. Note that it might be extended in the future, the commit message states: