Commit ec202509 authored by Paul Chaignon's avatar Paul Chaignon Committed by Alexei Starovoitov

bpftool: Match several programs with same tag

When several BPF programs have the same tag, bpftool matches only the
first (in ID order).  This patch changes that behavior such that dump and
show commands return all matched programs.  Commands that require a single
program (e.g., pin and attach) will error out if given a tag that matches
several.  bpftool prog dump will also error out if file or visual are
given and several programs have the given tag.

In the case of the dump command, a program header is added before each
dump only if the tag matches several programs; this patch doesn't change
the output if a single program matches.  The output when several
programs match thus looks as follows.

$ ./bpftool prog dump xlated tag 6deef7357e7b4530
3: cgroup_skb  tag 6deef7357e7b4530  gpl
   0: (bf) r6 = r1
   [...]
   7: (95) exit

4: cgroup_skb  tag 6deef7357e7b4530  gpl
   0: (bf) r6 = r1
   [...]
   7: (95) exit
Signed-off-by: default avatarPaul Chaignon <paul.chaignon@orange.com>
Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/fb1fe943202659a69cd21dd5b907c205af1e1e22.1576263640.git.paul.chaignon@gmail.com
parent a06bf42f
...@@ -53,8 +53,10 @@ DESCRIPTION ...@@ -53,8 +53,10 @@ DESCRIPTION
=========== ===========
**bpftool prog { show | list }** [*PROG*] **bpftool prog { show | list }** [*PROG*]
Show information about loaded programs. If *PROG* is Show information about loaded programs. If *PROG* is
specified show information only about given program, otherwise specified show information only about given programs,
list all programs currently loaded on the system. otherwise list all programs currently loaded on the system.
In case of **tag**, *PROG* may match several programs which
will all be shown.
Output will start with program ID followed by program type and Output will start with program ID followed by program type and
zero or more named attributes (depending on kernel version). zero or more named attributes (depending on kernel version).
...@@ -68,11 +70,15 @@ DESCRIPTION ...@@ -68,11 +70,15 @@ DESCRIPTION
performed via the **kernel.bpf_stats_enabled** sysctl knob. performed via the **kernel.bpf_stats_enabled** sysctl knob.
**bpftool prog dump xlated** *PROG* [{ **file** *FILE* | **opcodes** | **visual** | **linum** }] **bpftool prog dump xlated** *PROG* [{ **file** *FILE* | **opcodes** | **visual** | **linum** }]
Dump eBPF instructions of the program from the kernel. By Dump eBPF instructions of the programs from the kernel. By
default, eBPF will be disassembled and printed to standard default, eBPF will be disassembled and printed to standard
output in human-readable format. In this case, **opcodes** output in human-readable format. In this case, **opcodes**
controls if raw opcodes should be printed as well. controls if raw opcodes should be printed as well.
In case of **tag**, *PROG* may match several programs which
will all be dumped. However, if **file** or **visual** is
specified, *PROG* must match a single program.
If **file** is specified, the binary image will instead be If **file** is specified, the binary image will instead be
written to *FILE*. written to *FILE*.
...@@ -80,15 +86,17 @@ DESCRIPTION ...@@ -80,15 +86,17 @@ DESCRIPTION
built instead, and eBPF instructions will be presented with built instead, and eBPF instructions will be presented with
CFG in DOT format, on standard output. CFG in DOT format, on standard output.
If the prog has line_info available, the source line will If the programs have line_info available, the source line will
be displayed by default. If **linum** is specified, be displayed by default. If **linum** is specified,
the filename, line number and line column will also be the filename, line number and line column will also be
displayed on top of the source line. displayed on top of the source line.
**bpftool prog dump jited** *PROG* [{ **file** *FILE* | **opcodes** | **linum** }] **bpftool prog dump jited** *PROG* [{ **file** *FILE* | **opcodes** | **linum** }]
Dump jited image (host machine code) of the program. Dump jited image (host machine code) of the program.
If *FILE* is specified image will be written to a file, If *FILE* is specified image will be written to a file,
otherwise it will be disassembled and printed to stdout. otherwise it will be disassembled and printed to stdout.
*PROG* must match a single program when **file** is specified.
**opcodes** controls if raw opcodes will be printed. **opcodes** controls if raw opcodes will be printed.
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment