Skip to content

Commit 0076cad

Browse files
committed
Daniel Borkmann says: ==================== pull-request: bpf-next 2022-07-09 We've added 94 non-merge commits during the last 19 day(s) which contain a total of 125 files changed, 5141 insertions(+), 6701 deletions(-). The main changes are: 1) Add new way for performing BTF type queries to BPF, from Daniel Müller. 2) Add inlining of calls to bpf_loop() helper when its function callback is statically known, from Eduard Zingerman. 3) Implement BPF TCP CC framework usability improvements, from Jörn-Thorben Hinz. 4) Add LSM flavor for attaching per-cgroup BPF programs to existing LSM hooks, from Stanislav Fomichev. 5) Remove all deprecated libbpf APIs in prep for 1.0 release, from Andrii Nakryiko. 6) Add benchmarks around local_storage to BPF selftests, from Dave Marchevsky. 7) AF_XDP sample removal (given move to libxdp) and various improvements around AF_XDP selftests, from Magnus Karlsson & Maciej Fijalkowski. 8) Add bpftool improvements for memcg probing and bash completion, from Quentin Monnet. 9) Add arm64 JIT support for BPF-2-BPF coupled with tail calls, from Jakub Sitnicki. 10) Sockmap optimizations around throughput of UDP transmissions which have been improved by 61%, from Cong Wang. 11) Rework perf's BPF prologue code to remove deprecated functions, from Jiri Olsa. 12) Fix sockmap teardown path to avoid sleepable sk_psock_stop, from John Fastabend. 13) Fix libbpf's cleanup around legacy kprobe/uprobe on error case, from Chuang Wang. 14) Fix libbpf's bpf_helpers.h to work with gcc for the case of its sec/pragma macro, from James Hilliard. 15) Fix libbpf's pt_regs macros for riscv to use a0 for RC register, from Yixun Lan. 16) Fix bpftool to show the name of type BPF_OBJ_LINK, from Yafang Shao. * https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next: (94 commits) selftests/bpf: Fix xdp_synproxy build failure if CONFIG_NF_CONNTRACK=m/n bpf: Correctly propagate errors up from bpf_core_composites_match libbpf: Disable SEC pragma macro on GCC bpf: Check attach_func_proto more carefully in check_return_code selftests/bpf: Add test involving restrict type qualifier bpftool: Add support for KIND_RESTRICT to gen min_core_btf command MAINTAINERS: Add entry for AF_XDP selftests files selftests, xsk: Rename AF_XDP testing app bpf, docs: Remove deprecated xsk libbpf APIs description selftests/bpf: Add benchmark for local_storage RCU Tasks Trace usage libbpf, riscv: Use a0 for RC register libbpf: Remove unnecessary usdt_rel_ip assignments selftests/bpf: Fix few more compiler warnings selftests/bpf: Fix bogus uninitialized variable warning bpftool: Remove zlib feature test from Makefile libbpf: Cleanup the legacy uprobe_event on failed add/attach_event() libbpf: Fix wrong variable used in perf_event_uprobe_open_legacy() libbpf: Cleanup the legacy kprobe_event on failed add/attach_event() selftests/bpf: Add type match test against kernel's task_struct selftests/bpf: Add nested type to type based tests ... ==================== Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents 877d4e3 + 24bdfdd commit 0076cad

File tree

125 files changed

+5141
-6701
lines changed

Some content is hidden

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

125 files changed

+5141
-6701
lines changed

Documentation/bpf/instruction-set.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ These instructions have seven implicit operands:
351351
* Register R0 is an implicit output which contains the data fetched from
352352
the packet.
353353
* Registers R1-R5 are scratch registers that are clobbered after a call to
354-
``BPF_ABS | BPF_LD`` or ``BPF_IND`` | BPF_LD instructions.
354+
``BPF_ABS | BPF_LD`` or ``BPF_IND | BPF_LD`` instructions.
355355

356356
These instructions have an implicit program exit condition as well. When an
357357
eBPF program is trying to access the data beyond the packet boundary, the

