OSDN Git Service

bpf: Provide recursion prevention helpers
authorThomas Gleixner <tglx@linutronix.de>
Mon, 24 Feb 2020 14:01:47 +0000 (15:01 +0100)
committerAlexei Starovoitov <ast@kernel.org>
Tue, 25 Feb 2020 00:20:09 +0000 (16:20 -0800)
commitc518cfa0c5ad75ddf3d743f1e35b9cf5fc2c346e
treedc1af99817725ada8e5cae4c91e49dd113d41d0b
parent2a916f2f546ca1c1e3323e2a4269307f6d9890eb
bpf: Provide recursion prevention helpers

The places which need to prevent the execution of trace type BPF programs
to prevent deadlocks on the hash bucket lock do this open coded.

Provide two inline functions, bpf_disable/enable_instrumentation() to
replace these open coded protection constructs.

Use migrate_disable/enable() instead of preempt_disable/enable() right away
so this works on RT enabled kernels. On a !RT kernel migrate_disable /
enable() are mapped to preempt_disable/enable().

These helpers use this_cpu_inc/dec() instead of __this_cpu_inc/dec() on an
RT enabled kernel because migrate disabled regions are preemptible and
preemption might hit in the middle of a RMW operation which can lead to
inconsistent state.

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