Skip to content

Commit e1289cf

Browse files
committed
Merge git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next
Daniel Borkmann says: ==================== pull-request: bpf-next 2021-06-28 The following pull-request contains BPF updates for your *net-next* tree. We've added 37 non-merge commits during the last 12 day(s) which contain a total of 56 files changed, 394 insertions(+), 380 deletions(-). The main changes are: 1) XDP driver RCU cleanups, from Toke Høiland-Jørgensen and Paul E. McKenney. 2) Fix bpf_skb_change_proto() IPv4/v6 GSO handling, from Maciej Żenczykowski. 3) Fix false positive kmemleak report for BPF ringbuf alloc, from Rustam Kovhaev. 4) Fix x86 JIT's extable offset calculation for PROBE_LDX NULL, from Ravi Bangoria. 5) Enable libbpf fallback probing with tracing under RHEL7, from Jonathan Edwards. 6) Clean up x86 JIT to remove unused cnt tracking from EMIT macro, from Jiri Olsa. 7) Netlink cleanups for libbpf to please Coverity, from Kumar Kartikeya Dwivedi. 8) Allow to retrieve ancestor cgroup id in tracing programs, from Namhyung Kim. 9) Fix lirc BPF program query to use user-provided prog_cnt, from Sean Young. 10) Add initial libbpf doc including generated kdoc for its API, from Grant Seltzer. 11) Make xdp_rxq_info_unreg_mem_model() more robust, from Jakub Kicinski. 12) Fix up bpfilter startup log-level to info level, from Gary Lin. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 1fd07f3 + a78cae2 commit e1289cf

File tree

56 files changed

+394
-380
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+394
-380
lines changed

Documentation/RCU/checklist.rst

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -211,27 +211,40 @@ over a rather long period of time, but improvements are always welcome!
211211
of the system, especially to real-time workloads running on
212212
the rest of the system.
213213

214-
7. As of v4.20, a given kernel implements only one RCU flavor,
215-
which is RCU-sched for PREEMPTION=n and RCU-preempt for PREEMPTION=y.
216-
If the updater uses call_rcu() or synchronize_rcu(),
217-
then the corresponding readers may use rcu_read_lock() and
218-
rcu_read_unlock(), rcu_read_lock_bh() and rcu_read_unlock_bh(),
219-
or any pair of primitives that disables and re-enables preemption,
220-
for example, rcu_read_lock_sched() and rcu_read_unlock_sched().
221-
If the updater uses synchronize_srcu() or call_srcu(),
222-
then the corresponding readers must use srcu_read_lock() and
223-
srcu_read_unlock(), and with the same srcu_struct. The rules for
224-
the expedited primitives are the same as for their non-expedited
225-
counterparts. Mixing things up will result in confusion and
226-
broken kernels, and has even resulted in an exploitable security
227-
issue.
228-
229-
One exception to this rule: rcu_read_lock() and rcu_read_unlock()
230-
may be substituted for rcu_read_lock_bh() and rcu_read_unlock_bh()
231-
in cases where local bottom halves are already known to be
232-
disabled, for example, in irq or softirq context. Commenting
233-
such cases is a must, of course! And the jury is still out on
234-
whether the increased speed is worth it.
214+
7. As of v4.20, a given kernel implements only one RCU flavor, which
215+
is RCU-sched for PREEMPTION=n and RCU-preempt for PREEMPTION=y.
216+
If the updater uses call_rcu() or synchronize_rcu(), then
217+
the corresponding readers may use: (1) rcu_read_lock() and
218+
rcu_read_unlock(), (2) any pair of primitives that disables
219+
and re-enables softirq, for example, rcu_read_lock_bh() and
220+
rcu_read_unlock_bh(), or (3) any pair of primitives that disables
221+
and re-enables preemption, for example, rcu_read_lock_sched() and
222+
rcu_read_unlock_sched(). If the updater uses synchronize_srcu()
223+
or call_srcu(), then the corresponding readers must use
224+
srcu_read_lock() and srcu_read_unlock(), and with the same
225+
srcu_struct. The rules for the expedited RCU grace-period-wait
226+
primitives are the same as for their non-expedited counterparts.
227+
228+
If the updater uses call_rcu_tasks() or synchronize_rcu_tasks(),
229+
then the readers must refrain from executing voluntary
230+
context switches, that is, from blocking. If the updater uses
231+
call_rcu_tasks_trace() or synchronize_rcu_tasks_trace(), then
232+
the corresponding readers must use rcu_read_lock_trace() and
233+
rcu_read_unlock_trace(). If an updater uses call_rcu_tasks_rude()
234+
or synchronize_rcu_tasks_rude(), then the corresponding readers
235+
must use anything that disables interrupts.
236+
237+
Mixing things up will result in confusion and broken kernels, and
238+
has even resulted in an exploitable security issue. Therefore,
239+
when using non-obvious pairs of primitives, commenting is
240+
of course a must. One example of non-obvious pairing is
241+
the XDP feature in networking, which calls BPF programs from
242+
network-driver NAPI (softirq) context. BPF relies heavily on RCU
243+
protection for its data structures, but because the BPF program
244+
invocation happens entirely within a single local_bh_disable()
245+
section in a NAPI poll cycle, this usage is safe. The reason
246+
that this usage is safe is that readers can use anything that
247+
disables BH when updaters use call_rcu() or synchronize_rcu().
235248

