On 11/28/18 1:50 PM, Pablo Alvarez via Lists.Iovisor.Org wrote:
Dear eBPF community
If I understand correctly, per_cpu maps are meant to avoid threading
issues, and for example the need to call BPF_XADD to keep counters safe.
There is something I am unclear about:
- Is it possible for a BPF program to be preempted by another BPF
program on the same CPU?
eBPF programs are never preempted by the kernel, this allows to keep counters in per_cpu maps without need to use synchronized primitives on them.
This is also guaranteed that there is not preemption in a chain of tail calls, then per_cpu maps can also be used to store "global variables".
If this is the case, it seems that the following scenario could arise:
BPF program 1 on cpu 0 reads a counter and is preempted before
BPF program 2 on cpu 0 reads the same counter, increments it, and finishes
BPF program 1 on cpu 0 increments the counter
At which point both programs would have read the same value for the
counter, with possible problems ensuing.
Is this a valid scenario? Am I missing something about how the per_cpu
maps are intended to be used?