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 | unsigned long end; | 477 | unsigned long end; |
| 478 | char name[KSYM_NAME_LEN]; | 478 | char name[KSYM_NAME_LEN]; |
| 479 | struct list_head lnode; | 479 | struct list_head lnode; |
| 480 | struct latch_tree_node tnode; | ||
| 480 | }; | 481 | }; |
| 481 | 482 | ||
| 482 | enum bpf_tramp_prog_type { | 483 | enum bpf_tramp_prog_type { |
| @@ -659,7 +660,6 @@ struct bpf_prog_aux { · 176 unmodified lines | |||
| 659 | void *jit_data; /* JIT specific data. arch dependent */ | 660 | void *jit_data; /* JIT specific data. arch dependent */ |
| 660 | struct bpf_jit_poke_descriptor *poke_tab; | 661 | struct bpf_jit_poke_descriptor *poke_tab; |
| 661 | u32 size_poke_tab; | 662 | u32 size_poke_tab; |
| 662 | struct latch_tree_node ksym_tnode; | ||
| 663 | struct bpf_ksym ksym; | 663 | struct bpf_ksym ksym; |
| 664 | const struct bpf_prog_ops *ops; | 664 | const struct bpf_prog_ops *ops; |
| 665 | struct bpf_map **used_maps; | 665 | struct bpf_map **used_maps; |
| @@ -572,31 +572,27 @@ bpf_prog_ksym_set_name(struct bpf_prog *prog) · 571 unmodified lines | |||
| 572 | *sym = 0; | 572 | *sym = 0; |
| 573 | } | 573 | } |
| 574 | 574 | ||
| 575 | static __always_inline unsigned long | 575 | static unsigned long bpf_get_ksym_start(struct latch_tree_node *n) |
| 576 | bpf_get_prog_addr_start(struct latch_tree_node *n) | ||
| 577 | { | 576 | { |
| 578 | const struct bpf_prog_aux *aux; | 577 | return container_of(n, struct bpf_ksym, tnode)->start; |
| 579 | |||
| 580 | aux = container_of(n, struct bpf_prog_aux, ksym_tnode); | ||
| 581 | return aux->ksym.start; | ||
| 582 | } | 578 | } |
| 583 | 579 | ||
| 584 | static __always_inline bool bpf_tree_less(struct latch_tree_node *a, | 580 | static __always_inline bool bpf_tree_less(struct latch_tree_node *a, |
| 585 | struct latch_tree_node *b) | 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 | static __always_inline int bpf_tree_comp(void *key, struct latch_tree_node *n) | 586 | static __always_inline int bpf_tree_comp(void *key, struct latch_tree_node *n) |
| 591 | { | 587 | { |
| 592 | unsigned long val = (unsigned long)key; | 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 | return -1; | 594 | return -1; |
| 599 | if (val >= aux->ksym.end) | 595 | if (val >= ksym->end) |
| 600 | return 1; | 596 | return 1; |
| 601 | 597 | ||
| 602 | return 0; | 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 | WARN_ON_ONCE(!list_empty(&aux->ksym.lnode)); | 612 | WARN_ON_ONCE(!list_empty(&aux->ksym.lnode)); |
| 617 | list_add_tail_rcu(&aux->ksym.lnode, &bpf_kallsyms); | 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 | static void bpf_prog_ksym_node_del(struct bpf_prog_aux *aux) | 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 | if (list_empty(&aux->ksym.lnode)) | 619 | if (list_empty(&aux->ksym.lnode)) |
| 624 | return; | 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 | list_del_rcu(&aux->ksym.lnode); | 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 | n = latch_tree_find((void *)addr, &bpf_tree, &bpf_tree_ops); | 665 | n = latch_tree_find((void *)addr, &bpf_tree, &bpf_tree_ops); |
| 670 | return n ? | 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 | NULL; | 668 | NULL; |
| 673 | } | 669 | } |
| 674 | 670 | ||