236249
8. Although synchronize_rcu() is slower than is call_rcu(), it
237250
usually results in simpler code. So, unless update performance is

Documentation/bpf/index.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,19 @@ BPF instruction-set.
1212
The Cilium project also maintains a `BPF and XDP Reference Guide`_
1313
that goes into great technical depth about the BPF Architecture.
1414

15+
libbpf
16+
======
17+
18+
Libbpf is a userspace library for loading and interacting with bpf programs.
19+
20+
.. toctree::
21+
:maxdepth: 1
22+
23+
libbpf/libbpf
24+
libbpf/libbpf_api
25+
libbpf/libbpf_build
26+
libbpf/libbpf_naming_convention
27+
1528
BPF Type Format (BTF)
1629
=====================
1730

Documentation/bpf/libbpf/libbpf.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.. SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
2+
3+
libbpf
4+
======
5+
6+
This is documentation for libbpf, a userspace library for loading and
7+
interacting with bpf programs.
8+
9+
All general BPF questions, including kernel functionality, libbpf APIs and
10+
their application, should be sent to [email protected] mailing list.
11+
You can `subscribe <http://vger.kernel.org/vger-lists.html#bpf>`_ to the
12+
mailing list search its `archive <https://lore.kernel.org/bpf/>`_.
13+
Please search the archive before asking new questions. It very well might
14+
be that this was already addressed or answered before.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
.. SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
2+
3+
API
4+
===
5+
6+
This documentation is autogenerated from header files in libbpf, tools/lib/bpf
7+
8+
.. kernel-doc:: tools/lib/bpf/libbpf.h
9+
:internal:
10+
11+
.. kernel-doc:: tools/lib/bpf/bpf.h
12+
:internal:
13+
14+
.. kernel-doc:: tools/lib/bpf/btf.h
15+
:internal:
16+
17+
.. kernel-doc:: tools/lib/bpf/xsk.h
18+
:internal:
19+
20+
.. kernel-doc:: tools/lib/bpf/bpf_tracing.h
21+
:internal:
22+
23+
.. kernel-doc:: tools/lib/bpf/bpf_core_read.h
24+
:internal:
25+
26+
.. kernel-doc:: tools/lib/bpf/bpf_endian.h
27+
:internal:
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
.. SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
2+
3+
Building libbpf
4+
===============
5+
6+
libelf and zlib are internal dependencies of libbpf and thus are required to link
7+
against and must be installed on the system for applications to work.
8+
pkg-config is used by default to find libelf, and the program called
9+
can be overridden with PKG_CONFIG.
10+
11+
If using pkg-config at build time is not desired, it can be disabled by
12+
setting NO_PKG_CONFIG=1 when calling make.
13+
14+
To build both static libbpf.a and shared libbpf.so:
15+
16+
.. code-block:: bash
17+
18+
$ cd src
19+
$ make
20+
21+
To build only static libbpf.a library in directory build/ and install them
22+
together with libbpf headers in a staging directory root/:
23+
24+
.. code-block:: bash
25+
26+
$ cd src
27+
$ mkdir build root
28+
$ BUILD_STATIC_ONLY=y OBJDIR=build DESTDIR=root make install
29+
30+
To build both static libbpf.a and shared libbpf.so against a custom libelf
31+
dependency installed in /build/root/ and install them together with libbpf
32+
headers in a build directory /build/root/:
33+
34+
.. code-block:: bash
35+
36+
$ cd src
37+
$ PKG_CONFIG_PATH=/build/root/lib64/pkgconfig DESTDIR=/build/root make

