* [PATCH bpf-next v2] samples/bpf: fix kprobe attachment issue on x64
@ 2018-04-30 2:27 Yonghong Song
2018-04-30 3:39 ` Alexei Starovoitov
0 siblings, 1 reply; 2+ messages in thread
From: Yonghong Song @ 2018-04-30 2:27 UTC (permalink / raw)
To: ast, daniel, netdev; +Cc: kernel-team
Commit d5a00528b58c ("syscalls/core, syscalls/x86: Rename
struct pt_regs-based sys_*() to __x64_sys_*()") renamed a lot
of syscall function sys_*() to __x64_sys_*().
This caused several kprobe based samples/bpf tests failing.
This patch fixed the problem in bpf_load.c.
For x86_64 architecture, function name __x64_sys_*() will be
first used for kprobe event creation. If the creation is successful,
it will be used. Otherwise, function name sys_*() will be used
for kprobe event creation.
Fixes: d5a00528b58c ("syscalls/core, syscalls/x86: Rename struct pt_regs-based sys_*() to __x64_sys_*()")
Signed-off-by: Yonghong Song <yhs@fb.com>
---
samples/bpf/bpf_load.c | 34 ++++++++++++++++++++++++++--------
1 file changed, 26 insertions(+), 8 deletions(-)
Changelogs:
v1 -> v2:
. make change in bpf_load.c instead of each individual bpf programs.
diff --git a/samples/bpf/bpf_load.c b/samples/bpf/bpf_load.c
index a27ef3c..da9bccf 100644
--- a/samples/bpf/bpf_load.c
+++ b/samples/bpf/bpf_load.c
@@ -145,6 +145,9 @@ static int load_and_attach(const char *event, struct bpf_insn *prog, int size)
}
if (is_kprobe || is_kretprobe) {
+ bool need_normal_check = true;
+ const char *event_prefix = "";
+
if (is_kprobe)
event += 7;
else
@@ -158,18 +161,33 @@ static int load_and_attach(const char *event, struct bpf_insn *prog, int size)
if (isdigit(*event))
return populate_prog_array(event, fd);
- snprintf(buf, sizeof(buf),
- "echo '%c:%s %s' >> /sys/kernel/debug/tracing/kprobe_events",
- is_kprobe ? 'p' : 'r', event, event);
- err = system(buf);
- if (err < 0) {
- printf("failed to create kprobe '%s' error '%s'\n",
- event, strerror(errno));
- return -1;
+#ifdef __x86_64__
+ if (strncmp(event, "sys_", 4) == 0) {
+ snprintf(buf, sizeof(buf),
+ "echo '%c:__x64_%s __x64_%s' >> /sys/kernel/debug/tracing/kprobe_events",
+ is_kprobe ? 'p' : 'r', event, event);
+ err = system(buf);
+ if (err >= 0) {
+ need_normal_check = false;
+ event_prefix = "__x64_";
+ }
+ }
+#endif
+ if (need_normal_check) {
+ snprintf(buf, sizeof(buf),
+ "echo '%c:%s %s' >> /sys/kernel/debug/tracing/kprobe_events",
+ is_kprobe ? 'p' : 'r', event, event);
+ err = system(buf);
+ if (err < 0) {
+ printf("failed to create kprobe '%s' error '%s'\n",
+ event, strerror(errno));
+ return -1;
+ }
}
strcpy(buf, DEBUGFS);
strcat(buf, "events/kprobes/");
+ strcat(buf, event_prefix);
strcat(buf, event);
strcat(buf, "/id");
} else if (is_tracepoint) {
--
2.9.5
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH bpf-next v2] samples/bpf: fix kprobe attachment issue on x64
2018-04-30 2:27 [PATCH bpf-next v2] samples/bpf: fix kprobe attachment issue on x64 Yonghong Song
@ 2018-04-30 3:39 ` Alexei Starovoitov
0 siblings, 0 replies; 2+ messages in thread
From: Alexei Starovoitov @ 2018-04-30 3:39 UTC (permalink / raw)
To: Yonghong Song; +Cc: ast, daniel, netdev, kernel-team
On Sun, Apr 29, 2018 at 07:27:48PM -0700, Yonghong Song wrote:
> Commit d5a00528b58c ("syscalls/core, syscalls/x86: Rename
> struct pt_regs-based sys_*() to __x64_sys_*()") renamed a lot
> of syscall function sys_*() to __x64_sys_*().
> This caused several kprobe based samples/bpf tests failing.
>
> This patch fixed the problem in bpf_load.c.
> For x86_64 architecture, function name __x64_sys_*() will be
> first used for kprobe event creation. If the creation is successful,
> it will be used. Otherwise, function name sys_*() will be used
> for kprobe event creation.
>
> Fixes: d5a00528b58c ("syscalls/core, syscalls/x86: Rename struct pt_regs-based sys_*() to __x64_sys_*()")
> Signed-off-by: Yonghong Song <yhs@fb.com>
Applied, Thanks Yonghong.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-04-30 3:39 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-04-30 2:27 [PATCH bpf-next v2] samples/bpf: fix kprobe attachment issue on x64 Yonghong Song
2018-04-30 3:39 ` Alexei Starovoitov
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).