Blob Blame History Raw
From: Song Liu <songliubraving@fb.com>
Date: Thu, 23 Jul 2020 11:06:46 -0700
Subject: libbpf: Print hint when PERF_EVENT_IOC_SET_BPF returns -EPROTO
Patch-mainline: v5.9-rc1
Git-commit: d4b4dd6ce7709c2d2fe56dcfc15074ee18505bcb
References: bsc#1177028

The kernel prevents potential unwinder warnings and crashes by blocking
BPF program with bpf_get_[stack|stackid] on perf_event without
PERF_SAMPLE_CALLCHAIN, or with exclude_callchain_[kernel|user]. Print a
hint message in libbpf to help the user debug such issues.

Signed-off-by: Song Liu <songliubraving@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20200723180648.1429892-4-songliubraving@fb.com
Acked-by: Gary Lin <glin@suse.com>
---
 tools/lib/bpf/libbpf.c |    3 +++
 1 file changed, 3 insertions(+)

--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -7835,6 +7835,9 @@ struct bpf_link *bpf_program__attach_per
 		pr_warning("program '%s': failed to attach to pfd %d: %s\n",
 			   bpf_program__title(prog, false), pfd,
 			   libbpf_strerror_r(err, errmsg, sizeof(errmsg)));
+		if (err == -EPROTO)
+			pr_warning("program '%s': try add PERF_SAMPLE_CALLCHAIN to or remove exclude_callchain_[kernel|user] from pfd %d\n",
+				   bpf_program__title(prog, false), pfd);
 		return ERR_PTR(err);
 	}
 	if (ioctl(pfd, PERF_EVENT_IOC_ENABLE, 0) < 0) {