Skip to content

Conversation

kernel-patches-bot
Copy link

Pull request for series with
subject: libbpf: auto-resize relocatable LOAD/STORE instructions
version: 1
url: https://patchwork.kernel.org/project/bpf/list/?series=358607

@kernel-patches-bot
Copy link
Author

Master branch: 6208689
series: https://patchwork.kernel.org/project/bpf/list/?series=358607
version: 1

@kernel-patches-bot
Copy link
Author

Master branch: 360f898
series: https://patchwork.kernel.org/project/bpf/list/?series=358607
version: 1

@kernel-patches-bot
Copy link
Author

Master branch: 48ca624
series: https://patchwork.kernel.org/project/bpf/list/?series=358607
version: 1

@kernel-patches-bot
Copy link
Author

Master branch: 440c575
series: https://patchwork.kernel.org/project/bpf/list/?series=358607
version: 1

@kernel-patches-bot
Copy link
Author

Master branch: 60a128b
series: https://patchwork.kernel.org/project/bpf/list/?series=358607
version: 1

@kernel-patches-bot
Copy link
Author

Master branch: fb91db0
series: https://patchwork.kernel.org/project/bpf/list/?series=358607
version: 1

@kernel-patches-bot
Copy link
Author

Master branch: 1028ae4
series: https://patchwork.kernel.org/project/bpf/list/?series=358607
version: 1

@kernel-patches-bot
Copy link
Author

Master branch: b75597d
series: https://patchwork.kernel.org/project/bpf/list/?series=358607
version: 1

@kernel-patches-bot
Copy link
Author

Master branch: 8731745
series: https://patchwork.kernel.org/project/bpf/list/?series=358607
version: 1

@kernel-patches-bot
Copy link
Author

Master branch: 39d8f0d
series: https://patchwork.kernel.org/project/bpf/list/?series=358607
version: 1

@kernel-patches-bot
Copy link
Author

Master branch: dca4121
series: https://patchwork.kernel.org/project/bpf/list/?series=358607
version: 1

kernel-patches-bot and others added 4 commits October 5, 2020 15:58
…O-RE

Add support for patching instructions of the following form:
  - rX = *(T *)(rY + <off>);
  - *(T *)(rX + <off>) = rY;
  - *(T *)(rX + <off>) = <imm>, where T is one of {u8, u16, u32, u64}.

For such instructions, if the actual kernel field recorded in CO-RE relocation
has a different size than the one recorded locally (e.g., from vmlinux.h),
then libbpf will adjust T to an appropriate 1-, 2-, 4-, or 8-byte loads.

In general, such transformation is not always correct and could lead to
invalid final value being loaded or stored. But two classes of cases are
always safe:
  - if both local and target (kernel) types are unsigned integers, but of
  different sizes, then it's OK to adjust load/store instruction according to
  the necessary memory size. Zero-extending nature of such instructions and
  unsignedness make sure that the final value is always correct;
  - pointer size mismatch between BPF target architecture (which is always
  64-bit) and 32-bit host kernel architecture can be similarly resolved
  automatically, because pointer is essentially an unsigned integer. Loading
  32-bit pointer into 64-bit BPF register with zero extension will leave
  correct pointer in the register.

Both cases are necessary to support CO-RE on 32-bit kernels, as `unsigned
long` in vmlinux.h generated from 32-bit kernel is 32-bit, but when compiled
with BPF program for BPF target it will be treated by compiler as 64-bit
integer. Similarly, pointers in vmlinux.h are 32-bit for kernel, but treated
as 64-bit values by compiler for BPF target. Both problems are now resolved by
libbpf for direct memory reads.

But similar transformations are useful in general when kernel fields are
"resized" from, e.g., unsigned int to unsigned long (or vice versa).

Now, similar transformations for signed integers are not safe to perform as
they will result in incorrect sign extension of the value. If such situation
is detected, libbpf will emit helpful message and will poison the instruction.
Not failing immediately means that it's possible to guard the instruction
based on kernel version (or other conditions) and make sure it's not
reachable.

