New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tetragon: Use do_task_dead probe for exit sensor #1012
Conversation
✅ Deploy Preview for tetragon ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
de59db0
to
bb3b292
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lgtm , thank you ;-)
failure is not related to this PR as it is tracked here: #1025 |
66517d9
to
ebc157f
Compare
Hooking on do_task_dead kernel function, which is the last one the task would execute after exiting. It's stable since v4.19, so it's safe to hook for us. To find out if we are the last thread of execution in the task we use current->signal->live counter (thanks Djalal! ;-) ) It's initialized for thread leader: clone { copy_process copy_signal atomic_set(&sig->live, 1); } Incremented for each new thread: clone { copy_process atomic_inc(¤t->signal->live); ... wake_up_new_task } Decremented for each exiting thread: do_exit { atomic_dec_and_test(&tsk->signal->live); ... do_task_dead __schedule BUG } If task->signal->live == 0 we are the last thread of execution and we won't race with another clone, because there's no other thread to call it (current thread is in do_exit). Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Adding extra threads to the exit-leader test prog. Spawning 2 threads directly from leader and another 2 from the newly created threads. Signed-off-by: Jiri Olsa <jolsa@kernel.org>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool! Thanks!
* | ||
* If task->signal->live == 0 we are the last thread of execution and we | ||
* won't race with another clone, because there's no other thread to call | ||
* it (current thread is in do_exit). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the nice comment :)
Hooking on do_task_dead kernel function, which is the last one the
task would execute after exiting. It's stable since v4.19, so it's
safe to hook for us.
To find out if we are the last thread of execution in the task we
use current->signal->live counter (thanks Djalal! ;-) )
It's initialized for thread leader:
Incremented for each new thread:
Decremented for each exiting thread:
If task->signal->live == 0 we are the last thread of execution and we
won't race with another clone, because there's no other thread to call
it (current thread is in do_exit).