Skip to content

Commit cbd76f8

Browse files
olsajiriAlexei Starovoitov
authored andcommitted
bpf: Add prog flag to struct bpf_ksym object
Adding 'prog' bool flag to 'struct bpf_ksym' to mark that this object belongs to bpf_prog object. This change allows having bpf_prog objects together with other types (trampolines and dispatchers) in the single bpf_tree. It's used when searching for bpf_prog exception tables by the bpf_prog_ksym_find function, where we need to get the bpf_prog pointer. >From now we can safely add bpf_ksym support for trampoline or dispatcher objects, because we can differentiate them from bpf_prog objects. Signed-off-by: Jiri Olsa <jolsa@kernel.org> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://lore.kernel.org/bpf/20200312195610.346362-9-jolsa@kernel.org Signed-off-by: Alexei Starovoitov <ast@kernel.org>
1 parent eda0c92 commit cbd76f8

2 files changed

Lines changed: 12 additions & 11 deletions

File tree

‎include/linux/bpf.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,7 @@ struct bpf_ksym {
478478
char name[KSYM_NAME_LEN];
479479
struct list_head lnode;
480480
struct latch_tree_node tnode;
481+
bool prog;
481482
};
482483

483484
enum bpf_tramp_prog_type {

‎kernel/bpf/core.c‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,7 @@ void bpf_prog_kallsyms_add(struct bpf_prog *fp)
642642

643643
bpf_prog_ksym_set_addr(fp);
644644
bpf_prog_ksym_set_name(fp);
645+
fp->aux->ksym.prog = true;
645646

646647
spin_lock_bh(&bpf_lock);
647648
bpf_prog_ksym_node_add(fp->aux);
@@ -658,16 +659,6 @@ void bpf_prog_kallsyms_del(struct bpf_prog *fp)
658659
spin_unlock_bh(&bpf_lock);
659660
}
660661

661-
static struct bpf_prog *bpf_prog_kallsyms_find(unsigned long addr)
662-
{
663-
struct latch_tree_node *n;
664-
665-
n = latch_tree_find((void *)addr, &bpf_tree, &bpf_tree_ops);
666-
return n ?
667-
container_of(n, struct bpf_prog_aux, ksym.tnode)->prog :
668-
NULL;
669-
}
670-
671662
static struct bpf_ksym *bpf_ksym_find(unsigned long addr)
672663
{
673664
struct latch_tree_node *n;
@@ -712,13 +703,22 @@ bool is_bpf_text_address(unsigned long addr)
712703
return ret;
713704
}
714705

706+
static struct bpf_prog *bpf_prog_ksym_find(unsigned long addr)
707+
{
708+
struct bpf_ksym *ksym = bpf_ksym_find(addr);
709+
710+
return ksym && ksym->prog ?
711+
container_of(ksym, struct bpf_prog_aux, ksym)->prog :
712+
NULL;
713+
}
714+
715715
const struct exception_table_entry *search_bpf_extables(unsigned long addr)
716716
{
717717
const struct exception_table_entry *e = NULL;
718718
struct bpf_prog *prog;
719719

720720
rcu_read_lock();
721-
prog = bpf_prog_kallsyms_find(addr);
721+
prog = bpf_prog_ksym_find(addr);
722722
if (!prog)
723723
goto out;
724724
if (!prog->aux->num_exentries)

0 commit comments

Comments
 (0)