From: Tejun Heo <htejun@gmail.com>
To: rjw@sisk.pl, paul@paulmenage.org, lizf@cn.fujitsu.com
Cc: linux-pm@lists.linux-foundation.org,
linux-kernel@vger.kernel.org,
containers@lists.linux-foundation.org, fweisbec@gmail.com,
matthltc@us.ibm.com, akpm@linux-foundation.org,
Tejun Heo <tj@kernel.org>, Oleg Nesterov <oleg@redhat.com>,
Paul Menage <menage@google.com>
Subject: [PATCH 1/4] cgroup: change locking order in attach_task_by_pid()
Date: Mon, 5 Sep 2011 03:01:17 +0900 [thread overview]
Message-ID: <1315159280-25032-2-git-send-email-htejun@gmail.com> (raw)
In-Reply-To: <1315159280-25032-1-git-send-email-htejun@gmail.com>
From: Tejun Heo <tj@kernel.org>
cgroup_mutex is updated to nest inside threadgroup_fork_lock instead
of the other way around. threadgroup locking is scheduled to be
updated to cover all threadgroup altering operations and nesting it
inside cgroup_mutex complicates locking dependency unnecessarily.
This also simplifies code a bit.
The ugly "if (threadgroup)" conditionals for threadgroup locking will
soon be removed.
Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Paul Menage <menage@google.com>
Cc: Li Zefan <lizf@cn.fujitsu.com>
---
kernel/cgroup.c | 22 ++++++++++------------
1 files changed, 10 insertions(+), 12 deletions(-)
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index 1d2b6ce..bd1fb5f 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -2203,15 +2203,11 @@ static int attach_task_by_pid(struct cgroup *cgrp, u64 pid, bool threadgroup)
const struct cred *cred = current_cred(), *tcred;
int ret;
- if (!cgroup_lock_live_group(cgrp))
- return -ENODEV;
-
if (pid) {
rcu_read_lock();
tsk = find_task_by_vpid(pid);
if (!tsk) {
rcu_read_unlock();
- cgroup_unlock();
return -ESRCH;
}
if (threadgroup) {
@@ -2225,7 +2221,6 @@ static int attach_task_by_pid(struct cgroup *cgrp, u64 pid, bool threadgroup)
} else if (tsk->flags & PF_EXITING) {
/* optimization for the single-task-only case */
rcu_read_unlock();
- cgroup_unlock();
return -ESRCH;
}
@@ -2238,7 +2233,6 @@ static int attach_task_by_pid(struct cgroup *cgrp, u64 pid, bool threadgroup)
cred->euid != tcred->uid &&
cred->euid != tcred->suid) {
rcu_read_unlock();
- cgroup_unlock();
return -EACCES;
}
get_task_struct(tsk);
@@ -2251,15 +2245,19 @@ static int attach_task_by_pid(struct cgroup *cgrp, u64 pid, bool threadgroup)
get_task_struct(tsk);
}
- if (threadgroup) {
+ if (threadgroup)
threadgroup_fork_write_lock(tsk);
- ret = cgroup_attach_proc(cgrp, tsk);
- threadgroup_fork_write_unlock(tsk);
- } else {
- ret = cgroup_attach_task(cgrp, tsk);
+ ret = -ENODEV;
+ if (cgroup_lock_live_group(cgrp)) {
+ if (threadgroup)
+ ret = cgroup_attach_proc(cgrp, tsk);
+ else
+ ret = cgroup_attach_task(cgrp, tsk);
+ cgroup_unlock();
}
+ if (threadgroup)
+ threadgroup_fork_write_unlock(tsk);
put_task_struct(tsk);
- cgroup_unlock();
return ret;
}
--
1.7.6
next prev parent reply other threads:[~2011-09-04 18:01 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-09-04 18:01 [PATCHSET cgroup] extend threadgroup locking Tejun Heo
2011-09-04 18:01 ` Tejun Heo [this message]
2011-09-18 18:56 ` [PATCH 1/4] cgroup: change locking order in attach_task_by_pid() Oleg Nesterov
2011-10-10 17:34 ` Tejun Heo
2011-10-10 17:43 ` Tejun Heo
2011-09-04 18:01 ` Tejun Heo
2011-09-04 18:01 ` [PATCH 2/4] threadgroup: rename signal->threadgroup_fork_lock to ->group_rwsem Tejun Heo
2011-09-04 18:01 ` Tejun Heo
2011-09-04 18:01 ` [PATCH 3/4] threadgroup: extend threadgroup_lock() to cover exit and exec Tejun Heo
2011-09-04 18:01 ` Tejun Heo
2011-09-12 4:04 ` Paul Menage
2011-09-13 7:54 ` Tejun Heo
2011-09-18 17:37 ` Oleg Nesterov
2011-09-18 18:46 ` Oleg Nesterov
2011-10-08 18:37 ` Ben Blum
2011-10-10 17:11 ` Tejun Heo
2011-10-12 17:51 ` Oleg Nesterov
2011-10-12 18:05 ` Ben Blum
2011-10-12 18:29 ` Oleg Nesterov
2011-10-12 18:44 ` Ben Blum
2011-10-12 19:07 ` Oleg Nesterov
[not found] ` <1315159280-25032-1-git-send-email-htejun-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2011-09-04 18:01 ` [PATCH 1/4] cgroup: change locking order in attach_task_by_pid() Tejun Heo
2011-09-04 18:01 ` [PATCH 2/4] threadgroup: rename signal->threadgroup_fork_lock to ->group_rwsem Tejun Heo
2011-09-04 18:01 ` [PATCH 3/4] threadgroup: extend threadgroup_lock() to cover exit and exec Tejun Heo
2011-09-04 18:01 ` [PATCH 4/4] cgroup: always lock threadgroup during migration Tejun Heo
2011-09-05 4:05 ` [PATCHSET cgroup] extend threadgroup locking Rafael J. Wysocki
2011-09-06 9:00 ` Li Zefan
2011-09-11 3:35 ` Tejun Heo
2011-09-04 18:01 ` [PATCH 4/4] cgroup: always lock threadgroup during migration Tejun Heo
2011-09-18 17:41 ` Oleg Nesterov
2011-10-10 17:31 ` Tejun Heo
2011-09-04 18:01 ` Tejun Heo
2011-09-05 4:05 ` [PATCHSET cgroup] extend threadgroup locking Rafael J. Wysocki
2011-09-05 4:05 ` Rafael J. Wysocki
2011-09-05 8:43 ` Tejun Heo
[not found] ` <201109050605.57360.rjw-KKrjLPT3xs0@public.gmane.org>
2011-09-05 8:43 ` Tejun Heo
2011-09-05 8:43 ` Tejun Heo
2011-09-06 9:00 ` Li Zefan
2011-09-06 9:00 ` Li Zefan
2011-09-11 3:35 ` Tejun Heo
2011-09-14 18:33 ` Oleg Nesterov
2011-09-14 23:33 ` Tejun Heo
2011-09-11 3:35 ` Tejun Heo
2011-09-12 4:11 ` Paul Menage
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1315159280-25032-2-git-send-email-htejun@gmail.com \
--to=htejun@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=containers@lists.linux-foundation.org \
--cc=fweisbec@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@lists.linux-foundation.org \
--cc=lizf@cn.fujitsu.com \
--cc=matthltc@us.ibm.com \
--cc=menage@google.com \
--cc=oleg@redhat.com \
--cc=paul@paulmenage.org \
--cc=rjw@sisk.pl \
--cc=tj@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.