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

Submitted by Kirill Tkhai on Feb. 20, 2018, 3:09 p.m.

Details

Message ID 151913937422.27906.4707563554601656217.stgit@localhost.localdomain
State New
Series "Fix wrong loadavg accounting inside CT"
Headers show

Commit Message

Kirill Tkhai Feb. 20, 2018, 3:09 p.m.
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@virtuozzo.com>
---
 kernel/ve/ve.c |   15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

Patch hide | download patch | download mbox

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;
 }