lkml.org 
[lkml]   [2010]   [Jan]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 1/3] perf_event: fix race in perf_swevent_get_recursion_context()
On Mon, Jan 18, 2010 at 09:42:34PM +0800, Xiao Guangrong wrote:
> It only disable preemption in perf_swevent_get_recursion_context()
> it can't avoid race of hard-irq and NMI
>
> In this patch, we use atomic operation to avoid it and reduce
> cpu_ctx->recursion size, it also make this patch no need diable
> preemption
>
> Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>



I don't understand what is racy in what we have currently.



> int perf_swevent_get_recursion_context(void)
> {
> - struct perf_cpu_context *cpuctx = &get_cpu_var(perf_cpu_context);
> + struct perf_cpu_context *cpuctx = &__get_cpu_var(perf_cpu_context);
> int rctx;
>
> if (in_nmi())
> @@ -3933,13 +3933,8 @@ int perf_swevent_get_recursion_context(void)
> else
> rctx = 0;
>
> - if (cpuctx->recursion[rctx]) {
> - put_cpu_var(perf_cpu_context);
> + if (test_and_set_bit(rctx, &cpuctx->recursion))
> return -1;



This looks broken. We don't call back perf_swevent_put_recursion_context
in fail case, so the bit won't ever be cleared once we recurse.



\
 
 \ /
  Last update: 2010-01-18 17:43    [W:0.243 / U:0.092 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site