From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=66.220.155.179 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795193755; b=eeMNIPs8KRSz7AHmPgTwmxRuxB77RAvAfwVK0SIeazMGvsGXP/fOEbRUii37sPYM6VcP Ppifsmgmhf1if0hsz1zDTgvAX2XqeEqb9GkOcd/BAoGrL7Zr/Bh2+4BepzN+h93egmURE GvF/bcsWBNMkKlQZyg0cavFhRi+pWCY2/7nkhfib1fnUksfJzIAJPeO9qq1wO9JH7lTf5 UlkQQKPVyd208G8ipTSi4IZNd6lV+nBYZNv/TuOX9iqbr+WISUJhwK+aAfUuY7pmIRMcE 1rCcbXYcO69pxYgmSRvQZg+J1nBUqCuGBDQSwKTSFpa9H/5jgvWhnpMDcCcapXE6WHA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795193755; h=DMARC-Filter:Received:From:To:Cc:Subject:Date:Message-ID:X-Mailer: MIME-Version:Content-Transfer-Encoding; bh=KCdOHJp2zV4o27h1QxuSvSWdG0v+XnqwkvhP9YTxIl0=; b=fLE3J7NghsvQmBOkuXSrW7TM/i/2AQAsoyK8xbAO6v7beN0sJYS6iWIsJPpKEYFxPO3D CvalSDyQetEr6XrW9JOOSc6zylYNEp9n9vS9T+kCJ34Ow99khx1C7Z50aO0Obu0OHTBmv 2vPg6kNA/Tc6lq3/ubh246s+FszqnvdP14NjCiVzrFNJHJPoOVGn86+IMko+q13cgbmEO 4oCP/R19eZknVJgHHLkb2gxfVDQquwXv+x8BVNpvwF23abF9kToNrVajyA43cvtzKp4mk KHNTe1AyCw6zkXkV5hZiugFH9hWoF/UNCY+STARrJFtP8NmWwkLnPl6eQ/0fdtkqPfA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail header.from=linux.dev; spf=fail smtp.mailfrom=linux.dev; arc=none smtp.remote-ip=66.220.155.179 Received: from 66-220-155-179.mail-mxout.facebook.com (66-220-155-179.mail-mxout.facebook.com [66.220.155.179]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CC841606A331 for ; Fri, 20 Nov 2026 16:55:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org CC841606A331 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=linux.dev Received: by devvm50310.atn0.facebook.com (Postfix, from userid 128203) id 905B959328DB6; Fri, 20 Nov 2026 08:55:40 -0800 (PST) From: Yonghong Song To: bpf@vger.kernel.org Cc: Alexei Starovoitov , Andrii Nakryiko , Daniel Borkmann , Eduard Zingerman , kernel-team@fb.com Subject: [PATCH bpf-next v4 0/3] libbpf: Fix CO-RE relocations of unsigned 32-bit enum values Date: Fri, 20 Nov 2026 08:55:40 -0800 Message-ID: <20261120165540.2074139-1-yonghong.song@linux.dev> X-Mailer: git-send-email 2.53.1 X-Mailing-List: bpf@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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. GCC emits every 32-bit enum value sign-extended, since its __builtin_preserve_enum_value() returns int. So with the change above alone, GCC objects that load today would be refused. Patch 1 therefore also accepts the sign-extended form of an unsigned value, and patches the target value in the same form. The BTF of a kernel before v6.0, or generated by pahole before v1.24, has the kflag 0 on every enum, signed or not, so there the kflag 0 doesn't mean unsigned. If the local enum is signed, patch 1 takes such a target value as signed too, so that, e.g., -1 doesn't become 0xffffffff. Patch 2 tests the unsigned enum values, with clang and GCC. Patch 3 tests the signed ones against a target BTF without the kflag. Changelog: v3 -> v4: - v3: https://lore.kernel.org/bpf/20261119232647.3392045-1-yonghong.s= ong@linux.dev/ - Take a 32-bit target enum value as signed if the target enum has the kflag 0 but the local enum is signed, for the BTF of kernels without enum signedness (patch 1). - Test it with a target BTF whose enums have the kflag cleared (patch 3). v2 -> v3: - v2: https://lore.kernel.org/bpf/20261119051443.1902163-1-yonghong.s= ong@linux.dev/ - Fold patch 3 into patch 1 and patch 4 into patch 2 to avoid test failures when bisecting. v1 -> v2: - v1: https://lore.kernel.org/bpf/20261118161053.1768878-1-yonghong.s= ong@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 (3): libbpf: Fix CO-RE relocations of unsigned 32-bit enum values selftests/bpf: Test CO-RE relocations of unsigned 32-bit enum values selftests/bpf: Test CO-RE relocations of signed enum values without kflag include/linux/btf.h | 5 + tools/lib/bpf/relo_core.c | 59 +++++++++++- .../selftests/bpf/prog_tests/core_reloc.c | 92 ++++++++++++++++++- .../btf__core_reloc_enumval___no_kflag.c | 3 + .../selftests/bpf/progs/core_reloc_types.h | 24 +++++ .../bpf/progs/test_core_reloc_enumval.c | 35 +++++++ 6 files changed, 212 insertions(+), 6 deletions(-) create mode 100644 tools/testing/selftests/bpf/progs/btf__core_reloc_enu= mval___no_kflag.c --=20 2.53.1-Meta