Skip to content

Commit fd129f8

Browse files
committed
Merge git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next
Daniel Borkmann says: ==================== pull-request: bpf-next 2018-06-05 The following pull-request contains BPF updates for your *net-next* tree. The main changes are: 1) Add a new BPF hook for sendmsg similar to existing hooks for bind and connect: "This allows to override source IP (including the case when it's set via cmsg(3)) and destination IP:port for unconnected UDP (slow path). TCP and connected UDP (fast path) are not affected. This makes UDP support complete, that is, connected UDP is handled by connect hooks, unconnected by sendmsg ones.", from Andrey. 2) Rework of the AF_XDP API to allow extending it in future for type writer model if necessary. In this mode a memory window is passed to hardware and multiple frames might be filled into that window instead of just one that is the case in the current fixed frame-size model. With the new changes made this can be supported without having to add a new descriptor format. Also, core bits for the zero-copy support for AF_XDP have been merged as agreed upon, where i40e bits will be routed via Jeff later on. Various improvements to documentation and sample programs included as well, all from Björn and Magnus. 3) Given BPF's flexibility, a new program type has been added to implement infrared decoders. Quote: "The kernel IR decoders support the most widely used IR protocols, but there are many protocols which are not supported. [...] There is a 'long tail' of unsupported IR protocols, for which lircd is need to decode the IR. IR encoding is done in such a way that some simple circuit can decode it; therefore, BPF is ideal. [...] user-space can define a decoder in BPF, attach it to the rc device through the lirc chardev.", from Sean. 4) Several improvements and fixes to BPF core, among others, dumping map and prog IDs into fdinfo which is a straight forward way to correlate BPF objects used by applications, removing an indirect call and therefore retpoline in all map lookup/update/delete calls by invoking the callback directly for 64 bit archs, adding a new bpf_skb_cgroup_id() BPF helper for tc BPF programs to have an efficient way of looking up cgroup v2 id for policy or other use cases. Fixes to make sure we zero tunnel/xfrm state that hasn't been filled, to allow context access wrt pt_regs in 32 bit archs for tracing, and last but not least various test cases for fixes that landed in bpf earlier, from Daniel. 5) Get rid of the ndo_xdp_flush API and extend the ndo_xdp_xmit with a XDP_XMIT_FLUSH flag instead which allows to avoid one indirect call as flushing is now merged directly into ndo_xdp_xmit(), from Jesper. 6) Add a new bpf_get_current_cgroup_id() helper that can be used in tracing to retrieve the cgroup id from the current process in order to allow for e.g. aggregation of container-level events, from Yonghong. 7) Two follow-up fixes for BTF to reject invalid input values and related to that also two test cases for BPF kselftests, from Martin. 8) Various API improvements to the bpf_fib_lookup() helper, that is, dropping MPLS bits which are not fully hashed out yet, rejecting invalid helper flags, returning error for unsupported address families as well as renaming flowlabel to flowinfo, from David. 9) Various fixes and improvements to sockmap BPF kselftests in particular in proper error detection and data verification, from Prashant. 10) Two arm32 BPF JIT improvements. One is to fix imm range check with regards to whether immediate fits into 24 bits, and a naming cleanup to get functions related to rsh handling consistent to those handling lsh, from Wang. 11) Two compile warning fixes in BPF, one for BTF and a false positive to silent gcc in stack_map_get_build_id_offset(), from Arnd. 12) Add missing seg6.h header into tools include infrastructure in order to fix compilation of BPF kselftests, from Mathieu. 13) Several formatting cleanups in the BPF UAPI helper description that also fix an error during rst2man compilation, from Quentin. 14) Hide an unused variable in sk_msg_convert_ctx_access() when IPv6 is not built into the kernel, from Yue. 15) Remove a useless double assignment in dev_map_enqueue(), from Colin. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents a6fa908 + 9fa0610 commit fd129f8

76 files changed

Lines changed: 3841 additions & 730 deletions

Some content is hidden

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

‎Documentation/networking/af_xdp.rst‎

Lines changed: 58 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ packet processing.
1212

1313
This document assumes that the reader is familiar with BPF and XDP. If
1414
not, the Cilium project has an excellent reference guide at
15-
http://cilium.readthedocs.io/en/doc-1.0/bpf/.
15+
http://cilium.readthedocs.io/en/latest/bpf/.
1616

1717
Using the XDP_REDIRECT action from an XDP program, the program can
1818
redirect ingress frames to other XDP enabled netdevs, using the
@@ -33,22 +33,22 @@ for a while due to a possible retransmit, the descriptor that points
3333
to that packet can be changed to point to another and reused right
3434
away. This again avoids copying data.
3535

36-
The UMEM consists of a number of equally size frames and each frame
37-
has a unique frame id. A descriptor in one of the rings references a
38-
frame by referencing its frame id. The user space allocates memory for
39-
this UMEM using whatever means it feels is most appropriate (malloc,
40-
mmap, huge pages, etc). This memory area is then registered with the
41-
kernel using the new setsockopt XDP_UMEM_REG. The UMEM also has two
42-
rings: the FILL ring and the COMPLETION ring. The fill ring is used by
43-
the application to send down frame ids for the kernel to fill in with
44-
RX packet data. References to these frames will then appear in the RX
45-
ring once each packet has been received. The completion ring, on the
46-
other hand, contains frame ids that the kernel has transmitted
47-
completely and can now be used again by user space, for either TX or
48-
RX. Thus, the frame ids appearing in the completion ring are ids that
49-
were previously transmitted using the TX ring. In summary, the RX and
50-
FILL rings are used for the RX path and the TX and COMPLETION rings
51-
are used for the TX path.
36+
The UMEM consists of a number of equally sized chunks. A descriptor in
37+
one of the rings references a frame by referencing its addr. The addr
38+
is simply an offset within the entire UMEM region. The user space
39+
allocates memory for this UMEM using whatever means it feels is most
40+
appropriate (malloc, mmap, huge pages, etc). This memory area is then
41+
registered with the kernel using the new setsockopt XDP_UMEM_REG. The
42+
UMEM also has two rings: the FILL ring and the COMPLETION ring. The
43+
fill ring is used by the application to send down addr for the kernel
44+
to fill in with RX packet data. References to these frames will then
45+
appear in the RX ring once each packet has been received. The
46+
completion ring, on the other hand, contains frame addr that the
47+
kernel has transmitted completely and can now be used again by user
48+
space, for either TX or RX. Thus, the frame addrs appearing in the
49+
completion ring are addrs that were previously transmitted using the
50+
TX ring. In summary, the RX and FILL rings are used for the RX path
51+
and the TX and COMPLETION rings are used for the TX path.
5252

5353
The socket is then finally bound with a bind() call to a device and a
5454
specific queue id on that device, and it is not until bind is
@@ -59,13 +59,13 @@ wants to do this, it simply skips the registration of the UMEM and its
5959
corresponding two rings, sets the XDP_SHARED_UMEM flag in the bind
6060
call and submits the XSK of the process it would like to share UMEM
6161
with as well as its own newly created XSK socket. The new process will
62-
then receive frame id references in its own RX ring that point to this
63-
shared UMEM. Note that since the ring structures are single-consumer /
64-
single-producer (for performance reasons), the new process has to
65-
create its own socket with associated RX and TX rings, since it cannot
66-
share this with the other process. This is also the reason that there
67-
is only one set of FILL and COMPLETION rings per UMEM. It is the
68-
responsibility of a single process to handle the UMEM.
62+
then receive frame addr references in its own RX ring that point to
63+
this shared UMEM. Note that since the ring structures are
64+
single-consumer / single-producer (for performance reasons), the new
65+
process has to create its own socket with associated RX and TX rings,
66+
since it cannot share this with the other process. This is also the
67+
reason that there is only one set of FILL and COMPLETION rings per
68+
UMEM. It is the responsibility of a single process to handle the UMEM.
6969

