mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v1 0/2] Only cgroup v2 can be attached by bpf programs
@ 2024-10-18  8:15 Chen Ridong
  2024-10-18  8:15 ` [PATCH v1 1/2] Revert "cgroup: Fix memory leak caused by missing cgroup_bpf_offline" Chen Ridong
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Chen Ridong @ 2024-10-18  8:15 UTC (permalink / raw)
  To: tj, lizefan.x, hannes, longman, mkoutny, john.fastabend,
	roman.gushchin, quanyang.wang, ast
  Cc: cgroups, linux-kernel, bpf, chenridong, wangweiyang2

From: Chen Ridong <chenridong@huawei.com>

Only cgroup v2 can be attached by bpf programs. This patchset reverts
commit 04f8ef5643bc ("cgroup: Fix memory leak caused by missing
cgroup_bpf_offline") and avoid cgroup_bpf_inherit and cgroup_bpf_offline
being call in cgroup v1.

Chen Ridong (2):
  Revert "cgroup: Fix memory leak caused by missing cgroup_bpf_offline"
  cgroup/bpf: only cgroup v2 can be attached by bpf programs

 kernel/cgroup/cgroup.c | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

-- 
2.34.1


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

* [PATCH v1 1/2] Revert "cgroup: Fix memory leak caused by missing cgroup_bpf_offline"
  2024-10-18  8:15 [PATCH v1 0/2] Only cgroup v2 can be attached by bpf programs Chen Ridong
@ 2024-10-18  8:15 ` Chen Ridong
  2024-10-18  8:15 ` [PATCH v1 2/2] cgroup/bpf: only cgroup v2 can be attached by bpf programs Chen Ridong
  2024-10-21 20:03 ` [PATCH v1 0/2] Only " Tejun Heo
  2 siblings, 0 replies; 4+ messages in thread
From: Chen Ridong @ 2024-10-18  8:15 UTC (permalink / raw)
  To: tj, lizefan.x, hannes, longman, mkoutny, john.fastabend,
	roman.gushchin, quanyang.wang, ast
  Cc: cgroups, linux-kernel, bpf, chenridong, wangweiyang2

From: Chen Ridong <chenridong@huawei.com>

This reverts commit 04f8ef5643bcd8bcde25dfdebef998aea480b2ba.

Only cgroup v2 can be attached by cgroup by BPF programs. Revert this
commit and cgroup_bpf_inherit and cgroup_bpf_offline won't be called in
cgroup v1. The memory leak issue will be fixed with next patch.

Fixes: 04f8ef5643bc ("cgroup: Fix memory leak caused by missing cgroup_bpf_offline")
Link: https://lore.kernel.org/cgroups/aka2hk5jsel5zomucpwlxsej6iwnfw4qu5jkrmjhyfhesjlfdw@46zxhg5bdnr7/
Signed-off-by: Chen Ridong <chenridong@huawei.com>
---
 kernel/cgroup/cgroup.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c
index 044c7ba1cc48..30444e096027 100644
--- a/kernel/cgroup/cgroup.c
+++ b/kernel/cgroup/cgroup.c
@@ -2314,10 +2314,8 @@ static void cgroup_kill_sb(struct super_block *sb)
 	 * And don't kill the default root.
 	 */
 	if (list_empty(&root->cgrp.self.children) && root != &cgrp_dfl_root &&
-	    !percpu_ref_is_dying(&root->cgrp.self.refcnt)) {
-		cgroup_bpf_offline(&root->cgrp);
+	    !percpu_ref_is_dying(&root->cgrp.self.refcnt))
 		percpu_ref_kill(&root->cgrp.self.refcnt);
-	}
 	cgroup_put(&root->cgrp);
 	kernfs_kill_sb(sb);
 }
-- 
2.34.1


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

