All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eduard Zingerman <eddyz87@gmail.com>
To: "Alexis Lothoré" <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>,
	 "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>,  "Jiri Olsa" <jolsa@kernel.org>,
	 "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 3/4] bpf/selftests: add tests to validate proper arguments alignment on ARM64
Date: Mon, 28 Apr 2025 09:52:35 -0700	[thread overview]
Message-ID: <m21ptcmdnw.fsf@gmail.com> (raw)
In-Reply-To: <D9I6TQN2I6B1.QC4FFHEWAURZ@bootlin.com> ("Alexis Lothoré"'s message of "Mon, 28 Apr 2025 12:08:32 +0200")

Alexis Lothoré <alexis.lothore@bootlin.com> writes:

[...]

>> The function listened to is defined as accepting 'struct bpf_testmod_struct_arg_7',
>> at the same time this function uses 'struct bpf_testmod_struct_arg_5'.
>
> That's not an accidental mistake, those are in fact the same definition.
> bpf_testmod_struct_arg_7 is the kernel side definition in bpf_testmod.c:
>
> struct bpf_testmod_struct_arg_7 {
> 	__int128 a;
> };
>
> and struct bpf_testmode_struct_arg_5 is the one defined in the bpf test
> program:
>
> struct bpf_testmod_struct_arg_5 {
> 	__int128 a;
> };

Apologies, but I'm still confused:
- I apply this series on top of:
  224ee86639f5 ("Merge git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf after rc4")

- line 12 of tracing_struct_many_args.c has the following definition:

  struct bpf_testmod_struct_arg_5 {
         char a;
         short b;
         int c;
         long d;
  };

- line 135 of the same file has the following definition:

   SEC("fentry/bpf_testmod_test_struct_arg_11")
   int BPF_PROG2(test_struct_many_args_9, struct bpf_testmod_struct_arg_5, a,
                 struct bpf_testmod_struct_arg_5, b,
                 struct bpf_testmod_struct_arg_5, c,
                 struct bpf_testmod_struct_arg_5, d, int, e,
                 struct bpf_testmod_struct_arg_5, f)

- line 70 of tools/testing/selftests/bpf/test_kmods/bpf_testmod.c:

   struct bpf_testmod_struct_arg_7 {
         __int128 a;
   };

- line 152 of the same file:

  noinline int bpf_testmod_test_struct_arg_11(struct bpf_testmod_struct_arg_7 a,
                                              struct bpf_testmod_struct_arg_7 b,
                                              struct bpf_testmod_struct_arg_7 c,
                                              struct bpf_testmod_struct_arg_7 d,
                                              short e,
                                              struct bpf_testmod_struct_arg_7 f)

Do I use a wrong base to apply the series?

[...]

>> Nevertheless, the assertion persists even with correct types.
>
> So I digged a bit further to better share my observations here. This is the
> function stack when entering the trampoline after having triggered the
> target function execution:
>
> (gdb) x/64b $rbp+0x18
> 0xffffc9000015fd60:     41      0       0       0       0       0       0       0
> 0xffffc9000015fd68:     0       0       0       0       0       0       0       0
> 0xffffc9000015fd70:     42      0       0       0       0       0       0       0
> 0xffffc9000015fd78:     35      0       0       0       0       0       0       0
> 0xffffc9000015fd80:     43      0       0       0       0       0       0       0
> 0xffffc9000015fd88:     0       0       0       0       0       0       0       0
>
> We see the arguments that did not fit in registers, so d, e and f.
>
> This is the ebpf context generated by the trampoline for the fentry
> program, from the content of the stack above + the registers:
>
> (gdb) x/128b $rbp-60
> 0xffffc9000015fce8:     38      0       0       0       0       0       0       0
> 0xffffc9000015fcf0:     0       0       0       0       0       0       0       0
> 0xffffc9000015fcf8:     39      0       0       0       0       0       0       0
> 0xffffc9000015fd00:     0       0       0       0       0       0       0       0
> 0xffffc9000015fd08:     40      0       0       0       0       0       0       0
> 0xffffc9000015fd10:     0       0       0       0       0       0       0       0
> 0xffffc9000015fd18:     41      0       0       0       0       0       0       0
> 0xffffc9000015fd20:     0       0       0       0       0       0       0       0
> 0xffffc9000015fd28:     42      0       0       0       0       0       0       0
> 0xffffc9000015fd30:     35      0       0       0       0       0       0       0
> 0xffffc9000015fd38:     43      0       0       0       0       0       0       0
> 0xffffc9000015fd40:     37      0       0       0       0       0       0       0
>
> So IIUC, this is wrong because the "e" variable in the bpf program being
> an int (and about to receive value 42), it occupies only 1 "tracing context
> 8-byte slot", so the value 43 (representing the content for variable f),
> should be right after it, at 0xffffc9000015fd30. What we have instead is a
> hole, very likely because we copied silently the alignment from the
> original function call (and I guess this 35 value is a remnant from the
> previous test, which uses values from 27 to 37)

Interesting, thank you for the print outs.

> Regardless of this issue, based on discussion from last week, I think I'll
> go for the implementation suggested by Alexei: handling the nominal cases,
> and detecting and blocking the non trivial cases (eg: structs passed on
> stack). It sounds reasonable as there seems to be no exisiting kernel
> function currently able to trigger those very specific cases, so it could
> be added later if this changes.

Yes, this makes sense.

  reply	other threads:[~2025-04-28 16:52 UTC|newest]

Thread overview: 32+ 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
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
2025-06-04  9:02           ` [Question] attributes encoding in BTF Alexis Lothoré
2025-06-04 17:31             ` 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 [this message]
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=m21ptcmdnw.fsf@gmail.com \
    --to=eddyz87@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=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=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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.