Skip to content

bpf: Support struct argument for trampoline base progs

Yonghong Song bpf 4 versions – Applied

Status from this message: This series was applied to bpf/bpf-next.git (master)

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v4 Latest8 patches 9 repliesApplied 8/8
  2. v37 patches 8 repliesSuperseded
  3. v26 patches 12 repliesSuperseded
Earlier versions · 1
VersionPostedPatchesRepliesStatus
v1 RFC7 patches12 repliesSuperseded

Changes in v4 from the cover letter

- fix a test failure where no casting for bpf_get_func_arg() value as the value type is 'int'.
- add tracing_struct test in DENYLIST.s390x
- simplify macro BPF_REG_CNT for BPF_PROG2.

Patches in v4 All 8 applied

#Subject and filesSizeRepliesApplied
1/8bpf: Allow struct argument in trampoline based programsinclude/linux/bpf.h kernel/bpf/btf.c+43 -60 repliesApplied
2/8bpf: x86: Support in-register struct arguments in trampoline programsarch/x86/net/bpf_jit_comp.c+51 -174 repliesApplied
3/8bpf: Update descriptions for helpers bpf_get_func_arg[_cnt]()include/uapi/linux/bpf.h tools/include/uapi/linux/bpf.h+10 -82 repliesApplied
4/8bpf: arm64: No support of struct argument in trampoline programsarch/arm64/net/bpf_jit_comp.c+7 -10 repliesApplied
5/8libbpf: Add new BPF_PROG2 macrotools/lib/bpf/bpf_tracing.h+79 -03 repliesApplied
6/8selftests/bpf: Add struct argument tests with fentry/fexit programs.tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c tools/testing/selftests/bpf/prog_tests/tracing_struct.c tools/testing/selftests/bpf/progs/tracing_struct.c+231 -00 repliesApplied
7/8selftests/bpf: Use BPF_PROG2 for some fentry programs without struct argumentstools/testing/selftests/bpf/progs/timer.c+2 -20 repliesApplied
8/8selftests/bpf: Add tracing_struct test in DENYLIST.s390xtools/testing/selftests/bpf/DENYLIST.s390x+1 -00 repliesApplied

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v4 yet.

Read the v4 thread

Cover letter [PATCH bpf-next v4 0/8] bpf: Support struct argument for trampoline base progs

Currently struct arguments are not supported for trampoline based progs. One of major reason is that struct argument may pass by value which may use more than one registers. This breaks trampoline progs where each argument is assumed to take one register. bcc community reported the issue ([1]) where struct argument is not supported for fentry program.

  typedef struct {
        uid_t val;
  } kuid_t;
  typedef struct {
        gid_t val;
  } kgid_t;
  int security_path_chown(struct path *path, kuid_t uid, kgid_t gid);
Inside Meta, we also have a use case to attach to tcp_setsockopt()
  typedef struct {
        union {
                void            *kernel;
                void __user     *user;
        };
        bool            is_kernel : 1;
  } sockptr_t;
  int tcp_setsockopt(struct sock *sk, int level, int optname,
                     sockptr_t optval, unsigned int optlen);

This patch added struct value support for bpf tracing programs which uses trampoline. Only <= 16 byte struct size is supported for now which covers use cases in the above. For x86/arm64/bpf, <= 16 struct value will be passed in registers instead of by reference. Only x86_64 is supported in this patch. arm64 support can be added later.

[1] https://github.com/iovisor/bcc/issues/3657

Changelog:
v3 -> v4:
- fix a test failure where no casting for bpf_get_func_arg() value as the value type is 'int'.
- add tracing_struct test in DENYLIST.s390x
- simplify macro BPF_REG_CNT for BPF_PROG2.
v2 -> v3:
- previously struct arguments (<= 16 bytes) are passed by reference for bpf programs. Suggested by Alexei, it is passed by value now.
- in order to support passing <= 16 struct value, a new macro BPF_PROG2 is invented.
rfc v1 -> v2:
- changed bpf_func_model struct info fields to arg_flags[] to make it easy to iterate arguments in arch specific {save|restore}_regs() functions.
- added fexit tests to test return values with struct arguments.

Yonghong Song (8):
bpf: Allow struct argument in trampoline based programs
bpf: x86: Support in-register struct arguments in trampoline programs
bpf: Update descriptions for helpers bpf_get_func_arg[_cnt]()
bpf: arm64: No support of struct argument in trampoline programs
libbpf: Add new BPF_PROG2 macro
selftests/bpf: Add struct argument tests with fentry/fexit programs. selftests/bpf: Use BPF_PROG2 for some fentry programs without struct
arguments
selftests/bpf: Add tracing_struct test in DENYLIST.s390x

 arch/arm64/net/bpf_jit_comp.c                 |   8 +-
 arch/x86/net/bpf_jit_comp.c                   |  68 +++++++---
 include/linux/bpf.h                           |   4 +
 include/uapi/linux/bpf.h                      |   9 +-
 kernel/bpf/btf.c                              |  45 ++++++-
 tools/include/uapi/linux/bpf.h                |   9 +-
 tools/lib/bpf/bpf_tracing.h                   |  79 ++++++++++++
 tools/testing/selftests/bpf/DENYLIST.s390x    |   1 +
 .../selftests/bpf/bpf_testmod/bpf_testmod.c   |  48 +++++++
 .../selftests/bpf/prog_tests/tracing_struct.c |  63 +++++++++
 tools/testing/selftests/bpf/progs/timer.c     |   4 +-
 .../selftests/bpf/progs/tracing_struct.c      | 120 ++++++++++++++++++
 12 files changed, 424 insertions(+), 34 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/prog_tests/tracing_struct.c
 create mode 100644 tools/testing/selftests/bpf/progs/tracing_struct.c
Signature · 1 line
2.30.2