Commit b3eece09 authored by Alexei Starovoitov's avatar Alexei Starovoitov
Browse files

Merge branch 'bpftool-show-pid'



Andrii Nakryiko says:

====================
This patch set implements libbpf support for a second kind of special externs,
kernel symbols, in addition to existing Kconfig externs.

Right now, only untyped (const void) externs are supported, which, in
C language, allow only to take their address. In the future, with kernel BTF
getting type info about its own global and per-cpu variables, libbpf will
extend this support with BTF type info, which will allow to also directly
access variable's contents and follow its internal pointers, similarly to how
it's possible today in fentry/fexit programs.

As a first practical use of this functionality, bpftool gained ability to show
PIDs of processes that have open file descriptors for BPF map/program/link/BTF
object. It relies on iter/task_file BPF iterator program to extract this
information efficiently.

There was a bunch of bpftool refactoring (especially Makefile) necessary to
generalize bpftool's internal BPF program use. This includes generalization of
BPF skeletons support, addition of a vmlinux.h generation, extracting and
building minimal subset of bpftool for bootstrapping.

v2->v3:
- fix sec_btf_id check (Hao);

v1->v2:
- docs fixes (Quentin);
- dual GPL/BSD license for pid_inter.bpf.c (Quentin);
- NULL-init kcfg_data (Hao Luo);

rfc->v1:
- show pids, if supported by kernel, always (Alexei);
- switched iter output to binary to support showing process names;
- update man pages;
- fix few minor bugs in libbpf w.r.t. extern iteration.
====================

Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
parents 1bdb6c9a 075c7766
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
# SPDX-License-Identifier: GPL-2.0-only
*.d
/_bpftool
/bpftool-bootstrap
/bpftool
bpftool*.8
bpf-helpers.*
FEATURE-DUMP.bpftool
feature
libbpf
profiler.skel.h
/*.skel.h
/vmlinux.h
+5 −0
Original line number Diff line number Diff line
@@ -36,6 +36,11 @@ DESCRIPTION
		  otherwise list all BTF objects currently loaded on the
		  system.

		  Since Linux 5.8 bpftool is able to discover information about
		  processes that hold open file descriptors (FDs) against BTF
		  objects. On such kernels bpftool will automatically emit this
		  information as well.

	**bpftool btf dump** *BTF_SRC*
		  Dump BTF entries from a given *BTF_SRC*.

+12 −1
Original line number Diff line number Diff line
@@ -37,6 +37,11 @@ DESCRIPTION
		  zero or more named attributes, some of which depend on type
		  of link.

		  Since Linux 5.8 bpftool is able to discover information about
		  processes that hold open file descriptors (FDs) against BPF
		  links. On such kernels bpftool will automatically emit this
		  information as well.

	**bpftool link pin** *LINK* *FILE*
		  Pin link *LINK* as *FILE*.

@@ -82,6 +87,7 @@ EXAMPLES

    10: cgroup  prog 25
            cgroup_id 614  attach_type egress
            pids test_progs(223)

**# bpftool --json --pretty link show**

@@ -91,7 +97,12 @@ EXAMPLES
            "type": "cgroup",
            "prog_id": 25,
            "cgroup_id": 614,
            "attach_type": "egress"
            "attach_type": "egress",
            "pids": [{
                    "pid": 223,
                    "comm": "test_progs"
                }
            ]
        }
    ]

+7 −1
Original line number Diff line number Diff line
@@ -62,6 +62,11 @@ DESCRIPTION
		  Output will start with map ID followed by map type and
		  zero or more named attributes (depending on kernel version).

		  Since Linux 5.8 bpftool is able to discover information about
		  processes that hold open file descriptors (FDs) against BPF
		  maps. On such kernels bpftool will automatically emit this
		  information as well.

	**bpftool map create** *FILE* **type** *TYPE* **key** *KEY_SIZE* **value** *VALUE_SIZE*  **entries** *MAX_ENTRIES* **name** *NAME* [**flags** *FLAGS*] [**dev** *NAME*]
		  Create a new map with given parameters and pin it to *bpffs*
		  as *FILE*.
@@ -181,6 +186,7 @@ EXAMPLES

  10: hash  name some_map  flags 0x0
        key 4B  value 8B  max_entries 2048  memlock 167936B
        pids systemd(1)

The following three commands are equivalent:

+11 −0
Original line number Diff line number Diff line
@@ -75,6 +75,11 @@ DESCRIPTION
		  program run. Activation or deactivation of the feature is
		  performed via the **kernel.bpf_stats_enabled** sysctl knob.

		  Since Linux 5.8 bpftool is able to discover information about
		  processes that hold open file descriptors (FDs) against BPF
		  programs. On such kernels bpftool will automatically emit this
		  information as well.

	**bpftool prog dump xlated** *PROG* [{ **file** *FILE* | **opcodes** | **visual** | **linum** }]
		  Dump eBPF instructions of the programs from the kernel. By
		  default, eBPF will be disassembled and printed to standard
@@ -243,6 +248,7 @@ EXAMPLES
    10: xdp  name some_prog  tag 005a3d2123620c8b  gpl run_time_ns 81632 run_cnt 10
            loaded_at 2017-09-29T20:11:00+0000  uid 0
            xlated 528B  jited 370B  memlock 4096B  map_ids 10
            pids systemd(1)

**# bpftool --json --pretty prog show**

@@ -262,6 +268,11 @@ EXAMPLES
            "bytes_jited": 370,
            "bytes_memlock": 4096,
            "map_ids": [10
            ],
            "pids": [{
                    "pid": 1,
                    "comm": "systemd"
                }
            ]
        }
    ]
Loading