[Devel] [PATCH 1/5] ve/cgroup: Get correct VE init css when ve init_task is moved to child cgroup

Kirill Tkhai ktkhai at virtuozzo.com
Tue Feb 20 18:09:34 MSK 2018


Init task of container can be moved to any child cgroup.
But ve_get_init_css() remains to return its cgroup as
top of container. Fix that by finding of real top cgroup
among init_task cgroup parents.

https://jira.sw.ru/browse/PSBM-81572

Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 kernel/ve/ve.c |   15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/kernel/ve/ve.c b/kernel/ve/ve.c
index ef615caa3398..8f5a75b7fcf9 100644
--- a/kernel/ve/ve.c
+++ b/kernel/ve/ve.c
@@ -110,8 +110,9 @@ EXPORT_SYMBOL(put_ve);
 
 struct cgroup_subsys_state *ve_get_init_css(struct ve_struct *ve, int subsys_id)
 {
-	struct cgroup_subsys_state *css;
+	struct cgroup_subsys_state *css, *tmp;
 	struct task_struct *task;
+	struct cgroup *cgroup;
 
 	rcu_read_lock();
 	task = ve->ve_ns ? ve->init_task : &init_task;
@@ -121,6 +122,18 @@ struct cgroup_subsys_state *ve_get_init_css(struct ve_struct *ve, int subsys_id)
 			break;
 		cpu_relax();
 	}
+
+	cgroup = css->cgroup;
+	while (!test_bit(CGRP_VE_ROOT, &cgroup->flags) && cgroup->parent)
+		cgroup = cgroup->parent;
+
+	if (cgroup != css->cgroup) {
+		tmp = cgroup->subsys[subsys_id];
+		css_get(tmp);
+		css_put(css);
+		css = tmp;
+	}
+
 	rcu_read_unlock();
 	return css;
 }



More information about the Devel mailing list