2020-02-10 14:33:56

by Jiri Olsa

[permalink] [raw]
Subject: [PATCH 0/4] perf tools: Fix kmap handling

hi,
Ravi Bangoria reported crash in perf top due to wrong kmap
objects management, this patchset should fix that.

thanks,
jirka


---
Jiri Olsa (4):
perf tools: Mark modules dsos with kernel type
perf tools: Mark ksymbol dsos with kernel type
perf tools: Fix map__clone for struct kmap
perf tools: Move kmap::kmaps setup to maps__insert

tools/perf/util/machine.c | 24 ++++++++++--------------
tools/perf/util/map.c | 17 ++++++++++++++++-
2 files changed, 26 insertions(+), 15 deletions(-)


2020-02-10 14:34:10

by Jiri Olsa

[permalink] [raw]
Subject: [PATCH 3/4] perf tools: Fix map__clone for struct kmap

The map__clone function can be called on kernel maps
as well, so it needs to duplicate the whole kmap data.

Reported-by: Ravi Bangoria <[email protected]>
Tested-by: Ravi Bangoria <[email protected]>
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/util/map.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c
index f67960bedebb..cea05fc9595c 100644
--- a/tools/perf/util/map.c
+++ b/tools/perf/util/map.c
@@ -375,8 +375,13 @@ struct symbol *map__find_symbol_by_name(struct map *map, const char *name)

struct map *map__clone(struct map *from)
{
- struct map *map = memdup(from, sizeof(*map));
+ size_t size = sizeof(struct map);
+ struct map *map;
+
+ if (from->dso && from->dso->kernel)
+ size += sizeof(struct kmap);

+ map = memdup(from, size);
if (map != NULL) {
refcount_set(&map->refcnt, 1);
RB_CLEAR_NODE(&map->rb_node);
--
2.24.1

2020-02-10 14:34:33

by Jiri Olsa

[permalink] [raw]
Subject: [PATCH 1/4] perf tools: Mark modules dsos with kernel type

We add kernel module map into machine->kmaps, so it needs
to be created as 'struct kmap', which is dependent on its
dso having kernel type.

Reported-by: Ravi Bangoria <[email protected]>
Tested-by: Ravi Bangoria <[email protected]>
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/util/machine.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
index c8c5410315e8..e3e5490f6de5 100644
--- a/tools/perf/util/machine.c
+++ b/tools/perf/util/machine.c
@@ -686,6 +686,7 @@ static struct dso *machine__findnew_module_dso(struct machine *machine,

dso__set_module_info(dso, m, machine);
dso__set_long_name(dso, strdup(filename), true);
+ dso->kernel = DSO_TYPE_KERNEL;
}

dso__get(dso);
--
2.24.1

2020-02-10 16:48:40

by Kim Phillips

[permalink] [raw]
Subject: Re: [PATCH 0/4] perf tools: Fix kmap handling

On 2/10/20 8:32 AM, Jiri Olsa wrote:
> hi,
> Ravi Bangoria reported crash in perf top due to wrong kmap
> objects management, this patchset should fix that.
>
> thanks,
> jirka
>
>
> ---
> Jiri Olsa (4):
> perf tools: Mark modules dsos with kernel type
> perf tools: Mark ksymbol dsos with kernel type
> perf tools: Fix map__clone for struct kmap
> perf tools: Move kmap::kmaps setup to maps__insert
>
> tools/perf/util/machine.c | 24 ++++++++++--------------
> tools/perf/util/map.c | 17 ++++++++++++++++-
> 2 files changed, 26 insertions(+), 15 deletions(-)
>

This series fixes a segmentation fault I was seeing on a
couple of AMD systems, so:

Tested-by: Kim Phillips <[email protected]>

Thanks,

Kim

Thread 259 "perf" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7fff3b7b6700 (LWP 13241)]
__map__is_kernel (map=0x7fffd80098d0) at util/map.c:244
244 return machine__kernel_map(map__kmaps((struct map *)map)->machine) == map;
(gdb) bt
#0 __map__is_kernel (map=0x7fffd80098d0) at util/map.c:244
#1 0x000055555575d756 in perf_event__process_sample (machine=<optimized out>, sample=0x7fff3b7b5710,
evsel=0x555555ef9dd0, event=<optimized out>, tool=0x7fffffff8660) at builtin-top.c:799
#2 deliver_event (qe=<optimized out>, qevent=<optimized out>) at builtin-top.c:1192
#3 0x0000555555831f81 in do_flush (show_progress=false, oe=0x7fffffff8960) at util/ordered-events.c:244
#4 __ordered_events__flush (oe=oe@entry=0x7fffffff8960, how=how@entry=OE_FLUSH__TOP, timestamp=timestamp@entry=0)
at util/ordered-events.c:323
#5 0x00005555558328df in __ordered_events__flush (timestamp=<optimized out>, how=<optimized out>, oe=<optimized out>)
at util/ordered-events.c:342
#6 ordered_events__flush (oe=oe@entry=0x7fffffff8960, how=how@entry=OE_FLUSH__TOP) at util/ordered-events.c:341
#7 0x000055555575d0f1 in process_thread (arg=0x7fffffff8660) at builtin-top.c:1104
#8 0x00007ffff7bbd6db in start_thread (arg=0x7fff3b7b6700) at pthread_create.c:463
#9 0x00007ffff5d9788f in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95
(gdb) p map
$1 = (const struct map *) 0x7fffd80098d0

