Re: [PATCH 02/31] perf tools: Don't set cmdline_group_boundary if no evsel is collected

From: Wangnan (F)
Date: Tue Sep 01 2015 - 06:50:54 EST

On 2015/9/1 3:20, Arnaldo Carvalho de Melo wrote:
Em Sat, Aug 29, 2015 at 04:21:36AM +0000, Wang Nan escreveu:
If parse_events__scanner() collects no entry, perf_evlist__last(evlist)
is invalid. Then setting of cmdline_group_boundary touches invalid.

It could happend in currect BPF implementation. See [1]. Although it
can be fixed, for safety reason it whould be better to introduce this

Instead of checking number of entries, check data.list instead, so we
can add dummy evsel here.
Event parsing fixes should have Jiri Olsa on the CC list, Jiri, is this

From what I can see it looks Ok, my question, just from looking at this
patch, is if it is valid to get to this point with an empty data.list,
i.e. was it ever possible and this is a bug irrespective of eBPF?

It should not be a existing bug in perf. There are other places rely on
non-empty of the list. For example, in parse_events__set_leader(). Furtunately,
it won't triggered problem because we don't allow a BPF object to be wrapped with "{}"
lexically ("{./aaa.o}" will be interpreterd as file '{./aaa.o' and a extra '}').

- Arnaldo

Signed-off-by: Wang Nan <wangnan0@xxxxxxxxxx>
Cc: Alexei Starovoitov <ast@xxxxxxxxxxxx>
Cc: Masami Hiramatsu <>
Cc: Namhyung Kim <namhyung@xxxxxxxxxx>
Cc: Zefan Li <lizefan@xxxxxxxxxx>
Cc: pi3orama@xxxxxxx
Cc: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
tools/perf/util/parse-events.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index d826e6f..14cd7e3 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -1143,10 +1143,14 @@ int parse_events(struct perf_evlist *evlist, const char *str,
int entries = data.idx - evlist->nr_entries;
struct perf_evsel *last;
+ if (!list_empty(&data.list)) {
+ last = list_entry(data.list.prev,
+ struct perf_evsel, node);
+ last->cmdline_group_boundary = true;
+ }
perf_evlist__splice_list_tail(evlist, &data.list, entries);
evlist->nr_groups += data.nr_groups;
- last = perf_evlist__last(evlist);
- last->cmdline_group_boundary = true;
return 0;

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at
Please read the FAQ at