From: Oleg Nesterov <oleg@redhat.com>
To: Andrew Morton <akpm@linux-foundation.org>,
Ingo Molnar <mingo@elte.hu>,
Peter Zijlstra <peterz@infradead.org>
Cc: adobriyan@gmail.com, Doug Chapman <doug.chapman@hp.com>,
Roland McGrath <roland@redhat.com>,
linux-kernel@vger.kernel.org
Subject: [PATCH] for account_group_exec_runtime(), make sure ->signal can't be freed under rq->lock
Date: Mon, 10 Nov 2008 15:39:30 +0100 [thread overview]
Message-ID: <20081110143930.GA28275@redhat.com> (raw)
The patch is ugly, but I don't see the better fix for now. Needs
the review from Peter/Ingo.
Unlike other similar routines, account_group_exec_runtime() could be
called "implicitly" from within scheduler after exit_notify(). This
means we can race with the parent doing release_task(), we can't just
check ->signal != NULL.
Change __exit_signal() to do spin_unlock_wait(&task_rq(tsk)->lock)
before __cleanup_signal() to make sure ->signal can't be freed under
task_rq(tsk)->lock. Note that task_rq_unlock_wait() doesn't care
about the case when tsk changes cpu/rq under us, this should be OK.
Thanks to Ingo who nacked my previous buggy patch.
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Reported-by: Doug Chapman <doug.chapman@hp.com>
--- K-28/include/linux/sched.h~SIG_RQ_LOCK 2008-11-06 19:12:44.000000000 +0100
+++ K-28/include/linux/sched.h 2008-11-10 13:13:07.000000000 +0100
@@ -247,6 +247,7 @@ extern void init_idle(struct task_struct
extern void init_idle_bootup_task(struct task_struct *idle);
extern int runqueue_is_locked(void);
+extern void task_rq_unlock_wait(struct task_struct *p);
extern cpumask_t nohz_cpu_mask;
#if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ)
--- K-28/kernel/sched.c~SIG_RQ_LOCK 2008-11-06 19:12:44.000000000 +0100
+++ K-28/kernel/sched.c 2008-11-10 13:05:09.000000000 +0100
@@ -969,6 +969,14 @@ static struct rq *task_rq_lock(struct ta
}
}
+void task_rq_unlock_wait(struct task_struct *p)
+{
+ struct rq *rq = task_rq(p);
+
+ smp_mb();
+ spin_unlock_wait(&rq->lock);
+}
+
static void __task_rq_unlock(struct rq *rq)
__releases(rq->lock)
{
--- K-28/kernel/exit.c~SIG_RQ_LOCK 2008-11-06 19:11:02.000000000 +0100
+++ K-28/kernel/exit.c 2008-11-10 15:07:22.000000000 +0100
@@ -141,6 +141,11 @@ static void __exit_signal(struct task_st
if (sig) {
flush_sigqueue(&sig->shared_pending);
taskstats_tgid_free(sig);
+ /*
+ * Make sure ->signal can't go away under rq->lock,
+ * see account_group_exec_runtime().
+ */
+ task_rq_unlock_wait(tsk);
__cleanup_signal(sig);
}
}
next reply other threads:[~2008-11-10 13:39 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-11-10 14:39 Oleg Nesterov [this message]
2008-11-11 10:35 ` [PATCH] for account_group_exec_runtime(), make sure ->signal can't be freed under rq->lock Ingo Molnar
2008-11-11 12:58 ` Oleg Nesterov
2008-11-11 17:10 ` Frank Mayhar
2008-11-11 17:16 ` Ingo Molnar
2008-11-11 17:28 ` Frank Mayhar
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=20081110143930.GA28275@redhat.com \
--to=oleg@redhat.com \
--cc=adobriyan@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=doug.chapman@hp.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=peterz@infradead.org \
--cc=roland@redhat.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 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.