public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Puranjay Mohan <puranjay@kernel.org>
To: Xu Kuohai <xukuohai@huaweicloud.com>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	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>,
	John Fastabend <john.fastabend@gmail.com>,
	KP Singh <kpsingh@kernel.org>,
	Stanislav Fomichev <sdf@google.com>, Hao Luo <haoluo@google.com>,
	Jiri Olsa <jolsa@kernel.org>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Will Deacon <will@kernel.org>, Mykola Lysenko <mykolal@fb.com>,
	Shuah Khan <shuah@kernel.org>,
	bpf@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org
Subject: Re: [PATCH bpf-next v2] arm64, bpf: Add 12-argument support for bpf trampoline
Date: Mon, 08 Jul 2024 09:00:58 +0000	[thread overview]
Message-ID: <mb61py16c45rp.fsf@kernel.org> (raw)
In-Reply-To: <5c43f532-c849-41c9-92dc-83925f5835d7@huaweicloud.com>

[-- Attachment #1: Type: text/plain, Size: 2852 bytes --]

Xu Kuohai <xukuohai@huaweicloud.com> writes:

> On 7/5/2024 8:53 PM, Puranjay Mohan wrote:
>> The arm64 bpf JIT currently supports attaching the trampoline to
>> functions with <= 8 arguments. This is because up to 8 arguments can be
>> passed in registers r0-r7. If there are more than 8 arguments then the
>> 9th and later arguments are passed on the stack, with SP pointing to the
>> first stacked argument. See aapcs64[1] for more details.
>> 
>> If the 8th argument is a structure of size > 8B, then it is passed fully
>> on stack and r7 is not used for passing any argument. If there is a 9th
>> argument, it will be passed on the stack, even though r7 is available.
>> 
>> Add the support of storing and restoring arguments passed on the stack
>> to the arm64 bpf trampoline. This will allow attaching the trampoline to
>> functions that take up to 12 arguments.
>> 
>> [1] https://github.com/ARM-software/abi-aa/blob/main/aapcs64/aapcs64.rst#parameter-passing
>> 
>> Signed-off-by: Puranjay Mohan <puranjay@kernel.org>
>> ---
>> Changes in V1 -> V2:
>> V1: https://lore.kernel.org/all/20240704173227.130491-1-puranjay@kernel.org/
>> - Fixed the argument handling for composite types (structs)
>> ---
>>   arch/arm64/net/bpf_jit_comp.c                | 139 ++++++++++++++-----
>>   tools/testing/selftests/bpf/DENYLIST.aarch64 |   3 -
>>   2 files changed, 107 insertions(+), 35 deletions(-)
>> 

[SNIP]

>>   fill_link_info/kprobe_multi_invalid_ubuff        # bpf_program__attach_kprobe_multi_opts unexpected error: -95
>
> It looks like this patch, similar to [1], also does not handle
> parameter alignment properly [2].
>
> For example:
>
> int func(__int128 a, __int128 b, __int128 c, int64_t d, __int128 e, int64_t f, __int128 g)
> {
> }
>
> parameter a~d are passed through register x0~x6, while parameter
> e~g are passed through stack. Since __int128 is 16-byte aligned,
> parameter e, f, and g should be placed at sp + 0, +16, and +32
> respectively, with 8 bytes **padding** between f and g.
>
>
> And the compiler's alignment or packed attribute may make things
> worse, causing parameters to be placed on the stack at positions
> that are not naturally aligned.

Hi Xu,
Thanks for explaining this. I was not aware that you have already sent a
patch[1] to add this support to arm64.

So, I see that it will be non-trivial to calculate padding for each
argument passed on the stack. If you are not planning to work on this
then I can try to implement it.

Alsoi, do we currently have a selftest that checks for this edge case? if
not I can try to add that too.

Thanks,
Puranjay

> [1] https://lore.kernel.org/bpf/20230917150752.69612-1-xukuohai@huaweicloud.com/
> [2] https://lore.kernel.org/bpf/CABRcYmLtk8aQEzoUFw+j5Rdd-MXf-q+i7RHXZtu-skjRz11ZDw@mail.gmail.com/

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 255 bytes --]

  reply	other threads:[~2024-07-08  9:01 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-05 12:53 [PATCH bpf-next v2] arm64, bpf: Add 12-argument support for bpf trampoline Puranjay Mohan
2024-07-06  9:28 ` Xu Kuohai
2024-07-08  9:00   ` Puranjay Mohan [this message]
2024-07-08  9:33     ` Xu Kuohai
2025-02-21 16:58 ` Alexis Lothoré

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=mb61py16c45rp.fsf@kernel.org \
    --to=puranjay@kernel.org \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=haoluo@google.com \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kpsingh@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=mykolal@fb.com \
    --cc=sdf@google.com \
    --cc=shuah@kernel.org \
    --cc=song@kernel.org \
    --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