Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

bpf: Enable bpf_cgrp_storage for cgroup1 non-attach case

In the current cgroup1 environment, associating operations between cgroups
and applications in a BPF program requires storing a mapping of cgroup_id
to application either in a hash map or maintaining it in userspace.
However, by enabling bpf_cgrp_storage for cgroup1, it becomes possible to
conveniently store application-specific information in cgroup-local storage
and utilize it within BPF programs. Furthermore, enabling this feature for
cgroup1 involves minor modifications for the non-attach case, streamlining
the process.

However, when it comes to enabling this functionality for the cgroup1
attach case, it presents challenges. Therefore, the decision is to focus on
enabling it solely for the cgroup1 non-attach case at present. If
attempting to attach to a cgroup1 fd, the operation will simply fail with
the error code -EBADF.

Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
Acked-by: Tejun Heo <tj@kernel.org>
Acked-by: Yonghong Song <yonghong.song@linux.dev>
Link: https://lore.kernel.org/r/20231206115326.4295-2-laoar.shao@gmail.com
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>

authored by

Yafang Shao and committed by
Martin KaFai Lau
73d9eb34 1720c42b

+3 -3
+3 -3
kernel/bpf/bpf_cgrp_storage.c
··· 82 82 int fd; 83 83 84 84 fd = *(int *)key; 85 - cgroup = cgroup_get_from_fd(fd); 85 + cgroup = cgroup_v1v2_get_from_fd(fd); 86 86 if (IS_ERR(cgroup)) 87 87 return ERR_CAST(cgroup); 88 88 ··· 101 101 int fd; 102 102 103 103 fd = *(int *)key; 104 - cgroup = cgroup_get_from_fd(fd); 104 + cgroup = cgroup_v1v2_get_from_fd(fd); 105 105 if (IS_ERR(cgroup)) 106 106 return PTR_ERR(cgroup); 107 107 ··· 131 131 int err, fd; 132 132 133 133 fd = *(int *)key; 134 - cgroup = cgroup_get_from_fd(fd); 134 + cgroup = cgroup_v1v2_get_from_fd(fd); 135 135 if (IS_ERR(cgroup)) 136 136 return PTR_ERR(cgroup); 137 137