Documentation/bpf/libbpf/libbpf_naming_convention.rst

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ described here. It's recommended to follow these conventions whenever a
99
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
12-
following prefixes: ``bpf_``, ``btf_``, ``libbpf_``, ``xsk_``,
13-
``btf_dump_``, ``ring_buffer_``, ``perf_buffer_``.
12+
following prefixes: ``bpf_``, ``btf_``, ``libbpf_``, ``btf_dump_``,
13+
``ring_buffer_``, ``perf_buffer_``.
1414

1515
System call wrappers
1616
--------------------
@@ -59,15 +59,6 @@ Auxiliary functions and types that don't fit well in any of categories
5959
described above should have ``libbpf_`` prefix, e.g.
6060
``libbpf_get_error`` or ``libbpf_prog_type_by_name``.
6161

62-
AF_XDP functions
63-
-------------------
64-
65-
AF_XDP functions should have an ``xsk_`` prefix, e.g.
66-
``xsk_umem__get_data`` or ``xsk_umem__create``. The interface consists
67-
of both low-level ring access functions and high-level configuration
68-
functions. These can be mixed and matched. Note that these functions
69-
are not reentrant for performance reasons.
70-
7162
ABI
7263
---
7364

MAINTAINERS

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21917,8 +21917,7 @@ F: include/uapi/linux/if_xdp.h
2191721917
F: include/uapi/linux/xdp_diag.h
2191821918
F: include/net/netns/xdp.h
2191921919
F: net/xdp/
21920-
F: samples/bpf/xdpsock*
21921-
F: tools/lib/bpf/xsk*
21920+
F: tools/testing/selftests/bpf/*xsk*
2192221921

2192321922
XEN BLOCK SUBSYSTEM
2192421923
M: Roger Pau Monné <[email protected]>

arch/arm64/net/bpf_jit_comp.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ static bool is_lsi_offset(int offset, int scale)
246246
static int build_prologue(struct jit_ctx *ctx, bool ebpf_from_cbpf)
247247
{
248248
const struct bpf_prog *prog = ctx->prog;
249+
const bool is_main_prog = prog->aux->func_idx == 0;
249250
const u8 r6 = bpf2a64[BPF_REG_6];
250251
const u8 r7 = bpf2a64[BPF_REG_7];
251252
const u8 r8 = bpf2a64[BPF_REG_8];
@@ -299,7 +300,7 @@ static int build_prologue(struct jit_ctx *ctx, bool ebpf_from_cbpf)
299300
/* Set up BPF prog stack base register */
300301
emit(A64_MOV(1, fp, A64_SP), ctx);
301302