If there is a need to read signed integers that change sizes between different
kernels, it's possible to use BPF_CORE_READ_BITFIELD() macro, which works both
with bitfields and non-bitfield integers of any signedness and handles
sign-extension properly. Also, bpf_core_read() with proper size and/or use of
bpf_core_field_size() relocation could allow to deal with such complicated
situations explicitly, if not so conventiently as direct memory reads.

Selftests added in a separate patch in progs/test_core_autosize.c demonstrate
both direct memory and probed use cases.

BPF_CORE_READ() is not changed and it won't deal with such situations as
automatically as direct memory reads due to the signedness integer
limitations, which are much harder to detect and control with compiler macro
magic. So it's encouraged to utilize direct memory reads as much as possible.

Signed-off-by: Andrii Nakryiko <[email protected]>
Use generalized BTF parsing logic, making it possible to parse BTF both from
ELF file, as well as a raw BTF dump. This makes it easier to write custom
tests with manually generated BTFs.

Signed-off-by: Andrii Nakryiko <[email protected]>
Add selftests validating libbpf's auto-resizing of load/store instructions
when used with CO-RE relocations. An explicit and manual approach with using
bpf_core_read() is also demonstrated and tested. Separate BPF program is
supposed to fail due to using signed integers of sizes that differ from
kernel's sizes.

To reliably simulate 32-bit BTF (i.e., the one with sizeof(long) ==
sizeof(void *) == 4), selftest generates its own custom BTF and passes it as
a replacement for real kernel BTF. This allows to test 32/64-bitness mix on
all architectures.

Signed-off-by: Andrii Nakryiko <[email protected]>
@kernel-patches-bot
Copy link
Author

Master branch: dca4121
series: https://patchwork.kernel.org/project/bpf/list/?series=358607
version: 1

@kernel-patches-bot
Copy link
Author

At least one diff in series https://patchwork.kernel.org/project/bpf/list/?series=358607 irrelevant now. Closing PR.

@kernel-patches-bot kernel-patches-bot deleted the series/358607=>bpf-next branch October 7, 2020 01:45
kernel-patches-daemon-bpf bot pushed a commit that referenced this pull request Jan 24, 2025
Add selftests for prog_kfunc feature probing.
 ./test_progs -t libbpf_probe_kfuncs
 #153     libbpf_probe_kfuncs:OK
 Summary: 1/0 PASSED, 0 SKIPPED, 0 FAILED

Signed-off-by: Tao Chen <[email protected]>
kernel-patches-daemon-bpf bot pushed a commit that referenced this pull request Jan 24, 2025
Add selftests for prog_kfunc feature probing.
 ./test_progs -t libbpf_probe_kfuncs
 #153     libbpf_probe_kfuncs:OK
 Summary: 1/0 PASSED, 0 SKIPPED, 0 FAILED

Signed-off-by: Tao Chen <[email protected]>
kernel-patches-daemon-bpf bot pushed a commit that referenced this pull request Feb 6, 2025
Add selftests for prog_kfunc feature probing.

 ./test_progs -t libbpf_probe_kfuncs
 #153     libbpf_probe_kfuncs:OK
 Summary: 1/0 PASSED, 0 SKIPPED, 0 FAILED

Signed-off-by: Tao Chen <[email protected]>
kernel-patches-daemon-bpf bot pushed a commit that referenced this pull request Feb 10, 2025
Add selftests for prog_kfunc feature probing.

 ./test_progs -t libbpf_probe_kfuncs
 #153     libbpf_probe_kfuncs:OK
 Summary: 1/0 PASSED, 0 SKIPPED, 0 FAILED

