linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Frederic Weisbecker <fweisbec@gmail.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@elte.hu>, Paul Mackerras <paulus@samba.org>,
	Arnaldo Carvalho de Melo <acme@infradead.org>,
	Steven Rostedt <rostedt@goodmis.org>,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 02b/10] perf, trace: Fix probe unregister race
Date: Fri, 21 May 2010 12:43:54 +0200	[thread overview]
Message-ID: <20100521104352.GH30108@nowhere> (raw)
In-Reply-To: <1274438476.1674.1702.camel@laptop>

On Fri, May 21, 2010 at 12:41:16PM +0200, Peter Zijlstra wrote:
> tracepoint_probe_unregister() does not synchronize against the probe callbacks,
> so do that explicitly. This properly serializes the callbacks and the free of
> the data used therein.
> 
> Also, use this_cpu_ptr() where possible.
> 
> Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>


Acked-by: Frederic Weisbecker <fweisbec@gmail.com>

(and you previous patches too)



> ---
>  include/trace/ftrace.h          |    2 +-
>  kernel/trace/trace_event_perf.c |   10 ++++++++--
>  kernel/trace/trace_kprobe.c     |    4 ++--
>  kernel/trace/trace_syscalls.c   |    4 ++--
>  4 files changed, 13 insertions(+), 7 deletions(-)
> 
> Index: linux-2.6/include/trace/ftrace.h
> ===================================================================
> --- linux-2.6.orig/include/trace/ftrace.h
> +++ linux-2.6/include/trace/ftrace.h
> @@ -791,7 +791,7 @@ perf_trace_templ_##call(struct ftrace_ev
>  									\
>  	{ assign; }							\
>  									\
> -	head = per_cpu_ptr(event_call->perf_events, smp_processor_id());\
> +	head = this_cpu_ptr(event_call->perf_events);			\
>  	perf_trace_buf_submit(entry, __entry_size, rctx, __addr,	\
>  		__count, __regs, head);					\
>  }
> Index: linux-2.6/kernel/trace/trace_event_perf.c
> ===================================================================
> --- linux-2.6.orig/kernel/trace/trace_event_perf.c
> +++ linux-2.6/kernel/trace/trace_event_perf.c
> @@ -109,7 +109,7 @@ int perf_trace_enable(struct perf_event 
>  	if (WARN_ON_ONCE(!list))
>  		return -EINVAL;
>  
> -	list = per_cpu_ptr(list, smp_processor_id());
> +	list = this_cpu_ptr(list);
>  	hlist_add_head_rcu(&p_event->hlist_entry, list);
>  
>  	return 0;
> @@ -130,6 +130,12 @@ void perf_trace_destroy(struct perf_even
>  
>  	tp_event->perf_event_disable(tp_event);
>  
> +	/*
> +	 * Ensure our callback won't be called anymore. See
> +	 * tracepoint_probe_unregister() and __DO_TRACE().
> +	 */
> +	synchronize_sched();
> +
>  	free_percpu(tp_event->perf_events);
>  	tp_event->perf_events = NULL;
>  
> @@ -156,7 +162,7 @@ __kprobes void *perf_trace_buf_prepare(i
>  	if (*rctxp < 0)
>  		return NULL;
>  
> -	raw_data = per_cpu_ptr(perf_trace_buf[*rctxp], smp_processor_id());
> +	raw_data = this_cpu_ptr(perf_trace_buf[*rctxp]);
>  
>  	/* zero the dead bytes from align to not leak stack to user */
>  	memset(&raw_data[size - sizeof(u64)], 0, sizeof(u64));
> Index: linux-2.6/kernel/trace/trace_kprobe.c
> ===================================================================
> --- linux-2.6.orig/kernel/trace/trace_kprobe.c
> +++ linux-2.6/kernel/trace/trace_kprobe.c
> @@ -1362,7 +1362,7 @@ static __kprobes void kprobe_perf_func(s
>  	for (i = 0; i < tp->nr_args; i++)
>  		call_fetch(&tp->args[i].fetch, regs, data + tp->args[i].offset);
>  
> -	head = per_cpu_ptr(call->perf_events, smp_processor_id());
> +	head = this_cpu_ptr(call->perf_events);
>  	perf_trace_buf_submit(entry, size, rctx, entry->ip, 1, regs, head);
>  }
>  
> @@ -1395,7 +1395,7 @@ static __kprobes void kretprobe_perf_fun
>  	for (i = 0; i < tp->nr_args; i++)
>  		call_fetch(&tp->args[i].fetch, regs, data + tp->args[i].offset);
>  
> -	head = per_cpu_ptr(call->perf_events, smp_processor_id());
> +	head = this_cpu_ptr(call->perf_events);
>  	perf_trace_buf_submit(entry, size, rctx, entry->ret_ip, 1, regs, head);
>  }
>  
> Index: linux-2.6/kernel/trace/trace_syscalls.c
> ===================================================================
> --- linux-2.6.orig/kernel/trace/trace_syscalls.c
> +++ linux-2.6/kernel/trace/trace_syscalls.c
> @@ -469,7 +469,7 @@ static void perf_syscall_enter(struct pt
>  	syscall_get_arguments(current, regs, 0, sys_data->nb_args,
>  			       (unsigned long *)&rec->args);
>  
> -	head = per_cpu_ptr(sys_data->enter_event->perf_events, smp_processor_id());
> +	head = this_cpu_ptr(sys_data->enter_event->perf_events);
>  	perf_trace_buf_submit(rec, size, rctx, 0, 1, regs, head);
>  }
>  
> @@ -545,7 +545,7 @@ static void perf_syscall_exit(struct pt_
>  	rec->nr = syscall_nr;
>  	rec->ret = syscall_get_return_value(current, regs);
>  
> -	head = per_cpu_ptr(sys_data->exit_event->perf_events, smp_processor_id());
> +	head = this_cpu_ptr(sys_data->exit_event->perf_events);
>  	perf_trace_buf_submit(rec, size, rctx, 0, 1, regs, head);
>  }
>  
> 
> 


  reply	other threads:[~2010-05-21 10:44 UTC|newest]

Thread overview: 53+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-21  9:02 [PATCH 00/10] perf tracepoint and output optimizations Peter Zijlstra
2010-05-21  9:02 ` [PATCH 01/10] perf, trace: Remove IRQ-disable from perf/tracepoint interaction Peter Zijlstra
2010-05-21 17:43   ` Frank Ch. Eigler
2010-05-21 17:53     ` Steven Rostedt
2010-05-21 18:07       ` Frank Ch. Eigler
2010-05-23 12:11   ` Paul Mackerras
2010-05-23 18:16     ` Peter Zijlstra
2010-05-24  4:29       ` Paul Mackerras
2010-05-25  8:06         ` [tip:perf/core] perf, trace: Fix IRQ-disable removal " tip-bot for Peter Zijlstra
2010-05-25  9:02           ` Peter Zijlstra
2010-05-25  9:30             ` [tip:perf/core] perf, trace: Fix !x86 build bug tip-bot for Peter Zijlstra
2010-05-24 11:31       ` [PATCH 01/10] perf, trace: Remove IRQ-disable from perf/tracepoint interaction Frederic Weisbecker
2010-05-25  7:30   ` [PATCH 01a/10] perf, trace: Fix !x86 build issue Peter Zijlstra
2010-05-21  9:02 ` [PATCH 02/10] perf, trace: Use per-tracepoint-per-cpu hlist to track events Peter Zijlstra
2010-05-21  9:40   ` Frederic Weisbecker
2010-05-21 10:02     ` Peter Zijlstra
2010-05-21 10:13       ` Frederic Weisbecker
2010-05-21 10:15         ` Peter Zijlstra
2010-05-21 10:19           ` Frederic Weisbecker
2010-05-21 10:38           ` Ingo Molnar
2010-05-21 10:51             ` Ingo Molnar
2010-05-21 10:19         ` Peter Zijlstra
2010-05-21 10:21           ` Frederic Weisbecker
2010-05-21 10:34             ` Peter Zijlstra
2010-05-21 10:38               ` Frederic Weisbecker
2010-05-21 10:41   ` [PATCH 02b/10] perf, trace: Fix probe unregister race Peter Zijlstra
2010-05-21 10:43     ` Frederic Weisbecker [this message]
2010-05-31  7:19     ` [tip:perf/urgent] perf_events, " tip-bot for Peter Zijlstra
2010-05-21 11:28   ` [tip:perf/core] perf, trace: Optimize tracepoints by using per-tracepoint-per-cpu hlist to track events tip-bot for Peter Zijlstra
2010-05-21 14:04   ` [PATCH 02/10] perf, trace: Use " Steven Rostedt
2010-05-21 14:18     ` Peter Zijlstra
2010-05-21 14:25       ` Peter Zijlstra
2010-05-31  7:20         ` [tip:perf/urgent] perf_events, trace: Fix perf_trace_destroy(), mutex went missing tip-bot for Peter Zijlstra
2010-05-21  9:02 ` [PATCH 03/10] perf: Ensure IOC_OUTPUT isnt used to create multi-writer buffers Peter Zijlstra
2010-05-21 11:28   ` [tip:perf/core] perf: Ensure that IOC_OUTPUT isn't " tip-bot for Peter Zijlstra
2010-05-21  9:02 ` [PATCH 04/10] perf-record: Remove -M Peter Zijlstra
2010-05-21 11:28   ` [tip:perf/core] " tip-bot for Peter Zijlstra
2010-05-21  9:02 ` [PATCH 05/10] perf-record: Share per-cpu buffers Peter Zijlstra
2010-05-21  9:44   ` Frederic Weisbecker
2010-05-21 10:03     ` Peter Zijlstra
2010-05-21 11:29   ` [tip:perf/core] " tip-bot for Peter Zijlstra
2010-05-21  9:02 ` [PATCH 06/10] perf: Fix wakeup storm for RO mmap()s Peter Zijlstra
2010-05-21 11:29   ` [tip:perf/core] " tip-bot for Peter Zijlstra
2010-05-21  9:02 ` [PATCH 07/10] perf: Optimize perf_output_copy Peter Zijlstra
2010-05-21 11:29   ` [tip:perf/core] perf: Optimize perf_output_copy() tip-bot for Peter Zijlstra
2010-05-21  9:02 ` [PATCH 08/10] perf: Optimize the !vmalloc backed buffer Peter Zijlstra
2010-05-21 11:29   ` [tip:perf/core] " tip-bot for Peter Zijlstra
2010-05-21  9:02 ` [PATCH 09/10] perf: Remove more fastpath code Peter Zijlstra
2010-05-21 11:15   ` Steven Rostedt
2010-05-21 11:18     ` Peter Zijlstra
2010-05-21 11:30   ` [tip:perf/core] perf: Remove more code from the fastpath tip-bot for Peter Zijlstra
2010-05-21  9:02 ` [PATCH 10/10] perf: Optimize perf_tp_event_match Peter Zijlstra
2010-05-21 11:30   ` [tip:perf/core] perf: Optimize perf_tp_event_match() tip-bot for Peter Zijlstra

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=20100521104352.GH30108@nowhere \
    --to=fweisbec@gmail.com \
    --cc=acme@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=paulus@samba.org \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    /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;
as well as URLs for NNTP newsgroup(s).