Skip to content

Commit 07dd1b7

Browse files
committed
Merge git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next
Alexei Starovoitov says: ==================== pull-request: bpf-next 2020-07-13 The following pull-request contains BPF updates for your *net-next* tree. We've added 36 non-merge commits during the last 7 day(s) which contain a total of 62 files changed, 2242 insertions(+), 468 deletions(-). The main changes are: 1) Avoid trace_printk warning banner by switching bpf_trace_printk to use its own tracing event, from Alan. 2) Better libbpf support on older kernels, from Andrii. 3) Additional AF_XDP stats, from Ciara. 4) build time resolution of BTF IDs, from Jiri. 5) BPF_CGROUP_INET_SOCK_RELEASE hook, from Stanislav. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents bfe4c40 + 8afb259 commit 07dd1b7

62 files changed

Lines changed: 2242 additions & 468 deletions

Some content is hidden

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

‎Documentation/bpf/btf.rst‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,42 @@ kernel API, the ``insn_off`` is the instruction offset in the unit of ``struct
691691
bpf_insn``. For ELF API, the ``insn_off`` is the byte offset from the
692692
beginning of section (``btf_ext_info_sec->sec_name_off``).
693693

694+
4.2 .BTF_ids section
695+
====================
696+
697+
The .BTF_ids section encodes BTF ID values that are used within the kernel.
698+
699+
This section is created during the kernel compilation with the help of
700+
macros defined in ``include/linux/btf_ids.h`` header file. Kernel code can
701+
use them to create lists and sets (sorted lists) of BTF ID values.
702+
703+
The ``BTF_ID_LIST`` and ``BTF_ID`` macros define unsorted list of BTF ID values,
704+
with following syntax::
705+
706+
BTF_ID_LIST(list)
707+
BTF_ID(type1, name1)
708+
BTF_ID(type2, name2)
709+
710+
resulting in following layout in .BTF_ids section::
711+
712+
__BTF_ID__type1__name1__1:
713+
.zero 4
714+
__BTF_ID__type2__name2__2:
715+
.zero 4
716+
717+
The ``u32 list[];`` variable is defined to access the list.
718+
719+
The ``BTF_ID_UNUSED`` macro defines 4 zero bytes. It's used when we
720+
want to define unused entry in BTF_ID_LIST, like::
721+
722+
BTF_ID_LIST(bpf_skb_output_btf_ids)
723+
BTF_ID(struct, sk_buff)
724+
BTF_ID_UNUSED
725+
BTF_ID(struct, task_struct)
726+
727+
All the BTF ID lists and sets are compiled in the .BTF_ids section and
728+
resolved during the linking phase of kernel build by ``resolve_btfids`` tool.
729+
694730
5. Using BTF
695731
************
696732

‎Makefile‎

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,7 @@ OBJSIZE = $(CROSS_COMPILE)size
448448
STRIP = $(CROSS_COMPILE)strip
449449
endif
450450
PAHOLE = pahole
451+
RESOLVE_BTFIDS = $(objtree)/tools/bpf/resolve_btfids/resolve_btfids
451452
LEX = flex
452453
YACC = bison
453454
AWK = awk
@@ -510,7 +511,7 @@ GCC_PLUGINS_CFLAGS :=
510511
CLANG_FLAGS :=
511512

512513
export ARCH SRCARCH CONFIG_SHELL BASH HOSTCC KBUILD_HOSTCFLAGS CROSS_COMPILE LD CC
513-
export CPP AR NM STRIP OBJCOPY OBJDUMP OBJSIZE READELF PAHOLE LEX YACC AWK INSTALLKERNEL
514+
export CPP AR NM STRIP OBJCOPY OBJDUMP OBJSIZE READELF PAHOLE RESOLVE_BTFIDS LEX YACC AWK INSTALLKERNEL
514515
export PERL PYTHON PYTHON3 CHECK CHECKFLAGS MAKE UTS_MACHINE HOSTCXX
515516
export KGZIP KBZIP2 KLZOP LZMA LZ4 XZ
516517
export KBUILD_HOSTCXXFLAGS KBUILD_HOSTLDFLAGS KBUILD_HOSTLDLIBS LDFLAGS_MODULE
@@ -1053,9 +1054,10 @@ export mod_sign_cmd
10531054

10541055
HOST_LIBELF_LIBS = $(shell pkg-config libelf --libs 2>/dev/null || echo -lelf)
10551056

1057+
has_libelf = $(call try-run,\
1058+
echo "int main() {}" | $(HOSTCC) -xc -o /dev/null $(HOST_LIBELF_LIBS) -,1,0)
1059+
10561060
ifdef CONFIG_STACK_VALIDATION
1057-
has_libelf := $(call try-run,\
1058-
echo "int main() {}" | $(HOSTCC) -xc -o /dev/null $(HOST_LIBELF_LIBS) -,1,0)
10591061
ifeq ($(has_libelf),1)
10601062
objtool_target := tools/objtool FORCE
10611063
else
@@ -1064,6 +1066,14 @@ ifdef CONFIG_STACK_VALIDATION
10641066
endif
10651067
endif
10661068

