History

bpf: Refactor trampoline update code

As we need to introduce a third type of attachment for trampolines, the flattened signature of arch_prepare_bpf_trampoline gets even more complicated. Refactor the prog and count argument to arch_prepare_bpf_trampoline to use bpf_tramp_progs to simplify the addition and accounting for new attachment types.

KP Singh committed 6 years ago

Commit 88fd9e51 parent cc6fa774 files · +71 −45Browse files

Showing the changes to include/linux (1 of 4 files). Show all

Unified · Split

include/linux/bpf.h+11−2
@@ -433,6 +433,16 @@ struct btf_func_model { · 432 unmodified lines
433 */433 */
434#define BPF_TRAMP_F_SKIP_FRAME BIT(2)434#define BPF_TRAMP_F_SKIP_FRAME BIT(2)
435 435
436/* Each call __bpf_prog_enter + call bpf_func + call __bpf_prog_exit is ~50
437 * bytes on x86. Pick a number to fit into BPF_IMAGE_SIZE / 2
438 */
439#define BPF_MAX_TRAMP_PROGS 40
440
441struct bpf_tramp_progs {
442 struct bpf_prog *progs[BPF_MAX_TRAMP_PROGS];
443 int nr_progs;
444};
445
436/* Different use cases for BPF trampoline:446/* Different use cases for BPF trampoline:
437 * 1. replace nop at the function entry (kprobe equivalent)447 * 1. replace nop at the function entry (kprobe equivalent)
438 * flags = BPF_TRAMP_F_RESTORE_REGS448 * flags = BPF_TRAMP_F_RESTORE_REGS
@@ -455,8 +465,7 @@ struct btf_func_model { · 16 unmodified lines
455 */465 */
456int arch_prepare_bpf_trampoline(void *image, void *image_end,466int arch_prepare_bpf_trampoline(void *image, void *image_end,
457 const struct btf_func_model *m, u32 flags,467 const struct btf_func_model *m, u32 flags,
458 struct bpf_prog **fentry_progs, int fentry_cnt,468 struct bpf_tramp_progs *tprogs,
459 struct bpf_prog **fexit_progs, int fexit_cnt,
460 void *orig_call);469 void *orig_call);
461/* these two functions are called from generated trampoline */470/* these two functions are called from generated trampoline */
462u64 notrace __bpf_prog_enter(void);471u64 notrace __bpf_prog_enter(void);