Skip to content

Commit 2a702c2

Browse files
committed
Daniel Borkmann says: ==================== pull-request: bpf-next 2024-03-25 We've added 38 non-merge commits during the last 13 day(s) which contain a total of 50 files changed, 867 insertions(+), 274 deletions(-). The main changes are: 1) Add the ability to specify and retrieve BPF cookie also for raw tracepoint programs in order to ease migration from classic to raw tracepoints, from Andrii Nakryiko. 2) Allow the use of bpf_get_{ns_,}current_pid_tgid() helper for all program types and add additional BPF selftests, from Yonghong Song. 3) Several improvements to bpftool and its build, for example, enabling libbpf logs when loading pid_iter in debug mode, from Quentin Monnet. 4) Check the return code of all BPF-related set_memory_*() functions during load and bail out in case they fail, from Christophe Leroy. 5) Avoid a goto in regs_refine_cond_op() such that the verifier can be better integrated into Agni tool which doesn't support backedges yet, from Harishankar Vishwanathan. 6) Add a small BPF trie perf improvement by always inlining longest_prefix_match, from Jesper Dangaard Brouer. 7) Small BPF selftest refactor in bpf_tcp_ca.c to utilize start_server() helper instead of open-coding it, from Geliang Tang. 8) Improve test_tc_tunnel.sh BPF selftest to prevent client connect before the server bind, from Alessandro Carminati. 9) Fix BPF selftest benchmark for older glibc and use syscall(SYS_gettid) instead of gettid(), from Alan Maguire. 10) Implement a backward-compatible method for struct_ops types with additional fields which are not present in older kernels, from Kui-Feng Lee. 11) Add a small helper to check if an instruction is addr_space_cast from as(0) to as(1) and utilize it in x86-64 JIT, from Puranjay Mohan. 12) Small cleanup to remove unnecessary error check in bpf_struct_ops_map_update_elem, from Martin KaFai Lau. 13) Improvements to libbpf fd validity checks for BPF map/programs, from Mykyta Yatsenko. * tag 'for-netdev' of https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next: (38 commits) selftests/bpf: Fix flaky test btf_map_in_map/lookup_update bpf: implement insn_is_cast_user() helper for JITs bpf: Avoid get_kernel_nofault() to fetch kprobe entry IP selftests/bpf: Use start_server in bpf_tcp_ca bpf: Sync uapi bpf.h to tools directory libbpf: Add new sec_def "sk_skb/verdict" selftests/bpf: Mark uprobe trigger functions with nocf_check attribute selftests/bpf: Use syscall(SYS_gettid) instead of gettid() wrapper in bench bpf-next: Avoid goto in regs_refine_cond_op() bpftool: Clean up HOST_CFLAGS, HOST_LDFLAGS for bootstrap bpftool selftests/bpf: scale benchmark counting by using per-CPU counters bpftool: Remove unnecessary source files from bootstrap version bpftool: Enable libbpf logs when loading pid_iter in debug mode selftests/bpf: add raw_tp/tp_btf BPF cookie subtests libbpf: add support for BPF cookie for raw_tp/tp_btf programs bpf: support BPF cookie in raw tracepoint (raw_tp, tp_btf) programs bpf: pass whole link instead of prog when triggering raw tracepoint bpf: flatten bpf_probe_register call chain selftests/bpf: Prevent client connect before server bind in test_tc_tunnel.sh selftests/bpf: Add a sk_msg prog bpf_get_ns_current_pid_tgid() test ... ==================== Link: https://lore.kernel.org/r/20240325233940.7154-1-daniel@iogearbox.net Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2 parents ee36b1e + 14bb1e8 commit 2a702c2

Some content is hidden

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

50 files changed

+867
-274
lines changed

arch/arm/net/bpf_jit_32.c

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2222,28 +2222,21 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog)
22222222
/* If building the body of the JITed code fails somehow,
22232223
* we fall back to the interpretation.
22242224
*/
2225-
if (build_body(&ctx) < 0) {
2226-
image_ptr = NULL;
2227-
bpf_jit_binary_free(header);
2228-
prog = orig_prog;
2229-
goto out_imms;
2230-
}
2225+
if (build_body(&ctx) < 0)
2226+
goto out_free;
22312227
build_epilogue(&ctx);
22322228

22332229
/* 3.) Extra pass to validate JITed Code */
2234-
if (validate_code(&ctx)) {
2235-
image_ptr = NULL;
2236-
bpf_jit_binary_free(header);
2237-
prog = orig_prog;
2238-
goto out_imms;
2239-
}
2230+
if (validate_code(&ctx))
2231+
goto out_free;
22402232
flush_icache_range((u32)header, (u32)(ctx.target + ctx.idx));
22412233

22422234
if (bpf_jit_enable > 1)
22432235
/* there are 2 passes here */
22442236
bpf_jit_dump(prog->len, image_size, 2, ctx.target);
22452237

2246-
bpf_jit_binary_lock_ro(header);
2238+
if (bpf_jit_binary_lock_ro(header))
2239+
goto out_free;
22472240
prog->bpf_func = (void *)ctx.target;
22482241
prog->jited = 1;
22492242
prog->jited_len = image_size;
@@ -2260,5 +2253,11 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog)
22602253
bpf_jit_prog_release_other(prog, prog == orig_prog ?
22612254
tmp : orig_prog);
22622255
return prog;
2256+
2257+
out_free:
2258+
image_ptr = NULL;
2259+
bpf_jit_binary_free(header);
2260+
prog = orig_prog;
2261+
goto out_imms;
22632262
}
22642263

arch/arm64/net/bpf_jit_comp.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2176,12 +2176,9 @@ void arch_free_bpf_trampoline(void *image, unsigned int size)
21762176
bpf_prog_pack_free(image, size);
21772177
}
21782178

2179-
void arch_protect_bpf_trampoline(void *image, unsigned int size)
2180-
{
2181-
}
2182-
2183-
void arch_unprotect_bpf_trampoline(void *image, unsigned int size)
2179+
int arch_protect_bpf_trampoline(void *image, unsigned int size)
21842180
{
2181+
return 0;
21852182
}
21862183

21872184
int arch_prepare_bpf_trampoline(struct bpf_tramp_image *im, void *ro_image,

arch/loongarch/net/bpf_jit.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1294,16 +1294,19 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog)
12941294
flush_icache_range((unsigned long)header, (unsigned long)(ctx.image + ctx.idx));
12951295

12961296
if (!prog->is_func || extra_pass) {
1297+
int err;
1298+
12971299
if (extra_pass && ctx.idx != jit_data->ctx.idx) {
12981300
pr_err_once("multi-func JIT bug %d != %d\n",
12991301
ctx.idx, jit_data->ctx.idx);
1300-
bpf_jit_binary_free(header);
1301-
prog->bpf_func = NULL;
1302-
prog->jited = 0;
1303-
prog->jited_len = 0;
1304-
goto out_offset;
1302+
goto out_free;
1303+
}
1304+
err = bpf_jit_binary_lock_ro(header);
1305+
if (err) {
1306+
pr_err_once("bpf_jit_binary_lock_ro() returned %d\n",
1307+
err);
1308+
goto out_free;
13051309
}
1306-
bpf_jit_binary_lock_ro(header);
13071310
} else {
13081311
jit_data->ctx = ctx;
13091312
jit_data->image = image_ptr;
@@ -1334,6 +1337,13 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog)
13341337
out_offset = -1;
13351338

13361339
return prog;
1340+
1341+
out_free:
1342+
bpf_jit_binary_free(header);
1343+
prog->bpf_func = NULL;
1344+
prog->jited = 0;
1345+
prog->jited_len = 0;
1346+
goto out_offset;
13371347
}
13381348

13391349
/* Indicate the JIT backend supports mixing bpf2bpf and tailcalls. */

arch/mips/net/bpf_jit_comp.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1012,7 +1012,8 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog)
10121012
bpf_prog_fill_jited_linfo(prog, &ctx.descriptors[1]);
10131013

10141014
/* Set as read-only exec and flush instruction cache */
1015-
bpf_jit_binary_lock_ro(header);
1015+
if (bpf_jit_binary_lock_ro(header))
1016+
goto out_err;
10161017
flush_icache_range((unsigned long)header,
10171018
(unsigned long)&ctx.target[ctx.jit_index]);
10181019

arch/parisc/net/bpf_jit_core.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,13 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog)
167167
bpf_flush_icache(jit_data->header, ctx->insns + ctx->ninsns);
168168

