All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] cgroup/pid: fix the pid_cgrp attach bug in cgroup v2
@ 2021-07-02  9:18 ` Hui Su
  0 siblings, 0 replies; 4+ messages in thread
From: Hui Su @ 2021-07-02  9:18 UTC (permalink / raw)
  To: tj, lizefan.x, hannes, cgroups, linux-kernel; +Cc: Hui Su

pids_can_attach() should make sure the pids->counter not bigger
than pids->limit, so we should use pids_try_charge() here.

without the change:
root@test:/sys/fs/cgroup/test# cat pids.max
3
root@test:/sys/fs/cgroup/test# sleep 1000 &
[1] 3379
root@test:/sys/fs/cgroup/test# sleep 1000 &
[2] 3380
root@test:/sys/fs/cgroup/test# sleep 1000 &
[3] 3381
root@test:/sys/fs/cgroup/test# sleep 1000 &
[4] 3382
root@test:/sys/fs/cgroup/test# echo 3379 > cgroup.procs
root@test:/sys/fs/cgroup/test# echo 3380 > cgroup.procs
root@test:/sys/fs/cgroup/test# echo 3381 > cgroup.procs
root@test:/sys/fs/cgroup/test# echo 3382 > cgroup.procs
root@test:/sys/fs/cgroup/test# cat pids.max
3
root@test:/sys/fs/cgroup/test# cat pids.current
4
root@test:/sys/fs/cgroup/test# cat cgroup.procs
3379
3380
3381
3382
root@test:/sys/fs/cgroup/test#

with this change:
root@test:/sys/fs/cgroup/test# cat pids.current
3
root@test:/sys/fs/cgroup/test# cat pids.max
3
root@test:/sys/fs/cgroup/test# cat cgroup.procs
2614
3683
3684
root@test:/sys/fs/cgroup/test# sleep 10000 &
[5] 3733
root@test:/sys/fs/cgroup/test# echo 3733 > cgroup.procs
bash: echo: write error: Resource temporarily unavailable
root@test:/sys/fs/cgroup/test# cat cgroup.procs
2614
3683
3684
root@test:/sys/fs/cgroup/test# cat pids.current
3
root@test:/sys/fs/cgroup/test# dmesg |tail -n 1
[  863.612162] cgroup: attach rejected by pids controller in /test

Signed-off-by: Hui Su <suhui@zeku.com>
---
 kernel/cgroup/pids.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/kernel/cgroup/pids.c b/kernel/cgroup/pids.c
index 511af87f685e..5e24990f28de 100644
--- a/kernel/cgroup/pids.c
+++ b/kernel/cgroup/pids.c
@@ -172,6 +172,7 @@ static int pids_can_attach(struct cgroup_taskset *tset)
 {
 	struct task_struct *task;
 	struct cgroup_subsys_state *dst_css;
+	int ret = 0;
 
 	cgroup_taskset_for_each(task, dst_css, tset) {
 		struct pids_cgroup *pids = css_pids(dst_css);
@@ -186,11 +187,17 @@ static int pids_can_attach(struct cgroup_taskset *tset)
 		old_css = task_css(task, pids_cgrp_id);
 		old_pids = css_pids(old_css);
 
-		pids_charge(pids, 1);
+		ret = pids_try_charge(pids, 1);
+		if (ret) {
+			pr_info("cgroup: attach rejected by pids controller in ");
+			pr_cont_cgroup_path(dst_css->cgroup);
+			pr_cont("\n");
+			break;
+		}
 		pids_uncharge(old_pids, 1);
 	}
 
-	return 0;
+	return ret;
 }
 
 static void pids_cancel_attach(struct cgroup_taskset *tset)
-- 
2.25.1


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

* [PATCH] cgroup/pid: fix the pid_cgrp attach bug in cgroup v2
@ 2021-07-02  9:18 ` Hui Su
  0 siblings, 0 replies; 4+ messages in thread
From: Hui Su @ 2021-07-02  9:18 UTC (permalink / raw)
  To: tj-DgEjT+Ai2ygdnm+yROfE0A, lizefan.x-EC8Uxl6Npydl57MIdRCFDg,
	hannes-druUgvl0LCNAfugRpC6u6w, cgroups-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA
  Cc: Hui Su

