From: Song Liu <song@kernel.org>
To: <linux-kernel@vger.kernel.org>
Cc: <kernel-team@fb.com>, <acme@kernel.org>, <acme@redhat.com>,
<namhyung@kernel.org>, <jolsa@kernel.org>,
<songliubraving@fb.com>, Song Liu <song@kernel.org>
Subject: [PATCH v4 2/4] perf bpf: check perf_attr_map is compatible with the perf binary
Date: Mon, 19 Apr 2021 13:36:47 -0700 [thread overview]
Message-ID: <20210419203649.164121-3-song@kernel.org> (raw)
In-Reply-To: <20210419203649.164121-1-song@kernel.org>
perf_attr_map could be shared among different version of perf binary. Add
bperf_attr_map_compatible() to check whether the existing attr_map is
compatible with current perf binary.
Signed-off-by: Song Liu <song@kernel.org>
---
tools/perf/util/bpf_counter.c | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/tools/perf/util/bpf_counter.c b/tools/perf/util/bpf_counter.c
index be484ddbbd5be..5de991ab46af9 100644
--- a/tools/perf/util/bpf_counter.c
+++ b/tools/perf/util/bpf_counter.c
@@ -312,6 +312,20 @@ static __u32 bpf_map_get_id(int fd)
return map_info.id;
}
+static bool bperf_attr_map_compatible(int attr_map_fd)
+{
+ struct bpf_map_info map_info = {0};
+ __u32 map_info_len = sizeof(map_info);
+ int err;
+
+ err = bpf_obj_get_info_by_fd(attr_map_fd, &map_info, &map_info_len);
+
+ if (err)
+ return false;
+ return (map_info.key_size == sizeof(struct perf_event_attr)) &&
+ (map_info.value_size == sizeof(struct perf_event_attr_map_entry));
+}
+
static int bperf_lock_attr_map(struct target *target)
{
char path[PATH_MAX];
@@ -346,6 +360,11 @@ static int bperf_lock_attr_map(struct target *target)
return -1;
}
+ if (!bperf_attr_map_compatible(map_fd)) {
+ close(map_fd);
+ return -1;
+
+ }
err = flock(map_fd, LOCK_EX);
if (err) {
close(map_fd);
--
2.30.2
next prev parent reply other threads:[~2021-04-19 20:37 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-19 20:36 [PATCH v4 0/4] perf util: bpf perf improvements Song Liu
2021-04-19 20:36 ` [PATCH v4 1/4] perf util: move bpf_perf definitions to a libperf header Song Liu
2021-04-19 20:36 ` Song Liu [this message]
2021-04-19 20:36 ` [PATCH v4 3/4] perf-stat: introduce config stat.bpf-counter-events Song Liu
2021-04-20 17:31 ` Jiri Olsa
2021-04-20 21:21 ` Song Liu
2021-04-21 10:18 ` Jiri Olsa
2021-04-25 14:38 ` Arnaldo Carvalho de Melo
2021-04-25 15:16 ` Jiri Olsa
2021-04-25 19:09 ` Song Liu
2021-04-25 21:45 ` Song Liu
2021-04-19 20:36 ` [PATCH v4 4/4] perf-stat: introduce ':b' modifier Song Liu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210419203649.164121-3-song@kernel.org \
--to=song@kernel.org \
--cc=acme@kernel.org \
--cc=acme@redhat.com \
--cc=jolsa@kernel.org \
--cc=kernel-team@fb.com \
--cc=linux-kernel@vger.kernel.org \
--cc=namhyung@kernel.org \
--cc=songliubraving@fb.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).