All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf-next v2 0/4] libbpf: Fix CO-RE relocations of unsigned 32-bit enum values
@ 2026-11-19  5:14 Yonghong Song
  2026-11-19  5:14 ` [PATCH bpf-next v2 1/4] libbpf: Zero-extend unsigned 32-bit enum values in CO-RE relocations Yonghong Song
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: Yonghong Song @ 2026-11-19  5:14 UTC (permalink / raw)
  To: bpf
  Cc: Alexei Starovoitov, Andrii Nakryiko, Daniel Borkmann,
	Eduard Zingerman, kernel-team

For a BPF_CORE_ENUMVAL_VALUE relocation, libbpf sign-extends the value
of a 32-bit enumerator even if the enum is unsigned. A value in
[0x80000000, 0xffffffff], e.g., DCACHE_PRIVATE of enum dentry_flags,
then doesn't match the zero-extended value clang emits, and the whole
object is refused.

Patch 1 extends the value as given by the kflag of the enum, which is
the form clang emits. The kernel builds the same relo_core.c, so it gets
the fix too. Patch 2 tests it.

GCC emits every 32-bit enum value sign-extended, since its
__builtin_preserve_enum_value() returns int. So with patch 1 alone, GCC
objects that loaded before would be refused. Patch 3 accepts the
sign-extended form of an unsigned value and patches the target value in
the same form. Patch 4 makes the test of patch 2 work with GCC.


Changelog:
  v1 -> v2:
    - v1: https://lore.kernel.org/bpf/20261118161053.1768878-1-yonghong.song@linux.dev/
    - Accept the sign-extended enum values emitted by GCC (patch 3), and
      make the new test work with GCC (patch 4).

Yonghong Song (4):
  libbpf: Zero-extend unsigned 32-bit enum values in CO-RE relocations
  selftests/bpf: Test CO-RE relocations of unsigned 32-bit enum values
  libbpf: Accept sign-extended 32-bit enum values in CO-RE relocations
  selftests/bpf: Take unsigned enum values as unsigned int for GCC

 include/linux/btf.h                           |  5 ++++
 tools/lib/bpf/relo_core.c                     | 30 ++++++++++++++++---
 .../selftests/bpf/prog_tests/core_reloc.c     |  2 ++
 .../selftests/bpf/progs/core_reloc_types.h    |  8 +++++
 .../bpf/progs/test_core_reloc_enumval.c       | 21 +++++++++++++
 5 files changed, 62 insertions(+), 4 deletions(-)

-- 
2.53.1-Meta


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2026-11-19 15:57 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-19  5:14 [PATCH bpf-next v2 0/4] libbpf: Fix CO-RE relocations of unsigned 32-bit enum values Yonghong Song
2026-11-19  5:14 ` [PATCH bpf-next v2 1/4] libbpf: Zero-extend unsigned 32-bit enum values in CO-RE relocations Yonghong Song
2026-11-19  5:54   ` bot+bpf-ci
2026-11-19 15:55     ` Yonghong Song
2026-11-19  5:14 ` [PATCH bpf-next v2 2/4] selftests/bpf: Test CO-RE relocations of unsigned 32-bit enum values Yonghong Song
2026-11-19  5:54   ` bot+bpf-ci
2026-11-19 15:57     ` Yonghong Song
2026-11-19  5:14 ` [PATCH bpf-next v2 3/4] libbpf: Accept sign-extended 32-bit enum values in CO-RE relocations Yonghong Song
2026-11-19  5:21   ` sashiko-bot
2026-11-19  5:15 ` [PATCH bpf-next v2 4/4] selftests/bpf: Take unsigned enum values as unsigned int for GCC Yonghong Song

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.