Skip to contentSkip to conversation

resolve_btfids: Implement BTF tags emission for kfuncs

PATCH Applied Ihor Solodrai 3 participants 10 messages Aug 7

Subsystems (6)
Documentation Kbuild Kselftest BPF +2 more subsystems
lore
Share & tools
lore

Ihor Solodrai

author reviewer
#0 lore raw

v3 cover resolve_btfids: Implement BTF tags emission for kfuncs

BTF data for the kernel is generated through the following pipeline:
* DWARF is emitted by the compiler
* pahole reads in DWARF and produces BTF
* resolve_btfids makes kernel-specific btf2btf transformation and patches .BTF_ids section

This is orchestrated by link-vmlinux.sh, gen-btf.sh and Makefile.btf in ./scripts directory.

Historically kernel-specific BTF features were implemented in pahole, and controlled by the feature flags. This requires kernel build process to be aware of pahole version used for the build to set correct runtime arguments for BTF encoding [1].

This is a burden which can be alleviated by splitting kernel/module BTF generation in two stages:
1. Generic BTF generation from the kernel source code.
2. Kernel-specific BTF modifications to support various BPF features.

So far both stages were fused in pahole's BTF encoding. By moving stage (2) in-tree, the dependency of kernel build on pahole can become much more loose.

resolve_btfids is already responsible for a few kernel-specific BTF modifications:
* .BTF.base generation for modules [2]
* BTF sorting [3]
* KF_IMPLICIT_ARGS support [4]

This series completes the migration by emitting BTF kfunc annotations
in-tree: the "bpf_kfunc" and "bpf_fastcall" decl tags and the arena "address_space(1)" type attribute, dropping the corresponding pahole feature flags.

The three annotations depend on two pahole feature flags:
"decl_tag_kfuncs" and "attributes". Since emission is unconditional, each flag has to be dropped in the same commit as the emission that replaces it.

