public inbox for bpf@vger.kernel.org
 help / color / mirror / Atom feed
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
Subject: Re: [PATCH bpf-next 6/8] bpf: Add arch_bpf_trampoline_size()
Date: Thu, 21 Sep 2023 16:07:13 +0200	[thread overview]
Message-ID: <ZQxOEVFUFFgYpqtx@krava> (raw)
In-Reply-To: <20230920053158.3175043-7-song@kernel.org>

On Tue, Sep 19, 2023 at 10:31:56PM -0700, Song Liu wrote:

SNIP

> +int arch_bpf_trampoline_size(const struct btf_func_model *m, u32 flags,
> +			     struct bpf_tramp_links *tlinks, void *func_addr)
> +{
> +	struct bpf_tramp_image im;
> +	void *image;
> +	int ret;
> +
> +	/* Allocate a temporary buffer for __arch_prepare_bpf_trampoline().
> +	 * This will NOT cause fragmentation in direct map, as we do not
> +	 * call set_memory_*() on this buffer.
> +	 */
> +	image = bpf_jit_alloc_exec(PAGE_SIZE);
> +	if (!image)
> +		return -ENOMEM;
> +
> +	ret = __arch_prepare_bpf_trampoline(&im, image, image + PAGE_SIZE, m, flags,
> +					    tlinks, func_addr);
> +	bpf_jit_free_exec(image);
> +	if (ret < 0)
> +		return ret;
> +
> +	return ret;

this can be just 'return ret;'

jirka

> +}
> +
>  static int emit_bpf_dispatcher(u8 **pprog, int a, int b, s64 *progs, u8 *image, u8 *buf)
>  {
>  	u8 *jg_reloc, *prog = *pprog;
> diff --git a/include/linux/bpf.h b/include/linux/bpf.h
> index 548f3ef34ba1..5bbac549b0a0 100644
> --- a/include/linux/bpf.h
> +++ b/include/linux/bpf.h
> @@ -1087,6 +1087,8 @@ void *arch_alloc_bpf_trampoline(int size);
>  void arch_free_bpf_trampoline(void *image, int size);
>  void arch_protect_bpf_trampoline(void *image, int size);
>  void arch_unprotect_bpf_trampoline(void *image, int size);
> +int arch_bpf_trampoline_size(const struct btf_func_model *m, u32 flags,
> +			     struct bpf_tramp_links *tlinks, void *func_addr);
>  
>  u64 notrace __bpf_prog_enter_sleepable_recur(struct bpf_prog *prog,
>  					     struct bpf_tramp_run_ctx *run_ctx);
> diff --git a/kernel/bpf/trampoline.c b/kernel/bpf/trampoline.c
> index 5509bdf98067..285c5b7c1ea4 100644
> --- a/kernel/bpf/trampoline.c
> +++ b/kernel/bpf/trampoline.c
> @@ -1070,6 +1070,12 @@ void __weak arch_unprotect_bpf_trampoline(void *image, int size)
>  	set_memory_rw((long)image, 1);
>  }
>  
> +int __weak arch_bpf_trampoline_size(const struct btf_func_model *m, u32 flags,
> +				    struct bpf_tramp_links *tlinks, void *func_addr)
> +{
> +	return -ENOTSUPP;
> +}
> +
>  static int __init init_trampolines(void)
>  {
>  	int i;
> -- 
> 2.34.1
> 
> 

  parent reply	other threads:[~2023-09-21 17:22 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-20  5:31 [PATCH bpf-next 0/8] Allocate bpf trampoline on bpf_prog_pack Song Liu
2023-09-20  5:31 ` [PATCH bpf-next 1/8] s390/bpf: Let arch_prepare_bpf_trampoline return program size Song Liu
2023-09-20  5:31 ` [PATCH bpf-next 2/8] bpf: Let bpf_prog_pack_free handle any pointer Song Liu
2023-09-20  5:31 ` [PATCH bpf-next 3/8] bpf: Adjust argument names of arch_prepare_bpf_trampoline() Song Liu
2023-09-20  5:31 ` [PATCH bpf-next 4/8] bpf: Add helpers for trampoline image management Song Liu
2023-09-20 16:31   ` Song Liu
2023-09-20  5:31 ` [PATCH bpf-next 5/8] bpf, x86: Adjust arch_prepare_bpf_trampoline return value Song Liu
2023-09-20  5:31 ` [PATCH bpf-next 6/8] bpf: Add arch_bpf_trampoline_size() Song Liu
2023-09-20  7:39   ` Xu Kuohai
2023-09-20 15:56     ` Song Liu
2023-09-21  0:45   ` Pu Lehui
2023-09-21  5:12     ` Song Liu
2023-09-21 14:07   ` Jiri Olsa [this message]
2023-09-21 14:24   ` Jiri Olsa
2023-09-21 14:28     ` Jiri Olsa
2023-09-20  5:31 ` [PATCH bpf-next 7/8] bpf: Use arch_bpf_trampoline_size for trampoline Song Liu
2023-09-20  5:31 ` [PATCH bpf-next 8/8] x86, bpf: Use bpf_prog_pack for bpf trampoline Song Liu

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=ZQxOEVFUFFgYpqtx@krava \
    --to=olsajiri@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --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