pids_can_attach() should make sure the pids->counter not bigger
than pids->limit, so we should use pids_try_charge() here.

without the change:
root@test:/sys/fs/cgroup/test# cat pids.max
3
root@test:/sys/fs/cgroup/test# sleep 1000 &
[1] 3379
root@test:/sys/fs/cgroup/test# sleep 1000 &
[2] 3380
root@test:/sys/fs/cgroup/test# sleep 1000 &
[3] 3381
root@test:/sys/fs/cgroup/test# sleep 1000 &
[4] 3382
root@test:/sys/fs/cgroup/test# echo 3379 > cgroup.procs
root@test:/sys/fs/cgroup/test# echo 3380 > cgroup.procs
root@test:/sys/fs/cgroup/test# echo 3381 > cgroup.procs
root@test:/sys/fs/cgroup/test# echo 3382 > cgroup.procs
root@test:/sys/fs/cgroup/test# cat pids.max
3
root@test:/sys/fs/cgroup/test# cat pids.current
4
root@test:/sys/fs/cgroup/test# cat cgroup.procs
3379
3380
3381
3382
root@test:/sys/fs/cgroup/test#

with this change:
root@test:/sys/fs/cgroup/test# cat pids.current
3
root@test:/sys/fs/cgroup/test# cat pids.max
3
root@test:/sys/fs/cgroup/test# cat cgroup.procs
2614
3683
3684
root@test:/sys/fs/cgroup/test# sleep 10000 &
[5] 3733
root@test:/sys/fs/cgroup/test# echo 3733 > cgroup.procs
bash: echo: write error: Resource temporarily unavailable
root@test:/sys/fs/cgroup/test# cat cgroup.procs
2614
3683
3684
root@test:/sys/fs/cgroup/test# cat pids.current
3
root@test:/sys/fs/cgroup/test# dmesg |tail -n 1
[  863.612162] cgroup: attach rejected by pids controller in /test

Signed-off-by: Hui Su <suhui-OtvJRZzVyoU@public.gmane.org>
---
 kernel/cgroup/pids.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/kernel/cgroup/pids.c b/kernel/cgroup/pids.c
index 511af87f685e..5e24990f28de 100644
--- a/kernel/cgroup/pids.c
+++ b/kernel/cgroup/pids.c
@@ -172,6 +172,7 @@ static int pids_can_attach(struct cgroup_taskset *tset)
 {
 	struct task_struct *task;
 	struct cgroup_subsys_state *dst_css;
+	int ret = 0;
 
 	cgroup_taskset_for_each(task, dst_css, tset) {
 		struct pids_cgroup *pids = css_pids(dst_css);
@@ -186,11 +187,17 @@ static int pids_can_attach(struct cgroup_taskset *tset)
 		old_css = task_css(task, pids_cgrp_id);
 		old_pids = css_pids(old_css);
 
-		pids_charge(pids, 1);
+		ret = pids_try_charge(pids, 1);
+		if (ret) {
+			pr_info("cgroup: attach rejected by pids controller in ");
+			pr_cont_cgroup_path(dst_css->cgroup);
+			pr_cont("\n");
+			break;
+		}
 		pids_uncharge(old_pids, 1);
 	}
 
-	return 0;
+	return ret;
 }
 
 static void pids_cancel_attach(struct cgroup_taskset *tset)
-- 
2.25.1


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