169169
if (!prog->is_func || extra_pass) {
170-
bpf_jit_binary_lock_ro(jit_data->header);
170+
if (bpf_jit_binary_lock_ro(jit_data->header)) {
171+
bpf_jit_binary_free(jit_data->header);
172+
prog->bpf_func = NULL;
173+
prog->jited = 0;
174+
prog->jited_len = 0;
175+
goto out_offset;
176+
}
171177
prologue_len = ctx->epilogue_offset - ctx->body_len;
172178
for (i = 0; i < prog->len; i++)
173179
ctx->offset[i] += prologue_len;

arch/s390/net/bpf_jit_comp.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2111,7 +2111,11 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *fp)
21112111
print_fn_code(jit.prg_buf, jit.size_prg);
21122112
}
21132113
if (!fp->is_func || extra_pass) {
2114-
bpf_jit_binary_lock_ro(header);
2114+
if (bpf_jit_binary_lock_ro(header)) {
2115+
bpf_jit_binary_free(header);
2116+
fp = orig_fp;
2117+
goto free_addrs;
2118+
}
21152119
} else {
21162120
jit_data->header = header;
21172121
jit_data->ctx = jit;

arch/sparc/net/bpf_jit_comp_64.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1602,7 +1602,11 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog)
16021602
bpf_flush_icache(header, (u8 *)header + header->size);
16031603

16041604
if (!prog->is_func || extra_pass) {
1605-
bpf_jit_binary_lock_ro(header);
1605+
if (bpf_jit_binary_lock_ro(header)) {
1606+
bpf_jit_binary_free(header);
1607+
prog = orig_prog;
1608+
goto out_off;
1609+
}
16061610
} else {
16071611
jit_data->ctx = ctx;
16081612
jit_data->image = image_ptr;

arch/x86/net/bpf_jit_comp.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1351,8 +1351,7 @@ static int do_jit(struct bpf_prog *bpf_prog, int *addrs, u8 *image, u8 *rw_image
13511351
break;
13521352

13531353
case BPF_ALU64 | BPF_MOV | BPF_X:
1354-
if (insn->off == BPF_ADDR_SPACE_CAST &&
1355-
insn->imm == 1U << 16) {
1354+
if (insn_is_cast_user(insn)) {
13561355
if (dst_reg != src_reg)
13571356
/* 32-bit mov */
13581357
emit_mov_reg(&prog, false, dst_reg, src_reg);
@@ -3004,12 +3003,9 @@ void arch_free_bpf_trampoline(void *image, unsigned int size)
30043003
bpf_prog_pack_free(image, size);
30053004
}
30063005

3007-
void arch_protect_bpf_trampoline(void *image, unsigned int size)
3008-
{
3009-
}
3010-
3011-
void arch_unprotect_bpf_trampoline(void *image, unsigned int size)
3006+
int arch_protect_bpf_trampoline(void *image, unsigned int size)
30123007
{
3008+
return 0;
30133009
}
30143010

30153011
int arch_prepare_bpf_trampoline(struct bpf_tramp_image *im, void *image, void *image_end,

arch/x86/net/bpf_jit_comp32.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2600,8 +2600,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog)
26002600
if (bpf_jit_enable > 1)
26012601
bpf_jit_dump(prog->len, proglen, pass + 1, image);
26022602

2603-
if (image) {
2604-
bpf_jit_binary_lock_ro(header);
2603+
if (image && !bpf_jit_binary_lock_ro(header)) {
26052604
prog->bpf_func = (void *)image;
26062605
prog->jited = 1;
26072606
prog->jited_len = proglen;

include/linux/bpf.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,8 +1116,7 @@ int arch_prepare_bpf_trampoline(struct bpf_tramp_image *im, void *image, void *i
11161116
void *func_addr);
11171117
void *arch_alloc_bpf_trampoline(unsigned int size);
11181118
void arch_free_bpf_trampoline(void *image, unsigned int size);
1119-
void arch_protect_bpf_trampoline(void *image, unsigned int size);
1120-
void arch_unprotect_bpf_trampoline(void *image, unsigned int size);
1119+
int __must_check arch_protect_bpf_trampoline(void *image, unsigned int size);
11211120
int arch_bpf_trampoline_size(const struct btf_func_model *m, u32 flags,
11221121
struct bpf_tramp_links *tlinks, void *func_addr);
11231122

@@ -1608,6 +1607,12 @@ struct bpf_tracing_link {
16081607
struct bpf_prog *tgt_prog;
16091608
};
16101609

1610+
struct bpf_raw_tp_link {
1611+
struct bpf_link link;
1612+
struct bpf_raw_event_map *btp;
1613+
u64 cookie;
1614+
};
1615+
16111616
struct bpf_link_primer {
16121617
struct bpf_link *link;
16131618
struct file *file;

0 commit comments

Comments
 (0)