Skip to content

libbpf: auto-resize relocatable LOAD/STORE instructions

Andrii Nakryiko bpf netdev 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest3 patches 6 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3libbpf: support safe subset of load/store instruction resizing with CO-REtools/lib/bpf/libbpf.c+135 -92 replies
2/3libbpf: allow specifying both ELF and raw BTF for CO-RE BTF overridetools/lib/bpf/libbpf.c+1 -10 replies
3/3selftests/bpf: validate libbpf's auto-sizing of LD/ST/STX instructionstools/testing/selftests/bpf/prog_tests/core_autosize.c tools/testing/selftests/bpf/progs/test_core_autosize.c+347 -00 replies

Reviews trailers per patch

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

Read the v1 thread

Cover letter [PATCH bpf-next 0/3] libbpf: auto-resize relocatable LOAD/STORE instructions

Patch set implements logic in libbpf to auto-adjust memory size (1-, 2-, 4-, 8-bytes) of load/store (LD/ST/STX) instructions which have BPF CO-RE field offset relocation associated with it. In practice this means transparent handling of 32-bit kernels, both pointer and unsigned integers. Signed integers are not relocatable with zero-extending loads/stores, so libbpf poisons them and generates a warning. If/when BPF gets support for sign-extending loads/stores, it would be possible to automatically relocate them as well.

All the details are contained in patch #1 comments and commit message. Patch #2 is a simple change in libbpf to make advanced testing with custom BTF easier. Patch #3 validates correct uses of auto-resizable loads, as well as check that libbpf fails invalid uses.

I'd really appreciate folks that use BPF on 32-bit architectures to test this out with their BPF programs and report if there are any problems with the approach.

Cc Luka Perkov <[email protected]>
Cc Tony Ambardar <[email protected]>

Andrii Nakryiko (3):
libbpf: support safe subset of load/store instruction resizing with
CO-RE
libbpf: allow specifying both ELF and raw BTF for CO-RE BTF override selftests/bpf: validate libbpf's auto-sizing of LD/ST/STX instructions

 tools/lib/bpf/libbpf.c                        | 146 ++++++++++++-
 .../selftests/bpf/prog_tests/core_autosize.c  | 199 ++++++++++++++++++
 .../selftests/bpf/progs/test_core_autosize.c  | 148 +++++++++++++
 3 files changed, 483 insertions(+), 10 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/prog_tests/core_autosize.c
 create mode 100644 tools/testing/selftests/bpf/progs/test_core_autosize.c
Signature · 1 line
2.24.1