tools/lib/bpf/README.rst renamed to Documentation/bpf/libbpf/libbpf_naming_convention.rst

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.. SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
22
3-
libbpf API naming convention
4-
============================
3+
API naming convention
4+
=====================
55

66
libbpf API provides access to a few logically separated groups of
77
functions and types. Every group has its own naming convention
@@ -10,14 +10,14 @@ new function or type is added to keep libbpf API clean and consistent.
1010

1111
All types and functions provided by libbpf API should have one of the
1212
following prefixes: ``bpf_``, ``btf_``, ``libbpf_``, ``xsk_``,
13-
``perf_buffer_``.
13+
``btf_dump_``, ``ring_buffer_``, ``perf_buffer_``.
1414

1515
System call wrappers
1616
--------------------
1717

1818
System call wrappers are simple wrappers for commands supported by
1919
sys_bpf system call. These wrappers should go to ``bpf.h`` header file
20-
and map one-on-one to corresponding commands.
20+
and map one to one to corresponding commands.
2121

2222
For example ``bpf_map_lookup_elem`` wraps ``BPF_MAP_LOOKUP_ELEM``
2323
command of sys_bpf, ``bpf_prog_attach`` wraps ``BPF_PROG_ATTACH``, etc.
@@ -49,10 +49,6 @@ object, ``bpf_object``, double underscore and ``open`` that defines the
4949
purpose of the function to open ELF file and create ``bpf_object`` from
5050
it.
5151

52-
Another example: ``bpf_program__load`` is named for corresponding
53-
object, ``bpf_program``, that is separated from other part of the name
54-
by double underscore.
55-
5652
All objects and corresponding functions other than BTF related should go
5753
to ``libbpf.h``. BTF types and functions should go to ``btf.h``.
5854

@@ -72,11 +68,7 @@ of both low-level ring access functions and high-level configuration
7268
functions. These can be mixed and matched. Note that these functions
7369
are not reentrant for performance reasons.
7470

75-
Please take a look at Documentation/networking/af_xdp.rst in the Linux
76-
kernel source tree on how to use XDP sockets and for some common
77-
mistakes in case you do not get any traffic up to user space.
78-
79-
libbpf ABI
71+
ABI
8072
==========
8173

8274
libbpf can be both linked statically or used as DSO. To avoid possible
@@ -116,7 +108,8 @@ This bump in ABI version is at most once per kernel development cycle.
116108

117109
For example, if current state of ``libbpf.map`` is:
118110