Signed-off-by: Tao Chen <[email protected]>
kernel-patches-daemon-bpf bot pushed a commit that referenced this pull request Feb 11, 2025
Add selftests for prog_kfunc feature probing.

 ./test_progs -t libbpf_probe_kfuncs
 #153     libbpf_probe_kfuncs:OK
 Summary: 1/0 PASSED, 0 SKIPPED, 0 FAILED

Signed-off-by: Tao Chen <[email protected]>
kernel-patches-daemon-bpf bot pushed a commit that referenced this pull request Feb 11, 2025
Add selftests for prog_kfunc feature probing.

 ./test_progs -t libbpf_probe_kfuncs
 #153     libbpf_probe_kfuncs:OK
 Summary: 1/0 PASSED, 0 SKIPPED, 0 FAILED

Signed-off-by: Tao Chen <[email protected]>
kernel-patches-daemon-bpf bot pushed a commit that referenced this pull request Feb 12, 2025
Add selftests for prog_kfunc feature probing.

 ./test_progs -t libbpf_probe_kfuncs
 #153     libbpf_probe_kfuncs:OK
 Summary: 1/0 PASSED, 0 SKIPPED, 0 FAILED

Cc: Tao Chen <[email protected]>
Reviewed-by: Jiri Olsa <[email protected]>
Signed-off-by: Tao Chen <[email protected]>
kernel-patches-daemon-bpf bot pushed a commit that referenced this pull request Feb 12, 2025
Add selftests for prog_kfunc feature probing.

 ./test_progs -t libbpf_probe_kfuncs
 #153     libbpf_probe_kfuncs:OK
 Summary: 1/0 PASSED, 0 SKIPPED, 0 FAILED

Cc: Tao Chen <[email protected]>
Reviewed-by: Jiri Olsa <[email protected]>
Signed-off-by: Tao Chen <[email protected]>
kernel-patches-daemon-bpf bot pushed a commit that referenced this pull request Feb 13, 2025
Add selftests for prog_kfunc feature probing.

 ./test_progs -t libbpf_probe_kfuncs
 #153     libbpf_probe_kfuncs:OK
 Summary: 1/0 PASSED, 0 SKIPPED, 0 FAILED

Cc: Tao Chen <[email protected]>
Reviewed-by: Jiri Olsa <[email protected]>
Signed-off-by: Tao Chen <[email protected]>
kernel-patches-daemon-bpf bot pushed a commit that referenced this pull request Feb 14, 2025
Add selftests for prog_kfunc feature probing.

 ./test_progs -t libbpf_probe_kfuncs
 #153     libbpf_probe_kfuncs:OK
 Summary: 1/0 PASSED, 0 SKIPPED, 0 FAILED

Cc: Tao Chen <[email protected]>
Reviewed-by: Jiri Olsa <[email protected]>
Signed-off-by: Tao Chen <[email protected]>
kernel-patches-daemon-bpf bot pushed a commit that referenced this pull request Feb 14, 2025
Add selftests for prog_kfunc feature probing.

 ./test_progs -t libbpf_probe_kfuncs
 #153     libbpf_probe_kfuncs:OK
 Summary: 1/0 PASSED, 0 SKIPPED, 0 FAILED

Cc: Tao Chen <[email protected]>
Reviewed-by: Jiri Olsa <[email protected]>
Signed-off-by: Tao Chen <[email protected]>
kernel-patches-daemon-bpf bot pushed a commit that referenced this pull request Feb 14, 2025
Add selftests for prog_kfunc feature probing.

 ./test_progs -t libbpf_probe_kfuncs
 #153     libbpf_probe_kfuncs:OK
 Summary: 1/0 PASSED, 0 SKIPPED, 0 FAILED

Cc: Tao Chen <[email protected]>
Reviewed-by: Jiri Olsa <[email protected]>
Signed-off-by: Tao Chen <[email protected]>
kernel-patches-daemon-bpf bot pushed a commit that referenced this pull request Feb 14, 2025
Add selftests for prog_kfunc feature probing.

 ./test_progs -t libbpf_probe_kfuncs
 #153     libbpf_probe_kfuncs:OK
 Summary: 1/0 PASSED, 0 SKIPPED, 0 FAILED