7070
How is then packets distributed from an XDP program to the XSKs? There
7171
is a BPF map called XSKMAP (or BPF_MAP_TYPE_XSKMAP in full). The
@@ -102,10 +102,10 @@ UMEM
102102

103103
UMEM is a region of virtual contiguous memory, divided into
104104
equal-sized frames. An UMEM is associated to a netdev and a specific
105-
queue id of that netdev. It is created and configured (frame size,
106-
frame headroom, start address and size) by using the XDP_UMEM_REG
107-
setsockopt system call. A UMEM is bound to a netdev and queue id, via
108-
the bind() system call.
105+
queue id of that netdev. It is created and configured (chunk size,
106+
headroom, start address and size) by using the XDP_UMEM_REG setsockopt
107+
system call. A UMEM is bound to a netdev and queue id, via the bind()
108+
system call.
109109

110110
An AF_XDP is socket linked to a single UMEM, but one UMEM can have
111111
multiple AF_XDP sockets. To share an UMEM created via one socket A,
@@ -147,13 +147,17 @@ UMEM Fill Ring
147147
~~~~~~~~~~~~~~
148148

149149
The Fill ring is used to transfer ownership of UMEM frames from
150-
user-space to kernel-space. The UMEM indicies are passed in the
151-
ring. As an example, if the UMEM is 64k and each frame is 4k, then the
152-
UMEM has 16 frames and can pass indicies between 0 and 15.
150+
user-space to kernel-space. The UMEM addrs are passed in the ring. As
151+
an example, if the UMEM is 64k and each chunk is 4k, then the UMEM has
152+
16 chunks and can pass addrs between 0 and 64k.
153153

154154
Frames passed to the kernel are used for the ingress path (RX rings).
155155

156-
The user application produces UMEM indicies to this ring.
156+
The user application produces UMEM addrs to this ring. Note that the
157+
kernel will mask the incoming addr. E.g. for a chunk size of 2k, the
158+
log2(2048) LSB of the addr will be masked off, meaning that 2048, 2050
159+
and 3000 refers to the same chunk.
160+
157161

158162
UMEM Completetion Ring
159163
~~~~~~~~~~~~~~~~~~~~~~
@@ -165,16 +169,15 @@ used.
165169
Frames passed from the kernel to user-space are frames that has been
166170
sent (TX ring) and can be used by user-space again.
167171

168-
The user application consumes UMEM indicies from this ring.
172+
The user application consumes UMEM addrs from this ring.
169173

170174

171175
RX Ring
172176
~~~~~~~
173177

174178
The RX ring is the receiving side of a socket. Each entry in the ring
175-
is a struct xdp_desc descriptor. The descriptor contains UMEM index
176-
(idx), the length of the data (len), the offset into the frame
177-
(offset).
179+
is a struct xdp_desc descriptor. The descriptor contains UMEM offset
180+
(addr) and the length of the data (len).
178181

179182
If no frames have been passed to kernel via the Fill ring, no
180183
descriptors will (or can) appear on the RX ring.
@@ -221,38 +224,50 @@ side is xdpsock_user.c and the XDP side xdpsock_kern.c.
221224

222225
Naive ring dequeue and enqueue could look like this::
223226

227+
// struct xdp_rxtx_ring {
228+
// __u32 *producer;
229+
// __u32 *consumer;
230+
// struct xdp_desc *desc;
231+
// };
232+
233+
// struct xdp_umem_ring {
234+
// __u32 *producer;
235+
// __u32 *consumer;
236+
// __u64 *desc;
237+
// };
238+
224239
// typedef struct xdp_rxtx_ring RING;
225240
// typedef struct xdp_umem_ring RING;
226241