[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/scripts/Makefile.btf?h=v7.1-rc5
[2] https://docs.kernel.org/bpf/btf.html#btf-base-section
[3] https://lore.kernel.org/bpf/[email protected]/
[4] https://lore.kernel.org/bpf/[email protected]/
[5] https://lore.kernel.org/bpf/[email protected]/
[6] https://lore.kernel.org/bpf/[email protected]/

---

v2->v3:
* Refactoring in patch #2 (Eduard)
* restructure add_arena_tagged_proto() such that first we copy the func proto and then update param types in place
* push error messages down to arena_tag_ptr()
* introduce is_arena_arg() helper
* Docs cleanup in patch #6 (Eduard)
* Add stats in commit message for patch #1
v2: https://lore.kernel.org/bpf/[email protected]/

v1->v2:
* The bottom part of v1 has already been landed [5][6].
* New patch #1: run btf__dedup() in finalize_btf().
* Drop the "ensure" pattern. Emission is unconditional; kbuild owns the pahole flags, so assume input BTF is not already tagged.
* Each pahole flag is now dropped in the same commit as the emission that replaces it.
* Fail hard with an error on invalid kfunc declarations such as an arena flag naming a missing argument or a non-pointer type.
* Various cleanups and nits (Andrii, Emil, Jiri, Sashiko).
v1: https://lore.kernel.org/bpf/[email protected]/

---

Ihor Solodrai (6):
resolve_btfids: Deduplicate BTF after btf2btf transformations
resolve_btfids: Process KF_ARENA_* flags in resolve_btfids selftests/bpf: Verify arena type tags in resolve_btfids test
resolve_btfids: Emit bpf_kfunc and bpf_fastcall decl tags selftests/bpf: Verify decl tags emission in resolve_btfids test docs, resolve_btfids: Document kfunc BTF annotation emission

 Documentation/bpf/kfuncs.rst                  |   7 +
 Documentation/process/changes.rst             |   5 -
 scripts/Makefile.btf                          |   4 +-
 tools/bpf/resolve_btfids/main.c               | 185 +++++++++++++++++-
 .../selftests/bpf/prog_tests/resolve_btfids.c | 106 ++++++++++
 tools/testing/selftests/bpf/progs/btf_data.c  |  10 +
 6 files changed, 304 insertions(+), 13 deletions(-)
Signature · 1 line
2.55.0
author reviewer
#1 lore raw

PATCH v3 1/6 resolve_btfids: Deduplicate BTF after btf2btf transformations

btf2btf() adds new types to the BTF: the KF_IMPLICIT_ARGS transform synthesizes an _impl FUNC together with its FUNC_PROTO and copies of the kfunc's decl tags. Nothing deduplicates them afterwards. pahole runs btf__dedup() on its own output, but that happens before resolve_btfids sees the BTF, so any type the tool itself creates is emitted as-is, even when a structurally identical type is already present.

Call btf__dedup() at the start of finalize_btf(), so that base distillation and the by-name sort both operate on the canonical set of types.

On an x86_64 build with the BPF selftests config this removes 17 duplicate FUNC_PROTOs from vmlinux BTF.

The dedup call increases runtime of resolve_btfids on vmlinux by 30-40%. The performance hit is an acceptable cost to keep kernel BTF deduped [1].

[1] https://lore.kernel.org/bpf/[email protected]/

---
 tools/bpf/resolve_btfids/main.c | 6 ++++++
 1 file changed, 6 insertions(+)
tools/bpf/resolve_btfids/main.c +6 -0
index 85488935909d..5d168c2a5ff5 100644
@@ -1379,6 +1379,12 @@ static int finalize_btf(struct object *obj)
 	struct btf *base_btf = obj->base_btf, *btf = obj->btf;
 	int err;
 
+	err = btf__dedup(obj->btf, NULL);
+	if (err) {
+		pr_err("FAILED to dedup BTF: %s\n", strerror(errno));
+		goto out_err;
+	}
+
 	if (obj->base_btf && obj->distill_base) {
 		err = btf__distill_base(obj->btf, &base_btf, &btf);
 		if (err) {
Signature · 1 line
2.55.0
author reviewer
#2 lore raw

PATCH v3 2/6 resolve_btfids: Process KF_ARENA_* flags in resolve_btfids

In reply to Ihor Solodrai

For kfuncs flagged with KF_ARENA_RET, KF_ARENA_ARG1 or KF_ARENA_ARG2, the address_space(1) attribute (a type tag with kflag=1) must be emitted for the corresponding type in BTF. This was previously done by pahole via the "attributes" BTF feature [1].

Implement the emission of the arena attributes in resolve_btfids: for flagged kfuncs create a new function prototype with updated BTF types. The original proto may be shared with sibling FUNCs, so it is not modified in place.

Emission is unconditional: kbuild controls the pahole flags, so the input BTF is expected to not have these attributes. Invalid declarations are reported as errors.

Drop the "attributes" pahole feature from scripts/Makefile.btf resolve_btfids now emits them for all supported pahole versions.

[1] https://lore.kernel.org/dwarves/[email protected]/

---
 scripts/Makefile.btf            |   2 -
 tools/bpf/resolve_btfids/main.c | 139 ++++++++++++++++++++++++++++++--
 2 files changed, 134 insertions(+), 7 deletions(-)
scripts/Makefile.btf +0 -2
index e66e13e79653..8f73c093d27a 100644
@@ -16,8 +16,6 @@ else
 # Switch to using --btf_features for v1.26 and later.
 pahole-flags-$(call test-ge, $(pahole-ver), 126)  = -j$(JOBS) --btf_features=encode_force,var,float,enum64,decl_tag,type_tag,optimized_func,consistent_func,decl_tag_kfuncs
 
-pahole-flags-$(call test-ge, $(pahole-ver), 130) += --btf_features=attributes
-
 pahole-flags-$(call test-ge, $(pahole-ver), 131) += --btf_features=layout
 
 endif
tools/bpf/resolve_btfids/main.c +134 -5

160 lines not on this page · raw message

Signature · 1 line
2.55.0
author reviewer
#3 lore raw

PATCH v3 3/6 selftests/bpf: Verify arena type tags in resolve_btfids test

In reply to Ihor Solodrai

Extend test_resolve_btfids() to assert that resolve_btfids emits the address_space(1) type attribute (a BTF_KIND_TYPE_TAG with kflag=1) on the return type and/or arguments of kfuncs marked KF_ARENA_RET, KF_ARENA_ARG1 or KF_ARENA_ARG2.

---
 .../selftests/bpf/prog_tests/resolve_btfids.c | 66 +++++++++++++++++++
 tools/testing/selftests/bpf/progs/btf_data.c  | 10 +++
 2 files changed, 76 insertions(+)
tools/testing/selftests/bpf/prog_tests/resolve_btfids.c +66 -0
index ac51fd454821..8482f00046d4 100644
@@ -12,9 +12,20 @@
 
 #define BTF_DATA_FILE "resolve_btfids.test.o.BTF"
 
+#define TYPE_ATTR_ARENA "address_space(1)"
+
 #ifndef KF_FASTCALL
 #define KF_FASTCALL (1 << 12)
 #endif
+#ifndef KF_ARENA_RET
+#define KF_ARENA_RET  (1 << 13)
+#endif
+#ifndef KF_ARENA_ARG1
+#define KF_ARENA_ARG1 (1 << 14)
+#endif
+#ifndef KF_ARENA_ARG2
+#define KF_ARENA_ARG2 (1 << 15)
+#endif
 
 struct symbol {
 	const char	*name;
@@ -41,6 +52,8 @@ struct kfunc_symbol {
 static struct kfunc_symbol kfunc_symbols[] = {
 	{ "kfunc_a", -1, 0 },
 	{ "kfunc_b", -1, KF_FASTCALL },
+	{ "kfunc_c", -1, KF_ARENA_RET | KF_ARENA_ARG1 | KF_ARENA_ARG2 },
+	{ "kfunc_d", -1, KF_ARENA_ARG2 },
 };
 
 /* Align the .BTF_ids section to 4 bytes */
@@ -88,6 +101,8 @@ BTF_SET_END(test_set)
 BTF_KFUNCS_START(test_kfunc_set)
 BTF_ID_FLAGS(func, kfunc_a)
 BTF_ID_FLAGS(func, kfunc_b, KF_FASTCALL)
+BTF_ID_FLAGS(func, kfunc_c, KF_ARENA_RET | KF_ARENA_ARG1 | KF_ARENA_ARG2)
+BTF_ID_FLAGS(func, kfunc_d, KF_ARENA_ARG2)
 BTF_KFUNCS_END(test_kfunc_set)
 
 /*
@@ -95,6 +110,8 @@ BTF_KFUNCS_END(test_kfunc_set)
  * actually sort at least one of the two sets.
  */
 BTF_KFUNCS_START(test_kfunc_set_rev)
+BTF_ID_FLAGS(func, kfunc_d, KF_ARENA_ARG2)
+BTF_ID_FLAGS(func, kfunc_c, KF_ARENA_RET | KF_ARENA_ARG1 | KF_ARENA_ARG2)
 BTF_ID_FLAGS(func, kfunc_b, KF_FASTCALL)
 BTF_ID_FLAGS(func, kfunc_a)
 BTF_KFUNCS_END(test_kfunc_set_rev)
@@ -184,6 +201,22 @@ static void check_kfunc_set(struct btf_id_set8 *set)
 	}
 }
 
+/* True if @id is PTR -> TYPE_TAG(kflag=1, "address_space(1)") -> pointee */
+static bool is_arena_tagged_ptr(struct btf *btf, __u32 id)
+{
+	const struct btf_type *ptr, *tag;
+	const char *name;
+
+	ptr = btf__type_by_id(btf, id);
+	if (!btf_is_ptr(ptr))
+		return false;
+	tag = btf__type_by_id(btf, ptr->type);
+	if (!btf_is_type_tag(tag) || !btf_kflag(tag))
+		return false;
+	name = btf__name_by_offset(btf, tag->name_off);
+	return strcmp(name, TYPE_ATTR_ARENA) == 0;
+}
+
 void test_resolve_btfids(void)
 {
 	__u32 *test_list, *test_lists[] = { test_list_local, test_list_global };
@@ -227,6 +260,39 @@ void test_resolve_btfids(void)
 	check_kfunc_set(&test_kfunc_set);
 	check_kfunc_set(&test_kfunc_set_rev);
 
+	/*
+	 * Check resolve_btfids wrapped exactly the arena-flagged return/args
+	 * with the address_space(1) type attribute, and left other
+	 * pointers/returns untouched.
+	 */
+	for (i = 0; i < ARRAY_SIZE(kfunc_symbols); i++) {
+		const struct btf_type *fn, *proto;
+		const struct btf_param *params;
+		const char *name = kfunc_symbols[i].name;
+		u32 fl = kfunc_symbols[i].flags;
+		__u32 nr;
+
+		fn = btf__type_by_id(btf, kfunc_symbols[i].id);
+		if (!ASSERT_TRUE(btf_is_func(fn), name))
+			continue;
+		proto = btf__type_by_id(btf, fn->type);
+		if (!ASSERT_TRUE(btf_is_func_proto(proto), name))
+			continue;
+		params = btf_params(proto);
+		nr = btf_vlen(proto);
+
+		ASSERT_EQ(is_arena_tagged_ptr(btf, proto->type),
+			  !!(fl & KF_ARENA_RET), name);
+		if (nr > 0) {
+			ASSERT_EQ(is_arena_tagged_ptr(btf, params[0].type),
+				  !!(fl & KF_ARENA_ARG1), name);
+		}
+		if (nr > 1) {
+			ASSERT_EQ(is_arena_tagged_ptr(btf, params[1].type),
+				  !!(fl & KF_ARENA_ARG2), name);
+		}
+	}
+
 out:
 	btf__free(btf);
 }
tools/testing/selftests/bpf/progs/btf_data.c +10 -0
index 8587658012c3..ec34f7a6e038 100644
@@ -58,3 +58,13 @@ int kfunc_b(struct root_struct *root)
 {
 	return 0;
 }
+
+struct root_struct *kfunc_c(struct root_struct *a, struct root_struct *b)
+{
+	return a;
+}
+
+int kfunc_d(struct root_struct *a, struct root_struct *b)
+{
+	return 0;
+}
Signature · 1 line
2.55.0
author reviewer
#4 lore raw

PATCH v3 4/6 resolve_btfids: Emit bpf_kfunc and bpf_fastcall decl tags

In reply to Ihor Solodrai

Emit the bpf_kfunc decl tag for every discovered kfunc, and bpf_fastcall for kfuncs flagged KF_FASTCALL. These were previously produced by pahole under --btf_features=decl_tag_kfuncs.

resolve_btfids now discovers kfuncs from the BTF ID sets [1] and becomes the source of truth for their annotations.

Drop decl_tag_kfuncs pahole feature flag from scripts/Makefile.btf

[1] https://lore.kernel.org/all/[email protected]/

---
 scripts/Makefile.btf            |  2 +-
 tools/bpf/resolve_btfids/main.c | 31 ++++++++++++++++++++++++++++++-
 2 files changed, 31 insertions(+), 2 deletions(-)
scripts/Makefile.btf +1 -1
index 8f73c093d27a..a1812985a61a 100644
@@ -14,7 +14,7 @@ pahole-flags-$(call test-ge, $(pahole-ver), 125)	+= --skip_encoding_btf_inconsis
 else
 
 # Switch to using --btf_features for v1.26 and later.
-pahole-flags-$(call test-ge, $(pahole-ver), 126)  = -j$(JOBS) --btf_features=encode_force,var,float,enum64,decl_tag,type_tag,optimized_func,consistent_func,decl_tag_kfuncs
+pahole-flags-$(call test-ge, $(pahole-ver), 126)  = -j$(JOBS) --btf_features=encode_force,var,float,enum64,decl_tag,type_tag,optimized_func,consistent_func
 
 pahole-flags-$(call test-ge, $(pahole-ver), 131) += --btf_features=layout
 
tools/bpf/resolve_btfids/main.c +30 -1
index 53d9045ed5c8..a1b921e86ef0 100644
@@ -161,6 +161,10 @@ struct object {
 	u32 addr_syms_cap;
 };
 
+#define DECL_TAG_FASTCALL "bpf_fastcall"
+#define DECL_TAG_KFUNC "bpf_kfunc"
+
+#define KF_FASTCALL	(1 << 12)
 #define KF_ARENA_RET	(1 << 13)
 #define KF_ARENA_ARG1	(1 << 14)
 #define KF_ARENA_ARG2	(1 << 15)
@@ -1233,7 +1237,7 @@ static int process_kfunc_with_implicit_args(struct btf2btf_context *ctx, struct
 			continue;
 
 		tag_name = btf__name_by_offset(btf, t->name_off);
-		if (strcmp(tag_name, "bpf_kfunc") == 0)
+		if (strcmp(tag_name, DECL_TAG_KFUNC) == 0)
 			continue;
 
 		idx = btf_decl_tag(t)->component_idx;
@@ -1404,6 +1408,21 @@ static int process_kfunc_with_arena_flags(struct btf2btf_context *ctx,
 	return 0;
 }
 
+static int add_decl_tag(struct btf2btf_context *ctx, const char *tag_name,
+			u32 target_btf_id, int component_idx)
+{
+	s32 new_id;
+
+	new_id = btf__add_decl_tag(ctx->btf, tag_name, target_btf_id, component_idx);
+	if (new_id < 0) {
+		pr_err("ERROR: resolve_btfids: failed to add '%s' decl tag for BTF id %u: %d\n",
+		       tag_name, target_btf_id, new_id);
+		return new_id;
+	}
+
+	return push_decl_tag_id(ctx, new_id);
+}
+
 static int btf2btf(struct object *obj)
 {
 	struct btf2btf_context ctx = {};
@@ -1417,6 +1436,16 @@ static int btf2btf(struct object *obj)
 	for (next = rb_first(&ctx.kfuncs); next; next = rb_next(next)) {
 		struct kfunc *kfunc = rb_entry(next, struct kfunc, rb_node);
 
+		err = add_decl_tag(&ctx, DECL_TAG_KFUNC, kfunc->btf_id, -1);
+		if (err)
+			goto out;
+
+		if (kfunc->flags & KF_FASTCALL) {
+			err = add_decl_tag(&ctx, DECL_TAG_FASTCALL, kfunc->btf_id, -1);
+			if (err)
+				goto out;
+		}
+
 		if (kfunc->flags & KF_IMPLICIT_ARGS) {
 			err = process_kfunc_with_implicit_args(&ctx, kfunc);
 			if (err)
Signature · 1 line
2.55.0
author reviewer
#5 lore raw

PATCH v3 5/6 selftests/bpf: Verify decl tags emission in resolve_btfids test

In reply to Ihor Solodrai

Extend test_resolve_btfids() to assert that resolve_btfids emits a BTF_KIND_DECL_TAG named "bpf_kfunc" for every kfunc, and "bpf_fastcall" for kfuncs marked KF_FASTCALL.

Add a btf_has_decl_tag() helper that scans the output BTF for a decl tag matching name and target.

---
 .../selftests/bpf/prog_tests/resolve_btfids.c | 40 +++++++++++++++++++
 1 file changed, 40 insertions(+)
tools/testing/selftests/bpf/prog_tests/resolve_btfids.c +40 -0
index 8482f00046d4..732cfed35e1c 100644
@@ -12,6 +12,8 @@
 
 #define BTF_DATA_FILE "resolve_btfids.test.o.BTF"
 
+#define DECL_TAG_FASTCALL "bpf_fastcall"
+#define DECL_TAG_KFUNC "bpf_kfunc"
 #define TYPE_ATTR_ARENA "address_space(1)"
 
 #ifndef KF_FASTCALL
@@ -176,6 +178,28 @@ static int resolve_symbols(struct btf *btf)
 	return 0;
 }
 
+static bool btf_has_decl_tag(struct btf *btf, const char *tag_name, s32 target_id)
+{
+	const struct btf_type *t;
+	const char *name;
+	int nr, id;
+
+	nr = btf__type_cnt(btf);
+	for (id = 1; id < nr; id++) {
+		t = btf__type_by_id(btf, id);
+		if (!btf_is_decl_tag(t))
+			continue;
+		if (t->type != (__u32)target_id)
+			continue;
+		if (btf_decl_tag(t)->component_idx != -1)
+			continue;
+		name = btf__name_by_offset(btf, t->name_off);
+		if (strcmp(name, tag_name) == 0)
+			return true;
+	}
+	return false;
+}
+
 static void check_kfunc_set(struct btf_id_set8 *set)
 {
 	unsigned int i, j;
@@ -260,6 +284,22 @@ void test_resolve_btfids(void)
 	check_kfunc_set(&test_kfunc_set);
 	check_kfunc_set(&test_kfunc_set_rev);
 
+	/* Check resolve_btfids emitted a bpf_kfunc decl_tag for each kfunc */
+	for (i = 0; i < ARRAY_SIZE(kfunc_symbols); i++) {
+		ASSERT_TRUE(btf_has_decl_tag(btf, DECL_TAG_KFUNC,
+					     kfunc_symbols[i].id),
+			    kfunc_symbols[i].name);
+	}
+
+	/* Check resolve_btfids emitted bpf_fastcall for KF_FASTCALL kfuncs */
+	for (i = 0; i < ARRAY_SIZE(kfunc_symbols); i++) {
+		if (kfunc_symbols[i].flags & KF_FASTCALL) {
+			ASSERT_TRUE(btf_has_decl_tag(btf, DECL_TAG_FASTCALL,
+						     kfunc_symbols[i].id),
+				    kfunc_symbols[i].name);
+		}
+	}
+
 	/*
 	 * Check resolve_btfids wrapped exactly the arena-flagged return/args
 	 * with the address_space(1) type attribute, and left other
Signature · 1 line
2.55.0
#6 lore raw

Re: [PATCH bpf-next v3 5/6] selftests/bpf: Verify decl tags emission in resolve_btfids test

This isn't a bug, but could the bpf_fastcall check use an ASSERT_EQ form instead of the conditional ASSERT_TRUE?
Quoted 4 lines
tools/testing/selftests/bpf/prog_tests/resolve_btfids.c +0 -0
index 8482f00046d4c..732cfed35e1c5 100644

[ ... ]

Quoted 9 lines
tools/testing/selftests/bpf/prog_tests/resolve_btfids.c +5 -0
@@ -260,6 +284,22 @@ void test_resolve_btfids(void)
 	check_kfunc_set(&test_kfunc_set);
 	check_kfunc_set(&test_kfunc_set_rev);
 
+	/* Check resolve_btfids emitted a bpf_kfunc decl_tag for each kfunc */
+	for (i = 0; i < ARRAY_SIZE(kfunc_symbols); i++) {
+		ASSERT_TRUE(btf_has_decl_tag(btf, DECL_TAG_KFUNC,
+					     kfunc_symbols[i].id),
+			    kfunc_symbols[i].name);

tools/testing/selftests/bpf/prog_tests/resolve_btfids.c void test_resolve_btfids(void) · line 301

Quoted 10 lines
tools/testing/selftests/bpf/prog_tests/resolve_btfids.c +10 -0
+	}
+
+	/* Check resolve_btfids emitted bpf_fastcall for KF_FASTCALL kfuncs */
+	for (i = 0; i < ARRAY_SIZE(kfunc_symbols); i++) {
+		if (kfunc_symbols[i].flags & KF_FASTCALL) {
+			ASSERT_TRUE(btf_has_decl_tag(btf, DECL_TAG_FASTCALL,
+						     kfunc_symbols[i].id),
+				    kfunc_symbols[i].name);
+		}
+	}

This isn't a bug, but could the bpf_fastcall check use an ASSERT_EQ form instead of the conditional ASSERT_TRUE?

The arena block below this code uses:

	ASSERT_EQ(is_arena_tagged_ptr(btf, proto->type),
		  !!(fl & KF_ARENA_RET), name);

which checks both directions: flagged functions have the tag, and unflagged functions don't. As written here, the second loop only verifies that flagged kfuncs get bpf_fastcall; it doesn't check that kfunc_a, kfunc_c, and kfunc_d (which lack KF_FASTCALL) are correctly left untagged.

Using the same form as the arena check would fold the two loops into one and cover the negative case as well.

---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/31144437704

author reviewer
#7 lore raw

PATCH v3 6/6 docs, resolve_btfids: Document kfunc BTF annotation emission

In reply to Ihor Solodrai

resolve_btfids now emits the bpf_kfunc and bpf_fastcall BTF decl tags and the arena address_space(1) type attribute for kfuncs, which were previously produced by pahole.

Reflect this in the in-tree comments and documentation.

---
 Documentation/bpf/kfuncs.rst      |  7 +++++++
 Documentation/process/changes.rst |  5 -----
 tools/bpf/resolve_btfids/main.c   | 11 +++++++++++
 3 files changed, 18 insertions(+), 5 deletions(-)
Documentation/bpf/kfuncs.rst +7 -0
index cbde86d082cc..021be6d93dfb 100644
@@ -472,6 +472,13 @@ type. An example is shown below::
         }
         late_initcall(init_subsystem);
 
+At kernel build time the ``resolve_btfids`` tool finds all kfuncs declared with
+``BTF_KFUNCS_START()`` and emits their BTF annotations into the kernel's BTF.
+For each kfunc it emits a ``bpf_kfunc`` BTF decl tag, a ``bpf_fastcall`` decl
+tag when the kfunc is flagged ``KF_FASTCALL``, and the ``address_space(1)`` type
+attribute on the return value and/or arguments flagged ``KF_ARENA_RET``,
+``KF_ARENA_ARG1`` or ``KF_ARENA_ARG2`` (see section 2.8).
+
 2.7  Specifying no-cast aliases with ___init
 --------------------------------------------
 
Documentation/process/changes.rst +0 -5
index 1ca8c5f73ad0..0aa232b117b5 100644
@@ -147,11 +147,6 @@ Since Linux 5.2, if CONFIG_DEBUG_INFO_BTF is selected, the build system
 generates BTF (BPF Type Format) from DWARF in vmlinux, a bit later from kernel
 modules as well.  This requires pahole v1.22 or later.
 
-Since Linux 7.0, kfuncs annotated with KF_IMPLICIT_ARGS require pahole v1.26
-or later.  Without it, such kfuncs will have incorrect BTF prototypes in
-vmlinux, causing BPF programs to fail to load with a "func_proto incompatible
-with vmlinux" error.  Many sched_ext kfuncs are affected.
-
 It is found in the 'dwarves' or 'pahole' distro packages or from
 https://fedorapeople.org/~acme/dwarves/.
 
tools/bpf/resolve_btfids/main.c +11 -0
index a1b921e86ef0..d2e4176339da 100644
@@ -58,6 +58,17 @@
  *             __BTF_ID__func__vfs_fallocate__5:
  *             .zero 4
  *	       .word (1 << 3) | (1 << 1) | (1 << 2)
+ *
+ * In addition to resolving BTF IDs, resolve_btfids performs kernel-specific
+ * BTF-to-BTF transformations for kfuncs found in BTF_SET8_KFUNCS sets. For
+ * each such kfunc it:
+ *
+ *   - emits a "bpf_kfunc" decl tag, and "bpf_fastcall" when KF_FASTCALL is set;
+ *   - wraps the return value and/or arguments flagged KF_ARENA_RET,
+ *     KF_ARENA_ARG1 or KF_ARENA_ARG2 with the "address_space(1)" type attribute;
+ *   - rewrites the prototype of KF_IMPLICIT_ARGS kfuncs.
+ *
+ * These kfunc annotations were historically produced by pahole.
  */
 
 #define  _GNU_SOURCE
Signature · 1 line
2.55.0
#8 lore raw

Re: [PATCH bpf-next v3 6/6] docs, resolve_btfids: Document kfunc BTF annotation emission

Should this use an RST :ref: link instead of a hard-coded section number? The arena section currently has no label. If a 2.x subsection is inserted or reordered later, the reference would silently…
Quoted 5 lines
Documentation/bpf/kfuncs.rst +0 -0
index cbde86d082cce..021be6d93dfb0 100644

Documentation/bpf/kfuncs.rst type. An example is shown below:: · line 480

Quoted 9 lines
Documentation/bpf/kfuncs.rst +6 -0
@@ -472,6 +472,13 @@ type. An example is shown below::
         }
         late_initcall(init_subsystem);
 
+At kernel build time the ``resolve_btfids`` tool finds all kfuncs declared with
+``BTF_KFUNCS_START()`` and emits their BTF annotations into the kernel's BTF.
+For each kfunc it emits a ``bpf_kfunc`` BTF decl tag, a ``bpf_fastcall`` decl
+tag when the kfunc is flagged ``KF_FASTCALL``, and the ``address_space(1)`` type
+attribute on the return value and/or arguments flagged ``KF_ARENA_RET``,
+``KF_ARENA_ARG1`` or ``KF_ARENA_ARG2`` (see section 2.8).
                                             ^^^^^^^^^^^^^^^

Should this use an RST :ref: link instead of a hard-coded section number? The arena section currently has no label. If a 2.x subsection is inserted or reordered later, the reference would silently break, and the rendered HTML gives no clickable link. All other cross-references in kfuncs.rst use RST labels and :ref: (lines 16, 27, 51, 415, 609, 625, 807).

[ ... ]

---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/31144437704

#9 lore raw
In reply to Ihor Solodrai
This series was applied to bpf/bpf-next.git (master) by Eduard Zingerman <[email protected]>:

Hello:

This series was applied to bpf/bpf-next.git (master) by Eduard Zingerman <[email protected]>:

Quoted 10 lines · On Thu, 6 Aug 2026 20:20:23 -0700 you wrote:

BTF data for the kernel is generated through the following pipeline:
* DWARF is emitted by the compiler
* pahole reads in DWARF and produces BTF
* resolve_btfids makes kernel-specific btf2btf transformation and patches .BTF_ids section

This is orchestrated by link-vmlinux.sh, gen-btf.sh and Makefile.btf in ./scripts directory.

[...]

Here is the summary with links:
- [bpf-next,v3,1/6] resolve_btfids: Deduplicate BTF after btf2btf transformations

    https://git.kernel.org/bpf/bpf-next/c/3d72aca40b83
  - [bpf-next,v3,2/6] resolve_btfids: Process KF_ARENA_* flags in resolve_btfids
    https://git.kernel.org/bpf/bpf-next/c/27a78c2e7eee
  - [bpf-next,v3,3/6] selftests/bpf: Verify arena type tags in resolve_btfids test
    https://git.kernel.org/bpf/bpf-next/c/ef77140f4b3a
  - [bpf-next,v3,4/6] resolve_btfids: Emit bpf_kfunc and bpf_fastcall decl tags
    https://git.kernel.org/bpf/bpf-next/c/692393104909
  - [bpf-next,v3,5/6] selftests/bpf: Verify decl tags emission in resolve_btfids test
    https://git.kernel.org/bpf/bpf-next/c/9f3881ecad88
  - [bpf-next,v3,6/6] docs, resolve_btfids: Document kfunc BTF annotation emission
    https://git.kernel.org/bpf/bpf-next/c/fd5425b67355

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html