netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next v2 0/3] bpf: implement bpf_get_current_cgroup_id() helper
@ 2018-06-03 22:59 Yonghong Song
  2018-06-03 22:59 ` [PATCH net-next v2 1/3] " Yonghong Song
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Yonghong Song @ 2018-06-03 22:59 UTC (permalink / raw)
  To: ast, daniel, netdev; +Cc: kernel-team

bpf has been used extensively for tracing. For example, bcc
contains an almost full set of bpf-based tools to trace kernel
and user functions/events. Most tracing tools are currently
either filtered based on pid or system-wide.

Containers have been used quite extensively in industry and
cgroup is often used together to provide resource isolation
and protection. Several processes may run inside the same
container. It is often desirable to get container-level tracing
results as well, e.g. syscall count, function count, I/O
activity, etc.

This patch implements a new helper, bpf_get_current_cgroup_id(),
which will return cgroup id based on the cgroup within which
the current task is running.

Patch #1 implements the new helper in the kernel.
Patch #2 syncs the uapi bpf.h header and helper between tools
and kernel.
Patch #3 shows how to get the same cgroup id in user space,
so a filter or policy could be configgured in the bpf program
based on current task cgroup.

Changelog:
  v1 -> v2:
     . rebase to resolve merge conflict with latest bpf-next.

Yonghong Song (3):
  bpf: implement bpf_get_current_cgroup_id() helper
  tools/bpf: sync uapi bpf.h for bpf_get_current_cgroup_id() helper
  tools/bpf: add a selftest for bpf_get_current_cgroup_id() helper

 include/linux/bpf.h                              |   1 +
 include/uapi/linux/bpf.h                         |   8 +-
 kernel/bpf/core.c                                |   1 +
 kernel/bpf/helpers.c                             |  15 +++
 kernel/trace/bpf_trace.c                         |   2 +
 tools/include/uapi/linux/bpf.h                   |   8 +-
 tools/testing/selftests/bpf/.gitignore           |   1 +
 tools/testing/selftests/bpf/Makefile             |   6 +-
 tools/testing/selftests/bpf/bpf_helpers.h        |   2 +
 tools/testing/selftests/bpf/cgroup_helpers.c     |  57 +++++++++
 tools/testing/selftests/bpf/cgroup_helpers.h     |   1 +
 tools/testing/selftests/bpf/get_cgroup_id_kern.c |  28 +++++
 tools/testing/selftests/bpf/get_cgroup_id_user.c | 141 +++++++++++++++++++++++
 13 files changed, 267 insertions(+), 4 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/get_cgroup_id_kern.c
 create mode 100644 tools/testing/selftests/bpf/get_cgroup_id_user.c

-- 
2.9.5

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2018-06-04 15:11 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-03 22:59 [PATCH net-next v2 0/3] bpf: implement bpf_get_current_cgroup_id() helper Yonghong Song
2018-06-03 22:59 ` [PATCH net-next v2 1/3] " Yonghong Song
2018-06-04  9:08   ` Daniel Borkmann
2018-06-04 14:58     ` Alexei Starovoitov
2018-06-04 15:11       ` Yonghong Song
2018-06-03 22:59 ` [PATCH net-next v2 2/3] tools/bpf: sync uapi bpf.h for " Yonghong Song
2018-06-03 22:59 ` [PATCH net-next v2 3/3] tools/bpf: add a selftest " Yonghong Song
2018-06-04  1:27 ` [PATCH net-next v2 0/3] bpf: implement " Alexei Starovoitov

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).