1069+
ifdef CONFIG_DEBUG_INFO_BTF
1070+
ifeq ($(has_libelf),1)
1071+
resolve_btfids_target := tools/bpf/resolve_btfids FORCE
1072+
else
1073+
ERROR_RESOLVE_BTFIDS := 1
1074+
endif
1075+
endif
1076+
10671077
PHONY += prepare0
10681078

10691079
export MODORDER := $(extmod-prefix)modules.order
@@ -1175,7 +1185,7 @@ prepare0: archprepare
11751185
$(Q)$(MAKE) $(build)=.
11761186

11771187
# All the preparing..
1178-
prepare: prepare0 prepare-objtool
1188+
prepare: prepare0 prepare-objtool prepare-resolve_btfids
11791189

11801190
# Support for using generic headers in asm-generic
11811191
asm-generic := -f $(srctree)/scripts/Makefile.asm-generic obj
@@ -1188,7 +1198,7 @@ uapi-asm-generic:
11881198
$(Q)$(MAKE) $(asm-generic)=arch/$(SRCARCH)/include/generated/uapi/asm \
11891199
generic=include/uapi/asm-generic
11901200

1191-
PHONY += prepare-objtool
1201+
PHONY += prepare-objtool prepare-resolve_btfids
11921202
prepare-objtool: $(objtool_target)
11931203
ifeq ($(SKIP_STACK_VALIDATION),1)
11941204
ifdef CONFIG_UNWINDER_ORC
@@ -1199,6 +1209,11 @@ else
11991209
endif
12001210
endif
12011211

1212+
prepare-resolve_btfids: $(resolve_btfids_target)
1213+
ifeq ($(ERROR_RESOLVE_BTFIDS),1)
1214+
@echo "error: Cannot resolve BTF IDs for CONFIG_DEBUG_INFO_BTF, please install libelf-dev, libelf-devel or elfutils-libelf-devel" >&2
1215+
@false
1216+
endif
12021217
# Generate some files
12031218
# ---------------------------------------------------------------------------
12041219

‎include/asm-generic/vmlinux.lds.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,10 @@
641641
__start_BTF = .; \
642642
*(.BTF) \
643643
__stop_BTF = .; \
644+
} \
645+
. = ALIGN(4); \
646+
.BTF_ids : AT(ADDR(.BTF_ids) - LOAD_OFFSET) { \
647+
*(.BTF_ids) \
644648
}
645649
#else
646650
#define BTF

