OSDN Git Service

bpf: Add bpf_send_signal_thread() helper
authorYonghong Song <yhs@fb.com>
Wed, 15 Jan 2020 03:50:02 +0000 (19:50 -0800)
committerAlexei Starovoitov <ast@kernel.org>
Wed, 15 Jan 2020 19:44:51 +0000 (11:44 -0800)
commit8482941f09067da42f9c3362e15bfb3f3c19d610
tree66bbf4957c6b903a77ab29ff8fa2a4104cd32e09
parentd3a56931f9c8644a52e7a6735954c84ea895e8c3
bpf: Add bpf_send_signal_thread() helper

Commit 8b401f9ed244 ("bpf: implement bpf_send_signal() helper")
added helper bpf_send_signal() which permits bpf program to
send a signal to the current process. The signal may be
delivered to any threads in the process.

We found a use case where sending the signal to the current
thread is more preferable.
  - A bpf program will collect the stack trace and then
    send signal to the user application.
  - The user application will add some thread specific
    information to the just collected stack trace for
    later analysis.

If bpf_send_signal() is used, user application will need
to check whether the thread receiving the signal matches
the thread collecting the stack by checking thread id.
If not, it will need to send signal to another thread
through pthread_kill().

This patch proposed a new helper bpf_send_signal_thread(),
which sends the signal to the thread corresponding to
the current kernel task. This way, user space is guaranteed that
bpf_program execution context and user space signal handling
context are the same thread.

Signed-off-by: Yonghong Song <yhs@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20200115035002.602336-1-yhs@fb.com
include/uapi/linux/bpf.h
kernel/trace/bpf_trace.c
tools/include/uapi/linux/bpf.h