Skip to content

Commit 150f29f

Browse files
committed
Merge git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next
Daniel Borkmann says: ==================== pull-request: bpf-next 2020-09-01 The following pull-request contains BPF updates for your *net-next* tree. There are two small conflicts when pulling, resolve as follows: 1) Merge conflict in tools/lib/bpf/libbpf.c between 88a8212 ("libbpf: Factor out common ELF operations and improve logging") in bpf-next and 1e891e5 ("libbpf: Fix map index used in error message") in net-next. Resolve by taking the hunk in bpf-next: [...] scn = elf_sec_by_idx(obj, obj->efile.btf_maps_shndx); data = elf_sec_data(obj, scn); if (!scn || !data) { pr_warn("elf: failed to get %s map definitions for %s\n", MAPS_ELF_SEC, obj->path); return -EINVAL; } [...] 2) Merge conflict in drivers/net/ethernet/mellanox/mlx5/core/en/xsk/rx.c between 9647c57 ("xsk: i40e: ice: ixgbe: mlx5: Test for dma_need_sync earlier for better performance") in bpf-next and e20f0db ("net/mlx5e: RX, Add a prefetch command for small L1_CACHE_BYTES") in net-next. Resolve the two locations by retaining net_prefetch() and taking xsk_buff_dma_sync_for_cpu() from bpf-next. Should look like: [...] xdp_set_data_meta_invalid(xdp); xsk_buff_dma_sync_for_cpu(xdp, rq->xsk_pool); net_prefetch(xdp->data); [...] We've added 133 non-merge commits during the last 14 day(s) which contain a total of 246 files changed, 13832 insertions(+), 3105 deletions(-). The main changes are: 1) Initial support for sleepable BPF programs along with bpf_copy_from_user() helper for tracing to reliably access user memory, from Alexei Starovoitov. 2) Add BPF infra for writing and parsing TCP header options, from Martin KaFai Lau. 3) bpf_d_path() helper for returning full path for given 'struct path', from Jiri Olsa. 4) AF_XDP support for shared umems between devices and queues, from Magnus Karlsson. 5) Initial prep work for full BPF-to-BPF call support in libbpf, from Andrii Nakryiko. 6) Generalize bpf_sk_storage map & add local storage for inodes, from KP Singh. 7) Implement sockmap/hash updates from BPF context, from Lorenz Bauer. 8) BPF xor verification for scalar types & add BPF link iterator, from Yonghong Song. 9) Use target's prog type for BPF_PROG_TYPE_EXT prog verification, from Udip Pant. 10) Rework BPF tracing samples to use libbpf loader, from Daniel T. Lee. 11) Fix xdpsock sample to really cycle through all buffers, from Weqaar Janjua. 12) Improve type safety for tun/veth XDP frame handling, from Maciej Żenczykowski. 13) Various smaller cleanups and improvements all over the place. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents 8aa639e + ebc4ecd commit 150f29f

246 files changed

Lines changed: 13832 additions & 3105 deletions

File tree

Some content is hidden

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

‎Documentation/bpf/bpf_devel_QA.rst‎

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ In case the patch or patch series has to be reworked and sent out
149149
again in a second or later revision, it is also required to add a
150150
version number (``v2``, ``v3``, ...) into the subject prefix::
151151

152-
git format-patch --subject-prefix='PATCH net-next v2' start..finish
152+
git format-patch --subject-prefix='PATCH bpf-next v2' start..finish
153153