227242
// typedef struct xdp_desc RING_TYPE;
228-
// typedef __u32 RING_TYPE;
243+
// typedef __u64 RING_TYPE;
229244

230245
int dequeue_one(RING *ring, RING_TYPE *item)
231246
{
232-
__u32 entries = ring->ptrs.producer - ring->ptrs.consumer;
247+
__u32 entries = *ring->producer - *ring->consumer;
233248

234249
if (entries == 0)
235250
return -1;
236251

237252
// read-barrier!
238253

239-
*item = ring->desc[ring->ptrs.consumer & (RING_SIZE - 1)];
240-
ring->ptrs.consumer++;
254+
*item = ring->desc[*ring->consumer & (RING_SIZE - 1)];
255+
(*ring->consumer)++;
241256
return 0;
242257
}
243258

244259
int enqueue_one(RING *ring, const RING_TYPE *item)
245260
{
246-
u32 free_entries = RING_SIZE - (ring->ptrs.producer - ring->ptrs.consumer);
261+
u32 free_entries = RING_SIZE - (*ring->producer - *ring->consumer);
247262

248263
if (free_entries == 0)
249264
return -1;
250265

251-
ring->desc[ring->ptrs.producer & (RING_SIZE - 1)] = *item;
266+
ring->desc[*ring->producer & (RING_SIZE - 1)] = *item;
252267

253268
// write-barrier!
254269

255-
ring->ptrs.producer++;
270+
(*ring->producer)++;
256271
return 0;
257272
}
258273

‎MAINTAINERS‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2722,6 +2722,7 @@ L: netdev@vger.kernel.org
27222722
L: linux-kernel@vger.kernel.org
27232723
T: git git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf.git
27242724
T: git git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git
2725+
Q: https://patchwork.ozlabs.org/project/netdev/list/?delegate=77147
27252726
S: Supported
27262727
F: arch/x86/net/bpf_jit*
27272728
F: Documentation/networking/filter.txt
@@ -2740,6 +2741,7 @@ F: net/sched/act_bpf.c
27402741
F: net/sched/cls_bpf.c
27412742
F: samples/bpf/
27422743
F: tools/bpf/
2744+
F: tools/lib/bpf/
27432745
F: tools/testing/selftests/bpf/
27442746

27452747
BROADCOM B44 10/100 ETHERNET DRIVER

‎arch/arm/net/bpf_jit_32.c‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
*
8585
* 1. First argument is passed using the arm 32bit registers and rest of the
8686
* arguments are passed on stack scratch space.
87-
* 2. First callee-saved arugument is mapped to arm 32 bit registers and rest
87+
* 2. First callee-saved argument is mapped to arm 32 bit registers and rest
8888
* arguments are mapped to scratch space on stack.
8989
* 3. We need two 64 bit temp registers to do complex operations on eBPF
9090
* registers.
@@ -701,7 +701,7 @@ static inline void emit_a32_arsh_r64(const u8 dst[], const u8 src[], bool dstk,
701701
}
702702

