OSDN Git Service

bpf: Provide bpf_prog_run_pin_on_cpu() helper
authorThomas Gleixner <tglx@linutronix.de>
Mon, 24 Feb 2020 14:01:41 +0000 (15:01 +0100)
committerAlexei Starovoitov <ast@kernel.org>
Tue, 25 Feb 2020 00:20:05 +0000 (16:20 -0800)
commit3c58482a382bae89410439247152eb342e9872f7
tree36943f70dc78e8dae90117db6dd41c6ceaf233b0
parent569de905ebc30b9c61be7aa557403aeb5a9141a4
bpf: Provide bpf_prog_run_pin_on_cpu() helper

BPF programs require to run on one CPU to completion as they use per CPU
storage, but according to Alexei they don't need reentrancy protection as
obviously BPF programs running in thread context can always be 'preempted'
by hard and soft interrupts and instrumentation and the same program can
run concurrently on a different CPU.

The currently used mechanism to ensure CPUness is to wrap the invocation
into a preempt_disable/enable() pair. Disabling preemption is also
disabling migration for a task.

preempt_disable/enable() is used because there is no explicit way to
reliably disable only migration.

Provide a separate macro to invoke a BPF program which can be used in
migrateable task context.

It wraps BPF_PROG_RUN() in a migrate_disable/enable() pair which maps on
non RT enabled kernels to preempt_disable/enable(). On RT enabled kernels
this merely disables migration. Both methods ensure that the invoked BPF
program runs on one CPU to completion.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20200224145643.474592620@linutronix.de
include/linux/filter.h