Skip to content

Commit 5efc529

Browse files
anakryikoborkmann
authored andcommitted
docs/btf: fix typos, improve wording
Fix various typos, some of the formatting and wording for Documentation/btf.rst. Signed-off-by: Andrii Nakryiko <andriin@fb.com> Acked-by: Yonghong Song <yhs@fb.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
1 parent 4b91130 commit 5efc529

File tree

1 file changed

+53
-55
lines changed

1 file changed

+53
-55
lines changed

Documentation/bpf/btf.rst

Lines changed: 53 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ BPF Type Format (BTF)
55
1. Introduction
66
***************
77

8-
BTF (BPF Type Format) is the meta data format which
8+
BTF (BPF Type Format) is the metadata format which
99
encodes the debug info related to BPF program/map.
1010
The name BTF was used initially to describe
1111
data types. The BTF was later extended to include
@@ -40,8 +40,8 @@ details in :ref:`BTF_Type_String`.
4040
2. BTF Type and String Encoding
4141
*******************************
4242

43-
The file ``include/uapi/linux/btf.h`` provides high
44-
level definition on how types/strings are encoded.
43+
The file ``include/uapi/linux/btf.h`` provides high-level
44+
definition of how types/strings are encoded.
4545

4646
The beginning of data blob must be::
4747

@@ -59,23 +59,23 @@ The beginning of data blob must be::
5959
};
6060

6161
The magic is ``0xeB9F``, which has different encoding for big and little
62-
endian system, and can be used to test whether BTF is generated for
63-
big or little endian target.
64-
The btf_header is designed to be extensible with hdr_len equal to
65-
``sizeof(struct btf_header)`` when the data blob is generated.
62+
endian systems, and can be used to test whether BTF is generated for
63+
big- or little-endian target.
64+
The ``btf_header`` is designed to be extensible with ``hdr_len`` equal to
65+
``sizeof(struct btf_header)`` when a data blob is generated.
6666

6767
2.1 String Encoding
6868
===================
6969

7070
The first string in the string section must be a null string.
71-
The rest of string table is a concatenation of other null-treminated
71+
The rest of string table is a concatenation of other null-terminated
7272
strings.
7373

7474
2.2 Type Encoding
7575
=================
7676

7777
The type id ``0`` is reserved for ``void`` type.
78-
The type section is parsed sequentially and the type id is assigned to
78+
The type section is parsed sequentially and type id is assigned to
7979
each recognized type starting from id ``1``.
8080
Currently, the following types are supported::
8181

@@ -122,9 +122,9 @@ Each type contains the following common data::
122122
};
123123
};
124124

125-
For certain kinds, the common data are followed by kind specific data.
126-
The ``name_off`` in ``struct btf_type`` specifies the offset in the string table.
127-
The following details encoding of each kind.
125+
For certain kinds, the common data are followed by kind-specific data.
126+
The ``name_off`` in ``struct btf_type`` specifies the offset in the string
127+
table. The following sections detail encoding of each kind.
128128

129129
2.2.1 BTF_KIND_INT
130130
~~~~~~~~~~~~~~~~~~
@@ -136,7 +136,7 @@ The following details encoding of each kind.
136136
* ``info.vlen``: 0
137137
* ``size``: the size of the int type in bytes.
138138

139-
``btf_type`` is followed by a ``u32`` with following bits arrangement::
139+
``btf_type`` is followed by a ``u32`` with the following bits arrangement::
140140

141141
#define BTF_INT_ENCODING(VAL) (((VAL) & 0x0f000000) >> 24)
142142
#define BTF_INT_OFFSET(VAL) (((VAL & 0x00ff0000)) >> 16)
@@ -148,7 +148,7 @@ The ``BTF_INT_ENCODING`` has the following attributes::
148148
#define BTF_INT_CHAR (1 << 1)
149149
#define BTF_INT_BOOL (1 << 2)
150150

151-
The ``BTF_INT_ENCODING()`` provides extra information, signness,
151+
The ``BTF_INT_ENCODING()`` provides extra information: signedness,
152152
char, or bool, for the int type. The char and bool encoding
153153
are mostly useful for pretty print. At most one encoding can
154154
be specified for the int type.
@@ -161,8 +161,7 @@ The maximum value of ``BTF_INT_BITS()`` is 128.
161161

162162
The ``BTF_INT_OFFSET()`` specifies the starting bit offset to
163163
calculate values for this int. For example, a bitfield struct
164-
member has
165-
164+
member has:
166165
* btf member bit offset 100 from the start of the structure,
167166
* btf member pointing to an int type,
168167
* the int type has ``BTF_INT_OFFSET() = 2`` and ``BTF_INT_BITS() = 4``
@@ -179,7 +178,7 @@ access the same bits as the above:
179178