703703
/* dst = dst >> src */
704-
static inline void emit_a32_lsr_r64(const u8 dst[], const u8 src[], bool dstk,
704+
static inline void emit_a32_rsh_r64(const u8 dst[], const u8 src[], bool dstk,
705705
bool sstk, struct jit_ctx *ctx) {
706706
const u8 *tmp = bpf2a32[TMP_REG_1];
707707
const u8 *tmp2 = bpf2a32[TMP_REG_2];
@@ -717,7 +717,7 @@ static inline void emit_a32_lsr_r64(const u8 dst[], const u8 src[], bool dstk,
717717
emit(ARM_LDR_I(rm, ARM_SP, STACK_VAR(dst_hi)), ctx);
718718
}
719719

720-
/* Do LSH operation */
720+
/* Do RSH operation */
721721
emit(ARM_RSB_I(ARM_IP, rt, 32), ctx);
722722
emit(ARM_SUBS_I(tmp2[0], rt, 32), ctx);
723723
emit(ARM_MOV_SR(ARM_LR, rd, SRTYPE_LSR, rt), ctx);
@@ -767,7 +767,7 @@ static inline void emit_a32_lsh_i64(const u8 dst[], bool dstk,
767767
}
768768

769769
/* dst = dst >> val */
770-
static inline void emit_a32_lsr_i64(const u8 dst[], bool dstk,
770+
static inline void emit_a32_rsh_i64(const u8 dst[], bool dstk,
771771
const u32 val, struct jit_ctx *ctx) {
772772
const u8 *tmp = bpf2a32[TMP_REG_1];
773773
const u8 *tmp2 = bpf2a32[TMP_REG_2];
@@ -1192,8 +1192,8 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx)
11921192
s32 jmp_offset;
11931193

11941194
#define check_imm(bits, imm) do { \
1195-
if ((((imm) > 0) && ((imm) >> (bits))) || \
1196-
(((imm) < 0) && (~(imm) >> (bits)))) { \
1195+
if ((imm) >= (1 << ((bits) - 1)) || \
1196+
(imm) < -(1 << ((bits) - 1))) { \
11971197
pr_info("[%2d] imm=%d(0x%x) out of range\n", \
11981198
i, imm, imm); \
11991199
return -EINVAL; \
@@ -1323,15 +1323,15 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx)
13231323
case BPF_ALU64 | BPF_RSH | BPF_K:
13241324
if (unlikely(imm > 63))
13251325
return -EINVAL;
1326-
emit_a32_lsr_i64(dst, dstk, imm, ctx);
1326+
emit_a32_rsh_i64(dst, dstk, imm, ctx);
13271327
break;
13281328
/* dst = dst << src */
13291329
case BPF_ALU64 | BPF_LSH | BPF_X:
13301330
emit_a32_lsh_r64(dst, src, dstk, sstk, ctx);
13311331
break;
13321332
/* dst = dst >> src */
13331333
case BPF_ALU64 | BPF_RSH | BPF_X:
1334-
emit_a32_lsr_r64(dst, src, dstk, sstk, ctx);
1334+
emit_a32_rsh_r64(dst, src, dstk, sstk, ctx);
13351335
break;
13361336
/* dst = dst >> src (signed) */
13371337
case BPF_ALU64 | BPF_ARSH | BPF_X:

‎drivers/media/rc/Kconfig‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,19 @@ config LIRC
2525
passes raw IR to and from userspace, which is needed for
2626
IR transmitting (aka "blasting") and for the lirc daemon.
2727

28+
config BPF_LIRC_MODE2
29+
bool "Support for eBPF programs attached to lirc devices"
30+
depends on BPF_SYSCALL
31+
depends on RC_CORE=y
32+
depends on LIRC
33+
help
34+
Allow attaching eBPF programs to a lirc device using the bpf(2)
35+
syscall command BPF_PROG_ATTACH. This is supported for raw IR
36+
receivers.
37+
38+
These eBPF programs can be used to decode IR into scancodes, for
39+
IR protocols not supported by the kernel decoders.
40+
2841
menuconfig RC_DECODERS
2942
bool "Remote controller decoders"
3043
depends on RC_CORE

‎drivers/media/rc/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ obj-y += keymaps/
55
obj-$(CONFIG_RC_CORE) += rc-core.o
66
rc-core-y := rc-main.o rc-ir-raw.o
77
rc-core-$(CONFIG_LIRC) += lirc_dev.o
8+
rc-core-$(CONFIG_BPF_LIRC_MODE2) += bpf-lirc.o
89
obj-$(CONFIG_IR_NEC_DECODER) += ir-nec-decoder.o
910
obj-$(CONFIG_IR_RC5_DECODER) += ir-rc5-decoder.o
1011
obj-$(CONFIG_IR_RC6_DECODER) += ir-rc6-decoder.o

0 commit comments

Comments
 (0)