Moving ksym_tnode list node to 'struct bpf_ksym' object, so the symbol itself can be chained and used in other objects like bpf_trampoline and bpf_dispatcher. We need bpf_ksym object to be linked both in bpf_kallsyms via lnode for /proc/kallsyms and in bpf_tree via tnode for bpf address lookup functions like __bpf_address_lookup or bpf_prog_kallsyms_find.
Unified · Split
| @@ -477,6 +477,7 @@ struct bpf_ksym { · 476 unmodified lines | ||
| 477 | 477 | unsigned long end; |
| 478 | 478 | char name[KSYM_NAME_LEN]; |
| 479 | 479 | struct list_head lnode; |
| 480 | + struct latch_tree_node tnode; | |
| 480 | 481 | }; |
| 481 | 482 | |
| 482 | 483 | enum bpf_tramp_prog_type { |
| @@ -659,7 +660,6 @@ struct bpf_prog_aux { · 176 unmodified lines | ||
| 659 | 660 | void *jit_data; /* JIT specific data. arch dependent */ |
| 660 | 661 | struct bpf_jit_poke_descriptor *poke_tab; |
| 661 | 662 | u32 size_poke_tab; |
| 662 | − struct latch_tree_node ksym_tnode; | |
| 663 | 663 | struct bpf_ksym ksym; |
| 664 | 664 | const struct bpf_prog_ops *ops; |
| 665 | 665 | struct bpf_map **used_maps; |
| @@ -572,31 +572,27 @@ bpf_prog_ksym_set_name(struct bpf_prog *prog) · 571 unmodified lines | ||
| 572 | 572 | *sym = 0; |
| 573 | 573 | } |
| 574 | 574 | |
| 575 | −static __always_inline unsigned long | |
| 576 | −bpf_get_prog_addr_start(struct latch_tree_node *n) | |
| 575 | +static unsigned long bpf_get_ksym_start(struct latch_tree_node *n) | |
| 577 | 576 | { |
| 578 | − const struct bpf_prog_aux *aux; | |
| 579 | − | |
| 580 | − aux = container_of(n, struct bpf_prog_aux, ksym_tnode); | |
| 581 | − return aux->ksym.start; | |
| 577 | + return container_of(n, struct bpf_ksym, tnode)->start; | |
| 582 | 578 | } |
| 583 | 579 | |
| 584 | 580 | static __always_inline bool bpf_tree_less(struct latch_tree_node *a, |
| 585 | 581 | struct latch_tree_node *b) |
| 586 | 582 | { |
| 587 | − return bpf_get_prog_addr_start(a) < bpf_get_prog_addr_start(b); | |
| 583 | + return bpf_get_ksym_start(a) < bpf_get_ksym_start(b); | |
| 588 | 584 | } |
| 589 | 585 | |
| 590 | 586 | static __always_inline int bpf_tree_comp(void *key, struct latch_tree_node *n) |
| 591 | 587 | { |
| 592 | 588 | unsigned long val = (unsigned long)key; |
| 593 | − const struct bpf_prog_aux *aux; | |
| 589 | + const struct bpf_ksym *ksym; | |
| 594 | 590 | |
| 595 | − aux = container_of(n, struct bpf_prog_aux, ksym_tnode); | |
| 591 | + ksym = container_of(n, struct bpf_ksym, tnode); | |
| 596 | 592 | |
| 597 | − if (val < aux->ksym.start) | |
| 593 | + if (val < ksym->start) | |
| 598 | 594 | return -1; |
| 599 | − if (val >= aux->ksym.end) | |
| 595 | + if (val >= ksym->end) | |
| 600 | 596 | return 1; |
| 601 | 597 | |
| 602 | 598 | return 0; |
| @@ -615,7 +611,7 @@ static void bpf_prog_ksym_node_add(struct bpf_prog_aux *aux) · 12 unmodified lines | ||
| 615 | 611 | { |
| 616 | 612 | WARN_ON_ONCE(!list_empty(&aux->ksym.lnode)); |
| 617 | 613 | list_add_tail_rcu(&aux->ksym.lnode, &bpf_kallsyms); |
| 618 | − latch_tree_insert(&aux->ksym_tnode, &bpf_tree, &bpf_tree_ops); | |
| 614 | + latch_tree_insert(&aux->ksym.tnode, &bpf_tree, &bpf_tree_ops); | |
| 619 | 615 | } |
| 620 | 616 | |
| 621 | 617 | static void bpf_prog_ksym_node_del(struct bpf_prog_aux *aux) |
| @@ -623,7 +619,7 @@ static void bpf_prog_ksym_node_del(struct bpf_prog_aux *aux) · 1 unmodified line | ||
| 623 | 619 | if (list_empty(&aux->ksym.lnode)) |
| 624 | 620 | return; |
| 625 | 621 | |
| 626 | − latch_tree_erase(&aux->ksym_tnode, &bpf_tree, &bpf_tree_ops); | |
| 622 | + latch_tree_erase(&aux->ksym.tnode, &bpf_tree, &bpf_tree_ops); | |
| 627 | 623 | list_del_rcu(&aux->ksym.lnode); |
| 628 | 624 | } |
| 629 | 625 | |
| @@ -668,7 +664,7 @@ static struct bpf_prog *bpf_prog_kallsyms_find(unsigned long addr) · 38 unmodified lines | ||
| 668 | 664 | |
| 669 | 665 | n = latch_tree_find((void *)addr, &bpf_tree, &bpf_tree_ops); |
| 670 | 666 | return n ? |
| 671 | − container_of(n, struct bpf_prog_aux, ksym_tnode)->prog : | |
| 667 | + container_of(n, struct bpf_prog_aux, ksym.tnode)->prog : | |
| 672 | 668 | NULL; |
| 673 | 669 | } |
| 674 | 670 | |