[Devel] [PATCH RHEL7 COMMIT] cgroup: make cgroup_kernel_attach safe against cgroup removal

Konstantin Khorenko khorenko at virtuozzo.com
Tue Jun 9 07:45:08 PDT 2015


The commit is pushed to "branch-rh7-3.10.0-123.1.2-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-123.1.2.vz7.5.11
------>
commit 5bcb563c43b1d6fb6b7766bce92e25d2b23c6ef7
Author: Vladimir Davydov <vdavydov at parallels.com>
Date:   Tue Jun 9 18:45:07 2015 +0400

    cgroup: make cgroup_kernel_attach safe against cgroup removal
    
    Currently, this function is only safe to call if the cgroup is pinned
    (e.g. was open using cgroup_kernel_open). In a following patch, I need
    to be able to pass a cgroup that could have already been removed there,
    so make it safe against dead cgroups.
    
    Signed-off-by: Vladimir Davydov <vdavydov at parallels.com>
    Reviewed-by: Cyrill Gorcunov <gorcunov at openvz.org>
    
    Related to patchset:
    
    https://jira.sw.ru/browse/PSBM-34035
    
    Vladimir Davydov (6):
      cgroup: add function to lookup a cgroup by pathname
      cgroup: make cgroup_kernel_attach safe against cgroup removal
      ub: rename functions for reading/writing cgroup resources
      ub: rework connection between ub and mem/blkio cgroups
      memcg: pass struct mem_cgroup instead of cgroup to ub-related methods
      ub: introduce ub_total_pages
---
 kernel/cgroup.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index 7ec90e4..0c6fb55 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -5653,7 +5653,8 @@ int cgroup_kernel_attach(struct cgroup *cgrp, struct task_struct *tsk)
 {
 	int ret;
 
-	mutex_lock(&cgroup_mutex);
+	if (!cgroup_lock_live_group(cgrp))
+		return -ENODEV;
 	ret = cgroup_attach_task(cgrp, tsk, true);
 	mutex_unlock(&cgroup_mutex);
 	return ret;



More information about the Devel mailing list