2020-02-10 20:36:24

by Jiri Olsa

[permalink] [raw]
Subject: Re: [PATCH 0/4] perf tools: Fix kmap handling

On Mon, Feb 10, 2020 at 10:47:11AM -0600, Kim Phillips wrote:
> On 2/10/20 8:32 AM, Jiri Olsa wrote:
> > hi,
> > Ravi Bangoria reported crash in perf top due to wrong kmap
> > objects management, this patchset should fix that.
> >
> > thanks,
> > jirka
> >
> >
> > ---
> > Jiri Olsa (4):
> > perf tools: Mark modules dsos with kernel type
> > perf tools: Mark ksymbol dsos with kernel type
> > perf tools: Fix map__clone for struct kmap
> > perf tools: Move kmap::kmaps setup to maps__insert
> >
> > tools/perf/util/machine.c | 24 ++++++++++--------------
> > tools/perf/util/map.c | 17 ++++++++++++++++-
> > 2 files changed, 26 insertions(+), 15 deletions(-)
> >
>
> This series fixes a segmentation fault I was seeing on a
> couple of AMD systems, so:
>
> Tested-by: Kim Phillips <[email protected]>

great, thanks a lot for testing

jirka

Subject: [tip: perf/urgent] perf maps: Mark module DSOs with kernel type

The following commit has been merged into the perf/urgent branch of tip:

Commit-ID: 02213cec64bbef66d7ad9ddc3b7c47236da64343
Gitweb: https://git.kernel.org/tip/02213cec64bbef66d7ad9ddc3b7c47236da64343
Author: Jiri Olsa <[email protected]>
AuthorDate: Mon, 10 Feb 2020 15:32:15 +01:00
Committer: Arnaldo Carvalho de Melo <[email protected]>
CommitterDate: Tue, 11 Feb 2020 16:41:49 -03:00

perf maps: Mark module DSOs with kernel type

We add kernel module map into machine->kmaps, so it needs to be created
as 'struct kmap', which is dependent on its dso having kernel type.

Reported-by: Ravi Bangoria <[email protected]>
Signed-off-by: Jiri Olsa <[email protected]>
Tested-by: Kim Phillips <[email protected]>
Tested-by: Ravi Bangoria <[email protected]>
Cc: Alexander Shishkin <[email protected]>
Cc: Michael Petlan <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Link: http://lore.kernel.org/lkml/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
---
tools/perf/util/machine.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
index c8c5410..e3e5490 100644
--- a/tools/perf/util/machine.c
+++ b/tools/perf/util/machine.c
@@ -686,6 +686,7 @@ static struct dso *machine__findnew_module_dso(struct machine *machine,

dso__set_module_info(dso, m, machine);
dso__set_long_name(dso, strdup(filename), true);
+ dso->kernel = DSO_TYPE_KERNEL;
}

dso__get(dso);

Subject: [tip: perf/urgent] perf maps: Fix map__clone() for struct kmap

The following commit has been merged into the perf/urgent branch of tip:

Commit-ID: 7ce66139a99ce57caaf47b64afed5cb6ed02c5ed
Gitweb: https://git.kernel.org/tip/7ce66139a99ce57caaf47b64afed5cb6ed02c5ed
Author: Jiri Olsa <[email protected]>
AuthorDate: Mon, 10 Feb 2020 15:32:17 +01:00
Committer: Arnaldo Carvalho de Melo <[email protected]>
CommitterDate: Tue, 11 Feb 2020 16:41:49 -03:00

perf maps: Fix map__clone() for struct kmap

The map__clone() function can be called on kernel maps as well, so it
needs to duplicate the whole kmap data.

Reported-by: Ravi Bangoria <[email protected]>
Signed-off-by: Jiri Olsa <[email protected]>
Tested-by: Ravi Bangoria <[email protected]>
Tested-by: Kim Phillips <[email protected]>
Cc: Alexander Shishkin <[email protected]>
Cc: Michael Petlan <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Link: http://lore.kernel.org/lkml/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
---
tools/perf/util/map.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c
index f67960b..cea05fc 100644
--- a/tools/perf/util/map.c
+++ b/tools/perf/util/map.c
@@ -375,8 +375,13 @@ struct symbol *map__find_symbol_by_name(struct map *map, const char *name)

struct map *map__clone(struct map *from)
{
- struct map *map = memdup(from, sizeof(*map));
+ size_t size = sizeof(struct map);
+ struct map *map;
+
+ if (from->dso && from->dso->kernel)
+ size += sizeof(struct kmap);

+ map = memdup(from, size);
if (map != NULL) {
refcount_set(&map->refcnt, 1);
RB_CLEAR_NODE(&map->rb_node);