bpf: Replace open coded recursion prevention in sys_bpf()
authorThomas Gleixner <tglx@linutronix.de>
Mon, 24 Feb 2020 14:01:49 +0000 (15:01 +0100)
committerAlexei Starovoitov <ast@kernel.org>
Tue, 25 Feb 2020 00:20:10 +0000 (16:20 -0800)
commitb6e5dae15a61b0cc9219799926813baad0b58967
tree54d5a5804fe457956725474e079ec989054cba3c
parent085fee1a72a9fba101a4a68a2c02fa8bd2b6f913
bpf: Replace open coded recursion prevention in sys_bpf()

The required protection is that the caller cannot be migrated to a
different CPU as these functions end up in places which take either a hash
bucket lock or might trigger a kprobe inside the memory allocator. Both
scenarios can lead to deadlocks. The deadlock prevention is per CPU by
incrementing a per CPU variable which temporarily blocks the invocation of
BPF programs from perf and kprobes.

Replace the open coded preempt_[dis|en]able and __this_cpu_[inc|dec] pairs
with the new helper functions. These functions are already prepared to make
BPF work on PREEMPT_RT enabled kernels. No functional change for !RT
kernels.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20200224145644.317843926@linutronix.de
kernel/bpf/syscall.c