From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 9A63C37C92B; Tue, 24 Mar 2026 08:21:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774340501; cv=none; b=l3mH0c3280eDaCi6Hu9lMssQVBXiPqJuI4l7nPiwg9VxmQNgylq8yWLFfuu5FPgMYlTKdF3QGBWzXUDZAUu7BrledK1LTkmjWOqgjpgkqppO3RlI/DQoCoLLYxBClVlShEGCyud37PH6PsLe7T0T21HqRxP4xugI3v3jxPZ5JfI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774340501; c=relaxed/simple; bh=+/yv7u50LSQ0czIIcUA88oX+wGngzOSyyiw5j3ClYpA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ub79+MsmwSt0J0bd4tDZZYKOM/oQJ8y83Xd59I+GBMZrMGJ96km6qORP3tlIzoFDdJ/zbgM6yR0UA32jUIT9eomWdf1I/IMnBdvhG58Dox5xHr1LrJq9Q5Clz1NNx2Lo+K2agJb3W4XEpN0XiyCpDRvdwx5HFXN242NUJibUlxo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=gI6eicZR; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="gI6eicZR" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4FE89C19424; Tue, 24 Mar 2026 08:21:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1774340501; bh=+/yv7u50LSQ0czIIcUA88oX+wGngzOSyyiw5j3ClYpA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gI6eicZR/nNNEbmInLAu7/1j4ITrSX63do8H7/tXT4NPMJBlwbmwpiPowzqfqATvf KP/P6iO/JCQsecaHo9GGnnpO+7H+RR+U4C0PQn7vaHJJANuqtmPY/ZKskMse+hoN/k Q02dq06yKIIFHmEnuKQ7BvV4yVcOz5QNl6NQBl8fWJ7Is6TrfcZKnkFhmgneR8GH4d 8veUr6E4mipK7+s8pbdsIHQxag/RU/D/y0QJntKxAL0FYbF1rqaFQ6CLk7bNwbhHAW +14C7oGD1ySzB9vUoYeWpqVDRQ+zybs4hIdUHWW4ZoTL5k4Xl4TXQ0hujWD1Sk5Fhu hqjci3HwXlSzQ== From: Jiri Olsa To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Cc: bpf@vger.kernel.org, linux-trace-kernel@vger.kernel.org, Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , Menglong Dong , Steven Rostedt Subject: [PATCHv4 bpf-next 16/25] libbpf: Add btf_type_is_traceable_func function Date: Tue, 24 Mar 2026 09:18:37 +0100 Message-ID: <20260324081846.2334094-17-jolsa@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260324081846.2334094-1-jolsa@kernel.org> References: <20260324081846.2334094-1-jolsa@kernel.org> Precedence: bulk X-Mailing-List: linux-trace-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Adding btf_type_is_traceable_func function to perform same checks as the kernel's btf_distill_func_proto function to prevent attachment on some of the functions. Exporting the function via libbpf_internal.h because it will be used by benchmark test in following changes. Signed-off-by: Jiri Olsa --- tools/lib/bpf/libbpf.c | 54 +++++++++++++++++++++++++++++++++ tools/lib/bpf/libbpf_internal.h | 1 + 2 files changed, 55 insertions(+) diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index c6cd6ccb870b..139df8484edb 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -12353,6 +12353,60 @@ static int attach_uprobe_multi(const struct bpf_program *prog, long cookie, stru return ret; } +#define MAX_BPF_FUNC_ARGS 12 + +static bool btf_type_is_modifier(const struct btf_type *t) +{ + switch (BTF_INFO_KIND(t->info)) { + case BTF_KIND_TYPEDEF: + case BTF_KIND_VOLATILE: + case BTF_KIND_CONST: + case BTF_KIND_RESTRICT: + case BTF_KIND_TYPE_TAG: + return true; + default: + return false; + } +} + +bool btf_type_is_traceable_func(const struct btf *btf, const struct btf_type *t) +{ + const struct btf_type *proto; + const struct btf_param *args; + __u32 i, nargs; + __s64 ret; + + proto = btf_type_by_id(btf, t->type); + if (BTF_INFO_KIND(proto->info) != BTF_KIND_FUNC_PROTO) + return false; + + args = (const struct btf_param *)(proto + 1); + nargs = btf_vlen(proto); + if (nargs > MAX_BPF_FUNC_ARGS) + return false; + + /* No support for struct/union return argument type. */ + t = btf__type_by_id(btf, proto->type); + while (t && btf_type_is_modifier(t)) + t = btf__type_by_id(btf, t->type); + + if (btf_is_struct(t) || btf_is_union(t)) + return false; + + for (i = 0; i < nargs; i++) { + /* No support for variable args. */ + if (i == nargs - 1 && args[i].type == 0) + return false; + + /* No support of struct argument size greater than 16 bytes. */ + ret = btf__resolve_size(btf, args[i].type); + if (ret < 0 || ret > 16) + return false; + } + + return true; +} + static inline int add_uprobe_event_legacy(const char *probe_name, bool retprobe, const char *binary_path, size_t offset) { diff --git a/tools/lib/bpf/libbpf_internal.h b/tools/lib/bpf/libbpf_internal.h index 4bcb6ca69bb1..1b539c901898 100644 --- a/tools/lib/bpf/libbpf_internal.h +++ b/tools/lib/bpf/libbpf_internal.h @@ -250,6 +250,7 @@ const struct btf_type *skip_mods_and_typedefs(const struct btf *btf, __u32 id, _ const struct btf_header *btf_header(const struct btf *btf); void btf_set_base_btf(struct btf *btf, const struct btf *base_btf); int btf_relocate(struct btf *btf, const struct btf *base_btf, __u32 **id_map); +bool btf_type_is_traceable_func(const struct btf *btf, const struct btf_type *t); static inline enum btf_func_linkage btf_func_linkage(const struct btf_type *t) { -- 2.53.0