samples/bpf: fix kprobe attachment issue on x64
Commitd5a00528b5
("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:d5a00528b5
("syscalls/core, syscalls/x86: Rename struct pt_regs-based sys_*() to __x64_sys_*()") Signed-off-by: Yonghong Song <yhs@fb.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
This commit is contained in:
parent
7ef3771205
commit
34745aed51
|
@ -145,6 +145,9 @@ static int load_and_attach(const char *event, struct bpf_insn *prog, int size)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_kprobe || is_kretprobe) {
|
if (is_kprobe || is_kretprobe) {
|
||||||
|
bool need_normal_check = true;
|
||||||
|
const char *event_prefix = "";
|
||||||
|
|
||||||
if (is_kprobe)
|
if (is_kprobe)
|
||||||
event += 7;
|
event += 7;
|
||||||
else
|
else
|
||||||
|
@ -158,18 +161,33 @@ static int load_and_attach(const char *event, struct bpf_insn *prog, int size)
|
||||||
if (isdigit(*event))
|
if (isdigit(*event))
|
||||||
return populate_prog_array(event, fd);
|
return populate_prog_array(event, fd);
|
||||||
|
|
||||||
snprintf(buf, sizeof(buf),
|
#ifdef __x86_64__
|
||||||
"echo '%c:%s %s' >> /sys/kernel/debug/tracing/kprobe_events",
|
if (strncmp(event, "sys_", 4) == 0) {
|
||||||
is_kprobe ? 'p' : 'r', event, event);
|
snprintf(buf, sizeof(buf),
|
||||||
err = system(buf);
|
"echo '%c:__x64_%s __x64_%s' >> /sys/kernel/debug/tracing/kprobe_events",
|
||||||
if (err < 0) {
|
is_kprobe ? 'p' : 'r', event, event);
|
||||||
printf("failed to create kprobe '%s' error '%s'\n",
|
err = system(buf);
|
||||||
event, strerror(errno));
|
if (err >= 0) {
|
||||||
return -1;
|
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);
|
strcpy(buf, DEBUGFS);
|
||||||
strcat(buf, "events/kprobes/");
|
strcat(buf, "events/kprobes/");
|
||||||
|
strcat(buf, event_prefix);
|
||||||
strcat(buf, event);
|
strcat(buf, event);
|
||||||
strcat(buf, "/id");
|
strcat(buf, "/id");
|
||||||
} else if (is_tracepoint) {
|
} else if (is_tracepoint) {
|
||||||
|
|
Loading…
Reference in a new issue