From: Jiri Olsa <olsajiri@gmail.com>
To: "Alexis Lothoré (eBPF Foundation)" <alexis.lothore@bootlin.com>
Cc: Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
John Fastabend <john.fastabend@gmail.com>,
Andrii Nakryiko <andrii@kernel.org>,
Martin KaFai Lau <martin.lau@linux.dev>,
Eduard Zingerman <eddyz87@gmail.com>, Song Liu <song@kernel.org>,
Yonghong Song <yonghong.song@linux.dev>,
KP Singh <kpsingh@kernel.org>,
Stanislav Fomichev <sdf@fomichev.me>, Hao Luo <haoluo@google.com>,
Puranjay Mohan <puranjay@kernel.org>,
Xu Kuohai <xukuohai@huaweicloud.com>,
Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will@kernel.org>, Mykola Lysenko <mykolal@fb.com>,
Shuah Khan <shuah@kernel.org>,
Maxime Coquelin <mcoquelin.stm32@gmail.com>,
Alexandre Torgue <alexandre.torgue@foss.st.com>,
Florent Revest <revest@chromium.org>,
Bastien Curutchet <bastien.curutchet@bootlin.com>,
ebpf@linuxfoundation.org,
Thomas Petazzoni <thomas.petazzoni@bootlin.com>,
bpf@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-kselftest@vger.kernel.org,
linux-stm32@st-md-mailman.stormreply.com
Subject: Re: [PATCH RFC bpf-next 1/4] bpf: add struct largest member size in func model
Date: Mon, 14 Apr 2025 13:04:41 +0200 [thread overview]
Message-ID: <Z_zryQkfmrSXYN4k@krava> (raw)
In-Reply-To: <20250411-many_args_arm64-v1-1-0a32fe72339e@bootlin.com>
On Fri, Apr 11, 2025 at 10:32:10PM +0200, Alexis Lothoré (eBPF Foundation) wrote:
> In order to properly JIT the trampolines needed to attach BPF programs
> to functions, some architectures like ARM64 need to know about the
> alignment needed for the function arguments. Such alignment can
> generally be deduced from the argument size, but that's not completely
> true for composite types. In the specific case of ARM64, the AAPCS64 ABI
> defines that a composite type which needs to be passed through stack
> must be aligned on the maximum between 8 and the largest alignment
> constraint of its first-level members. So the JIT compiler needs more
> information about the arguments to make sure to generate code that
> respects those alignment constraints.
>
> For struct arguments, add information about the size of the largest
> first-level member in the struct btf_func_model to allow the JIT
> compiler to guess the needed alignment. The information is quite
> specific, but it allows to keep arch-specific concerns (ie: guessing the
> final needed alignment for an argument) isolated in each JIT compiler.
>
> Signed-off-by: Alexis Lothoré (eBPF Foundation) <alexis.lothore@bootlin.com>
> ---
> include/linux/bpf.h | 1 +
> kernel/bpf/btf.c | 25 +++++++++++++++++++++++++
> 2 files changed, 26 insertions(+)
>
> diff --git a/include/linux/bpf.h b/include/linux/bpf.h
> index 3f0cc89c0622cb1a097999afb78c17102593b6bb..8b34dcf60a0ce09228ff761b962ab67b6a3e2263 100644
> --- a/include/linux/bpf.h
> +++ b/include/linux/bpf.h
> @@ -1106,6 +1106,7 @@ struct btf_func_model {
> u8 nr_args;
> u8 arg_size[MAX_BPF_FUNC_ARGS];
> u8 arg_flags[MAX_BPF_FUNC_ARGS];
> + u8 arg_largest_member_size[MAX_BPF_FUNC_ARGS];
> };
>
> /* Restore arguments before returning from trampoline to let original function
> diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
> index 16ba36f34dfab7531babf5753cab9f368cddefa3..5d40911ec90210086a6175d569abb6e52d75ad17 100644
> --- a/kernel/bpf/btf.c
> +++ b/kernel/bpf/btf.c
> @@ -7318,6 +7318,29 @@ static int __get_type_size(struct btf *btf, u32 btf_id,
> return -EINVAL;
> }
>
> +static u8 __get_largest_member_size(struct btf *btf, const struct btf_type *t)
> +{
> + const struct btf_member *member;
> + const struct btf_type *mtype;
> + u8 largest_member_size = 0;
> + int i;
> +
> + if (!__btf_type_is_struct(t))
> + return largest_member_size;
> +
> + for_each_member(i, t, member) {
> + mtype = btf_type_by_id(btf, member->type);
> + while (mtype && btf_type_is_modifier(mtype))
> + mtype = btf_type_by_id(btf, mtype->type);
> + if (!mtype)
> + return -EINVAL;
should we use __get_type_size for member->type instead ?
jirka
> + if (mtype->size > largest_member_size)
> + largest_member_size = mtype->size;
> + }
> +
> + return largest_member_size;
> +}
> +
> static u8 __get_type_fmodel_flags(const struct btf_type *t)
> {
> u8 flags = 0;
> @@ -7396,6 +7419,8 @@ int btf_distill_func_proto(struct bpf_verifier_log *log,
> }
> m->arg_size[i] = ret;
> m->arg_flags[i] = __get_type_fmodel_flags(t);
> + m->arg_largest_member_size[i] =
> + __get_largest_member_size(btf, t);
> }
> m->nr_args = nargs;
> return 0;
>
> --
> 2.49.0
>
next prev parent reply other threads:[~2025-04-14 11:14 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-11 20:32 [PATCH RFC bpf-next 0/4] bpf, arm64: support up to 12 arguments Alexis Lothoré (eBPF Foundation)
2025-04-11 20:32 ` [PATCH RFC bpf-next 1/4] bpf: add struct largest member size in func model Alexis Lothoré (eBPF Foundation)
2025-04-14 11:04 ` Jiri Olsa [this message]
2025-04-14 20:27 ` Alexis Lothoré
2025-04-16 21:24 ` Andrii Nakryiko
2025-04-17 7:14 ` Alexis Lothoré
2025-04-17 14:10 ` Xu Kuohai
2025-04-20 16:02 ` Alexis Lothoré
2025-04-21 2:14 ` Xu Kuohai
2025-04-23 15:38 ` Alexis Lothoré
2025-04-23 17:15 ` Andrii Nakryiko
2025-04-23 19:24 ` Alexis Lothoré
2025-04-24 12:00 ` Xu Kuohai
2025-04-24 13:38 ` Alexis Lothoré
2025-04-24 23:14 ` Alexei Starovoitov
2025-04-25 8:47 ` Alexis Lothoré
2025-04-25 9:23 ` Xu Kuohai
2025-04-28 7:11 ` Eduard Zingerman
[not found] ` <DADMLIVHMSSO.3AXSI5216WCT6@bootlin.com>
2025-06-04 17:31 ` [Question] attributes encoding in BTF Ihor Solodrai
2025-06-05 7:35 ` Alexis Lothoré
2025-06-05 16:09 ` Alexei Starovoitov
2025-06-06 7:45 ` Alexis Lothoré
2025-06-06 16:22 ` Alexei Starovoitov
2025-04-11 20:32 ` [PATCH RFC bpf-next 2/4] bpf, arm64: Support up to 12 function arguments Alexis Lothoré
2025-04-11 20:32 ` [PATCH RFC bpf-next 3/4] bpf/selftests: add tests to validate proper arguments alignment on ARM64 Alexis Lothoré (eBPF Foundation)
2025-04-28 7:01 ` Eduard Zingerman
2025-04-28 10:08 ` Alexis Lothoré
2025-04-28 16:52 ` Eduard Zingerman
2025-04-28 20:41 ` Alexis Lothoré
2025-04-29 9:49 ` Alexis Lothoré
2025-04-11 20:32 ` [PATCH RFC bpf-next 4/4] bpf/selftests: enable tracing tests for ARM64 Alexis Lothoré (eBPF Foundation)
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=Z_zryQkfmrSXYN4k@krava \
--to=olsajiri@gmail.com \
--cc=alexandre.torgue@foss.st.com \
--cc=alexis.lothore@bootlin.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bastien.curutchet@bootlin.com \
--cc=bpf@vger.kernel.org \
--cc=catalin.marinas@arm.com \
--cc=daniel@iogearbox.net \
--cc=ebpf@linuxfoundation.org \
--cc=eddyz87@gmail.com \
--cc=haoluo@google.com \
--cc=john.fastabend@gmail.com \
--cc=kpsingh@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-stm32@st-md-mailman.stormreply.com \
--cc=martin.lau@linux.dev \
--cc=mcoquelin.stm32@gmail.com \
--cc=mykolal@fb.com \
--cc=puranjay@kernel.org \
--cc=revest@chromium.org \
--cc=sdf@fomichev.me \
--cc=shuah@kernel.org \
--cc=song@kernel.org \
--cc=thomas.petazzoni@bootlin.com \
--cc=will@kernel.org \
--cc=xukuohai@huaweicloud.com \
--cc=yonghong.song@linux.dev \
/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