libbpf now has macros to access syscall arguments in an architecture-agnostic manner, but unfortunately they have a number of issues on non-Intel arches, which this series aims to fix. v1: https://lore.kernel.org/bpf/20220201234200.1836443-1-iii@xxxxxxxxxxxxx/ v1 -> v2: * Put orig_gpr2 in place of args[1] on s390 (Vasily). * Fix arm64, powerpc and riscv (Heiko). v2: https://lore.kernel.org/bpf/20220204041955.1958263-1-iii@xxxxxxxxxxxxx/ v2 -> v3: * Undo args[1] change (Andrii). * Rename PT_REGS_SYSCALL to PT_REGS_SYSCALL_REGS (Andrii). * Split the riscv patch (Andrii). v3: https://lore.kernel.org/bpf/20220204145018.1983773-1-iii@xxxxxxxxxxxxx/ v3 -> v4: * Undo arm64's and s390's user_pt_regs changes. * Use struct pt_regs when vmlinux.h is available (Andrii). * Use offsetofend for accessing orig_gpr2 and orig_x0 (Andrii). * Move libbpf's copy of offsetofend to a new header. * Fix riscv's __PT_FP_REG. * Use PT_REGS_SYSCALL_REGS in test_probe_user.c. * Test bpf_syscall_macro with userspace headers. * Use Naveen's suggestions and code in patches 5 and 6. * Add warnings to arm64's and s390's ptrace.h (Andrii). Tested on x86_64, s390x, arm64, ppc64el and riscv64 in QEMU. +cc Mark. Ilya Leoshkevich (14): selftests/bpf: Fix an endianness issue in bpf_syscall_macro test selftests/bpf: Fix a potential offsetofend redefinition in test_cls_redirect selftests/bpf: Compile bpf_syscall_macro test also with user headers libbpf: Fix a typo in bpf_tracing.h libbpf: Generalize overriding syscall parameter access macros libbpf: Add PT_REGS_SYSCALL_REGS macro selftests/bpf: Use PT_REGS_SYSCALL_REGS in bpf_syscall_macro libbpf: Use struct pt_regs when compiling with kernel headers libbpf: Fix riscv register names libbpf: Move data structure manipulation macros to bpf_common_helpers.h libbpf: Fix accessing the first syscall argument on s390 s390: add a comment that warns that orig_gpr2 should not be moved libbpf: Fix accessing the first syscall argument on arm64 arm64: add a comment that warns that orig_x0 should not be moved arch/arm64/include/asm/ptrace.h | 4 + arch/s390/include/asm/ptrace.h | 4 + tools/lib/bpf/Makefile | 2 +- tools/lib/bpf/bpf_common_helpers.h | 30 +++++ tools/lib/bpf/bpf_helpers.h | 15 +-- tools/lib/bpf/bpf_tracing.h | 107 +++++++++++++++--- tools/testing/selftests/bpf/bpf_util.h | 10 +- ...acro.c => test_bpf_syscall_macro_common.h} | 8 +- .../test_bpf_syscall_macro_kernel.c | 13 +++ .../prog_tests/test_bpf_syscall_macro_user.c | 13 +++ tools/testing/selftests/bpf/progs/bpf_misc.h | 4 - ...all_macro.c => bpf_syscall_macro_common.h} | 15 ++- .../bpf/progs/bpf_syscall_macro_kernel.c | 4 + .../bpf/progs/bpf_syscall_macro_user.c | 10 ++ .../selftests/bpf/progs/test_cls_redirect.c | 2 + .../selftests/bpf/progs/test_probe_user.c | 8 +- 16 files changed, 191 insertions(+), 58 deletions(-) create mode 100644 tools/lib/bpf/bpf_common_helpers.h rename tools/testing/selftests/bpf/prog_tests/{test_bpf_syscall_macro.c => test_bpf_syscall_macro_common.h} (89%) create mode 100644 tools/testing/selftests/bpf/prog_tests/test_bpf_syscall_macro_kernel.c create mode 100644 tools/testing/selftests/bpf/prog_tests/test_bpf_syscall_macro_user.c rename tools/testing/selftests/bpf/progs/{bpf_syscall_macro.c => bpf_syscall_macro_common.h} (79%) create mode 100644 tools/testing/selftests/bpf/progs/bpf_syscall_macro_kernel.c create mode 100644 tools/testing/selftests/bpf/progs/bpf_syscall_macro_user.c -- 2.34.1