Re: [PATCH v8] perf: __kmod_path__parse: deal with kernel module names in '[]' correctly
From: Arnaldo Carvalho de Melo
Date: Wed Jun 03 2015 - 09:10:24 EST
Em Wed, Jun 03, 2015 at 11:12:04AM +0200, Jiri Olsa escreveu:
> On Wed, Jun 03, 2015 at 08:52:21AM +0000, Wang Nan wrote:
> > Before patch ba92732e9808df679ddf75c5ea1c0caae6d7dce2 ('perf kmaps:
> > Check kmaps to make code more robust'), perf report and perf annotate
> > will segfault if trace data contains kernel module information like
> > this:
>
> Acked-by: Jiri Olsa <jolsa@xxxxxxxxxx>
Had to fix the merge with one hunk I had from a fix I made, please
check, full patch below, but the clash was in this loop:
+++ b/tools/perf/util/machine.c
@@ -1149,9 +1149,29 @@ static int machine__process_kernel_mmap_event(struct machine *machine,
struct dso *dso;
list_for_each_entry(dso, &machine->dsos.head, node) {
- if (!dso->kernel || is_kernel_module(dso->long_name))
+
+ /*
+ * The cpumode passed to is_kernel_module is not the
+ * cpumode of *this* event. If we insist on passing
+ * correct cpumode to is_kernel_module, we should
+ * record the cpumode when we adding this dso to the
+ * linked list.
+ *
+ * However we don't really need passing correct
+ * cpumode. We know the correct cpumode must be kernel
+ * mode (if not, we should not link it onto kernel_dsos
+ * list).
+ *
+ * Therefore, we pass PERF_RECORD_MISC_CPUMODE_UNKNOWN.
+ * is_kernel_module() treats it as a kernel cpumode.
+ */
+
+ if (!dso->kernel ||
+ is_kernel_module(dso->long_name,
+ PERF_RECORD_MISC_CPUMODE_UNKNOWN))
continue;
+
kernel = dso;
break;
}
-
-------------------------------
I.e. before it was:
if (dso->kernel && is_kernel_module(dso->long_name))
But then, since now there are !dso->kernel entries in this list, it
could get as the 'kernel' a user DSO. So I changed it to:
if (!dso->kernel || is_kernel_module(dso->long_name))
To discard user and kernel module DSOs.
Applied the patch below, let me know if you disagree.
- Arnaldo