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
433433 */
434434 #define BPF_TRAMP_F_SKIP_FRAME BIT(2)
435435
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+
441+struct bpf_tramp_progs {
442+ struct bpf_prog *progs[BPF_MAX_TRAMP_PROGS];
443+ int nr_progs;
444+};
445+
436446 /* Different use cases for BPF trampoline:
437447 * 1. replace nop at the function entry (kprobe equivalent)
438448 * flags = BPF_TRAMP_F_RESTORE_REGS
@@ -455,8 +465,7 @@ struct btf_func_model { · 16 unmodified lines
455465 */
456466 int arch_prepare_bpf_trampoline(void *image, void *image_end,
457467 const struct btf_func_model *m, u32 flags,
458− struct bpf_prog **fentry_progs, int fentry_cnt,
459− struct bpf_prog **fexit_progs, int fexit_cnt,
468+ struct bpf_tramp_progs *tprogs,
460469 void *orig_call);
461470 /* these two functions are called from generated trampoline */
462471 u64 notrace __bpf_prog_enter(void);