Skip to content

RFC bpf: cgroup: support writing and freezing cgroups from BPF

Djalal Harouni bpf cgroups linux-kselftest 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v2 RFC Latest3 patches 12 repliesIn review

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3kernfs: cgroup: support writing cgroup interfaces from a kernfs nodeinclude/linux/cgroup.h kernel/cgroup/cgroup.c+99 -60 replies
2/3bpf: cgroup: Add BPF Kfunc to write and freeze a cgroupkernel/bpf/helpers.c+45 -00 replies
3/3selftests/bpf: add selftest for bpf_cgroup_write_interfacetools/testing/selftests/bpf/prog_tests/task_freeze_cgroup.c tools/testing/selftests/bpf/progs/test_task_freeze_cgroup.c+327 -00 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v2 yet.

Read the v2 thread

Cover letter [RFC PATCH v2 bpf-next 0/3] bpf: cgroup: support writing and freezing cgroups from BPF

This patch series add support to write cgroup interfaces from BPF.

It is useful to freeze a cgroup hierarchy on suspicious activity for a more thorough analysis before killing it. Planned users of this feature are: systemd and BPF tools where the cgroup hierarchy could be a system service, user session, k8s pod or a container.

The writing happens via kernfs nodes and the cgroup must be on the default hierarchy. It implements the requests and feedback from v1 [1] where now we use a unified path for cgroup user space and BPF writing.

So I want to validate that this is the right approach first.

Todo:
* Limit size of data to be written.
* Further tests.
* Add cgroup kill support.

# RFC v1 -> v2

* Implemented Alexei and Tejun requests [1].
* Unified path where user space or BPF writing end up taking directly a kernfs_node with an example on the "cgroup.freeze" interface.

[1] https://lore.kernel.org/bpf/[email protected]/

Djalal Harouni (3):
kernfs: cgroup: support writing cgroup interfaces from a kernfs node
bpf: cgroup: Add BPF Kfunc to write cgroup interfaces selftests/bpf: add selftest for bpf_cgroup_write_interface

 include/linux/cgroup.h                                      |   3 ++
 kernel/bpf/helpers.c                                        |  45 +++++
 kernel/cgroup/cgroup.c                                      | 102 +++++++
 tools/testing/selftests/bpf/prog_tests/task_freeze_cgroup.c | 172 ++++++++++++
 tools/testing/selftests/bpf/progs/test_task_freeze_cgroup.c | 155 ++++++++++
 5 files changed, 471 insertions(+), 6 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/prog_tests/task_freeze_cgroup.c
 create mode 100644 tools/testing/selftests/bpf/progs/test_task_freeze_cgroup.c
Signature · 1 line
2.34.1