302-
if (!ebpf_from_cbpf) {
303+
if (!ebpf_from_cbpf && is_main_prog) {
303304
/* Initialize tail_call_cnt */
304305
emit(A64_MOVZ(1, tcc, 0, 0), ctx);
305306

@@ -1530,3 +1531,9 @@ void bpf_jit_free_exec(void *addr)
15301531
{
15311532
return vfree(addr);
15321533
}
1534+
1535+
/* Indicate the JIT backend supports mixing bpf2bpf and tailcalls. */
1536+
bool bpf_jit_supports_subprog_tailcalls(void)
1537+
{
1538+
return true;
1539+
}

arch/x86/net/bpf_jit_comp.c

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1771,6 +1771,10 @@ static int invoke_bpf_prog(const struct btf_func_model *m, u8 **pprog,
17711771
struct bpf_tramp_link *l, int stack_size,
17721772
int run_ctx_off, bool save_ret)
17731773
{
1774+
void (*exit)(struct bpf_prog *prog, u64 start,
1775+
struct bpf_tramp_run_ctx *run_ctx) = __bpf_prog_exit;
1776+
u64 (*enter)(struct bpf_prog *prog,
1777+
struct bpf_tramp_run_ctx *run_ctx) = __bpf_prog_enter;
17741778
u8 *prog = *pprog;
17751779
u8 *jmp_insn;
17761780
int ctx_cookie_off = offsetof(struct bpf_tramp_run_ctx, bpf_cookie);
@@ -1789,15 +1793,21 @@ static int invoke_bpf_prog(const struct btf_func_model *m, u8 **pprog,
17891793
*/
17901794
emit_stx(&prog, BPF_DW, BPF_REG_FP, BPF_REG_1, -run_ctx_off + ctx_cookie_off);
17911795

1796+
if (p->aux->sleepable) {
1797+
enter = __bpf_prog_enter_sleepable;
1798+
exit = __bpf_prog_exit_sleepable;
1799+
} else if (p->expected_attach_type == BPF_LSM_CGROUP) {
1800+
enter = __bpf_prog_enter_lsm_cgroup;
1801+
exit = __bpf_prog_exit_lsm_cgroup;
1802+
}
1803+
17921804
/* arg1: mov rdi, progs[i] */
17931805
emit_mov_imm64(&prog, BPF_REG_1, (long) p >> 32, (u32) (long) p);
17941806
/* arg2: lea rsi, [rbp - ctx_cookie_off] */
17951807
EMIT4(0x48, 0x8D, 0x75, -run_ctx_off);
17961808

1797-
if (emit_call(&prog,
1798-
p->aux->sleepable ? __bpf_prog_enter_sleepable :
1799-
__bpf_prog_enter, prog))
1800-
return -EINVAL;
1809+
if (emit_call(&prog, enter, prog))
1810+
return -EINVAL;
18011811
/* remember prog start time returned by __bpf_prog_enter */
18021812
emit_mov_reg(&prog, true, BPF_REG_6, BPF_REG_0);
18031813

@@ -1841,10 +1851,8 @@ static int invoke_bpf_prog(const struct btf_func_model *m, u8 **pprog,
18411851
emit_mov_reg(&prog, true, BPF_REG_2, BPF_REG_6);
18421852
/* arg3: lea rdx, [rbp - run_ctx_off] */
18431853
EMIT4(0x48, 0x8D, 0x55, -run_ctx_off);
1844-
if (emit_call(&prog,
1845-
p->aux->sleepable ? __bpf_prog_exit_sleepable :
1846-
__bpf_prog_exit, prog))
1847-
return -EINVAL;
1854+
if (emit_call(&prog, exit, prog))
1855+
return -EINVAL;
18481856

18491857
*pprog = prog;
18501858
return 0;
@@ -2492,3 +2500,9 @@ void *bpf_arch_text_copy(void *dst, void *src, size_t len)
24922500
return ERR_PTR(-EINVAL);
24932501
return dst;
24942502
}
2503+
2504+
/* Indicate the JIT backend supports mixing bpf2bpf and tailcalls. */
2505+
bool bpf_jit_supports_subprog_tailcalls(void)
2506+
{
2507+
return true;
2508+
}

include/linux/bpf-cgroup-defs.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@
1010

1111
struct bpf_prog_array;
1212

13+
#ifdef CONFIG_BPF_LSM
14+
/* Maximum number of concurrently attachable per-cgroup LSM hooks. */
15+
#define CGROUP_LSM_NUM 10
16+
#else
17+
#define CGROUP_LSM_NUM 0
18+
#endif
19+
1320
enum cgroup_bpf_attach_type {
1421
CGROUP_BPF_ATTACH_TYPE_INVALID = -1,
1522
CGROUP_INET_INGRESS = 0,
@@ -35,6 +42,8 @@ enum cgroup_bpf_attach_type {
3542
CGROUP_INET4_GETSOCKNAME,
3643
CGROUP_INET6_GETSOCKNAME,
3744
CGROUP_INET_SOCK_RELEASE,
45+
CGROUP_LSM_START,
46+
CGROUP_LSM_END = CGROUP_LSM_START + CGROUP_LSM_NUM - 1,
3847
MAX_CGROUP_BPF_ATTACH_TYPE
3948
};
4049

@@ -47,8 +56,8 @@ struct cgroup_bpf {
4756
* have either zero or one element
4857
* when BPF_F_ALLOW_MULTI the list can have up to BPF_CGROUP_MAX_PROGS
4958
*/
50-
struct list_head progs[MAX_CGROUP_BPF_ATTACH_TYPE];
51-
u32 flags[MAX_CGROUP_BPF_ATTACH_TYPE];
59+
struct hlist_head progs[MAX_CGROUP_BPF_ATTACH_TYPE];
60+
u8 flags[MAX_CGROUP_BPF_ATTACH_TYPE];
5261

5362
/* list of cgroup shared storages */
5463
struct list_head storages;

include/linux/bpf-cgroup.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ struct ctl_table;
2323
struct ctl_table_header;
2424
struct task_struct;
2525

26+
unsigned int __cgroup_bpf_run_lsm_sock(const void *ctx,
27+
const struct bpf_insn *insn);
28+
unsigned int __cgroup_bpf_run_lsm_socket(const void *ctx,
29+
const struct bpf_insn *insn);
30+
unsigned int __cgroup_bpf_run_lsm_current(const void *ctx,
31+
const struct bpf_insn *insn);
32+
2633
#ifdef CONFIG_CGROUP_BPF
2734

2835
#define CGROUP_ATYPE(type) \
@@ -95,7 +102,7 @@ struct bpf_cgroup_link {
95102
};
96103

97104
struct bpf_prog_list {
98-
struct list_head node;
105+
struct hlist_node node;
99106
struct bpf_prog *prog;
100107
struct bpf_cgroup_link *link;
101108
struct bpf_cgroup_storage *storage[MAX_BPF_CGROUP_STORAGE_TYPE];

include/linux/bpf.h

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ typedef u64 (*bpf_callback_t)(u64, u64, u64, u64, u64);
5656
typedef int (*bpf_iter_init_seq_priv_t)(void *private_data,
5757
struct bpf_iter_aux_info *aux);
5858
typedef void (*bpf_iter_fini_seq_priv_t)(void *private_data);
59+
typedef unsigned int (*bpf_func_t)(const void *,
60+
const struct bpf_insn *);
5961
struct bpf_iter_seq_info {
6062
const struct seq_operations *seq_ops;
6163
bpf_iter_init_seq_priv_t init_seq_private;
@@ -792,6 +794,10 @@ void notrace __bpf_prog_exit(struct bpf_prog *prog, u64 start, struct bpf_tramp_
792794
u64 notrace __bpf_prog_enter_sleepable(struct bpf_prog *prog, struct bpf_tramp_run_ctx *run_ctx);
793795
void notrace __bpf_prog_exit_sleepable(struct bpf_prog *prog, u64 start,
794796
struct bpf_tramp_run_ctx *run_ctx);
797+
u64 notrace __bpf_prog_enter_lsm_cgroup(struct bpf_prog *prog,
798+
struct bpf_tramp_run_ctx *run_ctx);
799+
void notrace __bpf_prog_exit_lsm_cgroup(struct bpf_prog *prog, u64 start,
800+
struct bpf_tramp_run_ctx *run_ctx);
795801
void notrace __bpf_tramp_enter(struct bpf_tramp_image *tr);
796802
void notrace __bpf_tramp_exit(struct bpf_tramp_image *tr);
797803

@@ -879,8 +885,7 @@ struct bpf_dispatcher {
879885
static __always_inline __nocfi unsigned int bpf_dispatcher_nop_func(
880886
const void *ctx,
881887
const struct bpf_insn *insnsi,
882-
unsigned int (*bpf_func)(const void *,
883-
const struct bpf_insn *))
888+
bpf_func_t bpf_func)
884889
{
885890
return bpf_func(ctx, insnsi);
886891
}
@@ -909,8 +914,7 @@ int arch_prepare_bpf_dispatcher(void *image, s64 *funcs, int num_funcs);
909914
noinline __nocfi unsigned int bpf_dispatcher_##name##_func( \
910915
const void *ctx, \
911916
const struct bpf_insn *insnsi, \
912-
unsigned int (*bpf_func)(const void *, \
913-
const struct bpf_insn *)) \
917+
bpf_func_t bpf_func) \
914918
{ \
915919
return bpf_func(ctx, insnsi); \
916920
} \
@@ -921,8 +925,7 @@ int arch_prepare_bpf_dispatcher(void *image, s64 *funcs, int num_funcs);
921925
unsigned int bpf_dispatcher_##name##_func( \
922926
const void *ctx, \
923927
const struct bpf_insn *insnsi, \
924-
unsigned int (*bpf_func)(const void *, \
925-
const struct bpf_insn *)); \
928+
bpf_func_t bpf_func); \
926929
extern struct bpf_dispatcher bpf_dispatcher_##name;
927930
#define BPF_DISPATCHER_FUNC(name) bpf_dispatcher_##name##_func
928931
#define BPF_DISPATCHER_PTR(name) (&bpf_dispatcher_##name)
@@ -1061,6 +1064,7 @@ struct bpf_prog_aux {
10611064
struct user_struct *user;
10621065
u64 load_time; /* ns since boottime */
10631066
u32 verified_insns;
1067+
int cgroup_atype; /* enum cgroup_bpf_attach_type */
10641068
struct bpf_map *cgroup_storage[MAX_BPF_CGROUP_STORAGE_TYPE];
10651069
char name[BPF_OBJ_NAME_LEN];
10661070
#ifdef CONFIG_SECURITY
@@ -1168,6 +1172,11 @@ struct bpf_tramp_link {
11681172
u64 cookie;
11691173
};
11701174

1175+
struct bpf_shim_tramp_link {
1176+
struct bpf_tramp_link link;
1177+
struct bpf_trampoline *trampoline;
1178+
};
1179+
11711180
struct bpf_tracing_link {
11721181
struct bpf_tramp_link link;
11731182
enum bpf_attach_type attach_type;
@@ -1246,6 +1255,9 @@ struct bpf_dummy_ops {
12461255
int bpf_struct_ops_test_run(struct bpf_prog *prog, const union bpf_attr *kattr,
12471256
union bpf_attr __user *uattr);
12481257
#endif
1258+
int bpf_trampoline_link_cgroup_shim(struct bpf_prog *prog,
1259+
int cgroup_atype);
1260+
void bpf_trampoline_unlink_cgroup_shim(struct bpf_prog *prog);
12491261
#else
12501262
static inline const struct bpf_struct_ops *bpf_struct_ops_find(u32 type_id)
12511263
{
@@ -1269,6 +1281,14 @@ static inline int bpf_struct_ops_map_sys_lookup_elem(struct bpf_map *map,
12691281
{
12701282
return -EINVAL;
12711283
}
1284+
static inline int bpf_trampoline_link_cgroup_shim(struct bpf_prog *prog,
1285+
int cgroup_atype)
1286+
{
1287+
return -EOPNOTSUPP;
1288+
}
1289+
static inline void bpf_trampoline_unlink_cgroup_shim(struct bpf_prog *prog)
1290+
{
1291+
}
12721292
#endif
12731293

12741294
struct bpf_array {
@@ -1286,6 +1306,9 @@ struct bpf_array {
12861306
#define BPF_COMPLEXITY_LIMIT_INSNS 1000000 /* yes. 1M insns */
12871307
#define MAX_TAIL_CALL_CNT 33
12881308

1309+
/* Maximum number of loops for bpf_loop */
1310+
#define BPF_MAX_LOOPS BIT(23)
1311+
12891312
#define BPF_F_ACCESS_MASK (BPF_F_RDONLY | \
12901313
BPF_F_RDONLY_PROG | \
12911314
BPF_F_WRONLY | \
@@ -2363,9 +2386,13 @@ extern const struct bpf_func_proto bpf_for_each_map_elem_proto;
23632386
extern const struct bpf_func_proto bpf_btf_find_by_name_kind_proto;
23642387
extern const struct bpf_func_proto bpf_sk_setsockopt_proto;
23652388
extern const struct bpf_func_proto bpf_sk_getsockopt_proto;
2389+
extern const struct bpf_func_proto bpf_unlocked_sk_setsockopt_proto;
2390+
extern const struct bpf_func_proto bpf_unlocked_sk_getsockopt_proto;
23662391
extern const struct bpf_func_proto bpf_find_vma_proto;
23672392
extern const struct bpf_func_proto bpf_loop_proto;
23682393
extern const struct bpf_func_proto bpf_copy_from_user_task_proto;
2394+
extern const struct bpf_func_proto bpf_set_retval_proto;
2395+
extern const struct bpf_func_proto bpf_get_retval_proto;
23692396

23702397
const struct bpf_func_proto *tracing_prog_func_proto(
23712398
enum bpf_func_id func_id, const struct bpf_prog *prog);
@@ -2519,4 +2546,12 @@ void bpf_dynptr_init(struct bpf_dynptr_kern *ptr, void *data,
25192546
void bpf_dynptr_set_null(struct bpf_dynptr_kern *ptr);
25202547
int bpf_dynptr_check_size(u32 size);
25212548

2549+
#ifdef CONFIG_BPF_LSM
2550+
void bpf_cgroup_atype_get(u32 attach_btf_id, int cgroup_atype);
2551+
void bpf_cgroup_atype_put(int cgroup_atype);
2552+
#else
2553+
static inline void bpf_cgroup_atype_get(u32 attach_btf_id, int cgroup_atype) {}
2554+
static inline void bpf_cgroup_atype_put(int cgroup_atype) {}
2555+
#endif /* CONFIG_BPF_LSM */
2556+
25222557
#endif /* _LINUX_BPF_H */

include/linux/bpf_lsm.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ extern const struct bpf_func_proto bpf_inode_storage_get_proto;
4242
extern const struct bpf_func_proto bpf_inode_storage_delete_proto;
4343
void bpf_inode_storage_free(struct inode *inode);
4444

45+
void bpf_lsm_find_cgroup_shim(const struct bpf_prog *prog, bpf_func_t *bpf_func);
46+
4547
#else /* !CONFIG_BPF_LSM */
4648

4749
static inline bool bpf_lsm_is_sleepable_hook(u32 btf_id)
@@ -65,6 +67,11 @@ static inline void bpf_inode_storage_free(struct inode *inode)
6567
{
6668
}
6769

70+
static inline void bpf_lsm_find_cgroup_shim(const struct bpf_prog *prog,
71+
bpf_func_t *bpf_func)
72+
{
73+
}
74+
6875
#endif /* CONFIG_BPF_LSM */
6976

7077
#endif /* _LINUX_BPF_LSM_H */

include/linux/bpf_verifier.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,14 @@ struct bpf_verifier_state_list {
344344
int miss_cnt, hit_cnt;
345345
};
346346

347+
struct bpf_loop_inline_state {
348+
int initialized:1; /* set to true upon first entry */
349+
int fit_for_inline:1; /* true if callback function is the same
350+
* at each call and flags are always zero
351+
*/
352+
u32 callback_subprogno; /* valid when fit_for_inline is true */
353+
};
354+
347355
/* Possible states for alu_state member. */
348356
#define BPF_ALU_SANITIZE_SRC (1U << 0)
349357
#define BPF_ALU_SANITIZE_DST (1U << 1)
@@ -373,6 +381,10 @@ struct bpf_insn_aux_data {
373381
u32 mem_size; /* mem_size for non-struct typed var */
374382
};
375383
} btf_var;
384+
/* if instruction is a call to bpf_loop this field tracks
385+
* the state of the relevant registers to make decision about inlining
386+
*/
387+
struct bpf_loop_inline_state loop_inline_state;
376388
};
377389
u64 map_key_state; /* constant (32 bit) key tracking for maps */
378390
int ctx_field_size; /* the ctx field size for load insn, maybe 0 */

0 commit comments

Comments
 (0)