From: Rick Edgecombe <rick.p.edgecombe@intel.com>
To: daniel@iogearbox.net, ast@fb.com
Cc: netdev@vger.kernel.org, ard.biesheuvel@linaro.org,
dave.hansen@intel.com, kristen@linux.intel.com,
Rick Edgecombe <rick.p.edgecombe@intel.com>
Subject: [RFC PATCH 4/4] bpf, x64: Enable unprivlidged jit in vmalloc
Date: Tue, 5 Feb 2019 14:51:03 -0800 [thread overview]
Message-ID: <20190205225103.28296-5-rick.p.edgecombe@intel.com> (raw)
In-Reply-To: <20190205225103.28296-1-rick.p.edgecombe@intel.com>
This enables unprivlidged JIT allocations to be made in vmalloc space
when the bpf jit limit is exceeded.
The logic is we use module space unless it is full or we are not
CAP_SYS_ADMIN and bpf_jit_limit is exceeded, in which case we use vmalloc
space. So vmalloc is only used when either the insertion would fail, or
BPF would fallback to the interpreter.
In the case of using vmalloc, it is not charged against bpf_jit_limit.
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: Alexei Starovoitov <ast@fb.com>
Signed-off-by: Rick Edgecombe <rick.p.edgecombe@intel.com>
---
arch/x86/net/bpf_jit_comp.c | 32 ++++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+)
diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
index c9781d471e31..66d2b32a1db1 100644
--- a/arch/x86/net/bpf_jit_comp.c
+++ b/arch/x86/net/bpf_jit_comp.c
@@ -1118,6 +1118,38 @@ struct x64_jit_data {
struct jit_context ctx;
};
+void *bpf_jit_alloc_exec(unsigned long size)
+{
+ void *ret;
+ u32 pages = size / PAGE_SIZE;
+
+ /*
+ * The logic is we use module space unless it is full or we are not
+ * CAP_SYS_ADMIN and bpf_jit_limit is exceeded, in which case we use
+ * vmalloc space.
+ */
+ if (bpf_jit_charge_modmem(pages))
+ return vmalloc_exec(size);
+
+ ret = module_alloc(size);
+
+ if (!ret) {
+ bpf_jit_uncharge_modmem(pages);
+ /* If module space is full, try vmalloc */
+ return vmalloc_exec(size);
+ }
+
+ return ret;
+}
+
+void bpf_jit_free_exec(void *addr)
+{
+ if (is_vmalloc_addr(addr))
+ vfree(addr);
+ else
+ module_memfree(addr);
+}
+
struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog)
{
struct bpf_binary_header *header = NULL;
--
2.17.1
next prev parent reply other threads:[~2019-02-05 22:54 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-05 22:50 [RFC PATCH 0/4] Initial support for allocating BPF JITs in vmalloc for x86 Rick Edgecombe
2019-02-05 22:51 ` [RFC PATCH 1/4] bpf, x64: Implement BPF call retpoline Rick Edgecombe
2019-02-05 22:51 ` [RFC PATCH 2/4] bpf, x64: Increase distance for bpf calls Rick Edgecombe
2019-02-05 22:51 ` [RFC PATCH 3/4] bpf: Charge bpf jit limit in bpf_jit_alloc_exec Rick Edgecombe
2019-02-05 22:51 ` Rick Edgecombe [this message]
2019-02-06 0:35 ` [RFC PATCH 0/4] Initial support for allocating BPF JITs in vmalloc for x86 Alexei Starovoitov
2019-02-06 1:11 ` Edgecombe, Rick P
2019-02-06 1:40 ` Alexei Starovoitov
2019-02-06 15:38 ` Daniel Borkmann
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=20190205225103.28296-5-rick.p.edgecombe@intel.com \
--to=rick.p.edgecombe@intel.com \
--cc=ard.biesheuvel@linaro.org \
--cc=ast@fb.com \
--cc=daniel@iogearbox.net \
--cc=dave.hansen@intel.com \
--cc=kristen@linux.intel.com \
--cc=netdev@vger.kernel.org \
/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