mbox series

[bpf-next,v2,00/10] libbpf: Fix accessing syscall arguments

Message ID 20220204041955.1958263-1-iii@linux.ibm.com (mailing list archive)
Headers show
Series libbpf: Fix accessing syscall arguments | expand

Message

Ilya Leoshkevich Feb. 4, 2022, 4:19 a.m. UTC
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, that this series aims to fix.

v1: https://lore.kernel.org/bpf/20220201234200.1836443-1-iii@linux.ibm.com/
v1 -> v2:
* Put orig_gpr2 in place of args[1] on s390 (Vasily).
* Fix arm64, powerpc and riscv (Heiko).

The arm64 fix is similar to the s390 one.

powerpc and riscv are different in that they unpack arguments to
registers before invoking syscall handlers - libbpf needs to know about
this difference, so I've decided to introduce PT_REGS_SYSCALL macro for
this (see bpf_syscall_macro test for usage example).

Tested in QEMU.

@Catalin, @Michael, @Paul: could you please review the arm64, powerpc
and riscv parts?

Ilya Leoshkevich (10):
  arm64/bpf: Add orig_x0 to user_pt_regs
  s390/bpf: Add orig_gpr2 to user_pt_regs
  selftests/bpf: Fix an endianness issue in bpf_syscall_macro test
  libbpf: Add __PT_PARM1_REG_SYSCALL macro
  libbpf: Add PT_REGS_SYSCALL macro
  selftests/bpf: Use PT_REGS_SYSCALL in bpf_syscall_macro
  libbpf: Fix accessing the first syscall argument on arm64
  libbpf: Fix accessing syscall arguments on powerpc
  libbpf: Fix accessing syscall arguments on riscv
  libbpf: Fix accessing the first syscall argument on s390

 arch/arm64/include/asm/ptrace.h               |  2 +-
 arch/arm64/include/uapi/asm/ptrace.h          |  1 +
 arch/s390/include/asm/ptrace.h                |  3 +--
 arch/s390/include/uapi/asm/ptrace.h           |  2 +-
 tools/lib/bpf/bpf_tracing.h                   | 23 ++++++++++++++++++-
 .../selftests/bpf/progs/bpf_syscall_macro.c   |  7 ++++--
 6 files changed, 31 insertions(+), 7 deletions(-)

Comments

Andrii Nakryiko Feb. 4, 2022, 5:28 a.m. UTC | #1
On Thu, Feb 3, 2022 at 8:20 PM Ilya Leoshkevich <iii@linux.ibm.com> wrote:
>
> 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, that this series aims to fix.
>
> v1: https://lore.kernel.org/bpf/20220201234200.1836443-1-iii@linux.ibm.com/
> v1 -> v2:
> * Put orig_gpr2 in place of args[1] on s390 (Vasily).
> * Fix arm64, powerpc and riscv (Heiko).
>
> The arm64 fix is similar to the s390 one.
>
> powerpc and riscv are different in that they unpack arguments to
> registers before invoking syscall handlers - libbpf needs to know about
> this difference, so I've decided to introduce PT_REGS_SYSCALL macro for
> this (see bpf_syscall_macro test for usage example).
>
> Tested in QEMU.
>
> @Catalin, @Michael, @Paul: could you please review the arm64, powerpc
> and riscv parts?

I think it's worth waiting for these fixes before cutting libbpf v0.7
release, thanks for working on them! Please see my other comments on
respective patches.

>
> Ilya Leoshkevich (10):
>   arm64/bpf: Add orig_x0 to user_pt_regs
>   s390/bpf: Add orig_gpr2 to user_pt_regs
>   selftests/bpf: Fix an endianness issue in bpf_syscall_macro test
>   libbpf: Add __PT_PARM1_REG_SYSCALL macro
>   libbpf: Add PT_REGS_SYSCALL macro
>   selftests/bpf: Use PT_REGS_SYSCALL in bpf_syscall_macro
>   libbpf: Fix accessing the first syscall argument on arm64
>   libbpf: Fix accessing syscall arguments on powerpc
>   libbpf: Fix accessing syscall arguments on riscv
>   libbpf: Fix accessing the first syscall argument on s390
>
>  arch/arm64/include/asm/ptrace.h               |  2 +-
>  arch/arm64/include/uapi/asm/ptrace.h          |  1 +
>  arch/s390/include/asm/ptrace.h                |  3 +--
>  arch/s390/include/uapi/asm/ptrace.h           |  2 +-
>  tools/lib/bpf/bpf_tracing.h                   | 23 ++++++++++++++++++-
>  .../selftests/bpf/progs/bpf_syscall_macro.c   |  7 ++++--
>  6 files changed, 31 insertions(+), 7 deletions(-)
>
> --
> 2.34.1
>