From: Puranjay Mohan <puranjay12@gmail.com>
To: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org,
martin.lau@linux.dev, song@kernel.org, catalin.marinas@arm.com,
mark.rutland@arm.com, bpf@vger.kernel.org, kpsingh@kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org
Cc: puranjay12@gmail.com
Subject: [PATCH bpf-next v4 1/3] bpf: make bpf_prog_pack allocator portable
Date: Mon, 26 Jun 2023 08:58:09 +0000 [thread overview]
Message-ID: <20230626085811.3192402-2-puranjay12@gmail.com> (raw)
In-Reply-To: <20230626085811.3192402-1-puranjay12@gmail.com>
The bpf_prog_pack allocator currently uses module_alloc() and
module_memfree() to allocate and free memory. This is not portable
because different architectures use different methods for allocating
memory for BPF programs. Like ARM64 uses vmalloc()/vfree().
Use bpf_jit_alloc_exec() and bpf_jit_free_exec() for memory management
in bpf_prog_pack allocator. Other architectures can override these with
their implementation and will be able to use bpf_prog_pack directly.
Signed-off-by: Puranjay Mohan <puranjay12@gmail.com>
Acked-by: Song Liu <song@kernel.org>
---
Changes in V3 => v4
- No changes
Changes in V2 => V3:
- No changes
Changes in v1 => v2:
- No code changes.
- Added Acked-by: Song Liu <song@kernel.org>
kernel/bpf/core.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
index dc85240a0134..599136cb5096 100644
--- a/kernel/bpf/core.c
+++ b/kernel/bpf/core.c
@@ -860,7 +860,7 @@ static struct bpf_prog_pack *alloc_new_pack(bpf_jit_fill_hole_t bpf_fill_ill_ins
GFP_KERNEL);
if (!pack)
return NULL;
- pack->ptr = module_alloc(BPF_PROG_PACK_SIZE);
+ pack->ptr = bpf_jit_alloc_exec(BPF_PROG_PACK_SIZE);
if (!pack->ptr) {
kfree(pack);
return NULL;
@@ -884,7 +884,7 @@ void *bpf_prog_pack_alloc(u32 size, bpf_jit_fill_hole_t bpf_fill_ill_insns)
mutex_lock(&pack_mutex);
if (size > BPF_PROG_PACK_SIZE) {
size = round_up(size, PAGE_SIZE);
- ptr = module_alloc(size);
+ ptr = bpf_jit_alloc_exec(size);
if (ptr) {
bpf_fill_ill_insns(ptr, size);
set_vm_flush_reset_perms(ptr);
@@ -922,7 +922,7 @@ void bpf_prog_pack_free(struct bpf_binary_header *hdr)
mutex_lock(&pack_mutex);
if (hdr->size > BPF_PROG_PACK_SIZE) {
- module_memfree(hdr);
+ bpf_jit_free_exec(hdr);
goto out;
}
@@ -946,7 +946,7 @@ void bpf_prog_pack_free(struct bpf_binary_header *hdr)
if (bitmap_find_next_zero_area(pack->bitmap, BPF_PROG_CHUNK_COUNT, 0,
BPF_PROG_CHUNK_COUNT, 0) == 0) {
list_del(&pack->list);
- module_memfree(pack->ptr);
+ bpf_jit_free_exec(pack->ptr);
kfree(pack);
}
out:
--
2.40.1
next prev parent reply other threads:[~2023-06-26 9:03 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-26 8:58 [PATCH bpf-next v4 0/3] bpf, arm64: use BPF prog pack allocator in BPF JIT Puranjay Mohan
2023-06-26 8:58 ` Puranjay Mohan [this message]
2023-06-26 8:58 ` [PATCH bpf-next v4 2/3] arm64: patching: Add aarch64_insn_copy() Puranjay Mohan
2023-06-26 8:58 ` [PATCH bpf-next v4 3/3] bpf, arm64: use bpf_jit_binary_pack_alloc Puranjay Mohan
2023-08-15 14:09 ` Puranjay Mohan
2023-08-16 13:25 ` Daniel Borkmann
2023-06-30 17:20 ` [PATCH bpf-next v4 0/3] bpf, arm64: use BPF prog pack allocator in BPF JIT Florent Revest
2023-07-03 16:40 ` Daniel Borkmann
2023-07-03 17:15 ` Mark Rutland
2023-07-03 17:54 ` Daniel Borkmann
2023-07-17 7:50 ` Puranjay Mohan
2023-07-30 17:22 ` Puranjay Mohan
2023-08-02 21:02 ` Alexei Starovoitov
2023-08-03 11:13 ` Mark Rutland
2023-08-03 16:15 ` Alexei Starovoitov
2023-08-03 16:32 ` Florent Revest
2023-08-04 15:11 ` Puranjay Mohan
2023-11-02 15:59 ` Mark Rutland
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=20230626085811.3192402-2-puranjay12@gmail.com \
--to=puranjay12@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=catalin.marinas@arm.com \
--cc=daniel@iogearbox.net \
--cc=kpsingh@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=martin.lau@linux.dev \
--cc=song@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