From: "Björn Töpel" <bjorn.topel@gmail.com>
To: netdev@vger.kernel.org, ast@kernel.org, daniel@iogearbox.net
Cc: "Björn Töpel" <bjorn.topel@intel.com>,
bpf@vger.kernel.org, magnus.karlsson@gmail.com,
magnus.karlsson@intel.com, jonathan.lemon@gmail.com,
ecree@solarflare.com, thoiland@redhat.com, brouer@redhat.com,
andrii.nakryiko@gmail.com
Subject: [PATCH bpf-next v4 1/6] bpf: move trampoline JIT image allocation to a function
Date: Wed, 11 Dec 2019 13:30:12 +0100 [thread overview]
Message-ID: <20191211123017.13212-2-bjorn.topel@gmail.com> (raw)
In-Reply-To: <20191211123017.13212-1-bjorn.topel@gmail.com>
From: Björn Töpel <bjorn.topel@intel.com>
Refactor the image allocation in the BPF trampoline code into a
separate function, so it can be shared with the BPF dispatcher in
upcoming commits.
Signed-off-by: Björn Töpel <bjorn.topel@intel.com>
---
include/linux/bpf.h | 1 +
kernel/bpf/trampoline.c | 24 +++++++++++++++++-------
2 files changed, 18 insertions(+), 7 deletions(-)
diff --git a/include/linux/bpf.h b/include/linux/bpf.h
index 35903f148be5..5d744828b399 100644
--- a/include/linux/bpf.h
+++ b/include/linux/bpf.h
@@ -475,6 +475,7 @@ struct bpf_trampoline *bpf_trampoline_lookup(u64 key);
int bpf_trampoline_link_prog(struct bpf_prog *prog);
int bpf_trampoline_unlink_prog(struct bpf_prog *prog);
void bpf_trampoline_put(struct bpf_trampoline *tr);
+void *bpf_jit_alloc_exec_page(void);
#else
static inline struct bpf_trampoline *bpf_trampoline_lookup(u64 key)
{
diff --git a/kernel/bpf/trampoline.c b/kernel/bpf/trampoline.c
index 7e89f1f49d77..5ee301ddbd00 100644
--- a/kernel/bpf/trampoline.c
+++ b/kernel/bpf/trampoline.c
@@ -13,6 +13,22 @@ static struct hlist_head trampoline_table[TRAMPOLINE_TABLE_SIZE];
/* serializes access to trampoline_table */
static DEFINE_MUTEX(trampoline_mutex);
+void *bpf_jit_alloc_exec_page(void)
+{
+ void *image;
+
+ image = bpf_jit_alloc_exec(PAGE_SIZE);
+ if (!image)
+ return NULL;
+
+ set_vm_flush_reset_perms(image);
+ /* Keep image as writeable. The alternative is to keep flipping ro/rw
+ * everytime new program is attached or detached.
+ */
+ set_memory_x((long)image, 1);
+ return image;
+}
+
struct bpf_trampoline *bpf_trampoline_lookup(u64 key)
{
struct bpf_trampoline *tr;
@@ -33,7 +49,7 @@ struct bpf_trampoline *bpf_trampoline_lookup(u64 key)
goto out;
/* is_root was checked earlier. No need for bpf_jit_charge_modmem() */
- image = bpf_jit_alloc_exec(PAGE_SIZE);
+ image = bpf_jit_alloc_exec_page();
if (!image) {
kfree(tr);
tr = NULL;
@@ -47,12 +63,6 @@ struct bpf_trampoline *bpf_trampoline_lookup(u64 key)
mutex_init(&tr->mutex);
for (i = 0; i < BPF_TRAMP_MAX; i++)
INIT_HLIST_HEAD(&tr->progs_hlist[i]);
-
- set_vm_flush_reset_perms(image);
- /* Keep image as writeable. The alternative is to keep flipping ro/rw
- * everytime new program is attached or detached.
- */
- set_memory_x((long)image, 1);
tr->image = image;
out:
mutex_unlock(&trampoline_mutex);
--
2.20.1
next prev parent reply other threads:[~2019-12-11 12:30 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-11 12:30 [PATCH bpf-next v4 0/6] Introduce the BPF dispatcher Björn Töpel
2019-12-11 12:30 ` Björn Töpel [this message]
2019-12-11 12:30 ` [PATCH bpf-next v4 2/6] bpf: introduce " Björn Töpel
2019-12-11 13:26 ` Toke Høiland-Jørgensen
2019-12-13 8:23 ` Björn Töpel
2019-12-13 5:30 ` Alexei Starovoitov
2019-12-13 7:51 ` Björn Töpel
2019-12-13 15:04 ` Alexei Starovoitov
2019-12-13 15:49 ` Björn Töpel
2019-12-13 15:51 ` Alexei Starovoitov
2019-12-13 15:59 ` Björn Töpel
2019-12-13 16:03 ` Alexei Starovoitov
2019-12-13 16:09 ` Björn Töpel
2019-12-13 17:18 ` Alexei Starovoitov
2022-08-15 14:13 ` Steven Rostedt
2022-08-15 14:31 ` Alexei Starovoitov
2022-08-15 14:56 ` Peter Zijlstra
2022-08-15 15:16 ` Steven Rostedt
2022-08-15 15:19 ` Alexei Starovoitov
2022-08-15 15:21 ` Steven Rostedt
2022-08-15 15:39 ` Steven Rostedt
2019-12-11 12:30 ` [PATCH bpf-next v4 3/6] bpf, xdp: start using the BPF dispatcher for XDP Björn Töpel
2019-12-11 12:30 ` [PATCH bpf-next v4 4/6] bpf: start using the BPF dispatcher in BPF_TEST_RUN Björn Töpel
2019-12-11 12:30 ` [PATCH bpf-next v4 5/6] selftests: bpf: add xdp_perf test Björn Töpel
2019-12-11 12:30 ` [PATCH bpf-next v4 6/6] bpf, x86: align dispatcher branch targets to 16B Björn Töpel
2019-12-11 12:33 ` [PATCH bpf-next v4 0/6] Introduce the BPF dispatcher Björn Töpel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20191211123017.13212-2-bjorn.topel@gmail.com \
--to=bjorn.topel@gmail.com \
--cc=andrii.nakryiko@gmail.com \
--cc=ast@kernel.org \
--cc=bjorn.topel@intel.com \
--cc=bpf@vger.kernel.org \
--cc=brouer@redhat.com \
--cc=daniel@iogearbox.net \
--cc=ecree@solarflare.com \
--cc=jonathan.lemon@gmail.com \
--cc=magnus.karlsson@gmail.com \
--cc=magnus.karlsson@intel.com \
--cc=netdev@vger.kernel.org \
--cc=thoiland@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).