Skip to contentSkip to conversation

Support cgroup1 in get from fd/file interfaces

PATCH Applied Yosry Ahmed 3 participants 6 messages Oct 11, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v2 cover Support cgroup1 in get from fd/file interfaces

commit f3a2aebdd6fb ("cgroup: enable cgroup_get_from_file() on cgroup1") enabled using cgroup_get_from_file() and cgroup_get_from_fd() on cgroup1, to enable bpf cgroup_iter to attach to cgroup1.

Apparently, other callers depended on these functions only supporting cgroup2, so f3a2aebdd6 was reverted. Instead, add new separate interfaces that support both cgroup1 and cgroup2 and use them in bpf cgroup_iter.

Yosry Ahmed (2):
cgroup: add cgroup_v1v2_get_from_[fd/file]()
bpf: cgroup_iter: support cgroup1 using cgroup fd

 include/linux/cgroup.h   |  1 +
 kernel/bpf/cgroup_iter.c |  2 +-
 kernel/cgroup/cgroup.c   | 50 +++++++++++++++++++++++++++++++++++-----
 3 files changed, 46 insertions(+), 7 deletions(-)
Signature · 1 line
2.38.0.rc1.362.ged0d419d3c-goog
#1 lore raw

PATCH v2 1/2 cgroup: add cgroup_v1v2_get_from_[fd/file]()

Add cgroup_v1v2_get_from_fd() and cgroup_v1v2_get_from_file() that support both cgroup1 and cgroup2.

---
 include/linux/cgroup.h |  1 +
 kernel/cgroup/cgroup.c | 50 +++++++++++++++++++++++++++++++++++++-----
 2 files changed, 45 insertions(+), 6 deletions(-)
include/linux/cgroup.h +1 -0
index 398f0bce7c21..a88de5bdeaa9 100644
@@ -106,6 +106,7 @@ struct cgroup_subsys_state *css_tryget_online_from_dir(struct dentry *dentry,
 
 struct cgroup *cgroup_get_from_path(const char *path);
 struct cgroup *cgroup_get_from_fd(int fd);
+struct cgroup *cgroup_v1v2_get_from_fd(int fd);
 
 int cgroup_attach_task_all(struct task_struct *from, struct task_struct *);
 int cgroup_transfer_tasks(struct cgroup *to, struct cgroup *from);
kernel/cgroup/cgroup.c +44 -6

84 lines not on this page · raw message

Signature · 1 line
2.38.0.rc1.362.ged0d419d3c-goog
#2 lore raw

PATCH v2 2/2 bpf: cgroup_iter: support cgroup1 using cgroup fd

In reply to Yosry Ahmed

Use cgroup_v1v2_get_from_fd() in cgroup_iter to support attaching to both cgroup v1 and v2 using fds.

---
 kernel/bpf/cgroup_iter.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/bpf/cgroup_iter.c +1 -1
index 0d200a993489..9fcf09f2ef00 100644
@@ -196,7 +196,7 @@ static int bpf_iter_attach_cgroup(struct bpf_prog *prog,
 		return -EINVAL;
 
 	if (fd)
-		cgrp = cgroup_get_from_fd(fd);
+		cgrp = cgroup_v1v2_get_from_fd(fd);
 	else if (id)
 		cgrp = cgroup_get_from_id(id);
 	else /* walk the entire hierarchy by default. */
Signature · 1 line
2.38.0.rc1.362.ged0d419d3c-goog
reviewer Acked-by on v2 2/2
#3 lore raw

Re: [PATCH v2 2/2] bpf: cgroup_iter: support cgroup1 using cgroup fd

Quoted 13 lines · Yosry Ahmed

Use cgroup_v1v2_get_from_fd() in cgroup_iter to support attaching to both cgroup v1 and v2 using fds.

---
  kernel/bpf/cgroup_iter.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
kernel/bpf/cgroup_iter.c +0 -0
index 0d200a993489..9fcf09f2ef00 100644

kernel/bpf/cgroup_iter.c static int bpf_iter_attach_cgroup(struct bpf_prog *prog, · line 199

Quoted 5 lines
kernel/bpf/cgroup_iter.c +1 -1
@@ -196,7 +196,7 @@ static int bpf_iter_attach_cgroup(struct bpf_prog *prog,
  		return -EINVAL;
 
  	if (fd)
-		cgrp = cgroup_get_from_fd(fd);
+		cgrp = cgroup_v1v2_get_from_fd(fd);

Tejun, patch 1 should depend on a recent revert that is not in the bpf tree yet.
Do you want to take this set to the cgroup tree?

Quoted 3 lines
kernel/bpf/cgroup_iter.c +0 -0
  	else if (id)
  		cgrp = cgroup_get_from_id(id);
  	else /* walk the entire hierarchy by default. */
maintainer
#4 lore raw

Re: [PATCH v2 2/2] bpf: cgroup_iter: support cgroup1 using cgroup fd

Quoted 21 lines · Martin KaFai Lau
Quoted 13 lines · Yosry Ahmed

Use cgroup_v1v2_get_from_fd() in cgroup_iter to support attaching to both cgroup v1 and v2 using fds.

---
  kernel/bpf/cgroup_iter.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
kernel/bpf/cgroup_iter.c +0 -0
index 0d200a993489..9fcf09f2ef00 100644

kernel/bpf/cgroup_iter.c static int bpf_iter_attach_cgroup(struct bpf_prog *prog, · line 198

Quoted 4 lines
kernel/bpf/cgroup_iter.c +1 -1
@@ -196,7 +196,7 @@ static int bpf_iter_attach_cgroup(struct bpf_prog *prog,
  		return -EINVAL;
  	if (fd)
-		cgrp = cgroup_get_from_fd(fd);
+		cgrp = cgroup_v1v2_get_from_fd(fd);
Quoted 2 lines

Tejun, patch 1 should depend on a recent revert that is not in the bpf tree yet. Do you want to take this set to the cgroup tree?

Yeah, will do.

Thanks.

Signature · 1 line
tejun
maintainer Applied
#5 lore raw
In reply to Yosry Ahmed
Quoted 7 lines · Yosry Ahmed

commit f3a2aebdd6fb ("cgroup: enable cgroup_get_from_file() on cgroup1") enabled using cgroup_get_from_file() and cgroup_get_from_fd() on cgroup1, to enable bpf cgroup_iter to attach to cgroup1.

Apparently, other callers depended on these functions only supporting cgroup2, so f3a2aebdd6 was reverted. Instead, add new separate interfaces that support both cgroup1 and cgroup2 and use them in bpf cgroup_iter.

Applied to cgroup/for-6.1-fixes.

Thanks.

Signature · 1 line
tejun