summaryrefslogtreecommitdiff
path: root/fs/proc/base.c
diff options
context:
space:
mode:
authorDavid Rientjes <rientjes@google.com>2010-10-26 14:21:26 -0700
committerLinus Torvalds <torvalds@linux-foundation.org>2010-10-26 16:52:05 -0700
commitd19d5476f4b9f91d2de92b91588bb118beba6c0d (patch)
treeb267c225c2b7507f7e4900676649b20e56e06ba2 /fs/proc/base.c
parent723548bff1dde9ab6bdb23f4bb92277c4da49473 (diff)
oom: fix locking for oom_adj and oom_score_adj
The locking order in oom_adjust_write() and oom_score_adj_write() for task->alloc_lock and task->sighand->siglock is reversed, and lockdep notices that irqs could encounter an ABBA scenario. This fixes the locking order so that we always take task_lock(task) prior to lock_task_sighand(task). Signed-off-by: David Rientjes <rientjes@google.com> Reported-by: Andrew Morton <akpm@linux-foundation.org> Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com> Cc: Rik van Riel <riel@redhat.com> Cc: Ying Han <yinghan@google.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs/proc/base.c')
-rw-r--r--fs/proc/base.c40
1 files changed, 21 insertions, 19 deletions
diff --git a/fs/proc/base.c b/fs/proc/base.c
index 34d11ac31f2e..53dc8ad40ae6 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -1042,9 +1042,16 @@ static ssize_t oom_adjust_write(struct file *file, const char __user *buf,
err = -ESRCH;
goto out;
}
+
+ task_lock(task);
+ if (!task->mm) {
+ err = -EINVAL;
+ goto err_task_lock;
+ }
+
if (!lock_task_sighand(task, &flags)) {
err = -ESRCH;
- goto err_task_struct;
+ goto err_task_lock;
}
if (oom_adjust < task->signal->oom_adj && !capable(CAP_SYS_RESOURCE)) {
@@ -1052,12 +1059,6 @@ static ssize_t oom_adjust_write(struct file *file, const char __user *buf,
goto err_sighand;
}
- task_lock(task);
- if (!task->mm) {
- err = -EINVAL;
- goto err_task_lock;
- }
-
if (oom_adjust != task->signal->oom_adj) {
if (oom_adjust == OOM_DISABLE)
atomic_inc(&task->mm->oom_disable_count);
@@ -1083,11 +1084,10 @@ static ssize_t oom_adjust_write(struct file *file, const char __user *buf,
else
task->signal->oom_score_adj = (oom_adjust * OOM_SCORE_ADJ_MAX) /
-OOM_DISABLE;
-err_task_lock:
- task_unlock(task);
err_sighand:
unlock_task_sighand(task, &flags);
-err_task_struct:
+err_task_lock:
+ task_unlock(task);
put_task_struct(task);
out:
return err < 0 ? err : count;
@@ -1150,21 +1150,24 @@ static ssize_t oom_score_adj_write(struct file *file, const char __user *buf,
err = -ESRCH;
goto out;
}
+
+ task_lock(task);
+ if (!task->mm) {
+ err = -EINVAL;
+ goto err_task_lock;
+ }
+
if (!lock_task_sighand(task, &flags)) {
err = -ESRCH;
- goto err_task_struct;
+ goto err_task_lock;
}
+
if (oom_score_adj < task->signal->oom_score_adj &&
!capable(CAP_SYS_RESOURCE)) {
err = -EACCES;
goto err_sighand;
}
- task_lock(task);
- if (!task->mm) {
- err = -EINVAL;
- goto err_task_lock;
- }
if (oom_score_adj != task->signal->oom_score_adj) {
if (oom_score_adj == OOM_SCORE_ADJ_MIN)
atomic_inc(&task->mm->oom_disable_count);
@@ -1181,11 +1184,10 @@ static ssize_t oom_score_adj_write(struct file *file, const char __user *buf,
else
task->signal->oom_adj = (oom_score_adj * OOM_ADJUST_MAX) /
OOM_SCORE_ADJ_MAX;
-err_task_lock:
- task_unlock(task);
err_sighand:
unlock_task_sighand(task, &flags);
-err_task_struct:
+err_task_lock:
+ task_unlock(task);
put_task_struct(task);
out:
return err < 0 ? err : count;