From: Yonghong Song <yhs@fb.com>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: bpf <bpf@vger.kernel.org>, Alexei Starovoitov <ast@fb.com>,
"Daniel Borkmann" <daniel@iogearbox.net>,
Kernel Team <Kernel-team@fb.com>
Subject: Re: [PATCH bpf-next 1/2] bpf: add bpf_send_signal_thread() helper
Date: Tue, 14 Jan 2020 01:15:20 +0000 [thread overview]
Message-ID: <3eefa7f2-438f-9eda-b573-a8b2d0699441@fb.com> (raw)
In-Reply-To: <CAEf4Bzab0S_cXb3sJNaOFZ7gSrp8u5Y2Q+dmA4BWrqiXmYx7Gw@mail.gmail.com>
On 1/13/20 4:58 PM, Andrii Nakryiko wrote:
> On Thu, Jan 9, 2020 at 5:16 PM Yonghong Song <yhs@fb.com> wrote:
>>
>> 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.
>>
>> 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 current thread. 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>
>> ---
>> include/uapi/linux/bpf.h | 18 ++++++++++++++++--
>> kernel/trace/bpf_trace.c | 27 ++++++++++++++++++++++++---
>> 2 files changed, 40 insertions(+), 5 deletions(-)
>>
>> diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
>> index 52966e758fe5..3320f8bdfe7e 100644
>> --- a/include/uapi/linux/bpf.h
>> +++ b/include/uapi/linux/bpf.h
>> @@ -2714,7 +2714,7 @@ union bpf_attr {
>> *
>> * int bpf_send_signal(u32 sig)
>> * Description
>> - * Send signal *sig* to the current task.
>> + * Send signal *sig* to the process of the current task.
>> * Return
>> * 0 on success or successfully queued.
>> *
>> @@ -2850,6 +2850,19 @@ union bpf_attr {
>> * Return
>> * 0 on success, or a negative error in case of failure.
>> *
>> + * int bpf_send_signal_thread(u32 sig)
>> + * Description
>> + * Send signal *sig* to the current task.
>
>
> This all makes sense and looks good, but I think it's very unclear why
> the distinction between sending signal to process vs thread. Could you
> extend bpf_send_signal and bpf_send_signal_thread descriptions
> explaining the difference (e.g., that, according to POSIX, when
> sending signal to a process, any thread within that process can get
> signal delivered, while sending to a specific thread will ensure that
> that specific thread will receive desired signal).
Sounds good. Will send v2 with better descriptions later.
>
> [...]
>
next prev parent reply other threads:[~2020-01-14 1:15 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-10 1:15 [PATCH bpf-next 0/2] bpf: add bpf_send_signal_thread() helper Yonghong Song
2020-01-10 1:15 ` [PATCH bpf-next 1/2] " Yonghong Song
2020-01-14 0:58 ` Andrii Nakryiko
2020-01-14 1:15 ` Yonghong Song [this message]
2020-01-10 1:15 ` [PATCH bpf-next 2/2] tools/bpf: add a selftest for bpf_send_signal_thread() Yonghong Song
2020-01-14 1:19 ` Andrii Nakryiko
2020-01-14 1:22 ` Yonghong Song
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3eefa7f2-438f-9eda-b573-a8b2d0699441@fb.com \
--to=yhs@fb.com \
--cc=Kernel-team@fb.com \
--cc=andrii.nakryiko@gmail.com \
--cc=ast@fb.com \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).