[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20210826193922.66204-13-jolsa@kernel.org>
Date: Thu, 26 Aug 2021 21:39:07 +0200
From: Jiri Olsa <jolsa@...hat.com>
To: Alexei Starovoitov <ast@...nel.org>,
Daniel Borkmann <daniel@...earbox.net>,
Andrii Nakryiko <andriin@...com>,
"Steven Rostedt (VMware)" <rostedt@...dmis.org>
Cc: netdev@...r.kernel.org, bpf@...r.kernel.org,
Martin KaFai Lau <kafai@...com>,
Song Liu <songliubraving@...com>, Yonghong Song <yhs@...com>,
John Fastabend <john.fastabend@...il.com>,
KP Singh <kpsingh@...omium.org>, Daniel Xu <dxu@...uu.xyz>,
Viktor Malik <vmalik@...hat.com>
Subject: [PATCH bpf-next v4 12/27] bpf: Factor out __bpf_trampoline_lookup function
Separating out __bpf_trampoline_lookup function, so it can
be used from other places in following patches.
Signed-off-by: Jiri Olsa <jolsa@...nel.org>
---
kernel/bpf/trampoline.c | 26 ++++++++++++++++++++------
1 file changed, 20 insertions(+), 6 deletions(-)
diff --git a/kernel/bpf/trampoline.c b/kernel/bpf/trampoline.c
index f44899c9698a..6dba43266e0b 100644
--- a/kernel/bpf/trampoline.c
+++ b/kernel/bpf/trampoline.c
@@ -70,23 +70,37 @@ static void bpf_trampoline_init(struct bpf_trampoline *tr, u64 key)
INIT_HLIST_HEAD(&tr->progs_hlist[i]);
}
-static struct bpf_trampoline *bpf_trampoline_lookup(u64 key)
+static struct bpf_trampoline *__bpf_trampoline_lookup(u64 key)
{
struct bpf_trampoline *tr;
struct hlist_head *head;
- mutex_lock(&trampoline_mutex);
+ lockdep_assert_held(&trampoline_mutex);
+
head = &trampoline_table[hash_64(key, TRAMPOLINE_HASH_BITS)];
hlist_for_each_entry(tr, head, hlist) {
- if (tr->key == key) {
- refcount_inc(&tr->refcnt);
- goto out;
- }
+ if (tr->key == key)
+ return tr;
+ }
+ return NULL;
+}
+
+static struct bpf_trampoline *bpf_trampoline_lookup(u64 key)
+{
+ struct bpf_trampoline *tr;
+ struct hlist_head *head;
+
+ mutex_lock(&trampoline_mutex);
+ tr = __bpf_trampoline_lookup(key);
+ if (tr) {
+ refcount_inc(&tr->refcnt);
+ goto out;
}
tr = kzalloc(sizeof(*tr), GFP_KERNEL);
if (!tr)
goto out;
bpf_trampoline_init(tr, key);
+ head = &trampoline_table[hash_64(key, TRAMPOLINE_HASH_BITS)];
hlist_add_head(&tr->hlist, head);
out:
mutex_unlock(&trampoline_mutex);
--
2.31.1
Powered by blists - more mailing lists