From: Yonghong Song <yhs@fb.com>
To: Dmitrii Dolgov <9erthalion6@gmail.com>,
bpf@vger.kernel.org, ast@kernel.org, daniel@iogearbox.net,
andrii@kernel.org, quentin@isovalent.com
Subject: Re: [RFC PATCH v4] bpftool: Add bpf_cookie to link output
Date: Tue, 1 Mar 2022 23:53:56 -0800 [thread overview]
Message-ID: <a646e7d3-b4aa-3a00-013e-4fc9531c2d83@fb.com> (raw)
In-Reply-To: <20220225152802.20957-1-9erthalion6@gmail.com>
On 2/25/22 7:28 AM, Dmitrii Dolgov wrote:
> Commit 82e6b1eee6a8 ("bpf: Allow to specify user-provided bpf_cookie for
> BPF perf links") introduced the concept of user specified bpf_cookie,
> which could be accessed by BPF programs using bpf_get_attach_cookie().
> For troubleshooting purposes it is convenient to expose bpf_cookie via
> bpftool as well, so there is no need to meddle with the target BPF
> program itself.
Do you still need RFC tag? It looks like we have a consensus
with this bpf_iter approach, right?
Please also add "bpf-next" to the tag for clarity purpose.
>
> Implemented using the pid iterator BPF program to actually fetch
> bpf_cookies, which allows constraining code changes only to bpftool.
>
> $ bpftool link
> 1: type 7 prog 5
> bpf_cookie 123
> pids bootstrap(81)
>
> Signed-off-by: Dmitrii Dolgov <9erthalion6@gmail.com>
> ---
> Changes in v4:
> - Fetch cookies only for bpf_perf_link
> - Signal about bpf_cookie via the flag, instead of deducing it from
> the object and link type
> - Reset pid_iter_entry to avoid invalid indirect read from stack
>
> Changes in v3:
> - Use pid iterator to fetch bpf_cookie
>
> Changes in v2:
> - Display bpf_cookie in bpftool link command instead perf
>
> Previous discussion: https://lore.kernel.org/bpf/20220218075103.10002-1-9erthalion6@gmail.com/
>
> tools/bpf/bpftool/main.h | 2 ++
> tools/bpf/bpftool/pids.c | 10 +++++++++
> tools/bpf/bpftool/skeleton/pid_iter.bpf.c | 25 +++++++++++++++++++++++
> tools/bpf/bpftool/skeleton/pid_iter.h | 2 ++
> 4 files changed, 39 insertions(+)
>
> diff --git a/tools/bpf/bpftool/main.h b/tools/bpf/bpftool/main.h
> index 0c3840596b5a..1bb76aa1f3b2 100644
> --- a/tools/bpf/bpftool/main.h
> +++ b/tools/bpf/bpftool/main.h
> @@ -114,6 +114,8 @@ struct obj_ref {
> struct obj_refs {
> int ref_cnt;
> struct obj_ref *refs;
> + bool bpf_cookie_set;
> + __u64 bpf_cookie;
> };
>
> struct btf;
> diff --git a/tools/bpf/bpftool/pids.c b/tools/bpf/bpftool/pids.c
> index 7c384d10e95f..152502c2d6f9 100644
> --- a/tools/bpf/bpftool/pids.c
> +++ b/tools/bpf/bpftool/pids.c
> @@ -55,6 +55,8 @@ static void add_ref(struct hashmap *map, struct pid_iter_entry *e)
> ref->pid = e->pid;
> memcpy(ref->comm, e->comm, sizeof(ref->comm));
> refs->ref_cnt++;
> + refs->bpf_cookie_set = e->bpf_cookie_set;
> + refs->bpf_cookie = e->bpf_cookie;
Do we need here? It is weird that we overwrite the bpf_cookie with every
new 'pid' reference.
When you create a link, the cookie is fixed for that link. You could pin
that link in bpffs e.g., /sys/fs/bpf/link1 and other programs can then
get a reference to the link1, but they should still have the same
cookie. Is that right?
>
> return;
> }
> @@ -78,6 +80,8 @@ static void add_ref(struct hashmap *map, struct pid_iter_entry *e)
> ref->pid = e->pid;
> memcpy(ref->comm, e->comm, sizeof(ref->comm));
> refs->ref_cnt = 1;
> + refs->bpf_cookie_set = e->bpf_cookie_set;
> + refs->bpf_cookie = e->bpf_cookie;
>
> err = hashmap__append(map, u32_as_hash_field(e->id), refs);
> if (err)
> @@ -205,6 +209,9 @@ void emit_obj_refs_json(struct hashmap *map, __u32 id,
> if (refs->ref_cnt == 0)
[...]
next prev parent reply other threads:[~2022-03-02 7:54 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-25 15:28 [RFC PATCH v4] bpftool: Add bpf_cookie to link output Dmitrii Dolgov
2022-03-02 7:53 ` Yonghong Song [this message]
2022-03-03 16:20 ` Dmitry Dolgov
2022-03-03 18:24 ` Yonghong Song
2022-03-03 20:14 ` Dmitry Dolgov
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=a646e7d3-b4aa-3a00-013e-4fc9531c2d83@fb.com \
--to=yhs@fb.com \
--cc=9erthalion6@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=quentin@isovalent.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