bpf: Avoid hashtab deadlock with map_locked
authorSong Liu <songliubraving@fb.com>
Thu, 29 Oct 2020 07:19:25 +0000 (00:19 -0700)
committerAlexei Starovoitov <ast@kernel.org>
Fri, 30 Oct 2020 20:03:29 +0000 (13:03 -0700)
commit20b6cc34ea74b6a84599c1f8a70f3315b56a1883
treed3a5f38e379c3a12c5592aeec15e1806e9a26403
parentc50eb518e262fa06bd334e6eec172eaf5d7a5bd9
bpf: Avoid hashtab deadlock with map_locked

If a hashtab is accessed in both non-NMI and NMI context, the system may
deadlock on bucket->lock. Fix this issue with percpu counter map_locked.
map_locked rejects concurrent access to the same bucket from the same CPU.
To reduce memory overhead, map_locked is not added per bucket. Instead,
8 percpu counters are added to each hashtab. buckets are assigned to these
counters based on the lower bits of its hash.

Signed-off-by: Song Liu <songliubraving@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20201029071925.3103400-3-songliubraving@fb.com
kernel/bpf/hashtab.c