119-
.. code-block::
111+
.. code-block:: c
112+
120113
LIBBPF_0.0.1 {
121114
global:
122115
bpf_func_a;
@@ -128,7 +121,8 @@ For example, if current state of ``libbpf.map`` is:
128121
, and a new symbol ``bpf_func_c`` is being introduced, then
129122
``libbpf.map`` should be changed like this:
130123

131-
.. code-block::
124+
.. code-block:: c
125+
132126
LIBBPF_0.0.1 {
133127
global:
134128
bpf_func_a;
@@ -148,7 +142,7 @@ Format of version script and ways to handle ABI changes, including
148142
incompatible ones, described in details in [1].
149143

150144
Stand-alone build
151-
=================
145+
-------------------
152146

153147
Under https://github.com/libbpf/libbpf there is a (semi-)automated
154148
mirror of the mainline's version of libbpf for a stand-alone build.
@@ -157,12 +151,12 @@ However, all changes to libbpf's code base must be upstreamed through
157151
the mainline kernel tree.
158152

159153
License
160-
=======
154+
-------------------
161155

162156
libbpf is dual-licensed under LGPL 2.1 and BSD 2-Clause.
163157

164158
Links
165-
=====
159+
-------------------
166160

167161
[1] https://www.akkadia.org/drepper/dsohowto.pdf
168162
(Chapter 3. Maintaining APIs and ABIs).

Documentation/networking/af_xdp.rst

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -290,19 +290,19 @@ round-robin example of distributing packets is shown below:
290290
#define MAX_SOCKS 16
291291
292292
struct {
293-
__uint(type, BPF_MAP_TYPE_XSKMAP);
294-
__uint(max_entries, MAX_SOCKS);
295-
__uint(key_size, sizeof(int));
296-
__uint(value_size, sizeof(int));
293+
__uint(type, BPF_MAP_TYPE_XSKMAP);
294+
__uint(max_entries, MAX_SOCKS);
295+
__uint(key_size, sizeof(int));
296+
__uint(value_size, sizeof(int));
297297
} xsks_map SEC(".maps");
298298
299299
static unsigned int rr;
300300
301301
SEC("xdp_sock") int xdp_sock_prog(struct xdp_md *ctx)
302302
{
303-
rr = (rr + 1) & (MAX_SOCKS - 1);
303+
rr = (rr + 1) & (MAX_SOCKS - 1);
304304
305-
return bpf_redirect_map(&xsks_map, rr, XDP_DROP);
305+
return bpf_redirect_map(&xsks_map, rr, XDP_DROP);
306306
}
307307
308308
Note, that since there is only a single set of FILL and COMPLETION
@@ -379,7 +379,7 @@ would look like this for the TX path:
379379
.. code-block:: c
380380
381381
if (xsk_ring_prod__needs_wakeup(&my_tx_ring))
382-
sendto(xsk_socket__fd(xsk_handle), NULL, 0, MSG_DONTWAIT, NULL, 0);
382+
sendto(xsk_socket__fd(xsk_handle), NULL, 0, MSG_DONTWAIT, NULL, 0);
383383
384384
I.e., only use the syscall if the flag is set.
385385

@@ -442,9 +442,9 @@ purposes. The supported statistics are shown below:
442442
.. code-block:: c
443443
444444
struct xdp_statistics {
445-
__u64 rx_dropped; /* Dropped for reasons other than invalid desc */
446-
__u64 rx_invalid_descs; /* Dropped due to invalid descriptor */
447-
__u64 tx_invalid_descs; /* Dropped due to invalid descriptor */
445+
__u64 rx_dropped; /* Dropped for reasons other than invalid desc */
446+
__u64 rx_invalid_descs; /* Dropped due to invalid descriptor */
447+
__u64 tx_invalid_descs; /* Dropped due to invalid descriptor */
448448
};
449449
450450
XDP_OPTIONS getsockopt
@@ -483,15 +483,15 @@ like this:
483483
.. code-block:: c
484484
485485
// struct xdp_rxtx_ring {
486-
// __u32 *producer;
487-
// __u32 *consumer;
488-
// struct xdp_desc *desc;
486+
// __u32 *producer;
487+
// __u32 *consumer;
488+
// struct xdp_desc *desc;
489489
// };
490490
491491
// struct xdp_umem_ring {
492-
// __u32 *producer;
493-
// __u32 *consumer;
494-
// __u64 *desc;
492+
// __u32 *producer;
493+
// __u32 *consumer;
494+
// __u64 *desc;
495495
// };
496496
497497
// typedef struct xdp_rxtx_ring RING;

0 commit comments

Comments
 (0)