提交 fe3dd826 编写于 作者: S Song Liu 提交者: Arnaldo Carvalho de Melo

perf bpf: check perf_attr_map is compatible with the perf binary

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: NSong Liu <song@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Song Liu <songliubraving@fb.com>
Cc: kernel-team@fb.com
Link: https://lore.kernel.org/r/20210425214333.1090950-3-song@kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
上级 ec8149fb
......@@ -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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册