From: Kui-Feng Lee <kuifeng@fb.com>
To: <bpf@vger.kernel.org>, <ast@kernel.org>, <daniel@iogearbox.net>,
<andrii@kernel.org>, <kernel-team@fb.com>
Cc: Kui-Feng Lee <kuifeng@fb.com>
Subject: [PATCH dwarves v6 4/6] bpf: Create fentry/fexit/fmod_ret links through BPF_LINK_CREATE
Date: Fri, 15 Apr 2022 21:29:38 -0700 [thread overview]
Message-ID: <20220416042940.656344-5-kuifeng@fb.com> (raw)
In-Reply-To: <20220416042940.656344-1-kuifeng@fb.com>
Make fentry/fexit/fmod_ret as valid attach-types for BPF_LINK_CREATE.
Pass a cookie along with BPF_LINK_CREATE requests.
Signed-off-by: Kui-Feng Lee <kuifeng@fb.com>
---
include/uapi/linux/bpf.h | 7 +++++++
kernel/bpf/syscall.c | 9 +++++++++
tools/include/uapi/linux/bpf.h | 7 +++++++
3 files changed, 23 insertions(+)
diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
index a4f557338af7..780be5a8ae39 100644
--- a/include/uapi/linux/bpf.h
+++ b/include/uapi/linux/bpf.h
@@ -1490,6 +1490,13 @@ union bpf_attr {
__aligned_u64 addrs;
__aligned_u64 cookies;
} kprobe_multi;
+ struct {
+ /* black box user-provided value passed through
+ * to BPF program at the execution time and
+ * accessible through bpf_get_attach_cookie() BPF helper
+ */
+ __u64 cookie;
+ } tracing;
};
} link_create;
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index 966f2d40ae55..ca14b0a2e222 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -3189,6 +3189,10 @@ attach_type_to_prog_type(enum bpf_attach_type attach_type)
return BPF_PROG_TYPE_SK_LOOKUP;
case BPF_XDP:
return BPF_PROG_TYPE_XDP;
+ case BPF_TRACE_FENTRY:
+ case BPF_TRACE_FEXIT:
+ case BPF_MODIFY_RETURN:
+ return BPF_PROG_TYPE_TRACING;
default:
return BPF_PROG_TYPE_UNSPEC;
}
@@ -4254,6 +4258,11 @@ static int tracing_bpf_link_attach(const union bpf_attr *attr, bpfptr_t uattr,
attr->link_create.target_fd,
attr->link_create.target_btf_id,
0);
+ else if (prog->type == BPF_PROG_TYPE_TRACING)
+ return bpf_tracing_prog_attach(prog,
+ 0,
+ 0,
+ attr->link_create.tracing.cookie);
return -EINVAL;
}
diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h
index a4f557338af7..780be5a8ae39 100644
--- a/tools/include/uapi/linux/bpf.h
+++ b/tools/include/uapi/linux/bpf.h
@@ -1490,6 +1490,13 @@ union bpf_attr {
__aligned_u64 addrs;
__aligned_u64 cookies;
} kprobe_multi;
+ struct {
+ /* black box user-provided value passed through
+ * to BPF program at the execution time and
+ * accessible through bpf_get_attach_cookie() BPF helper
+ */
+ __u64 cookie;
+ } tracing;
};
} link_create;
--
2.30.2
next prev parent reply other threads:[~2022-04-16 4:30 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-16 4:29 [PATCH dwarves v6 0/6] Attach a cookie to a tracing program Kui-Feng Lee
2022-04-16 4:29 ` [PATCH dwarves v6 1/6] bpf, x86: Generate trampolines from bpf_tramp_links Kui-Feng Lee
2022-04-20 17:37 ` Andrii Nakryiko
2022-04-20 20:17 ` Kui-Feng Lee
2022-04-20 21:41 ` Andrii Nakryiko
2022-04-29 1:52 ` Kui-Feng Lee
2022-04-29 5:01 ` Andrii Nakryiko
2022-04-16 4:29 ` [PATCH dwarves v6 2/6] bpf, x86: Create bpf_tramp_run_ctx on the caller thread's stack Kui-Feng Lee
2022-04-20 17:39 ` Andrii Nakryiko
2022-04-16 4:29 ` [PATCH dwarves v6 3/6] bpf, x86: Attach a cookie to fentry/fexit/fmod_ret Kui-Feng Lee
2022-04-16 4:29 ` Kui-Feng Lee [this message]
2022-04-20 17:49 ` [PATCH dwarves v6 4/6] bpf: Create fentry/fexit/fmod_ret links through BPF_LINK_CREATE Andrii Nakryiko
2022-04-20 21:12 ` Kui-Feng Lee
2022-04-16 4:29 ` [PATCH dwarves v6 5/6] libbpf: Assign cookies to links in libbpf Kui-Feng Lee
2022-04-20 17:55 ` Andrii Nakryiko
2022-04-16 4:29 ` [PATCH dwarves v6 6/6] selftest/bpf: The test cses of BPF cookie for fentry/fexit/fmod_ret Kui-Feng Lee
2022-04-20 17:56 ` Andrii Nakryiko
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=20220416042940.656344-5-kuifeng@fb.com \
--to=kuifeng@fb.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=kernel-team@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