From: Quentin Monnet <qmo@kernel.org>
To: Tao Chen <chen.dylane@linux.dev>,
ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org,
martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org,
yonghong.song@linux.dev, john.fastabend@gmail.com,
kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com,
jolsa@kernel.org, davem@davemloft.net, kuba@kernel.org,
hawk@kernel.org
Cc: linux-kernel@vger.kernel.org, bpf@vger.kernel.org,
netdev@vger.kernel.org
Subject: Re: [PATCH bpf-next 1/2] bpftool: Add bpf_token show
Date: Tue, 22 Jul 2025 10:23:53 +0100 [thread overview]
Message-ID: <f956664e-24a2-410a-be9b-4d90e08c7c64@kernel.org> (raw)
In-Reply-To: <06387128-8d34-49fd-a409-d35f5d60b094@linux.dev>
2025-07-22 13:48 UTC+0800 ~ Tao Chen <chen.dylane@linux.dev>
> 在 2025/7/22 00:23, Quentin Monnet 写道:
>> Thanks a lot for this!
>>
>
> Hi Quenin,
>
>>
>> 2025-07-21 01:33 UTC+0800 ~ Tao Chen <chen.dylane@linux.dev>
>>> Add `bpftool token show` command to get token info
>>> from bpf fs in /proc/mounts.
>>>
>>> Example plain output for `token show`:
>>> token_info:
>>> /sys/fs/bpf/token
>>>
>>> allowed_cmds:
>>> map_create prog_load
>>>
>>> allowed_maps:
>>>
>>> allowed_progs:
>>> kprobe
>>>
>>> allowed_attachs:
>>> xdp
>>>
>>> Example json output for `token show`:
>>> {
>>> "token_info": "/sys/fs/bpf/token",
>>> "allowed_cmds": ["map_create","prog_load"
>>> ],
>>> "allowed_maps":
>>
>>
>> This is not valid JSON. You're missing a value for "allowed_maps" (here
>> it should likely be an empty array), and the comma:
>>
>> "allowed_maps": [],
>>
>>
>>> "allowed_progs": ["kprobe"
>>> ],
>>> "allowed_attachs": ["xdp"
>>> ]
>>> }
>>>
>>> Signed-off-by: Tao Chen <chen.dylane@linux.dev>
>>> ---
>>> tools/bpf/bpftool/main.c | 3 +-
>>> tools/bpf/bpftool/main.h | 1 +
>>> tools/bpf/bpftool/token.c | 229 ++++++++++++++++++++++++++++++++++++++
>>> 3 files changed, 232 insertions(+), 1 deletion(-)
>>> create mode 100644 tools/bpf/bpftool/token.c
>>>
[...]
>>> diff --git a/tools/bpf/bpftool/token.c b/tools/bpf/bpftool/token.c
>>> new file mode 100644
>>> index 00000000000..2fcaff4f2ba
>>> --- /dev/null
>>> +++ b/tools/bpf/bpftool/token.c
[...]
>>> + if (has_delegate_options(ent->mnt_opts)) {
>>> + hit = true;
>>> + break;
>>
>>
>> Apologies, my knowledge of BPF tokens is limited. Can you have only one
>> token exposed through a bpffs at a time? Asking because I know you can
>> have several bpffs on your system, if each can have delegate options
>> then why stop after the first bpffs mount point you find?
>>
>
> Yes it is, only the first bpffs with token info will be showed above.
> Actually, it will not be limited how many bpffs ceated in kernel, it
> depends on the user scenarios. In most cases, only one will be created.
> But, maybe it's better to show all. I will change it in v2.
Yes please. If there are several tokens available, bpftool should "list"
them all, as the command name implies. The user scenarios don't really
count here, we should just dump all token info we can see. In the
future, we could then add the possibility to take an argument (likely a
path to a bpffs) to show info for a particular mountpoint; a bit like
you can list all existing programs with "bpftool prog show" but can also
chose to pick one with "bpftool prog show id ...".
If we print info for several mountpoint, I'd suggest adjusting the
format for the plain output slightly: I'd remove the blank lines between
the different sections to get something more compact, maybe play with
the indent as well, like when we list programs or maps.
Thanks,
Quentin
prev parent reply other threads:[~2025-07-22 9:23 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-20 17:33 Tao Chen
2025-07-20 17:33 ` [PATCH bpf-next 2/2] bpftool: Add bpftool-token manpage Tao Chen
2025-07-21 16:23 ` Quentin Monnet
2025-07-22 6:06 ` Tao Chen
2025-07-21 16:23 ` [PATCH bpf-next 1/2] bpftool: Add bpf_token show Quentin Monnet
2025-07-22 5:48 ` Tao Chen
2025-07-22 9:23 ` Quentin Monnet [this message]
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=f956664e-24a2-410a-be9b-4d90e08c7c64@kernel.org \
--to=qmo@kernel.org \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=chen.dylane@linux.dev \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=eddyz87@gmail.com \
--cc=haoluo@google.com \
--cc=hawk@kernel.org \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=netdev@vger.kernel.org \
--cc=sdf@fomichev.me \
--cc=song@kernel.org \
--cc=yonghong.song@linux.dev \
/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
all inboxes | Powered by JetHome®