android_kernel_sony_sdm845/kernel/cgroup
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Andrey Ignatov a72e6bf1f5 BACKPORT: bpf: Support replacing cgroup-bpf program in MULTI mode
The common use-case in production is to have multiple cgroup-bpf
programs per attach type that cover multiple use-cases. Such programs
are attached with BPF_F_ALLOW_MULTI and can be maintained by different
people.

Order of programs usually matters, for example imagine two egress
programs: the first one drops packets and the second one counts packets.
If they're swapped the result of counting program will be different.

It brings operational challenges with updating cgroup-bpf program(s)
attached with BPF_F_ALLOW_MULTI since there is no way to replace a
program:

* One way to update is to detach all programs first and then attach the
  new version(s) again in the right order. This introduces an
  interruption in the work a program is doing and may not be acceptable
  (e.g. if it's egress firewall);

* Another way is attach the new version of a program first and only then
  detach the old version. This introduces the time interval when two
  versions of same program are working, what may not be acceptable if a
  program is not idempotent. It also imposes additional burden on
  program developers to make sure that two versions of their program can
  co-exist.

Solve the problem by introducing a "replace" mode in BPF_PROG_ATTACH
command for cgroup-bpf programs being attached with BPF_F_ALLOW_MULTI
flag. This mode is enabled by newly introduced BPF_F_REPLACE attach flag
and bpf_attr.replace_bpf_fd attribute to pass fd of the old program to
replace

That way user can replace any program among those attached with
BPF_F_ALLOW_MULTI flag without the problems described above.

Details of the new API:

* If BPF_F_REPLACE is set but replace_bpf_fd doesn't have valid
  descriptor of BPF program, BPF_PROG_ATTACH will return corresponding
  error (EINVAL or EBADF).

* If replace_bpf_fd has valid descriptor of BPF program but such a
  program is not attached to specified cgroup, BPF_PROG_ATTACH will
  return ENOENT.

BPF_F_REPLACE is introduced to make the user intent clear, since
replace_bpf_fd alone can't be used for this (its default value, 0, is a
valid fd). BPF_F_REPLACE also makes it possible to extend the API in the
future (e.g. add BPF_F_BEFORE and BPF_F_AFTER if needed).

Change-Id: I4ff69b3a12eb8672a6e0fdde4decfaafbb00cd3b
Signed-off-by: Andrey Ignatov <rdna@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Martin KaFai Lau <kafai@fb.com>
Acked-by: Andrii Narkyiko <andriin@fb.com>
Link: https://lore.kernel.org/bpf/30cd850044a0057bdfcaaf154b7d2f39850ba813.1576741281.git.rdna@fb.com
Signed-off-by: Sorayukii <sorayukii69@gmail.com>
2026-05-15 17:59:23 +07:00
..
cgroup-internal.h BACKPORT: cgroup: implement __cgroup_task_count() helper 2026-05-15 17:50:46 +07:00
cgroup-v1.c BACKPORT: cgroup: implement __cgroup_task_count() helper 2026-05-15 17:50:46 +07:00
cgroup.c BACKPORT: bpf: Support replacing cgroup-bpf program in MULTI mode 2026-05-15 17:59:23 +07:00
cpuset.c cpuset: Remove cpus_allowed/mems_allowed setup in cpuset_init_smp() 2026-05-15 17:50:42 +07:00
debug.c cgroup: update debug controller to print out thread mode information 2026-05-15 17:50:37 +07:00
freezer.c BACKPORT: cgroup: cgroup v2 freezer 2026-05-15 17:50:46 +07:00
legacy_freezer.c BACKPORT: cgroup: rename freezer.c into legacy_freezer.c 2026-05-15 17:50:46 +07:00
Makefile BACKPORT: cgroup: cgroup v2 freezer 2026-05-15 17:50:46 +07:00
namespace.c kernel: convert cgroup_namespace.count from atomic_t to refcount_t 2026-05-15 17:50:33 +07:00
pids.c BACKPORT: treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 451 2026-05-15 17:57:56 +07:00
rdma.c cgroup: Fixed rdmacg uninitialized current resource usage 2026-05-15 17:50:32 +07:00