Skip to content

bpf: implement bpf_get_current_cgroup_id() helper

Yonghong Song netdev 2 versions Applied

Status from this message: Applied, Thanks.

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest3 patches 4 repliesApplied
  2. v13 patches 2 repliesSuperseded

Changes in v2 from the cover letter

. rebase to resolve merge conflict with latest bpf-next.

Patches in v2 Applied

#Subject and filesSizeRepliesApplied
1/3bpf: implement bpf_get_current_cgroup_id() helperinclude/linux/bpf.h include/uapi/linux/bpf.h kernel/bpf/core.c +2 more+26 -13 replies
2/3tools/bpf: sync uapi bpf.h for bpf_get_current_cgroup_id() helpertools/include/uapi/linux/bpf.h tools/testing/selftests/bpf/bpf_helpers.h+9 -10 replies
3/3tools/bpf: add a selftest for bpf_get_current_cgroup_id() helpertools/testing/selftests/bpf/.gitignore tools/testing/selftests/bpf/Makefile tools/testing/selftests/bpf/cgroup_helpers.c +3 more+232 -20 replies

Reviews trailers per patch

All 3 patches have a Reviewed-by or Acked-by.

PatchAlexei Starovoitov
1/3A-b
2/3A-b
3/3A-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v2 thread

Cover letter [PATCH net-next v2 0/3] bpf: implement bpf_get_current_cgroup_id() helper

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
Signature · 1 line
2.9.5