mbox series

[RFC,bpf-next,0/3] bpf: Expand bpf_cgrp_storage to support cgroup1 non-attach case

Message ID 20231205143725.4224-1-laoar.shao@gmail.com (mailing list archive)
Headers show
Series bpf: Expand bpf_cgrp_storage to support cgroup1 non-attach case | expand

Message

Yafang Shao Dec. 5, 2023, 2:37 p.m. UTC
In the current cgroup1 environment, associating operations between a cgroup
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.

Yafang Shao (3):
  bpf: Enable bpf_cgrp_storage for cgroup1 non-attach case
  selftests/bpf: Add a new cgroup helper open_classid()
  selftests/bpf: Add selftests for cgroup1 local storage

 kernel/bpf/bpf_cgrp_storage.c                      |  6 +-
 tools/testing/selftests/bpf/cgroup_helpers.c       | 16 ++++
 tools/testing/selftests/bpf/cgroup_helpers.h       |  1 +
 .../selftests/bpf/prog_tests/cgrp_local_storage.c  | 92 +++++++++++++++++++++-
 .../selftests/bpf/progs/cgrp_ls_recursion.c        | 84 ++++++++++++++++----
 .../selftests/bpf/progs/cgrp_ls_sleepable.c        | 67 ++++++++++++++--
 tools/testing/selftests/bpf/progs/cgrp_ls_tp_btf.c | 82 +++++++++++++------
 7 files changed, 298 insertions(+), 50 deletions(-)

Comments

Tejun Heo Dec. 5, 2023, 5:15 p.m. UTC | #1
On Tue, Dec 05, 2023 at 02:37:22PM +0000, Yafang Shao wrote:
> In the current cgroup1 environment, associating operations between a cgroup
> 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.
> 
> Yafang Shao (3):
>   bpf: Enable bpf_cgrp_storage for cgroup1 non-attach case
>   selftests/bpf: Add a new cgroup helper open_classid()
>   selftests/bpf: Add selftests for cgroup1 local storage

Acked-by: Tejun Heo <tj@kernel.org>

Thanks.
Alexei Starovoitov Dec. 6, 2023, 2:47 a.m. UTC | #2
On Tue, Dec 5, 2023 at 9:15 AM Tejun Heo <tj@kernel.org> wrote:
>
> On Tue, Dec 05, 2023 at 02:37:22PM +0000, Yafang Shao wrote:
> > In the current cgroup1 environment, associating operations between a cgroup
> > 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.
> >
> > Yafang Shao (3):
> >   bpf: Enable bpf_cgrp_storage for cgroup1 non-attach case
> >   selftests/bpf: Add a new cgroup helper open_classid()
> >   selftests/bpf: Add selftests for cgroup1 local storage
>
> Acked-by: Tejun Heo <tj@kernel.org>


Yafang,
please resubmit without RFC tag, so it can get tested by BPF CI.
Yafang Shao Dec. 6, 2023, 3:01 a.m. UTC | #3
On Wed, Dec 6, 2023 at 10:47 AM Alexei Starovoitov
<alexei.starovoitov@gmail.com> wrote:
>
> On Tue, Dec 5, 2023 at 9:15 AM Tejun Heo <tj@kernel.org> wrote:
> >
> > On Tue, Dec 05, 2023 at 02:37:22PM +0000, Yafang Shao wrote:
> > > In the current cgroup1 environment, associating operations between a cgroup
> > > 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.
> > >
> > > Yafang Shao (3):
> > >   bpf: Enable bpf_cgrp_storage for cgroup1 non-attach case
> > >   selftests/bpf: Add a new cgroup helper open_classid()
> > >   selftests/bpf: Add selftests for cgroup1 local storage
> >
> > Acked-by: Tejun Heo <tj@kernel.org>
>
>
> Yafang,
> please resubmit without RFC tag, so it can get tested by BPF CI.

will do it.