All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] perf mmap: Fix accessing unmapped mmap in perf_mmap__read_done()
@ 2018-03-26 13:42 kan.liang
  2018-03-26 14:26 ` Arnaldo Carvalho de Melo
  2018-03-29 13:58 ` [tip:perf/core] perf mmap: Fix accessing unmapped mmap in perf_mmap__read_done() tip-bot for Kan Liang
  0 siblings, 2 replies; 6+ messages in thread
From: kan.liang @ 2018-03-26 13:42 UTC (permalink / raw)
  To: acme, mingo, linux-kernel; +Cc: jolsa, namhyung, wangnan0, Kan Liang

From: Kan Liang <kan.liang@linux.intel.com>

There is segmentation fault when running perf trace. For example,
  [root@jouet e]# perf trace -e *chdir -o /tmp/bla perf report
  --ignore-vmlinux -i ../perf.data

The perf_mmap__consume() could unmap the mmap. It needs to check the
refcnt in perf_mmap__read_done().

Fixes: ee023de05f35 ("perf mmap: Introduce perf_mmap__read_done()")
Reported-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Kan Liang <kan.liang@linux.intel.com>
---
 tools/perf/util/mmap.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c
index 38ca3ff..f6cfc52 100644
--- a/tools/perf/util/mmap.c
+++ b/tools/perf/util/mmap.c
@@ -317,5 +317,11 @@ int perf_mmap__push(struct perf_mmap *md, void *to,
  */
 void perf_mmap__read_done(struct perf_mmap *map)
 {
+	/*
+	 * Check if event was unmapped due to a POLLHUP/POLLERR.
+	 */
+	if (!refcount_read(&map->refcnt))
+		return;
+
 	map->prev = perf_mmap__read_head(map);
 }
-- 
2.4.11

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2018-03-29 13:59 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-03-26 13:42 [PATCH] perf mmap: Fix accessing unmapped mmap in perf_mmap__read_done() kan.liang
2018-03-26 14:26 ` Arnaldo Carvalho de Melo
2018-03-26 14:41   ` Arnaldo Carvalho de Melo
2018-03-26 14:51     ` Liang, Kan
2018-03-29 13:58     ` [tip:perf/core] perf mmap: Be consistent when checking for an unmaped ring buffer tip-bot for Arnaldo Carvalho de Melo
2018-03-29 13:58 ` [tip:perf/core] perf mmap: Fix accessing unmapped mmap in perf_mmap__read_done() tip-bot for Kan Liang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.