Skip to content

Commit 8b35e63

Browse files
jrifeKernel Patches Daemon
authored andcommitted
bpf, x86: Make program update work for trampoline ops
Use update_prog in place of current link prog when link matches update_link. Signed-off-by: Jordan Rife <[email protected]>
1 parent 0ad67ad commit 8b35e63

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

arch/x86/net/bpf_jit_comp.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2956,15 +2956,13 @@ static void restore_regs(const struct btf_func_model *m, u8 **prog,
29562956
}
29572957

29582958
static int invoke_bpf_prog(const struct btf_func_model *m, u8 **pprog,
2959-
struct bpf_tramp_link *l, int stack_size,
2959+
struct bpf_prog *p, u64 cookie, int stack_size,
29602960
int run_ctx_off, bool save_ret,
29612961
void *image, void *rw_image)
29622962
{
29632963
u8 *prog = *pprog;
29642964
u8 *jmp_insn;
29652965
int ctx_cookie_off = offsetof(struct bpf_tramp_run_ctx, bpf_cookie);
2966-
struct bpf_prog *p = l->link.prog;
2967-
u64 cookie = l->cookie;
29682966

29692967
/* mov rdi, cookie */
29702968
emit_mov_imm64(&prog, BPF_REG_1, (long) cookie >> 32, (u32) (long) cookie);
@@ -3079,7 +3077,8 @@ static int invoke_bpf(const struct btf_func_model *m, u8 **pprog,
30793077
u8 *prog = *pprog;
30803078

30813079
for (i = 0; i < tl->nr_links; i++) {
3082-
if (invoke_bpf_prog(m, &prog, tl->links[i], stack_size,
3080+
if (invoke_bpf_prog(m, &prog, bpf_tramp_links_prog(tl, i),
3081+
tl->links[i]->cookie, stack_size,
30833082
run_ctx_off, save_ret, image, rw_image))
30843083
return -EINVAL;
30853084
}
@@ -3101,8 +3100,9 @@ static int invoke_bpf_mod_ret(const struct btf_func_model *m, u8 **pprog,
31013100
emit_mov_imm32(&prog, false, BPF_REG_0, 0);
31023101
emit_stx(&prog, BPF_DW, BPF_REG_FP, BPF_REG_0, -8);
31033102
for (i = 0; i < tl->nr_links; i++) {
3104-
if (invoke_bpf_prog(m, &prog, tl->links[i], stack_size, run_ctx_off, true,
3105-
image, rw_image))
3103+
if (invoke_bpf_prog(m, &prog, bpf_tramp_links_prog(tl, i),
3104+
tl->links[i]->cookie, stack_size,
3105+
run_ctx_off, true, image, rw_image))
31063106
return -EINVAL;
31073107

31083108
/* mod_ret prog stored return value into [rbp - 8]. Emit:
@@ -3486,6 +3486,11 @@ int arch_protect_bpf_trampoline(void *image, unsigned int size)
34863486
return 0;
34873487
}
34883488

3489+
bool bpf_trampoline_supports_update_prog(void)
3490+
{
3491+
return true;
3492+
}
3493+
34893494
int arch_prepare_bpf_trampoline(struct bpf_tramp_image *im, void *image, void *image_end,
34903495
const struct btf_func_model *m, u32 flags,
34913496
struct bpf_tramp_links *tlinks,

0 commit comments

Comments
 (0)