Skip to content
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

v0.9 backports 20230627 #1149

Merged
merged 5 commits into from
Jun 28, 2023
Merged

v0.9 backports 20230627 #1149

merged 5 commits into from
Jun 28, 2023

Conversation

kkourt
Copy link
Contributor

@kkourt kkourt commented Jun 27, 2023

Commits for pr #1012 (tetragon: Use do_task_dead probe for exit sensor):

  • efbcfa1 tetragon: Use do_task_dead probe for exit
  • 0646c56 tetragon: Add more thread to TestExitLeader

Commits for pr #1090 (Fix memory corruption bug):

  • 590a524 bpf: OpenMap do not leak fd
  • 2df044e observer_stats: use GetNumPossibleCPUs()
  • 0ffc6c6 updateMapMetric: close maps on errors
  • 8f19ada testObserverOptions: remove unused pretty field was not backported, due to conflicts

olsajiri and others added 5 commits June 27, 2023 17:54
[ upstream commit efbcfa1 ]

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(&current->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>
Signed-off-by: Kornilios Kourtis <kornilios@isovalent.com>
[ upstream commit 0646c56 ]

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>
Signed-off-by: Kornilios Kourtis <kornilios@isovalent.com>
[ upstream commit 590a524 ]

Close fds in case of returning with an error.

Signed-off-by: Kornilios Kourtis <kornilios@isovalent.com>
[ upstream commit 2df044e ]

runtime.NumCPU() returns the number of CPUs available to the process.
This excludes offline CPUs, but also does not take into acount task CPU
affinity.

For example:

```
$ cat numcpus.go
package main

import (
        "fmt"
        "runtime"
)

func main() {
        fmt.Printf("%d\n", runtime.NumCPU())
}
$ go run numcpus.go
16
$ taskset --cpu-list 0 go run numcpus.go
1
```

This leads to memory corruption because we pass to the bpf() call a
buffer smaller than the write it will perform, leading to data being
overwritten. Reducing the timeout of the goroutine that reads stat maps
will reproduce this quickly and lead to SIGSEGVs, corrupted prometheus
metrics or other symptoms.

Signed-off-by: Kornilios Kourtis <kornilios@isovalent.com>
[ upstream commit 0ffc6c6 ]

create updateMapMetric() function to update the metrics for a single
map. This allows to use defer() to do proper cleanup in case of an error.

Signed-off-by: Kornilios Kourtis <kornilios@isovalent.com>
@kkourt kkourt requested a review from a team as a code owner June 27, 2023 15:58
@kkourt kkourt requested review from mtardy and removed request for a team June 27, 2023 15:58
@olsajiri olsajiri self-requested a review June 28, 2023 13:08
Copy link
Member

@mtardy mtardy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looked quickly but the backports seem 👌

@kkourt kkourt merged commit 8e059b2 into v0.9 Jun 28, 2023
15 checks passed
@kkourt kkourt deleted the pr/kkourt/v0.9-backports-20230627 branch June 28, 2023 13:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants