[PATCH 1/4] perf tools: Do not read symbols/data from device files

From: Jiri Olsa
Date: Wed Jan 20 2016 - 06:56:47 EST


With mem sampling we could get data source within mapped
device file. Processing such sample would block during
report phase on trying to read the device file.

Chacking for device files and skip the processing if
it's detected.

Link: http://lkml.kernel.org/n/tip-rdj48ax089rhsdzpy31r48fw@xxxxxxxxxxxxxx
Signed-off-by: Jiri Olsa <jolsa@xxxxxxxxxx>
---
tools/perf/util/dso.c | 5 +++++
tools/perf/util/symbol.c | 6 +++++-
tools/perf/util/util.c | 10 ++++++++++
tools/perf/util/util.h | 1 +
4 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c
index e8e9a9dbf5e3..8e6395439ca0 100644
--- a/tools/perf/util/dso.c
+++ b/tools/perf/util/dso.c
@@ -52,6 +52,11 @@ int dso__read_binary_type_filename(const struct dso *dso,
debuglink--;
if (*debuglink == '/')
debuglink++;
+
+ ret = -1;
+ if (!is_regular_file(filename))
+ break;
+
ret = filename__read_debuglink(filename, debuglink,
size - (debuglink - filename));
}
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index ab02209a7cf3..90cedfa30e43 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -1466,7 +1466,8 @@ int dso__load(struct dso *dso, struct map *map, symbol_filter_t filter)
* Read the build id if possible. This is required for
* DSO_BINARY_TYPE__BUILDID_DEBUGINFO to work
*/
- if (filename__read_build_id(dso->long_name, build_id, BUILD_ID_SIZE) > 0)
+ if (is_regular_file(name) &&
+ filename__read_build_id(dso->long_name, build_id, BUILD_ID_SIZE) > 0)
dso__set_build_id(dso, build_id);

/*
@@ -1487,6 +1488,9 @@ int dso__load(struct dso *dso, struct map *map, symbol_filter_t filter)
root_dir, name, PATH_MAX))
continue;

+ if (!is_regular_file(name))
+ continue;
+
/* Name is now the name of the next image to try */
if (symsrc__init(ss, dso, name, symtab_type) < 0)
continue;
diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c
index ead9509835d2..7a2da7ef556e 100644
--- a/tools/perf/util/util.c
+++ b/tools/perf/util/util.c
@@ -691,3 +691,13 @@ out:

return tip;
}
+
+bool is_regular_file(const char *file)
+{
+ struct stat st;
+
+ if (stat(file, &st))
+ return false;
+
+ return S_ISREG(st.st_mode);
+}
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h
index fe915e616f9b..61650f05e5c1 100644
--- a/tools/perf/util/util.h
+++ b/tools/perf/util/util.h
@@ -343,5 +343,6 @@ int fetch_kernel_version(unsigned int *puint,
#define KVER_PARAM(x) KVER_VERSION(x), KVER_PATCHLEVEL(x), KVER_SUBLEVEL(x)

const char *perf_tip(const char *dirpath);
+bool is_regular_file(const char *file);

#endif /* GIT_COMPAT_UTIL_H */
--
2.4.3