From: Steven Rostedt <rostedt@goodmis.org>
To: Namhyung Kim <namhyung@kernel.org>
Cc: linux-kernel@vger.kernel.org, Ingo Molnar <mingo@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
Rusty Russell <rusty@rustcorp.com.au>
Subject: Re: [RFC][PATCH 02/10] tracing: Allow for modules to export their trace enums as well
Date: Mon, 30 Mar 2015 09:48:02 -0400 [thread overview]
Message-ID: <20150330094802.3bfaabd4@gandalf.local.home> (raw)
In-Reply-To: <20150330024100.GB32033@sejong>
On Mon, 30 Mar 2015 11:41:00 +0900
Namhyung Kim <namhyung@kernel.org> wrote:
> > + * The trace_enum_maps are saved in an array whith two extra elements,
>
> s/whith/with/
Heh, thanks for catching that.
>
> > + * one at the beginning, and one at the end. The beginning item contains
> > + * the count of the saved maps (head.length), and the module they
> > + * belong to if not built in (head.mod). The ending item contains a
> > + * pointer to the next array of saved enum_map items.
> > + */
> > +union trace_enum_map_item {
> > + struct trace_enum_map map;
> > + struct trace_enum_map_head head;
> > + struct trace_enum_map_tail tail;
> > +};
> > +
> > +static union trace_enum_map_item *trace_enum_maps;
> >
> > static int tracing_set_tracer(struct trace_array *tr, const char *buf);
> >
> > @@ -3911,29 +3942,47 @@ static const struct file_operations tracing_saved_cmdlines_size_fops = {
> > .write = tracing_saved_cmdlines_size_write,
> > };
> >
> > +static union trace_enum_map_item *
> > +update_enum_map(union trace_enum_map_item *ptr)
> > +{
> > + if (!ptr->map.enum_string) {
> > + if (ptr->tail.next) {
> > + ptr = ptr->tail.next;
> > + ptr++;
>
> I guess this additional increment is to skip head item. Maybe it
> deserves a comment. :)
Yep it does. I'll add one.
>
>
> > + } else
> > + return NULL;
> > + }
> > + return ptr;
> > +}
> > +
> > static void *enum_map_next(struct seq_file *m, void *v, loff_t *pos)
> > {
> > - struct trace_enum_map *ptr = v;
> > + union trace_enum_map_item *ptr = v;
> >
> > - if (!ptr->enum_string)
> > + ptr = update_enum_map(ptr);
>
> Again, is this necessary?
Not really, but I'm doing it to be paranoid. If for some reason 'ptr'
is at the tail end (which it should never happen), then the increment
below will cause an invalid pointer dereference.
I should at least add a comment here saying I'm being paranoid. It's
far from a fast path so I don't really care about slowing things down
here to be extra safe.
>
>
> > + if (!ptr)
> > return NULL;
> >
> > ptr++;
> >
> > (*pos)++;
> >
> > - if (!ptr->enum_string)
> > - return NULL;
> > + ptr = update_enum_map(ptr);
> >
> > return ptr;
> > }
> >
> > + /*
> > + * The trace_enum_maps contains the map plus a head and tail item,
> > + * where the head holds the module and length of array, and the
> > + * tail holds a pointer to the next list.
> > + */
> > + map_array = kmalloc(sizeof(*map_array) * (len + 2), GFP_KERNEL);
> > if (!map_array) {
> > pr_warning("Unable to allocate trace enum mapping\n");
> > return;
> > }
> >
> > - trace_enum_maps = map_array;
> > + mutex_lock(&trace_enum_mutex);
> > +
> > + if (!trace_enum_maps)
> > + trace_enum_maps = map_array;
> > + else {
> > + ptr = trace_enum_maps;
> > + for (;;) {
> > + ptr = ptr + ptr->head.length + 1;
>
> Looks like access to tail item is used frequently. How about adding a
> helper function like enum_maps_tail_item()?
I'll look into it. Thanks for the review.
-- Steve
next prev parent reply other threads:[~2015-03-30 13:48 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-27 21:37 [RFC][PATCH 00/10] tracing: Use TRACE_DEFINE_ENUM() to show enum values Steven Rostedt
2015-03-27 21:37 ` [RFC][PATCH 01/10] tracing: Add TRACE_DEFINE_ENUM() macro to map enums to their values Steven Rostedt
2015-03-30 2:27 ` Namhyung Kim
2015-03-27 21:37 ` [RFC][PATCH 02/10] tracing: Allow for modules to export their trace enums as well Steven Rostedt
2015-03-30 2:10 ` Rusty Russell
2015-03-30 2:41 ` Namhyung Kim
2015-03-30 13:48 ` Steven Rostedt [this message]
2015-03-27 21:37 ` [RFC][PATCH 03/10] x86/tlb/trace: Export enums in used by tlb_flush tracepoint Steven Rostedt
2015-03-27 21:37 ` [RFC][PATCH 04/10] net/9p/tracing: Export enums in tracepoints to userspace Steven Rostedt
2015-03-27 21:37 ` [RFC][PATCH 05/10] f2fs: Export the enums in the " Steven Rostedt
2015-03-30 2:47 ` Namhyung Kim
2015-03-30 13:49 ` Steven Rostedt
2015-03-27 21:37 ` [RFC][PATCH 06/10] irq/tracing: Export enums in tracepoints to user space Steven Rostedt
2015-03-27 21:46 ` Steven Rostedt
2015-03-27 21:37 ` [RFC][PATCH 07/10] mm: tracing: " Steven Rostedt
2015-03-27 21:37 ` [RFC][PATCH 08/10] SUNRPC: " Steven Rostedt
2015-03-27 21:37 ` [RFC][PATCH 09/10] v4l: Export enums used by " Steven Rostedt
2015-03-28 13:00 ` Xie XiuQi
2015-03-28 16:20 ` Steven Rostedt
2015-03-27 21:37 ` [RFC][PATCH 10/10] writeback: Export enums used by tracepoint " Steven Rostedt
2015-03-30 3:38 ` [RFC][PATCH 00/10] tracing: Use TRACE_DEFINE_ENUM() to show enum values Masami Hiramatsu
2015-03-30 14:07 ` Steven Rostedt
2015-03-31 7:36 ` Masami Hiramatsu
2015-03-31 13:26 ` Steven Rostedt
2015-04-01 7:23 ` Masami Hiramatsu
2015-03-31 21:30 ` Dave Chinner
2015-03-31 22:56 ` 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=20150330094802.3bfaabd4@gandalf.local.home \
--to=rostedt@goodmis.org \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=masami.hiramatsu.pt@hitachi.com \
--cc=mathieu.desnoyers@efficios.com \
--cc=mingo@kernel.org \
--cc=namhyung@kernel.org \
--cc=rusty@rustcorp.com.au \
/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
all inboxes | Powered by JetHome®