samples/bpf: Add test_current_task_under_cgroup test
authorSargun Dhillon <sargun@sargun.me>
Fri, 12 Aug 2016 15:57:04 +0000 (08:57 -0700)
committerDavid S. Miller <davem@davemloft.net>
Sat, 13 Aug 2016 04:49:42 +0000 (21:49 -0700)
commit9e6e60ecbd7323d4ac3f98dcdc1bd2c527a736ef
tree249b8cc8c37b46570ca05305aaa0c5ab79c28cee
parent60d20f9195b260bdf0ac10c275ae9f6016f9c069
samples/bpf: Add test_current_task_under_cgroup test

This test has a BPF program which writes the last known pid to call the
sync syscall within a given cgroup to a map.

The user mode program creates its own mount namespace, and mounts the
cgroupsv2  hierarchy in there, as on all current test systems
(Ubuntu 16.04, Debian), the cgroupsv2 vfs is unmounted by default.
Once it does this, it proceeds to test.

The test checks for positive and negative condition. It ensures that
when it's part of a given cgroup, its pid is captured in the map,
and that when it leaves the cgroup, this doesn't happen.

It populate a cgroups arraymap prior to execution in userspace. This means
that the program must be run in the same cgroups namespace as the programs
that are being traced.

Signed-off-by: Sargun Dhillon <sargun@sargun.me>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: Tejun Heo <tj@kernel.org>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
samples/bpf/Makefile
samples/bpf/bpf_helpers.h
samples/bpf/test_current_task_under_cgroup_kern.c [new file with mode: 0644]
samples/bpf/test_current_task_under_cgroup_user.c [new file with mode: 0644]