From: Ilya Leoshkevich <iii@linux.ibm.com>
To: Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii.nakryiko@gmail.com>,
Heiko Carstens <hca@linux.ibm.com>,
Vasily Gorbik <gor@linux.ibm.com>,
Christian Borntraeger <borntraeger@linux.ibm.com>,
Alexander Gordeev <agordeev@linux.ibm.com>
Cc: bpf@vger.kernel.org, Ilya Leoshkevich <iii@linux.ibm.com>
Subject: [PATCH bpf-next v5 09/10] libbpf: Fix accessing the first syscall argument on arm64
Date: Wed, 9 Feb 2022 03:17:44 +0100 [thread overview]
Message-ID: <20220209021745.2215452-10-iii@linux.ibm.com> (raw)
In-Reply-To: <20220209021745.2215452-1-iii@linux.ibm.com>
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));
+
/* 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; \
+})
+#define PT_REGS_PARM1_CORE_SYSCALL(x) \
+ BPF_CORE_READ((const struct pt_regs___arm64 *)(x), orig_x0)
#define __PT_PARM1_REG regs[0]
#define __PT_PARM2_REG regs[1]
#define __PT_PARM3_REG regs[2]
--
2.34.1
next prev parent reply other threads:[~2022-02-09 2:39 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 ` Ilya Leoshkevich [this message]
2022-02-09 5:39 ` [PATCH bpf-next v5 09/10] libbpf: Fix accessing the first syscall argument on arm64 Andrii Nakryiko
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=20220209021745.2215452-10-iii@linux.ibm.com \
--to=iii@linux.ibm.com \
--cc=agordeev@linux.ibm.com \
--cc=andrii.nakryiko@gmail.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 \
/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;
as well as URLs for NNTP newsgroup(s).