From: Jiri Olsa <olsajiri@gmail.com>
To: Song Liu <song@kernel.org>
Cc: bpf@vger.kernel.org, ast@kernel.org, daniel@iogearbox.net,
andrii@kernel.org, martin.lau@kernel.org, kernel-team@meta.com,
iii@linux.ibm.com, bjorn@kernel.org
Subject: Re: [PATCH v3 bpf-next 8/8] x86, bpf: Use bpf_prog_pack for bpf trampoline
Date: Wed, 27 Sep 2023 15:16:11 +0200 [thread overview]
Message-ID: <ZRQrG7ve8MRKD6xT@krava> (raw)
In-Reply-To: <20230926190020.1111575-9-song@kernel.org>
On Tue, Sep 26, 2023 at 12:00:20PM -0700, Song Liu wrote:
SNIP
> @@ -2665,25 +2672,61 @@ static int __arch_prepare_bpf_trampoline(struct bpf_tramp_image *im, void *image
> if (flags & BPF_TRAMP_F_SKIP_FRAME)
> /* skip our return address and return to parent */
> EMIT4(0x48, 0x83, 0xC4, 8); /* add rsp, 8 */
> - emit_return(&prog, prog);
> + emit_return(&prog, image + (prog - (u8 *)rw_image));
> /* Make sure the trampoline generation logic doesn't overflow */
> - if (WARN_ON_ONCE(prog > (u8 *)image_end - BPF_INSN_SAFETY)) {
> + if (WARN_ON_ONCE(prog > (u8 *)rw_image_end - BPF_INSN_SAFETY)) {
> ret = -EFAULT;
> goto cleanup;
> }
> - ret = prog - (u8 *)image + BPF_INSN_SAFETY;
> + ret = prog - (u8 *)rw_image + BPF_INSN_SAFETY;
>
> cleanup:
> kfree(branches);
> return ret;
> }
>
> +void *arch_alloc_bpf_trampoline(int size)
> +{
> + return bpf_prog_pack_alloc(size, jit_fill_hole);
> +}
> +
> +void arch_free_bpf_trampoline(void *image, int size)
> +{
> + bpf_prog_pack_free(image, size);
> +}
> +
> +void arch_protect_bpf_trampoline(void *image, int size)
> +{
> +}
> +
> +void arch_unprotect_bpf_trampoline(void *image, int size)
> +{
> +}
seems bit confusing having empty non weak functions to overload
the weak versions IIUC
would maybe some other way fit better than weak functions in here?
like having arch specific macro to use bpf_prog_pack_alloc for
trampoline allocation
feel free to disregard if you have already investigated this ;-)
jirka
> +
> int arch_prepare_bpf_trampoline(struct bpf_tramp_image *im, void *image, void *image_end,
> const struct btf_func_model *m, u32 flags,
> struct bpf_tramp_links *tlinks,
> void *func_addr)
> {
> - return __arch_prepare_bpf_trampoline(im, image, image_end, m, flags, tlinks, func_addr);
> + void *rw_image, *tmp;
> + int ret;
> + u32 size = image_end - image;
> +
> + rw_image = bpf_jit_alloc_exec(size);
> + if (!rw_image)
> + return -ENOMEM;
> +
> + ret = __arch_prepare_bpf_trampoline(im, rw_image, rw_image + size, image, m,
> + flags, tlinks, func_addr);
> + if (ret < 0)
> + goto out;
> +
> + tmp = bpf_arch_text_copy(image, rw_image, size);
> + if (IS_ERR(tmp))
> + ret = PTR_ERR(tmp);
> +out:
> + bpf_jit_free_exec(rw_image);
> + return ret;
> }
>
> int arch_bpf_trampoline_size(const struct btf_func_model *m, u32 flags,
> @@ -2701,8 +2744,8 @@ int arch_bpf_trampoline_size(const struct btf_func_model *m, u32 flags,
> if (!image)
> return -ENOMEM;
>
> - ret = __arch_prepare_bpf_trampoline(&im, image, image + PAGE_SIZE, m, flags,
> - tlinks, func_addr);
> + ret = __arch_prepare_bpf_trampoline(&im, image, image + PAGE_SIZE, image,
> + m, flags, tlinks, func_addr);
> bpf_jit_free_exec(image);
> return ret;
> }
> --
> 2.34.1
>
>
next prev parent reply other threads:[~2023-09-27 13:16 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-26 19:00 [PATCH v3 bpf-next 0/8] Allocate bpf trampoline on bpf_prog_pack Song Liu
2023-09-26 19:00 ` [PATCH v3 bpf-next 1/8] s390/bpf: Let arch_prepare_bpf_trampoline return program size Song Liu
2023-09-26 19:00 ` [PATCH v3 bpf-next 2/8] bpf: Let bpf_prog_pack_free handle any pointer Song Liu
2023-09-27 18:29 ` Björn Töpel
2023-09-26 19:00 ` [PATCH v3 bpf-next 3/8] bpf: Adjust argument names of arch_prepare_bpf_trampoline() Song Liu
2023-09-26 19:00 ` [PATCH v3 bpf-next 4/8] bpf: Add helpers for trampoline image management Song Liu
2023-09-26 19:00 ` [PATCH v3 bpf-next 5/8] bpf, x86: Adjust arch_prepare_bpf_trampoline return value Song Liu
2023-09-26 19:00 ` [PATCH v3 bpf-next 6/8] bpf: Add arch_bpf_trampoline_size() Song Liu
2023-09-26 19:00 ` [PATCH v3 bpf-next 7/8] bpf: Use arch_bpf_trampoline_size Song Liu
2023-09-26 19:00 ` [PATCH v3 bpf-next 8/8] x86, bpf: Use bpf_prog_pack for bpf trampoline Song Liu
2023-09-27 13:16 ` Jiri Olsa [this message]
2023-09-27 15:47 ` Song Liu
2023-10-04 15:40 ` [PATCH v3 bpf-next 0/8] Allocate bpf trampoline on bpf_prog_pack patchwork-bot+netdevbpf
2023-10-04 15:50 ` Alexei Starovoitov
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=ZRQrG7ve8MRKD6xT@krava \
--to=olsajiri@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bjorn@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=iii@linux.ibm.com \
--cc=kernel-team@meta.com \
--cc=martin.lau@kernel.org \
--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