Cc: Tao Chen <[email protected]>
Reviewed-by: Jiri Olsa <[email protected]>
Signed-off-by: Tao Chen <[email protected]>
kernel-patches-daemon-bpf bot pushed a commit that referenced this pull request Feb 15, 2025
Add selftests for prog_kfunc feature probing.

 ./test_progs -t libbpf_probe_kfuncs
 #153     libbpf_probe_kfuncs:OK
 Summary: 1/0 PASSED, 0 SKIPPED, 0 FAILED

Cc: Tao Chen <[email protected]>
Reviewed-by: Jiri Olsa <[email protected]>
Signed-off-by: Tao Chen <[email protected]>
kernel-patches-daemon-bpf bot pushed a commit that referenced this pull request Feb 15, 2025
Add selftests for prog_kfunc feature probing.

 ./test_progs -t libbpf_probe_kfuncs
 #153     libbpf_probe_kfuncs:OK
 Summary: 1/0 PASSED, 0 SKIPPED, 0 FAILED

Cc: Tao Chen <[email protected]>
Reviewed-by: Jiri Olsa <[email protected]>
Signed-off-by: Tao Chen <[email protected]>
kernel-patches-daemon-bpf bot pushed a commit that referenced this pull request Feb 17, 2025
Add selftests for prog_kfunc feature probing.

 ./test_progs -t libbpf_probe_kfuncs
 #153     libbpf_probe_kfuncs:OK
 Summary: 1/0 PASSED, 0 SKIPPED, 0 FAILED

Cc: Tao Chen <[email protected]>
Reviewed-by: Jiri Olsa <[email protected]>
Signed-off-by: Tao Chen <[email protected]>
kernel-patches-daemon-bpf bot pushed a commit that referenced this pull request Feb 18, 2025
Add selftests for prog_kfunc feature probing.

 ./test_progs -t libbpf_probe_kfuncs
 #153     libbpf_probe_kfuncs:OK
 Summary: 1/0 PASSED, 0 SKIPPED, 0 FAILED

Cc: Tao Chen <[email protected]>
Reviewed-by: Jiri Olsa <[email protected]>
Signed-off-by: Tao Chen <[email protected]>
kernel-patches-daemon-bpf bot pushed a commit that referenced this pull request Feb 18, 2025
Add selftests for prog_kfunc feature probing.

 ./test_progs -t libbpf_probe_kfuncs
 #153     libbpf_probe_kfuncs:OK
 Summary: 1/0 PASSED, 0 SKIPPED, 0 FAILED

Cc: Tao Chen <[email protected]>
Reviewed-by: Jiri Olsa <[email protected]>
Signed-off-by: Tao Chen <[email protected]>
kernel-patches-daemon-bpf bot pushed a commit that referenced this pull request Feb 21, 2025
Add selftests for prog_kfunc feature probing. Thanks for
Eduard providing the libbpf_probe_func_many test case.

 ./test_progs -t libbpf_probe_kfuncs
 #153     libbpf_probe_kfuncs:OK
 Summary: 1/0 PASSED, 0 SKIPPED, 0 FAILED

 ./test_progs -t libbpf_probe_kfuncs_many
 #154     libbpf_probe_kfuncs_many:OK
 Summary: 1/0 PASSED, 0 SKIPPED, 0 FAILED

