From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=69.171.232.181 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795478736; b=hEKZDAn2ZL8l9rVBxM3PvtEOgVoy7TpppConywW///kdxBYwVndjIxwAjRtZWwOdPSpB gJBn/YNu++6TO6LO/KLR7GMHOidoSclyd7K+CIEzD88gBXxIwmZeDB2scD9ip20NbTGJ8 4vVqU6Yrc1W7DKygybp79Sq7ehzUTLkU/lkhZ4w0xEzCS6dbSE8dYazz4cfT1iR4WvDb5 orsAENECLCy81xeO8aBU//azBA8WzvEVBI83NDkzTBtc+BS0mTNYuUvKxe22MPJLFlwC6 D0aY0pg7yVFhN0o4s60SdxEu3bSOpzuW2UO+WaZmIAYW4MX0P0RB+Ise7kKy0eL/c7A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795478736; h=DMARC-Filter:Received:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=Wjqn7q88oZSyaTsL3Wfjj/7TwKmeKEPkBqR39IM+9Gs=; b=n1bbeGJL3ULhyK+FG7GydzFvdtfLWeFLNaIoAd7C+hSZwiP24Zjfsl9LEaWmVJohAi69 ZGG2p06Jzf8OIMm0DP4BuqpZSH/2ciq1YUTRipz/VvHLah5YubhmXstVz+J1wGuWXfqdd /OKA1cSb3E3JGXICwVLub0R0Ax9CHQjiXpZ6riqvBX4oCqlgtHHjBbScf0tKWlflGpGPF J6TJpC/tSIdUITM5etzzgDnXvNU/kF+hD1Byymyh/M3w6OY/kX4j4meDtaw5E0rZS1pN3 vGPlQLyIUQtw7wfk6QFzKweTefhlDF/55w9/UkZyDrNKM3N8dXS7IZJMYrNPFeXoPwQ== 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=69.171.232.181 Received: from 69-171-232-181.mail-mxout.facebook.com (69-171-232-181.mail-mxout.facebook.com [69.171.232.181]) (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 AF12B606A32C for ; Tue, 24 Nov 2026 00:05:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org AF12B606A32C 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 BEC645989F95E; Mon, 23 Nov 2026 16:05:24 -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 v6 2/2] selftests/bpf: Test CO-RE relocations of unsigned 32-bit enum values Date: Mon, 23 Nov 2026 16:05:24 -0800 Message-ID: <20261124000524.2956489-1-yonghong.song@linux.dev> X-Mailer: git-send-email 2.53.1 In-Reply-To: <20261124000514.2955878-1-yonghong.song@linux.dev> References: <20261124000514.2955878-1-yonghong.song@linux.dev> 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 Test the extension of unsigned 32-bit enum values in CO-RE relocations from the previous patch. test_core_reloc_enumval gets an optional local enum with values out of the range of int, i.e., an unsigned 4-byte enum, whose values clang emits zero-extended in the ld_imm64 of the relocations. The enumval target has the same enum with different values, 0x80000001 and 0xffffffff, which are expected zero-extended in the 64-bit outputs. GCC's __builtin_preserve_enum_value() returns int, so GCC emits these values sign-extended, and libbpf refuses the object. With GCC, don't read the values of enum named_uint_enum. Only test whether the enum exists in the target BTF, which libbpf patches without checking the value, and skip the test if it does. Without the fix, the check of the original value fails, and the whole object is refused: libbpf: prog 'test_core_enumval': relo #11: unexpected insn #53 (LDIMM6= 4) value: got 2147483648, exp 18446744071562067968 -> 184467440715= 62067969 libbpf: prog 'test_core_enumval': relo #11: failed to patch insn #53: -= EINVAL #122/71 core_reloc/enumval:FAIL Signed-off-by: Yonghong Song --- .../selftests/bpf/prog_tests/core_reloc.c | 2 ++ .../selftests/bpf/progs/core_reloc_types.h | 8 +++++++ .../bpf/progs/test_core_reloc_enumval.c | 23 +++++++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/tools/testing/selftests/bpf/prog_tests/core_reloc.c b/tools/= testing/selftests/bpf/prog_tests/core_reloc.c index 80432c4656b5..98b3c5fb1028 100644 --- a/tools/testing/selftests/bpf/prog_tests/core_reloc.c +++ b/tools/testing/selftests/bpf/prog_tests/core_reloc.c @@ -904,6 +904,8 @@ static const struct core_reloc_test_case test_cases[]= =3D { .named_val2 =3D 2, .anon_val1 =3D 0x10, .anon_val2 =3D 0x20, + .uint_val1 =3D 0x80000001, + .uint_val2 =3D 0xffffffff, }), ENUMVAL_CASE(enumval___diff, { .named_val1_exists =3D true, diff --git a/tools/testing/selftests/bpf/progs/core_reloc_types.h b/tools= /testing/selftests/bpf/progs/core_reloc_types.h index 5760ae015e09..6d758e74bd58 100644 --- a/tools/testing/selftests/bpf/progs/core_reloc_types.h +++ b/tools/testing/selftests/bpf/progs/core_reloc_types.h @@ -1215,6 +1215,8 @@ struct core_reloc_enumval_output { int named_val2; int anon_val1; int anon_val2; + long uint_val1; + long uint_val2; }; =20 struct core_reloc_enum64val_output { @@ -1243,9 +1245,15 @@ typedef enum { ANON_ENUM_VAL3 =3D 0x30, } anon_enum; =20 +enum named_uint_enum { + UINT_ENUM_VAL1 =3D 0x80000001, + UINT_ENUM_VAL2 =3D 0xffffffff, +}; + struct core_reloc_enumval { enum named_enum f1; anon_enum f2; + enum named_uint_enum f3; }; =20 enum named_unsigned_enum64 { diff --git a/tools/testing/selftests/bpf/progs/test_core_reloc_enumval.c = b/tools/testing/selftests/bpf/progs/test_core_reloc_enumval.c index e7ef3dada2bf..9933eadc2993 100644 --- a/tools/testing/selftests/bpf/progs/test_core_reloc_enumval.c +++ b/tools/testing/selftests/bpf/progs/test_core_reloc_enumval.c @@ -27,6 +27,12 @@ typedef enum { ANON_ENUM_VAL3 =3D 0x30, } anon_enum; =20 +/* 4-byte enum with values out of the range of int, so it is unsigned */ +enum named_uint_enum { + UINT_ENUM_VAL1 =3D 0x80000000, + UINT_ENUM_VAL2 =3D 0xfffffff0, +}; + struct core_reloc_enumval_output { bool named_val1_exists; bool named_val2_exists; @@ -39,6 +45,8 @@ struct core_reloc_enumval_output { int named_val2; int anon_val1; int anon_val2; + long uint_val1; + long uint_val2; }; =20 SEC("raw_tracepoint/sys_enter") @@ -64,6 +72,21 @@ int test_core_enumval(void *ctx) out->anon_val1 =3D bpf_core_enum_value(anon, ANON_ENUM_VAL1); out->anon_val2 =3D bpf_core_enum_value(anon, ANON_ENUM_VAL2); /* ANON_ENUM_VAL3 value is optional */ + + /* enum named_uint_enum is optional */ +#ifdef __clang__ + if (bpf_core_enum_value_exists(enum named_uint_enum, UINT_ENUM_VAL1)) + out->uint_val1 =3D bpf_core_enum_value(enum named_uint_enum, UINT_ENUM= _VAL1); + if (bpf_core_enum_value_exists(enum named_uint_enum, UINT_ENUM_VAL2)) + out->uint_val2 =3D bpf_core_enum_value(enum named_uint_enum, UINT_ENUM= _VAL2); +#else + /* + * GCC's __builtin_preserve_enum_value() returns int, so GCC emits the + * values sign-extended, and libbpf refuses them. + */ + if (bpf_core_enum_value_exists(enum named_uint_enum, UINT_ENUM_VAL1)) + data.skip =3D true; +#endif #else data.skip =3D true; #endif --=20 2.53.1-Meta