* 回复: [PATCH] cgroup/pid: fix the pid_cgrp attach bug in cgroup v2
@ 2021-07-02  9:22   ` 苏辉(Robert Su)
  0 siblings, 0 replies; 4+ messages in thread
From: 苏辉(Robert Su) @ 2021-07-02  9:22 UTC (permalink / raw)
  To: tj, lizefan.x, hannes, cgroups, linux-kernel

Sorry, please ignore this change...

-----邮件原件-----
发件人: 苏辉(Robert Su) <suhui@zeku.com> 
发送时间: 2021年7月2日 17:19
收件人: tj@kernel.org; lizefan.x@bytedance.com; hannes@cmpxchg.org; cgroups@vger.kernel.org; linux-kernel@vger.kernel.org
抄送: 苏辉(Robert Su) <suhui@zeku.com>
主题: [PATCH] cgroup/pid: fix the pid_cgrp attach bug in cgroup v2

pids_can_attach() should make sure the pids->counter not bigger than pids->limit, so we should use pids_try_charge() here.

without the change:
root@test:/sys/fs/cgroup/test# cat pids.max
3
root@test:/sys/fs/cgroup/test# sleep 1000 & [1] 3379 root@test:/sys/fs/cgroup/test# sleep 1000 & [2] 3380 root@test:/sys/fs/cgroup/test# sleep 1000 & [3] 3381 root@test:/sys/fs/cgroup/test# sleep 1000 & [4] 3382 root@test:/sys/fs/cgroup/test# echo 3379 > cgroup.procs root@test:/sys/fs/cgroup/test# echo 3380 > cgroup.procs root@test:/sys/fs/cgroup/test# echo 3381 > cgroup.procs root@test:/sys/fs/cgroup/test# echo 3382 > cgroup.procs root@test:/sys/fs/cgroup/test# cat pids.max
3
root@test:/sys/fs/cgroup/test# cat pids.current
4
root@test:/sys/fs/cgroup/test# cat cgroup.procs
3379
3380
3381
3382
root@test:/sys/fs/cgroup/test#

with this change:
root@test:/sys/fs/cgroup/test# cat pids.current
3
root@test:/sys/fs/cgroup/test# cat pids.max
3
root@test:/sys/fs/cgroup/test# cat cgroup.procs
2614
3683
3684
root@test:/sys/fs/cgroup/test# sleep 10000 & [5] 3733 root@test:/sys/fs/cgroup/test# echo 3733 > cgroup.procs
bash: echo: write error: Resource temporarily unavailable root@test:/sys/fs/cgroup/test# cat cgroup.procs
2614
3683
3684
root@test:/sys/fs/cgroup/test# cat pids.current
3
root@test:/sys/fs/cgroup/test# dmesg |tail -n 1 [  863.612162] cgroup: attach rejected by pids controller in /test

Signed-off-by: Hui Su <suhui@zeku.com>
---
 kernel/cgroup/pids.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/kernel/cgroup/pids.c b/kernel/cgroup/pids.c index 511af87f685e..5e24990f28de 100644
--- a/kernel/cgroup/pids.c
+++ b/kernel/cgroup/pids.c
@@ -172,6 +172,7 @@ static int pids_can_attach(struct cgroup_taskset *tset)  {
 	struct task_struct *task;
 	struct cgroup_subsys_state *dst_css;
+	int ret = 0;
 
 	cgroup_taskset_for_each(task, dst_css, tset) {
 		struct pids_cgroup *pids = css_pids(dst_css); @@ -186,11 +187,17 @@ static int pids_can_attach(struct cgroup_taskset *tset)
 		old_css = task_css(task, pids_cgrp_id);
 		old_pids = css_pids(old_css);
 
-		pids_charge(pids, 1);
+		ret = pids_try_charge(pids, 1);
+		if (ret) {
+			pr_info("cgroup: attach rejected by pids controller in ");
+			pr_cont_cgroup_path(dst_css->cgroup);
+			pr_cont("\n");
+			break;
+		}
 		pids_uncharge(old_pids, 1);
 	}
 
-	return 0;
+	return ret;
 }
 
 static void pids_cancel_attach(struct cgroup_taskset *tset)
--
2.25.1


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

* 回复: [PATCH] cgroup/pid: fix the pid_cgrp attach bug in cgroup v2
@ 2021-07-02  9:22   ` 苏辉(Robert Su)
  0 siblings, 0 replies; 4+ messages in thread
From: 苏辉(Robert Su) @ 2021-07-02  9:22 UTC (permalink / raw)
  To: tj-DgEjT+Ai2ygdnm+yROfE0A, lizefan.x-EC8Uxl6Npydl57MIdRCFDg,
	hannes-druUgvl0LCNAfugRpC6u6w, cgroups-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA

Sorry, please ignore this change...