154154
When changes have been requested to the patch series, always send the
155155
whole patch series again with the feedback incorporated (never send
@@ -479,17 +479,18 @@ LLVM's static compiler lists the supported targets through
479479

480480
$ llc --version
481481
LLVM (http://llvm.org/):
482-
LLVM version 6.0.0svn
482+
LLVM version 10.0.0
483483
Optimized build.
484484
Default target: x86_64-unknown-linux-gnu
485485
Host CPU: skylake
486486

487487
Registered Targets:
488-
bpf - BPF (host endian)
489-
bpfeb - BPF (big endian)
490-
bpfel - BPF (little endian)
491-
x86 - 32-bit X86: Pentium-Pro and above
492-
x86-64 - 64-bit X86: EM64T and AMD64
488+
aarch64 - AArch64 (little endian)
489+
bpf - BPF (host endian)
490+
bpfeb - BPF (big endian)
491+
bpfel - BPF (little endian)
492+
x86 - 32-bit X86: Pentium-Pro and above
493+
x86-64 - 64-bit X86: EM64T and AMD64
493494

494495
For developers in order to utilize the latest features added to LLVM's
495496
BPF back end, it is advisable to run the latest LLVM releases. Support
@@ -517,6 +518,10 @@ from the git repositories::
517518
The built binaries can then be found in the build/bin/ directory, where
518519
you can point the PATH variable to.
519520

521+
Set ``-DLLVM_TARGETS_TO_BUILD`` equal to the target you wish to build, you
522+
will find a full list of targets within the llvm-project/llvm/lib/Target
523+
directory.
524+
520525
Q: Reporting LLVM BPF issues
521526
----------------------------
522527
Q: Should I notify BPF kernel maintainers about issues in LLVM's BPF code

‎Documentation/bpf/btf.rst‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,31 @@ want to define unused entry in BTF_ID_LIST, like::
724724
BTF_ID_UNUSED
725725
BTF_ID(struct, task_struct)
726726

727+
The ``BTF_SET_START/END`` macros pair defines sorted list of BTF ID values
728+
and their count, with following syntax::
729+
730+
BTF_SET_START(set)
731+
BTF_ID(type1, name1)
732+
BTF_ID(type2, name2)
733+
BTF_SET_END(set)
734+
735+
resulting in following layout in .BTF_ids section::
736+
737+
__BTF_ID__set__set:
738+
.zero 4
739+
__BTF_ID__type1__name1__3:
740+
.zero 4
741+
__BTF_ID__type2__name2__4:
742+
.zero 4
743+
744+
The ``struct btf_id_set set;`` variable is defined to access the list.
745+
746+
The ``typeX`` name can be one of following::
747+
748+
struct, union, typedef, func
749+
750+
and is used as a filter when resolving the BTF ID value.
751+
727752
All the BTF ID lists and sets are compiled in the .BTF_ids section and
728753
resolved during the linking phase of kernel build by ``resolve_btfids`` tool.
729754

‎Documentation/bpf/index.rst‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ Program types
5252
prog_cgroup_sysctl
5353
prog_flow_dissector
5454
bpf_lsm
55+
prog_sk_lookup
5556

5657

5758
Map types
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
.. SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
2+
3+
=====================
4+
BPF sk_lookup program
5+
=====================
6+
7+
BPF sk_lookup program type (``BPF_PROG_TYPE_SK_LOOKUP``) introduces programmability
8+
into the socket lookup performed by the transport layer when a packet is to be
9+
delivered locally.
10+
11+
When invoked BPF sk_lookup program can select a socket that will receive the
12+
incoming packet by calling the ``bpf_sk_assign()`` BPF helper function.
13+
14+
Hooks for a common attach point (``BPF_SK_LOOKUP``) exist for both TCP and UDP.
15+
16+
Motivation
17+
==========
18+
19+
BPF sk_lookup program type was introduced to address setup scenarios where
20+
binding sockets to an address with ``bind()`` socket call is impractical, such
21+
as:
22+
23+
1. receiving connections on a range of IP addresses, e.g. 192.0.2.0/24, when
24+
binding to a wildcard address ``INADRR_ANY`` is not possible due to a port
25+
conflict,
26+
2. receiving connections on all or a wide range of ports, i.e. an L7 proxy use
27+
case.
28+
29+
Such setups would require creating and ``bind()``'ing one socket to each of the
30+
IP address/port in the range, leading to resource consumption and potential
31+
latency spikes during socket lookup.
32+
33+
Attachment
34+
==========
35+
36+
BPF sk_lookup program can be attached to a network namespace with
37+
``bpf(BPF_LINK_CREATE, ...)`` syscall using the ``BPF_SK_LOOKUP`` attach type and a
38+
netns FD as attachment ``target_fd``.
39+
40+
Multiple programs can be attached to one network namespace. Programs will be
41+
invoked in the same order as they were attached.
42+
43+
Hooks
44+
=====
45+
46+
The attached BPF sk_lookup programs run whenever the transport layer needs to
47+
find a listening (TCP) or an unconnected (UDP) socket for an incoming packet.
48+
49+
Incoming traffic to established (TCP) and connected (UDP) sockets is delivered
50+
as usual without triggering the BPF sk_lookup hook.
51+
52+
The attached BPF programs must return with either ``SK_PASS`` or ``SK_DROP``
53+
verdict code. As for other BPF program types that are network filters,
54+
``SK_PASS`` signifies that the socket lookup should continue on to regular
55+
hashtable-based lookup, while ``SK_DROP`` causes the transport layer to drop the
56+
packet.
57+
58+
A BPF sk_lookup program can also select a socket to receive the packet by
59+
calling ``bpf_sk_assign()`` BPF helper. Typically, the program looks up a socket
60+
in a map holding sockets, such as ``SOCKMAP`` or ``SOCKHASH``, and passes a
61+
``struct bpf_sock *`` to ``bpf_sk_assign()`` helper to record the
62+
selection. Selecting a socket only takes effect if the program has terminated
63+
with ``SK_PASS`` code.
64+
65+
When multiple programs are attached, the end result is determined from return
66+
codes of all the programs according to the following rules:
67+
68+
1. If any program returned ``SK_PASS`` and selected a valid socket, the socket
69+
is used as the result of the socket lookup.
70+
2. If more than one program returned ``SK_PASS`` and selected a socket, the last
71+
selection takes effect.
72+
3. If any program returned ``SK_DROP``, and no program returned ``SK_PASS`` and
73+
selected a socket, socket lookup fails.
74+
4. If all programs returned ``SK_PASS`` and none of them selected a socket,
75+
socket lookup continues on.
76+
77+
API
78+
===
79+
80+
In its context, an instance of ``struct bpf_sk_lookup``, BPF sk_lookup program
81+
receives information about the packet that triggered the socket lookup. Namely:
82+
83+
* IP version (``AF_INET`` or ``AF_INET6``),
84+
* L4 protocol identifier (``IPPROTO_TCP`` or ``IPPROTO_UDP``),
85+
* source and destination IP address,
86+
* source and destination L4 port,
87+
* the socket that has been selected with ``bpf_sk_assign()``.
88+
89+
Refer to ``struct bpf_sk_lookup`` declaration in ``linux/bpf.h`` user API
90+
header, and `bpf-helpers(7)
91+
<https://man7.org/linux/man-pages/man7/bpf-helpers.7.html>`_ man-page section
92+
for ``bpf_sk_assign()`` for details.
93+
94+
Example
95+
=======
96+
97+
See ``tools/testing/selftests/bpf/prog_tests/sk_lookup.c`` for the reference
98+
implementation.

‎Documentation/networking/af_xdp.rst‎

Lines changed: 58 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -258,14 +258,21 @@ socket into zero-copy mode or fail.
258258
XDP_SHARED_UMEM bind flag
259259
-------------------------
260260

261-
This flag enables you to bind multiple sockets to the same UMEM, but
262-
only if they share the same queue id. In this mode, each socket has
263-
their own RX and TX rings, but the UMEM (tied to the fist socket
264-
created) only has a single FILL ring and a single COMPLETION
265-
ring. To use this mode, create the first socket and bind it in the normal
266-
way. Create a second socket and create an RX and a TX ring, or at
267-
least one of them, but no FILL or COMPLETION rings as the ones from
268-
the first socket will be used. In the bind call, set he
261+
This flag enables you to bind multiple sockets to the same UMEM. It
262+
works on the same queue id, between queue ids and between
263+
netdevs/devices. In this mode, each socket has their own RX and TX
264+
rings as usual, but you are going to have one or more FILL and
265+
COMPLETION ring pairs. You have to create one of these pairs per
266+
unique netdev and queue id tuple that you bind to.
267+
268+
Starting with the case were we would like to share a UMEM between
269+
sockets bound to the same netdev and queue id. The UMEM (tied to the
270+
fist socket created) will only have a single FILL ring and a single
271+
COMPLETION ring as there is only on unique netdev,queue_id tuple that
272+
we have bound to. To use this mode, create the first socket and bind
273+
it in the normal way. Create a second socket and create an RX and a TX
274+
ring, or at least one of them, but no FILL or COMPLETION rings as the
275+
ones from the first socket will be used. In the bind call, set he
269276
XDP_SHARED_UMEM option and provide the initial socket's fd in the
270277
sxdp_shared_umem_fd field. You can attach an arbitrary number of extra
271278
sockets this way.
@@ -305,11 +312,41 @@ concurrently. There are no synchronization primitives in the
305312
libbpf code that protects multiple users at this point in time.
306313

307314
Libbpf uses this mode if you create more than one socket tied to the
308-
same umem. However, note that you need to supply the
315+
same UMEM. However, note that you need to supply the
309316
XSK_LIBBPF_FLAGS__INHIBIT_PROG_LOAD libbpf_flag with the
310317
xsk_socket__create calls and load your own XDP program as there is no
311318
built in one in libbpf that will route the traffic for you.
312319

320+
The second case is when you share a UMEM between sockets that are
321+
bound to different queue ids and/or netdevs. In this case you have to
322+
create one FILL ring and one COMPLETION ring for each unique
323+
netdev,queue_id pair. Let us say you want to create two sockets bound
324+
to two different queue ids on the same netdev. Create the first socket
325+
and bind it in the normal way. Create a second socket and create an RX
326+
and a TX ring, or at least one of them, and then one FILL and
327+
COMPLETION ring for this socket. Then in the bind call, set he
328+
XDP_SHARED_UMEM option and provide the initial socket's fd in the
329+
sxdp_shared_umem_fd field as you registered the UMEM on that
330+
socket. These two sockets will now share one and the same UMEM.
331+
332+
There is no need to supply an XDP program like the one in the previous
333+
case where sockets were bound to the same queue id and
334+
device. Instead, use the NIC's packet steering capabilities to steer
335+
the packets to the right queue. In the previous example, there is only
336+
one queue shared among sockets, so the NIC cannot do this steering. It
337+
can only steer between queues.
338+
339+
In libbpf, you need to use the xsk_socket__create_shared() API as it
340+
takes a reference to a FILL ring and a COMPLETION ring that will be
341+
created for you and bound to the shared UMEM. You can use this
342+
function for all the sockets you create, or you can use it for the
343+
second and following ones and use xsk_socket__create() for the first
344+
one. Both methods yield the same result.
345+
346+
Note that a UMEM can be shared between sockets on the same queue id
347+
and device, as well as between queues on the same device and between
348+
devices at the same time.
349+
313350
XDP_USE_NEED_WAKEUP bind flag
314351
-----------------------------
315352

@@ -364,7 +401,7 @@ resources by only setting up one of them. Both the FILL ring and the
364401
COMPLETION ring are mandatory as you need to have a UMEM tied to your
365402
socket. But if the XDP_SHARED_UMEM flag is used, any socket after the
366403
first one does not have a UMEM and should in that case not have any
367-
FILL or COMPLETION rings created as the ones from the shared umem will
404+
FILL or COMPLETION rings created as the ones from the shared UMEM will
368405
be used. Note, that the rings are single-producer single-consumer, so
369406
do not try to access them from multiple processes at the same
370407
time. See the XDP_SHARED_UMEM section.
@@ -567,6 +604,17 @@ A: The short answer is no, that is not supported at the moment. The
567604
switch, or other distribution mechanism, in your NIC to direct
568605
traffic to the correct queue id and socket.
569606

607+
Q: My packets are sometimes corrupted. What is wrong?
608+
609+
A: Care has to be taken not to feed the same buffer in the UMEM into
610+
more than one ring at the same time. If you for example feed the
611+
same buffer into the FILL ring and the TX ring at the same time, the
612+
NIC might receive data into the buffer at the same time it is
613+
sending it. This will cause some packets to become corrupted. Same
614+
thing goes for feeding the same buffer into the FILL rings
615+
belonging to different queue ids or netdevs bound with the
616+
XDP_SHARED_UMEM flag.
617+
570618
Credits
571619
=======
572620

‎arch/x86/net/bpf_jit_comp.c‎

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1379,10 +1379,15 @@ static int invoke_bpf_prog(const struct btf_func_model *m, u8 **pprog,
13791379
u8 *prog = *pprog;
13801380
int cnt = 0;
13811381

1382-
if (emit_call(&prog, __bpf_prog_enter, prog))
1383-
return -EINVAL;
1384-
/* remember prog start time returned by __bpf_prog_enter */
1385-
emit_mov_reg(&prog, true, BPF_REG_6, BPF_REG_0);
1382+
if (p->aux->sleepable) {
1383+
if (emit_call(&prog, __bpf_prog_enter_sleepable, prog))
1384+
return -EINVAL;
1385+
} else {
1386+
if (emit_call(&prog, __bpf_prog_enter, prog))
1387+
return -EINVAL;
1388+
/* remember prog start time returned by __bpf_prog_enter */
1389+
emit_mov_reg(&prog, true, BPF_REG_6, BPF_REG_0);
1390+
}
13861391

13871392
/* arg1: lea rdi, [rbp - stack_size] */
13881393
EMIT4(0x48, 0x8D, 0x7D, -stack_size);
@@ -1402,13 +1407,18 @@ static int invoke_bpf_prog(const struct btf_func_model *m, u8 **pprog,
14021407
if (mod_ret)
14031408
emit_stx(&prog, BPF_DW, BPF_REG_FP, BPF_REG_0, -8);
14041409

1405-
/* arg1: mov rdi, progs[i] */
1406-
emit_mov_imm64(&prog, BPF_REG_1, (long) p >> 32,
1407-
(u32) (long) p);
1408-
/* arg2: mov rsi, rbx <- start time in nsec */
1409-
emit_mov_reg(&prog, true, BPF_REG_2, BPF_REG_6);
1410-
if (emit_call(&prog, __bpf_prog_exit, prog))
1411-
return -EINVAL;
1410+
if (p->aux->sleepable) {
1411+
if (emit_call(&prog, __bpf_prog_exit_sleepable, prog))
1412+
return -EINVAL;
1413+
} else {
1414+
/* arg1: mov rdi, progs[i] */
1415+
emit_mov_imm64(&prog, BPF_REG_1, (long) p >> 32,
1416+
(u32) (long) p);
1417+
/* arg2: mov rsi, rbx <- start time in nsec */
1418+
emit_mov_reg(&prog, true, BPF_REG_2, BPF_REG_6);
1419+
if (emit_call(&prog, __bpf_prog_exit, prog))
1420+
return -EINVAL;
1421+
}
14121422

14131423
*pprog = prog;
14141424
return 0;

‎drivers/net/ethernet/intel/i40e/i40e_ethtool.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1967,7 +1967,7 @@ static int i40e_set_ringparam(struct net_device *netdev,
19671967
(new_rx_count == vsi->rx_rings[0]->count))
19681968
return 0;
19691969

1970-
/* If there is a AF_XDP UMEM attached to any of Rx rings,
1970+
/* If there is a AF_XDP page pool attached to any of Rx rings,
19711971
* disallow changing the number of descriptors -- regardless
19721972
* if the netdev is running or not.
19731973
*/

0 commit comments

Comments
 (0)