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.
Showing the changes to include/linux (1 of 4 files). Show all
Unified · Split
| @@ -433,6 +433,16 @@ struct btf_func_model { · 432 unmodified lines | ||
| 433 | 433 | */ |
| 434 | 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 | + | |
| 441 | +struct bpf_tramp_progs { | |
| 442 | + struct bpf_prog *progs[BPF_MAX_TRAMP_PROGS]; | |
| 443 | + int nr_progs; | |
| 444 | +}; | |
| 445 | + | |
| 436 | 446 | /* Different use cases for BPF trampoline: |
| 437 | 447 | * 1. replace nop at the function entry (kprobe equivalent) |
| 438 | 448 | * flags = BPF_TRAMP_F_RESTORE_REGS |
| @@ -455,8 +465,7 @@ struct btf_func_model { · 16 unmodified lines | ||
| 455 | 465 | */ |
| 456 | 466 | int arch_prepare_bpf_trampoline(void *image, void *image_end, |
| 457 | 467 | 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, | |
| 460 | 469 | void *orig_call); |
| 461 | 470 | /* these two functions are called from generated trampoline */ |
| 462 | 471 | u64 notrace __bpf_prog_enter(void); |