‎include/linux/bpf-cgroup.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,9 @@ int bpf_percpu_cgroup_storage_update(struct bpf_map *map, void *key,
210210
#define BPF_CGROUP_RUN_PROG_INET_SOCK(sk) \
211211
BPF_CGROUP_RUN_SK_PROG(sk, BPF_CGROUP_INET_SOCK_CREATE)
212212

213+
#define BPF_CGROUP_RUN_PROG_INET_SOCK_RELEASE(sk) \
214+
BPF_CGROUP_RUN_SK_PROG(sk, BPF_CGROUP_INET_SOCK_RELEASE)
215+
213216
#define BPF_CGROUP_RUN_PROG_INET4_POST_BIND(sk) \
214217
BPF_CGROUP_RUN_SK_PROG(sk, BPF_CGROUP_INET4_POST_BIND)
215218

@@ -401,6 +404,7 @@ static inline int bpf_percpu_cgroup_storage_update(struct bpf_map *map,
401404
#define BPF_CGROUP_RUN_PROG_INET_INGRESS(sk,skb) ({ 0; })
402405
#define BPF_CGROUP_RUN_PROG_INET_EGRESS(sk,skb) ({ 0; })
403406
#define BPF_CGROUP_RUN_PROG_INET_SOCK(sk) ({ 0; })
407+
#define BPF_CGROUP_RUN_PROG_INET_SOCK_RELEASE(sk) ({ 0; })
404408
#define BPF_CGROUP_RUN_PROG_INET4_BIND(sk, uaddr) ({ 0; })
405409
#define BPF_CGROUP_RUN_PROG_INET6_BIND(sk, uaddr) ({ 0; })
406410
#define BPF_CGROUP_RUN_PROG_INET4_POST_BIND(sk) ({ 0; })

‎include/linux/btf_ids.h‎

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
3+
#ifndef _LINUX_BTF_IDS_H
4+
#define _LINUX_BTF_IDS_H
5+
6+
#include <linux/compiler.h> /* for __PASTE */
7+
8+
/*
9+
* Following macros help to define lists of BTF IDs placed
10+
* in .BTF_ids section. They are initially filled with zeros
11+
* (during compilation) and resolved later during the
12+
* linking phase by resolve_btfids tool.
13+
*
14+
* Any change in list layout must be reflected in resolve_btfids
15+
* tool logic.
16+
*/
17+
18+
#define BTF_IDS_SECTION ".BTF_ids"
19+
20+
#define ____BTF_ID(symbol) \
21+
asm( \
22+
".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \
23+
".local " #symbol " ; \n" \
24+
".type " #symbol ", @object; \n" \
25+
".size " #symbol ", 4; \n" \
26+
#symbol ": \n" \
27+
".zero 4 \n" \
28+
".popsection; \n");
29+
30+
#define __BTF_ID(symbol) \
31+
____BTF_ID(symbol)
32+
33+
#define __ID(prefix) \
34+
__PASTE(prefix, __COUNTER__)
35+
36+
/*
37+
* The BTF_ID defines unique symbol for each ID pointing
38+
* to 4 zero bytes.
39+
*/
40+
#define BTF_ID(prefix, name) \
41+
__BTF_ID(__ID(__BTF_ID__##prefix##__##name##__))
42+
43+
/*
44+
* The BTF_ID_LIST macro defines pure (unsorted) list
45+
* of BTF IDs, with following layout:
46+
*
47+
* BTF_ID_LIST(list1)
48+
* BTF_ID(type1, name1)
49+
* BTF_ID(type2, name2)
50+
*
51+
* list1:
52+
* __BTF_ID__type1__name1__1:
53+
* .zero 4
54+
* __BTF_ID__type2__name2__2:
55+
* .zero 4
56+
*
57+
*/
58+
#define __BTF_ID_LIST(name) \
59+
asm( \
60+
".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \
61+
".local " #name "; \n" \
62+
#name ":; \n" \
63+
".popsection; \n"); \
64+
65+
#define BTF_ID_LIST(name) \
66+
__BTF_ID_LIST(name) \
67+
extern u32 name[];
68+
69+
/*
70+
* The BTF_ID_UNUSED macro defines 4 zero bytes.
71+
* It's used when we want to define 'unused' entry
72+
* in BTF_ID_LIST, like:
73+
*
74+
* BTF_ID_LIST(bpf_skb_output_btf_ids)
75+
* BTF_ID(struct, sk_buff)
76+
* BTF_ID_UNUSED
77+
* BTF_ID(struct, task_struct)
78+
*/
79+
80+
#define BTF_ID_UNUSED \
81+
asm( \
82+
".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \
83+
".zero 4 \n" \
84+
".popsection; \n");
85+
86+
87+
#endif

‎include/net/xdp_sock.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,11 @@ struct xdp_sock {
6969
spinlock_t tx_completion_lock;
7070
/* Protects generic receive. */
7171
spinlock_t rx_lock;
72+
73+
/* Statistics */
7274
u64 rx_dropped;
75+
u64 rx_queue_full;
76+
7377
struct list_head map_list;
7478
/* Protects map_list */
7579
spinlock_t map_list_lock;

‎include/uapi/linux/bpf.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ enum bpf_attach_type {
226226
BPF_CGROUP_INET4_GETSOCKNAME,
227227
BPF_CGROUP_INET6_GETSOCKNAME,
228228
BPF_XDP_DEVMAP,
229+
BPF_CGROUP_INET_SOCK_RELEASE,
229230
__MAX_BPF_ATTACH_TYPE
230231
};
231232

‎include/uapi/linux/if_xdp.h‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,12 @@ struct xdp_umem_reg {
7373
};
7474

7575
struct xdp_statistics {
76-
__u64 rx_dropped; /* Dropped for reasons other than invalid desc */
76+
__u64 rx_dropped; /* Dropped for other reasons */
7777
__u64 rx_invalid_descs; /* Dropped due to invalid descriptor */
7878
__u64 tx_invalid_descs; /* Dropped due to invalid descriptor */
79+
__u64 rx_ring_full; /* Dropped due to rx ring being full */
80+
__u64 rx_fill_ring_empty_descs; /* Failed to retrieve item from fill ring */
81+
__u64 tx_ring_empty_descs; /* Failed to retrieve item from tx ring */
7982
};
8083

8184
struct xdp_options {

‎include/uapi/linux/xdp_diag.h‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ struct xdp_diag_msg {
3030
#define XDP_SHOW_RING_CFG (1 << 1)
3131
#define XDP_SHOW_UMEM (1 << 2)
3232
#define XDP_SHOW_MEMINFO (1 << 3)
33+
#define XDP_SHOW_STATS (1 << 4)
3334

3435
enum {
3536
XDP_DIAG_NONE,
@@ -41,6 +42,7 @@ enum {
4142
XDP_DIAG_UMEM_FILL_RING,
4243
XDP_DIAG_UMEM_COMPLETION_RING,
4344
XDP_DIAG_MEMINFO,
45+
XDP_DIAG_STATS,
4446
__XDP_DIAG_MAX,
4547
};
4648

@@ -69,4 +71,13 @@ struct xdp_diag_umem {
6971
__u32 refs;
7072
};
7173

74+
struct xdp_diag_stats {
75+
__u64 n_rx_dropped;
76+
__u64 n_rx_invalid;
77+
__u64 n_rx_full;
78+
__u64 n_fill_ring_empty;
79+
__u64 n_tx_invalid;
80+
__u64 n_tx_ring_empty;
81+
};
82+
7283
#endif /* _LINUX_XDP_DIAG_H */

0 commit comments

Comments
 (0)