Thread (7 messages) 7 messages, 2 authors, 2025-07-23

Re: [PATCH bpf-next v3 1/3] bpftool: Add bpf_token show

From: Quentin Monnet <qmo@kernel.org>
Date: 2025-07-23 10:50:36
Also in: bpf, lkml

2025-07-23 11:40 UTC+0100 ~ Quentin Monnet [off-list ref]
2025-07-23 11:31 UTC+0800 ~ Tao Chen [off-list ref]
quoted
Add `bpftool token show` command to get token info
from bpffs 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
token_info  /sys/fs/bpf/token2
	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": [],
	"allowed_progs": ["kprobe"],
	"allowed_attachs": ["xdp"]
}, {
	"token_info": "/sys/fs/bpf/token2",
	"allowed_cmds": ["map_create", "prog_load"],
	"allowed_maps": [],
	"allowed_progs": ["kprobe"],
	"allowed_attachs": ["xdp"]
}]

Signed-off-by: Tao Chen <redacted>
---
[...]
quoted
diff --git a/tools/bpf/bpftool/token.c b/tools/bpf/bpftool/token.c
new file mode 100644
index 00000000000..06b56ea40b8
--- /dev/null
+++ b/tools/bpf/bpftool/token.c
[...]
quoted
+static int do_help(int argc, char **argv)
+{
+	if (json_output) {
+		jsonw_null(json_wtr);
+		return 0;
+	}
+
+	fprintf(stderr,
+		"Usage: %1$s %2$s { show | list }\n"
+		"	%1$s %2$s help\n"

One more nit: applying and testing the help message locally, I noticed
that the alignement is not correct:

    $ ./bpftool token help
    Usage: bpftool token { show | list }
            bpftool token help

The two "bpftool" should be aligned. This is because you use a tab for
indent on the "help" line. Can you please replace it with spaces to fix
indentation, and remain consistent with what other files do?

After that change, you can add:

    Reviewed-by: Quentin Monnet [off-list ref]

Please also take a look at the "CHECK" reports from checkpatch, some of
them are worth addressing:

https://netdev.bots.linux.dev/static/nipa/984952/14165722/checkpatch/stdout

(accessed via
https://patchwork.kernel.org/project/netdevbpf/patch/20250723033107.1411154-1-chen.dylane@linux.dev/)

Thanks,
Quentin
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help