Skip to content

Commit ca4424c

Browse files
olsajiriAlexei Starovoitov
authored andcommitted
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. Signed-off-by: Jiri Olsa <jolsa@kernel.org> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://lore.kernel.org/bpf/20200312195610.346362-7-jolsa@kernel.org Signed-off-by: Alexei Starovoitov <ast@kernel.org>
1 parent ecb60d1 commit ca4424c

2 files changed

Lines changed: 11 additions & 15 deletions

File tree

‎include/linux/bpf.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,7 @@ struct bpf_ksym {
477477
unsigned long end;
478478
char name[KSYM_NAME_LEN];
479479
struct list_head lnode;
480+
struct latch_tree_node tnode;
480481
};
481482

482483
enum bpf_tramp_prog_type {
@@ -659,7 +660,6 @@ struct bpf_prog_aux {
659660
void *jit_data; /* JIT specific data. arch dependent */
660661
struct bpf_jit_poke_descriptor *poke_tab;
661662
u32 size_poke_tab;
662-
struct latch_tree_node ksym_tnode;
663663
struct bpf_ksym ksym;
664664
const struct bpf_prog_ops *ops;
665665
struct bpf_map **used_maps;

‎kernel/bpf/core.c‎

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -572,31 +572,27 @@ bpf_prog_ksym_set_name(struct bpf_prog *prog)
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,15 +611,15 @@ static void bpf_prog_ksym_node_add(struct bpf_prog_aux *aux)
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)
622618
{
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)
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

0 commit comments

Comments
 (0)