From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-188.mta0.migadu.com (out-188.mta0.migadu.com [91.218.175.188]) (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 5B85237FF5D for ; Tue, 16 Jun 2026 21:49:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.188 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781646563; cv=none; b=l653jSY6+u/U8rXD+D3it45x09kc+AO6AK/eH8G4GCXrapBw6pbOTZS7UlKWgpJ4EbPtxMEQ9miYEXgXUU4Sw+Hlvr2CwUWbElLGFXWRJxwCeiMQc05XGYO6l0assbH2qlu38LUy+dgW/DSwMkU8yJIj6E9RvixEBm4s/XvSiZg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781646563; c=relaxed/simple; bh=MOcFjMqsYk7UWh9f9Sgwv5TsKc//MxEiNuUu7bDbkCs=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=AShtSxGqPvuky2+s9WZawHO4q86xtN5pks4xk5/PgFB+numLBzXYhMuzO4kxNJnIUN2stmtd/sZ+SABvinYuuowfot5YiZNG3hOeJYrFWAi6KxlZDblFEkdCbTje7yRLOpDgXyuPpka+qrmK+hSsn3Jsv+4gZei8c85gjeTYu40= 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=n0Y/tBoM; arc=none smtp.client-ip=91.218.175.188 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="n0Y/tBoM" Message-ID: <949fdd43-9feb-44a1-9c7f-8807689a68e0@linux.dev> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1781646560; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eFiXNMEE3Ha5bwhXk4lM+1jbLSoICDimVXikp/JJQkM=; b=n0Y/tBoMAhAeu3x+I5iyWadCwOwp2ESE7De2vUG5Z4xp0KAmMiZIBRps2kF1KO/qnAi2/f Yts5krb4nlNG0B5QyN1a/oVvmXIPbjWSPc6643a8cU5ERzq//RBrKmqsNW+jPFSjJhIR8K psZU/8gi4uXf8HIoRqdTUf5h0upUT/c= Date: Tue, 16 Jun 2026 14:49:13 -0700 Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: [PATCH bpf-next v1 06/14] resolve_btfids: Discover kfuncs from BTF ID sets To: Andrii Nakryiko Cc: Alexei Starovoitov , Andrii Nakryiko , Daniel Borkmann , Eduard Zingerman , Kumar Kartikeya Dwivedi , Alan Maguire , Jiri Olsa , bpf@vger.kernel.org, linux-kbuild@vger.kernel.org, Emil Tsalapatis References: <20260601221805.821394-1-ihor.solodrai@linux.dev> <20260601221805.821394-7-ihor.solodrai@linux.dev> Content-Language: en-US X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Ihor Solodrai In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT On 6/3/26 4:45 PM, Andrii Nakryiko wrote: > On Mon, Jun 1, 2026 at 3:19 PM Ihor Solodrai wrote: >> >> 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. >> >> Kernel functions can appear in more than one set, which is legitimate, >> since kfunc sets are prog-type dependent in the kernel. So for btf2btf >> processing deduplicate kfuncs by BTF ID, accumulate (OR) the flags, >> and warn on flags mismatch to catch inconsistent declarations. >> >> Signed-off-by: Ihor Solodrai >> --- >> tools/bpf/resolve_btfids/main.c | 122 ++++++++++++++------------------ >> 1 file changed, 55 insertions(+), 67 deletions(-) >> >> diff --git a/tools/bpf/resolve_btfids/main.c b/tools/bpf/resolve_btfids/main.c >> index 43512af13148..d35a7b2460e8 100644 >> --- a/tools/bpf/resolve_btfids/main.c >> +++ b/tools/bpf/resolve_btfids/main.c >> @@ -970,6 +970,23 @@ static int push_kfunc(struct btf2btf_context *ctx, struct kfunc *kfunc) >> struct kfunc *arr = ctx->kfuncs; >> u32 cap = ctx->max_kfuncs; >> >> + /* >> + * A kfunc can be listed in multiple BTF ID sets. >> + * In this case, dedup by btf_id and accumulate kfunc flags. >> + */ >> + for (u32 i = 0; i < ctx->nr_kfuncs; i++) { >> + if (ctx->kfuncs[i].btf_id != kfunc->btf_id) >> + continue; >> + > > with hundreds of kfuncs, this O(N^2) approach is going to be a bit > slow, should we use rb tree for lookups? Yeah, it's O(n^2). I was thinking it's fine, because the number of kfuncs is ~ a few hundreds. I'll use the rbtree in v2. > >> + if (ctx->kfuncs[i].flags != kfunc->flags) { >> + pr_err("WARN: resolve_btfids: inconsistent flags for kfunc %s: 0x%x != 0x%x\n", >> + kfunc->name, ctx->kfuncs[i].flags, kfunc->flags); >> + warnings++; >> + } >> + ctx->kfuncs[i].flags |= kfunc->flags; >> + return 0; >> + } >> + >> if (ctx->nr_kfuncs + 1 > cap) { >> cap = max(cap + 256, cap * 2); >> arr = realloc(arr, sizeof(struct kfunc) * cap); > > [...]