Cc: Tao Chen <[email protected]>
Reviewed-by: Jiri Olsa <[email protected]>
Co-developed-by: Eduard Zingerman <[email protected]>
Signed-off-by: Eduard Zingerman <[email protected]>
Signed-off-by: Tao Chen <[email protected]>
kernel-patches-daemon-bpf bot pushed a commit that referenced this pull request Feb 23, 2025
Add selftests for prog_kfunc feature probing. Thanks for
Eduard providing the libbpf_probe_func_many test case.

 ./test_progs -t libbpf_probe_kfuncs
 #153     libbpf_probe_kfuncs:OK
 Summary: 1/0 PASSED, 0 SKIPPED, 0 FAILED

 ./test_progs -t libbpf_probe_kfuncs_many
 #154     libbpf_probe_kfuncs_many:OK
 Summary: 1/0 PASSED, 0 SKIPPED, 0 FAILED

Cc: Tao Chen <[email protected]>
Reviewed-by: Jiri Olsa <[email protected]>
Co-developed-by: Eduard Zingerman <[email protected]>
Signed-off-by: Eduard Zingerman <[email protected]>
Signed-off-by: Tao Chen <[email protected]>
kernel-patches-daemon-bpf bot pushed a commit that referenced this pull request Feb 23, 2025
Add selftests for prog_kfunc feature probing. Thanks for
Eduard providing the libbpf_probe_func_many test case.

 ./test_progs -t libbpf_probe_kfuncs
 #153     libbpf_probe_kfuncs:OK
 Summary: 1/0 PASSED, 0 SKIPPED, 0 FAILED

 ./test_progs -t libbpf_probe_kfuncs_many
 #154     libbpf_probe_kfuncs_many:OK
 Summary: 1/0 PASSED, 0 SKIPPED, 0 FAILED

Cc: Tao Chen <[email protected]>
Reviewed-by: Jiri Olsa <[email protected]>
Co-developed-by: Eduard Zingerman <[email protected]>
Signed-off-by: Eduard Zingerman <[email protected]>
Signed-off-by: Tao Chen <[email protected]>
kernel-patches-daemon-bpf bot pushed a commit that referenced this pull request Feb 24, 2025
Add selftests for prog_kfunc feature probing.

 ./test_progs -t libbpf_probe_kfuncs
 #153     libbpf_probe_kfuncs:OK
 Summary: 1/0 PASSED, 0 SKIPPED, 0 FAILED

Cc: Tao Chen <[email protected]>
Reviewed-by: Jiri Olsa <[email protected]>
Reviewed-by: Eduard Zingerman <[email protected]>
Signed-off-by: Tao Chen <[email protected]>
kernel-patches-daemon-bpf bot pushed a commit that referenced this pull request Feb 24, 2025
Add selftests for prog_kfunc feature probing.

 ./test_progs -t libbpf_probe_kfuncs
 #153     libbpf_probe_kfuncs:OK
 Summary: 1/0 PASSED, 0 SKIPPED, 0 FAILED

Cc: Tao Chen <[email protected]>
Reviewed-by: Jiri Olsa <[email protected]>
Reviewed-by: Eduard Zingerman <[email protected]>
Signed-off-by: Tao Chen <[email protected]>
kernel-patches-daemon-bpf bot pushed a commit that referenced this pull request Feb 24, 2025
Add selftests for prog_kfunc feature probing.

 ./test_progs -t libbpf_probe_kfuncs
 #153     libbpf_probe_kfuncs:OK
 Summary: 1/0 PASSED, 0 SKIPPED, 0 FAILED

Cc: Tao Chen <[email protected]>
Reviewed-by: Jiri Olsa <[email protected]>
Reviewed-by: Eduard Zingerman <[email protected]>
Signed-off-by: Tao Chen <[email protected]>
kernel-patches-daemon-bpf bot pushed a commit that referenced this pull request Feb 24, 2025
Add selftests for prog_kfunc feature probing.

 ./test_progs -t libbpf_probe_kfuncs
 #153     libbpf_probe_kfuncs:OK
 Summary: 1/0 PASSED, 0 SKIPPED, 0 FAILED

Cc: Tao Chen <[email protected]>
Reviewed-by: Jiri Olsa <[email protected]>
Reviewed-by: Eduard Zingerman <[email protected]>
Signed-off-by: Tao Chen <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants