public inbox for cgroups@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 bpf-next 00/11] bpf, cgroup: Add BPF support for cgroup1 hierarchy
@ 2023-10-29  6:14 Yafang Shao
  2023-10-29  6:14 ` [PATCH v3 bpf-next 01/11] cgroup: Remove unnecessary list_empty() Yafang Shao
                   ` (12 more replies)
  0 siblings, 13 replies; 46+ messages in thread
From: Yafang Shao @ 2023-10-29  6:14 UTC (permalink / raw)
  To: ast, daniel, john.fastabend, andrii, martin.lau, song,
	yonghong.song, kpsingh, sdf, haoluo, jolsa, tj, lizefan.x, hannes,
	yosryahmed, mkoutny, sinquersw, longman
  Cc: cgroups, bpf, oliver.sang, Yafang Shao

Currently, BPF is primarily confined to cgroup2, with the exception of
cgroup_iter, which supports cgroup1 fds. Unfortunately, this limitation
prevents us from harnessing the full potential of BPF within cgroup1
environments.

In our endeavor to seamlessly integrate BPF within our Kubernetes
environment, which relies on cgroup1, we have been exploring the
possibility of transitioning to cgroup2. While this transition is
forward-looking, it poses challenges due to the necessity for numerous
applications to adapt.

While we acknowledge that cgroup2 represents the future, we also recognize
that such transitions demand time and effort. As a result, we are
considering an alternative approach. Instead of migrating to cgroup2, we
are contemplating modifications to the BPF kernel code to ensure
compatibility with cgroup1. These adjustments appear to be relatively
minor, making this option more feasible.

As discussed with Tejun[0], it has been determined that tying the interface
directly to the cgroup1 hierarchies is acceptable. As a result, this
patchset introduces cgroup1-only interfaces that operate with both
hierarchy ID and cgroup ID as parameters.

Within this patchset, a new cgroup1-only interface have been introduced,
which is also suggested by Tejun.

- [bpf_]task_get_cgroup1
  Acquires the associated cgroup of a task within a specific cgroup1
  hierarchy. The cgroup1 hierarchy is identified by its hierarchy ID.

This new kfunc enables the tracing of tasks within a designated container
or its ancestor cgroup directory in BPF programs. Additionally, it is
capable of operating on named cgroups, providing valuable utility for
hybrid cgroup mode scenarios.

To enable the use of this new kfunc in non-sleepable contexts, we need to
eliminate the reliance on the cgroup_mutex. Consequently, the cgroup
root_list is made RCU-safe, allowing us to replace the cgroup_mutex with
RCU read lock in specific paths. This enhancement can also bring
benefits to common operations in a production environment, such as
`cat /proc/self/cgroup`. As pointed out by Michal, we can further
replace cgroup_mutex with the RCU read lock in other paths like
cgroup_path_ns(), but it necessitates some refactoring, so I prefer to
address it in a separate patchset.

[0]. https://lwn.net/ml/cgroups/ZRHU6MfwqRxjBFUH@slm.duckdns.org/

Changes:
- RFC v2 -> v3:
  - Use [bpf_]task_get_cgroup1 instead (Tejun)
  - Skip the unmounted cgroup in /proc/self/cgroup (Tejun)
  - Fix lockdep_is_held() in list_for_each_entry_rcu()
    (Tejun, oliver.sang@intel.com)
  - Drop the warning in __cset_cgroup_from_root()(Tejun) 
  - Fix mismatched comments (Tejun, lkp@intel.com)
  - Add a explicit warning in current_cgns_cgroup_from_root (Michal)
- RFC v1 -> RFC v2:
  - Introduce a new kunc to get cgroup kptr instead of getting the cgrp ID
    (Tejun)
  - Eliminate the cgroup_mutex by making cgroup root_list RCU-safe, as
    disccussed with Michal 
- RFC v1: bpf, cgroup: Add BPF support for cgroup1 hierarchy
  https://lwn.net/Articles/947130/
- bpf, cgroup: Add bpf support for cgroup controller
  https://lwn.net/Articles/945318/
- bpf, cgroup: Enable cgroup_array map on cgroup1
  https://lore.kernel.org/bpf/20230903142800.3870-1-laoar.shao@gmail.com

Yafang Shao (11):
  cgroup: Remove unnecessary list_empty()
  cgroup: Make operations on the cgroup root_list RCU safe
  cgroup: Eliminate the need for cgroup_mutex in proc_cgroup_show()
  cgroup: Add annotation for holding namespace_sem in
    current_cgns_cgroup_from_root()
  cgroup: Add a new helper for cgroup1 hierarchy
  bpf: Add a new kfunc for cgroup1 hierarchy
  selftests/bpf: Fix issues in setup_classid_environment()
  selftests/bpf: Add parallel support for classid
  selftests/bpf: Add a new cgroup helper get_classid_cgroup_id()
  selftests/bpf: Add a new cgroup helper get_cgroup_hierarchy_id()
  selftests/bpf: Add selftests for cgroup1 hierarchy

 include/linux/cgroup-defs.h                        |   1 +
 include/linux/cgroup.h                             |   4 +-
 kernel/bpf/helpers.c                               |  20 +++
 kernel/cgroup/cgroup-internal.h                    |   4 +-
 kernel/cgroup/cgroup-v1.c                          |  33 +++++
 kernel/cgroup/cgroup.c                             |  45 ++++--
 tools/testing/selftests/bpf/cgroup_helpers.c       | 113 ++++++++++++---
 tools/testing/selftests/bpf/cgroup_helpers.h       |   4 +-
 .../selftests/bpf/prog_tests/cgroup1_hierarchy.c   | 159 +++++++++++++++++++++
 .../testing/selftests/bpf/prog_tests/cgroup_v1v2.c |   2 +-
 .../selftests/bpf/progs/test_cgroup1_hierarchy.c   |  72 ++++++++++
 11 files changed, 420 insertions(+), 37 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/prog_tests/cgroup1_hierarchy.c
 create mode 100644 tools/testing/selftests/bpf/progs/test_cgroup1_hierarchy.c

-- 
1.8.3.1


^ permalink raw reply	[flat|nested] 46+ messages in thread

end of thread, other threads:[~2023-11-10 17:05 UTC | newest]

Thread overview: 46+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-29  6:14 [PATCH v3 bpf-next 00/11] bpf, cgroup: Add BPF support for cgroup1 hierarchy Yafang Shao
2023-10-29  6:14 ` [PATCH v3 bpf-next 01/11] cgroup: Remove unnecessary list_empty() Yafang Shao
2023-11-09 21:09   ` Tejun Heo
2023-10-29  6:14 ` [PATCH v3 bpf-next 02/11] cgroup: Make operations on the cgroup root_list RCU safe Yafang Shao
2023-11-09 21:19   ` Tejun Heo
2023-10-29  6:14 ` [PATCH v3 bpf-next 03/11] cgroup: Eliminate the need for cgroup_mutex in proc_cgroup_show() Yafang Shao
2023-11-09 21:20   ` Tejun Heo
2023-10-29  6:14 ` [PATCH v3 bpf-next 04/11] cgroup: Add annotation for holding namespace_sem in current_cgns_cgroup_from_root() Yafang Shao
2023-11-09 21:22   ` Tejun Heo
2023-10-29  6:14 ` [PATCH v3 bpf-next 05/11] cgroup: Add a new helper for cgroup1 hierarchy Yafang Shao
2023-11-09  9:33   ` Hou Tao
2023-11-09 21:27   ` Tejun Heo
2023-11-09 23:30   ` Tejun Heo
2023-11-10  2:37     ` Yafang Shao
2023-10-29  6:14 ` [PATCH v3 bpf-next 06/11] bpf: Add a new kfunc " Yafang Shao
2023-10-30  9:00   ` kernel test robot
2023-10-30 11:35     ` Yafang Shao
2023-10-30 13:59       ` Jiri Olsa
2023-10-31  2:40         ` Yafang Shao
2023-10-31  4:22           ` David Marchevsky
2023-11-03  8:18   ` kernel test robot
2023-11-03  8:49     ` Yafang Shao
2023-11-05  6:22     ` [PATCH bpf-next] compiler-gcc: Ignore -Wmissing-prototypes warning for older GCC Yafang Shao
2023-11-05  8:24       ` Arnd Bergmann
2023-11-05 11:54         ` Yafang Shao
2023-11-05 13:01           ` Arnd Bergmann
2023-11-05 13:50             ` Yafang Shao
2023-11-06  3:18     ` [PATCH v2 bpf-next] compiler-gcc: Suppress -Wmissing-prototypes warning for all supported GCC Yafang Shao
2023-11-09 18:23       ` Alexei Starovoitov
2023-11-10  6:34         ` Arnd Bergmann
2023-11-10  7:48           ` Yafang Shao
2023-11-10 16:00       ` patchwork-bot+netdevbpf
2023-11-09 21:29   ` [PATCH v3 bpf-next 06/11] bpf: Add a new kfunc for cgroup1 hierarchy Tejun Heo
2023-10-29  6:14 ` [PATCH v3 bpf-next 07/11] selftests/bpf: Fix issues in setup_classid_environment() Yafang Shao
2023-10-29  6:14 ` [PATCH v3 bpf-next 08/11] selftests/bpf: Add parallel support for classid Yafang Shao
2023-10-29  6:14 ` [PATCH v3 bpf-next 09/11] selftests/bpf: Add a new cgroup helper get_classid_cgroup_id() Yafang Shao
2023-10-29  6:14 ` [PATCH v3 bpf-next 10/11] selftests/bpf: Add a new cgroup helper get_cgroup_hierarchy_id() Yafang Shao
2023-11-09 21:32   ` Tejun Heo
2023-11-10  2:40     ` Yafang Shao
2023-10-29  6:14 ` [PATCH v3 bpf-next 11/11] selftests/bpf: Add selftests for cgroup1 hierarchy Yafang Shao
2023-11-09 21:36 ` [PATCH v3 bpf-next 00/11] bpf, cgroup: Add BPF support " Tejun Heo
2023-11-09 23:06   ` Alexei Starovoitov
2023-11-09 23:28 ` Tejun Heo
2023-11-09 23:35   ` Alexei Starovoitov
2023-11-10  6:04     ` Yafang Shao
2023-11-10 17:05       ` Alexei Starovoitov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox