[<prev] [next>] [day] [month] [year] [list]
Message-ID: <tip-3f4dee227348daac32f36daad9a91059efd0723e@git.kernel.org>
Date: Fri, 29 May 2009 12:27:34 GMT
From: tip-bot for Ingo Molnar <mingo@...e.hu>
To: linux-tip-commits@...r.kernel.org
Cc: linux-kernel@...r.kernel.org, acme@...hat.com, paulus@...ba.org,
hpa@...or.com, mingo@...hat.com, jkacur@...hat.com,
a.p.zijlstra@...llo.nl, efault@....de, mtosatti@...hat.com,
tglx@...utronix.de, cjashfor@...ux.vnet.ibm.com, mingo@...e.hu
Subject: [tip:perfcounters/core] perf_counter: Fix cpuctx->task_ctx races
Commit-ID: 3f4dee227348daac32f36daad9a91059efd0723e
Gitweb: http://git.kernel.org/tip/3f4dee227348daac32f36daad9a91059efd0723e
Author: Ingo Molnar <mingo@...e.hu>
AuthorDate: Fri, 29 May 2009 11:25:09 +0200
Committer: Ingo Molnar <mingo@...e.hu>
CommitDate: Fri, 29 May 2009 14:28:36 +0200
perf_counter: Fix cpuctx->task_ctx races
Peter noticed that we are sometimes reading cpuctx->task_ctx with
interrupts enabled.
Noticed-by: Peter Zijlstra <a.p.zijlstra@...llo.nl>
Acked-by: Peter Zijlstra <a.p.zijlstra@...llo.nl>
Cc: Mike Galbraith <efault@....de>
Cc: Paul Mackerras <paulus@...ba.org>
Cc: Corey Ashford <cjashfor@...ux.vnet.ibm.com>
Cc: Marcelo Tosatti <mtosatti@...hat.com>
Cc: Arnaldo Carvalho de Melo <acme@...hat.com>
Cc: John Kacur <jkacur@...hat.com>
LKML-Reference: <new-submission>
Signed-off-by: Ingo Molnar <mingo@...e.hu>
---
kernel/perf_counter.c | 28 ++++++++++++++++++++--------
1 files changed, 20 insertions(+), 8 deletions(-)
diff --git a/kernel/perf_counter.c b/kernel/perf_counter.c
index db843f8..eb34604 100644
--- a/kernel/perf_counter.c
+++ b/kernel/perf_counter.c
@@ -234,15 +234,18 @@ static void __perf_counter_remove_from_context(void *info)
struct perf_counter_context *ctx = counter->ctx;
unsigned long flags;
+ local_irq_save(flags);
/*
* If this is a task context, we need to check whether it is
* the current task context of this cpu. If not it has been
* scheduled out before the smp call arrived.
*/
- if (ctx->task && cpuctx->task_ctx != ctx)
+ if (ctx->task && cpuctx->task_ctx != ctx) {
+ local_irq_restore(flags);
return;
+ }
- spin_lock_irqsave(&ctx->lock, flags);
+ spin_lock(&ctx->lock);
/*
* Protect the list operation against NMI by disabling the
* counters on a global level.
@@ -382,14 +385,17 @@ static void __perf_counter_disable(void *info)
struct perf_counter_context *ctx = counter->ctx;
unsigned long flags;
+ local_irq_save(flags);
/*
* If this is a per-task counter, need to check whether this
* counter's task is the current task on this cpu.
*/
- if (ctx->task && cpuctx->task_ctx != ctx)
+ if (ctx->task && cpuctx->task_ctx != ctx) {
+ local_irq_restore(flags);
return;
+ }
- spin_lock_irqsave(&ctx->lock, flags);
+ spin_lock(&ctx->lock);
/*
* If the counter is on, turn it off.
@@ -615,6 +621,7 @@ static void __perf_install_in_context(void *info)
unsigned long flags;
int err;
+ local_irq_save(flags);
/*
* If this is a task context, we need to check whether it is
* the current task context of this cpu. If not it has been
@@ -623,12 +630,14 @@ static void __perf_install_in_context(void *info)
* on this cpu because it had no counters.
*/
if (ctx->task && cpuctx->task_ctx != ctx) {
- if (cpuctx->task_ctx || ctx->task != current)
+ if (cpuctx->task_ctx || ctx->task != current) {
+ local_irq_restore(flags);
return;
+ }
cpuctx->task_ctx = ctx;
}
- spin_lock_irqsave(&ctx->lock, flags);
+ spin_lock(&ctx->lock);
ctx->is_active = 1;
update_context_time(ctx);
@@ -745,17 +754,20 @@ static void __perf_counter_enable(void *info)
unsigned long flags;
int err;
+ local_irq_save(flags);
/*
* If this is a per-task counter, need to check whether this
* counter's task is the current task on this cpu.
*/
if (ctx->task && cpuctx->task_ctx != ctx) {
- if (cpuctx->task_ctx || ctx->task != current)
+ if (cpuctx->task_ctx || ctx->task != current) {
+ local_irq_restore(flags);
return;
+ }
cpuctx->task_ctx = ctx;
}
- spin_lock_irqsave(&ctx->lock, flags);
+ spin_lock(&ctx->lock);
ctx->is_active = 1;
update_context_time(ctx);
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists