public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@redhat.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Balbir Singh <balbir@linux.vnet.ibm.com>,
	Americo Wang <xiyou.wangcong@gmail.com>,
	"Eric W. Biederman" <ebiederm@xmission.com>,
	Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>,
	Ingo Molnar <mingo@elte.hu>,
	Peter Zijlstra <peterz@infradead.org>,
	Roland McGrath <roland@redhat.com>,
	Spencer Candland <spencer@bluehost.com>,
	Stanislaw Gruszka <sgruszka@redhat.com>,
	linux-kernel@vger.kernel.org
Subject: [PATCH -mm 3/4] cputimers: thread_group_times: make it rcu-safe
Date: Mon, 29 Mar 2010 20:13:59 +0200	[thread overview]
Message-ID: <20100329181359.GD16356@redhat.com> (raw)
In-Reply-To: <20100329181204.GA16356@redhat.com>

thread_group_times() relies on ->siglock hold by the caller when it
updates sig->prev_Xtime members. Change the code to take cputimer.lock
around the assignment.

This makes it rcu-safe and fixes the theoretical race. wait_task_zombie()
calls it lockless and thus can race with do_task_stat().

Note: we are taking cputimer.lock under ->siglock but this dependency
is not new, thread_group_cputimer() already does this.

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
---

 kernel/sched.c |    3 +++
 1 file changed, 3 insertions(+)

--- 34-rc1/kernel/sched.c~cpuacct_3_thread_group_times_dont_rely_on_siglock	2010-03-29 19:44:25.000000000 +0200
+++ 34-rc1/kernel/sched.c	2010-03-29 19:46:21.000000000 +0200
@@ -3449,6 +3449,7 @@ void thread_group_times(struct task_stru
 	struct signal_struct *sig = p->signal;
 	struct task_cputime cputime;
 	cputime_t rtime, utime, total;
+	unsigned long flags;
 
 	thread_group_cputime(p, &cputime);
 
@@ -3464,9 +3465,11 @@ void thread_group_times(struct task_stru
 	} else
 		utime = rtime;
 
+	spin_lock_irqsave(&sig->cputimer.lock, flags);
 	sig->prev_utime = max(sig->prev_utime, utime);
 	sig->prev_stime = max(sig->prev_stime,
 			      cputime_sub(rtime, sig->prev_utime));
+	spin_unlock_irqrestore(&sig->cputimer.lock, flags);
 
 	*ut = sig->prev_utime;
 	*st = sig->prev_stime;


  parent reply	other threads:[~2010-03-29 18:16 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-24 20:45 [RFC,PATCH 1/2] cputimers/proc: do_task_stat()->task_times() can race with getrusage() Oleg Nesterov
2010-03-26  3:53 ` Balbir Singh
2010-03-26  7:37   ` Stanislaw Gruszka
2010-03-26 16:12     ` Stanislaw Gruszka
2010-03-26 21:49   ` Oleg Nesterov
2010-03-29 11:17     ` Stanislaw Gruszka
2010-03-29 12:54       ` Oleg Nesterov
2010-03-29 18:12         ` [PATCH -mm 0/4] cputimers/proc: do_task_stat: don't walk through the thread list under ->siglock Oleg Nesterov
2010-03-29 18:12           ` [PATCH -mm 1/4] cputimers: thread_group_cputime: cleanup rcu/signal stuff Oleg Nesterov
2010-03-29 18:13           ` [PATCH -mm 2/4] cputimers: make sure thread_group_cputime() can't count the same thread twice lockless Oleg Nesterov
2010-03-30 11:01             ` Stanislaw Gruszka
2010-03-30 13:43               ` Oleg Nesterov
2010-03-29 18:13           ` Oleg Nesterov [this message]
2010-03-29 18:14           ` [PATCH -mm 1/4] cputimers: do_task_stat: avoid ->siglock for while_each_thread() Oleg Nesterov
2010-03-29 18:16             ` Oleg Nesterov

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=20100329181359.GD16356@redhat.com \
    --to=oleg@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=balbir@linux.vnet.ibm.com \
    --cc=ebiederm@xmission.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=peterz@infradead.org \
    --cc=roland@redhat.com \
    --cc=seto.hidetoshi@jp.fujitsu.com \
    --cc=sgruszka@redhat.com \
    --cc=spencer@bluehost.com \
    --cc=xiyou.wangcong@gmail.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox