From: Tom Zanussi <tom.zanussi@linux.intel.com>
To: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: rostedt@goodmis.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 10/11] tracing: add and use generic set_trigger_filter() implementation
Date: Fri, 21 Jun 2013 12:59:35 -0500 [thread overview]
Message-ID: <1371837575.6453.23.camel@empanada> (raw)
In-Reply-To: <51C3D3FD.2070408@hitachi.com>
Hi Masami,
On Fri, 2013-06-21 at 13:18 +0900, Masami Hiramatsu wrote:
> (2013/06/21 3:31), Tom Zanussi wrote:
> > diff --git a/include/trace/ftrace.h b/include/trace/ftrace.h
> > index 88ac7da..7c5627f 100644
> > --- a/include/trace/ftrace.h
> > +++ b/include/trace/ftrace.h
> > @@ -522,14 +522,6 @@ ftrace_raw_event_##call(void *__data, proto) \
> > int __data_size; \
> > int pc; \
> > \
> > - if (test_bit(FTRACE_EVENT_FL_TRIGGER_MODE_BIT, \
> > - &ftrace_file->flags)) \
> > - event_triggers_call(ftrace_file); \
> > - \
> > - if (test_bit(FTRACE_EVENT_FL_SOFT_DISABLED_BIT, \
> > - &ftrace_file->flags)) \
> > - return; \
> > - \
> > local_save_flags(irq_flags); \
> > pc = preempt_count(); \
> > \
> > @@ -547,8 +539,22 @@ ftrace_raw_event_##call(void *__data, proto) \
> > \
> > { assign; } \
> > \
> > + if (test_bit(FTRACE_EVENT_FL_SOFT_DISABLED_BIT, \
> > + &ftrace_file->flags)) { \
> > + ring_buffer_discard_commit(buffer, event); \
> > + \
> > + if (test_bit(FTRACE_EVENT_FL_TRIGGER_MODE_BIT, \
> > + &ftrace_file->flags)) \
> > + event_triggers_call(ftrace_file, entry); \
> > + return; \
> > + } \
> > + \
> > if (!filter_current_check_discard(buffer, event_call, entry, event)) \
> > trace_buffer_unlock_commit(buffer, event, irq_flags, pc); \
> > + \
> > + if (test_bit(FTRACE_EVENT_FL_TRIGGER_MODE_BIT, \
> > + &ftrace_file->flags)) \
> > + event_triggers_call(ftrace_file, entry); \
>
> Actually, since "entry" is a part of "event" which may be already discarded,
> I think we should not access it here. It may not cause real problem because
> even if it is discarded, that does NOT mean it is freed. However, it depends
> on the ring-buffer implementation.
>
> I recommend you to call event triggers before commit the event. It will also
> make the code simpler :)
>
That's what I originally did, and is what I was referring to when I
mentioned the bit of 'trickiness' here. ;-)
The problem is that the trace_recursive_lock() check in
ring_buffer_lock_reserve() prevents a trigger that itself logs to the
ring buffer from reserving a slot in the buffer, since it's being done
from the same context as the triggering event. For example, the
stacktrace trigger, which calls trace_dump_stack().
So the code is a bit more convoluted than I'd like because of that -
since we can't really invoke the triggers before the current event is
committed, it waits until the current event is either discarded (because
we're soft disabled) or committed (logging a normally-enabled event).
But you do point out a real problem with this - it means having to look
at a discarded event in the soft-disabled case, and if for example some
interrupt actually reserves and logs an event between the time we do the
discard and invoke the filter, we could end up with a false filtering
outcome. I'm not sure how to prevent that though at this point - will
have think about it some more...
Tom
> > diff --git a/kernel/trace/trace_syscalls.c b/kernel/trace/trace_syscalls.c
> > index e287011..47fa712 100644
> > --- a/kernel/trace/trace_syscalls.c
> > +++ b/kernel/trace/trace_syscalls.c
> > @@ -319,14 +319,6 @@ static void ftrace_syscall_enter(void *data, struct pt_regs *regs, long id)
> > if (!sys_data)
> > return;
> >
> > - if (test_bit(FTRACE_EVENT_FL_TRIGGER_MODE_BIT,
> > - &sys_data->enter_file->flags))
> > - event_triggers_call(sys_data->enter_file);
> > -
> > - if (test_bit(FTRACE_EVENT_FL_SOFT_DISABLED_BIT,
> > - &sys_data->enter_file->flags))
> > - return;
> > -
> > size = sizeof(*entry) + sizeof(unsigned long) * sys_data->nb_args;
> >
> > buffer = tr->trace_buffer.buffer;
> > @@ -339,9 +331,23 @@ static void ftrace_syscall_enter(void *data, struct pt_regs *regs, long id)
> > entry->nr = syscall_nr;
> > syscall_get_arguments(current, regs, 0, sys_data->nb_args, entry->args);
> >
> > + if (test_bit(FTRACE_EVENT_FL_SOFT_DISABLED_BIT,
> > + &sys_data->enter_file->flags)) {
> > + ring_buffer_discard_commit(buffer, event);
> > +
> > + if (test_bit(FTRACE_EVENT_FL_TRIGGER_MODE_BIT,
> > + &sys_data->enter_file->flags))
> > + event_triggers_call(sys_data->enter_file, entry);
> > + return;
> > + }
> > +
> > if (!filter_current_check_discard(buffer, sys_data->enter_event,
> > entry, event))
> > trace_current_buffer_unlock_commit(buffer, event, 0, 0);
> > +
> > + if (test_bit(FTRACE_EVENT_FL_TRIGGER_MODE_BIT,
> > + &sys_data->enter_file->flags))
> > + event_triggers_call(sys_data->enter_file, entry);
> > }
> >
> > static void ftrace_syscall_exit(void *data, struct pt_regs *regs, long ret)
> > @@ -363,14 +369,6 @@ static void ftrace_syscall_exit(void *data, struct pt_regs *regs, long ret)
> > if (!sys_data)
> > return;
> >
> > - if (test_bit(FTRACE_EVENT_FL_TRIGGER_MODE_BIT,
> > - &sys_data->exit_file->flags))
> > - event_triggers_call(sys_data->exit_file);
> > -
> > - if (test_bit(FTRACE_EVENT_FL_SOFT_DISABLED_BIT,
> > - &sys_data->exit_file->flags))
> > - return;
> > -
> > buffer = tr->trace_buffer.buffer;
> > event = trace_buffer_lock_reserve(buffer,
> > sys_data->exit_event->event.type, sizeof(*entry), 0, 0);
> > @@ -381,9 +379,23 @@ static void ftrace_syscall_exit(void *data, struct pt_regs *regs, long ret)
> > entry->nr = syscall_nr;
> > entry->ret = syscall_get_return_value(current, regs);
> >
> > + if (test_bit(FTRACE_EVENT_FL_SOFT_DISABLED_BIT,
> > + &sys_data->exit_file->flags)) {
> > + ring_buffer_discard_commit(buffer, event);
> > +
> > + if (test_bit(FTRACE_EVENT_FL_TRIGGER_MODE_BIT,
> > + &sys_data->exit_file->flags))
> > + event_triggers_call(sys_data->exit_file, entry);
> > + return;
> > + }
> > +
> > if (!filter_current_check_discard(buffer, sys_data->exit_event,
> > entry, event))
> > trace_current_buffer_unlock_commit(buffer, event, 0, 0);
> > +
> > + if (test_bit(FTRACE_EVENT_FL_TRIGGER_MODE_BIT,
> > + &sys_data->exit_file->flags))
> > + event_triggers_call(sys_data->exit_file, entry);
> > }
> >
> > static int reg_event_syscall_enter(struct ftrace_event_file *file,
> >
>
> Same changes are needed here.
>
> Thank you,
>
next prev parent reply other threads:[~2013-06-21 17:59 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-20 18:31 [PATCH 00/11] tracing: trace event triggers Tom Zanussi
2013-06-20 18:31 ` [PATCH 01/11] tracing: simplify event_enable_read() Tom Zanussi
2013-06-21 6:52 ` Masami Hiramatsu
2013-06-20 18:31 ` [PATCH 02/11] tracing: add missing syscall_metadata comment Tom Zanussi
2013-06-21 7:06 ` Masami Hiramatsu
2013-06-21 19:48 ` Steven Rostedt
2013-06-20 18:31 ` [PATCH 03/11] tracing: add soft disable for syscall events Tom Zanussi
2013-06-21 6:53 ` zhangwei(Jovi)
2013-06-21 20:22 ` Steven Rostedt
2013-06-22 5:08 ` Jovi Zhang
2013-06-22 11:45 ` Steven Rostedt
2013-06-20 18:31 ` [PATCH 04/11] tracing: fix disabling of soft disable Tom Zanussi
2013-06-21 11:12 ` Masami Hiramatsu
2013-06-21 20:39 ` Steven Rostedt
2013-06-21 21:14 ` Tom Zanussi
2013-06-22 5:25 ` Tom Zanussi
2013-07-01 11:38 ` Masami Hiramatsu
2013-06-20 18:31 ` [PATCH 05/11] tracing: add basic event trigger framework Tom Zanussi
2013-06-21 12:12 ` Masami Hiramatsu
2013-06-20 18:31 ` [PATCH 06/11] tracing: add 'traceon' and 'traceoff' event trigger commands Tom Zanussi
2013-06-20 18:31 ` [PATCH 07/11] tracing: add 'snapshot' event trigger command Tom Zanussi
2013-06-20 18:31 ` [PATCH 08/11] tracing: add 'stacktrace' " Tom Zanussi
2013-06-20 18:31 ` [PATCH 09/11] tracing: add 'enable_event' and 'disable_event' event trigger commands Tom Zanussi
2013-06-20 18:31 ` [PATCH 10/11] tracing: add and use generic set_trigger_filter() implementation Tom Zanussi
2013-06-21 4:18 ` Masami Hiramatsu
2013-06-21 17:59 ` Tom Zanussi [this message]
2013-06-22 11:53 ` Steven Rostedt
2013-06-20 18:31 ` [PATCH 11/11] tracing: add documentation for trace event triggers Tom Zanussi
2013-06-21 19:45 ` [PATCH 00/11] tracing: " Steven Rostedt
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=1371837575.6453.23.camel@empanada \
--to=tom.zanussi@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=masami.hiramatsu.pt@hitachi.com \
--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).