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
572572 *sym = 0;
573573 }
574574
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)
577576 {
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;
582578 }
583579
584580 static __always_inline bool bpf_tree_less(struct latch_tree_node *a,
585581 struct latch_tree_node *b)
586582 {
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);
588584 }
589585
590586 static __always_inline int bpf_tree_comp(void *key, struct latch_tree_node *n)
591587 {
592588 unsigned long val = (unsigned long)key;
593− const struct bpf_prog_aux *aux;
589+ const struct bpf_ksym *ksym;
594590
595− aux = container_of(n, struct bpf_prog_aux, ksym_tnode);
591+ ksym = container_of(n, struct bpf_ksym, tnode);
596592
597− if (val < aux->ksym.start)
593+ if (val < ksym->start)
598594 return -1;
599− if (val >= aux->ksym.end)
595+ if (val >= ksym->end)
600596 return 1;
601597
602598 return 0;
@@ -615,7 +611,7 @@ static void bpf_prog_ksym_node_add(struct bpf_prog_aux *aux) · 12 unmodified lines
615611 {
616612 WARN_ON_ONCE(!list_empty(&aux->ksym.lnode));
617613 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);
619615 }
620616
621617 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
623619 if (list_empty(&aux->ksym.lnode))
624620 return;
625621
626− latch_tree_erase(&aux->ksym_tnode, &bpf_tree, &bpf_tree_ops);
622+ latch_tree_erase(&aux->ksym.tnode, &bpf_tree, &bpf_tree_ops);
627623 list_del_rcu(&aux->ksym.lnode);
628624 }
629625
@@ -668,7 +664,7 @@ static struct bpf_prog *bpf_prog_kallsyms_find(unsigned long addr) · 38 unmodified lines
668664
669665 n = latch_tree_find((void *)addr, &bpf_tree, &bpf_tree_ops);
670666 return n ?
671− container_of(n, struct bpf_prog_aux, ksym_tnode)->prog :
667+ container_of(n, struct bpf_prog_aux, ksym.tnode)->prog :
672668 NULL;
673669 }
674670

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