[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20200226130345.209469-16-jolsa@kernel.org>
Date: Wed, 26 Feb 2020 14:03:42 +0100
From: Jiri Olsa <jolsa@...nel.org>
To: Alexei Starovoitov <ast@...nel.org>,
Daniel Borkmann <daniel@...earbox.net>
Cc: netdev@...r.kernel.org, bpf@...r.kernel.org,
Andrii Nakryiko <andriin@...com>, Yonghong Song <yhs@...com>,
Song Liu <songliubraving@...com>,
Martin KaFai Lau <kafai@...com>,
Jakub Kicinski <kuba@...nel.org>,
David Miller <davem@...hat.com>,
Björn Töpel <bjorn.topel@...el.com>,
John Fastabend <john.fastabend@...il.com>,
Jesper Dangaard Brouer <hawk@...nel.org>,
Arnaldo Carvalho de Melo <acme@...hat.com>
Subject: [PATCH 15/18] bpf: Sort bpf kallsyms symbols
Currently we don't sort bpf_kallsyms and display symbols
in proc/kallsyms as they come in via __bpf_ksym_add.
Using the latch tree to get the next bpf_ksym object
and insert the new symbol ahead of it.
Signed-off-by: Jiri Olsa <jolsa@...nel.org>
---
kernel/bpf/core.c | 21 ++++++++++++++++++++-
1 file changed, 20 insertions(+), 1 deletion(-)
diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
index 9879fb02ee8e..3319019735f0 100644
--- a/kernel/bpf/core.c
+++ b/kernel/bpf/core.c
@@ -647,9 +647,28 @@ static struct latch_tree_root bpf_progs_tree __cacheline_aligned;
static void __bpf_ksym_add(struct bpf_ksym *ksym)
{
+ struct list_head *head = &bpf_kallsyms;
+ struct rb_node *next;
+
WARN_ON_ONCE(!list_empty(&ksym->lnode));
- list_add_tail_rcu(&ksym->lnode, &bpf_kallsyms);
latch_tree_insert(&ksym->tnode, &bpf_ksym_tree, &bpf_ksym_tree_ops);
+
+ /*
+ * Add ksym into bpf_kallsyms in ordered position,
+ * which is prepared for us by latch tree addition.
+ *
+ * Find out the next symbol and insert ksym right
+ * ahead of it. If ksym is the last one, just tail
+ * add to the bpf_kallsyms.
+ */
+ next = rb_next(&ksym->tnode.node[0]);
+ if (next) {
+ struct bpf_ksym *ptr;
+
+ ptr = container_of(next, struct bpf_ksym, tnode.node[0]);
+ head = &ptr->lnode;
+ }
+ list_add_tail_rcu(&ksym->lnode, head);
}
void bpf_ksym_add(struct bpf_ksym *ksym)
--
2.24.1
Powered by blists - more mailing lists