From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-174.mta1.migadu.com (out-174.mta1.migadu.com [95.215.58.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 07CE845D5DE for ; Wed, 22 Jul 2026 23:36:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.174 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784763370; cv=none; b=pf3kJLlU3ufjY+SLMQYkjDo4/PQNVrVaPlk++CemM9lbGNPAHGeJBWKYEUjRasALxG8MBP/tDVgvabVHEIxyRJgvnFmv+VXH7z/SVkQwqF6W50jNmi70vT18z7KGsGJ0yP3HCApXJlON0ut8Wh2qDJhwd3ZR0sPwi+iSPzTyjwM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784763370; c=relaxed/simple; bh=v/pdv2JkGVy2ehVlwH12QM6u9pjseR651rfnlEQFhlg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OU44FIXCWHn7O6eDcRebIeDBaFbI66ViN6fFdALieeKDb5mDnCU9SIZWZGua+2Yq4R4wKdFFCv8iAExaseiV5hlK/yT4dg8AiZ1+4yfr0FVNYhd28vZKNZ9JXUhxjNuUNGZFHI/Gkw5/VOUs8L4LnLcay+AJeov+EiJKIxEdJdA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=qbyNbVg/; arc=none smtp.client-ip=95.215.58.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="qbyNbVg/" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1784763367; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+pUu9hMQ6iFpr4xfemjKlsB1b1nynINi2lTPgLEpDWM=; b=qbyNbVg/UiY7rdDejarC2RcuCJ+NVtgb/8n5703Ua2kqFYq6BBwMwfc+C+aZGYDW//nsJN WfyFgSF4+yq/euVEh76b9KSpVIGprbKaFVGHSqm5tHegA2AUVBqChOTJpJaQUVI9qT2aBO OMsPw+heiaFk41/dUPlVQGwQRsGjRJA= From: Ihor Solodrai To: Alexei Starovoitov , Andrii Nakryiko , Daniel Borkmann , Eduard Zingerman , Kumar Kartikeya Dwivedi Cc: Benjamin Tissoires , Jiri Kosina , Emil Tsalapatis , Jiri Olsa , bpf@vger.kernel.org, linux-input@vger.kernel.org, kernel-team@meta.com Subject: [PATCH bpf-next v1 7/8] resolve_btfids: Discover kfuncs from BTF ID sets Date: Wed, 22 Jul 2026 16:35:17 -0700 Message-ID: <20260722233518.778854-8-ihor.solodrai@linux.dev> In-Reply-To: <20260722233518.778854-1-ihor.solodrai@linux.dev> References: <20260722233518.778854-1-ihor.solodrai@linux.dev> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT collect_kfuncs() currently uses bpf_kfunc decl tags to identify the list of kfuncs. The decl tags are generated by pahole, which makes current implementation implicitly rely on those tags being generated. The authoritative source, used by the the BPF verifier for kfunc registration, of functions being BPF kfuncs are BTF_KFUNCS_START()/END() declarations. These are BTF_ID_SET8 under the hood. Currently resolve_btfids reads kfunc flags from these sets, and populates them with BTF IDs. Implement kfunc discovery from BTF_ID_SET8 symbols in resolve_btfids, removing the dependency on pahole's emmission of decl tags. Walk BTF_ID_KIND_SET8 sets, and use the address-to-symbol index to look up set entry's BTF_ID symbol name (before .BTF_ids is patched), recording the paired flags directly. This makes find_kfunc_flags() helper unnecessary, so it's removed. Signed-off-by: Ihor Solodrai --- tools/bpf/resolve_btfids/main.c | 89 +++++++++++---------------------- 1 file changed, 29 insertions(+), 60 deletions(-) diff --git a/tools/bpf/resolve_btfids/main.c b/tools/bpf/resolve_btfids/main.c index ab3ab3045592..338d0c0a8e58 100644 --- a/tools/bpf/resolve_btfids/main.c +++ b/tools/bpf/resolve_btfids/main.c @@ -1039,19 +1039,18 @@ static int collect_decl_tags(struct btf2btf_context *ctx) return 0; } -/* - * To find kfunc flags, scan BTF_SET8_KFUNCS entries and use the entry - * address to recover the corresponding BTF_ID symbol name. - * Return 0 (no flags!) if not found. - */ -static u32 find_kfunc_flags(struct object *obj, struct btf_id *kfunc_id) +static int collect_kfuncs(struct object *obj, struct btf2btf_context *ctx) { Elf_Data *idlist = obj->efile.idlist; - struct btf_id *set_id; + struct btf *btf = ctx->btf; struct rb_node *next; + if (!idlist || !idlist->d_buf) + return 0; + for (next = rb_first(&obj->sets); next; next = rb_next(next)) { struct btf_id_set8 *set8; + struct btf_id *set_id; u64 set_addr; set_id = rb_entry(next, struct btf_id, rb_node); @@ -1066,64 +1065,34 @@ static u32 find_kfunc_flags(struct object *obj, struct btf_id *kfunc_id) for (u32 i = 0; i < set_id->cnt; i++) { size_t off = (char *)&set8->pairs[i] - (char *)set8; const char *name = find_name_by_addr(obj, set_addr + off); + struct kfunc kfunc; + s32 func_id; + int err; - if (!name || strcmp(name, kfunc_id->name) != 0) + if (!name) { + pr_err("WARN: resolve_btfids: no BTF ID symbol for %s entry %u\n", + set_id->name, i); + warnings++; continue; + } - pr_debug("found kfunc %s in BTF_ID_FLAGS %s\n", - kfunc_id->name, set_id->name); - - return set8->pairs[i].flags; - } - } - - return 0; -} - -static int collect_kfuncs(struct object *obj, struct btf2btf_context *ctx) -{ - const char *tag_name, *func_name; - struct btf *btf = ctx->btf; - const struct btf_type *t; - u32 flags, func_id; - struct kfunc kfunc; - struct btf_id *id; - int err; - - if (ctx->nr_decl_tags == 0) - return 0; - - for (u32 i = 0; i < ctx->nr_decl_tags; i++) { - t = btf__type_by_id(btf, ctx->decl_tags[i]); - if (btf_kflag(t) || btf_decl_tag(t)->component_idx != -1) - continue; - - tag_name = btf__name_by_offset(btf, t->name_off); - if (strcmp(tag_name, "bpf_kfunc") != 0) - continue; - - func_id = t->type; - t = btf__type_by_id(btf, func_id); - if (!btf_is_func(t)) - continue; - - func_name = btf__name_by_offset(btf, t->name_off); - if (!func_name) - continue; - - id = btf_id__find(&obj->funcs, func_name); - if (!id || id->kind != BTF_ID_KIND_SYM) - continue; - - flags = find_kfunc_flags(obj, id); + func_id = btf__find_by_name_kind_own(btf, name, BTF_KIND_FUNC); + if (func_id < 0) { + pr_err("WARN: resolve_btfids: no BTF func for kfunc %s in %s\n", + name, set_id->name); + warnings++; + continue; + } - kfunc.name = id->name; - kfunc.btf_id = func_id; - kfunc.flags = flags; + pr_debug("found kfunc %s in %s\n", name, set_id->name); - err = push_kfunc(ctx, &kfunc); - if (err) - return err; + kfunc.name = name; + kfunc.btf_id = func_id; + kfunc.flags = set8->pairs[i].flags; + err = push_kfunc(ctx, &kfunc); + if (err) + return err; + } } return 0; -- 2.55.0