From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-186.mta1.migadu.com (out-186.mta1.migadu.com [95.215.58.186]) (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 8343E2DCF55 for ; Tue, 2 Jun 2026 21:08:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.186 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780434541; cv=none; b=LsD6rJL6+MJt2Bn0kRBcyViAFMmCX2QuFANEM8+UKhwNxjxG7/tGc+WfkOXkwwC3Fc1Trjee+2lvbfJ6+vPbQF0KV7tISr6DHvRl2yAeK+uk3yZ/uGGqbGWNGi3f9YasWeHaH8OCLHpqGiv6f0hu+2ZL4df3Sramp5P95/c4qVg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780434541; c=relaxed/simple; bh=dNGkSx2tM1qxsXApQVddpm2XfsR6us8p4reR7Pi9/q8=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=gJIAKS/9cSf0TH5lr2gGp/SrEFyf0L3eSwghwo1Pjfsyl1OmK389AbazxNr89uDtog0dCSakgZRMA8lBZBFe57PE+BEBgelojcUj6PDkTvzYmT2sJDaYObL7ELgpU7Xt9c5RQ7vMjMFMMtkhAdAEuBOL7EQa3wsOdROsKHar6ls= 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=xZkjmCQq; arc=none smtp.client-ip=95.215.58.186 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="xZkjmCQq" Message-ID: <3ba6ed89-82b3-4dbb-99d4-5e34e496fc33@linux.dev> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1780434537; 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=zeurb2c9F7oUWsVkVTj1COrkRc3hnNlwZ2PJ3T6Sw8o=; b=xZkjmCQq172aGjiyhf3GfFYl9aAefj82joEGbZtlKGCeKicndPOVdXRKGsDNN9QHmebHfv Na8Spkj50s3WgWsBbFKXUO53I8ZloIbh3qbAec5FWZ8qp5lncFIffmTBQEfnUMAckBRDFq qkqtGnh97m1eoJtWZpC+o27MrRIaxX0= Date: Tue, 2 Jun 2026 14:08:46 -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: Jiri Olsa Cc: Alexei Starovoitov , Andrii Nakryiko , Daniel Borkmann , Eduard Zingerman , Kumar Kartikeya Dwivedi , Alan Maguire , bpf@vger.kernel.org, linux-kbuild@vger.kernel.org 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: 7bit X-Migadu-Flow: FLOW_OUT On 6/2/26 1:36 PM, Jiri Olsa wrote: > On Mon, Jun 01, 2026 at 03:17:57PM -0700, 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; >> + >> + 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++; >> + } > > hit few of those > > WARN: resolve_btfids: inconsistent flags for kfunc hid_bpf_allocate_context: 0x5 != 0x25 > WARN: resolve_btfids: inconsistent flags for kfunc hid_bpf_release_context: 0x2 != 0x22 > WARN: resolve_btfids: inconsistent flags for kfunc hid_bpf_hw_request: 0x0 != 0x20 > WARN: resolve_btfids: inconsistent flags for kfunc hid_bpf_hw_output_report: 0x0 != 0x20 > WARN: resolve_btfids: inconsistent flags for kfunc hid_bpf_input_report: 0x0 != 0x20 > > I'd think flags like KF_SLEEPABLE might vary in different sets for the same kfunc, > IIUC you don't need to use KF_SLEEPABLE for syscall hook, because syscall programs > are already sleepable.. not sure there are other examples That's a good point. I think from the PoV of resolve_btfids what matters is the mismatch of flags that trigger BTF changes, like KF_IMPLICIT_ARGS. We could check for the specific flags here, or filter out acceptable inconsistencies (KF_SLEEPABLE). Any other ideas? > > jirka