-----邮件原件-----
发件人: 苏辉(Robert Su) <suhui@zeku.com> 
发送时间: 2021年7月2日 17:19
收件人: tj@kernel.org; lizefan.x@bytedance.com; hannes@cmpxchg.org; cgroups@vger.kernel.org; linux-kernel@vger.kernel.org
抄送: 苏辉(Robert Su) <suhui@zeku.com>
主题: [PATCH] cgroup/pid: fix the pid_cgrp attach bug in cgroup v2

pids_can_attach() should make sure the pids->counter not bigger than pids->limit, so we should use pids_try_charge() here.

without the change:
root@test:/sys/fs/cgroup/test# cat pids.max
3
root@test:/sys/fs/cgroup/test# sleep 1000 & [1] 3379 root@test:/sys/fs/cgroup/test# sleep 1000 & [2] 3380 root@test:/sys/fs/cgroup/test# sleep 1000 & [3] 3381 root@test:/sys/fs/cgroup/test# sleep 1000 & [4] 3382 root@test:/sys/fs/cgroup/test# echo 3379 > cgroup.procs root@test:/sys/fs/cgroup/test# echo 3380 > cgroup.procs root@test:/sys/fs/cgroup/test# echo 3381 > cgroup.procs root@test:/sys/fs/cgroup/test# echo 3382 > cgroup.procs root@test:/sys/fs/cgroup/test# cat pids.max
3
root@test:/sys/fs/cgroup/test# cat pids.current
4
root@test:/sys/fs/cgroup/test# cat cgroup.procs
3379
3380
3381
3382
root@test:/sys/fs/cgroup/test#

with this change:
root@test:/sys/fs/cgroup/test# cat pids.current
3
root@test:/sys/fs/cgroup/test# cat pids.max
3
root@test:/sys/fs/cgroup/test# cat cgroup.procs
2614
3683
3684
root@test:/sys/fs/cgroup/test# sleep 10000 & [5] 3733 root@test:/sys/fs/cgroup/test# echo 3733 > cgroup.procs
bash: echo: write error: Resource temporarily unavailable root@test:/sys/fs/cgroup/test# cat cgroup.procs
2614
3683
3684
root@test:/sys/fs/cgroup/test# cat pids.current
3
root@test:/sys/fs/cgroup/test# dmesg |tail -n 1 [  863.612162] cgroup: attach rejected by pids controller in /test

Signed-off-by: Hui Su <suhui@zeku.com>
---
 kernel/cgroup/pids.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/kernel/cgroup/pids.c b/kernel/cgroup/pids.c index 511af87f685e..5e24990f28de 100644
--- a/kernel/cgroup/pids.c
+++ b/kernel/cgroup/pids.c
@@ -172,6 +172,7 @@ static int pids_can_attach(struct cgroup_taskset *tset)  {
 	struct task_struct *task;
 	struct cgroup_subsys_state *dst_css;
+	int ret = 0;
 
 	cgroup_taskset_for_each(task, dst_css, tset) {
 		struct pids_cgroup *pids = css_pids(dst_css); @@ -186,11 +187,17 @@ static int pids_can_attach(struct cgroup_taskset *tset)
 		old_css = task_css(task, pids_cgrp_id);
 		old_pids = css_pids(old_css);
 
-		pids_charge(pids, 1);
+		ret = pids_try_charge(pids, 1);
+		if (ret) {
+			pr_info("cgroup: attach rejected by pids controller in ");
+			pr_cont_cgroup_path(dst_css->cgroup);
+			pr_cont("\n");
+			break;
+		}
 		pids_uncharge(old_pids, 1);
 	}
 
-	return 0;
+	return ret;
 }
 
 static void pids_cancel_attach(struct cgroup_taskset *tset)
--
2.25.1


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

end of thread, other threads:[~2021-07-02  9:22 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-02  9:18 [PATCH] cgroup/pid: fix the pid_cgrp attach bug in cgroup v2 Hui Su
2021-07-02  9:18 ` Hui Su
2021-07-02  9:22 ` 回复: " 苏辉(Robert Su)
2021-07-02  9:22   ` 苏辉(Robert Su)

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.