All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrii Nakryiko <andrii.nakryiko@gmail.com>
To: Ilya Leoshkevich <iii@linux.ibm.com>
Cc: Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Heiko Carstens <hca@linux.ibm.com>,
	Vasily Gorbik <gor@linux.ibm.com>,
	Christian Borntraeger <borntraeger@linux.ibm.com>,
	Alexander Gordeev <agordeev@linux.ibm.com>,
	bpf <bpf@vger.kernel.org>
Subject: Re: [PATCH bpf-next v5 09/10] libbpf: Fix accessing the first syscall argument on arm64
Date: Tue, 8 Feb 2022 21:39:35 -0800	[thread overview]
Message-ID: <CAEf4BzYunGCapVMZVFznh_qsRmOPdunvk2ZZfJOVVo29vrZwOw@mail.gmail.com> (raw)
In-Reply-To: <20220209021745.2215452-10-iii@linux.ibm.com>

On Tue, Feb 8, 2022 at 6:18 PM Ilya Leoshkevich <iii@linux.ibm.com> wrote:
>
> On arm64, the first syscall argument should be accessed via orig_x0
> (see arch/arm64/include/asm/syscall.h). Currently regs[0] is used
> instead, leading to bpf_syscall_macro test failure.
>
> orig_x0 cannot be added to struct user_pt_regs, since its layout is a
> part of the ABI. Therefore provide access to it only through
> PT_REGS_PARM1_CORE_SYSCALL() by using a struct pt_regs flavor.
>
> Reported-by: Heiko Carstens <hca@linux.ibm.com>
> Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
> ---
>  tools/lib/bpf/bpf_tracing.h | 10 ++++++++++
>  1 file changed, 10 insertions(+)
>
> diff --git a/tools/lib/bpf/bpf_tracing.h b/tools/lib/bpf/bpf_tracing.h
> index f364f1f4710e..928f85f7961c 100644
> --- a/tools/lib/bpf/bpf_tracing.h
> +++ b/tools/lib/bpf/bpf_tracing.h
> @@ -142,8 +142,18 @@
>
>  #elif defined(bpf_target_arm64)
>
> +struct pt_regs___arm64 {
> +       unsigned long orig_x0;
> +} __attribute__((preserve_access_index));
> +

I just realized that this will probably break anyone who's using old
Clang to compile a non-CORE BPF program because preserve_access_index
attribute will be unknown.

But we don't have to use __attribute__((preserve_access_index)) here,
because we use BPF_CORE_READ() in those macro, which will make
accesses CO-RE-relocatable anyways. So I dropped
__attribute__((preserve_access_index)) for better backwards
compatibility.

>  /* arm64 provides struct user_pt_regs instead of struct pt_regs to userspace */
>  #define __PT_REGS_CAST(x) ((const struct user_pt_regs *)(x))
> +#define PT_REGS_PARM1_SYSCALL(x) ({ \
> +       _Pragma("GCC error \"PT_REGS_PARM1_SYSCALL() is not supported on arm64, use PT_REGS_PARM1_CORE_SYSCALL() instead\""); \
> +       0l; \
> +})

I shortened message to just "use PT_REGS_PARM1_CORE_SYSCALL() instead"
and made it into a single-liner

> +#define PT_REGS_PARM1_CORE_SYSCALL(x) \
> +       BPF_CORE_READ((const struct pt_regs___arm64 *)(x), orig_x0)

also made this into a single-liner


>  #define __PT_PARM1_REG regs[0]
>  #define __PT_PARM2_REG regs[1]
>  #define __PT_PARM3_REG regs[2]
> --
> 2.34.1
>

  reply	other threads:[~2022-02-09  5:49 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-09  2:17 [PATCH bpf-next v5 00/10] Fix accessing syscall arguments Ilya Leoshkevich
2022-02-09  2:17 ` [PATCH bpf-next v5 01/10] selftests/bpf: Fix an endianness issue in bpf_syscall_macro test Ilya Leoshkevich
2022-02-09  2:17 ` [PATCH bpf-next v5 02/10] libbpf: Add PT_REGS_SYSCALL_REGS macro Ilya Leoshkevich
2022-02-09  2:17 ` [PATCH bpf-next v5 03/10] selftests/bpf: Use PT_REGS_SYSCALL_REGS in bpf_syscall_macro Ilya Leoshkevich
2022-02-09  2:17 ` [PATCH bpf-next v5 04/10] libbpf: Fix accessing syscall arguments on powerpc Ilya Leoshkevich
2022-02-09  2:17 ` [PATCH bpf-next v5 05/10] libbpf: Fix riscv register names Ilya Leoshkevich
2022-02-09  2:17 ` [PATCH bpf-next v5 06/10] libbpf: Fix accessing syscall arguments on riscv Ilya Leoshkevich
2022-02-09  2:17 ` [PATCH bpf-next v5 07/10] selftests/bpf: Skip test_bpf_syscall_macro:syscall_arg1 on arm64 and s390 Ilya Leoshkevich
2022-02-09  2:17 ` [PATCH bpf-next v5 08/10] libbpf: Allow overriding PT_REGS_PARM1{_CORE}_SYSCALL Ilya Leoshkevich
2022-02-09  5:39   ` Andrii Nakryiko
2022-02-09  2:17 ` [PATCH bpf-next v5 09/10] libbpf: Fix accessing the first syscall argument on arm64 Ilya Leoshkevich
2022-02-09  5:39   ` Andrii Nakryiko [this message]
2022-02-09  2:17 ` [PATCH bpf-next v5 10/10] libbpf: Fix accessing the first syscall argument on s390 Ilya Leoshkevich
2022-02-09  5:39   ` Andrii Nakryiko
2022-02-09  5:39 ` [PATCH bpf-next v5 00/10] Fix accessing syscall arguments Andrii Nakryiko
2022-02-09  5:40 ` patchwork-bot+netdevbpf

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=CAEf4BzYunGCapVMZVFznh_qsRmOPdunvk2ZZfJOVVo29vrZwOw@mail.gmail.com \
    --to=andrii.nakryiko@gmail.com \
    --cc=agordeev@linux.ibm.com \
    --cc=ast@kernel.org \
    --cc=borntraeger@linux.ibm.com \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=gor@linux.ibm.com \
    --cc=hca@linux.ibm.com \
    --cc=iii@linux.ibm.com \
    /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.