* [PATCH v1 2/2] cgroup/bpf: only cgroup v2 can be attached by bpf programs
  2024-10-18  8:15 [PATCH v1 0/2] Only cgroup v2 can be attached by bpf programs Chen Ridong
  2024-10-18  8:15 ` [PATCH v1 1/2] Revert "cgroup: Fix memory leak caused by missing cgroup_bpf_offline" Chen Ridong
@ 2024-10-18  8:15 ` Chen Ridong
  2024-10-21 20:03 ` [PATCH v1 0/2] Only " Tejun Heo
  2 siblings, 0 replies; 4+ messages in thread
From: Chen Ridong @ 2024-10-18  8:15 UTC (permalink / raw)
  To: tj, lizefan.x, hannes, longman, mkoutny, john.fastabend,
	roman.gushchin, quanyang.wang, ast
  Cc: cgroups, linux-kernel, bpf, chenridong, wangweiyang2

From: Chen Ridong <chenridong@huawei.com>

Only cgroup v2 can be attached by bpf programs, so this patch introduces
that cgroup_bpf_inherit and cgroup_bpf_offline can only be called in
cgroup v2, and this can fix the memleak mentioned by commit 04f8ef5643bc
("cgroup: Fix memory leak caused by missing cgroup_bpf_offline"), which
has been reverted.

Fixes: 2b0d3d3e4fcf ("percpu_ref: reduce memory footprint of percpu_ref in fast path")
Fixes: 4bfc0bb2c60e ("bpf: decouple the lifetime of cgroup_bpf from cgroup itself")
Link: https://lore.kernel.org/cgroups/aka2hk5jsel5zomucpwlxsej6iwnfw4qu5jkrmjhyfhesjlfdw@46zxhg5bdnr7/
Signed-off-by: Chen Ridong <chenridong@huawei.com>
---
 kernel/cgroup/cgroup.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c
index 30444e096027..e275eaf2de7f 100644
--- a/kernel/cgroup/cgroup.c
+++ b/kernel/cgroup/cgroup.c
@@ -2140,8 +2140,10 @@ int cgroup_setup_root(struct cgroup_root *root, u16 ss_mask)
 	if (ret)
 		goto exit_stats;
 
-	ret = cgroup_bpf_inherit(root_cgrp);
-	WARN_ON_ONCE(ret);
+	if (root == &cgrp_dfl_root) {
+		ret = cgroup_bpf_inherit(root_cgrp);
+		WARN_ON_ONCE(ret);
+	}
 
 	trace_cgroup_setup_root(root);
 
@@ -5708,9 +5710,11 @@ static struct cgroup *cgroup_create(struct cgroup *parent, const char *name,
 	if (ret)
 		goto out_kernfs_remove;
 
-	ret = cgroup_bpf_inherit(cgrp);
-	if (ret)
-		goto out_psi_free;
+	if (cgrp->root == &cgrp_dfl_root) {
+		ret = cgroup_bpf_inherit(cgrp);
+		if (ret)
+			goto out_psi_free;
+	}
 
 	/*
 	 * New cgroup inherits effective freeze counter, and
@@ -6024,7 +6028,8 @@ static int cgroup_destroy_locked(struct cgroup *cgrp)
 
 	cgroup1_check_for_release(parent);
 
-	cgroup_bpf_offline(cgrp);
+	if (cgrp->root == &cgrp_dfl_root)
+		cgroup_bpf_offline(cgrp);
 
 	/* put the base reference */
 	percpu_ref_kill(&cgrp->self.refcnt);
-- 
2.34.1


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

* Re: [PATCH v1 0/2] Only cgroup v2 can be attached by bpf programs
  2024-10-18  8:15 [PATCH v1 0/2] Only cgroup v2 can be attached by bpf programs Chen Ridong
  2024-10-18  8:15 ` [PATCH v1 1/2] Revert "cgroup: Fix memory leak caused by missing cgroup_bpf_offline" Chen Ridong
  2024-10-18  8:15 ` [PATCH v1 2/2] cgroup/bpf: only cgroup v2 can be attached by bpf programs Chen Ridong
@ 2024-10-21 20:03 ` Tejun Heo
  2 siblings, 0 replies; 4+ messages in thread
From: Tejun Heo @ 2024-10-21 20:03 UTC (permalink / raw)
  To: Chen Ridong
  Cc: lizefan.x, hannes, longman, mkoutny, john.fastabend,
	roman.gushchin, quanyang.wang, ast, cgroups, linux-kernel, bpf,
	chenridong, wangweiyang2

On Fri, Oct 18, 2024 at 08:15:18AM +0000, Chen Ridong wrote:
> From: Chen Ridong <chenridong@huawei.com>
> 
> Only cgroup v2 can be attached by bpf programs. This patchset reverts
> commit 04f8ef5643bc ("cgroup: Fix memory leak caused by missing
> cgroup_bpf_offline") and avoid cgroup_bpf_inherit and cgroup_bpf_offline
> being call in cgroup v1.

Applied to cgroup/for-6.13.

Thanks.

-- 
tejun

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

end of thread, other threads:[~2024-10-21 20:03 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-10-18  8:15 [PATCH v1 0/2] Only cgroup v2 can be attached by bpf programs Chen Ridong
2024-10-18  8:15 ` [PATCH v1 1/2] Revert "cgroup: Fix memory leak caused by missing cgroup_bpf_offline" Chen Ridong
2024-10-18  8:15 ` [PATCH v1 2/2] cgroup/bpf: only cgroup v2 can be attached by bpf programs Chen Ridong
2024-10-21 20:03 ` [PATCH v1 0/2] Only " Tejun Heo

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

all inboxes | Powered by JetHome®