On RV64, as Ilya mentioned before [0], the first syscall parameter should be
accessed through orig_a0 (see arch/riscv64/include/asm/syscall.h),
otherwise it will cause selftests like bpf_syscall_macro, vmlinux,
test_lsm, etc. to fail on RV64.
Link: https://lore.kernel.org/bpf/20220209021745.2215452-1-iii@linux.ibm.com [0]
v3:
- Fix test case error.
v2: https://lore.kernel.org/all/20240831023646.1558629-1-pulehui@huaweicloud.com/
- Access first syscall argument with CO-RE direct read. (Andrii)
v1: https://lore.kernel.org/all/20240829133453.882259-1-pulehui@huaweicloud.com/
Pu Lehui (4):
libbpf: Access first syscall argument with CO-RE direct read on s390
libbpf: Access first syscall argument with CO-RE direct read on arm64
selftests/bpf: Enable test_bpf_syscall_macro:syscall_arg1 on s390 and
arm64
libbpf: Fix accessing first syscall argument on RV64
tools/lib/bpf/bpf_tracing.h | 17 ++++++++++++-----
.../bpf/prog_tests/test_bpf_syscall_macro.c | 4 ----
.../selftests/bpf/progs/bpf_syscall_macro.c | 2 --
3 files changed, 12 insertions(+), 11 deletions(-)
--
2.34.1
From: Pu Lehui <pulehui@huawei.com>
Considering that CO-RE direct read access to the first system call
argument is already available on s390 and arm64, let's enable
test_bpf_syscall_macro:syscall_arg1 on these architectures.
Signed-off-by: Pu Lehui <pulehui@huawei.com>
---
.../testing/selftests/bpf/prog_tests/test_bpf_syscall_macro.c | 4 ----
tools/testing/selftests/bpf/progs/bpf_syscall_macro.c | 2 --
2 files changed, 6 deletions(-)
@@ -43,9 +43,7 @@ int BPF_KPROBE(handle_sys_prctl)/* test for PT_REGS_PARM */-#if !defined(bpf_target_arm64) && !defined(bpf_target_s390)bpf_probe_read_kernel(&tmp,sizeof(tmp),&PT_REGS_PARM1_SYSCALL(real_regs));-#endifarg1=tmp;bpf_probe_read_kernel(&arg2,sizeof(arg2),&PT_REGS_PARM2_SYSCALL(real_regs));bpf_probe_read_kernel(&arg3,sizeof(arg3),&PT_REGS_PARM3_SYSCALL(real_regs));
From: Pu Lehui <pulehui@huawei.com>
Currently PT_REGS_PARM1 SYSCALL(x) is consistent with PT_REGS_PARM1_CORE
SYSCALL(x), which will introduce the overhead of BPF_CORE_READ(), taking
into account the read pt_regs comes directly from the context, let's use
CO-RE direct read to access the first system call argument.
Suggested-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Pu Lehui <pulehui@huawei.com>
---
tools/lib/bpf/bpf_tracing.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
From: Pu Lehui <pulehui@huawei.com>
Currently PT_REGS_PARM1 SYSCALL(x) is consistent with PT_REGS_PARM1_CORE
SYSCALL(x), which will introduce the overhead of BPF_CORE_READ(), taking
into account the read pt_regs comes directly from the context, let's use
CO-RE direct read to access the first system call argument.
Suggested-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Pu Lehui <pulehui@huawei.com>
---
tools/lib/bpf/bpf_tracing.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
From: Pu Lehui <pulehui@huawei.com>
On RV64, as Ilya mentioned before [0], the first syscall parameter should be
accessed through orig_a0 (see arch/riscv64/include/asm/syscall.h),
otherwise it will cause selftests like bpf_syscall_macro, vmlinux,
test_lsm, etc. to fail on RV64. Let's fix it by using the struct pt_regs
style CO-RE direct access.
Link: https://lore.kernel.org/bpf/20220209021745.2215452-1-iii@linux.ibm.com [0]
Signed-off-by: Pu Lehui <pulehui@huawei.com>
---
tools/lib/bpf/bpf_tracing.h | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
From: Pu Lehui <pulehui@huawei.com>
Currently PT_REGS_PARM1 SYSCALL(x) is consistent with PT_REGS_PARM1_CORE
SYSCALL(x), which will introduce the overhead of BPF_CORE_READ(), taking
into account the read pt_regs comes directly from the context, let's use
CO-RE direct read to access the first system call argument.
Suggested-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Pu Lehui <pulehui@huawei.com>
---
tools/lib/bpf/bpf_tracing.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
From: Pu Lehui <pulehui@huawei.com>
Currently PT_REGS_PARM1 SYSCALL(x) is consistent with PT_REGS_PARM1_CORE
SYSCALL(x), which will introduce the overhead of BPF_CORE_READ(), taking
into account the read pt_regs comes directly from the context, let's use
CO-RE direct read to access the first system call argument.
Suggested-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Pu Lehui <pulehui@huawei.com>
---
tools/lib/bpf/bpf_tracing.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
@@ -43,7 +43,7 @@ int BPF_KPROBE(handle_sys_prctl)/* test for PT_REGS_PARM */-bpf_probe_read_kernel(&tmp,sizeof(tmp),&PT_REGS_PARM1_SYSCALL(real_regs));+tmp=PT_REGS_PARM1_SYSCALL(real_regs);arg1=tmp;bpf_probe_read_kernel(&arg2,sizeof(arg2),&PT_REGS_PARM2_SYSCALL(real_regs));bpf_probe_read_kernel(&arg3,sizeof(arg3),&PT_REGS_PARM3_SYSCALL(real_regs));
On Sat, Aug 31, 2024 at 12:57 AM Xu Kuohai [off-list ref] wrote:
On 8/31/2024 3:26 PM, Xu Kuohai wrote:
quoted
On 8/31/2024 12:19 PM, Pu Lehui wrote:
quoted
From: Pu Lehui <pulehui@huawei.com>
Currently PT_REGS_PARM1 SYSCALL(x) is consistent with PT_REGS_PARM1_CORE
SYSCALL(x), which will introduce the overhead of BPF_CORE_READ(), taking
into account the read pt_regs comes directly from the context, let's use
CO-RE direct read to access the first system call argument.
Suggested-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Pu Lehui <pulehui@huawei.com>
---
tools/lib/bpf/bpf_tracing.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
You mean, *if you change the existing test like below*, it will break,
right? And that's expected, because arm64 has
ARCH_HAS_SYSCALL_WRAPPER, which means syscall pt_regs are actually not
the kprobe's ctx, so you can't directly access it. Which is why we
have PT_REGS_PARM1_CORE_SYSCALL() variants.
See how BPF_KSYSCALL macro is implemented, there are two cases:
___bpf_syswap_args(), which uses BPF_CORE_READ()-based macros to fetch
arguments, and ___bpf_syscall_args() which uses direct ctx reads.
@@ -43,7 +43,7 @@ int BPF_KPROBE(handle_sys_prctl)/* test for PT_REGS_PARM */-bpf_probe_read_kernel(&tmp,sizeof(tmp),&PT_REGS_PARM1_SYSCALL(real_regs));+tmp=PT_REGS_PARM1_SYSCALL(real_regs);arg1=tmp;bpf_probe_read_kernel(&arg2,sizeof(arg2),&PT_REGS_PARM2_SYSCALL(real_regs));bpf_probe_read_kernel(&arg3,sizeof(arg3),&PT_REGS_PARM3_SYSCALL(real_regs));
On Fri, Aug 30, 2024 at 9:17 PM Pu Lehui [off-list ref] wrote:
quoted hunk
From: Pu Lehui <pulehui@huawei.com>
Currently PT_REGS_PARM1 SYSCALL(x) is consistent with PT_REGS_PARM1_CORE
SYSCALL(x), which will introduce the overhead of BPF_CORE_READ(), taking
into account the read pt_regs comes directly from the context, let's use
CO-RE direct read to access the first system call argument.
Suggested-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Pu Lehui <pulehui@huawei.com>
---
tools/lib/bpf/bpf_tracing.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
It would probably be best (for consistency) to stick to using
__PTR_PARM1_SYSCALL_REG instead of hard-coding orig_x0 here, no? I'll
fix it up while applying. Same for patch #1 and #4.
It would be great if you can double-check that final patches in
bpf-next/master compile and work well for arm64, s390x, and RV64 (as I
can't really test that much locally).
On Fri, Aug 30, 2024 at 9:17 PM Pu Lehui [off-list ref] wrote:
quoted hunk
From: Pu Lehui <pulehui@huawei.com>
Considering that CO-RE direct read access to the first system call
argument is already available on s390 and arm64, let's enable
test_bpf_syscall_macro:syscall_arg1 on these architectures.
Signed-off-by: Pu Lehui <pulehui@huawei.com>
---
.../testing/selftests/bpf/prog_tests/test_bpf_syscall_macro.c | 4 ----
tools/testing/selftests/bpf/progs/bpf_syscall_macro.c | 2 --
2 files changed, 6 deletions(-)
@@ -43,9 +43,7 @@ int BPF_KPROBE(handle_sys_prctl)/* test for PT_REGS_PARM */-#if !defined(bpf_target_arm64) && !defined(bpf_target_s390)bpf_probe_read_kernel(&tmp,sizeof(tmp),&PT_REGS_PARM1_SYSCALL(real_regs));-#endifarg1=tmp;
There is no point in having tmp variable now, I cleaned that up as well
Hello:
This series was applied to bpf/bpf-next.git (master)
by Andrii Nakryiko [off-list ref]:
On Sat, 31 Aug 2024 04:19:30 +0000 you wrote:
On RV64, as Ilya mentioned before [0], the first syscall parameter should be
accessed through orig_a0 (see arch/riscv64/include/asm/syscall.h),
otherwise it will cause selftests like bpf_syscall_macro, vmlinux,
test_lsm, etc. to fail on RV64.
Link: https://lore.kernel.org/bpf/20220209021745.2215452-1-iii@linux.ibm.com [0]
[...]
On Sat, Aug 31, 2024 at 12:57 AM Xu Kuohai [off-list ref] wrote:
quoted
On 8/31/2024 3:26 PM, Xu Kuohai wrote:
quoted
On 8/31/2024 12:19 PM, Pu Lehui wrote:
quoted
From: Pu Lehui <pulehui@huawei.com>
Currently PT_REGS_PARM1 SYSCALL(x) is consistent with PT_REGS_PARM1_CORE
SYSCALL(x), which will introduce the overhead of BPF_CORE_READ(), taking
into account the read pt_regs comes directly from the context, let's use
CO-RE direct read to access the first system call argument.
Suggested-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Pu Lehui <pulehui@huawei.com>
---
tools/lib/bpf/bpf_tracing.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
You mean, *if you change the existing test like below*, it will break,
right? And that's expected, because arm64 has
ARCH_HAS_SYSCALL_WRAPPER, which means syscall pt_regs are actually not
the kprobe's ctx, so you can't directly access it. Which is why we
have PT_REGS_PARM1_CORE_SYSCALL() variants.
See how BPF_KSYSCALL macro is implemented, there are two cases:
___bpf_syswap_args(), which uses BPF_CORE_READ()-based macros to fetch
arguments, and ___bpf_syscall_args() which uses direct ctx reads.
@@ -43,7 +43,7 @@ int BPF_KPROBE(handle_sys_prctl)/* test for PT_REGS_PARM */-bpf_probe_read_kernel(&tmp,sizeof(tmp),&PT_REGS_PARM1_SYSCALL(real_regs));+tmp=PT_REGS_PARM1_SYSCALL(real_regs);arg1=tmp;bpf_probe_read_kernel(&arg2,sizeof(arg2),&PT_REGS_PARM2_SYSCALL(real_regs));bpf_probe_read_kernel(&arg3,sizeof(arg3),&PT_REGS_PARM3_SYSCALL(real_regs));
On Fri, Aug 30, 2024 at 9:17 PM Pu Lehui [off-list ref] wrote:
quoted
From: Pu Lehui <pulehui@huawei.com>
Currently PT_REGS_PARM1 SYSCALL(x) is consistent with PT_REGS_PARM1_CORE
SYSCALL(x), which will introduce the overhead of BPF_CORE_READ(), taking
into account the read pt_regs comes directly from the context, let's use
CO-RE direct read to access the first system call argument.
Suggested-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Pu Lehui <pulehui@huawei.com>
---
tools/lib/bpf/bpf_tracing.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
It would probably be best (for consistency) to stick to using
__PTR_PARM1_SYSCALL_REG instead of hard-coding orig_x0 here, no? I'll
fix it up while applying. Same for patch #1 and #4.
It would be great if you can double-check that final patches in
bpf-next/master compile and work well for arm64, s390x, and RV64 (as I
can't really test that much locally).
I check that locally with cross-platform vmtest on RV64, it looks good:
Summary: 569/3944 PASSED, 104 SKIPPED, 0 FAILED
and BPF CI meet happy on arm64, s390x.
Hello:
This series was applied to riscv/linux.git (fixes)
by Andrii Nakryiko [off-list ref]:
On Sat, 31 Aug 2024 04:19:30 +0000 you wrote:
On RV64, as Ilya mentioned before [0], the first syscall parameter should be
accessed through orig_a0 (see arch/riscv64/include/asm/syscall.h),
otherwise it will cause selftests like bpf_syscall_macro, vmlinux,
test_lsm, etc. to fail on RV64.
Link: https://lore.kernel.org/bpf/20220209021745.2215452-1-iii@linux.ibm.com [0]
[...]