180179
The original intention of ``BTF_INT_OFFSET()`` is to provide
181180
flexibility of bitfield encoding.
182-
Currently, both llvm and pahole generates ``BTF_INT_OFFSET() = 0``
181+
Currently, both llvm and pahole generate ``BTF_INT_OFFSET() = 0``
183182
for all int types.
184183

185184
2.2.2 BTF_KIND_PTR
@@ -204,7 +203,7 @@ No additional type data follow ``btf_type``.
204203
* ``info.vlen``: 0
205204
* ``size/type``: 0, not used
206205

207-
btf_type is followed by one "struct btf_array"::
206+
``btf_type`` is followed by one ``struct btf_array``::
208207

209208
struct btf_array {
210209
__u32 type;
@@ -217,27 +216,26 @@ The ``struct btf_array`` encoding:
217216
* ``index_type``: the index type
218217
* ``nelems``: the number of elements for this array (``0`` is also allowed).
219218

220-
The ``index_type`` can be any regular int types
221-
(u8, u16, u32, u64, unsigned __int128).
222-
The original design of including ``index_type`` follows dwarf
223-
which has a ``index_type`` for its array type.
219+
The ``index_type`` can be any regular int type
220+
(``u8``, ``u16``, ``u32``, ``u64``, ``unsigned __int128``).
221+
The original design of including ``index_type`` follows DWARF,
222+
which has an ``index_type`` for its array type.
224223
Currently in BTF, beyond type verification, the ``index_type`` is not used.
225224

226225
The ``struct btf_array`` allows chaining through element type to represent
227-
multiple dimensional arrays. For example, ``int a[5][6]``, the following
228-
type system illustrates the chaining:
226+
multidimensional arrays. For example, for ``int a[5][6]``, the following
227+
type information illustrates the chaining:
229228

230229
* [1]: int
231230
* [2]: array, ``btf_array.type = [1]``, ``btf_array.nelems = 6``
232231
* [3]: array, ``btf_array.type = [2]``, ``btf_array.nelems = 5``
233232

234-
Currently, both pahole and llvm collapse multiple dimensional array
235-
into one dimensional array, e.g., ``a[5][6]``, the btf_array.nelems
236-
equal to ``30``. This is because the original use case is map pretty
237-
print where the whole array is dumped out so one dimensional array
233+
Currently, both pahole and llvm collapse multidimensional array
234+
into one-dimensional array, e.g., for ``a[5][6]``, the ``btf_array.nelems``
235+
is equal to ``30``. This is because the original use case is map pretty
236+
print where the whole array is dumped out so one-dimensional array
238237
is enough. As more BTF usage is explored, pahole and llvm can be
239-
changed to generate proper chained representation for
240-
multiple dimensional arrays.
238+
changed to generate proper chained representation for multidimensional arrays.
241239

242240
2.2.4 BTF_KIND_STRUCT
243241
~~~~~~~~~~~~~~~~~~~~~
@@ -382,7 +380,7 @@ No additional type data follow ``btf_type``.
382380

383381
No additional type data follow ``btf_type``.
384382

385-
A BTF_KIND_FUNC defines, not a type, but a subprogram (function) whose
383+
A BTF_KIND_FUNC defines not a type, but a subprogram (function) whose
386384
signature is defined by ``type``. The subprogram is thus an instance of
387385
that type. The BTF_KIND_FUNC may in turn be referenced by a func_info in
388386
the :ref:`BTF_Ext_Section` (ELF) or in the arguments to
@@ -459,10 +457,10 @@ The workflow typically looks like:
459457
3.1 BPF_BTF_LOAD
460458
================
461459

462-
Load a blob of BTF data into kernel. A blob of data
463-
described in :ref:`BTF_Type_String`
460+
Load a blob of BTF data into kernel. A blob of data,
461+
described in :ref:`BTF_Type_String`,
464462
can be directly loaded into the kernel.
465-
A ``btf_fd`` returns to userspace.
463+
A ``btf_fd`` is returned to a userspace.
466464

467465
3.2 BPF_MAP_CREATE
468466
==================
@@ -487,7 +485,7 @@ In libbpf, the map can be defined with extra annotation like below:
487485
Here, the parameters for macro BPF_ANNOTATE_KV_PAIR are map name,
488486
key and value types for the map.
489487
During ELF parsing, libbpf is able to extract key/value type_id's
490-
and assigned them to BPF_MAP_CREATE attributes automatically.
488+
and assign them to BPF_MAP_CREATE attributes automatically.
491489

492490
.. _BPF_Prog_Load:
493491

@@ -532,7 +530,7 @@ Below are requirements for func_info:
532530
bpf func boundaries.
533531

534532
Below are requirements for line_info:
535-
* the first insn in each func must points to a line_info record.
533+
* the first insn in each func must have a line_info record pointing to it.
536534
* the line_info insn_off is in strictly increasing order.
537535

538536
For line_info, the line number and column number are defined as below:
@@ -544,26 +542,26 @@ For line_info, the line number and column number are defined as below:
544542
3.4 BPF_{PROG,MAP}_GET_NEXT_ID
545543

546544
In kernel, every loaded program, map or btf has a unique id.
547-
The id won't change during the life time of the program, map or btf.
545+
The id won't change during the lifetime of a program, map, or btf.
548546

549547
The bpf syscall command BPF_{PROG,MAP}_GET_NEXT_ID
550548
returns all id's, one for each command, to user space, for bpf
551-
program or maps,
552-
so the inspection tool can inspect all programs and maps.
549+
program or maps, respectively,
550+
so an inspection tool can inspect all programs and maps.
553551

554552
3.5 BPF_{PROG,MAP}_GET_FD_BY_ID
555553

556-
The introspection tool cannot use id to get details about program or maps.
557-
A file descriptor needs to be obtained first for reference counting purpose.
554+
An introspection tool cannot use id to get details about program or maps.
555+
A file descriptor needs to be obtained first for reference-counting purpose.
558556

559557
3.6 BPF_OBJ_GET_INFO_BY_FD
560558
==========================
561559

562-
Once a program/map fd is acquired, the introspection tool can
560+
Once a program/map fd is acquired, an introspection tool can
563561
get the detailed information from kernel about this fd,
564-
some of which is btf related. For example,
565-
``bpf_map_info`` returns ``btf_id``, key/value type id.
566-
``bpf_prog_info`` returns ``btf_id``, func_info and line info
562+
some of which are BTF-related. For example,
563+
``bpf_map_info`` returns ``btf_id`` and key/value type ids.
564+
``bpf_prog_info`` returns ``btf_id``, func_info, and line info
567565
for translated bpf byte codes, and jited_line_info.
568566

569567
3.7 BPF_BTF_GET_FD_BY_ID
@@ -574,9 +572,9 @@ bpf syscall command BPF_BTF_GET_FD_BY_ID can retrieve a btf fd.
574572
Then, with command BPF_OBJ_GET_INFO_BY_FD, the btf blob, originally
575573
loaded into the kernel with BPF_BTF_LOAD, can be retrieved.
576574

577-
With the btf blob, ``bpf_map_info`` and ``bpf_prog_info``, the introspection
575+
With the btf blob, ``bpf_map_info``, and ``bpf_prog_info``, an introspection
578576
tool has full btf knowledge and is able to pretty print map key/values,
579-
dump func signatures, dump line info along with byte/jit codes.
577+
dump func signatures and line info, along with byte/jit codes.
580578

581579
4. ELF File Format Interface
582580
****************************
@@ -625,8 +623,8 @@ The func_info is organized as below.::
625623
...
626624

627625
``func_info_rec_size`` specifies the size of ``bpf_func_info`` structure
628-
when .BTF.ext is generated. btf_ext_info_sec, defined below, is
629-
the func_info for each specific ELF section.::
626+
when .BTF.ext is generated. ``btf_ext_info_sec``, defined below, is
627+
a collection of func_info for each specific ELF section.::
630628

631629
struct btf_ext_info_sec {
632630
__u32 sec_name_off; /* offset to section name */
@@ -661,7 +659,7 @@ from the beginning of section (``btf_ext_info_sec->sec_name_off``).
661659

662660
With BTF, the map key/value can be printed based on fields rather than
663661
simply raw bytes. This is especially
664-
valuable for large structure or if you data structure
662+
valuable for large structure or if your data structure
665663
has bitfields. For example, for the following map,::
666664

667665
enum A { A1, A2, A3, A4, A5 };
@@ -702,8 +700,8 @@ bpftool is able to pretty print like below:
702700
5.2 bpftool prog dump
703701
=====================
704702

705-
The following is an example to show func_info and line_info
706-
can help prog dump with better kernel symbol name, function prototype
703+
The following is an example showing how func_info and line_info
704+
can help prog dump with better kernel symbol names, function prototypes
707705
and line information.::
708706

709707
$ bpftool prog dump jited pinned /sys/fs/bpf/test_btf_haskv
@@ -733,10 +731,10 @@ and line information.::
733731
; counts = bpf_map_lookup_elem(&btf_map, &key);
734732
[...]
735733

736-
5.3 verifier log
734+
5.3 Verifier Log
737735
================
738736

739-
The following is an example how line_info can help verifier failure debug.::
737+
The following is an example of how line_info can help debugging verification failure.::
740738

741739
/* The code at tools/testing/selftests/bpf/test_xdp_noinline.c
742740
* is modified as below.
@@ -867,4 +865,4 @@ The assembly code (-S) is able to show the BTF encoding in assembly format.::
867865
7. Testing
868866
**********
869867

870-
Kernel bpf selftest `test_btf.c` provides extensive set of BTF related tests.
868+
Kernel bpf selftest `test_btf.c` provides extensive set of BTF-related tests.

0 commit comments

Comments
 (0)