lkml.org 
[lkml]   [2019]   [Oct]   [22]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH V3 04/13] perf header: Add check for event attr
Date
From: Kan Liang <kan.liang@linux.intel.com>

The perf.data may be generated by a newer version of perf tool,
which support new input bits in attr, e.g. new bit for
branch_sample_type.
The perf.data may be parsed by an older version of perf tool later.
The old perf tool may parse the perf.data incorrectly. There is no
warning message for this case.

Current perf header never check for unknown input bits in attr.

When read the event desc from header, check the stored event attr.
The reserved bits, sample type, read format and branch sample type
will be checked.

Signed-off-by: Kan Liang <kan.liang@linux.intel.com>
---
tools/perf/util/header.c | 38 ++++++++++++++++++++++++++++++++++++++
1 file changed, 38 insertions(+)

diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 86d9396cb131..6c51404fbeef 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -1597,6 +1597,41 @@ static void free_event_desc(struct evsel *events)
free(events);
}

+static bool perf_attr_check(struct perf_event_attr *attr)
+{
+ if (attr->__reserved_1) {
+ pr_warning("Unexpected reserved bits (0x%x) are detected. "
+ "Please update perf tool.\n",
+ attr->__reserved_1);
+ return false;
+ }
+
+ if (attr->sample_type & ~(PERF_SAMPLE_MAX-1)) {
+ pr_warning("Unknown sample type (0x%llx) is detected. "
+ "Please update perf tool.\n",
+ attr->sample_type);
+ return false;
+ }
+
+ if (attr->read_format & ~(PERF_FORMAT_MAX-1)) {
+ pr_warning("Unknown read format (0x%llx) is detected. "
+ "Please update perf tool.\n",
+ attr->read_format);
+ return false;
+ }
+
+ if ((attr->sample_type & PERF_SAMPLE_BRANCH_STACK) &&
+ (attr->branch_sample_type & ~(PERF_SAMPLE_BRANCH_MAX-1))) {
+ pr_warning("Unknown branch sample type (0x%llx) is detected. "
+ "Please update perf tool.\n",
+ attr->branch_sample_type);
+
+ return false;
+ }
+
+ return true;
+}
+
static struct evsel *read_event_desc(struct feat_fd *ff)
{
struct evsel *evsel, *events = NULL;
@@ -1641,6 +1676,9 @@ static struct evsel *read_event_desc(struct feat_fd *ff)

memcpy(&evsel->core.attr, buf, msz);

+ if (!perf_attr_check(&evsel->core.attr))
+ goto error;
+
if (do_read_u32(ff, &nr))
goto error;

--
2.17.1
\
 
 \ /
  Last update: 2019-10-22 19:13    [W:0.127 / U:1.024 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site