From: Shailabh Nagar <nagar@watson.ibm.com>
To: akpm@osdl.org
Cc: Arjan van de Ven <arjan@infradead.org>,
michal.k.k.piotrowski@gmail.com, linux-kernel@vger.kernel.org,
mingo@elte.hu, balbir@in.ibm.com, jlan@engr.sgi.com
Subject: [PATCH] delay accounting taskstats interface: send tgid once locking fix
Date: Tue, 27 Jun 2006 12:55:12 -0400 [thread overview]
Message-ID: <44A162F0.3060808@watson.ibm.com> (raw)
In-Reply-To: <44A1576C.8090307@watson.ibm.com>
Use irqsave variants of spin_lock for newly introduced tsk->signal->stats_lock
The lock is nested within tasklist_lock as part of release_task() and hence
there is possibility of a AB-BA deadlock if a timer interrupt occurs while
stats_lock is held.
Thanks to Arjan van de Ven for pointing out the lock bug.
The patch conservatively converts all use of stats_lock to irqsave variant
rather than only the call within taskstats_tgid_free which is the function
called within tasklist_lock protection.
Signed-off-by: Shailabh Nagar <nagar@watson.ibm.com>
---
include/linux/taskstats_kern.h | 11 +++++++----
kernel/taskstats.c | 16 ++++++++++------
2 files changed, 17 insertions(+), 10 deletions(-)
Index: linux-2.6.17/kernel/taskstats.c
===================================================================
--- linux-2.6.17.orig/kernel/taskstats.c 2006-06-27 12:22:45.000000000 -0400
+++ linux-2.6.17/kernel/taskstats.c 2006-06-27 12:34:16.000000000 -0400
@@ -133,6 +133,7 @@ static int fill_tgid(pid_t tgid, struct
struct taskstats *stats)
{
struct task_struct *tsk, *first;
+ unsigned long flags;
/*
* Add additional stats from live tasks except zombie thread group
@@ -152,10 +153,10 @@ static int fill_tgid(pid_t tgid, struct
get_task_struct(first);
/* Start with stats from dead tasks */
- spin_lock(&first->signal->stats_lock);
+ spin_lock_irqsave(&first->signal->stats_lock, flags);
if (first->signal->stats)
memcpy(stats, first->signal->stats, sizeof(*stats));
- spin_unlock(&first->signal->stats_lock);
+ spin_unlock_irqrestore(&first->signal->stats_lock, flags);
tsk = first;
read_lock(&tasklist_lock);
@@ -185,7 +186,9 @@ static int fill_tgid(pid_t tgid, struct
static void fill_tgid_exit(struct task_struct *tsk)
{
- spin_lock(&tsk->signal->stats_lock);
+ unsigned long flags;
+
+ spin_lock_irqsave(&tsk->signal->stats_lock, flags);
if (!tsk->signal->stats)
goto ret;
@@ -197,7 +200,7 @@ static void fill_tgid_exit(struct task_s
*/
delayacct_add_tsk(tsk->signal->stats, tsk);
ret:
- spin_unlock(&tsk->signal->stats_lock);
+ spin_unlock_irqrestore(&tsk->signal->stats_lock, flags);
return;
}
@@ -268,13 +271,14 @@ void taskstats_exit_send(struct task_str
size_t size;
int is_thread_group;
struct nlattr *na;
+ unsigned long flags;
if (!family_registered || !tidstats)
return;
- spin_lock(&tsk->signal->stats_lock);
+ spin_lock_irqsave(&tsk->signal->stats_lock, flags);
is_thread_group = tsk->signal->stats ? 1 : 0;
- spin_unlock(&tsk->signal->stats_lock);
+ spin_unlock_irqrestore(&tsk->signal->stats_lock, flags);
rc = 0;
/*
Index: linux-2.6.17/include/linux/taskstats_kern.h
===================================================================
--- linux-2.6.17.orig/include/linux/taskstats_kern.h 2006-06-27 12:22:34.000000000 -0400
+++ linux-2.6.17/include/linux/taskstats_kern.h 2006-06-27 12:36:12.000000000 -0400
@@ -50,17 +50,18 @@ static inline void taskstats_tgid_init(s
static inline void taskstats_tgid_alloc(struct signal_struct *sig)
{
struct taskstats *stats;
+ unsigned long flags;
stats = kmem_cache_zalloc(taskstats_cache, SLAB_KERNEL);
if (!stats)
return;
- spin_lock(&sig->stats_lock);
+ spin_lock_irqsave(&sig->stats_lock, flags);
if (!sig->stats) {
sig->stats = stats;
stats = NULL;
}
- spin_unlock(&sig->stats_lock);
+ spin_unlock_irqrestore(&sig->stats_lock, flags);
if (stats)
kmem_cache_free(taskstats_cache, stats);
@@ -69,12 +70,14 @@ static inline void taskstats_tgid_alloc(
static inline void taskstats_tgid_free(struct signal_struct *sig)
{
struct taskstats *stats = NULL;
- spin_lock(&sig->stats_lock);
+ unsigned long flags;
+
+ spin_lock_irqsave(&sig->stats_lock, flags);
if (sig->stats) {
stats = sig->stats;
sig->stats = NULL;
}
- spin_unlock(&sig->stats_lock);
+ spin_unlock_irqrestore(&sig->stats_lock, flags);
if (stats)
kmem_cache_free(taskstats_cache, stats);
}
next prev parent reply other threads:[~2006-06-27 16:56 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <200606261906.k5QJ6vCp025201@shell0.pdx.osdl.net>
2006-06-27 15:15 ` + delay-accounting-taskstats-interface-send-tgid-once.patch added to -mm tree Arjan van de Ven
2006-06-27 15:26 ` Arjan van de Ven
2006-06-27 15:53 ` Shailabh Nagar
2006-06-27 16:06 ` Shailabh Nagar
2006-06-27 16:55 ` Shailabh Nagar [this message]
2006-06-27 18:41 ` [PATCH] delay accounting taskstats interface: send tgid once locking fix Michal Piotrowski
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=44A162F0.3060808@watson.ibm.com \
--to=nagar@watson.ibm.com \
--cc=akpm@osdl.org \
--cc=arjan@infradead.org \
--cc=balbir@in.ibm.com \
--cc=jlan@engr.sgi.com \
--cc=linux-kernel@vger.kernel.org \
--cc=michal.k.k.piotrowski@gmail.com \
--cc=mingo@elte.hu \
/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