bpf: Remove trace_printk_lock
authorJiri Olsa <jolsa@kernel.org>
Thu, 15 Dec 2022 21:44:30 +0000 (22:44 +0100)
committerDaniel Borkmann <daniel@iogearbox.net>
Mon, 19 Dec 2022 21:08:37 +0000 (22:08 +0100)
commite2bb9e01d589f7fa82573aedd2765ff9b277816a
tree2e4f31e746c2d7efa4abc68daad8030d09166c22
parentf19a4050455aad847fb93f18dc1fe502eb60f989
bpf: Remove trace_printk_lock

Both bpf_trace_printk and bpf_trace_vprintk helpers use static buffer guarded
with trace_printk_lock spin lock.

The spin lock contention causes issues with bpf programs attached to
contention_begin tracepoint [1][2].

Andrii suggested we could get rid of the contention by using trylock, but we
could actually get rid of the spinlock completely by using percpu buffers the
same way as for bin_args in bpf_bprintf_prepare function.

Adding new return 'buf' argument to struct bpf_bprintf_data and making
bpf_bprintf_prepare to return also the buffer for printk helpers.

  [1] https://lore.kernel.org/bpf/CACkBjsakT_yWxnSWr4r-0TpPvbKm9-OBmVUhJb7hV3hY8fdCkw@mail.gmail.com/
  [2] https://lore.kernel.org/bpf/CACkBjsaCsTovQHFfkqJKto6S4Z8d02ud1D7MPESrHa1cVNNTrw@mail.gmail.com/

Reported-by: Hao Sun <sunhao.th@gmail.com>
Suggested-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Yonghong Song <yhs@fb.com>
Link: https://lore.kernel.org/bpf/20221215214430.1336195-4-jolsa@kernel.org
include/linux/bpf.h
kernel/bpf/helpers.c
kernel/trace/bpf_trace.c