History

bpf: Move ksym_tnode to bpf_ksym

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.

Jiri Olsa committed 6 years ago

Commit ca4424c1 parent ecb60d12 files · +11 −15Browse files

Showing the changes to kernel (1 of 2 files). Show all

Unified · Split

kernel/bpf/core.c+10−14
@@ -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
575static __always_inline unsigned long575static unsigned long bpf_get_ksym_start(struct latch_tree_node *n)
576bpf_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
584static __always_inline bool bpf_tree_less(struct latch_tree_node *a,580static __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
590static __always_inline int bpf_tree_comp(void *key, struct latch_tree_node *n)586static __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
621static void bpf_prog_ksym_node_del(struct bpf_prog_aux *aux)617static 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

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t